diff --git a/api/controllers/plan/Score.php b/api/controllers/plan/Score.php new file mode 100644 index 00000000..0485110d --- /dev/null +++ b/api/controllers/plan/Score.php @@ -0,0 +1,142 @@ +load->model('receiver/receiver_score_log_model'); + $this->load->model('receiver/receiver_score_config_model'); + $this->load->model('app/licheb/app_licheb_users_model'); + $this->load->library('receiver/score_entity'); + $this->load->model('receiver/receiver_score_day_model'); + } + + public function index() + { + $biz_id = $this->input->get('biz_id'); + $uid = $this->input->get('uid'); + $getPage = $this->input->get('page'); + $redis = &load_cache('redis'); + $pageCacheKey = "RECEIVER_SCORE_PLAN_PAGE"; + if ($getPage) { + $page = $getPage; + } else { + $page = $redis->get($pageCacheKey) ?: 1; + } + $size = 100; + $groups_string = implode(',', [App_licheb_users_model::GROUP_BIZ, App_licheb_users_model::GROUP_MANAGER]); + $where = [ + "group_id in ({$groups_string})" => null, + 'status' => 1 + ]; + $biz_id && $where['biz_id'] = $biz_id; + $uid && $where['id'] = $uid; + $rows = $this->app_licheb_users_model->select($where, "id desc", $page, $size, 'id, uname, biz_id'); + if ($rows) { + $day = date('Y-m-d', strtotime("-1 day")); + foreach ($rows as $item) { + $result = Score_entity::init($day, $item['id'], $item['group_id'], $item['biz_id']); + } + } else { + $msg = '执行完成'; + echo $msg; + debug_log("[info]# " . $msg, __FUNCTION__, $this->log_dir); + } + } + + //每日统计 + public function scoreDay() + { + $day = date('Y-m-d', strtotime("-1 day")); + $scoreLogModel = new Receiver_score_log_model(); + $receiverScoreDayModel = new Receiver_score_day_model(); + $redis = &load_cache('redis'); + $page = 1; + $size = 100; + $where = [ + 'day' => $day, + ]; + $rows = $scoreLogModel->select($where, "id desc", $page, $size, 'DISTINCT biz_id,uid,day'); + if ($rows) { + foreach ($rows as $item) { + $where = [ + 'biz_id' => $item['biz_id'], + 'uid' => $item['uid'], + 'day' => $day, + 'type' => Receiver_score_day_model::TYPE_USER + ]; + $scoreDayRow = $receiverScoreDayModel->get($where); + $scoreSum = $scoreLogModel->sum('score', ['uid' => $item['uid'], 'day' => $day]); + $score = $scoreSum ? $scoreSum['score'] : 0; + //获取上一天数据 + $where = [ + 'biz_id' => $item['biz_id'], + 'uid' => $item['uid'], + 'day<' => $day, + 'type' => Receiver_score_day_model::TYPE_USER + ]; + $dayRow = $receiverScoreDayModel->select($where, 'day desc', 1, 1, 'score'); + $change_score = $dayRow[0]['score'] ? $score - $dayRow[0]['score'] : $score; + if ($scoreDayRow) { + $receiverScoreDayModel->update(['score' => $score, 'change_score' => $change_score], ['id' => $scoreDayRow['id']]); + } else { + $addData = [ + 'biz_id' => $item['biz_id'], 'uid' => $item['uid'], + 'score' => $score, 'day' => $day, 'type' => Receiver_score_day_model::TYPE_USER, + 'change_score' => $change_score, 'c_time' => time() + ]; + $receiverScoreDayModel->add($addData); + } + } + } else { //合并门店数据 + $this->scoreBizDay($day); + } + } + + public function scoreBizDay($day) + { + $receiverScoreDayModel = new Receiver_score_day_model(); + $redis = &load_cache('redis'); + $page = 1; + $size = 100; + $where = [ + 'day' => $day, + 'type' => Receiver_score_day_model::TYPE_USER + ]; + $rows = $receiverScoreDayModel->select($where, "id desc", $page, $size, 'DISTINCT biz_id,day'); + if ($rows) { + foreach ($rows as $item) { + $where = [ + 'biz_id' => $item['biz_id'], + 'day' => $day, + 'type' => Receiver_score_day_model::TYPE_BIZ + ]; + $scoreDayRow = $receiverScoreDayModel->get($where); + $scoreSum = $receiverScoreDayModel->sum('score', ['biz_id' => $item['biz_id'], 'day' => $day]); + $score = $scoreSum ? $scoreSum['score'] : 0; + //获取上一天数据 + $where = [ + 'biz_id' => $item['biz_id'], + 'day<' => $day, + 'type' => Receiver_score_day_model::TYPE_BIZ + ]; + $dayRow = $receiverScoreDayModel->select($where, 'day desc', 1, 1, 'score'); + $change_score = $dayRow[0]['score'] ? $score - $dayRow[0]['score'] : $score; + if ($scoreDayRow) { + $receiverScoreDayModel->update(['score' => $score, 'change_score' => $change_score], ['id' => $scoreDayRow['id']]); + } else { + $addData = [ + 'biz_id' => $item['biz_id'], 'uid' => $item['uid'], + 'score' => $score, 'day' => $day, 'type' => Receiver_score_day_model::TYPE_USER, + 'change_score' => $change_score, 'c_time' => time() + ]; + $receiverScoreDayModel->add($addData); + } + } + } + } +} \ No newline at end of file diff --git a/api/controllers/wxapp/Wxapp.php b/api/controllers/wxapp/Wxapp.php index 539dac27..29cd69e8 100644 --- a/api/controllers/wxapp/Wxapp.php +++ b/api/controllers/wxapp/Wxapp.php @@ -101,6 +101,8 @@ abstract class Wxapp extends HD_Controller //获取session $this->fetch_session(); + //请求接口就算开工-增加基础分(一天只能算一次) + $this->add_user_score(); } /** @@ -537,4 +539,24 @@ abstract class Wxapp extends HD_Controller { return $this->session['new_biz_id'] ? $this->session['new_biz_id'] : intval($this->session['biz_id']); } + + //添加积分 + protected function add_user_score() + { + $redis = &load_cache('redis'); + $cache_key = "RECEIVER_SCORE_LOG_API_{$this->session['uid']}"; + if ($redis->get($cache_key)) { + return false; + } + if (in_array($this->session['group_id'], [App_licheb_users_model::GROUP_BIZ, App_licheb_users_model::GROUP_MANAGER])) { + $this->load->model('receiver/receiver_score_log_model'); + $this->load->model('receiver/receiver_score_config_model'); + $scoreLogModel = new receiver_score_log_model(); + $day = date('Y-m-d'); + $scoreLogModel->add_score($this->session['uid'], $this->get_biz_id(), $day, Receiver_score_config_model::TYPE_BASE, + Receiver_score_config_model::TYPE_BASE_KG, '请求接口', 1); + $redis->save($cache_key, 1, 60 * 60); + } + return true; + } } diff --git a/api/controllers/wxapp/licheb/Cusorderdata.php b/api/controllers/wxapp/licheb/Cusorderdata.php index 8d2892f2..8c9cedc8 100644 --- a/api/controllers/wxapp/licheb/Cusorderdata.php +++ b/api/controllers/wxapp/licheb/Cusorderdata.php @@ -10,6 +10,7 @@ require_once APPPATH . 'controllers/wxapp/Wxapp.php'; class Cusorderdata extends Wxapp { private $biz_id = ''; + function __construct($inputs, $app_key) { parent::__construct($inputs, $app_key); @@ -23,6 +24,7 @@ class Cusorderdata extends Wxapp $this->load->model('receiver/order/receiver_order_datas_model'); $this->load->model("biz/biz_model"); $this->load->model('app/licheb/app_licheb_users_model', 'app_user_model'); + $this->load->model('receiver/order/receiver_order_oplogs_model'); $this->load->library('receiver/order_datas_entity'); $this->load->library('TcOrc'); @@ -292,6 +294,16 @@ class Cusorderdata extends Wxapp // } // } // } + $log = array( + 'order_id' => $id, + 'uid' => $this->session['uid'], + 'uname' => $this->session['uname'], + 'type' => 1, + 'log' => $key, + 'cf_platform' => 'wxapp', + 'c_time' => time(), + ); + $this->receiver_order_oplogs_model->add($log); throw new Exception('修改成功', API_CODE_SUCCESS); } else { throw new Exception('修改失败', ERR_PARAMS_ERROR); diff --git a/api/controllers/wxapp/licheb/Customers.php b/api/controllers/wxapp/licheb/Customers.php index 598f7963..bc31f52d 100644 --- a/api/controllers/wxapp/licheb/Customers.php +++ b/api/controllers/wxapp/licheb/Customers.php @@ -364,6 +364,9 @@ class Customers extends Wxapp 'wxgrimg' => $wxgrimg ? $wxgrimg : '', 'c_time' => time() ]; + if($wxgr){ + $add_data['add_wx_time'] = date('Y-m-d H:i:s'); + } if (!$add_data['city_id'] && $biz_row['city_id']) { $add_data['city_id'] = $biz_row['city_id']; } @@ -547,6 +550,7 @@ class Customers extends Wxapp $jsondata['defeat']['time'] = date("Y-m-d H:i:s"); $jsondata['defeat']['reason'] = $defeat_reason . "({$tag_str})"; $up_data['if_defeat'] = 1; + $up_data['apply_def_time'] = date("Y-m-d H:i:s"); $up_data['jsondata'] = json_encode($jsondata, JSON_UNESCAPED_UNICODE); $log_0 = '申请战败:' . $defeat_reason . "({$tag_str})"; } else { diff --git a/api/controllers/wxapp/licheb/Score.php b/api/controllers/wxapp/licheb/Score.php new file mode 100644 index 00000000..b09f0643 --- /dev/null +++ b/api/controllers/wxapp/licheb/Score.php @@ -0,0 +1,159 @@ +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->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) { //上月 + $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) { //个人且非查看门店 + $score_list = [ + ['name' => '基础分', 'value' => 10, 'operator' => ''], + ['name' => '线索分', 'value' => 2, 'operator' => '+'], + ['name' => '订单分', 'value' => 10, 'operator' => '+'], + ['name' => '扣分项', 'value' => 0, 'operator' => '-'], + ]; + } + return [ + 'score' => $score, + 'percentage' => $percentage, + 'title' => $title, + 'sub_title' => '当前显示为昨日运营情况评分', + 'u_time_text' => "*更新于" . $up_time, + 'score_trend' => $score_trend, //控制样式:1 上升 、2 下降 + '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上月 + if ($day_type) { + $result = Receiver_score_month_model::getTopLists($type, $this->biz_id); + } else { + $result = Receiver_score_day_model::getTopLists($type, $this->biz_id); + } + 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 = $user_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, + ]; + $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]; + } +} \ No newline at end of file diff --git a/common/libraries/receiver/Score_entity.php b/common/libraries/receiver/Score_entity.php new file mode 100644 index 00000000..600c954d --- /dev/null +++ b/common/libraries/receiver/Score_entity.php @@ -0,0 +1,180 @@ +ci = &get_instance(); + $this->ci->load->model('receiver/receiver_score_config_model'); + $this->ci->load->model('receiver/receiver_score_log_model'); + $this->ci->load->model('receiver/receiver_customers_model'); + $this->ci->load->model('receiver/receiver_customer_oplogs_model'); + $this->ci->load->model('receiver/order/receiver_orders_model'); + $this->ci->load->model('receiver/order/receiver_order_oplogs_model'); + $this->ci->load->model('receiver/receiver_customers_visit_data_model'); + } + + /** + * @param $day + * @param $uid + * @param $biz_id + * @return true + */ + public static function init($day, $uid, $group_id, $biz_id) + { + $typeList = Receiver_score_config_model::TYPE_LIST; + foreach ($typeList as $k => $v) { + $type = $k; + if (is_array($v['sub_list'])) { + foreach ($v['sub_list'] as $k2 => $v2) { + $sub_type = $k2; + self::addLogByType($day, $uid, $group_id, $biz_id, $type, $sub_type); + } + } + } + exit; + return true; + } + + public static function addLogByType($day, $uid, $group_id, $biz_id, $type, $sub_type) + { + switch ($type) { + case Receiver_score_config_model::TYPE_BASE: //基础分 + if ($sub_type == Receiver_score_config_model::TYPE_BASE_KG) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, '接口请求默认值', 1, 0, 0); + } + break; + case Receiver_score_config_model::TYPE_CLUE: + $receiverCustomersModel = new Receiver_customers_model(); + if ($sub_type == Receiver_score_config_model::TYPE_CLUE_ADD) { //添加线索 + $where = [ + 'status>=' => 0, 'rid' => 0, 'sales_id' => $uid, 'biz_id' => $biz_id, + 'c_time>=' => strtotime($day . ' 00:00:00'), 'c_time<=' => strtotime($day . ' 23:59:59') + ]; + $rows = $receiverCustomersModel->select($where, '', 1, 1000, 'id'); + $desc = '新增线索'; + if ($rows) { + foreach ($rows as $val) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}:" . $val['id'], 2, $val['id']); + } + } else { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}默认值", 1, 0, 0); + } + } elseif ($sub_type == Receiver_score_config_model::TYPE_CLUE_ADD_WX) { //添加微信 + $receiverCustomerOplogsModel = new Receiver_customer_oplogs_model(); + $where = [ + 'uid' => $uid, 'type' => 10, + 'c_time>=' => strtotime($day . ' 00:00:00'), 'c_time<=' => strtotime($day . ' 23:59:59') + ]; + $rows = $receiverCustomerOplogsModel->select($where, '', 1, 1000, 'DISTINCT(customer_id)'); + $desc = '添加微信'; + if ($rows) { + foreach ($rows as $val) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}:" . $val['customer_id'], 2, $val['id']); + } + } else { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}默认值", 1, 0, 0); + } + } elseif ($sub_type == Receiver_score_config_model::TYPE_CLUE_ADD_GJ) { //跟进 + + } + break; + case Receiver_score_config_model::TYPE_ORDER: + if ($sub_type == Receiver_score_config_model::TYPE_ORDER_ADD) { //新增订单 + $receiverOrdersModel = new Receiver_orders_model(); + $where = [ + 'status>=' => 0, 'sale_id' => $uid, 'biz_id' => $biz_id, + 'c_time>=' => strtotime($day . ' 00:00:00'), 'c_time<=' => strtotime($day . ' 23:59:59') + ]; + $rows = $receiverOrdersModel->select($where, '', 1, 1000, 'id'); + $desc = '新增订单'; + if ($rows) { + foreach ($rows as $val) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}:" . $val['id'], 2, $val['id']); + } + } else { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}默认值", 1, 0, 0); + } + } elseif ($sub_type == Receiver_score_config_model::TYPE_ORDER_UPLOAD_DATA) { //订单上传资料 + $receiverOrderOplogModel = new Receiver_order_oplogs_model(); + $where = [ + 'uid' => $uid, 'type' => 1, + 'c_time>=' => strtotime($day . ' 00:00:00'), 'c_time<=' => strtotime($day . ' 23:59:59') + ]; + $rows = $receiverOrderOplogModel->select($where, '', 1, 1000, 'DISTINCT order_id,log'); + $desc = '上传资料'; + if ($rows) { + foreach ($rows as $val) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}:" . $val['customer_id'], 2, $val['log']); + } + } else { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}默认值", 1, 0, 0); + } + } + break; + case Receiver_score_config_model::TYPE_DEDUCT: + if ($sub_type == Receiver_score_config_model::TYPE_DEDUCT_CLUE_TIMEOUT) { + + } elseif ($sub_type == Receiver_score_config_model::TYPE_DEDUCT_BILL_TIMEOUT) { + $receiverOrdersModel = new Receiver_orders_model(); + $where = [ + 'status>=' => 0, 'sale_id' => $uid, 'biz_id' => $biz_id, + 'bill_time!=' => '0000-00-00 00:00:00', 'UNIX_TIMESTAMP( bill_time ) > c_time' => null, + 'u_time>=' => strtotime($day . ' 00:00:00'), 'u_time<=' => strtotime($day . ' 23:59:59') + ]; + $rows = $receiverOrdersModel->select($where, '', 1, 1000, 'id'); + $desc = '开票时间大于订单录入时间'; + if ($rows) { + foreach ($rows as $val) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}:" . $val['id'], 2, $val['id']); + } + } else { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}默认值", 1, 0, 0); + } + } elseif ($sub_type == Receiver_score_config_model::TYPE_DEDUCT_ORDER_CTIME) { + + } elseif ($sub_type == Receiver_score_config_model::TYPE_DEDUCT_VISIT_TIMEOUT) { + $mdCustomerVisitData = new receiver_customers_visit_data_model(); + $where = [ + "a.biz_id" => $biz_id, "a.cs_biz_id<>" => -1, + "a.status in(0,1)" => null, "b.t_day" => $day, + "b.status" => 1, "a.admin_id" => $uid + ]; + $rows = $mdCustomerVisitData->select_visit($where, 'a.id desc', 1, 100, 'a.id'); + $desc = '线索回访时间逾期未跟进'; + if ($rows) { + foreach ($rows as $val) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}:" . $val['id'], 2, $val['id']); + } + } else { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}默认值", 1, 0, 0); + } + } elseif ($sub_type == Receiver_score_config_model::TYPE_DEDUCT_P_TIME_TIMEOUT && $group_id == App_licheb_users_model::GROUP_BIZ) { + + } elseif ($sub_type == Receiver_score_config_model::TYPE_DEDUCT__TIMEOUT && $group_id == App_licheb_users_model::GROUP_BIZ) { + $receiverOrdersModel = new Receiver_orders_model(); + $where = [ + 'status>=' => 0, 'biz_id' => $biz_id, 'apply_def_time!=' => '0000-00-00 00:00:00', 'if_defeat' => 1, + 'apply_def_time>=' => strtotime($day . ' 00:00:00'), 'apply_def_time<=' => strtotime($day . ' 23:59:59') + ]; + $rows = $receiverOrdersModel->select($where, '', 1, 1000, 'id'); + $desc = '战败未处理'; + if ($rows) { + foreach ($rows as $val) { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}:" . $val['id'], 2, $val['id']); + } + } else { + Receiver_score_log_model::add_score($uid, $biz_id, $day, $type, $sub_type, "{$desc}默认值", 1, 0, 0); + } + } + break; + } + + return true; + } +} + +?> diff --git a/common/models/app/licheb/App_licheb_users_model.php b/common/models/app/licheb/App_licheb_users_model.php index 10309e92..3f485896 100644 --- a/common/models/app/licheb/App_licheb_users_model.php +++ b/common/models/app/licheb/App_licheb_users_model.php @@ -7,6 +7,11 @@ class App_licheb_users_model extends HD_Model private $group_arr = [1 => '车管家', 2 => '店长', 3 => '投资人', 4 => '客户成功经理']; + const GROUP_MANAGER = 1; // 车管家 + const GROUP_BIZ = 2; // 店长 + const GROUP_INVESTOR = 3; // 投资人 + const GROUP_CUSTOMER_MANAGER = 4; // 客户成功经理 + public function __construct() { parent::__construct($this->table_name, 'default'); diff --git a/common/models/receiver/Receiver_score_config_model.php b/common/models/receiver/Receiver_score_config_model.php new file mode 100644 index 00000000..fe037365 --- /dev/null +++ b/common/models/receiver/Receiver_score_config_model.php @@ -0,0 +1,68 @@ + ['name' => '基础分', 'sub_list' => self::TYPE_BASE_LIST], + self::TYPE_CLUE => ['name' => '线索分', 'sub_list' => self::TYPE_CLUE_LIST], + self::TYPE_ORDER => ['name' => '订单分', 'sub_list' => self::TYPE_ORDER_LIST], + self::TYPE_DEDUCT => ['name' => '扣分项', 'sub_list' => self::TYPE_DEDUCT_LIST], + ]; + // ==== 基础分子类型 ==== + const TYPE_BASE_KG = 0; + // ==== 线索分子类型 ==== + const TYPE_CLUE_ADD = 0; + const TYPE_CLUE_ADD_WX = 1; + const TYPE_CLUE_ADD_GJ = 2; + // ==== 订单分子类型 ==== + const TYPE_ORDER_ADD = 0; + const TYPE_ORDER_UPLOAD_DATA = 1; + // ==== 扣分项子类型 ==== + const TYPE_DEDUCT_CLUE_TIMEOUT = 0; + const TYPE_DEDUCT_BILL_TIMEOUT = 1; + const TYPE_DEDUCT_ORDER_CTIME = 2; + const TYPE_DEDUCT_VISIT_TIMEOUT = 3; + const TYPE_DEDUCT_P_TIME_TIMEOUT = 4; + const TYPE_DEDUCT__TIMEOUT = 5; + + const TYPE_BASE_LIST = [ + self::TYPE_BASE_KG => '正常开工', + ]; + const TYPE_CLUE_LIST = [ + self::TYPE_CLUE_ADD => '新增线索', + self::TYPE_CLUE_ADD_WX => '加微信', + self::TYPE_CLUE_ADD_GJ => '跟进(小计或打电话)', + ]; + const TYPE_ORDER_LIST = [ + self::TYPE_ORDER_ADD => '新增订单', + self::TYPE_ORDER_UPLOAD_DATA => '上传资料', + ]; + const TYPE_DEDUCT_LIST = [ + //车管家 + self::TYPE_DEDUCT_CLUE_TIMEOUT => '线索跟进时间大于10分钟', + self::TYPE_DEDUCT_BILL_TIMEOUT => '开票时间大于订单录入时间', + self::TYPE_DEDUCT_ORDER_CTIME => '线索创建时间和下单创建时间小于10分钟', + self::TYPE_DEDUCT_VISIT_TIMEOUT => '线索回访时间逾期未跟进', + //店长 + self::TYPE_DEDUCT_P_TIME_TIMEOUT => '分配派单时间大于10分钟', + self::TYPE_DEDUCT__TIMEOUT => '战败未处理当日扣分' + ]; + + const STATUS_NORMAL = 1; //正常状态 + + public function __construct() + { + parent::__construct($this->table_name, 'default'); + } + + +} diff --git a/common/models/receiver/Receiver_score_day_model.php b/common/models/receiver/Receiver_score_day_model.php new file mode 100644 index 00000000..0caf97a2 --- /dev/null +++ b/common/models/receiver/Receiver_score_day_model.php @@ -0,0 +1,63 @@ +table_name, 'default'); + $this->load->model('app/licheb/app_licheb_users_model'); + $this->load->model('biz/biz_model'); + } + + /** + * @param $type int 类型(0个人 1门店) + * @param $biz_id int 门店id + * @param $limit int 获取条数 + * @param $day string 排行日期 YYYY-MM-DD + * @return array + */ + public static function getTopLists($type, $biz_id = 0, $limit = 10, $day = '') + { + !$day && $day = date('Y-m-d', strtotime("-1 day")); + $where = []; + $where['day'] = $day; + if ($type) { + $where['type'] = self::TYPE_BIZ; + } else { + $where['biz_id'] = $biz_id; + $where['type'] = self::TYPE_USER; + } + $lists = []; + $rows = (new Receiver_score_day_model)->select($where, 'score desc', 1, $limit); + if ($rows) { + $userModel = new App_licheb_users_model(); + $groups = $userModel->get_group(); + foreach ($rows as $row) { + $tip = ''; + if ($type) { + $biz = (new Biz_model())->get(['id' => $row['biz_id']]); + $name = $biz['biz_name'] ?: ''; + } else { + $user = $userModel->get(['id' => $row['uid']]); + $name = $user['uname'] ?: ''; + $tip = $groups[$user['group_id']] ?: ''; + } + $lists[] = [ + 'name' => $name, + 'tip' => $tip, + 'trend' => $row['change_score'] >= 0 ? 1 : 2, //1 上升 、2 下降 + 'score' => ceil($row['score']) . '分' + ]; + } + } + return ['lists' => $lists, 'day' => $day]; + } +} diff --git a/common/models/receiver/Receiver_score_log_model.php b/common/models/receiver/Receiver_score_log_model.php new file mode 100644 index 00000000..8b64281d --- /dev/null +++ b/common/models/receiver/Receiver_score_log_model.php @@ -0,0 +1,91 @@ +table_name, 'default'); + $this->load->model('receiver/receiver_score_config_model'); + } + + public static function getUserLogLists($biz_id, $uid, $day, $type = '') + { + $where = [ + 'biz_id' => $biz_id, + 'uid' => $uid, + 'day' => $day, + ]; + if (is_numeric($type)) { + $where['type'] = $type; + } + $rows = (new Receiver_score_log_model)->select_groupby('sub_type', $where, '', 1, 50, 'id,uid,type,sub_type,sum(score) as score'); + $lists = []; + if ($rows) { + foreach ($rows as $item) { + $sub_type = Receiver_score_config_model::TYPE_LIST[$item['type']]['sub_list']; + $name = $sub_type[$item['sub_type']] ?: ''; + $lists[] = [ + 'name' => $name, + 'score' => ceil($item['score']), + ]; + } + } + return $lists; + } + + /** + * 添加分数日志 + * @param $uid + * @param $biz_id + * @param $day + * @param $type + * @param $sub_type + * @param $desc + * @param $limit_type 0不限制 1每天限制对应target_id增加一次 2永久限制添加一次 + * @param $target_id + * @param $score + * @return false|mixed + */ + public static function add_score($uid, $biz_id, $day, $type, $sub_type, $desc = '', $limit_type = 0, $target_id = 0, $score = '') + { + $scoreLogModel = new Receiver_score_log_model(); + if (!is_numeric($score)) { + $scoreConfigModel = new Receiver_score_config_model(); + $where = ['type' => $type, 'sub_type' => $sub_type, 'status' => Receiver_score_config_model::STATUS_NORMAL]; + $configRow = $scoreConfigModel->get($where); + $score = $configRow['score'] ?: 0; + } + $isExit = false; + if ($limit_type) { + $where = [ + 'type' => $type, + 'sub_type' => $sub_type, + 'uid' => $uid, + 'biz_id' => $biz_id + ]; + if ($limit_type == 1) { + $where['day'] = $day; + } + $target_id && $where['target_id'] = $target_id; + $isExit = $scoreLogModel->get($where); + } + if ($isExit) { + return false; + } + $add_data = [ + 'biz_id' => $biz_id, + 'uid' => $uid, + 'day' => $day, + 'type' => $type, + 'sub_type' => $sub_type, + 'score' => $score, + 'c_time' => time(), + ]; + $desc && $add_data['desc'] = $desc; + return $scoreLogModel->add($add_data); + } +} diff --git a/common/models/receiver/Receiver_score_month_model.php b/common/models/receiver/Receiver_score_month_model.php new file mode 100644 index 00000000..ec0197a7 --- /dev/null +++ b/common/models/receiver/Receiver_score_month_model.php @@ -0,0 +1,61 @@ +table_name, 'default'); + } + + /** + * @param $type int 类型(0个人 1门店) + * @param $biz_id int 门店id + * @param $limit int 获取条数 + * @param $day string 排行日期 YYYY-MM + * @return array + */ + public static function getTopLists($type, $biz_id = 0, $limit = 10, $day = '') + { + !$day && $day = date('Y-m', strtotime("-1 month")); + $where = []; + $where['year'] = date('Y', strtotime($day));; + $where['month'] = date('m', strtotime($day));; + if ($type) { + $where['type'] = self::TYPE_BIZ; + } else { + $where['biz_id'] = $biz_id; + $where['type'] = self::TYPE_USER; + } + $lists = []; + $rows = (new Receiver_score_month_model)->select($where, 'score desc', 1, $limit); + if ($rows) { + $userModel = new App_licheb_users_model(); + $groups = $userModel->get_group(); + foreach ($rows as $row) { + $tip = ''; + if ($type) { + $biz = (new Biz_model())->get(['id' => $row['biz_id']]); + $name = $biz['biz_name'] ?: ''; + } else { + $user = $userModel->get(['id' => $row['uid']]); + $name = $user['uname'] ?: ''; + $tip = $groups[$user['group_id']] ?: ''; + } + $lists[] = [ + 'name' => $name, + 'tip' => $tip, + 'trend' => $row['change_score'] >= 0 ? 1 : 2, //1 上升 、2 下降 + 'score' => ceil($row['score']) . '分' + ]; + } + } + return ['lists' => $lists, 'day' => $day]; + } +} diff --git a/common/models/receiver/order/Receiver_order_oplogs_model.php b/common/models/receiver/order/Receiver_order_oplogs_model.php index b6c03cd3..37fd8cfc 100644 --- a/common/models/receiver/order/Receiver_order_oplogs_model.php +++ b/common/models/receiver/order/Receiver_order_oplogs_model.php @@ -1,10 +1,15 @@ '小记', + 1 => '上传图片' + ]; + public function __construct() { parent::__construct($this->table_name, 'default');