| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- <?php
- namespace app\crontab;
- use think\console\Command;
- use think\console\Input;
- use think\console\Output;
- use think\Db;
- /**
- * 聚合渠道游戏流水统计定时器脚本
- *
- * - 半小时执行一次
- */
- class PolyChannelFlowStats extends Command {
- const TABLE_PAY = 'nw_complex_pay'; // 聚合游戏消费表
- const TABLE_POLYCHANNEL_GAME_FROZEN = 'cy_polychannel_game_frozen'; // 聚合游戏冻结配置表
- protected function configure() {
- $this->setName('PolyChannelFlowStats')->setDescription('聚合渠道游戏流水统计脚本');
- }
- protected function execute(Input $input, Output $output) {
- $list = Db::table(self::TABLE_POLYCHANNEL_GAME_FROZEN)
- ->where([
- 'status' => 1,
- // 'game_id' => ['in', [344]],
- // 'channel_id' => 29,
- ])
- ->field('id,game_id,channel_id,last_sum_time')->select();
- $count = count($list);
- $output->writeln(date('Y-m-d H:i:s')." start - sum={$count}");
- $sum_save_num = 0;
- $sum_save_num_fail = 0;
- if ( ! empty($list) ) {
- foreach ( $list as $row ) {
- $id = (int)$row['id'];
- $game_id = (int)$row['game_id'];
- $channel_id = (int)$row['channel_id'];
- // $last_sum_time = (int)$row['last_sum_time'];
- if ( empty($id) || empty($game_id) || empty($channel_id) ) {
- continue;
- }
- $total_amount = Db::table(self::TABLE_PAY)->where("channel_id='{$channel_id}' AND gameid='{$game_id}' AND `status`=1")->sum('amount');
- $last_sum_time = (int)Db::table(self::TABLE_PAY)->where("channel_id='{$channel_id}' AND gameid='{$game_id}' AND `status`=1")->max('create_time');
- // && 0 < $last_sum_time
- if ( 0 < $total_amount) {
- $sum_save_num++;
- $update = Db::table(self::TABLE_POLYCHANNEL_GAME_FROZEN)->where("id='{$id}'")->update([
- 'total_amount' => $total_amount,
- 'last_sum_time' => $last_sum_time??time()
- ]);
- if ($update !== false) {
- $output->writeln(date('H:i:s')." {$channel_id}/{$game_id} - 渠道游戏总流水更新结果:success");
- } else {
- $sum_save_num_fail++;
- $output->writeln(date('H:i:s')." {$channel_id}/{$game_id} - 渠道游戏总流水更新结果:fail");
- }
- }
- }
- }
- $output->writeln(date('Y-m-d H:i:s')." end - success={$sum_save_num} / fail={$sum_save_num_fail}\r\n\n");
- }
- }
|