313 lines
14 KiB
PHP
313 lines
14 KiB
PHP
<?php
|
||
defined('WXAPP_APP') or exit('No direct script access allowed');
|
||
require_once APPPATH . 'controllers/wxapp/Wxapp.php';
|
||
|
||
class Score extends Wxapp
|
||
{
|
||
|
||
function __construct($inputs, $app_key)
|
||
{
|
||
parent::__construct($inputs, $app_key);
|
||
$this->load->model('receiver/receiver_score_config_model');
|
||
$this->load->model('receiver/receiver_score_day_model');
|
||
$this->load->model('receiver/receiver_score_month_model');
|
||
$this->load->model('receiver/receiver_score_log_model');
|
||
$this->load->model('app/licheb/app_licheb_users_model');
|
||
$this->load->model('receiver/receiver_customers_model', 'customers_model');
|
||
$this->load->model('receiver/order/receiver_orders_model', 'orders_model');
|
||
$this->load->model('receiver/receiver_score_avg_day_model');
|
||
$this->biz_id = $this->get_biz_id();
|
||
$this->group_id = $this->session['group_id'];
|
||
}
|
||
|
||
/**
|
||
* @return array
|
||
*/
|
||
protected function get()
|
||
{
|
||
$max_score = 100; //最高得分
|
||
$uid = $this->session['uid'];
|
||
$show_biz = false;
|
||
$type = $this->input_param('type'); // 0个人 1门店
|
||
$day_type = $this->input_param('day_type'); // 默认0昨天 1上月
|
||
if ($this->group_id == App_licheb_users_model::GROUP_BIZ && $type) { //店长可查看个人或门店
|
||
$show_biz = true;
|
||
} elseif ($this->group_id == App_licheb_users_model::GROUP_INVESTOR || $this->group_id == App_licheb_users_model::GROUP_CUSTOMER_MANAGER) { //投资人和客户成功经理 只能查看门店
|
||
$show_biz = true;
|
||
}
|
||
$where = [
|
||
'biz_id' => $this->biz_id
|
||
];
|
||
if (!$show_biz) {//查看个人
|
||
$where['uid'] = $uid;
|
||
}
|
||
if ($day_type == 1) { //本月
|
||
$where['day'] = date('Y-m-d');
|
||
$where['type'] = $type ? Receiver_score_avg_day_model::TYPE_BIZ : Receiver_score_avg_day_model::TYPE_USER;
|
||
$row = $this->receiver_score_avg_day_model->get($where);
|
||
$up_time = date('Y-m-d');
|
||
$title_hd = '较上日';
|
||
} elseif ($day_type == 2) {
|
||
$up_month = strtotime("-1 month"); //上个月时间
|
||
$where['year'] = date('Y', $up_month);
|
||
$where['month'] = date('m', $up_month);
|
||
$where['type'] = $type ? Receiver_score_month_model::TYPE_BIZ : Receiver_score_month_model::TYPE_USER;
|
||
$row = $this->receiver_score_month_model->get($where);
|
||
$up_time = date('Y-m-01', time());
|
||
$title_hd = '较上月';
|
||
} else {
|
||
$up_month = strtotime("-1 day");
|
||
$where['day'] = date('Y-m-d', $up_month);
|
||
$where['type'] = $type ? Receiver_score_day_model::TYPE_BIZ : Receiver_score_day_model::TYPE_USER;
|
||
$row = $this->receiver_score_day_model->get($where);
|
||
$up_time = date('Y-m-d', $up_month);
|
||
$title_hd = '较上一日';
|
||
}
|
||
$score = ceil($row['score']) ?: 0;
|
||
$abs_score = ceil($row['change_score']) ?: 0;
|
||
if ($abs_score >= 0) {
|
||
$title = $title_hd . "提升{$abs_score}分";
|
||
$score_trend = 1;
|
||
} else {
|
||
$abs_score = abs($abs_score);
|
||
$title = $title_hd . "下降{$abs_score}分";
|
||
$score_trend = 2;
|
||
}
|
||
$percentage = $score / $max_score * 100;
|
||
$score_list = [];
|
||
if (!$day_type && !$show_biz) { //个人且非查看门店
|
||
$scoreLogModel = new receiver_score_log_model();
|
||
$day = date('Y-m-d', strtotime("-1 day"));
|
||
$base_list = Receiver_score_config_model::TYPE_LIST;
|
||
foreach ($base_list as $key => $item) {
|
||
$where = [
|
||
'biz_id' => $this->biz_id,
|
||
'uid' => $uid,
|
||
'day' => $day,
|
||
'type' => $key
|
||
];
|
||
$scoreSum = $scoreLogModel->sum('score', $where);
|
||
$operator = '';
|
||
if ($key > 0) {
|
||
$operator = $scoreSum['operator'] >= 0 ? '+' : '-';
|
||
}
|
||
if ($key == Receiver_score_config_model::TYPE_DEDUCT) {
|
||
$operator = '-';
|
||
}
|
||
$score_list[] = [
|
||
'name' => $item['name'],
|
||
'value' => $scoreSum['score'] ? abs(ceil($scoreSum['score'])) : 0,
|
||
'operator' => $operator
|
||
];
|
||
}
|
||
}
|
||
|
||
if($type){
|
||
$desc = "<p><h3>门店运营分</h3></p>
|
||
<p> 门店运营分是通过统计每日店长及车管家的运营分加权平均后得出的分值,运营分按天每日更新,店内人均分数越高,门店的运营分越高。</p><br/>";
|
||
}else{
|
||
$desc = "<p><h3>如何提升运营分?</h3></p>
|
||
<p> 运营分是根据个人在理车宝的基础分、线索分、订单分等方面综合计算得出的分值,运营分按天每日更新,可通过以下方式提升运营分:</p><br/>
|
||
<p><b>基础分:</b>每日初始基本分为50分,当日登录理车宝进行信息查询、线索跟进等操作即视为开工,可再得10分。</p><br/>
|
||
<p><b>线索分:</b>录入线索并且按要求完善信息,无论是平台分配还是自录线索都按时跟进回访并做好小记,尽可能添加客户微信并上传截图,使用系统提供的虚拟电话联系客户留存回访录音以便复盘。
|
||
单条线索不因重复动作而多次加分,分值次日更新,每日新增/跟进的线索越多,线索分越多。</p><br/>
|
||
<p><b>订单分:</b>新增订单并且按要求完善信息,上传相关资料。产生订单时应及时录入系统,否则会因订单时间逻辑不符而导致扣分。分值次日更新,新增订单越多,相关资料上传越完善,订单分越多。</p><br/>
|
||
<p><b>扣分:</b>理车宝使用过程,未按规范要求操作,将会导致运营分被扣。</p><p>具体如下:</p>
|
||
<p>* 线索逾期未跟进;</p>
|
||
<p>* 店长分配线索后未及时跟进,时间超过15分钟;</p>
|
||
<p>* 线索未提前录入,与下单时间间隔少于T+1;</p>
|
||
<p>* 订单未及时录入,导致开票时间早于订单录入时间;</p>
|
||
<p>* 平台下发线索,分配时间超过10分钟[店长];</p>
|
||
<p>* 战败申请当日未处理[店长];</p>";
|
||
}
|
||
|
||
return [
|
||
'score' => $score,
|
||
'percentage' => $percentage,
|
||
'title' => $title,
|
||
'sub_title' => '当前显示为昨日运营情况评分',
|
||
'u_time_text' => "*更新于" . $up_time,
|
||
'score_trend' => $score_trend, //控制样式:1 上升 、2 下降
|
||
'desc' => $desc,
|
||
'score_list' => $score_list
|
||
];
|
||
}
|
||
|
||
/**
|
||
* 获取分数排行
|
||
* @return array
|
||
*/
|
||
public function get_lists()
|
||
{
|
||
$type = $this->input_param('type'); // 默认0店内排行 1门店排行
|
||
$day_type = $this->input_param('day_type'); // 默认0昨天 1本月 2上月
|
||
$limit = $type ? 100 : 10;
|
||
if ($day_type == 1) {
|
||
$result = Receiver_score_avg_day_model::getTopLists($type, $this->biz_id, $limit);
|
||
} elseif ($day_type == 2) {
|
||
$result = Receiver_score_month_model::getTopLists($type, $this->biz_id, $limit);
|
||
} else {
|
||
$result = Receiver_score_day_model::getTopLists($type, $this->biz_id, $limit);
|
||
}
|
||
return [
|
||
'lists' => $result['lists'],
|
||
'day' => $result['day']
|
||
];
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @return array
|
||
*/
|
||
public function get_detail()
|
||
{
|
||
$uid = $this->session['uid'];
|
||
$base_list = Receiver_score_config_model::TYPE_LIST;
|
||
$day = date('Y-m-d', strtotime("-1 day"));
|
||
$where = [
|
||
'day' => $day,
|
||
'type' => Receiver_score_day_model::TYPE_USER,
|
||
'uid' => $uid,
|
||
'biz_id' => $this->biz_id
|
||
];
|
||
$dayRow = $this->receiver_score_day_model->get($where);
|
||
$user_score = $dayRow['score'] ? ceil($dayRow['score']) : 0;
|
||
$change_score = $dayRow['change_score'] ? ceil($dayRow['change_score']) : 0;
|
||
$up_data_score = $change_score;
|
||
$score_trend = 1;
|
||
if ($up_data_score >= 0) {
|
||
$change_text = '较上一日提升' . $up_data_score . '分';
|
||
} else {
|
||
$change_text = '较上一日下降' . abs($up_data_score) . '分';
|
||
$score_trend = 2;
|
||
}
|
||
$data = [];
|
||
if ($base_list) {
|
||
$scoreLogModel = new receiver_score_log_model();
|
||
foreach ($base_list as $key => $item) {
|
||
$where = [
|
||
'biz_id' => $this->biz_id,
|
||
'uid' => $uid,
|
||
'day' => $day,
|
||
'type' => $key
|
||
];
|
||
$scoreSum = $scoreLogModel->sum('score', $where);
|
||
$score = $scoreSum['score'] ? ceil($scoreSum['score']) : 0;
|
||
$trend = $score >= 0 ? 1 : 2;
|
||
$data_list = Receiver_score_log_model::getUserLogLists($this->biz_id, $uid, $day, $key);
|
||
$data[] = [
|
||
'name' => $item['name'],
|
||
'score' => $score,
|
||
'trend' => $trend,
|
||
'data' => $data_list
|
||
];
|
||
}
|
||
}
|
||
return ['data' => $data, 'score' => $user_score, 'up_data_score' => $up_data_score, 'change_text' => $change_text, 'score_trend' => $score_trend];
|
||
}
|
||
|
||
public function get_radar()
|
||
{
|
||
$day_type = $this->input_param('day_type'); // 默认0昨天 1本月 2上月
|
||
if($day_type==2){
|
||
$s_time = date('Y-m-01 00:00:00', strtotime('last month'));
|
||
$e_time = date('Y-m-t 23:59:59', strtotime('last month'));
|
||
}elseif($day_type==1){
|
||
$s_time = date('Y-m-01 00:00:00');
|
||
$e_time = date('Y-m-d 23:59:59');
|
||
}else{
|
||
$s_time = date('Y-m-d 00:00:00',strtotime("-1 day"));
|
||
$e_time = date('Y-m-d 23:59:59',strtotime("-1 day"));
|
||
}
|
||
|
||
$ts_s_time = strtotime($s_time);
|
||
$ts_e_time = strtotime($e_time);
|
||
|
||
$biz = (new Biz_model())->get(['id' => $this->biz_id]);
|
||
$province_id = $biz['province_id'];
|
||
$bizs = (new Biz_model())->select(['province_id' => $province_id, 'status' => 1]);
|
||
$biz_id_arr = implode(',', array_unique(array_column($bizs, 'id')));
|
||
!$biz_id_arr && $biz_id_arr = 0;
|
||
$biz_count = count($bizs);
|
||
|
||
$names = [ '拓客能力', '跟进能力', '邀约能力', '成交能力', '交付能力'];
|
||
$series_value = [];
|
||
$max_total = [];
|
||
$indicator = [];
|
||
|
||
//拓客能力
|
||
$where_max = $where = [
|
||
'status>=' => 0,
|
||
'of_id' => 3,
|
||
'c_time >=' => $ts_s_time,
|
||
'c_time <=' => $ts_e_time,
|
||
];
|
||
$where_max["biz_id in ($biz_id_arr)"] = null;
|
||
$max = $this->customers_model->count($where_max);
|
||
$where['biz_id'] = $this->biz_id;
|
||
$value = $this->customers_model->count($where);
|
||
$series_value[] = $value ? $value : 1;
|
||
$max_total[] = $max > $biz_count ? ceil($max/$biz_count)*5 : 10 ;
|
||
|
||
//跟进能力
|
||
$where_max = $where = [
|
||
'status>=' => 0,
|
||
"id in (select DISTINCT customer_id from lc_receiver_customer_oplogs where c_time>={$ts_s_time} and c_time<={$ts_e_time} and cf_platform like 'wxapp' and log like '跟进方式%')" => null
|
||
];
|
||
$where_max["biz_id in ($biz_id_arr)"] = null;
|
||
$max = $this->customers_model->count($where_max);
|
||
$where['biz_id'] = $this->biz_id;
|
||
$value = $this->customers_model->count($where);
|
||
$series_value[] = $value ? $value : 1;
|
||
$max_total[] = $max > $biz_count ? ceil($max/$biz_count)*5 : 10 ;
|
||
|
||
//邀约能力
|
||
$where_max = $where = [
|
||
'status>=' => 0,
|
||
'dt_time >=' => $s_time,
|
||
'dt_time <=' => $e_time,
|
||
];
|
||
$where_max["biz_id in ($biz_id_arr)"] = null;
|
||
$max = $this->customers_model->count($where_max);
|
||
$where['biz_id'] = $this->biz_id;
|
||
$value = $this->customers_model->count($where);
|
||
$series_value[] = $value ? $value : 1;
|
||
$max_total[] = $max > $biz_count ? ceil($max/$biz_count)*5 : 10 ;
|
||
|
||
//成交能力
|
||
$where_max = $where = [
|
||
'status>=' => 0,
|
||
'order_time >=' => $s_time,
|
||
'order_time <=' => $e_time,
|
||
];
|
||
$where_max["biz_id in ($biz_id_arr)"] = null;
|
||
$max = $this->orders_model->count($where_max);
|
||
$where["biz_id"] = $this->biz_id;
|
||
$value = $this->orders_model->count($where);
|
||
$series_value[] = $value ? $value : 1;
|
||
$max_total[] = $max > $biz_count ? ceil($max/$biz_count)*5 : 10 ;
|
||
|
||
//交付能力
|
||
$where_max = $where = [
|
||
'status>=' => 0,
|
||
'over_time >=' => $s_time,
|
||
'over_time <=' => $e_time,
|
||
];
|
||
$where_max["biz_id in ($biz_id_arr)"] = null;
|
||
$max = $this->orders_model->count($where_max);
|
||
$where["biz_id"] = $this->biz_id;
|
||
$value = $this->orders_model->count($where);
|
||
$series_value[] = $value ? $value : 1;
|
||
$max_total[] = $max > $biz_count ? ceil($max/$biz_count)*5 : 10 ;
|
||
|
||
foreach ($names as $key => $value) {
|
||
$indicator[] = array('name' => $value, 'max' => $max_total[$key]);
|
||
}
|
||
|
||
$data = [
|
||
'indicator' => $indicator,
|
||
'series_value' => $series_value
|
||
];
|
||
return $data;
|
||
}
|
||
} |