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; if (getenv('YII_ENV') != 'dev' && $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(); // 同步变更客户表(xhCustom)中的数据 $customList = \bizMall\custom\classes\CustomClass::getAllByCondition(['userId' => $user->id], 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(); //变更客户生日的同时,同步清空含对应客户的门店的缓存 BirthdayGiftClass::clearWorkbenchSummaryCache($custom->shopId); } } // 同步变更生日赠礼记录表(xhBirthdayGift)中的数据(只更新当年年份的,往年的不去修改) $birthdayGiftList = BirthdayGiftClass::getAllByCondition(['userId' => $user->id, 'year' => date("Y")], null, '*', null, true); if (!empty($birthdayGiftList)) { foreach ($birthdayGiftList as $birthdayGift) { list($giftBirthdayMonth, $giftBirthdayDate) = BirthdayGiftClass::convertBirthdayMonthDay( $lunar, $birthdayMonth, $birthdayDate ); $birthdayGift->lunar = $lunar; $birthdayGift->birthdayMonth = $giftBirthdayMonth; $birthdayGift->birthdayDate = $giftBirthdayDate; $birthdayGift->birthdayDisplay = BirthdayGiftClass::formatBirthdayDisplay($custom, $giftBirthdayMonth, $giftBirthdayDate); $birthdayGift->status = 1; $birthdayGift->save(); } } util::complete('修改成功'); } //获取当前登录用户的信息 ssh 20221014 public function actionCurrentInfo() { $user = $this->user; if (!empty($user)) { $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; if ($userId > 0) { $mallUpgrading = getenv('MALL_UPGRADING') == false ? 0 : getenv('MALL_UPGRADING'); if ($mallUpgrading == 1) { $allowShopAdminIdsStr = getenv('MALL_UPGRADE_ALLOW_USER_IDS') ?: ''; $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : []; if (!in_array($userId, $allowShopAdminIds)) { util::fail('系统升级中,稍后再试,编号:' . $userId); } } } $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; if ($userId > 0) { $mallUpgrading = getenv('MALL_UPGRADING') == false ? 0 : getenv('MALL_UPGRADING'); if ($mallUpgrading == 1) { $allowShopAdminIdsStr = getenv('MALL_UPGRADE_ALLOW_USER_IDS') ?: ''; $allowShopAdminIds = !empty($allowShopAdminIdsStr) ? explode(',', $allowShopAdminIdsStr) : []; if (!in_array($userId, $allowShopAdminIds)) { util::fail('系统升级中,稍后再试,编号:' . $userId); } } } $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) { // 记录详细日志以便排查。常见错误:-41003(AES解密失败/sessionKey过期) Yii::info("小程序获取用户信息解密失败:errCode={$errCode}, miniOpenId={$miniOpenId}, appId={$appId}"); util::fail("获取用户信息失败(code:{$errCode})"); } 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) { // 记录详细日志以便排查。常见错误:-41003(AES解密失败/sessionKey过期) Yii::info("小程序手机号解密失败:errCode={$errCode}, miniOpenId={$miniOpenId}, appId={$appId}"); noticeUtil::push("小程序手机号解密失败:errCode={$errCode}, miniOpenId={$miniOpenId}, appId={$appId}", '15280215347'); util::fail("解密失败(code:{$errCode}),请尝试重新登录或重试"); } $arr = Json::decode($result); $mobile = $arr['purePhoneNumber'] ?? ''; if (empty($mobile)) { util::fail('没有取到手机号,请重试'); } util::success(['mobile' => $mobile]); } //小程序获取手机号新接口 ssh 2025.07.28 //接口文档:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/user-info/phone-number/getPhoneNumber.html public function actionGetMiniMobile() { $post = Yii::$app->request->post(); $code = $post['code'] ?? ''; if (empty($code)) { util::fail('参数错误:缺少code'); } // 使用 miniUtil 封装好的方法获取手机号 (ptStyle=3 表示商城端) $merchant = WxOpenClass::getMallWxMiniBase(); $res = miniUtil::getPhoneNumber($merchant, $code, 3); if (isset($res['errcode']) && $res['errcode'] == 0) { $mobile = $res['phone_info']['purePhoneNumber'] ?? ''; if (empty($mobile)) { util::fail('获取手机号内容为空'); } util::success(['mobile' => $mobile]); } else { $errMsg = $res['errmsg'] ?? '获取手机号失败'; $errCode = $res['errcode'] ?? -1; Yii::info("小程序新接口获取手机号失败:code={$errCode}, msg={$errMsg}"); noticeUtil::push("小程序新接口获取手机号失败:code={$errCode}, msg={$errMsg}", '15280215347'); util::fail("获取手机号失败:{$errMsg}({$errCode})"); } } //密码修改 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); } //成长值列表 public function actionGrowthList() { $where = []; $where['shopId'] = $this->shopId; $where['userId'] = $this->userId; $list = UserGrowthClass::getGrowthList($where); util::success($list); } //积分列表 public function actionIntegralList() { $where = []; $where['shopId'] = $this->shopId; $where['userId'] = $this->userId; $list = UserIntegralClass::getIntegralList($where); util::success($list); } }