UserController.php 6.5 KB

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