2025-12-31 03:19:22 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace app\cron\controller;
|
|
|
|
|
|
|
|
|
|
|
|
use app\common\controller\Push;
|
|
|
|
|
|
use think\Cache;
|
|
|
|
|
|
use think\Db;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 定时任务,每秒执行的方法
|
|
|
|
|
|
*/
|
|
|
|
|
|
class AppTodayStatistical
|
|
|
|
|
|
{
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 运行函数
|
|
|
|
|
|
*/
|
|
|
|
|
|
function index()
|
|
|
|
|
|
{
|
|
|
|
|
|
echo "每日12点统计用户数据:\n";
|
|
|
|
|
|
$this->daily_statistics();
|
|
|
|
|
|
echo "每日12点统计用户数据结束 \n";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
* 每日12点统计用户数据
|
|
|
|
|
|
*/
|
|
|
|
|
|
public function daily_statistics(){
|
|
|
|
|
|
echo date('Y-m-d')."每日统计开始:\n";
|
|
|
|
|
|
$time = strtotime(date('Y-m-d'));
|
2025-12-31 15:21:02 +08:00
|
|
|
|
$stime = strtotime(date('Y-m-d'));
|
|
|
|
|
|
$etime = strtotime(date('Y-m-d 23:59:59'));
|
2026-01-12 14:58:35 +08:00
|
|
|
|
// $user_list = Db::name('user_wallet')->select();
|
|
|
|
|
|
$user_list = db::name('user_wallet_coin')->select();
|
2025-12-31 03:19:22 +08:00
|
|
|
|
foreach ($user_list as $k=>$v){
|
|
|
|
|
|
$gift_pack = Db::name('vs_user_gift_pack')->field('gid,num')->where(['user_id'=>$v['user_id'],'is_tester'=>1])->select();
|
|
|
|
|
|
$gift_pack_price = 0;
|
|
|
|
|
|
foreach ($gift_pack as $key=>$val){
|
|
|
|
|
|
$gift_pack_price += Db::name('vs_gift')->where(['gid'=>$val['gid'],])->value('gift_price')*$val['num'];
|
|
|
|
|
|
}
|
|
|
|
|
|
//用户房间今日总流水
|
|
|
|
|
|
//用户房间id
|
2025-12-31 15:21:02 +08:00
|
|
|
|
$room_id = db::name('vs_room')->where('user_id', $v['user_id'])->value('id');
|
2025-12-31 03:19:22 +08:00
|
|
|
|
$transaction = 0;
|
|
|
|
|
|
if($room_id){
|
|
|
|
|
|
$transaction = db::name('vs_give_gift')
|
|
|
|
|
|
->where('from_id',$room_id)
|
|
|
|
|
|
->where('from',2)
|
2025-12-31 15:21:02 +08:00
|
|
|
|
->whereBetween('createtime', [$stime, $etime])
|
2025-12-31 03:19:22 +08:00
|
|
|
|
->sum('total_price');
|
|
|
|
|
|
}
|
|
|
|
|
|
//公会流水
|
|
|
|
|
|
$guild_flow_price = 0;
|
2025-12-31 15:21:02 +08:00
|
|
|
|
$guild_id = db::name('vs_guild')->where(['user_id'=>$v['user_id'],'status'=>1,'delete_time'=>0])->value('id');
|
2025-12-31 03:19:22 +08:00
|
|
|
|
if($guild_id){
|
|
|
|
|
|
$guild_flow_price= db::name('vs_guild_flow')->where('guild_id', $guild_id)->where('day', date('Y-m-d',$time))->sum('flow_price');
|
|
|
|
|
|
}
|
|
|
|
|
|
//充值金额
|
2025-12-31 15:21:02 +08:00
|
|
|
|
$recharge_price = db::name('vs_user_recharge')
|
|
|
|
|
|
->where('user_id', $v['user_id'])
|
|
|
|
|
|
->where('pay_status',2)
|
|
|
|
|
|
->whereBetween('pay_time', [$stime, $etime])
|
2025-12-31 03:19:22 +08:00
|
|
|
|
->sum('money');
|
|
|
|
|
|
//提现
|
2025-12-31 15:21:02 +08:00
|
|
|
|
$withdraw_price = db::name('vs_user_withdrawal')
|
|
|
|
|
|
->where('user_id', $v['user_id'])
|
|
|
|
|
|
->whereIn('status',[2,6])
|
|
|
|
|
|
->whereBetween('createtime', [$stime, $etime])
|
|
|
|
|
|
->sum('money');
|
2025-12-31 03:19:22 +08:00
|
|
|
|
$data = [
|
2025-12-31 15:21:02 +08:00
|
|
|
|
'user_id'=>$v['user_id']??0,
|
|
|
|
|
|
'coin'=>$v['coin']??0,
|
2026-01-12 14:58:35 +08:00
|
|
|
|
'earnings'=> db::name('user_wallet_earnings')->where('user_id', $v['user_id'])->value('earnings')??0,
|
2025-12-31 15:21:02 +08:00
|
|
|
|
'gift_pack_price'=>$gift_pack_price??0,
|
|
|
|
|
|
'room_flow_price'=>$transaction??0,
|
|
|
|
|
|
'guild_flow_price'=>$guild_flow_price??0,
|
|
|
|
|
|
'recharge_price'=>$recharge_price??0,
|
|
|
|
|
|
'withdraw_price'=>$withdraw_price??0,
|
2025-12-31 03:19:22 +08:00
|
|
|
|
'day'=>date('Y-m-d',$time),
|
|
|
|
|
|
'createtime'=>$time,
|
|
|
|
|
|
];
|
2025-12-31 15:21:02 +08:00
|
|
|
|
Db::name('vs_app_today_statistical')->insert($data);
|
2025-12-31 03:19:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
echo date('Y-m-d')."每日统计结束 用户数量".count($user_list)." \n";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|