Files
2022-09-08 09:25:59 +08:00

146 lines
5.7 KiB
PHP

<?php
/**
* 客户
*/
class Customers_entity
{
private $ci;
private $level = [3 => 'H', 7 => 'A', 15 => 'B', 30 => 'C'];
public function __construct()
{
$this->ci = &get_instance();
}
/**
* Notes:添加日志/更新客户已跟进
* Created on: 2021/11/2 14:10
* Created by: dengbw
* @param $customer_id
* @param $uid
* @param $uname
* @param $content
* @param string $type
* @param int $visit
* @param array $imgs
* @param string $cf_platform
* @return mixed
*/
public function add_log_visit($customer_id, $uid, $uname, $content, $type = '', $visit = 0, $imgs = [], $cf_platform = 'wxapp')
{
$result = '';
if ($content) {
$result = $this->add_log($customer_id, $uid, $uname, $content, $type, $cf_platform, $imgs);
}
if ($visit && ($result || !$content)) {//更新客户已跟进
if ($type == 1 || $type == 2) {//1发短信2拨打号码 不算入已跟进
return $result;
}
//更新已更进状态
$this->ci->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData');
$result = $this->ci->mdCustomerVisitData->update(['status' => 2], ['c_id' => $customer_id,
'sales_id' => $uid, 't_day' => date('Y-m-d')]);
}
return $result;
}
/**
* Notes:添加日志
* Created on: 2022/6/28 10:09
* Created by: dengbw
* @param $customer_id 客户id
* @param $uid 操作用户id
* @param $uname 操作用户名
* @param $content 日志内容
* @param string $type 操作类型 (0普通日志 1短信 2拨打电话)
* @param string $cf_platform 来源 (wxapp小程序 admin后台)
* @param array $imgs 日志图片
* @param string $c_time 创建日期
* @return string
*/
public function add_log($customer_id, $uid, $uname, $content, $type = '', $cf_platform = 'wxapp', $imgs = [], $c_time = '')
{
$this->ci->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
if ($type == 4 || $type == 5) {//到店或试驾,一天只记录一次
$day = date('Y-m-d');
$re = $this->ci->customer_oplogs_model->get(['customer_id' => $customer_id, 'type' => $type,
'c_time >=' => strtotime($day . ' 00:00:00'), 'c_time <=' => strtotime($day . ' 23:59:59')]);
if ($re) {
return '';
}
}
if ($type == 6 || $type == 7) {//生成订单或战败客户删除回访记录
$this->ci->load->model('receiver/receiver_customers_visit_data_model', 'mdCustomerVisitData');
$this->ci->mdCustomerVisitData->delete(['c_id' => $customer_id, 'status<>' => 2, 't_day >=' => date('Y-m-d')]);
}
if ($type == 6) {//订单客户
$count_4 = $this->ci->customer_oplogs_model->count(['customer_id' => $customer_id, 'type' => 4]);
if (!$count_4) {//无到店日志
$this->ci->load->model('receiver/receiver_customers_model', 'mdCustomers');
$re_cus = $this->ci->mdCustomers->get(['id' => $customer_id]);
if ($re_cus['status'] == 0) {
$up_data = ['status' => 1, 'a_num' => 1, 'cont_time' => date('Y-m-d H:i:s')];//改成到店客户
if ($re_cus['dt_time'] == '0000-00-00 00:00:00') {//首次到店时间
$up_data['dt_time'] = date('Y-m-d H:i:s');
}
$this->ci->mdCustomers->update($up_data, ['id' => $customer_id]);
$this->add_log($customer_id, $uid, $uname, '客户到店', 4);
} else if ($re_cus['status'] == 1) {
$up_data['a_num = a_num+1'] = null;
$this->ci->mdCustomers->update($up_data, ['id' => $customer_id]);
$this->add_log($customer_id, $uid, $uname, '客户再次到店', 4);
}
}
}
$add_data = [
'customer_id' => $customer_id,
'uid' => $uid,
'c_time' => $c_time ? $c_time : time()
];
$content && $add_data['log'] = $content;
$uname && $add_data['uname'] = $uname;
$type && $add_data['type'] = $type;
$cf_platform && $add_data['cf_platform'] = $cf_platform;
$imgs && $add_data['imgs'] = json_encode($imgs, JSON_UNESCAPED_UNICODE);
$result = $this->ci->customer_oplogs_model->add($add_data);
if (($type == 2 || $type == 1) && $result) { //更新最后联系时间
$this->ci->load->model('receiver/receiver_customers_model');
$this->ci->receiver_customers_model->update(['cont_time' => date('Y-m-d H:i:s')], ['id' => $customer_id]);
}
return $result;
}
/**
* 购车时间计算用户等级
* @param $buy_time int 预计购车天数
*/
public function cal_level($buy_time)
{
if ($this->level[$buy_time]) {
$level = $this->level[$buy_time];
} else {
$level = 'C';
}
return $level;
}
/**
* 同步线索日志到客户日志
* @param $customer_id int 客户id
* @param $clue_id int 线索id
*/
public function syn_clues($customer_id, $clue_id)
{
$sql = "insert into lc_receiver_customer_oplogs (customer_id,cf_platform,c_time,uid,uname,type,log) select {$customer_id},'admin',c_time,uid,uname,type,log from lc_receiver_clue_oplogs where clue_id={$clue_id}";
$this->ci->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
$this->ci->customer_oplogs_model->db->query($sql);
return $this->ci->customer_oplogs_model->db->affected_rows();
}
}
?>