Staff.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use think\Db;
  5. use fast\Random;
  6. /**
  7. * 员工管理
  8. */
  9. class Staff extends Apic
  10. {
  11. protected $noNeedLogin = [];
  12. protected $noNeedRight = '*';
  13. //列表
  14. public function lists(){
  15. $list = Db::name('company_staff')->field('id,company_id,truename,mobile')->where('company_id',$this->auth->company_id)->autopage()->select();
  16. $this->success('success',$list);
  17. }
  18. //新增
  19. public function add(){
  20. $data = [
  21. 'truename' => input('truename',''),
  22. 'mobile' => input('mobile',''),
  23. 'company_id' => $this->auth->company_id,
  24. 'type' => 2,
  25. ];
  26. //密码
  27. $password = input('password','123456');
  28. $salt = Random::alnum();
  29. $newpassword = $this->getEncryptPassword($password, $salt);
  30. $data['password'] = $newpassword;
  31. $data['salt'] = $salt;
  32. //检查
  33. $check2 = Db::name('company_staff')->where('mobile',$data['mobile'])->find();
  34. if($check2){
  35. $this->error('该手机已经被注册为员工或商户管理员');
  36. }
  37. Db::name('company_staff')->insertGetId($data);
  38. $this->success('添加成功');
  39. }
  40. /**
  41. * 获取密码加密后的字符串
  42. * @param string $password 密码
  43. * @param string $salt 密码盐
  44. * @return string
  45. */
  46. public function getEncryptPassword($password, $salt = '')
  47. {
  48. return md5(md5($password) . $salt);
  49. }
  50. //详情
  51. public function info(){
  52. $id = input('id',0);
  53. $info = Db::name('company_staff')->field('id,company_id,truename,mobile')->where('id',$id)->find();
  54. $this->success(1,$info);
  55. }
  56. //编辑
  57. public function edit(){
  58. $id = input('id',0);
  59. $data = [
  60. 'truename' => input('truename',''),
  61. 'mobile' => input('mobile',''),
  62. ];
  63. //密码
  64. $password = input('password','123456');
  65. $salt = Random::alnum();
  66. $newpassword = $this->getEncryptPassword($password, $salt);
  67. $data['password'] = $newpassword;
  68. $data['salt'] = $salt;
  69. //检查
  70. $check2 = Db::name('company_staff')->where('id','neq',$id)->where('mobile',$data['mobile'])->find();
  71. if($check2){
  72. $this->error('该手机已经被注册为员工或商户管理员');
  73. }
  74. Db::name('company_staff')->where('id',$id)->update($data);
  75. $this->success('编辑成功');
  76. }
  77. }