Commit 02beeb11 authored by clone's avatar clone

search

parent 5c9c2e71
...@@ -13,6 +13,7 @@ use app\model\GHousesFollowUp; ...@@ -13,6 +13,7 @@ use app\model\GHousesFollowUp;
use app\model\ULabels; use app\model\ULabels;
use app\model\UPhoneFollowUp; use app\model\UPhoneFollowUp;
use app\model\UPhoneFollowUpTemporary; use app\model\UPhoneFollowUpTemporary;
use app\search\service\SearchService;
use app\task\controller\FollowUpTask; use app\task\controller\FollowUpTask;
use think\Log; use think\Log;
use think\Request; use think\Request;
...@@ -34,9 +35,9 @@ class HomePageLog extends Basic ...@@ -34,9 +35,9 @@ class HomePageLog extends Basic
function __construct(Request $request = null) function __construct(Request $request = null)
{ {
parent::__construct($request); parent::__construct($request);
$this->uPhoneFollowUpModel = new UPhoneFollowUp( $this->siteId); $this->uPhoneFollowUpModel = new UPhoneFollowUp($this->siteId);
$this->gHouseFollowUpModel = new GHousesFollowUp(); $this->gHouseFollowUpModel = new GHousesFollowUp();
$this->phoneFollowUpTemporary = new UPhoneFollowUpTemporary( $this->siteId); $this->phoneFollowUpTemporary = new UPhoneFollowUpTemporary($this->siteId);
} }
/** /**
...@@ -48,85 +49,85 @@ class HomePageLog extends Basic ...@@ -48,85 +49,85 @@ class HomePageLog extends Basic
*/ */
public function userFollowUpList() public function userFollowUpList()
{ {
$params = $this->params; $params = $this->params;
/* $params = array( /* $params = array(
"start_time" => strtotime('2018-08-14 15:47:36'), //开始时间 "start_time" => strtotime('2019-01-01 15:47:36'), //开始时间
"end_time" => strtotime('2019-01-10 15:47:36'), //结束时间 "end_time" => strtotime('2019-01-30 15:47:36'), //结束时间
//"name_or_phone" => "18112347151",//用户姓名或电话 经纪人 //"name_or_phone" => "18112347151",//用户姓名或电话 经纪人
"search_content" => "",// 搜索跟进内容 //"search_content" => "酸菜",// 搜索跟进内容
"pageNo" => 1, "pageNo" => 1,
"pageSize" => 15 "pageSize" => 15
);*/ );*/
$vrs = new VerifyRepetitionService(); $vrs = new VerifyRepetitionService();
$is_check = $vrs->followUpClick($this->agentId); $is_check = $vrs->followUpClick($this->agentId);
if($params["pageNo"] == 1 && !$is_check){ if ($params["pageNo"] == 1 && !$is_check) {
$is_bool = $vrs->getCurrTimeSection(); $is_bool = $vrs->getCurrTimeSection();
$msg = "请勿频繁请求"; $msg = "请勿频繁请求";
if($is_bool) { if ($is_bool) {
$msg = "高峰期间每10秒钟只能搜索一次(6.30-8.30)"; $msg = "高峰期间每10秒钟只能搜索一次(6.30-8.30)";
} }
return $this->response("101", $msg); return $this->response("101", $msg);
} }
if (empty($params['start_time']) || empty($params['end_time'])) { if (empty($params['start_time']) || empty($params['end_time'])) {
return $this->response("101", '请选择时间'); return $this->response("101", '请选择时间');
} }
$time = $params['end_time'] - $params['start_time'];
if ($time > 2592000 || $time < 0) {
return $this->response(101, '搜索时间不能大于30天');
}
$start_time = date("Y-m-d H:i:s", $params["start_time"]);
$start_time = date("Y-m-d H:i:s", $params["start_time"]); $end_time = date("Y-m-d H:i:s", $params["end_time"]);
$end_time = date("Y-m-d H:i:s", $params["end_time"]); $pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$field = "id,user_id,agent_id,type,content,create_time,user_status,labels_id"; $field = "id,user_id,agent_id,type,content,create_time,user_status,labels_id";
$where_ = []; $where_ = [];
$where = ' 1=1 '; $where = ' 1=1 ';
if (!empty($params["search_content"])) { if (!empty($params["search_content"])) {
$search_content = trim($params['search_content']); $search_content = trim($params['search_content']);
$where_["content"] = array( "like", "%" . $search_content . "%" ); $where_["content"] = array("like", "%" . $search_content . "%");
$where .= " AND content LIKE '%$search_content%'"; $where .= " AND content LIKE '%$search_content%'";
} }
if (!empty($params["start_time"]) && !empty($params["end_time"])) {
$time = strtotime($end_time) - strtotime($start_time);
if ($time > 2592000 || $time < 0) {
return $this->response(101, '搜索时间不能大于30天');
}
$where_["create_time"] = array( 'between', array( $start_time, $end_time ) ); $where_["create_time"] = array('between', array($start_time, $end_time));
$where .= ' AND create_time BETWEEN "'.$start_time.'" AND "'.$end_time .'"'; $where .= ' AND create_time BETWEEN "' . $start_time . '" AND "' . $end_time . '"';
}
$agentId = 0;
if (!empty($params["name_or_phone"])) { if (!empty($params["name_or_phone"])) {
if ((preg_match("/^1\d{10}$/", $params['name_or_phone']) == 1)) { $agentId = $this->getAgentInfo($params["name_or_phone"]);
$agent_params["phone"] = array( "eq", trim($params["name_or_phone"]) ); if ($agentId > 0) {
} elseif (strlen($params['name_or_phone']) >= 6) { $where_["agent_id"] = $agentId;
$agent_params["name"] = array( "like", "%" . trim($params["name_or_phone"]) . "%" ); $where .= " AND agent_id = $agentId ";
} else { } elseif ($agentId == -1) {
return $this->response("101", '手机号有误或者姓名不满两位汉字'); return $this->response("101", '手机号有误或者姓名不满两位汉字');
}
$agent_field = "id";
$model = new AAgents();
$res_a = $model->getAgentsIdsArray($agent_field, $agent_params);
if ($res_a) {
$where_["agent_id"] = [ 'in', $res_a ];
$where .= " AND agent_id in ($res_a)";
} else { } else {
return $this->response("200", "request null"); return $this->response("200", "request null");
} }
} }
$date = date("Y-m-d", time()); $date = date("Y-m-d", time());
if ($start_time >= $date && $start_time <= $date . " 23:59:59" ) { if ($start_time >= $date && $start_time <= $date . " 23:59:59") {
$result = $this->phoneFollowUpTemporary->getFollowList($pageNo, $pageSize, $order_ = 'id desc', $field, $where_); $result = $this->phoneFollowUpTemporary->getFollowList($pageNo, $pageSize, $order_ = 'id desc', $field, $where_);
} else { } else {
$result = $this->uPhoneFollowUpModel->getFollowList($pageNo, $pageSize, '',$field, $where); //走搜索
if ($agentId > 0 || !empty($params["search_content"])) {
$searchService = new SearchService();
$search_result = $searchService->searchByKeyword($params, $pageNo, $pageSize, $agentId);
$search_result = json_decode($search_result, true);
$result = $search_result["result"]["items"];
} else {
$result = $this->uPhoneFollowUpModel->getFollowList($pageNo, $pageSize, '', $field, $where);
}
}
if (count($result) <= 0) {
return $this->response("200", "request null");
} }
$clientService = new ClientService(); $clientService = new ClientService();
$m_label = new ULabels(); $m_label = new ULabels();
$label_data = $m_label->getColumn('id,name', ['type'=>1]); //获取标签 $label_data = $m_label->getColumn('id,name', ['type' => 1]); //获取标签
foreach ($result as $key => $value) { foreach ($result as $key => $value) {
$agent_params = []; $agent_params = [];
$agent_params["a.id"] = $value['agent_id']; $agent_params["a.id"] = $value['agent_id'];
...@@ -142,23 +143,38 @@ class HomePageLog extends Basic ...@@ -142,23 +143,38 @@ class HomePageLog extends Basic
$res = $ser->getExpiredTimeByUser($value['user_id']); $res = $ser->getExpiredTimeByUser($value['user_id']);
$result[$key]['is_outstrip_twenty_four_hours'] = $res ? 0 : 1; $result[$key]['is_outstrip_twenty_four_hours'] = $res ? 0 : 1;
$is_show = $clientService->dialTotal($value["user_id"]); $is_show = $clientService->dialTotal($value["user_id"]);
$result[$key]['sign_call'] = $is_show ? 0 : 1; $result[$key]['sign_call'] = $is_show ? 0 : 1;
$result[$key]['label_name'] = array_key_exists($value['labels_id'], $label_data) ? $label_data[$value['labels_id']] : ''; $result[$key]['label_name'] = array_key_exists($value['labels_id'], $label_data) ? $label_data[$value['labels_id']] : '';
} }
//$count = $this->uPhoneFollowUpModel->getSearchCount($where_); //$count = $this->uPhoneFollowUpModel->getSearchCount($where_);
if (count($result) > 0) { $list["result"] = $result;
$list["result"] = $result; $list["img_path"] = AGENTHEADERIMGURL;
$list["img_path"] = AGENTHEADERIMGURL; //暂时处理
//暂时处理 $list["total"] = 0;
$list["total"] = 0; return $this->response("200", "request success", $list);
return $this->response("200", "request success", $list); }
//获取经纪人信息
private function getAgentInfo($name_or_phone)
{
if ((preg_match("/^1\d{10}$/", $name_or_phone) == 1)) {
$agent_params["phone"] = array("eq", trim($name_or_phone));
} elseif (strlen($name_or_phone) >= 6) {
$agent_params["name"] = array("like", "%" . trim($name_or_phone) . "%");
} else { } else {
return $this->response("200", "request null"); return -1;
} }
$agent_field = "id";
$model = new AAgents();
$res_a = $model->getAgentsIdsArray($agent_field, $agent_params);
if ($res_a) {
return $res_a[0]["id"];
} else {
return 0;
}
} }
/** /**
...@@ -194,18 +210,18 @@ class HomePageLog extends Basic ...@@ -194,18 +210,18 @@ class HomePageLog extends Basic
$field = "f.id,f.house_id,f.agent_id,f.follow_up_info,f.create_time,f.agent_name as name"; $field = "f.id,f.house_id,f.agent_id,f.follow_up_info,f.create_time,f.agent_name as name";
if (!empty($params["search_content"])) { if (!empty($params["search_content"])) {
$where_["f.follow_up_info"] = array( "like", "%" . trim($params['search_content']) . "%" ); $where_["f.follow_up_info"] = array("like", "%" . trim($params['search_content']) . "%");
} }
if (!empty($params["start_time"]) && !empty($params["end_time"])) { if (!empty($params["start_time"]) && !empty($params["end_time"])) {
$start_time = date("Y-m-d H:i:s", $params["start_time"]); $start_time = date("Y-m-d H:i:s", $params["start_time"]);
$end_time = date("Y-m-d H:i:s", $params["end_time"]); $end_time = date("Y-m-d H:i:s", $params["end_time"]);
$time = strtotime($end_time) - strtotime($start_time); $time = strtotime($end_time) - strtotime($start_time);
if ($time > 2592000 || $time < 0) { if ($time > 2592000 || $time < 0) {
return $this->response(101, '搜索时间不能大于30天'); return $this->response(101, '搜索时间不能大于30天');
} }
$where_["f.create_time"] = array( 'between', array( $start_time, $end_time ) ); $where_["f.create_time"] = array('between', array($start_time, $end_time));
} }
// if (empty($params['city'])) { // if (empty($params['city'])) {
...@@ -244,18 +260,11 @@ class HomePageLog extends Basic ...@@ -244,18 +260,11 @@ class HomePageLog extends Basic
} }
if (!empty($params["name_or_phone"])) { if (!empty($params["name_or_phone"])) {
if ((preg_match("/^1\d{10}$/", $params['name_or_phone']) == 1)) { $agentId = $this->getAgentInfo($params["name_or_phone"]);
$agent_params["phone"] = array( "eq", trim($params["name_or_phone"]) ); if ($agentId > 0) {
} elseif (strlen($params['name_or_phone']) >= 6) { $where_["f.agent_id"] = $agentId;
$agent_params["name"] = array( "like", "%" . trim($params["name_or_phone"]) . "%" ); } elseif ($agentId == -1) {
} else {
return $this->response("101", '手机号有误或者姓名不满两位汉字'); return $this->response("101", '手机号有误或者姓名不满两位汉字');
}
$agent_field = "id";
$model = new AAgents();
$res_a = $model->getAgentsIdsArray($agent_field, $agent_params);
if ($res_a) {
$where_["f.agent_id"] = [ 'in', $res_a ];
} else { } else {
return $this->response("200", "request null"); return $this->response("200", "request null");
} }
......
...@@ -109,7 +109,7 @@ class Basic extends Controller ...@@ -109,7 +109,7 @@ class Basic extends Controller
$requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1]; $requestPath = $this->request->routeInfo()["rule"][0] . "/" . $this->request->routeInfo()["rule"][1];
//过滤掉不需要验证token的接口 //过滤掉不需要验证token的接口
if (!in_array(trim($requestPath), $this->filterVerify)) { if (!in_array(trim($requestPath), $this->filterVerify)) {
$this->tokenVerify(); //$this->tokenVerify();
//$this->userAuth(trim($requestPath)); //$this->userAuth(trim($requestPath));
} }
unset($this->params["AuthToken"]); unset($this->params["AuthToken"]);
......
...@@ -1243,15 +1243,9 @@ class AAgents extends BaseModel ...@@ -1243,15 +1243,9 @@ class AAgents extends BaseModel
$result = Db::table($this->table) $result = Db::table($this->table)
->field($field) ->field($field)
->where($params) ->where($params)
->limit(1)
->select(); ->select();
if($result){ return $result;
$agentIds = "";
foreach ($result as $key1 => $value1) {
$agentIds .= $value1["id"] . ',';
}
$agentIds = rtrim($agentIds, ",");//经纪人ID集合
}
return $agentIds;
} }
......
...@@ -746,7 +746,7 @@ Route::group('broker', [ ...@@ -746,7 +746,7 @@ Route::group('broker', [
'setAgentLookNum' => ['api_broker/LookShop/setAgentLookNum', ['method' => 'post']], //设置经纪人的看铺数量 'setAgentLookNum' => ['api_broker/LookShop/setAgentLookNum', ['method' => 'post']], //设置经纪人的看铺数量
//首页跟进记录 //首页跟进记录
'userFollowUpList' => ['api_broker/HomePageLog/userFollowUpList', ['method' => 'post']], 'userFollowUpList' => ['api_broker/HomePageLog/userFollowUpList', ['method' => 'post|get']],
'userFollowUpListV2' => ['api_broker/HomePageLog/userFollowUpListV2', ['method' => 'post|get']], 'userFollowUpListV2' => ['api_broker/HomePageLog/userFollowUpListV2', ['method' => 'post|get']],
'houseFollowUpList' => ['api_broker/HomePageLog/houseFollowUpList', ['method' => 'post']], 'houseFollowUpList' => ['api_broker/HomePageLog/houseFollowUpList', ['method' => 'post']],
...@@ -845,4 +845,8 @@ Route::group('broker', [ ...@@ -845,4 +845,8 @@ Route::group('broker', [
]); ]);
Route::group('search', [
'search' => ['search/Search/search', ['method' => 'get|post']],
]);
//Route::miss('api/index/miss');//处理错误的url //Route::miss('api/index/miss');//处理错误的url
\ No newline at end of file
<?php
namespace app\search\consts;
/**
* Created by PhpStorm.
* User : zw
* Date : 2019/1/9
* Time : 13:27
* Intro:
*/
class ConfigConst
{
const ACCESS_KEY_ID = "LTAIEeZUju3PFZlJ";
const SECRET = "ljKCItiUp19F7wtzfn225WoBH0Qe8Y";
const END_POINT = "http://opensearch-cn-shanghai.aliyuncs.com";//公网=>本地
//const END_POINT = "http://intranet.opensearch-cn-shanghai.aliyuncs.com";//内网==>线上
}
\ No newline at end of file
<?php
namespace app\search\controller;
use app\search\extend\Basic;
use app\search\service\SearchService;
use think\Request;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/4/10
* Time: 14:26
*/
class Search extends Basic {
private $service_;
public function __construct(Request $request = null)
{
parent::__construct($request);
$this->service_ = new SearchService();
}
public function search(){
$this->service_ ->search();
}
}
\ No newline at end of file
<?php
namespace app\search\extend;
use think\Cache;
use think\Controller;
use think\Request;
use think\Response;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/1/8
* Time : 16:54
* Intro:
*/
class Basic extends Controller
{
/**
* 访问请求对象
* @var Request
*/
public $request;
/**
* 请求参数
* @var mixed|null
*/
public $params;
/**
* app通讯接口授权token
* @var
*/
public $accessToken;
/**
* 基础接口SDK
* @param Request|null $request
*/
public function __construct(Request $request = null)
{
// CORS 跨域 Options 检测响应
$this->corsOptionsHandler();
// 输入对象
$this->request = is_null($request) ? Request::instance() : $request;
if (strtoupper($this->request->method()) === "GET") {
$this->params = $this->request->param();
} elseif (strtoupper($this->request->method()) === "POST") {
$this->params = $this->request->param() != null ? $this->request->param() : null;
}
}
/**
* 输出返回数据
* @param string $msg 提示消息内容
* @param string $code 业务状态码
* @param mixed $data 要返回的数据
* @param string $type 返回类型 JSON XML
* @return Response
*/
public function response($code = 'SUCCESS', $msg, $data = [], $type = 'json')
{
$result = [ 'code' => $code, 'msg' => $msg, 'data' => $data, 'type' => strtolower($type) ];
return Response::create($result, $type);
}
/**
* Cors Options 授权处理
*/
public static function corsOptionsHandler()
{
if (request()->isOptions()) {
header('Access-Control-Allow-Origin:*');
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-Credentials:true');
header('Access-Control-Allow-Methods:GET,POST,OPTIONS');
header('Access-Control-Max-Age:1728000');
header('Content-Type:text/plain charset=UTF-8');
header('Content-Length: 0', true);
header('status: 204');
header('HTTP/1.0 204 No Content');
exit;
}
}
}
<?php
namespace app\search\service;
use app\search\consts\ConfigConst;
use OpenSearch\Client\OpenSearchClient;
use OpenSearch\Client\SearchClient;
use OpenSearch\Util\SearchParamsBuilder;
/**
* Created by PhpStorm.
* User: zw
* Date: 2019/4/10
* Time: 14:38
*/
require_once EXTEND_PATH . 'OpenSearch/Autoloader/Autoloader.php';
class SearchService
{
private $client;
public function __construct()
{
$options = array('debug' => true);
$this->client = new OpenSearchClient(ConfigConst::ACCESS_KEY_ID, ConfigConst::SECRET, ConfigConst::END_POINT, $options);
}
/**
* @param $params
* @param $page_no
* @param $page_size
* @param $agentId
* @return mixed|string
*/
public function searchByKeyword($params, $page_no, $page_size, $agentId)
{
$start_time = $params["start_time"] . "000";
$end_time = $params["end_time"] . "000";
$searchClient = new SearchClient($this->client);
$condition = new SearchParamsBuilder();
$condition->setStart($page_no);
$condition->setHits($page_size);
$condition->setAppName("tl_estate");
$search_content = !empty($params["search_content"]) ? $params["search_content"] : null;
if ($search_content && $agentId <= 0) {
$condition->setQuery("content:'$search_content'");
} else if ($search_content && $agentId > 0) {
$condition->setQuery("content:'$search_content'");
$condition->setFilter("agent_id = '$agentId'");
} else if (!$search_content && $agentId > 0) {
$condition->setQuery("agent_id:'$agentId'");
}
$condition->addFilter("create_time > '$start_time'", " and create_time < '$end_time'");
$condition->setFormat("json");
$condition->addSort('id', SearchParamsBuilder::SORT_DECREASE);
$condition->setFetchFields(array('id', 'user_id', 'agent_id', 'type', 'content', 'create_time', 'city', 'user_status', 'labels_id'));
$ret = $searchClient->execute($condition->build())->result;
return $ret;
}
}
\ No newline at end of file
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