Commit f36ee9e6 authored by hujun's avatar hujun

咨询经纪人V2

parent 1512f5d3
...@@ -111,6 +111,84 @@ class Broker extends Basic ...@@ -111,6 +111,84 @@ class Broker extends Basic
return $this->response($data['status'], $data['msg'], $data['data']); return $this->response($data['status'], $data['msg'], $data['data']);
} }
/**
* 咨询经纪人
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function indexV2()
{
header('Access-Control-Allow-Origin:*');
if (empty($this->params['house_id'])) {
$this->response(101, '参数错误');
}
$data['status'] = 101;
$data['data'] = $list = [];
$data['msg'] = '';
$agents = new AAgents();
$m_march = new OMarchInModel();
$m_evaluate = new Evaluate();
//查找30天带看最多的人
$report_fields = 'a.reception_id';
$report_where['b.house_id'] = $this->params['house_id'];
$report_where['a.create_time'] = ['between', [date('Y-m-d', strtotime("-30 day")) . ' 00:00:00', date('Y-m-d').' 23:59:59']];
$reception_id = $m_march->getMaxMarchInAgent($report_fields, $report_where);
$fields_agent = 'id,name,img,phone';
if (!empty($reception_id['reception_id'])) {
$march_agent = $agents->findByOne($fields_agent, [ 'id' => $reception_id['reception_id']]);
if (!empty($march_agent)){
$list[0] = $march_agent;
$list[0]['show_content'] = '我对本铺非常了解,最近带看本铺多次';
}
}
$fields = 'a.id,a.name,a.img,a.phone';
//客方
if (!empty($this->userId)) {
$client = $agents->getAgentUser($fields, [ 'a.id' => $this->userId, 'b.agent_id'=>['neq', $list[0]['id']]]); //客方
if (!empty($client)){
$list[1] = $client;
$list[1]['show_content'] = '帮助客户找更多,善于了解客户需求';
}
}
//独家方
$where['b.houses_id'] = $this->params['house_id'];
$where['b.is_del'] = $where['a.status'] = 0;
$where['a.id'] = ['not in', [$list[0]['id'], $list[2]['id']]];
$where['b.type'] = 3;
$house_agent = $agents->getAgentHouseType($fields, $where);
if (!empty($house_agent)){
$list[2] = $house_agent;
$list[2]['show_content'] = '本铺由我登记,熟悉房源信息';
}
foreach ($list as $k => $v) {
$list[$k]['head_portrait'] = AGENTHEADERIMGURL . $v['img'];
$evaluate_data = $m_evaluate->getAgentEvaluateFraction('count(id) as evaluate,sum(evaluate_grade) as evaluate_grade', ['agents_id'=>$v['id']]);
if ($evaluate_data[0]['evaluate_grade']) {
$evaluate_grade = floor(($evaluate_data[0]['evaluate_grade'] / 2) / $evaluate_data[0]['evaluate']);
} else {
$evaluate_grade = 0;
}
$list[$k]['evaluate_grade'] = $evaluate_grade;
$list[$k]['evaluate'] = $evaluate_data[0]['evaluate'];
unset($list[$k]['img']);
}
$data['data']['list'] = $list;
$data['status'] = 200;
return $this->response($data['status'], $data['msg'], $data['data']);
}
/** /**
* 评价经纪人 * 评价经纪人
* *
......
<?php <?php
namespace app\api\extend; namespace app\api\extend;
/** /**
* Created by PhpStorm. * Created by PhpStorm.
* User: zw * User: zw
* Date: 2017/12/4 * Date: 2017/12/4
* Time: 9:35 * Time: 9:35
* 基类 * 基类
*/ */
use app\extra\RedisExt; use app\extra\RedisExt;
use app\model\Users; use app\model\Users;
use think\Controller; use think\Controller;
use think\Exception; use think\Exception;
use Think\Log; use Think\Log;
use think\Request; use think\Request;
use think\Response; use think\Response;
use Qiniu; use Qiniu;
use UnexpectedValueException; use UnexpectedValueException;
use InvalidArgumentException; use InvalidArgumentException;
class Basic extends Controller class Basic extends Controller
{ {
/** /**
* 访问请求对象 * 访问请求对象
* @var Request * @var Request
*/ */
public $request; public $request;
public $params; public $params;
public $user_city; public $user_city;
protected $authToken; protected $authToken;
/** /**
* @var int userId * @var int userId
*/ */
protected $userId; protected $userId;
protected $userNick; protected $userNick;
protected $phone; protected $phone;
protected $timeStamp_; protected $timeStamp_;
protected $filterVerify = array( protected $filterVerify = array(
"api/getShopList", "api/getShopList",
"api/sendSms", "api/sendSms",
"api/sendCode", "api/sendCode",
"api/userVerify", "api/userVerify",
"api/saveWxInfo", "api/saveWxInfo",
"api/logout", "api/logout",
"api/login", "api/login",
"api/register", "api/register",
"api/shopList", "api/shopList",
"api/filtrateCondition", "api/filtrateCondition",
"api/filtrateConditionV2", "api/filtrateConditionV2",
"api/getShopDetail", "api/getShopDetail",
"api/bannerList", "api/bannerList",
"api/averagePriceAndTurnover", "api/averagePriceAndTurnover",
"api/getBroker", "api/getBroker",
"api/brokerDetail", "api/getBrokerV2",
"api/commentAndDeal", "api/brokerDetail",
"api/check_code", "api/commentAndDeal",
"api/convertOrderByTime", "api/check_code",
"api/convertMarchIn", "api/convertOrderByTime",
"api/convertCollectingBill", "api/convertMarchIn",
"api/getVersionNo", "api/convertCollectingBill",
"api/getVersionNoV2", "api/getVersionNo",
"api/getMarchInList", "api/getVersionNoV2",
"api/addSublet", "api/getMarchInList",
"api/getSiteListApp", "api/addSublet",
"api/recordCallNumShare", "api/getSiteListApp",
"api/addUserCallAgentV2" "api/recordCallNumShare",
); "api/addUserCallAgentV2"
);
/**
* 基础接口SDK /**
* @param Request|null $request * 基础接口SDK
*/ * @param Request|null $request
public function __construct(Request $request = null) */
{ public function __construct(Request $request = null)
// CORS 跨域 Options 检测响应 {
$this->corsOptionsHandler(); // CORS 跨域 Options 检测响应
// 输入对象 $this->corsOptionsHandler();
$this->request = is_null($request) ? Request::instance() : $request; // 输入对象
$this->request = is_null($request) ? Request::instance() : $request;
if (strtoupper($this->request->method()) === "GET") {
$this->params = $this->request->param(); if (strtoupper($this->request->method()) === "GET") {
} elseif (strtoupper($this->request->method()) === "POST") { $this->params = $this->request->param();
$this->params = $this->request->param() != null ? $this->request->param() : null; } elseif (strtoupper($this->request->method()) === "POST") {
} $this->params = $this->request->param() != null ? $this->request->param() : null;
if (isset($this->params['AuthToken']) && $this->params['AuthToken'] != 'null' && !empty($this->params['AuthToken'])) { }
$jwt = new \Firebase\JWT\JWT(); if (isset($this->params['AuthToken']) && $this->params['AuthToken'] != 'null' && !empty($this->params['AuthToken'])) {
$jwt = new \Firebase\JWT\JWT();
try {
$result = $jwt->decode($this->params['AuthToken'], config('jwt_key'), array( 'HS256' )); //解码token try {
} catch( UnexpectedValueException $e) { $result = $jwt->decode($this->params['AuthToken'], config('jwt_key'), array( 'HS256' )); //解码token
echo json_encode(array( "code" => "300", "msg" => "AuthToken parameter error!", "data" => [], "type" => "json" )); } catch( UnexpectedValueException $e) {
exit; echo json_encode(array( "code" => "300", "msg" => "AuthToken parameter error!", "data" => [], "type" => "json" ));
} catch( InvalidArgumentException $e) { exit;
echo json_encode(array( "code" => "300", "msg" => "AuthToken parameter error!", "data" => [], "type" => "json" )); } catch( InvalidArgumentException $e) {
exit; echo json_encode(array( "code" => "300", "msg" => "AuthToken parameter error!", "data" => [], "type" => "json" ));
} exit;
}
$this->authToken = $this->params['AuthToken'];
$this->userId = $result->data->id; $this->authToken = $this->params['AuthToken'];
$this->phone = $result->data->phone; $this->userId = $result->data->id;
$this->userNick = isset($result->data->userNick) ? $result->data->userNick : ""; $this->phone = $result->data->phone;
$this->timeStamp_ = $result->timeStamp_; $this->userNick = isset($result->data->userNick) ? $result->data->userNick : "";
} $this->timeStamp_ = $result->timeStamp_;
}
$this->getCity($this->userId);
$this->getCity($this->userId);
$requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1];
//过滤掉不需要验证token的接口 $requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1];
if (!in_array(trim($requestPath), $this->filterVerify)) { //过滤掉不需要验证token的接口
$this->tokenVerify(); if (!in_array(trim($requestPath), $this->filterVerify)) {
} $this->tokenVerify();
} }
}
/**
* 默认城市选择 /**
* @param $userId * 默认城市选择
*/ * @param $userId
public function getCity($userId) */
{ public function getCity($userId)
if(!$userId){ {
return; if(!$userId){
} return;
try { }
$redis_ = RedisExt::getRedis(); try {
if ($redis_) { $redis_ = RedisExt::getRedis();
$city = $redis_->get("user_city_" . $userId); if ($redis_) {
$this->user_city = empty($city) ? "上海市" : $city; $city = $redis_->get("user_city_" . $userId);
} else { $this->user_city = empty($city) ? "上海市" : $city;
$this->user_city = "上海市"; } else {
} $this->user_city = "上海市";
Log::record("-------basic-------".$redis_->get("user_city_" . $userId),"info"); }
} catch (Exception $exception) { Log::record("-------basic-------".$redis_->get("user_city_" . $userId),"info");
$this->user_city = "上海市"; } catch (Exception $exception) {
} $this->user_city = "上海市";
}
}
}
/**
* token 验证 /**
*/ * token 验证
public function tokenVerify() */
{ public function tokenVerify()
if (!isset($this->params['AuthToken'])) { {
echo json_encode(array( "code" => "300", "msg" => "AuthToken不能为空!", "data" => [], "type" => "json" )); if (!isset($this->params['AuthToken'])) {
exit; echo json_encode(array( "code" => "300", "msg" => "AuthToken不能为空!", "data" => [], "type" => "json" ));
} exit;
$this->verifyUserInfo(); }
$this->verifyTime(); $this->verifyUserInfo();
} $this->verifyTime();
}
public function verifyTime()
{ public function verifyTime()
//authToken有效期为30天 {
if ((time() - $this->timeStamp_) > 2592000) { //authToken有效期为30天
echo json_encode(array( "code" => "300", "msg" => "AuthToken失效,请重新登录!", "data" => [], "type" => "json" )); if ((time() - $this->timeStamp_) > 2592000) {
exit; echo json_encode(array( "code" => "300", "msg" => "AuthToken失效,请重新登录!", "data" => [], "type" => "json" ));
} exit;
} }
}
public function verifyUserInfo()
{ public function verifyUserInfo()
$userModel = new Users(); {
$userArr = $userModel->selectUser($this->userId); $userModel = new Users();
if (count($userArr) > 0 && ($userArr["id"] != $this->userId || $userArr["user_phone"] != $this->phone)) { $userArr = $userModel->selectUser($this->userId);
echo json_encode(array( "code" => "300", "msg" => "用户验证失败,重新登录!", "data" => [], "type" => "json" )); if (count($userArr) > 0 && ($userArr["id"] != $this->userId || $userArr["user_phone"] != $this->phone)) {
exit; echo json_encode(array( "code" => "300", "msg" => "用户验证失败,重新登录!", "data" => [], "type" => "json" ));
} exit;
return true; }
} return true;
}
/**
* 输出返回数据 /**
* @param string $msg 提示消息内容 * 输出返回数据
* @param string $code 业务状态码 * @param string $msg 提示消息内容
* @param mixed $data 要返回的数据 * @param string $code 业务状态码
* @param string $type 返回类型 JSON XML * @param mixed $data 要返回的数据
* @return Response * @param string $type 返回类型 JSON XML
*/ * @return Response
public function response($code = 'SUCCESS', $msg, $data = [], $type = 'json') */
{ public function response($code = 'SUCCESS', $msg, $data = [], $type = 'json')
$result = [ 'code' => $code, 'msg' => $msg, 'data' => $data, 'type' => strtolower($type) ]; {
return Response::create($result, $type); $result = [ 'code' => $code, 'msg' => $msg, 'data' => $data, 'type' => strtolower($type) ];
} return Response::create($result, $type);
}
/**
* 一维数据数组生成数据树 /**
* @param array $list 数据列表 * 一维数据数组生成数据树
* @param string $id 父ID Key * @param array $list 数据列表
* @param string $pid ID Key * @param string $id 父ID Key
* @param string $son 定义子数据Key * @param string $pid ID Key
* @return array * @param string $son 定义子数据Key
*/ * @return array
public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub') */
{ public static function arr2tree($list, $id = 'id', $pid = 'pid', $son = 'sub')
list($tree, $map) = [ [], [] ]; {
foreach ($list as $item) { list($tree, $map) = [ [], [] ];
$map[$item[$id]] = $item; foreach ($list as $item) {
} $map[$item[$id]] = $item;
foreach ($list as $item) { }
if (isset($item[$pid]) && isset($map[$item[$pid]])) { foreach ($list as $item) {
$map[$item[$pid]][$son][] = &$map[$item[$id]]; if (isset($item[$pid]) && isset($map[$item[$pid]])) {
} else { $map[$item[$pid]][$son][] = &$map[$item[$id]];
$tree[] = &$map[$item[$id]]; } else {
} $tree[] = &$map[$item[$id]];
} }
unset($map); }
return $tree; unset($map);
} return $tree;
}
/**
* 一维数据数组生成数据树 /**
* @param array $list 数据列表 * 一维数据数组生成数据树
* @param string $id ID Key * @param array $list 数据列表
* @param string $pid 父ID Key * @param string $id ID Key
* @param string $path * @param string $pid 父ID Key
* @param string $ppath * @param string $path
* @return array * @param string $ppath
*/ * @return array
public static function arr2table(array $list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '') */
{ public static function arr2table(array $list, $id = 'id', $pid = 'pid', $path = 'path', $ppath = '')
$tree = []; {
foreach (self::arr2tree($list, $id, $pid) as $attr) { $tree = [];
$attr[$path] = "{$ppath}-{$attr[$id]}"; foreach (self::arr2tree($list, $id, $pid) as $attr) {
$attr['sub'] = isset($attr['sub']) ? $attr['sub'] : []; $attr[$path] = "{$ppath}-{$attr[$id]}";
$attr['spl'] = str_repeat("&nbsp;&nbsp;&nbsp;├&nbsp;&nbsp;", substr_count($ppath, '-')); $attr['sub'] = isset($attr['sub']) ? $attr['sub'] : [];
$sub = $attr['sub']; $attr['spl'] = str_repeat("&nbsp;&nbsp;&nbsp;├&nbsp;&nbsp;", substr_count($ppath, '-'));
unset($attr['sub']); $sub = $attr['sub'];
$tree[] = $attr; unset($attr['sub']);
if (!empty($sub)) { $tree[] = $attr;
$tree = array_merge($tree, (array)self::arr2table($sub, $id, $pid, $path, $attr[$path])); if (!empty($sub)) {
} $tree = array_merge($tree, (array)self::arr2table($sub, $id, $pid, $path, $attr[$path]));
} }
return $tree; }
} return $tree;
}
/**
* 获取数据树子ID /**
* @param array $list 数据列表 * 获取数据树子ID
* @param int $id 起始ID * @param array $list 数据列表
* @param string $key 子Key * @param int $id 起始ID
* @param string $pkey 父Key * @param string $key 子Key
* @return array * @param string $pkey 父Key
*/ * @return array
public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid') */
{ public static function getArrSubIds($list, $id = 0, $key = 'id', $pkey = 'pid')
$ids = [ intval($id) ]; {
foreach ($list as $vo) { $ids = [ intval($id) ];
if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) === intval($id)) { foreach ($list as $vo) {
$ids = array_merge($ids, self::getArrSubIds($list, intval($vo[$key]), $key, $pkey)); if (intval($vo[$pkey]) > 0 && intval($vo[$pkey]) === intval($id)) {
} $ids = array_merge($ids, self::getArrSubIds($list, intval($vo[$key]), $key, $pkey));
} }
return $ids; }
} return $ids;
}
/**
* Cors Options 授权处理 /**
*/ * Cors Options 授权处理
public static function corsOptionsHandler() */
{ public static function corsOptionsHandler()
if (request()->isOptions()) { {
header('Access-Control-Allow-Origin:*'); if (request()->isOptions()) {
header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token'); header('Access-Control-Allow-Origin:*');
header('Access-Control-Allow-Credentials:true'); header('Access-Control-Allow-Headers:Accept,Referer,Host,Keep-Alive,User-Agent,X-Requested-With,Cache-Control,Content-Type,Cookie,token');
header('Access-Control-Allow-Methods:GET,POST,OPTIONS'); header('Access-Control-Allow-Credentials:true');
header('Access-Control-Max-Age:1728000'); header('Access-Control-Allow-Methods:GET,POST,OPTIONS');
header('Content-Type:text/plain charset=UTF-8'); header('Access-Control-Max-Age:1728000');
header('Content-Length: 0', true); header('Content-Type:text/plain charset=UTF-8');
header('status: 204'); header('Content-Length: 0', true);
header('HTTP/1.0 204 No Content'); header('status: 204');
exit; header('HTTP/1.0 204 No Content');
} exit;
} }
}
/**
* Cors Request Header信息 /**
* @return array * Cors Request Header信息
*/ * @return array
public static function corsRequestHander() */
{ public static function corsRequestHander()
return [ {
'Access-Control-Allow-Origin' => '*', return [
'Access-Control-Allow-Credentials' => true, 'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS', 'Access-Control-Allow-Credentials' => true,
'Access-Defined-X-Support' => 'service@cuci.cc', 'Access-Control-Allow-Methods' => 'GET,POST,OPTIONS',
'Access-Defined-X-Servers' => 'Guangzhou Cuci Technology Co. Ltd', 'Access-Defined-X-Support' => 'service@cuci.cc',
]; 'Access-Defined-X-Servers' => 'Guangzhou Cuci Technology Co. Ltd',
} ];
}
}
}
...@@ -1576,6 +1576,9 @@ class AAgents extends BaseModel ...@@ -1576,6 +1576,9 @@ class AAgents extends BaseModel
} }
public function findByOne($field,$params) { public function findByOne($field,$params) {
if (!isset($params['status'])) {
$where['status'] = 0;
}
$result = $this $result = $this
->field($field) ->field($field)
->where($params) ->where($params)
...@@ -1590,4 +1593,37 @@ class AAgents extends BaseModel ...@@ -1590,4 +1593,37 @@ class AAgents extends BaseModel
return $return; return $return;
} }
/**
* @param $field
* @param $where
* @return array|false|\PDOStatement|string|\think\Model
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentUser($field, $where) {
$where['a.status'] = 0;
return $this->alias('a')
->field($field)
->join('u_users b','a.id = b.agent_id', 'left')
->where($where)
->find();
}
/**
* @param $field
* @param $where
* @return false|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getAgentHouseType($field, $where) {
return $this->alias('a')
->field($field)
->join('g_houses_to_agents b', 'a.id=b.agents_id', 'left')
->where($where)
->find();
}
} }
\ No newline at end of file
...@@ -430,6 +430,7 @@ Route::group('api', [ ...@@ -430,6 +430,7 @@ Route::group('api', [
//get broker //get broker
'getBroker' => ['api/broker/index', ['method' => 'get']], //获取当前商铺或街铺的经纪人评论信息列表 'getBroker' => ['api/broker/index', ['method' => 'get']], //获取当前商铺或街铺的经纪人评论信息列表
'getBrokerV2' => ['api/broker/indexV2', ['method' => 'get']], //获取当前商铺或街铺的经纪人评论信息列表
'test' => ['api/broker/testtest', ['method' => 'get']], //获取当前商铺或街铺的经纪人评论信息列表 'test' => ['api/broker/testtest', ['method' => 'get']], //获取当前商铺或街铺的经纪人评论信息列表
'commentAndDeal' => ['api/broker/commentAndDeal', ['method' => 'get']], //获取当前经纪人的评价和交易列表 'commentAndDeal' => ['api/broker/commentAndDeal', ['method' => 'get']], //获取当前经纪人的评价和交易列表
'brokerDetail' => ['api/broker/brokerDetail', ['method' => 'get']], //经纪人详情 'brokerDetail' => ['api/broker/brokerDetail', ['method' => 'get']], //经纪人详情
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment