Worker.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace app\company\controller;
  3. use app\common\controller\Apic;
  4. use Symfony\Component\Cache\Adapter\NullAdapter;
  5. use think\Db;
  6. /**
  7. * 师傅
  8. */
  9. class Worker extends Apic
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = [];
  13. protected $table = 'worker';
  14. public function index(){
  15. $list = Db::name($this->table)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->select();
  16. $list = list_domain_image($list,['avatar']);
  17. $this->success(1,$list);
  18. }
  19. public function add(){
  20. $mobile = input('mobile','');
  21. if(empty($mobile)){
  22. $this->error();
  23. }
  24. $check = Db::name($this->table)->where('mobile',$mobile)->where('deletetime',NULL)->find();
  25. if($check){
  26. $this->error('该手机号已被他人注册');
  27. }
  28. $data = [
  29. 'avatar' => input('avatar',''),
  30. 'truename' => input('truename',''),
  31. 'gonghao' => input('gonghao',''),
  32. 'mobile' => $mobile,
  33. 'password' => input('password',''),
  34. 'company_id' => $this->auth->company_id,
  35. ];
  36. Db::name($this->table)->insertGetId($data);
  37. $this->success();
  38. }
  39. public function info(){
  40. $id = input('id',0);
  41. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  42. $info = info_domain_image($info,['avatar']);
  43. $this->success(1,$info);
  44. }
  45. public function edit(){
  46. $id = input('id',0);
  47. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  48. if(empty($info)){
  49. $this->error('没找到该信息,请刷新重试');
  50. }
  51. $mobile = input('mobile','');
  52. if(empty($mobile)){
  53. $this->error();
  54. }
  55. $check = Db::name($this->table)->where('mobile',$mobile)->where('id','NEQ',$id)->where('deletetime',NULL)->find();
  56. if($check){
  57. $this->error('该手机号已被他人注册');
  58. }
  59. $data = [
  60. 'avatar' => input('avatar',''),
  61. 'truename' => input('truename',''),
  62. 'gonghao' => input('gonghao',''),
  63. 'mobile' => $mobile,
  64. 'password' => input('password',''),
  65. ];
  66. Db::name($this->table)->where('id',$id)->update($data);
  67. $this->success();
  68. }
  69. public function del(){
  70. $ids = input('ids','');
  71. $ids = explode(',',$ids);
  72. if (empty($ids)) {
  73. $this->error();
  74. }
  75. Db::name($this->table)->where('id','IN',$ids)->where('company_id',$this->auth->company_id)->update(['deletetime'=>time()]);
  76. $this->success();
  77. }
  78. }