/** * 获取智囊图列表 * @param int $mem_id 用户id * @param string $mem_mark 单点标识 * @param int $page_id 分页页码 * @param int $limit 每页条数 * @return int|array */ public function getSageList($mem_id, $mem_mark, $page_id = 1, $limit = 20) { //单点查询 $member_exists = $this->singleMember($mem_id, $mem_mark); if ($member_exists != OK) { return $member_exists; } //查询智囊 $sql = 'select mem_id,mem_head,mem_nickname,mem_answers,mem_fine from member where mem_is_sage=1 and mem_status=1 order by mem_fine desc,mem_answers desc'; $list = $this->pagination($sql, [], 'mem_id', $page_id, $limit); //处理数据 $mem_ides = ''; $data = []; if ($list['list']) { foreach ($list['list'] as $key => $val) { //智囊头像 $val['mem_head'] = Func::setImg($val['mem_head']); //反转义数据 $val['mem_nickname'] = Func::unescape($val['mem_nickname']); //用智囊id当数据键 $val['tags'] = []; $data[$val['mem_id']] = $val; //提取提问id $tmp = $key == 0 ? '' : ','; $mem_ides .= "{$tmp}{$val['mem_id']}"; } //查询智囊标签 $sql = "select p1.mem_id,p2.tag_name from tag_adept p1 inner join tag p2 on p1.tag_id=p2.tag_id where p1.mem_id in ({$mem_ides})"; $tags = $this->fetchAll($sql); if ($tags) { foreach ($tags as $val) { if (isset($data[$val['mem_id']])) { $data[$val['mem_id']]['tags'][] = $val['tag_name']; } } } } $list['list'] = $data; return $list; }
/** * 获取提问列表 * @param int $que_id 提问id * @return mixed 失败返回int,成功返回array */ public function getQuestionInfo($que_id) { //查询数据 $sql = "select p1.que_id,p1.mem_id,p1.que_content,p1.que_img,p1.que_reward,p1.que_answers,p1.que_addtime,\n p2.mem_head,p2.mem_nickname,p2.mem_rong_id\n from question p1\n inner join member p2 on p1.mem_id=p2.mem_id\n where p1.que_is_hidden=1 and p1.que_status=2 and p2.mem_status=1 and p1.que_id=?"; $question = $this->fetchOne($sql, [$que_id]); if (!$question) { return NOT_FOUND_DATA; } //查询标签 $question['tags'] = []; $sql = 'select p2.tag_name from question_tag p1 inner join tag p2 on p1.tag_id=p2.tag_id where p1.que_id=?'; $tags = $this->fetchAll($sql, [$que_id]); if ($tags) { foreach ($tags as $val) { $question['tags'][] = $val['tag_name']; } } //处理数据 $question['mem_head'] = Func::setImg($question['mem_head']); $question['mem_nickname'] = Func::unescape($question['mem_nickname']); $question['que_content'] = Func::unescape($question['que_content']); $question['que_img'] = json_decode($question['que_img'], true); if ($question['que_img']) { foreach ($question['que_img'] as $key => $val) { $question['que_img'][$key] = Func::setImg($val); } } return $question; }
/** * 手机验证码登陆 * @param string $pho_phone 手机号 * @param int $pho_code 验证码 * @param int $login_system 操作系统 * @param string $login_number 手机序列号 * @param string $mem_client_id 推送key * @return int|array */ public function codeLogin($pho_phone, $pho_code, $login_system, $login_number, $mem_client_id) { //手机验证码验证 $phone_status = $this->verifyPhoneCode($pho_phone, $pho_code); if ($phone_status != OK) { return $phone_status; } //查询用户信息 $field = 'mem_id,mem_status,mem_online,mem_mark,mem_nickname,mem_head,mem_sex,mem_is_sage,mem_questions, mem_answers,mem_fine,mem_gold,mem_on_system,mem_on_user,mem_rong_id,mem_rong_token'; $sql = "select {$field} from member where mem_phone=?"; $member = $this->fetchOne($sql, [$pho_phone]); //判断手机是否注册 if (!$member) { return NOT_FOUND_USER; } //账号状态 if ($member['mem_status'] != 1) { return USER_AUTHORITY_ERROR; } //添加登陆信息 $login_status = $this->addLoginLog($member, $login_system, $login_number, $mem_client_id); if ($login_status != OK) { return $login_status; } //销毁无用字段 unset($member['mem_status']); unset($member['mem_online']); //格式化 $member['mem_head'] = Func::setImg($member['mem_head']); //翻转义昵称 $member['mem_nickname'] = Func::unescape($member['mem_nickname']); return $member; }