Comendnotice.php 2.7 KB

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