User.php 3.4 KB

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