userId); util::success($asset); } //获取登陆客户的优惠情况 shish 2019.12.3 public function actionDiscount() { $userId = Yii::$app->params['userId']; $discount = UserAssetService::getDiscount($userId); util::success($discount); } //小程序用户完整信息 shish 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->merchant['miniAppId']; $merchantId = $this->merchantId; $miniOpenId = $this->user['miniOpenId']; if (empty($miniOpenId)) { util::fail('mini_open_id empty'); } $cacheKey = '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 = UserService::$userSourceId['mini']['name']; $user = UserService::replaceUser($originalInfo, $source, $merchantId); $userId = $user['id']; $userInfo = UserService::getUserInfo($userId); util::success($userInfo); } //小程序用户手机号 public function actionMiniMobile() { $post = Yii::$app->request->post(); $iv = $post['iv']; $encryptedData = $post['encryptedData']; $merchantId = $this->merchantId; $merchant = $this->merchant; $appId = $merchant['miniAppId']; $miniOpenId = $this->user['miniOpenId']; $user = $this->user; if (!empty($user) && !empty($user['mobile'])) { $userId = $user['id']; UserService::updateById($userId, ['isMember' => 1]); UserAssetService::updateByUserId($userId, ['isMember' => 1]); util::successInfo('操作成功', 'A0001', ['mobile' => $user['mobile']]); } $cacheKey = 'MINI_SESSION_KEY_' . $miniOpenId; $sessionKey = Yii::$app->redis->executeCommand('GET', [$cacheKey]); if (empty($sessionKey)) { util::fail('sesstion key 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'] : ''; $userId = $user['id']; /**升级成为会员**/ UserService::upgradeToMember($userId, $merchantId, ['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('二次密码不一致'); } $user = $this->user; $userId = $this->userId; if (!empty($user['password'])) { if (empty($old)) { util::fail('请填写旧密码'); } if (password_verify($old, $user['password']) == false) { util::fail('旧密码错误'); } } UserService::updateById($userId, ['password' => password_hash($new, PASSWORD_BCRYPT)]); util::ok('修改成功'); } //申请会员 shish 2019.12.18 public function actionApplyMember() { $post = Yii::$app->request->post(); $mobile = isset($post['mobile']) ? $post['mobile'] : 0; if (stringUtil::isMobieNumber($mobile) == false) { util::fail('请输入手机号'); } $user = $this->user; if (isset($user['isMember']) && $user['isMember'] == 1) { util::fail('已经是会员了'); } $userId = $this->userId; $code = isset($post['code']) ? $post['code'] : ''; $cacheCode = SmsService::getApplyMemberCode($userId); 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->merchantId, 'mobile' => $mobile]); if (!empty($user)) { util::fail('手机号已经注册过了'); } $update['mobile'] = $mobile; UserService::upgradeToMember($userId, $this->merchantId, $update); util::ok('注册成功'); } }