PolyChannelFlowStats.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. <?php
  2. namespace app\crontab;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. use think\Db;
  7. /**
  8. * 聚合渠道游戏流水统计定时器脚本
  9. *
  10. * - 半小时执行一次
  11. */
  12. class PolyChannelFlowStats extends Command {
  13. const TABLE_PAY = 'nw_complex_pay'; // 聚合游戏消费表
  14. const TABLE_POLYCHANNEL_GAME_FROZEN = 'cy_polychannel_game_frozen'; // 聚合游戏冻结配置表
  15. protected function configure() {
  16. $this->setName('PolyChannelFlowStats')->setDescription('聚合渠道游戏流水统计脚本');
  17. }
  18. protected function execute(Input $input, Output $output) {
  19. $list = Db::table(self::TABLE_POLYCHANNEL_GAME_FROZEN)
  20. ->where([
  21. 'status' => 1,
  22. // 'game_id' => ['in', [344]],
  23. // 'channel_id' => 29,
  24. ])
  25. ->field('id,game_id,channel_id,last_sum_time')->select();
  26. $count = count($list);
  27. $output->writeln(date('Y-m-d H:i:s')." start - sum={$count}");
  28. $sum_save_num = 0;
  29. $sum_save_num_fail = 0;
  30. if ( ! empty($list) ) {
  31. foreach ( $list as $row ) {
  32. $id = (int)$row['id'];
  33. $game_id = (int)$row['game_id'];
  34. $channel_id = (int)$row['channel_id'];
  35. // $last_sum_time = (int)$row['last_sum_time'];
  36. if ( empty($id) || empty($game_id) || empty($channel_id) ) {
  37. continue;
  38. }
  39. $total_amount = Db::table(self::TABLE_PAY)->where("channel_id='{$channel_id}' AND gameid='{$game_id}' AND `status`=1")->sum('amount');
  40. $last_sum_time = (int)Db::table(self::TABLE_PAY)->where("channel_id='{$channel_id}' AND gameid='{$game_id}' AND `status`=1")->max('create_time');
  41. // && 0 < $last_sum_time
  42. if ( 0 < $total_amount) {
  43. $sum_save_num++;
  44. $update = Db::table(self::TABLE_POLYCHANNEL_GAME_FROZEN)->where("id='{$id}'")->update([
  45. 'total_amount' => $total_amount,
  46. 'last_sum_time' => $last_sum_time??time()
  47. ]);
  48. if ($update !== false) {
  49. $output->writeln(date('H:i:s')." {$channel_id}/{$game_id} - 渠道游戏总流水更新结果:success");
  50. } else {
  51. $sum_save_num_fail++;
  52. $output->writeln(date('H:i:s')." {$channel_id}/{$game_id} - 渠道游戏总流水更新结果:fail");
  53. }
  54. }
  55. }
  56. }
  57. $output->writeln(date('Y-m-d H:i:s')." end - success={$sum_save_num} / fail={$sum_save_num_fail}\r\n\n");
  58. }
  59. }