Files
liche/common/libraries/receiver/Customers_entity.php
T
2022-04-14 14:11:38 +08:00

118 lines
4.0 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)) {//更新客户已回访
$this->ci->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
$result = $this->ci->mdCustomersVisit->update(array('contact' => 2, 'status' => 2)
, array('c_id' => $customer_id, 'contact' => 1, 'status' => 1));
}
return $result;
}
/**
* Notes:添加日志
* Created on: 2022/4/13 11:57
* 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 日志图片
* @return string
*/
public function add_log($customer_id, $uid, $uname, $content, $type = '', $cf_platform = 'wxapp', $imgs = [])
{
$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 '';
}
}
$add_data = [
'customer_id' => $customer_id,
'uid' => $uid,
'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();
}
}
?>