Worker.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 = ['info'];
  13. protected $table = 'worker';
  14. public function index(){
  15. $list = Db::name($this->table)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->order('id desc')->select();
  16. $list = list_domain_image($list,['avatar','idcard_z_image','idcard_f_image','jineng_image']);
  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. 'status' => input('status',1),
  36. 'idcard_z_image' => input('idcard_z_image',''),
  37. 'idcard_f_image' => input('idcard_f_image',''),
  38. 'jineng_image' => input('jineng_image',''),
  39. ];
  40. Db::name($this->table)->insertGetId($data);
  41. $this->success();
  42. }
  43. public function info(){
  44. $id = input('id',0);
  45. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  46. $info = info_domain_image($info,['avatar','idcard_z_image','idcard_f_image','jineng_image']);
  47. $this->success(1,$info);
  48. }
  49. public function edit(){
  50. $id = input('id',0);
  51. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  52. if(empty($info)){
  53. $this->error('没找到该信息,请刷新重试');
  54. }
  55. $mobile = input('mobile','');
  56. if(empty($mobile)){
  57. $this->error();
  58. }
  59. $check = Db::name($this->table)->where('mobile',$mobile)->where('id','NEQ',$id)->where('deletetime',NULL)->find();
  60. if($check){
  61. $this->error('该手机号已被他人注册');
  62. }
  63. $data = [
  64. 'avatar' => input('avatar',''),
  65. 'truename' => input('truename',''),
  66. 'gonghao' => input('gonghao',''),
  67. 'mobile' => $mobile,
  68. 'password' => input('password',''),
  69. 'status' => input('status',1),
  70. 'idcard_z_image' => input('idcard_z_image',''),
  71. 'idcard_f_image' => input('idcard_f_image',''),
  72. 'jineng_image' => input('jineng_image',''),
  73. ];
  74. Db::name($this->table)->where('id',$id)->update($data);
  75. $this->success();
  76. }
  77. public function del(){
  78. $ids = input('ids','');
  79. $ids = explode(',',$ids);
  80. if (empty($ids)) {
  81. $this->error();
  82. }
  83. Db::name($this->table)->where('id','IN',$ids)->where('company_id',$this->auth->company_id)->update(['deletetime'=>time()]);
  84. $this->success();
  85. }
  86. }