db()->alias('d') ->join($userInfo->getTableName() . ' u', 'u.id = d.uid'); // 首次进藏 if ($isFirst != self::AllData) { $model->where('is_first_to_tibet', $isFirst); } // 性别 if ($gender != self::AllData) { $model->where('gender', $gender); } // 性别 if ($province != self::AllData) { $model->where('province', $province); } // 性别 if ($city != self::AllData) { $model->where('city', $city); } if (!empty($name)) { //, ['name' => ""] $model->where("(u.nickname LIKE '%{$name}%' OR d.realname LIKE '%{$name}%')"); } $dataArray = $model->limit(($page - 1) * $pageSize, $pageSize)// 分页 ->field('u.nickname,u.open_id,u.avatarUrl,d.*')// 查询字段 ->select()->toArray(); // 获取结果 $count = $model->limit(0,1)->count(); // 查询总数 self::parseArray($dataArray); return ListCountData::Create($count, $dataArray); } public function getSearchModel(){ } private static function parseArray(&$dataArray) { $userData = Config::get('app.user.subject'); foreach ($dataArray as $key => &$item) { // $item['is_first_to_tibet'] = $item['is_first_to_tibet'] == 1 ? '是' : '否'; $item['smoke'] = $userData['smoke'][$item['smoke']]; $item['medical_history'] = empty($item['medical_history']) ? [] : self::getDataFromArray( $userData['medical_history'], explode(',', $item['medical_history']) ); } } private static function getDataFromArray(array $data, array $keys) { foreach ($keys as $key => $v) { $keys[$key] = $data[$v]; } return $keys; } public static function getSessionByCode(string $code): array { $wechat = new WechatUtil(); $session = $wechat->codeToSession($code); if (isset($session['errcode']) && $session['errcode'] != 0) { throw new \Exception($session['errmsg'], ErrorCode::User_Login_Fail); } return $session; } /** * 更新数据 * @param $data * @param UserInfo $userInfo * @return UserDetail|array|null|\think\Model * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ public static function saveDetail($data, UserInfo $userInfo) { $detail = UserDetail::where('uid', $userInfo->id)->find(); $data['uid'] = $userInfo->id; if (empty($detail)) { $detail = UserDetail::create($data); } else { $detail = UserDetail::update($data, ['uid' => $userInfo->id]); } return $detail; } }