Comendnotice.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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 * 36000);
  38. $model = $this->where([['game_start_time', '<=', $now], ['game_start_time', '>=', $lastDay], ['ctime', '>=', $lastDay], ['pcount', '=', 0]])->orderBy('game_start_time', 'asc')->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. $table = "st_" . $type . "_result";
  63. $sql = <<<EOS
  64. select tabb.match_id,tabb.start_time from
  65. ( select match_id,start_time from $table where start_time>='$time' and status=2 ) as tabb
  66. where match_id not in (select match_id from comendnotice where game_code='$type')
  67. order by match_id asc
  68. EOS;
  69. $result = DB::select($sql);
  70. return $result;
  71. }
  72. }