UserController.php 6.9 KB

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