userId)->where('deleted_at', 0)->count(); $orderCount = OrderModel::where('user_id', $this->userId)->where('deleted_at', 0)->count(); $user = WxUserModel::with('enterprise')->where('id', $this->userId)->first(); $user = $user ? $user->toArray() : $this->userInfo; unset($user['session_key']); return [ 'count' => $listCount, 'order_count' => $orderCount, 'user' => $user, ]; } /** * 绑定手机号 * * 优先用微信手机号快速验证的 code 换真实号码(用户填的可能是假号); * 只有客户端拿不到 code 时才退回直接写入。 */ public function bandPhone(array $params): array { $phone = trim((string) ($params['phone'] ?? '')); $phoneCode = trim((string) ($params['phone_code'] ?? '')); if ($phoneCode !== '') { $phone = WxMiniService::getInstance()->getPhoneNumber($phoneCode); } if ($phone === '') { $this->utils->errorThrow('手机号不能为空'); } WxUserModel::where('id', $this->userId)->update([ 'phone' => $phone, 'updated_at' => time(), ]); return ['phone' => $phone]; } public function updateNickName(string $nickName): array { $nickName = trim($nickName); if ($nickName === '') { $this->utils->errorThrow('昵称不能为空'); } WxUserModel::where('id', $this->userId)->update([ 'nick_name' => $nickName, 'updated_at' => time(), ]); return ['nick_name' => $nickName]; } /** * 当前用户绑定的企业资料,给企业详情页 */ public function enterprise(): array { $user = WxUserModel::with('enterprise')->where('id', $this->userId)->first(); $ent = $user['enterprise'] ?? null; if (empty($ent)) { $this->utils->errorThrow('未绑定企业'); } $row = is_array($ent) ? $ent : $ent->toArray(); $row['logo'] = \App\Service\common\MediaUrlService::getInstance()->toPublic($row['logo'] ?? ''); return $row; } }