Staff.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. //验证
  21. if($this->auth->type != 1){
  22. $this->error('只有门店老板才能设置');
  23. }
  24. $data = [
  25. 'truename' => input('truename',''),
  26. 'mobile' => input('mobile',''),
  27. 'company_id' => $this->auth->company_id,
  28. 'type' => 2,
  29. ];
  30. //密码
  31. $password = input('password','123456');
  32. $salt = Random::alnum();
  33. $newpassword = $this->getEncryptPassword($password, $salt);
  34. $data['password'] = $newpassword;
  35. $data['salt'] = $salt;
  36. //检查
  37. $check2 = Db::name('company_staff')->where('mobile',$data['mobile'])->find();
  38. if($check2){
  39. $this->error('该手机已经被注册为员工或商户管理员');
  40. }
  41. Db::name('company_staff')->insertGetId($data);
  42. $this->success('添加成功');
  43. }
  44. /**
  45. * 获取密码加密后的字符串
  46. * @param string $password 密码
  47. * @param string $salt 密码盐
  48. * @return string
  49. */
  50. public function getEncryptPassword($password, $salt = '')
  51. {
  52. return md5(md5($password) . $salt);
  53. }
  54. //详情
  55. public function info(){
  56. $id = input('id',0);
  57. $info = Db::name('company_staff')->field('id,company_id,truename,mobile')->where('id',$id)->find();
  58. $this->success(1,$info);
  59. }
  60. //编辑
  61. public function edit(){
  62. //验证
  63. if($this->auth->type != 1){
  64. $this->error('只有门店老板才能设置');
  65. }
  66. $id = input('id',0);
  67. $data = [
  68. 'truename' => input('truename',''),
  69. 'mobile' => input('mobile',''),
  70. ];
  71. //密码
  72. $password = input('password','123456');
  73. $salt = Random::alnum();
  74. $newpassword = $this->getEncryptPassword($password, $salt);
  75. $data['password'] = $newpassword;
  76. $data['salt'] = $salt;
  77. //检查
  78. $check2 = Db::name('company_staff')->where('id','neq',$id)->where('mobile',$data['mobile'])->find();
  79. if($check2){
  80. $this->error('该手机已经被注册为员工或商户管理员');
  81. }
  82. Db::name('company_staff')->where('id',$id)->update($data);
  83. $this->success('编辑成功');
  84. }
  85. }