Comendnotice.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /**
  3. *------Create thems Model------
  4. *------SCWPHP Version 1.0.0------
  5. *------Dev Model Jions------
  6. *------Create Time 2017-06-13 18:45:24------
  7. */
  8. namespace App\Models;
  9. use DB;
  10. use App\Models\MoneyBuyMatch as MoneyBuyMatchModel;
  11. use App\Lib\Biz\Sport\Common;
  12. class Comendnotice extends BaseModel
  13. {
  14. protected $table = 'comendnotice';
  15. public $timestamps = false;
  16. protected $fillable = ['status', 'pcount', 'logs', 'game_code', 'match_id', 'result', 'done_time', 'start_time', 'ctime'];
  17. //添加赛事结束纪录
  18. function addcomendnotice($match_id, $type, $pcount = 1, $game_start_time = 0)
  19. {
  20. $data = $this->where(['match_id' => $match_id, 'game_code' => $type])->first();
  21. if (!$data) {
  22. $insertArr = ['game_code' => $type, 'status' => 0, 'pcount' => $pcount, 'match_id' => $match_id, 'ctime' => date('Y-m-d H:i:s')];
  23. if ($game_start_time) {
  24. $insertArr['game_start_time'] = $game_start_time;
  25. }
  26. $res = $this->insert($insertArr);
  27. if (!$res) {
  28. return -6030001222;
  29. }
  30. }
  31. return 1;
  32. }
  33. //
  34. public function getNeedSettelent()
  35. {
  36. $lastDay = date("Y-m-d H:i:s", time() - 86400 * 30);
  37. $now = date("Y-m-d H:i:s", time() - 5 * 3600);
  38. $now_2 = date('Y-m-d H:i:s', time() - 60);
  39. // $model = $this->where([['game_start_time', '<=', $now], ['game_start_time', '>=', $lastDay], ['pcount', '=', 0]])->orderBy('game_start_time', 'desc')->first();
  40. $model = $this->where([['ctime', '<=', $now_2], ['ctime', '>=', $lastDay], ['pcount', '=', 0]])->orderBy('ctime', 'desc')->first();
  41. return $model;
  42. }
  43. //找到比赛已经结束,还没结算的记录,插入到消息通知表里[多个球类]
  44. public function InsertEndGame($day = 30)
  45. {
  46. $types = ['zq', 'lq', 'wq', 'bq'];
  47. foreach ($types as $gtype) {
  48. $rows = $this->findByType($gtype, $day);
  49. if (!empty($rows) && count($rows) > 0) {
  50. Common::SET_NOMAM_RECORD('自动结算之添加通知消息!', ['count' => count($rows)]);
  51. foreach ($rows as $matchidObj) {
  52. $matchid = $matchidObj->match_id;
  53. $start_time = $matchidObj->start_time;
  54. $this->addcomendnotice($matchid, $gtype, 0, $start_time);
  55. }
  56. }
  57. }
  58. return true;
  59. }
  60. public function findByType($type, $days = 30)
  61. {
  62. $days = intval($days);
  63. $time = date("Y-m-d 00:00:00", (time() - 86400 * $days));
  64. $time2 = date("Y-m-d 00:00:00", (time() - 86400 * ($days + 5)));
  65. $table = "st_" . $type . "_result";
  66. $sql = <<<EOS
  67. select tabb.match_id,tabb.start_time from
  68. ( select match_id,start_time from $table where start_time>='$time' and status=2 ) as tabb
  69. where match_id not in (select match_id from comendnotice where game_code='$type' and game_start_time>='$time2')
  70. order by match_id asc
  71. EOS;
  72. $result = DB::select($sql);
  73. return $result;
  74. }
  75. }