任务统计提交
This commit is contained in:
@@ -481,4 +481,185 @@ class Statistical extends adminApi
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
//任务统计
|
||||
public function task_statistics(){
|
||||
$page = input('page', 1);
|
||||
$page_limit = input('page_limit', 10);
|
||||
$search_id = input('search_uid', '');
|
||||
$search_name = input('search_name', '');
|
||||
$search_task_id = input('search_task_id', '');
|
||||
$search_task_name = input('search_task_name', '');
|
||||
$begin_time = input('begin_time', '');
|
||||
$end_time = input('end_time', '');
|
||||
$where =[];
|
||||
if($search_id){
|
||||
$where['b.user_code'] = $search_id;
|
||||
}
|
||||
if($search_name){
|
||||
$where['b.nickname'] = ['like', '%'.$search_name.'%'];
|
||||
}
|
||||
if($search_task_id){
|
||||
$where['a.task_id'] = $search_task_id;
|
||||
}
|
||||
if($search_task_name){
|
||||
$where['c.task_name'] = ['like', '%'.$search_task_name.'%'];
|
||||
}
|
||||
if($begin_time !== ''){
|
||||
$where['a.collection_time'] = ['>=', strtotime($begin_time)];
|
||||
}
|
||||
if($end_time !== ''){
|
||||
$where['a.collection_time'] = ['<=', strtotime($end_time)];
|
||||
}
|
||||
|
||||
// 添加条件:只统计已领取的任务奖励
|
||||
// $where['a.is_claimed'] = 1;
|
||||
|
||||
$count = db::name('vs_tasks_user_daily')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_tasks c', 'a.task_id = c.id')
|
||||
->where($where)
|
||||
->count();
|
||||
$lists = db::name('vs_tasks_user_daily')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_tasks c', 'a.task_id = c.id')
|
||||
->where($where)
|
||||
->field('a.*,c.task_name,b.nickname,b.user_code,c.tasks_bag_id')
|
||||
->order('a.id desc')
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
|
||||
// 收集所有需要的用户ID和任务包ID以批量获取数据
|
||||
$user_ids = array_column($lists, 'user_id');
|
||||
$bag_ids = array_unique(array_filter(array_column($lists, 'tasks_bag_id')));
|
||||
|
||||
// 批量获取用户装饰详情
|
||||
$user_decorates = [];
|
||||
if (!empty($user_ids)) {
|
||||
foreach ($user_ids as $user_id) {
|
||||
$user_decorates[$user_id] = model('api/Decorate')->user_decorate_detail($user_id, 6);
|
||||
}
|
||||
}
|
||||
// 批量获取奖励包详情
|
||||
$bag_details = [];
|
||||
if (!empty($bag_ids)) {
|
||||
$details = db::name('vs_gift_bag_detail')
|
||||
->where('gift_bag_id', 'in', $bag_ids)
|
||||
->select();
|
||||
|
||||
foreach ($details as $detail) {
|
||||
$bag_details[$detail['gift_bag_id']][] = $detail;
|
||||
}
|
||||
}
|
||||
// 获取所有相关礼品的价格信息
|
||||
$gift_ids = [];
|
||||
$decorate_ids = [];
|
||||
foreach ($bag_details as $details) {
|
||||
foreach ($details as $detail) {
|
||||
if ($detail['type'] == 2) {
|
||||
$gift_ids[] = $detail['foreign_id'];
|
||||
} elseif ($detail['type'] == 3) {
|
||||
$decorate_ids[] = $detail['foreign_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
// 批量获取礼品价格
|
||||
$gift_prices = [];
|
||||
if (!empty($gift_ids)) {
|
||||
$gifts = db::name('vs_gift')
|
||||
->where('gid', 'in', array_unique($gift_ids))
|
||||
->column('gift_price', 'gid');
|
||||
$gift_prices = $gifts;
|
||||
}
|
||||
|
||||
// 批量获取装饰价格
|
||||
$decorate_prices = [];
|
||||
if (!empty($decorate_ids)) {
|
||||
$decorates = db::name('vs_decorate_price')
|
||||
->where('id', 'in', array_unique($decorate_ids))
|
||||
->column('price', 'id');
|
||||
$decorate_prices = $decorates;
|
||||
}
|
||||
|
||||
$data_list = [];
|
||||
$total_reward_price = 0;
|
||||
foreach ($lists as $listkey=>$list){
|
||||
$user_code = isset($user_decorates[$list['user_id']]) ? $user_decorates[$list['user_id']] : '';
|
||||
$data_list[$listkey]['user_code'] = $user_code;
|
||||
$data_list[$listkey]['nickname'] = $list['nickname']."-".$user_code;
|
||||
$data_list[$listkey]['task_name'] = $list['task_name'];
|
||||
$data_list[$listkey]['createtime'] = date('Y-m-d H:i:s', $list['createtime']);
|
||||
$data_list[$listkey]['is_completed'] = $list['is_completed'];//是否已完成
|
||||
$data_list[$listkey]['is_completed_str'] = $list['is_completed']==1 ?"是":"否";
|
||||
//领取状态
|
||||
$data_list[$listkey]['is_claimed'] = $list['is_claimed']; //奖励是否已领取
|
||||
$data_list[$listkey]['is_claimed_str'] = $list['is_claimed']==1 ?"是":"否";
|
||||
//奖品内容
|
||||
$data_list[$listkey]['reward_str'] = "";
|
||||
//奖品价值
|
||||
$data_list[$listkey]['reward_price'] = 0;
|
||||
|
||||
// 计算奖励信息
|
||||
if (isset($bag_details[$list['tasks_bag_id']])) {
|
||||
$reward_info = $bag_details[$list['tasks_bag_id']];
|
||||
foreach ($reward_info as $value) {
|
||||
//价格
|
||||
$reward_price = 0;
|
||||
if($value['type'] == 1){
|
||||
$reward_name = $value['quantity'].$value['name'];
|
||||
$reward_price = $value['gold'] * $value['quantity'];
|
||||
}elseif($value['type'] == 2){
|
||||
$reward_name = $value['name'].'x'.$value['quantity'];
|
||||
$gift_price = isset($gift_prices[$value['foreign_id']]) ? $gift_prices[$value['foreign_id']] : 0;
|
||||
$reward_price = $gift_price * $value['quantity'];
|
||||
}elseif($value['type'] == 3){
|
||||
$reward_name = $value['name'].'x'.$value['days'].'天';
|
||||
//$reward_price = isset($decorate_prices[$value['foreign_id']]) ? $decorate_prices[$value['foreign_id']] : 0;
|
||||
}else{
|
||||
$reward_name = $value['quantity'].$value['name'];
|
||||
//$reward_price = $value['gold'] * $value['quantity'];
|
||||
}
|
||||
$data_list[$listkey]['reward_str'] .= $reward_name." ";
|
||||
$data_list[$listkey]['reward_price'] += $reward_price;
|
||||
}
|
||||
}
|
||||
}
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'total_reward_price' => $this->get_claimed_reward_price($begin_time, $end_time),
|
||||
'lists' => $data_list,
|
||||
];
|
||||
return V(1,"成功", $return_data);
|
||||
}
|
||||
//获取已领取任务奖励的总价值
|
||||
public function get_claimed_reward_price($stime="",$etime=""){
|
||||
//获取所有已领取的任务奖励礼包
|
||||
$where = [];
|
||||
if(!empty($stime)){
|
||||
$where['createtime'] = ['>=', strtotime($stime)];
|
||||
}
|
||||
if(!empty($etime)){
|
||||
$where['createtime'] = ['<=', strtotime($etime)];
|
||||
}
|
||||
$tasks_bag_details = db::name('vs_gift_bag_detail')
|
||||
->where(['type'=>['in', [1,2]]])
|
||||
->where('gift_bag_id','>=',18)
|
||||
->where('gift_bag_id','<=',51)
|
||||
->where($where)
|
||||
->select();
|
||||
$total_reward_price = 0;
|
||||
foreach ($tasks_bag_details as $detail){
|
||||
if($detail['type'] == 1){
|
||||
$total_reward_price += $detail['gold'] * $detail['quantity'];
|
||||
}else{
|
||||
$gift_price = db::name('vs_gift')->where('gid',$detail['foreign_id'])->value('gift_price');
|
||||
$total_reward_price += $gift_price * $detail['quantity'];
|
||||
}
|
||||
}
|
||||
return $total_reward_price;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -155,9 +155,23 @@ class User extends adminApi
|
||||
$lists[$key]['special_num'] = "无";
|
||||
}
|
||||
}
|
||||
$total_coin = db::name('user')->alias('a')
|
||||
->join('(SELECT * FROM fa_user_auth WHERE id IN (SELECT MAX(id) FROM fa_user_auth GROUP BY mobile)) b', 'a.mobile = b.mobile', 'LEFT')
|
||||
->join('user_wallet c', 'a.id = c.user_id','LEFT')
|
||||
->where($where)
|
||||
->field($field)
|
||||
->sum('c.coin');
|
||||
$total_earnings = db::name('user')->alias('a')
|
||||
->join('(SELECT * FROM fa_user_auth WHERE id IN (SELECT MAX(id) FROM fa_user_auth GROUP BY mobile)) b', 'a.mobile = b.mobile', 'LEFT')
|
||||
->join('user_wallet c', 'a.id = c.user_id','LEFT')
|
||||
->where($where)
|
||||
->field($field)
|
||||
->sum('c.earnings');
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'total_coin' => $total_coin,
|
||||
'total_earnings' => $total_earnings,
|
||||
'count' => $count,
|
||||
'lists' => $lists
|
||||
];
|
||||
@@ -642,32 +656,56 @@ class User extends adminApi
|
||||
$page_limit = input('page_limit',10);
|
||||
$where['a.is_tester'] = 1;
|
||||
if($user_id){
|
||||
$where['a.user_id'] = $user_id;
|
||||
$where['b.user_code'] = $user_id;
|
||||
}
|
||||
if($gid){
|
||||
$where['a.gid'] = $gid;
|
||||
}
|
||||
$count = db::name('vs_user_gift_pack')->alias('a')->join('user b', 'a.user_id = b.id')->where($where)->count();
|
||||
$count = db::name('vs_user_gift_pack')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_gift c', 'a.gid = c.gid')
|
||||
->where($where)
|
||||
->where(['a.num'=>['>',0]])
|
||||
->count();
|
||||
$list = db::name('vs_user_gift_pack')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_gift c', 'a.gid = c.gid')
|
||||
->field('a.*,b.user_code,b.nickname,c.gift_name,c.base_image,c.gift_price')->where($where)->order('a.pid', "desc")->page($page, $page_limit)->select();
|
||||
->field('a.*,b.user_code,b.nickname,c.gift_name,c.base_image,c.gift_price')
|
||||
->where($where)
|
||||
->where(['a.num'=>['>',0]])
|
||||
->order('a.pid', "desc")
|
||||
->page($page, $page_limit)
|
||||
->select();
|
||||
$gift_total = 0;
|
||||
$gift_count = 0;
|
||||
foreach ($list as $key => &$value) {
|
||||
$value['createtime'] = date('Y-m-d H:i:s',$value['createtime']);
|
||||
$value['user_id_nickname'] = $value['user_code'].'——'.$value['nickname'];
|
||||
$value['gift_id_name'] = $value['gid'].'——'.$value['gift_name'];
|
||||
$value['nickname'] = $value['nickname'].'-'.$value['user_code'];
|
||||
$value['gift_id_name'] = $value['gift_name'].'-'.$value['gid'];
|
||||
}
|
||||
//礼物个数
|
||||
$gift_count = db::name('vs_user_gift_pack')->alias('a')->join('user b', 'a.user_id = b.id')->where($where)->group('a.gid')->count();
|
||||
//礼物总金额
|
||||
$gift_total = db::name('vs_user_gift_pack')->alias('a')->join('user b', 'a.user_id = b.id')
|
||||
//礼物种类个数
|
||||
$gift_kinds = db::name('vs_user_gift_pack')->alias('a')->join('user b', 'a.user_id = b.id')->where($where)->where(['num'=>['>',0]])->group('a.gid')->count();
|
||||
$gift_count = db::name('vs_user_gift_pack')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_gift c', 'a.gid = c.gid')
|
||||
->where($where)->sum('c.gift_price');
|
||||
->where($where)
|
||||
->where(['a.num'=>['>',0]])
|
||||
->sum('a.num');
|
||||
$gift_total = db::name('vs_user_gift_pack')
|
||||
->alias('a')
|
||||
->join('user b', 'a.user_id = b.id')
|
||||
->join('vs_gift c', 'a.gid = c.gid')
|
||||
->where($where)
|
||||
->where(['a.num'=>['>',0]])
|
||||
->sum('c.gift_price');
|
||||
$return_data = [
|
||||
'page' =>$page,
|
||||
'page_limit' => $page_limit,
|
||||
'count' => $count,
|
||||
'gift_kinds' => $gift_kinds,
|
||||
'gift_count' => $gift_count,
|
||||
'gift_total' => $gift_total,
|
||||
'lists' => $list
|
||||
|
||||
Reference in New Issue
Block a user