user; $user->miniOpenId = ''; $user->save(); util::complete(); } //修改信息 ssh 20221015 public function actionUpdate() { $post = Yii::$app->request->post(); $user = $this->user; if (empty($user)) { util::fail('请先登录'); } $userId = $user->id ?? 0; $address = $post['address'] ?? ''; $floor = $post['floor'] ?? ''; $fullAddress = $address . $floor; $post['fullAddress'] = $fullAddress; UserClass::updateUserInfo($user, $post); util::complete(); } //修改生日 ssh 20250830 public function actionModifyBirthday() { date_default_timezone_set('PRC'); $get = Yii::$app->request->get(); $lunar = $get['lunar'] ?? 0; $birthdayMonth = $get['birthdayMonth'] ?? 1; if ($birthdayMonth > 12 || $birthdayMonth < 1) { util::fail('月份必须1到12月'); } $birthdayDate = $get['birthdayDate'] ?? 1; if ($birthdayDate > 31 || $birthdayDate < 1) { util::fail('日期必须1到31号'); } if ($lunar == 1 && $birthdayDate == 31) { util::fail('农历没有31号'); } $user = $this->user; $userId = $this->userId; if ($user->birthdaySet == 1) { util::fail('你已经设置过了'); } if ($lunar == 1) { try { //农历转阳历,有多处使用,需要同步修改,关键词change_my_birthday $calendar = new Calendar(); $result = $calendar->lunar(date("Y"), $birthdayMonth, $birthdayDate); $month = $result['gregorian_month'] ?? 1; $date = $result['gregorian_day'] ?? 1; $birthday = date("Y") . '-' . $month . '-' . $date; } catch (\InvalidArgumentException $e) { $msg = $e->getMessage(); $birthday = '0000-00-00 00:00:00'; util::fail($msg); } } else { $birthday = date("Y") . '-' . $birthdayMonth . '-' . $birthdayDate; } $birthdayTime = strtotime($birthday); $user->lunar = $lunar; $user->birthdayDate = $birthdayDate; $user->birthdayMonth = $birthdayMonth; $user->birthday = $birthday; $user->birthdayTime = $birthdayTime; $user->birthdaySet = 1; $user->save(); $userId = $user->id; $customList = \bizMall\custom\classes\CustomClass::getAllByCondition(['userId' => $userId], null, '*', null, true); if (!empty($customList)) { foreach ($customList as $custom) { $custom->lunar = $lunar; $custom->birthdayDate = $birthdayDate; $custom->birthdayMonth = $birthdayMonth; $custom->birthday = $birthday; $custom->birthdayTime = $birthdayTime; $custom->save(); } } util::complete('修改成功'); } //获取当前登录用户的信息 ssh 20221014 public function actionCurrentInfo() { $user = $this->user; if (!empty($user)) { $birthday = $user->birthday ?? ''; //如果当年的生日时间没有更新,则需要给更新 $year = date("Y", strtotime($birthday)); $thisYear = date("Y"); if ($year != $thisYear) { $lunar = $user->lunar ?? 0; $userId = $this->userId; $birthdayMonth = $user->birthdayMonth ?? 0; $birthdayDate = $user->birthdayDate ?? 0; if ($lunar == 1 && $birthdayMonth > 0 && $birthdayDate > 0) { try { //农历转阳历,有多处使用,需要同步修改,关键词change_my_birthday $calendar = new Calendar(); $result = $calendar->lunar(date("Y"), $birthdayMonth, $birthdayDate); $month = $result['gregorian_month'] ?? 1; $date = $result['gregorian_day'] ?? 1; $birthday = date("Y") . '-' . $month . '-' . $date; $user->birthday = $birthday; $user->save(); CustomClass::updateByCondition(['userId' => $userId], ['birthday' => $birthday]); } catch (\InvalidArgumentException $e) { $msg = $e->getMessage(); noticeUtil::push("更新生日出错了呢,userId:" . $userId . ' ' . $msg, '15280215347'); } } else { $birthday = date("Y") . '-' . $birthdayMonth . '-' . $birthdayDate; $user->birthday = $birthday; $user->save(); CustomClass::updateByCondition(['userId' => $userId], ['birthday' => $birthday]); } } // 将 $user 转换为数组,然后添加 hasMap 属性(字典中的 hasMap) $user = $user->toArray(); $shortAvatar = $user['avatar'] ?? ''; $smallAvatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_130,w_130"; $avatar = imgUtil::groupImg($shortAvatar) . "?x-oss-process=image/resize,m_fill,h_700,w_700"; $user['avatar'] = $avatar; $user['smallAvatar'] = $smallAvatar; $user['shortAvatar'] = $shortAvatar; } // 补充店铺信息 $shop = []; if (!empty($this->shop)) { $intraCityRet = ShopClass::hasIntraCity($this->shop); $shop['openIntraCity'] = $intraCityRet['openIntraCity']; $shop['hcFreeKm'] = $intraCityRet['hcFreeKm']; $shop['hcMap'] = $intraCityRet['hcMap']; } util::success(['info' => $user, 'shop' => $shop]); } //使用账号登录 ssh 20220920 public function actionAccountLogin() { $getParams = Yii::$app->request->get(); $postParams = Yii::$app->request->post(); $allParams = array_merge($getParams, $postParams); $mobile = $allParams['mobile'] ?? ''; $password = $allParams['password'] ?? ''; if ($password != 'a.1234') { util::fail('密码错误'); } $user = UserClass::getByCondition(['mobile' => $mobile], true); if (empty($user)) { util::fail('账号无效'); } $userId = $user->id ?? 0; $token = !empty($userId) ? jwt::getNewToken($userId) : ''; // 将 $user 转换为数组,然后添加 hasMap 属性(字典中的 hasMap) $user = $user->toArray(); $user['hasMap'] = dict::getDict('hasMap'); util::success(['user' => $user, 'token' => $token]); } //生成用户和花店增加客户 ssh 20250307 public function actionCreate() { $post = Yii::$app->request->post(); $user = UserClass::replaceUser($post); if (!empty($this->shop)) { //花店增加客户 CustomClass::buildRelation($this->shop, $user); } $userId = $user->id ?? 0; $token = !empty($userId) ? jwt::getNewToken($userId) : ''; $fullUser = UserClass::getById($userId, true); // 将 $fullUser 转换为数组,然后添加 hasMap 属性(字典中的 hasMap) $fullUser = $fullUser->toArray(); $fullUser['hasMap'] = dict::getDict('hasMap'); util::success(['user' => $fullUser, 'token' => $token]); } //最近店铺 ssh 2021.2.27 public function actionRecentShop() { $list = []; //显示国兰的信息 0不是 1是 $showGlInfo = getenv('SHOW_GL_INFO'); $info = $showGlInfo === false ? 1 : $showGlInfo; util::success(['list' => $list, 'showGlInfo' => $info]); } //获取登陆客户的资产 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 = $post['iv'] ?? ''; $encryptedData = $post['encryptedData'] ?? ''; $merchant = WxOpenClass::getMallWxMiniBase(); $appId = $merchant['miniAppId']; $miniOpenId = $post['miniOpenId']; if (empty($miniOpenId)) { util::success(['hasNoOpenId' => 1], '登录失败'); } $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); util::success($originalInfo); } //小程序用户手机号 public function actionMiniMobile() { $post = Yii::$app->request->post(); $iv = $post['iv']; $encryptedData = $post['encryptedData']; $merchant = WxOpenClass::getMallWxMiniBase(); $appId = $merchant['miniAppId']; $miniOpenId = $post['miniOpenId']; if (empty($miniOpenId)) { util::success(['hasNoOpenId' => 1], '登录失败'); } $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 = $arr['purePhoneNumber'] ?? ''; if (empty($mobile)) { util::fail('没有取到手机号,请重试'); } util::success(['mobile' => $mobile]); } //密码修改 public function actionPassword() { $post = Yii::$app->request->post(); $old = $post['old'] ?? ''; $new = $post['new'] ?? ''; $confirm = $post['confirm'] ?? ''; if (empty($new)) { util::fail('请输入新密码'); } if ($new != $confirm) { util::fail('二次密码不一致'); } $userId = $this->userId; $user = UserService::getUserInfo($userId); if (isset($user['hasPayPwd']) && $user['hasPayPwd'] == 1) { if (empty($old)) { util::fail('请填写旧密码'); } if (!password_verify($old, $user['payPassword'])) { 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 = $post['mobile'] ?? 0; if (!stringUtil::isMobile($mobile)) { util::fail('请输入手机号'); } $userId = $this->userId; $asset = UserAssetService::getByUserId($userId); if (isset($asset['member']) && $asset['member'] != -1) { util::fail('已经是会员了'); } $code = $post['code'] ?? ''; $cacheCode = SmsService::getApplyMemberCode($userId, $mobile); if (empty($cacheCode) || $cacheCode != $code) { util::fail('验证码错误'); } $update = []; if (!empty($post['realName'])) { $update['realName'] = $post['realName']; } if (!empty($post['birthday'])) { $update['birthday'] = $post['birthday']; } $user = UserService::getByCondition(['sjId' => $this->sjId, 'mobile' => $mobile]); if ($userId == $user['id']) { util::fail('手机号已验证'); } if (!empty($user)) { util::fail('手机号已经注册过了'); } $update['mobile'] = $mobile; $userInfo = $this->user->attributes ?? []; UserService::becomeMember($userInfo, $this->sj->attributes, $update); util::complete('注册成功'); } //登陆客户的信息 ssh 2020.3.12 public function actionLoginDetail() { $user = $this->user->attributes ?? []; util::success($user); } }