fixRedpackLog.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /**
  3. * 修复红包领取状态
  4. * * 每分钟执行一次
  5. * User: solu
  6. * Date: 2019/1/28
  7. * Time: 2:40 PM
  8. */
  9. ini_set("display_errors", "On");
  10. set_time_limit(0);
  11. error_reporting(E_ALL & ~E_NOTICE);
  12. require_once realpath(dirname(__FILE__)) . '/../common.php';
  13. if (!singleProcess(getCurrentCommand(), ROOT_PATH . "/bin/run/fixRedpackLog.pid")) {
  14. exit("Sorry, this script file has already been running ...\n");
  15. }
  16. $st = microtime(true);
  17. define('MAX_REQ', 5);
  18. define('PROCESS_TIME', 30); // 修复超过30秒的记录
  19. $objLog = new TableHelper('redpack_log', 'dw_chat');
  20. $objRedpack = new Redpack();
  21. $t = date('Y-m-d H:i:s', time() - PROCESS_TIME);
  22. $sql = 'select * from redpack_log where status=0 and req_times<' . MAX_REQ . " and create_time<='{$t}'";
  23. $logs = $objLog->getDb()->getAll($sql);
  24. $c = count($logs);
  25. $sc = 0;
  26. $trxIds = array_column($logs, 'redpack_trx_id');
  27. $redpacks = $objRedpack->objTable->getAll(['transfer_trx_id' => $trxIds], ['_field' => 'id, transfer_trx_id']);
  28. $redpacks = arrayFormatKey($redpacks, 'transfer_trx_id', 'id');
  29. foreach ($logs as $log) {
  30. $trxId = $log['redpack_trx_id'];
  31. $redpackId = $redpacks[$trxId] ?: 0;
  32. if (!$redpackId) {
  33. Eos::log("logId:{$log['id']} miss redpack id");
  34. continue;
  35. }
  36. $i = 0;
  37. do {
  38. sleep($i * 0.1);
  39. $json = Eos::grabRedpack($redpackId, $trxId, $log['id'], $log['player'], $log['quantity'], $log['net_id']);
  40. $ret = json_decode($json, true);
  41. $i += 1;
  42. } while ($i < 3 && !$ret['transaction_id']);
  43. if ($ret['transaction_id']) {
  44. $sc += 1;
  45. Eos::log("logId:{$log['id']} fix success");
  46. } else {
  47. Eos::log("logId:{$log['id']} fix error");
  48. }
  49. $req = $log['req_times'] + 1;
  50. $objLog->updateObject(['req_times' => $req], ['id' => $log['id']]);
  51. }
  52. $ct = microtime(true) - $st;
  53. Eos::log("处理{$c}记录,成功{$sc},耗时{$ct}");