Commit 473550dd authored by zhuwei's avatar zhuwei

商铺跟进优化

parent ef7e9f6f
......@@ -3,6 +3,8 @@
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\model\AAgents;
use app\model\GHouses;
use app\model\GHousesFollowUp;
use app\model\UPhoneFollowPp;
use think\Request;
......@@ -100,16 +102,16 @@ class HomePageLog extends Basic
public function houseFollowUpList()
{
$params = $this->params;
/* $params = array(
"start_time" => time(), //开始时间
"end_time" => time() . " 23:59:59", //结束时间
"name_or_phone" => "li",//用户姓名或电话
"search_content" => "111",// 搜索跟进内容
/*$params = array(
"start_time" => strtotime('2016-08-14 11:02:36'), //开始时间
"end_time" => strtotime('2018-08-14 11:07:10'), //结束时间
"name_or_phone" => "18112347151",//用户姓名或电话
"search_content" => "1",// 搜索跟进内容
"pageNo" => 1,
"pageSize" => 15
);*/
if (empty($params['start_time']) || empty($params['end_time'])) {
return $this->response("101", '请选择时间');
}
......@@ -119,37 +121,63 @@ class HomePageLog extends Basic
$pageNo = empty($params['pageNo']) ? 1 : $params['pageNo'];
$pageSize = empty($params['pageSize']) ? 15 : $params['pageSize'];
$field = "f.id,f.house_id,f.agent_id,f.follow_up_info,f.create_time,a.name,a.img,b.store_name,c.internal_title";
$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"])) {
$where_["f.follow_up_info"] = array( "like", "%" . trim($params['search_content']) . "%" );
}
if (!empty($params["start_time"]) && !empty($params["end_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"]);
$where_["f.create_time"] = array( 'between', array( $start_time, $end_time ) );
}
if (!empty($params["name_or_phone"])) {
$where_["a.phone|a.name"] = array( "like", "%" . trim($params["name_or_phone"]) . "%" );
}
if (empty($params['city'])) {
$where_["c.city"] = trim($this->city);
$where_["f.city"] = trim($this->city)? trim($this->city) :'上海市';
} else {
$where_["c.city"] = $params['city'];
$where_["f.city"] = $params['city']? $params['city'] :'上海市';
}
if (!empty($params['disc'])) {
$where_["c.disc"] = $params['disc'];
$where_["f.disc"] = $params['disc'];
}
$join = [
[ 'a_agents a', 'a.id=f.agent_id', 'left' ],
[ 'a_store b', 'b.id=a.store_id', 'left' ],
[ 'g_houses c', 'f.house_id=c.id', 'left' ]
];
if (!empty($params["name_or_phone"])) {
if(!preg_match("/^1\d{10}$/", $params['name_or_phone']) and (strlen($params['name_or_phone']) < 6)){
return $this->response("300", '手机号有误或者姓名不满两位汉字');
}
//$agent_params["phone|name"] = array( "like", "%" . trim($params["name_or_phone"]) . "%" );
$agent_params["phone|name"] = $params["name_or_phone"];
$agent_field = "id";
$model = new AAgents();
$res_a = $model->getAgentsIdsArray($agent_field, $agent_params);
if($res_a){
$where_["f.agent_id"] = ['in',$res_a];
}
}
$join = [];
$order = "f.id desc";
$result = $this->gHouseFollowUpModel->getSearch($pageNo, $pageSize, $order, $field, $join, $where_, "");
foreach ($result as $key => $value) {
$agent_params =[];
$agent_params["a.id"] = $value['agent_id'];
$agent_field = "a.name,a.img,b.store_name";
$model = new AAgents();
$res_a = $model->getAgentsInfo($agent_field, $agent_params);
$result[$key]['name'] =$res_a[0]['name'];
$result[$key]['img'] =$res_a[0]['img'];
$result[$key]['store_name']=$res_a[0]['store_name'];
$house_params =[];
$house_params["id"] = $value['house_id'];
$house_field = "internal_title";
$model = new GHouses();
$res_a = $model->getHouseInfo($house_field, $house_params);
$result[$key]['internal_title'] =$res_a[0]['internal_title'];
}
$count = $this->gHouseFollowUpModel->getSearchCount($join, $where_);
if (count($result) > 0) {
$list["result"] = $result;
......
......@@ -985,4 +985,36 @@ class AAgents extends BaseModel
//dump($this->getLastSql());
return $result;
}
public function getAgentsIdsArray($field, $params)
{
$params["status"] = 0;
$result = Db::table($this->table)
->field($field)
->where($params)
->select();
if($result){
$agentIds = "";
foreach ($result as $key1 => $value1) {
$agentIds .= $value1["id"] . ',';
}
$agentIds = rtrim($agentIds, ",");//经纪人ID集合
}
return $agentIds;
}
public function getAgentsInfo($field, $params)
{
$params["a.status"] = 0;
$result = Db::table($this->table)
->alias('a')
->join('a_store b', 'b.id=a.store_id', 'left' )
->field($field)
->where($params)
->select();
return $result;
}
}
\ No newline at end of file
......@@ -1339,4 +1339,32 @@ class GHouses extends BaseModel
return $result;
}
public function getHouseIdsArray($field, $params)
{
$result = Db::table($this->table)
->field($field)
->where($params)
->select();
if($result){
$houseids = "";
foreach ($result as $key1 => $value1) {
$houseids .= $value1["id"] . ',';
}
$houseids = rtrim($houseids, ",");//经纪人ID集合
}
return $houseids;
}
public function getHouseInfo($field, $params)
{
$result = Db::table($this->table)
->field($field)
->where($params)
->select();
return $result;
}
}
......@@ -106,7 +106,7 @@ class GHousesFollowUp extends Model
->limit($pageSize)
->page($p)
->select();
// echo $this->getLastSql();
//echo $this->getLastSql();
return $data;
}
......
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