Comendnotice.php 2.5 KB

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