SportsBase.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jonlin
  5. * Date: 2019/3/28
  6. * Time: 9:05
  7. */
  8. namespace App\Models;
  9. use Illuminate\Support\Facades\DB;
  10. class SportsBase extends BaseModel {
  11. protected $table = "st_bq_competition";
  12. public $timestamps = false;
  13. function getinfo($list = 10, $page, $where = '',$orwhere = '')
  14. {
  15. if (is_array ($where) && count ($where) > 0) {
  16. $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  17. ->select('st_bq_competition.id','st_bq_competition.match_id','st_bq_competition.lg_id','st_bq_league.name_chinese','st_bq_competition.home_team','st_bq_competition.guest_team','st_bq_competition.match_date','st_bq_competition.match_time','st_bq_competition.status','st_bq_competition.recommend')
  18. ->orderby('st_bq_competition.match_date','desc')
  19. ->orderby('st_bq_competition.match_time','desc')
  20. ->where($where)
  21. ->orwhere($orwhere)
  22. ->paginate ($list);
  23. } else {
  24. $data = $this->join('st_bq_league','st_bq_competition.lg_id','=','st_bq_league.lg_id')
  25. ->select('st_bq_competition.id','st_bq_competition.match_id','st_bq_competition.lg_id','st_bq_league.name_chinese','st_bq_competition.home_team','st_bq_competition.guest_team','st_bq_competition.match_date','st_bq_competition.match_time','st_bq_competition.status','st_bq_competition.recommend')
  26. ->orderby('st_bq_competition.match_date','desc')
  27. ->orderby('st_bq_competition.match_time','desc')
  28. ->paginate ($list);
  29. }
  30. if (!$data < 0) {
  31. return -2021052003; //
  32. }
  33. for($i=0;$i<count($data);$i++){
  34. if($data[$i]->match_date < date('Y-m-d',time())){
  35. $data[$i]->status = '2';
  36. //$this->where('id', $data[$i]->id)->update(['status' => 2]);
  37. }else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time)+5400 <= strtotime(date('H:i:s',time()))){
  38. $data[$i]->status = '2';
  39. //$this->where('id', $data[$i]->id)->update(['status' => 2]);
  40. }
  41. else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time) < strtotime(date('H:i:s',time())) && strtotime(date('H:i:s',time())) < strtotime($data[$i]->match_time)+5400){
  42. $data[$i]->status = '1';
  43. //$this->where('id', $data[$i]->id)->update(['status' => 1]);
  44. }else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time) > strtotime(date('H:i:s',time()))){
  45. $data[$i]->status = '0';
  46. //$this->where('id', $data[$i]->id)->update(['status' => 0]);
  47. }
  48. else if($data[$i]->match_date > date('Y-m-d',time())){
  49. $data[$i]->status = '0';
  50. //$this->where('id', $data[$i]->id)->update(['status' => 0]);
  51. }
  52. if($data[$i]->status==0){
  53. $data[$i]->status = '未开始';
  54. }else if($data[$i]->status==1){
  55. $data[$i]->status = '正在进行';
  56. }else if($data[$i]->status==2){
  57. $data[$i]->status = '已结束';
  58. }
  59. if($data[$i]->guest_team == ''){
  60. $data[$i]->home_guest = $data[$i]->home_team;
  61. }else{
  62. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  63. }
  64. $result = \App\Models\Comendnotice::where('match_id',$data[$i]->match_id)->where('game_code','bq')->first();
  65. if(!empty($result)){
  66. if($result->status == '0'){
  67. $data[$i]->result = '<a class="layui-btn layui-btn-sm dealwith" lay-event="detail" pid="id" uri="/admin/SportsBase/dealwith/?id=" href="javascript:dealwith(\'/admin/SportsBase/dealwith/?id='.$result->id.'\');" style="background-color: #FF5722;"> 处理 </a>';
  68. }else{
  69. $data[$i]->result = '<a class="layui-btn layui-btn-sm dealwith" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 已处理 </a>';
  70. }
  71. }else{
  72. $data[$i]->result = '<a class="layui-btn layui-btn-sm audit" lay-event="detail" pid="id" uri="" href="javascript:void(0)" style="background-color: grey;"> 处理 </a>';
  73. }
  74. }
  75. return $data->toArray();
  76. }
  77. //更新设置
  78. function updateInfos($data,$id){
  79. $res=$this->where('id',$id)->update($data);
  80. if(!$res) {
  81. return -7020050022;//更新失败
  82. }
  83. return 1;
  84. }
  85. function getmatchid($id){
  86. $res=$this->where('id',$id)->first();
  87. if(!$res){
  88. return -2021052003;
  89. }
  90. return $res->match_id;
  91. }
  92. }