User.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\api\controller\company;
  3. use app\common\controller\Apic;
  4. use app\common\library\Sms;
  5. use fast\Random;
  6. use think\Config;
  7. use think\Validate;
  8. use think\Db;
  9. /**
  10. * 会员接口
  11. */
  12. class User extends Apic
  13. {
  14. protected $noNeedLogin = ['accountlogin','resetpwd'];
  15. protected $noNeedRight = '*';
  16. public function _initialize()
  17. {
  18. parent::_initialize();
  19. }
  20. //员工手机+密码登录
  21. public function accountlogin(){
  22. $mobile = $this->request->post('mobile');
  23. $password = $this->request->post('password');
  24. if (!$mobile || !$password) {
  25. $this->error(__('Invalid parameters'));
  26. }
  27. $ret = $this->auth->login($mobile, $password);
  28. if ($ret) {
  29. $data = $this->auth->getUserinfo();
  30. $this->success(__('Logged in successful'), $data);
  31. } else {
  32. $this->error($this->auth->getError());
  33. }
  34. }
  35. /**
  36. * 退出登录
  37. * @ApiMethod (POST)
  38. */
  39. public function logout()
  40. {
  41. if (!$this->request->isPost()) {
  42. $this->error(__('Invalid parameters'));
  43. }
  44. $this->auth->logout();
  45. $this->success(__('Logout successful'));
  46. }
  47. //用户详细资料
  48. public function getUserinfo($type = 1){
  49. $info = $this->auth->getUserinfo();
  50. if($type == 'return'){
  51. return $info;
  52. }
  53. $this->success(__('success'),$info);
  54. }
  55. /**
  56. * 重置密码
  57. *
  58. * @ApiMethod (POST)
  59. * @param string $mobile 手机号
  60. * @param string $captcha 验证码
  61. * @param string $newpassword 新密码
  62. */
  63. public function resetpwd()
  64. {
  65. $mobile = $this->request->post('mobile');
  66. $captcha = $this->request->post('captcha');
  67. $newpassword = $this->request->post("newpassword");
  68. if (!$mobile || !$captcha || !$newpassword) {
  69. $this->error(__('Invalid parameters'));
  70. }
  71. //验证Token
  72. if (!Validate::make()->check(['newpassword' => $newpassword], ['newpassword' => 'require|regex:\S{6,30}'])) {
  73. $this->error(__('Password must be 6 to 30 characters'));
  74. }
  75. if (!Validate::regex($mobile, "^1\d{10}$")) {
  76. $this->error(__('Mobile is incorrect'));
  77. }
  78. $user = \app\common\model\CompanyStaff::getByMobile($mobile);
  79. if (!$user) {
  80. $this->error(__('User not found'));
  81. }
  82. $ret = Sms::check($mobile, $captcha, 'resetpwd');
  83. if (!$ret) {
  84. $this->error(__('Captcha is incorrect'));
  85. }
  86. Sms::flush($mobile, 'resetpwd');
  87. //模拟一次登录
  88. $this->auth->direct($user->id);
  89. $ret = $this->auth->resetpwd($newpassword, '', true);
  90. if ($ret) {
  91. $this->success(__('Reset password successful'));
  92. } else {
  93. $this->error($this->auth->getError());
  94. }
  95. }
  96. /**
  97. * 修改会员个人信息
  98. *
  99. * @ApiMethod (POST)
  100. * @param string $avatar 头像地址
  101. * @param string $username 用户名
  102. * @param string $nickname 昵称
  103. * @param string $bio 个人简介
  104. */
  105. public function profile()
  106. {
  107. //检查
  108. $check = Db::name('company')->where('id',$this->auth->id)->find();
  109. if($check['status'] == 1){
  110. $this->success('资料审核通过后需联系客服修改');
  111. }
  112. $field = [
  113. 'company_name',
  114. 'company_code',
  115. 'company_registerdate',
  116. 'company_address',
  117. 'company_image',
  118. 'truename',
  119. 'idcard',
  120. 'idcard_images',
  121. 'bank_name',
  122. 'bank_branchname',
  123. 'bank_account',
  124. 'bank_card',
  125. ];
  126. $data = request_post_hub($field);
  127. $data['status'] = 0;
  128. $update_rs = Db::name('company')->where('id',$this->auth->id)->update($data);
  129. $this->success('资料更新完成');
  130. }
  131. }