| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202 |
- <?php
- namespace mall\controllers;
- use bizHd\custom\classes\CustomClass;
- use bizMall\merchant\services\MerchantExtendService;
- use bizMall\message\services\SmsService;
- use bizMall\user\classes\UserClass;
- use bizMall\user\services\UserAssetService;
- use bizMall\user\services\UserService;
- use common\components\imgUtil;
- use common\components\stringUtil;
- use Yii;
- use common\components\util;
- use yii\helpers\Json;
- class UserController extends BaseController
- {
- public $guestAccess = ['recent-shop'];
- //最近店铺 ssh 2021.2.27
- public function actionRecentShop()
- {
- $list = UserClass::getRecentShop($this->user);
- //1 显示最近访问的店铺 0不显示
- util::success(['list' => $list, 'showIndex' => 0]);
- }
- //获取登陆客户的资产 ssh 2019.11.22
- public function actionAsset()
- {
- $asset = UserAssetService::getByUserId($this->userId);
- util::success($asset);
- }
- //获取登陆客户的优惠情况 ssh 2019.12.3
- public function actionDiscount()
- {
- $discount = UserAssetService::getDiscount($this->userId);
- util::success($discount);
- }
- //小程序用户完整信息 ssh 2019.12.12
- public function actionMiniFullInfo()
- {
- $post = Yii::$app->request->post();
- $iv = isset($post['iv']) ? $post['iv'] : '';
- $encryptedData = isset($post['encryptedData']) ? $post['encryptedData'] : '';
- $appId = $this->sj['miniAppId'];
- $sjId = $this->sjId;
- $miniOpenId = $this->user['miniOpenId'];
- if (empty($miniOpenId)) {
- util::fail('mini_open_id empty');
- }
- $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- Yii::info($result . ' ' . $errCode);
- util::fail('获取用户信息失败');
- }
- Yii::info('小程序获取用户信息:' . $result);
- $originalInfo = Json::decode($result);
- $source = UserClass::$userSourceId['mini']['name'];
- $user = UserClass::replaceUser($originalInfo, $source, $sjId);
- $userId = $user['id'];
- $userInfo = UserService::getUserInfo($userId);
- util::success($userInfo);
- }
- //小程序用户手机号
- public function actionMiniMobile()
- {
- $post = Yii::$app->request->post();
- $iv = $post['iv'];
- $encryptedData = $post['encryptedData'];
- $sjWx = $this->sjWx;
- $appId = $sjWx['miniAppId'];
- $user = $this->user;
- $miniOpenId = $user['miniOpenId'];
- $customId = $this->customId;
- $info = CustomClass::getCustomInfo($customId);
- if (isset($info['mobile']) && !empty($info['mobile'])) {
- util::success(['mobile' => $info['mobile']]);
- }
- $cacheKey = 'MALL_MINI_SESSION_KEY_' . $miniOpenId;
- $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]);
- if (empty($sessionKey)) {
- util::fail('系统错误,session empty');
- }
- $wxMiniSecret = Yii::getAlias("@vendor/weixinMiniSecret");
- require_once($wxMiniSecret . '/wxBizDataCrypt.php');
- $pc = new \WXBizDataCrypt($appId, $sessionKey);
- $errCode = $pc->decryptData($encryptedData, $iv, $result);
- if ($errCode != 0) {
- util::fail('解密失败');
- }
- $arr = Json::decode($result);
- $mobile = isset($arr['purePhoneNumber']) ? $arr['purePhoneNumber'] : '';
- if (empty($mobile)) {
- util::fail('没有取到手机号,请重试');
- }
- CustomClass::updateCustomInfo($info, ['mobile' => $mobile]);
- util::success(['mobile' => $mobile]);
- }
- //密码修改
- public function actionPassword()
- {
- $post = Yii::$app->request->post();
- $old = isset($post['old']) ? $post['old'] : '';
- $new = isset($post['new']) ? $post['new'] : '';
- $confirm = isset($post['confirm']) ? $post['confirm'] : '';
- if (empty($new)) {
- util::fail('请输入新密码');
- }
- if ($new != $confirm) {
- util::fail('二次密码不一致');
- }
- $userId = $this->userId;
- $user = UserService::getUserInfo($userId, false);
- if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) {
- if (empty($old)) {
- util::fail('请填写旧密码');
- }
- if (password_verify($old, $user['payPassword']) == false) {
- util::fail('旧密码错误');
- }
- }
- UserService::updateById($userId, ['payPassword' => password_hash($new, PASSWORD_BCRYPT), 'hasPayPwd' => 1]);
- util::complete('修改成功');
- }
- //申请会员 ssh 2019.12.18
- public function actionApplyMember()
- {
- $post = Yii::$app->request->post();
- $mobile = isset($post['mobile']) ? $post['mobile'] : 0;
- if (stringUtil::isMobile($mobile) == false) {
- util::fail('请输入手机号');
- }
- $userId = $this->userId;
- $asset = UserAssetService::getByUserId($userId);
- if (isset($asset['member']) && $asset['member'] != -1) {
- util::fail('已经是会员了');
- }
- $code = isset($post['code']) ? $post['code'] : '';
- $cacheCode = SmsService::getApplyMemberCode($userId, $mobile);
- if (empty($cacheCode) || $cacheCode != $code) {
- util::fail('验证码错误');
- }
- $update = [];
- if (isset($post['realName']) && !empty($post['realName'])) {
- $update['realName'] = $post['realName'];
- }
- if (isset($post['birthday']) && !empty($post['birthday'])) {
- $update['birthday'] = $post['birthday'];
- }
- $user = UserService::getByCondition(['merchantId' => $this->sjId, 'mobile' => $mobile]);
- if ($userId == $user['id']) {
- util::fail('手机号已验证');
- }
- if (!empty($user)) {
- util::fail('手机号已经注册过了');
- }
- $update['mobile'] = $mobile;
- UserService::becomeMember($this->user, $this->sj, $update);
- util::complete('注册成功');
- }
- //用户基本信息和资产 ssh 2019.12.19
- public function actionMyProfile()
- {
- $custom = $this->custom;
- $growth = $custom['growth'] ?? 0;
- $extend = $this->sjExtend;
- $grade = MerchantExtendService::getGradeList($extend, 'asc');
- //下个等级的积分
- $nextLevelGrowth = 0;
- foreach ($grade as $val) {
- $currentGrowth = $val['growth'];
- if ($currentGrowth > $growth) {
- $nextLevelGrowth = $currentGrowth;
- break;
- }
- }
- $custom['userAsset']['nextLevelGrowth'] = $nextLevelGrowth;
- util::success($custom);
- }
- //登陆客户的信息 ssh 2020.3.12
- public function actionLoginDetail()
- {
- $user = $this->user;
- util::success($user);
- }
- }
|