UserController.php 6.6 KB

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