returnRedpack.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * 退回已超时的红包
  4. * * 每10分钟执行一次
  5. * User: solu
  6. */
  7. ini_set("display_errors", "On");
  8. set_time_limit(0);
  9. error_reporting(E_ALL & ~E_NOTICE);
  10. require_once realpath(dirname(__FILE__)) . '/../common.php';
  11. if (!singleProcess(getCurrentCommand(), ROOT_PATH . "/bin/run/returnRedpack.pid")) {
  12. exit("Sorry, this script file has already been running ...\n");
  13. }
  14. $st = microtime(true);
  15. $objRedpack = new Redpack();
  16. $t = date('Y-m-d H:i:s', strtotime('-1 days'));
  17. $sql = "select id, sender, transfer_trx_id, status, num_left, create_time from redpack where status=0 and create_time<'{$t}'";
  18. $redpacks = $objRedpack->objDb->getAll($sql);
  19. $c = count($redpacks);
  20. $sc = 0;
  21. foreach ($redpacks as $redpack) {
  22. $trxId = $redpack['transfer_trx_id'];
  23. $redpackId = $redpack['id'];
  24. $i = 0;
  25. do {
  26. sleep($i * 0.1);
  27. $json = Eos::returnRedpack($redpackId, $trxId, $redpack['sender']);
  28. $ret = json_decode($json, true);
  29. $i += 1;
  30. } while ($i < 3 && !$ret['transaction_id']);
  31. if ($ret['transaction_id']) {
  32. $sc += 1;
  33. Eos::log("redpack:{$log['id']} return success");
  34. } else {
  35. Eos::log("redpack:{$log['id']} return error");
  36. }
  37. }
  38. $ct = microtime(true) - $st;
  39. Eos::log("处理{$c}记录,成功{$sc},耗时{$ct}");