Worker.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <?php
  2. namespace app\company\controller;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. use app\common\library\Tenim;
  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. $worker_id = Db::name($this->table)->insertGetId($data);
  41. //注册到im
  42. //user_用户端小程序,master_师傅,kefu_客服
  43. $tenim = new Tenim();
  44. $rs = $tenim->register('master_'. $worker_id, $data['truename'], localpath_to_netpath($data['avatar']));
  45. $this->success();
  46. }
  47. public function info(){
  48. $id = input('id',0);
  49. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  50. $info = info_domain_image($info,['avatar','idcard_z_image','idcard_f_image','jineng_image']);
  51. $this->success(1,$info);
  52. }
  53. public function edit(){
  54. $id = input('id',0);
  55. $info = Db::name($this->table)->where('id',$id)->where('company_id',$this->auth->company_id)->where('deletetime',NULL)->find();
  56. if(empty($info)){
  57. $this->error('没找到该信息,请刷新重试');
  58. }
  59. $mobile = input('mobile','');
  60. if(empty($mobile)){
  61. $this->error();
  62. }
  63. $check = Db::name($this->table)->where('mobile',$mobile)->where('id','NEQ',$id)->where('deletetime',NULL)->find();
  64. if($check){
  65. $this->error('该手机号已被他人注册');
  66. }
  67. $data = [
  68. 'avatar' => input('avatar',''),
  69. 'truename' => input('truename',''),
  70. 'gonghao' => input('gonghao',''),
  71. 'mobile' => $mobile,
  72. 'password' => input('password',''),
  73. 'status' => input('status',1),
  74. 'idcard_z_image' => input('idcard_z_image',''),
  75. 'idcard_f_image' => input('idcard_f_image',''),
  76. 'jineng_image' => input('jineng_image',''),
  77. ];
  78. Db::name($this->table)->where('id',$id)->update($data);
  79. //如果有修改头像或昵称,同步到im
  80. //user_用户端小程序,master_师傅,kefu_客服
  81. $tenim = new Tenim();
  82. $rs = $tenim->useredit('master_'. $id, $data['truename'], localpath_to_netpath($data['avatar']));
  83. $this->success();
  84. }
  85. public function del(){
  86. $ids = input('ids','');
  87. $ids = explode(',',$ids);
  88. if (empty($ids)) {
  89. $this->error();
  90. }
  91. Db::name($this->table)->where('id','IN',$ids)->where('company_id',$this->auth->company_id)->update(['deletetime'=>time()]);
  92. $this->success();
  93. }
  94. }