修改评分
This commit is contained in:
@@ -13,6 +13,7 @@ class Score extends HD_Controller
|
||||
$this->load->model('app/licheb/app_licheb_users_model');
|
||||
$this->load->library('receiver/score_entity');
|
||||
$this->load->model('receiver/receiver_score_day_model');
|
||||
$this->load->model('receiver/receiver_score_month_model');
|
||||
$this->load->model("biz/biz_model");
|
||||
}
|
||||
|
||||
@@ -199,4 +200,186 @@ class Score extends HD_Controller
|
||||
debug_log("[info]# " . $msg, __FUNCTION__, $this->log_dir);
|
||||
}
|
||||
}
|
||||
|
||||
public function mergeUser()
|
||||
{
|
||||
$t_limit = $this->input->get('time_limit');
|
||||
$m = date('m');
|
||||
if (!$t_limit && $m != 1) { //每月1号执行
|
||||
echo '当前时间段不可执行';
|
||||
exit;
|
||||
}
|
||||
$getPage = $this->input->get('page');
|
||||
$year = date('Y', strtotime('last month'));
|
||||
$month = date('m', strtotime('last month'));
|
||||
$firstDayOfLastMonth = date('Y-m-01', strtotime('last month'));
|
||||
$lastDayOfLastMonth = date('Y-m-t', strtotime('last month'));
|
||||
$redis = &load_cache('redis');
|
||||
$pageCacheKey = "RECEIVER_SCORE_MONTH_PLAN_USER_PAGE";
|
||||
if ($getPage) {
|
||||
$page = $getPage;
|
||||
} else {
|
||||
$page = $redis->get($pageCacheKey) ?: 1;
|
||||
}
|
||||
$size = 50;
|
||||
$receiverScoreDayModel = new Receiver_score_day_model();
|
||||
$receiverScoreMonthModel = new Receiver_score_month_model();
|
||||
$where = [
|
||||
'type' => $receiverScoreDayModel::TYPE_USER,
|
||||
'day>=' => $firstDayOfLastMonth,
|
||||
'day<=' => $lastDayOfLastMonth,
|
||||
];
|
||||
$rows = $receiverScoreDayModel->select($where, '', $page, $size, 'DISTINCT biz_id,uid,province_id');
|
||||
if ($rows) {
|
||||
foreach ($rows as $item) {
|
||||
$total_sum = $receiverScoreDayModel->sum('score', [
|
||||
'type' => $receiverScoreDayModel::TYPE_USER,
|
||||
'uid' => $item['uid'],
|
||||
]);
|
||||
$total_score = $total_sum['score'] ? $total_sum['score'] : 0;
|
||||
$total_num = $receiverScoreDayModel->count([
|
||||
'type' => $receiverScoreDayModel::TYPE_USER,
|
||||
'uid' => $item['uid'],
|
||||
]);
|
||||
$score = $total_num > 0 ? $total_score / $total_num : 0;
|
||||
$where = [
|
||||
'uid' => $item['uid'],
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'type' => Receiver_score_day_model::TYPE_USER
|
||||
];
|
||||
$monthRow = $receiverScoreMonthModel->get($where);
|
||||
//获取上一个月数据
|
||||
$where = [
|
||||
'uid' => $item['uid'],
|
||||
'type' => Receiver_score_day_model::TYPE_USER
|
||||
];
|
||||
$monthRow && $where['id<'] = $monthRow['id'];
|
||||
$lastRow = $receiverScoreDayModel->select($where, 'c_time desc', 1, 1, 'score');
|
||||
$change_score = $lastRow[0]['score'] ? $score - $lastRow[0]['score'] : $score;
|
||||
if ($monthRow) {
|
||||
$update = [
|
||||
'score' => $score,
|
||||
'total_score' => $total_score,
|
||||
'total_num' => $total_num,
|
||||
'change_score' => $change_score,
|
||||
];
|
||||
$receiverScoreMonthModel->update($update, ['id' => $monthRow['id']]);
|
||||
} else {
|
||||
$add = [
|
||||
'biz_id' => $item['biz_id'],
|
||||
'uid' => $item['uid'],
|
||||
'score' => $score,
|
||||
'total_score' => $total_score,
|
||||
'total_num' => $total_num,
|
||||
'change_score' => $change_score,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'type' => Receiver_score_month_model::TYPE_USER,
|
||||
'province_id' => $item['province_id'],
|
||||
'c_time' => time(),
|
||||
];
|
||||
$receiverScoreMonthModel->add($add);
|
||||
}
|
||||
debug_log("[info]# 当前执行页数" . $page, __FUNCTION__, $this->log_dir);
|
||||
$page++;
|
||||
$redis->save($pageCacheKey, $page, 60 * 60);
|
||||
}
|
||||
} else {
|
||||
$msg = '执行完成';
|
||||
echo $msg;
|
||||
debug_log("[info]# " . $msg, __FUNCTION__, $this->log_dir);
|
||||
}
|
||||
}
|
||||
|
||||
public function mergeBiz()
|
||||
{
|
||||
$t_limit = $this->input->get('time_limit');
|
||||
$m = date('m');
|
||||
if (!$t_limit && $m != 1) { //每月1号执行
|
||||
echo '当前时间段不可执行';
|
||||
exit;
|
||||
}
|
||||
$getPage = $this->input->get('page');
|
||||
$year = date('Y', strtotime('last month'));
|
||||
$month = date('m', strtotime('last month'));
|
||||
$firstDayOfLastMonth = date('Y-m-01', strtotime('last month'));
|
||||
$lastDayOfLastMonth = date('Y-m-t', strtotime('last month'));
|
||||
$redis = &load_cache('redis');
|
||||
$pageCacheKey = "RECEIVER_SCORE_MONTH_PLAN_BIZ_PAGE";
|
||||
if ($getPage) {
|
||||
$page = $getPage;
|
||||
} else {
|
||||
$page = $redis->get($pageCacheKey) ?: 1;
|
||||
}
|
||||
$size = 50;
|
||||
$receiverScoreDayModel = new Receiver_score_day_model();
|
||||
$receiverScoreMonthModel = new Receiver_score_month_model();
|
||||
$where = [
|
||||
'type' => $receiverScoreDayModel::TYPE_BIZ,
|
||||
'day>=' => $firstDayOfLastMonth,
|
||||
'day<=' => $lastDayOfLastMonth,
|
||||
];
|
||||
$rows = $receiverScoreDayModel->select($where, '', $page, $size, 'DISTINCT biz_id,province_id');
|
||||
if ($rows) {
|
||||
foreach ($rows as $item) {
|
||||
$total_sum = $receiverScoreDayModel->sum('score', [
|
||||
'type' => $receiverScoreDayModel::TYPE_BIZ,
|
||||
'biz_id' => $item['biz_id'],
|
||||
]);
|
||||
$total_score = $total_sum['score'] ? $total_sum['score'] : 0;
|
||||
$total_num = $receiverScoreDayModel->count([
|
||||
'type' => $receiverScoreDayModel::TYPE_BIZ,
|
||||
'biz_id' => $item['biz_id'],
|
||||
]);
|
||||
$score = $total_num > 0 ? $total_score / $total_num : 0;
|
||||
$where = [
|
||||
'biz_id' => $item['biz_id'],
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'type' => Receiver_score_day_model::TYPE_BIZ
|
||||
];
|
||||
$monthRow = $receiverScoreMonthModel->get($where);
|
||||
//获取上一个月数据
|
||||
$where = [
|
||||
'biz_id' => $item['biz_id'],
|
||||
'type' => Receiver_score_day_model::TYPE_BIZ
|
||||
];
|
||||
$monthRow && $where['id<'] = $monthRow['id'];
|
||||
$lastRow = $receiverScoreDayModel->select($where, 'c_time desc', 1, 1, 'score');
|
||||
$change_score = $lastRow[0]['score'] ? $score - $lastRow[0]['score'] : $score;
|
||||
if ($monthRow) {
|
||||
$update = [
|
||||
'score' => $score,
|
||||
'total_score' => $total_score,
|
||||
'total_num' => $total_num,
|
||||
'change_score' => $change_score,
|
||||
];
|
||||
$receiverScoreMonthModel->update($update, ['id' => $monthRow['id']]);
|
||||
} else {
|
||||
$add = [
|
||||
'biz_id' => $item['biz_id'],
|
||||
'score' => $score,
|
||||
'total_score' => $total_score,
|
||||
'total_num' => $total_num,
|
||||
'change_score' => $change_score,
|
||||
'year' => $year,
|
||||
'month' => $month,
|
||||
'type' => Receiver_score_month_model::TYPE_BIZ,
|
||||
'province_id' => $item['province_id'],
|
||||
'c_time' => time(),
|
||||
];
|
||||
$receiverScoreMonthModel->add($add);
|
||||
}
|
||||
debug_log("[info]# 当前执行页数" . $page, __FUNCTION__, $this->log_dir);
|
||||
$page++;
|
||||
$redis->save($pageCacheKey, $page, 60 * 60);
|
||||
}
|
||||
} else {
|
||||
$msg = '执行完成';
|
||||
echo $msg;
|
||||
debug_log("[info]# " . $msg, __FUNCTION__, $this->log_dir);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -195,11 +195,11 @@ class Score extends Wxapp
|
||||
$s_stime = strtotime($s_time);
|
||||
$s_etime = strtotime($e_time);
|
||||
$indicator = [
|
||||
['name' => '拓客能力', 'max' => 0],
|
||||
['name' => '跟进能力', 'max' => 0],
|
||||
['name' => '邀约能力', 'max' => 0],
|
||||
['name' => '成交能力', 'max' => 0],
|
||||
['name' => '交付能力', 'max' => 0]
|
||||
['name' => '拓客能力', 'max' => 100],
|
||||
['name' => '跟进能力', 'max' => 1],
|
||||
['name' => '邀约能力', 'max' => 100],
|
||||
['name' => '成交能力', 'max' => 100],
|
||||
['name' => '交付能力', 'max' => 1]
|
||||
];
|
||||
$series_value = [];
|
||||
foreach ($indicator as $key => $value) {
|
||||
@@ -211,22 +211,51 @@ class Score extends Wxapp
|
||||
'c_time >=' => $s_stime,
|
||||
'c_time <=' => $s_etime,
|
||||
];
|
||||
$indicator[$key]['max'] = $this->customers_model->count($where);
|
||||
$where['biz_id'] = $this->biz_id;
|
||||
$max = $this->customers_model->count($where);
|
||||
$max && $indicator[$key]['max'] = $max;
|
||||
$where["biz_id in (select id from lc_biz where province_id =$province_id)"] = null;
|
||||
$value = $this->customers_model->count($where);
|
||||
break;
|
||||
case 1:
|
||||
$sub_sql = "select DISTINCT customer_id from lc_receiver_customer_oplogs where c_time>={$s_stime} and c_time>={$s_etime}";
|
||||
case 1://跟进能力
|
||||
$where = [
|
||||
'status>=' => 0,
|
||||
'province_id' => $province_id,
|
||||
'c_time >=' => strtotime($s_time),
|
||||
'c_time <=' => strtotime($e_time),
|
||||
"id in ($sub_sql)" => null
|
||||
"id in (select DISTINCT customer_id from lc_receiver_customer_oplogs where c_time>={$s_stime} and c_time>={$s_etime})" => null
|
||||
];
|
||||
$indicator[$key]['max'] = $this->customers_model->count($where);
|
||||
$where['biz_id'] = $this->biz_id;
|
||||
$value = $this->customers_model->count($where);
|
||||
$province_gj = $this->customers_model->count($where);
|
||||
$where = [
|
||||
'status>=' => 0,
|
||||
'province_id' => $province_id,
|
||||
'c_time >=' => strtotime($s_time),
|
||||
'c_time <=' => strtotime($e_time),
|
||||
"id in (select DISTINCT customer_id from lc_receiver_customer_oplogs where c_time>={$s_stime} and c_time>={$s_etime})" => null,
|
||||
"biz_id in (select id from lc_biz where province_id =$province_id)" => null
|
||||
];
|
||||
$biz_gj = $this->customers_model->count($where);
|
||||
$where = [
|
||||
'status>=' => 0,
|
||||
'province_id' => $province_id,
|
||||
'c_time >=' => strtotime($s_time),
|
||||
'c_time <=' => strtotime($e_time),
|
||||
"status in (0,1)" => null
|
||||
];
|
||||
$province_total = $this->customers_model->count($where);
|
||||
$where = [
|
||||
'status>=' => 0,
|
||||
'province_id' => $province_id,
|
||||
'c_time >=' => strtotime($s_time),
|
||||
'c_time <=' => strtotime($e_time),
|
||||
"status in (0,1)" => null,
|
||||
'biz_id' => $this->biz_id
|
||||
];
|
||||
$biz_total = $this->customers_model->count($where);
|
||||
$province_total && $max = $province_gj / $province_total;
|
||||
$value = 0;
|
||||
if ($biz_total) {
|
||||
$value = $biz_gj / $biz_total;
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
$where = [
|
||||
@@ -235,8 +264,9 @@ class Score extends Wxapp
|
||||
'dt_time >=' => $s_time,
|
||||
'dt_time <=' => $e_time,
|
||||
];
|
||||
$indicator[$key]['max'] = $this->customers_model->count($where);
|
||||
$where['biz_id'] = $this->biz_id;
|
||||
$max = $this->customers_model->count($where);
|
||||
$max && $indicator[$key]['max'] = $max;
|
||||
$where["biz_id in (select id from lc_biz where province_id =$province_id)"] = null;
|
||||
$value = $this->customers_model->count($where);
|
||||
break;
|
||||
case 3:
|
||||
@@ -246,11 +276,12 @@ class Score extends Wxapp
|
||||
'c_time >=' => $s_stime,
|
||||
'c_time <=' => $s_etime,
|
||||
];
|
||||
$indicator[$key]['max'] = $this->customers_model->count($where);
|
||||
$max = $this->customers_model->count($where);
|
||||
$max && $indicator[$key]['max'] = $max;
|
||||
$sub_sql = "select id from lc_receiver_customers where province_id={$province_id} and biz_id={$this->biz_id} and c_time>={$s_stime} and c_time>={$s_etime}";
|
||||
$where = [
|
||||
'status>=' => 0,
|
||||
'biz_id' => $this->biz_id,
|
||||
"biz_id in (select id from lc_biz where province_id =$province_id)" => null,
|
||||
'c_time >=' => strtotime($s_time),
|
||||
'c_time <=' => strtotime($e_time),
|
||||
"customer_id in ($sub_sql)" => null
|
||||
@@ -265,10 +296,22 @@ class Score extends Wxapp
|
||||
'c_time <=' => strtotime($e_time),
|
||||
"customer_id in ($sub_sql)" => null
|
||||
];
|
||||
$indicator[$key]['max'] = $this->orders_model->count($where);
|
||||
$province_order = $this->orders_model->count($where);
|
||||
$where['status'] = 3;
|
||||
$where['biz_id'] = $this->biz_id;
|
||||
$value = $this->orders_model->count($where);
|
||||
$province_jf = $this->orders_model->count($where);
|
||||
$sub_sql = "select id from lc_receiver_customers where biz_id={$this->biz_id} and province_id={$province_id} and c_time>={$s_stime} and c_time>={$s_etime}";
|
||||
$where = [
|
||||
'status>=' => 0,
|
||||
'c_time >=' => strtotime($s_time),
|
||||
'c_time <=' => strtotime($e_time),
|
||||
"customer_id in ($sub_sql)" => null
|
||||
];
|
||||
$biz_order = $this->orders_model->count($where);
|
||||
$where['status'] = 3;
|
||||
$biz_jf = $this->orders_model->count($where);
|
||||
$province_order && $max = $province_jf / $province_order;
|
||||
$max && $indicator[$key]['max'] = $max;
|
||||
$value = $biz_order ? $biz_jf / $biz_order : 0;
|
||||
default:
|
||||
}
|
||||
$series_value[] = $value;
|
||||
|
||||
Reference in New Issue
Block a user