Staff.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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->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->id,
  23. ];
  24. //检查
  25. $check1 = Db::name('company')->where('mobile',$data['mobile'])->find();
  26. $check2 = Db::name('company_staff')->where('mobile',$data['mobile'])->find();
  27. if($check1 || $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. $check1 = Db::name('company')->where('mobile',$data['mobile'])->find();
  48. $check2 = Db::name('company_staff')->where('id','neq',$id)->where('mobile',$data['mobile'])->find();
  49. if($check1 || $check2){
  50. $this->error('该手机已经被注册为员工或商户管理员');
  51. }
  52. Db::name('company_staff')->where('id',$id)->update($data);
  53. $this->success('编辑成功');
  54. }
  55. }