Staff.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. /**
  6. * 员工管理
  7. */
  8. class Staff extends Apic
  9. {
  10. protected $noNeedLogin = [];
  11. protected $noNeedRight = '*';
  12. //列表
  13. public function lists(){
  14. $list = Db::name('company_staff')->where('company_id',$this->auth->company_id)->autopage()->select();
  15. $this->success('success',$list);
  16. }
  17. //新增
  18. public function add(){
  19. $data = [
  20. 'truename' => input('truename',''),
  21. 'mobile' => input('mobile',''),
  22. 'company_id' => $this->auth->company_id,
  23. 'type' => 2,
  24. ];
  25. //检查
  26. $check2 = Db::name('company_staff')->where('mobile',$data['mobile'])->find();
  27. if($check2){
  28. $this->error('该手机已经被注册为员工或商户管理员');
  29. }
  30. Db::name('company_staff')->insertGetId($data);
  31. $this->success('添加成功');
  32. }
  33. //详情
  34. public function info(){
  35. $id = input('id',0);
  36. $info = Db::name('company_staff')->where('id',$id)->find();
  37. $this->success(1,$info);
  38. }
  39. //编辑
  40. public function edit(){
  41. $id = input('id',0);
  42. $data = [
  43. 'truename' => input('truename',''),
  44. 'mobile' => input('mobile',''),
  45. ];
  46. //检查
  47. $check2 = Db::name('company_staff')->where('id','neq',$id)->where('mobile',$data['mobile'])->find();
  48. if($check2){
  49. $this->error('该手机已经被注册为员工或商户管理员');
  50. }
  51. Db::name('company_staff')->where('id',$id)->update($data);
  52. $this->success('编辑成功');
  53. }
  54. }