Commit 5caafc4a authored by clone's avatar clone

1

parent a4316134
<?php
namespace app\api_broker\controller;
use app\api_broker\extend\Basic;
use app\api_broker\service\ClientService;
use app\api_broker\service\RedisCacheService;
use app\api_broker\service\UserExpiredTimeService;
use app\api_broker\service\VerifyRepetitionService;
use app\extra\RedisExt;
use app\index\service\UserService;
use app\model\AAgents;
use app\model\GHouses;
use app\model\GHousesFollowUp;
use app\model\OfficeGHousesFollowUp;
use app\model\OfficeUPhoneFollowUp;
use app\model\ULabels;
use app\model\UPhoneFollowUp;
use app\model\UPhoneFollowUpTemporary;
use app\search\service\SearchService;
use app\task\controller\FollowUpTask;
use think\Log;
use think\Request;
/**
* Created by PhpStorm.
* User : zw
* Date : 2018/5/23
* Time : 上午11:34
* Intro: 首页客户跟进和商铺跟进列表
*/
class OfficeHomePageLog extends Basic
{
private $uPhoneFollowUpModel;
private $gHouseFollowUpModel;
function __construct(Request $request = null)
{
parent::__construct($request);
$this->uPhoneFollowUpModel = new OfficeUPhoneFollowUp($this->siteId);
$this->gHouseFollowUpModel = new OfficeGHousesFollowUp();
}
/**
* 首页客户跟进
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function userFollowUpList()
{
$params = $this->params;
/* $params = array(
"start_time" => strtotime('2019-04-01 15:47:36'), //开始时间
"end_time" => strtotime('2019-04-07 15:47:36'), //结束时间
"name_or_phone" => "黄莉",//用户姓名或电话 经纪人
"search_content" => "奶茶",// 搜索跟进内容
"pageNo" => 1,
"pageSize" => 15
);
$this->siteId = 10001;*/
$vrs = new VerifyRepetitionService();
$is_check = $vrs->followUpClick($this->agentId);
if ($params["pageNo"] == 1 && !$is_check) {
$is_bool = $vrs->getCurrTimeSection();
$msg = "请勿频繁请求";
if ($is_bool) {
$msg = "高峰期间每10秒钟只能搜索一次(6.30-8.30)";
}
return $this->response("101", $msg);
}
if (empty($params['start_time']) || empty($params['end_time'])) {
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"]);
$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'];
$field = "id,user_id,agent_id,type,content,create_time,user_status,labels_id";
$where = ' 1=1 ';
if (!empty($params["search_content"])) {
$search_content = trim($params['search_content']);
$where .= " AND content LIKE '%$search_content%'";
}
$where .= ' AND create_time BETWEEN "' . $start_time . '" AND "' . $end_time . '"';
$agentId = 0;
if (!empty($params["name_or_phone"])) {
$agentId = $this->getAgentInfo($params["name_or_phone"]);
if ($agentId > 0) {
$where .= " AND agent_id = $agentId ";
} elseif ($agentId == -1) {
return $this->response("101", '手机号有误或者姓名不满两位汉字');
} else {
return $this->response("200", "request null");
}
}
$result = $this->uPhoneFollowUpModel->getFollowList($pageNo, $pageSize, '', $field, $where);
if (count($result) <= 0) {
return $this->response("200", "request null");
}
$clientService = new ClientService();
$redis_service = new RedisCacheService();
$label_data = $redis_service->userCallLabelCache();
$user_service = new UserService();
foreach ($result as $key => $value) {
if ($value['agent_id']) {
$res_a = $redis_service->getRedisCache(2, $value['agent_id']);
$result[$key]['name'] = $res_a['name'];
$result[$key]['img'] = $res_a['img'];
$result[$key]['store_name'] = $res_a['store_name'];
} else {
$result[$key]['name'] = '';
$result[$key]['img'] = '';
$result[$key]['store_name'] = '';
}
#保护期(0:保护器内 1:超过保护期)
$result[$key]['is_outstrip_twenty_four_hours'] = $user_service->isUserProtect($value['user_id']);
$is_show = $clientService->dialTotal($value["user_id"]);
$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']] : '';
}
//$count = $this->uPhoneFollowUpModel->getSearchCount($where_);
$list["result"] = $result;
$list["img_path"] = AGENTHEADERIMGURL;
//暂时处理
$list["total"] = 0;
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 {
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;
}
}
/**
* 首页商铺跟进
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function houseFollowUpList()
{
$params = $this->params;
/*$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", '请选择时间');
}
$where_ = [];
$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,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"]);
$time = strtotime($end_time) - strtotime($start_time);
if ($time > 2592000 || $time < 0) {
return $this->response(101, '搜索时间不能大于30天');
}
$where_["f.create_time"] = array('between', array($start_time, $end_time));
}
// if (empty($params['city'])) {
// $where_["f.city"] = trim($this->city) ? trim($this->city) : '上海市';
// } else {
// $where_["f.city"] = $params['city'] ? $params['city'] : '上海市';
// }
if ($this->city != '全部') {
$where_["f.city"] = $this->city;
}
if (!empty($params['disc'])) {
$where_["f.disc"] = $params['disc'];
}
if (!empty($params["province"]) && !empty($params["province"])) {
$where_["f.province"] = $params["province"];
}
//商铺ID搜索
if (!empty($params["house_id"]) && !empty($params["house_id"])) {
$where_["f.house_id"] = $params["house_id"];
}
//部门搜索
if (!empty($params["district_id"]) && !empty($params["district_id"])) {
$where_["a.district_id"] = $params["district_id"];
}
//门店搜索
if (!empty($params["store_id"]) && !empty($params["store_id"])) {
$where_["a.store_id"] = $params["store_id"];
}
//经纪人id
if (!empty($params["agent_id"]) && !empty($params["agent_id"])) {
$where_["f.agent_id"] = $params["agent_id"];
}
if (!empty($params["name_or_phone"])) {
$agentId = $this->getAgentInfo($params["name_or_phone"]);
if ($agentId > 0) {
$where_["f.agent_id"] = $agentId;
} elseif ($agentId == -1) {
return $this->response("101", '手机号有误或者姓名不满两位汉字');
} else {
return $this->response("200", "request null");
}
}
$redis_service = new RedisCacheService();
$order = "f.id desc";
$result = $this->gHouseFollowUpModel->getSearch($pageNo, $pageSize, $order, $field, $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'];
if ($value['agent_id']) {
$agent_data = $redis_service->getRedisCache(2, $value['agent_id']);
$result[$key]['name'] = $agent_data['name'];
$result[$key]['img'] = $agent_data['img'];
$result[$key]['store_name'] = $agent_data['store_name'];
} else {
$result[$key]['name'] = [];
$result[$key]['img'] = [];
$result[$key]['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( $where_);
if (count($result) > 0) {
$list["result"] = $result;
$list["img_path"] = AGENTHEADERIMGURL;
$list["total"] = 0;
return $this->response("200", "request success", $list);
} else {
return $this->response("200", "request null");
}
}
}
\ No newline at end of file
...@@ -11,7 +11,7 @@ namespace app\index\service; ...@@ -11,7 +11,7 @@ namespace app\index\service;
use app\api_broker\service\VerifyRepetitionService; use app\api_broker\service\VerifyRepetitionService;
use app\model\AAgents; use app\model\AAgents;
use app\model\OfficePhoneFollowUp; use app\model\OfficePhoneFollowUp;
use app\model\OfficeUPhoneFollowUpTemporary; use app\model\OfficeUPhoneFollowUp;
class OfficePhoneFollowUpService class OfficePhoneFollowUpService
{ {
...@@ -23,7 +23,7 @@ class OfficePhoneFollowUpService ...@@ -23,7 +23,7 @@ class OfficePhoneFollowUpService
{ {
$this->siteId = $site_id; $this->siteId = $site_id;
$this->phoneFollowUp = new OfficePhoneFollowUp($site_id); $this->phoneFollowUp = new OfficePhoneFollowUp($site_id);
$this->phoneFollowUpTemporary = new OfficeUPhoneFollowUpTemporary($site_id); $this->phoneFollowUpTemporary = new OfficeUPhoneFollowUp($site_id);
} }
/** /**
......
...@@ -9,30 +9,20 @@ use app\task\controller\FollowUpTask; ...@@ -9,30 +9,20 @@ use app\task\controller\FollowUpTask;
use think\Db; use think\Db;
class OfficeUPhoneFollowUpTemporary extends BaseModel class OfficeUPhoneFollowUp extends BaseModel
{ {
protected $table = 'office_u_phone_follow_up'; protected $table = 'office_u_phone_follow_up';
protected $follow_up; protected $follow_up;
protected $siteId; protected $siteId;
protected $table_name_string;
function __construct($site_id) function __construct($site_id)
{ {
$date = date("Y-m-d", time()); $date = date("Y-m-d", time());
$this->follow_up = Db($this->table."_".$site_id."_".$date); $this->follow_up = Db($this->table."_".$site_id."_".$date);
$this->siteId = $site_id; $this->siteId = $site_id;
$this->table_name_string = '`'.$this->table."_".$site_id."_".$date.'`';
} }
public function createTable(){
$date = date("Y-m-d", time());
$t_follow_up_task = new FollowUpTask();
if(!$t_follow_up_task->isExistTable($date, $this->siteId)){
return false;
}
return true;
}
/** /**
* 新增电话跟进-插入数据 * 新增电话跟进-插入数据
...@@ -40,10 +30,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -40,10 +30,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
* @return int|string * @return int|string
*/ */
public function savePhoneFollow($params) { public function savePhoneFollow($params) {
if(!$this->createTable()){
return null;
}
$arr = []; $arr = [];
if (isset($params["content"])) { if (isset($params["content"])) {
$arr["content"] = $params["content"]; $arr["content"] = $params["content"];
...@@ -84,6 +70,16 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -84,6 +70,16 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
$city = '深圳市'; $city = '深圳市';
$disc = '罗湖区'; $disc = '罗湖区';
break; break;
case 10004 :
$province = '广东省';
$city = '广州市';
$disc = '黄埔区';
break;
case 10005 :
$province = '北京市';
$city = '北京市';
$disc = '朝阳区';
break;
default : default :
$province = '上海市'; $province = '上海市';
$city = '上海市'; $city = '上海市';
...@@ -104,9 +100,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -104,9 +100,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
} }
public function getFollowList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') { public function getFollowList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
if(!$this->createTable()){
return null;
}
return $this->follow_up->field($field) return $this->follow_up->field($field)
->where($params) ->where($params)
->order($order_) ->order($order_)
...@@ -117,9 +110,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -117,9 +110,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
public function getFollowUpList($field, $params,$page_no,$page_size) public function getFollowUpList($field, $params,$page_no,$page_size)
{ {
if(!$this->createTable()){
return null;
}
$where_ = []; $where_ = [];
if (isset($params["user_id"])) { if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"]; $where_["a.user_id"] = $params["user_id"];
...@@ -139,9 +129,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -139,9 +129,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
} }
public function getFollowUpListByUserId($field, $params) public function getFollowUpListByUserId($field, $params)
{ {
if(!$this->createTable()){
return null;
}
$where_ = []; $where_ = [];
if (isset($params["user_id"])) { if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"]; $where_["a.user_id"] = $params["user_id"];
...@@ -171,9 +158,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -171,9 +158,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
* @return int|string * @return int|string
*/ */
public function insertDefaultFollow($agent_id, $user_id, $content, $type) { public function insertDefaultFollow($agent_id, $user_id, $content, $type) {
if(!$this->createTable()){
return null;
}
$data['agent_id'] = $agent_id; $data['agent_id'] = $agent_id;
$data['user_id'] = $user_id; $data['user_id'] = $user_id;
$data['content'] = $content; $data['content'] = $content;
...@@ -189,9 +173,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -189,9 +173,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
*/ */
public function getFollowTotal($params) public function getFollowTotal($params)
{ {
if(!$this->createTable()){
return null;
}
return $this->follow_up->where($params) return $this->follow_up->where($params)
->count(); ->count();
} }
...@@ -202,9 +183,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -202,9 +183,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
*/ */
public function getPhoneFollowData($field,$params,$order) public function getPhoneFollowData($field,$params,$order)
{ {
if(!$this->createTable()){
return null;
}
$result = $this->follow_up $result = $this->follow_up
->field($field) ->field($field)
->order($order) ->order($order)
...@@ -216,9 +194,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -216,9 +194,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
} }
public function getFollowListV2($site_id,$pageNo = 1, $pageSize = 15, $where, $filed = '`id`, `user_id`, `create_time`, `content`, `user_status`, `labels_id`, `agent_id`') { public function getFollowListV2($site_id,$pageNo = 1, $pageSize = 15, $where, $filed = '`id`, `user_id`, `create_time`, `content`, `user_status`, `labels_id`, `agent_id`') {
if(!$this->createTable()){
return null;
}
$start_index = ($pageNo - 1) * $pageSize; $start_index = ($pageNo - 1) * $pageSize;
$sql = "SELECT * FROM $sql = "SELECT * FROM
((SELECT ((SELECT
...@@ -251,9 +226,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -251,9 +226,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
* @throws \think\exception\DbException * @throws \think\exception\DbException
*/ */
public function getFollowListV3($site_id, $pageNo, $pageSize, $where, $field = '`id`, `user_id`, `create_time`, `content`, `user_status`, `labels_id`, `agent_id`') { public function getFollowListV3($site_id, $pageNo, $pageSize, $where, $field = '`id`, `user_id`, `create_time`, `content`, `user_status`, `labels_id`, `agent_id`') {
if(!$this->createTable()){
return null;
}
$sql = Db::table('u_phone_follow_up_'.$site_id)->field($field)->order('id desc')->where($where)->buildSql(); $sql = Db::table('u_phone_follow_up_'.$site_id)->field($field)->order('id desc')->where($where)->buildSql();
$sql_string = $this->table($this->table_name_string)->field($field)->where($where)->union([$sql], true)->buildSql(); $sql_string = $this->table($this->table_name_string)->field($field)->where($where)->union([$sql], true)->buildSql();
$data = Db::table($sql_string. ' a') $data = Db::table($sql_string. ' a')
...@@ -274,9 +246,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel ...@@ -274,9 +246,6 @@ class OfficeUPhoneFollowUpTemporary extends BaseModel
* @return null * @return null
*/ */
public function getUserFollowKey($field, $where, $order = 'id asc') { public function getUserFollowKey($field, $where, $order = 'id asc') {
if(!$this->createTable()){
return null;
}
return $this->follow_up->where($where) return $this->follow_up->where($where)
->order($order) ->order($order)
->value($field); ->value($field);
......
...@@ -84,6 +84,16 @@ class UPhoneFollowUpTemporary extends BaseModel ...@@ -84,6 +84,16 @@ class UPhoneFollowUpTemporary extends BaseModel
$city = '深圳市'; $city = '深圳市';
$disc = '罗湖区'; $disc = '罗湖区';
break; break;
case 10004 :
$province = '广东省';
$city = '广州市';
$disc = '黄埔区';
break;
case 10005 :
$province = '北京市';
$city = '北京市';
$disc = '朝阳区';
break;
default : default :
$province = '上海市'; $province = '上海市';
$city = '上海市'; $city = '上海市';
......
...@@ -1002,6 +1002,9 @@ Route::group('office', [ ...@@ -1002,6 +1002,9 @@ Route::group('office', [
'bargainListSearchBargainId' => ['api_broker/OfficeBargain/bargainListSearchBargainId', ['method' => 'POST|GET']], 'bargainListSearchBargainId' => ['api_broker/OfficeBargain/bargainListSearchBargainId', ['method' => 'POST|GET']],
'bargainMain' => ['api_broker/OfficeBargain/bargainList', ['method' => 'POST|GET']], 'bargainMain' => ['api_broker/OfficeBargain/bargainList', ['method' => 'POST|GET']],
'bargainMainV2' => ['api_broker/OfficeBargain/bargainListV2', ['method' => 'POST|GET']], 'bargainMainV2' => ['api_broker/OfficeBargain/bargainListV2', ['method' => 'POST|GET']],
'userFollowUpList' => ['api_broker/OfficeHomePageLog/userFollowUpList', ['method' => 'POST|GET']],
'houseFollowUpList' => ['api_broker/OfficeHomePageLog/houseFollowUpList', ['method' => 'POST|GET']],
]); ]);
Route::group('office_index', [ Route::group('office_index', [
......
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