Staff.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. public function _initialize()
  13. {
  14. parent::_initialize();
  15. }
  16. //列表
  17. public function lists(){
  18. $list = Db::name('company_staff')->where('company_id',$this->auth->id)->autopage()->select();
  19. $this->success('success',$list);
  20. }
  21. //新增
  22. public function add(){
  23. $data = [
  24. 'truename' => input('truename',''),
  25. 'mobile' => input('mobile',''),
  26. 'company_id' => $this->auth->id,
  27. ];
  28. //检查
  29. $check1 = Db::name('company')->where('mobile',$data['mobile'])->find();
  30. $check2 = Db::name('company_staff')->where('mobile',$data['mobile'])->find();
  31. if($check1 || $check2){
  32. $this->error('该手机已经被注册为员工或商户管理员');
  33. }
  34. Db::name('company_staff')->insertGetId($data);
  35. $this->success('添加成功');
  36. }
  37. //详情
  38. public function info(){
  39. $id = input('id',0);
  40. $info = Db::name('company_staff')->where('id',$id)->find();
  41. $this->success(1,$info);
  42. }
  43. //编辑
  44. public function edit(){
  45. $id = input('id',0);
  46. $data = [
  47. 'truename' => input('truename',''),
  48. 'mobile' => input('mobile',''),
  49. ];
  50. //检查
  51. $check1 = Db::name('company')->where('mobile',$data['mobile'])->find();
  52. $check2 = Db::name('company_staff')->where('id','neq',$id)->where('mobile',$data['mobile'])->find();
  53. if($check1 || $check2){
  54. $this->error('该手机已经被注册为员工或商户管理员');
  55. }
  56. Db::name('company_staff')->where('id',$id)->update($data);
  57. $this->success('编辑成功');
  58. }
  59. }