CrontabController.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use Illuminate\Routing\Controller as BaseController;
  4. use App\Http\Response\Response;
  5. use Illuminate\Support\Facades\DB;
  6. use App\Lib\Biz\Sport\Common as commonFunction;
  7. use App\Http\Model\StZqMatch as StMatchModel;
  8. use App\Models\SportsNoteList as SportsNoteListModel;
  9. /**
  10. * 定时处理任务
  11. * Tank
  12. * 2019/10/31
  13. */
  14. class CrontabController extends BaseController{
  15. //是否启用 数据写入记录
  16. protected $isRecord;
  17. public function __construct()
  18. {
  19. $this->isRecord = config('record.isRecord');
  20. }
  21. /**
  22. * 定时执行 滚球投注危险球审核
  23. * 每分钟执行一次
  24. */
  25. public function HandleOrder(){
  26. try {
  27. //开启事务
  28. DB::beginTransaction();
  29. $time =60*5;
  30. //处理指定时间内的滚球待审核订单
  31. SportsNoteListModel::getOrderData($time);
  32. //提交事务
  33. DB::commit();
  34. //写请求数据 日志记录
  35. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('zq', [], 'HandleOrder', Response::success());
  36. return Response::success();
  37. } catch (\Exception $e) {
  38. //回滚事务
  39. DB::rollBack();
  40. //写请求数据 日志记录
  41. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('zq', [], 'HandleOrder', $e->getMessage());
  42. return $e->getMessage();
  43. }
  44. }
  45. /**
  46. * 定时执行 处理到时间应该开始而未开始的赛事
  47. * 每分钟执行一次
  48. */
  49. public function HandleMatch(){
  50. try {
  51. //开启事务
  52. DB::beginTransaction();
  53. $time = 60*5;//60 秒
  54. //处理指定时间内的赛事
  55. StMatchModel::HandleMatch($time);
  56. //提交事务
  57. DB::commit();
  58. //写请求数据 日志记录
  59. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleMatch', Response::success());
  60. return Response::success();
  61. } catch (\Exception $e) {
  62. //回滚事务
  63. DB::rollBack();
  64. //写请求数据 日志记录
  65. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleMatch', $e->getMessage());
  66. return $e->getMessage();
  67. }
  68. }
  69. /**
  70. * 定时执行 处理时间段内赛事已取消的注单1
  71. */
  72. public function HandleOrderInvalid(){
  73. try {
  74. //开启事务
  75. DB::beginTransaction();
  76. $time = 60*5;//5分钟
  77. //处理指定时间内已取消赛事的注单
  78. SportsNoteListModel::HandleOrderInvalid($time);
  79. //提交事务
  80. DB::commit();
  81. //写请求数据 日志记录
  82. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleOrderInvalid', Response::success());
  83. return Response::success();
  84. } catch (\Exception $e) {
  85. //回滚事务
  86. DB::rollBack();
  87. //写请求数据 日志记录
  88. if ($this->isRecord) commonFunction::SET_SPORTS_RECORD('all', [], 'HandleOrderInvalid', $e->getMessage());
  89. return $e->getMessage();
  90. }
  91. }
  92. }