Comendnotice.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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. $model = $this->where([['game_start_time', '<=', $now], ['game_start_time', '>=', $lastDay], ['pcount', '=', 0]])->orderBy('game_start_time', 'desc')->first();
  39. return $model;
  40. }
  41. //找到比赛已经结束,还没结算的记录,插入到消息通知表里[多个球类]
  42. public function InsertEndGame($day = 30)
  43. {
  44. $types = ['zq', 'lq', 'wq', 'bq'];
  45. foreach ($types as $gtype) {
  46. $rows = $this->findByType($gtype, $day);
  47. if (!empty($rows) && count($rows) > 0) {
  48. Common::SET_NOMAM_RECORD('自动结算之添加通知消息!', ['count' => count($rows)]);
  49. foreach ($rows as $matchidObj) {
  50. $matchid = $matchidObj->match_id;
  51. $start_time = $matchidObj->start_time;
  52. $this->addcomendnotice($matchid, $gtype, 0, $start_time);
  53. }
  54. }
  55. }
  56. return true;
  57. }
  58. public function findByType($type, $days = 30)
  59. {
  60. $days = intval($days);
  61. $time = date("Y-m-d 00:00:00", (time() - 86400 * $days));
  62. $time2 = date("Y-m-d 00:00:00", (time() - 86400 * ($days + 5)));
  63. $table = "st_" . $type . "_result";
  64. $sql = <<<EOS
  65. select tabb.match_id,tabb.start_time from
  66. ( select match_id,start_time from $table where start_time>='$time' and status=2 ) as tabb
  67. where match_id not in (select match_id from comendnotice where game_code='$type' and game_start_time>='$time2')
  68. order by match_id asc
  69. EOS;
  70. $result = DB::select($sql);
  71. return $result;
  72. }
  73. }