UserController.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. <?php
  2. namespace mall\controllers;
  3. use bizHd\custom\classes\CustomClass;
  4. use bizMall\merchant\services\MerchantExtendService;
  5. use bizMall\message\services\SmsService;
  6. use bizMall\user\classes\UserClass;
  7. use bizMall\user\services\UserAssetService;
  8. use bizMall\user\services\UserService;
  9. use common\components\dict;
  10. use common\components\imgUtil;
  11. use common\components\stringUtil;
  12. use Yii;
  13. use common\components\util;
  14. use yii\helpers\Json;
  15. class UserController extends BaseController
  16. {
  17. //最近店铺 ssh 2021.2.27
  18. public function actionRecentShop()
  19. {
  20. $list = UserClass::getRecentShop($this->user);
  21. //显示国兰的信息 0不是 1是
  22. $showGlInfo = getenv('SHOW_GL_INFO');
  23. $info = $showGlInfo === false ? 1 : $showGlInfo;
  24. util::success(['list' => $list, 'showGlInfo' => $info]);
  25. }
  26. //获取登陆客户的资产 ssh 2019.11.22
  27. public function actionAsset()
  28. {
  29. $asset = UserAssetService::getByUserId($this->userId);
  30. util::success($asset);
  31. }
  32. //获取登陆客户的优惠情况 ssh 2019.12.3
  33. public function actionDiscount()
  34. {
  35. $discount = UserAssetService::getDiscount($this->userId);
  36. util::success($discount);
  37. }
  38. //小程序用户完整信息 ssh 2019.12.12
  39. public function actionMiniFullInfo()
  40. {
  41. $post = Yii::$app->request->post();
  42. $iv = isset($post['iv']) ? $post['iv'] : '';
  43. $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
  44. $sjWx = $this->sjWx;
  45. $appId = $sjWx['miniAppId'];
  46. $sjId = $this->sjId;
  47. $miniOpenId = $this->user['miniOpenId'];
  48. if (empty($miniOpenId)) {
  49. util::fail('mini_open_id empty');
  50. }
  51. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  52. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  53. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  54. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  55. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  56. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  57. if ($errCode != 0) {
  58. Yii::info($result . ' ' . $errCode);
  59. util::fail('获取用户信息失败');
  60. }
  61. Yii::info('小程序获取用户信息:' . $result);
  62. $originalInfo = Json::decode($result);
  63. //新接口没有openId这边补一下,以免后面的流程报错
  64. $originalInfo['miniOpenId'] = $miniOpenId;
  65. $source = UserClass::$userSourceId['mini']['name'];
  66. $user = UserClass::replaceUser($originalInfo, $source, $sjId, $this->shopId);
  67. util::success($user);
  68. }
  69. //小程序用户手机号
  70. public function actionMiniMobile()
  71. {
  72. $post = Yii::$app->request->post();
  73. $iv = $post['iv'];
  74. $encryptedData = $post['encryptedData'];
  75. $sjWx = $this->sjWx;
  76. $appId = $sjWx['miniAppId'];
  77. $user = isset($this->user->attributes) ? $this->user->attributes : [];
  78. $miniOpenId = $user['miniOpenId'];
  79. $customId = $this->customId;
  80. $info = CustomClass::getCustomInfo($customId);
  81. if (isset($info['mobile']) && !empty($info['mobile'])) {
  82. util::success(['mobile' => $info['mobile']]);
  83. }
  84. $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
  85. $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
  86. if (empty($sessionKey)) {
  87. util::fail('系统错误,session empty');
  88. }
  89. $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
  90. require_once($wxMiniSecret . '/wxBizDataCrypt.php');
  91. $pc = new \WXBizDataCrypt($appId, $sessionKey);
  92. $errCode = $pc->decryptData($encryptedData, $iv, $result);
  93. if ($errCode != 0) {
  94. util::fail('解密失败');
  95. }
  96. $arr = Json::decode($result);
  97. $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
  98. if (empty($mobile)) {
  99. util::fail('没有取到手机号,请重试');
  100. }
  101. CustomClass::updateCustomInfo($info, ['mobile' => $mobile]);
  102. util::success(['mobile' => $mobile]);
  103. }
  104. //密码修改
  105. public function actionPassword()
  106. {
  107. $post = Yii::$app->request->post();
  108. $old = isset($post['old']) ? $post['old'] : '';
  109. $new = isset($post['new']) ? $post['new'] : '';
  110. $confirm = isset($post['confirm']) ? $post['confirm'] : '';
  111. if (empty($new)) {
  112. util::fail('请输入新密码');
  113. }
  114. if ($new != $confirm) {
  115. util::fail('二次密码不一致');
  116. }
  117. $userId = $this->userId;
  118. $user = UserService::getUserInfo($userId);
  119. if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
  120. if (empty($old)) {
  121. util::fail('请填写旧密码');
  122. }
  123. if (password_verify($old, $user['payPassword']) == false) {
  124. util::fail('旧密码错误');
  125. }
  126. }
  127. UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
  128. util::complete('修改成功');
  129. }
  130. //申请会员 ssh 2019.12.18
  131. public function actionApplyMember()
  132. {
  133. $post = Yii::$app->request->post();
  134. $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
  135. if (stringUtil::isMobile($mobile) == false) {
  136. util::fail('请输入手机号');
  137. }
  138. $userId = $this->userId;
  139. $asset = UserAssetService::getByUserId($userId);
  140. if (isset($asset['member']) && $asset['member'] != -1) {
  141. util::fail('已经是会员了');
  142. }
  143. $code = isset($post['code']) ? $post['code'] : '';
  144. $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
  145. if (empty($cacheCode) || $cacheCode != $code) {
  146. util::fail('验证码错误');
  147. }
  148. $update = [];
  149. if (isset($post['realName']) && !empty($post['realName'])) {
  150. $update['realName'] = $post['realName'];
  151. }
  152. if (isset($post['birthday']) && !empty($post['birthday'])) {
  153. $update['birthday'] = $post['birthday'];
  154. }
  155. $user = UserService::getByCondition(['sjId' => $this->sjId, 'mobile' => $mobile]);
  156. if ($userId == $user['id']) {
  157. util::fail('手机号已验证');
  158. }
  159. if (!empty($user)) {
  160. util::fail('手机号已经注册过了');
  161. }
  162. $update['mobile'] = $mobile;
  163. $userInfo = isset($this->user->attributes) ? $this->user->attributes : [];
  164. UserService::becomeMember($userInfo, $this->sj->attributes, $update);
  165. util::complete('注册成功');
  166. }
  167. //登陆客户的信息 ssh 2020.3.12
  168. public function actionLoginDetail()
  169. {
  170. $user = isset($this->user->attributes) ? $this->user->attributes : [];
  171. util::success($user);
  172. }
  173. }