UserController.php 6.4 KB

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