修改评分
This commit is contained in:
@@ -33,6 +33,8 @@ class Plan extends CI_Controller
|
||||
//$plan[] = array('url' => base_url(array('plan', 'licheb', 'bizs_log')), 'interval' => 2);//门店日志
|
||||
$plan[] = array('url' => base_url(array('plan', 'score', 'index')), 'interval' => 1); //统计分数
|
||||
$plan[] = array('url' => base_url(array('plan', 'score', 'scoreDay')), 'interval' => 1); //合并分数日志
|
||||
$plan[] = array('url' => base_url(array('plan', 'score', 'mergeUser')), 'interval' => 1); //合并上月个人分数日志
|
||||
$plan[] = array('url' => base_url(array('plan', 'score', 'mergeBiz')), 'interval' => 1); //合并上月门店分数日志
|
||||
|
||||
$this->plan = $plan;
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ class Score extends HD_Controller
|
||||
$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('receiver/receiver_score_avg_day_model');
|
||||
$this->load->model("biz/biz_model");
|
||||
}
|
||||
|
||||
@@ -235,11 +236,15 @@ class Score extends HD_Controller
|
||||
$total_sum = $receiverScoreDayModel->sum('score', [
|
||||
'type' => $receiverScoreDayModel::TYPE_USER,
|
||||
'uid' => $item['uid'],
|
||||
'day>=' => $firstDayOfLastMonth,
|
||||
'day<=' => $lastDayOfLastMonth,
|
||||
]);
|
||||
$total_score = $total_sum['score'] ? $total_sum['score'] : 0;
|
||||
$total_num = $receiverScoreDayModel->count([
|
||||
'type' => $receiverScoreDayModel::TYPE_USER,
|
||||
'uid' => $item['uid'],
|
||||
'day>=' => $firstDayOfLastMonth,
|
||||
'day<=' => $lastDayOfLastMonth,
|
||||
]);
|
||||
$score = $total_num > 0 ? $total_score / $total_num : 0;
|
||||
$where = [
|
||||
@@ -326,11 +331,15 @@ class Score extends HD_Controller
|
||||
$total_sum = $receiverScoreDayModel->sum('score', [
|
||||
'type' => $receiverScoreDayModel::TYPE_BIZ,
|
||||
'biz_id' => $item['biz_id'],
|
||||
'day>=' => $firstDayOfLastMonth,
|
||||
'day<=' => $lastDayOfLastMonth,
|
||||
]);
|
||||
$total_score = $total_sum['score'] ? $total_sum['score'] : 0;
|
||||
$total_num = $receiverScoreDayModel->count([
|
||||
'type' => $receiverScoreDayModel::TYPE_BIZ,
|
||||
'biz_id' => $item['biz_id'],
|
||||
'day>=' => $firstDayOfLastMonth,
|
||||
'day<=' => $lastDayOfLastMonth,
|
||||
]);
|
||||
$score = $total_num > 0 ? $total_score / $total_num : 0;
|
||||
$where = [
|
||||
@@ -382,4 +391,185 @@ class Score extends HD_Controller
|
||||
}
|
||||
}
|
||||
|
||||
public function mergeAvgUser()
|
||||
{
|
||||
$t_limit = $this->input->get('time_limit');
|
||||
$h = date('H');
|
||||
if (!$t_limit && $h > 5) {
|
||||
echo '当前时间段不可执行';
|
||||
exit;
|
||||
}
|
||||
$getPage = $this->input->get('page');
|
||||
$s_time = date('Y-m-01');
|
||||
$e_time = date('Y-m-t');
|
||||
$redis = &load_cache('redis');
|
||||
$pageCacheKey = "RECEIVER_SCORE_AGV_PLAN_USER_PAGE";
|
||||
if ($getPage) {
|
||||
$page = $getPage;
|
||||
} else {
|
||||
$page = $redis->get($pageCacheKey) ?: 1;
|
||||
}
|
||||
$size = 50;
|
||||
$receiverScoreDayModel = new Receiver_score_day_model();
|
||||
$receiverScoreAvgDayModel = new Receiver_score_avg_day_model();
|
||||
$where = [
|
||||
'type' => $receiverScoreDayModel::TYPE_USER,
|
||||
'day>=' => $s_time,
|
||||
'day<=' => $e_time,
|
||||
];
|
||||
$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'],
|
||||
'day>=' => $s_time,
|
||||
'day<=' => $e_time,
|
||||
]);
|
||||
$total_score = $total_sum['score'] ? $total_sum['score'] : 0;
|
||||
$total_num = $receiverScoreDayModel->count([
|
||||
'type' => $receiverScoreDayModel::TYPE_USER,
|
||||
'uid' => $item['uid'],
|
||||
'day>=' => $s_time,
|
||||
'day<=' => $e_time,
|
||||
]);
|
||||
$score = $total_num > 0 ? $total_score / $total_num : 0;
|
||||
$where = [
|
||||
'uid' => $item['uid'],
|
||||
'day' => date('Y-m-d'),
|
||||
'type' => Receiver_score_day_model::TYPE_USER
|
||||
];
|
||||
$monthRow = $receiverScoreAvgDayModel->get($where);
|
||||
//获取最后一条数据
|
||||
$where = [
|
||||
'uid' => $item['uid'],
|
||||
'type' => Receiver_score_day_model::TYPE_USER
|
||||
];
|
||||
$monthRow && $where['id<'] = $monthRow['id'];
|
||||
$lastRow = $receiverScoreAvgDayModel->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,
|
||||
];
|
||||
$receiverScoreAvgDayModel->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,
|
||||
'day' => date('Y-m-d'),
|
||||
'type' => Receiver_score_month_model::TYPE_USER,
|
||||
'province_id' => $item['province_id'],
|
||||
'c_time' => time(),
|
||||
];
|
||||
$receiverScoreAvgDayModel->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 mergeAvgBiz()
|
||||
{
|
||||
$t_limit = $this->input->get('time_limit');
|
||||
$h = date('H');
|
||||
if (!$t_limit && $h > 5) {
|
||||
echo '当前时间段不可执行';
|
||||
exit;
|
||||
}
|
||||
$getPage = $this->input->get('page');
|
||||
$s_time = date('Y-m-01');
|
||||
$e_time = date('Y-m-t');
|
||||
$redis = &load_cache('redis');
|
||||
$pageCacheKey = "RECEIVER_SCORE_AGV_PLAN_BIZ_PAGE";
|
||||
if ($getPage) {
|
||||
$page = $getPage;
|
||||
} else {
|
||||
$page = $redis->get($pageCacheKey) ?: 1;
|
||||
}
|
||||
$size = 50;
|
||||
$receiverScoreDayModel = new Receiver_score_day_model();
|
||||
$receiverScoreAvgDayModel = new Receiver_score_avg_day_model();
|
||||
$where = [
|
||||
'type' => $receiverScoreDayModel::TYPE_BIZ,
|
||||
'day>=' => $s_time,
|
||||
'day<=' => $e_time,
|
||||
];
|
||||
$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'],
|
||||
'day>=' => $s_time,
|
||||
'day<=' => $e_time,
|
||||
]);
|
||||
$total_score = $total_sum['score'] ? $total_sum['score'] : 0;
|
||||
$total_num = $receiverScoreDayModel->count([
|
||||
'type' => $receiverScoreDayModel::TYPE_BIZ,
|
||||
'biz_id' => $item['biz_id'],
|
||||
'day>=' => $s_time,
|
||||
'day<=' => $e_time,
|
||||
]);
|
||||
$score = $total_num > 0 ? $total_score / $total_num : 0;
|
||||
$where = [
|
||||
'biz_id' => $item['biz_id'],
|
||||
'day' => date('Y-m-d'),
|
||||
'type' => Receiver_score_day_model::TYPE_BIZ
|
||||
];
|
||||
$monthRow = $receiverScoreAvgDayModel->get($where);
|
||||
//获取上一个月数据
|
||||
$where = [
|
||||
'biz_id' => $item['biz_id'],
|
||||
'type' => Receiver_score_day_model::TYPE_BIZ
|
||||
];
|
||||
$monthRow && $where['id<'] = $monthRow['id'];
|
||||
$lastRow = $receiverScoreAvgDayModel->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,
|
||||
];
|
||||
$receiverScoreAvgDayModel->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,
|
||||
'day' => date('Y-m-d'),
|
||||
'type' => Receiver_score_month_model::TYPE_BIZ,
|
||||
'province_id' => $item['province_id'],
|
||||
'c_time' => time(),
|
||||
];
|
||||
$receiverScoreAvgDayModel->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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,7 @@ class Score extends Wxapp
|
||||
$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'];
|
||||
}
|
||||
@@ -40,13 +41,11 @@ class Score extends Wxapp
|
||||
if (!$show_biz) {//查看个人
|
||||
$where['uid'] = $uid;
|
||||
}
|
||||
if ($day_type == 1) { //上月
|
||||
$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());
|
||||
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"); //上个月时间
|
||||
@@ -136,7 +135,7 @@ class Score extends Wxapp
|
||||
$day_type = $this->input_param('day_type'); // 默认0昨天 1本月 2上月
|
||||
$limit = $type ? 100 : 10;
|
||||
if ($day_type == 1) {
|
||||
$result = Receiver_score_month_model::getTopLists($type, $this->biz_id, $limit);
|
||||
$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 {
|
||||
@@ -203,8 +202,17 @@ class Score extends Wxapp
|
||||
{
|
||||
$biz = (new Biz_model())->get(['id' => $this->biz_id]);
|
||||
$province_id = $biz['province_id'];
|
||||
$s_time = date('Y-m-d 00:00:00');
|
||||
$e_time = date('Y-m-d 23:59:59');
|
||||
$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"));
|
||||
}
|
||||
$s_stime = strtotime($s_time);
|
||||
$s_etime = strtotime($e_time);
|
||||
$indicator = [
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
defined('BASEPATH') or exit('No direct script access allowed');
|
||||
|
||||
class Receiver_score_avg_day_model extends HD_Model
|
||||
{
|
||||
private $table_name = 'lc_receiver_score_avg_day';
|
||||
|
||||
// 类型(0个人 1门店)
|
||||
const TYPE_USER = 0;
|
||||
const TYPE_BIZ = 1;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct($this->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
|
||||
* @return array
|
||||
*/
|
||||
public static function getTopLists($type, $biz_id = 0, $limit = 10, $day = '')
|
||||
{
|
||||
!$day && $day = date('Y-m-d');
|
||||
$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_avg_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];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user