Commit 37b0ad23 authored by zhuwei's avatar zhuwei

1

parent b9309b03
......@@ -11,7 +11,6 @@ use app\index\service\UserService;
use app\model\AAgents;
use app\model\GOperatingRecords;
use app\model\OfficeUPhoneFollowUp;
use app\model\OfficeUPhoneFollowUpTemporary;
use app\model\UPhoneFollowUp;
use app\model\UPhoneFollowUpTemporary;
use app\model\Users;
......
......@@ -15,7 +15,7 @@ use app\model\ACollectUser;
use app\model\ASite;
use app\model\GOperatingRecords;
use app\model\OfficePhoneFollowUp;
use app\model\OfficeUPhoneFollowUpTemporary;
use app\model\OfficeUPhoneFollowUp;
use app\model\OReportModel;
use app\model\ULabels;
use app\model\UPhoneFollowUp;
......@@ -71,7 +71,7 @@ class OfficeUserLogService
$m_label = new ULabels();
$label_data = $m_label->getColumn('id,name', ['type'=>1]); //获取标签
$m_office_phone_follow_up_tmp = new OfficeUPhoneFollowUpTemporary($site_id);
$m_office_phone_follow_up_tmp = new OfficeUPhoneFollowUp($site_id);
//电话跟进
$userParams["user_id"] = $user_id;
......
<?php
namespace app\model;
/**
* 客户电话跟进-临时表
*/
use app\task\controller\FollowUpTask;
use think\Db;
class OfficeUPhoneFollowUpTemporary extends BaseModel
{
protected $table = 'u_phone_follow_up';
protected $follow_up;
protected $siteId;
protected $table_name_string;
function __construct($site_id)
{
$date = date("Y-m-d", time());
$this->follow_up = Db($this->table."_".$site_id."_".$date);
$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;
}
/**
* 新增电话跟进-插入数据
* @param $params
* @return int|string
*/
public function savePhoneFollow($params) {
if(!$this->createTable()){
return null;
}
$arr = [];
if (isset($params["content"])) {
$arr["content"] = $params["content"];
}
if (isset($params["labels_id"])) {
$arr["labels_id"] = $params["labels_id"];
}
if (isset($params["user_id"])) {
$arr["user_id"] = $params["user_id"];
}
if (isset($params["agent_id"])) {
$arr["agent_id"] = $params["agent_id"];
}
if (isset($params["type"])) {
$arr["type"] = $params["type"];
}
if (isset($params["user_status"])) {
$arr["user_status"] = $params["user_status"];
}
if (isset($params['create_time'])) {
$arr["create_time"] = $params["create_time"];
}
if (isset($this->siteId)) {
switch ($this->siteId) {
case 10001 :
$province = '上海市';
$city = '上海市';
$disc = '黄埔区';
break;
case 10002 :
$province = '浙江省';
$city = '杭州市';
$disc = '西湖区';
break;
case 10003 :
$province = '广东省';
$city = '深圳市';
$disc = '罗湖区';
break;
case 10004 :
$province = '广东省';
$city = '广州市';
$disc = '黄埔区';
break;
case 10005 :
$province = '北京市';
$city = '北京市';
$disc = '朝阳区';
break;
default :
$province = '上海市';
$city = '上海市';
$disc = '黄埔区';
}
$arr["province"] = $province;
$arr["city"] = $city;
$arr["disc"] = $disc;
}else{
$arr["site_id"] = '10001';
$arr["province"] = '上海市';
$arr["city"] = '上海市';
$arr["disc"] = '黄埔区';
}
$result = $this->follow_up->insert($arr);
return $result;
}
public function getFollowList($pageNo = 1, $pageSize = 15, $order_ = 'id desc', $field = '', $params = '') {
if(!$this->createTable()){
return null;
}
return $this->follow_up->field($field)
->where($params)
->order($order_)
->limit($pageSize)
->page($pageNo)
->select();
}
public function getFollowUpList($field, $params,$page_no,$page_size)
{
if(!$this->createTable()){
return null;
}
$where_ = [];
if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"];
}
$result = $this->follow_up
->field($field)
->alias("a")
->join("a_agents b", "a.agent_id = b.id", "left")
->where($where_)
->order("a.create_time desc")
->page($page_no)
->limit($page_size)
->select();
return $result;
}
public function getFollowUpListByUserId($field, $params)
{
if(!$this->createTable()){
return null;
}
$where_ = [];
if (isset($params["user_id"])) {
$where_["a.user_id"] = $params["user_id"];
}
if (isset($params["type"])) {
$where_["a.type"] = $params["type"];
}
$result = $this->follow_up
->field($field)
->alias("a")
->join("a_agents b", "a.agent_id = b.id", "left")
->join("a_store c", "b.store_id = c.id", "left")
->where($where_)
->select();
return $result;
}
/**
* 插入默认跟进
*
* @param $agent_id
* @param $user_id
* @param $content
* @param $type
* @return int|string
*/
public function insertDefaultFollow($agent_id, $user_id, $content, $type) {
if(!$this->createTable()){
return null;
}
$data['agent_id'] = $agent_id;
$data['user_id'] = $user_id;
$data['content'] = $content;
$data['type'] = $type;
return $this->follow_up->insertGetId($data);
}
/**
* 记录总数
*
* @param $params
* @return int|string
*/
public function getFollowTotal($params)
{
if(!$this->createTable()){
return null;
}
return $this->follow_up->where($params)
->count();
}
/**
* 查询数据
* 朱伟 2018-10-24
*/
public function getPhoneFollowData($field,$params,$order)
{
if(!$this->createTable()){
return null;
}
$result = $this->follow_up
->field($field)
->order($order)
->where($params)
->limit(1)
->select();
//dump($this->getLastSql());
return $result;
}
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;
$sql = "SELECT * FROM
((SELECT
$filed
FROM
$this->table_name_string
WHERE
$where)
UNION
(SELECT
$filed
FROM
u_phone_follow_up_$site_id
WHERE
$where
) ) as aa ORDER BY `id` DESC limit $start_index,$pageSize";
return $this->follow_up->execute($sql);
}
/**
* @param $site_id
* @param int $pageNo
* @param int $pageSize
* @param $where
* @param string $field
* @return false|null|\PDOStatement|string|\think\Collection
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @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`') {
if(!$this->createTable()){
return null;
}
$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();
$data = Db::table($sql_string. ' a')
->field($field)
->order('id desc')
->limit($pageSize)
->page($pageNo)
->order('id desc')
->select();
return $data;
}
/**
* @param $field
* @param $where
* @param string $order
* @return null
*/
public function getUserFollowKey($field, $where, $order = 'id asc') {
if(!$this->createTable()){
return null;
}
return $this->follow_up->where($where)
->order($order)
->value($field);
}
}
<?php
namespace app\task\controller;
use app\api_broker\service\RedisCacheService;
use app\extra\RedisExt;
use app\model\ASite;
use app\model\UPhoneFollowUp;
use app\model\UPhoneFollowUpTemporary;
/**
* Created by PhpStorm.
* User : zw
* Date : 2019/1/10
* Time : 2:20 PM
* Intro:
*/
class OfficeFollowUpTask
{
private $redis_;
private $table = 'office_u_phone_follow_up_';
private $siteModel;
public function __construct()
{
$this->redis_ = RedisExt::getRedis();
$this->siteModel = new ASite();
}
/**
* @param $time
* @param $siteId
* @return bool
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public function isExistTable($time, $siteId)
{
if(!$siteId){
return false;
}
$redis_service = new RedisCacheService();
$site_arr = $redis_service->getRedisCache(4, $siteId);
if (empty($site_arr)) {
$site_arr = $this->siteModel->findByOne('city', ["id" => $siteId]);
}
if (is_array($site_arr) && count($site_arr) <= 0) {
return false;
}
//todo 1.判断表是否存在,不存在则创建,
$date = date("Y-m-d", time());
//时间是今天
if ($time >= $date && $time <= $date . " 23:59:59") {
$phoneFollowUpModel = new UPhoneFollowUpTemporary($siteId);
$table_name = $this->table . $siteId . "_" . $date;
//存在表
if ($this->redis_->get($table_name) > 0) {
return true;
}
$isTable = $phoneFollowUpModel->query('SHOW TABLES LIKE "' . $table_name . '"');
if ($isTable) {
$this->redis_->set($table_name, 1, 24 * 3600);
return true;//存在表
} else {
//创建表
return $this->createTemp($phoneFollowUpModel, $table_name);
}
}
return false;
}
/**
* @param $db
* @param $tableName
* @return bool
*/
public function createTemp($db, $tableName)
{
if (!$tableName) {
return false;
}
$sql = "CREATE TABLE `" . $tableName . "` (
`id` int(10) NOT NULL AUTO_INCREMENT COMMENT '电话跟进表',
`content` varchar(255) DEFAULT '' COMMENT '跟进内容',
`labels_id` int(10) DEFAULT '0' COMMENT 'u_labels表主键',
`user_id` int(10) unsigned DEFAULT '0' COMMENT 'u_users ID用户表id',
`agent_id` int(10) unsigned DEFAULT '0' COMMENT 'agent表id',
`province` varchar(60) DEFAULT '' COMMENT '省份',
`city` varchar(60) DEFAULT '' COMMENT '城市',
`disc` varchar(60) DEFAULT '' COMMENT '区域',
`type` int(10) unsigned DEFAULT '0' COMMENT '0 电话跟进 1普通跟进 2不知道是什么,3打电话未跟进',
`create_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
`update_time` timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
`user_status` tinyint(2) DEFAULT '0' COMMENT '客户状态(0:求租;1:已租;-1:无效)',
PRIMARY KEY (`id`),
KEY `idx_agent_id` (`agent_id`),
KEY `idx_user_id` (`user_id`),
KEY `idx_create_time` (`create_time`),
KEY `idx_city` (`city`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8";
if (false !== $db->execute($sql)) {
return true;
} else {
return false;
}
}
/**
* 每天0.30执行移动操作
* @throws \think\db\exception\BindParamException
* @throws \think\exception\PDOException
*/
public function moveFollowUpList()
{
$key = $_GET["key"];
//todo 判断参数和时间
$checkDayStr = date('Y-m-d ', time());
$timeBegin1 = strtotime($checkDayStr . "0:10" . ":00");
$timeEnd1 = strtotime($checkDayStr . "0:50" . ":00");
$curr_time = time();
if (!$key || $key!= "zw" ||$curr_time < $timeBegin1 || $curr_time > $timeEnd1) {
echo "hello world";
return;
}
$site_arr = $this->siteModel->getSite("id,name,city,is_del", ["is_del" => 0]);
if (count($site_arr) <= 0) {
return;
}
$date = date("Y-m-d",strtotime("-1 day"));
foreach ($site_arr as $item) {
$site_id = $item["id"];
//判断此站点是否执行过
if ($this->redis_->get("is_run_" . $date . "_" . $site_id) > 0) {
continue;
}
$table_name = $this->table . $site_id . "_" . $date;
$phoneFollowUpModel = new UPhoneFollowUpTemporary($site_id);
$isTable = $phoneFollowUpModel->query('SHOW TABLES LIKE "' . $table_name . '"');
if ($isTable) {
$sql = "INSERT into u_phone_follow_up_" . $site_id . "
(content,labels_id,user_id,agent_id,province,city,disc,type,create_time,update_time,user_status )
select content,labels_id,user_id,agent_id,province,city,disc,type,create_time,update_time,user_status
from `" . $table_name . "`";
$followUpModel = new UPhoneFollowUp($site_id);
if (false !== $followUpModel->execute($sql)) {
$this->redis_->set("is_run_" . $date . "_" . $site_id, 1, 24 * 3600);
}
}
}
}
}
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