api_licheb_1102_2

This commit is contained in:
dengbw
2021-11-02 14:49:22 +08:00
parent 2542dc14d7
commit 20a447aeda
5 changed files with 93 additions and 56 deletions
+2 -6
View File
@@ -93,12 +93,8 @@ class Xzcall extends HD_Controller
$cust = $this->customers_model->get(['id' => $row['cf_id']]);
}
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2);
if ($row['cf_title'] == 'customer') {//更新客户已回访
$this->load->model('receiver/receiver_customers_visit_model', 'mdCustomersVisit');
$this->mdCustomersVisit->update(array('contact' => 2, 'status' => 2)
, array('c_id' => $row['cf_id'], 'contact' => 1, 'status' => 1));
}
$visit = $row['cf_title'] == 'customer' ? 1 : 0;
$this->customers_entity->add_log_visit($cust['id'], $row['cf_uid'], $data['uname'], $row['id'], 2,$visit);
}
} else {
debug_log("error: 未找到拨打记录", $this->log_file);
+34 -29
View File
@@ -7,23 +7,27 @@ defined('WXAPP_APP') OR exit('No direct script access allowed');
* Date: 2021/06/23
* Time: 14:08
*/
require_once APPPATH.'controllers/wxapp/Wxapp.php';
class Customerlogs extends Wxapp{
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
function __construct($inputs, $app_key){
class Customerlogs extends Wxapp
{
function __construct($inputs, $app_key)
{
parent::__construct($inputs, $app_key);
$this->login_white = array();//登录白名单
$this->check_status = array();//用户状态校验
$this->check_mobile = array();//需要手机号
$this->check_headimg =array();//授权微信信息
$this->check_headimg = array();//授权微信信息
$this->load->model('receiver/receiver_customers_model','customers_model');
$this->load->model('receiver/receiver_customer_oplogs_model','customer_oplogs_model');
$this->load->model('receiver/receiver_customers_model', 'customers_model');
$this->load->model('receiver/receiver_customer_oplogs_model', 'customer_oplogs_model');
$this->load->model('receiver/receiver_xz_model');
}
protected function get(){
protected function get()
{
$uid = $this->session['uid'];
$id = $this->input_param('id');
$page = $this->input_param('page');
@@ -36,32 +40,32 @@ class Customerlogs extends Wxapp{
];
$count = $this->customer_oplogs_model->count($where);
$lists = [];
if($count){
$rows = $this->customer_oplogs_model->select($where,'id desc',$page,$size,'log,uname,type,c_time,imgs');
foreach($rows as $key => $val){
if ($count) {
$rows = $this->customer_oplogs_model->select($where, 'id desc', $page, $size, 'log,uname,type,c_time,imgs');
foreach ($rows as $key => $val) {
$record = '';
$second = 0;
$content = $val['log'];
$img_json = json_decode($val['imgs'],true);
$img_json = json_decode($val['imgs'], true);
$imgs = [];
if($img_json){
foreach($img_json as $val2){
if ($img_json) {
foreach ($img_json as $val2) {
$imgs[] = build_qiniu_image_url($val2);
}
}
if($val['type']==2){
$rec_row = $this->receiver_xz_model->get(['id'=>$val['log']],'rec_url,duration');
if ($val['type'] == 2) {
$rec_row = $this->receiver_xz_model->get(['id' => $val['log']], 'rec_url,duration');
$content = '拨打电话';
!$rec_row['duration'] && $content .= '(未接通)';
$rec_row['rec_url'] && $record = $rec_row['rec_url'];
$rec_row['duration'] && $second = intval($rec_row['duration']/1000);
$rec_row['duration'] && $second = intval($rec_row['duration'] / 1000);
}
$lists[] = [
'content' => "{$val['uname']}".$content,
'content' => "{$val['uname']}" . $content,
'record_url' => $record,
'second' => $second,
'imgs' => $imgs,
'c_time' => date('Y.m.d',$val['c_time'])
'c_time' => date('Y.m.d', $val['c_time'])
];
}
}
@@ -69,17 +73,17 @@ class Customerlogs extends Wxapp{
'list' => $lists,
'total' => $count
];
if($page == 1){ //获取统计数据
$row = $this->customers_model->get(['id'=>$id]);
if ($page == 1) { //获取统计数据
$row = $this->customers_model->get(['id' => $id]);
$statistics = [
[
'name' => '去电',
'val' => $this->customer_oplogs_model->count(['customer_id'=>$id,'type'=>2]),
'val' => $this->customer_oplogs_model->count(['customer_id' => $id, 'type' => 2]),
'color' => '#f3f6fc',
],
[
'name' => '短信',
'val' => $this->customer_oplogs_model->count(['customer_id'=>$id,'type'=>1]),
'val' => $this->customer_oplogs_model->count(['customer_id' => $id, 'type' => 1]),
'color' => '#fffaeb',
],
[
@@ -96,20 +100,21 @@ class Customerlogs extends Wxapp{
$data['statistics'] = $statistics;
}
return $data;
}
}
protected function post(){
protected function post()
{
$id = $this->input_param('cus_id');
$log = trim($this->input_param('content'));
$img_arr = $this->input_param('imgs');
if(!$log && !$img_arr){
if (!$log && !$img_arr) {
throw new Exception('参数错误', ERR_PARAMS_ERROR);
}
$this->load->library('receiver/customers_entity');
$result = $this->customers_entity->add_log($id,$this->session['uid'],$this->session['uname'],$log,'','wxapp',$img_arr);
if($result){
$result = $this->customers_entity->add_log_visit($id, $this->session['uid'], $this->session['uname'], $log, 0, 1, $img_arr);
if ($result) {
throw new Exception('修改成功', API_CODE_SUCCESS);
}else{
} else {
throw new Exception('修改失败', ERR_PARAMS_ERROR);
}
}
+4 -2
View File
@@ -311,7 +311,8 @@ class Customers extends Wxapp
$msg = '到店+1';
$log = $log ? $log . ',' . $msg : $msg;
}
$this->customers_entity->add_log($id, $uid, $this->session['uname'], $log);
$visit = $status == 2 ? 1 : 0;//变成订单客户,更新客户已回访
$this->customers_entity->add_log_visit($id, $uid, $this->session['uname'], $log,0,$visit);
}
}
if ($result) {
@@ -691,7 +692,8 @@ class Customers extends Wxapp
$ret = $this->customers_model->update($update, ['id' => $id]);
if ($ret) {
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($id, $this->session['uid'], $this->session['uname'], $log);
$visit = $update['status'] == 3 ? 1 : 0;
$this->customers_entity->add_log_visit($id, $this->session['uid'], $this->session['uname'], $log,0,$visit);
throw new Exception('操作成功', API_CODE_SUCCESS);
}
throw new Exception('操作失败', ERR_PARAMS_ERROR);
+3 -3
View File
@@ -54,7 +54,7 @@ class Sms extends Wxapp{
$uid = $this->session['uid'];
$id = $this->input_param('id');
$content = $this->input_param('content');
$content = trim($this->input_param('content'));
$row = $this->customers_model->get(['id'=>$id]);
if(!$row || !$content){
@@ -65,9 +65,9 @@ class Sms extends Wxapp{
}
$mobile = $row['mobile'];
$content = '【狸车】'.$content;
b2m_send_sms($mobile,$content);
b2m_send_sms($mobile,$content);
$this->load->library('receiver/customers_entity');
$this->customers_entity->add_log($id,$uid,$this->session['uname'],$content,1);
$this->customers_entity->add_log_visit($id,$uid,$this->session['uname'],$content,1,1);
throw new Exception('短信发送成功', API_CODE_SUCCESS);
}
//通过订单发短信
+50 -16
View File
@@ -3,13 +3,41 @@
/**
* 客户
*/
class Customers_entity{
class Customers_entity
{
private $ci;
private $ci;
private $level = [3=>'H',7=>'A',15=>'B',30=>'C'];
public function __construct(){
$this->ci = & get_instance();
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 = $this->add_log($customer_id, $uid, $uname, $content, $type, $cf_platform, $imgs);
if ($visit && $result) {//更新客户已回访
$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;
}
/**
@@ -21,8 +49,9 @@ class Customers_entity{
* @param $type int 操作类型 (0普通日志 1短信 2拨打电话)
* @param $cf_platform string 来源 (wxapp小程序 admin后台)
*/
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');
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');
$add_data = [
'customer_id' => $customer_id,
'uid' => $uid,
@@ -32,37 +61,42 @@ class Customers_entity{
$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);
$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){ //更新最后联系时间
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]);
$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]){
public function cal_level($buy_time)
{
if ($this->level[$buy_time]) {
$level = $this->level[$buy_time];
}else{
} else {
$level = 'C';
}
return $level;
}
/**
* 同步线索日志到客户日志
* @param $customer_id int 客户id
* @param $clue_id int 线索id
*/
public function syn_clues($customer_id,$clue_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->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();
return $this->ci->customer_oplogs_model->db->affected_rows();
}
}
?>