SportsBasket.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: Jonlin
  5. * Date: 2019/3/29
  6. * Time: 9:28
  7. */
  8. namespace App\Models;
  9. use Illuminate\Support\Facades\DB;
  10. class SportsBasket extends BaseModel {
  11. protected $table = "st_lq_competition";
  12. public $timestamps = false;
  13. function getinfo($list = 10, $page, $where = '')
  14. {
  15. if (is_array ($where) && count ($where) > 0) {
  16. $data = $this->join('st_lq_league','st_lq_competition.lg_id','=','st_lq_league.lg_id')
  17. ->select('st_lq_competition.id','st_lq_competition.match_id','st_lq_competition.lg_id','st_lq_league.name_chinese','st_lq_competition.home_team','st_lq_competition.guest_team','st_lq_competition.match_date','st_lq_competition.match_time','st_lq_competition.status')
  18. ->orderby('st_lq_competition.match_date','desc')
  19. ->orderby('st_lq_competition.match_time','desc')
  20. ->where($where)
  21. ->paginate ($list);
  22. } else {
  23. $data = $this->join('st_lq_league','st_lq_competition.lg_id','=','st_lq_league.lg_id')
  24. ->select('st_lq_competition.id','st_lq_competition.match_id','st_lq_competition.lg_id','st_lq_league.name_chinese','st_lq_competition.home_team','st_lq_competition.guest_team','st_lq_competition.match_date','st_lq_competition.match_time','st_lq_competition.status')
  25. ->orderby('st_lq_competition.match_date','desc')
  26. ->orderby('st_lq_competition.match_time','desc')
  27. ->paginate ($list);
  28. }
  29. if (!$data < 0) {
  30. return -2021052003; //
  31. }
  32. for($i=0;$i<count($data);$i++){
  33. if($data[$i]->match_date < date('Y-m-d',time())){
  34. $data[$i]->status = '2';
  35. $this->where('id', $data[$i]->id)->update(['status' => 2]);
  36. }else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time)+2400 <= strtotime(date('H:i:s',time()))){
  37. $data[$i]->status = '2';
  38. $this->where('id', $data[$i]->id)->update(['status' => 2]);
  39. }
  40. 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)+2400){
  41. $data[$i]->status = '1';
  42. $this->where('id', $data[$i]->id)->update(['status' => 1]);
  43. }else if($data[$i]->match_date == date('Y-m-d',time()) && strtotime($data[$i]->match_time) > strtotime(date('H:i:s',time()))){
  44. $data[$i]->status = '0';
  45. $this->where('id', $data[$i]->id)->update(['status' => 0]);
  46. }
  47. else if($data[$i]->match_date > date('Y-m-d',time())){
  48. $data[$i]->status = '0';
  49. $this->where('id', $data[$i]->id)->update(['status' => 0]);
  50. }
  51. if($data[$i]->status==0){
  52. $data[$i]->status = '未开始';
  53. }else if($data[$i]->status==1){
  54. $data[$i]->status = '正在进行';
  55. }else if($data[$i]->status==2){
  56. $data[$i]->status = '已结束';
  57. }
  58. $data[$i]->home_guest = $data[$i]->home_team.' VS '.$data[$i]->guest_team;
  59. }
  60. return $data->toArray();
  61. }
  62. //更新设置
  63. function updateInfos($data,$id){
  64. $res=$this->where('id',$id)->update($data);
  65. if(!$res) {
  66. return -7020050022;//更新失败
  67. }
  68. return 1;
  69. }
  70. function getmatchid($id){
  71. $res=$this->where('id',$id)->first();
  72. if(!$res<0){
  73. return -2021052003;
  74. }
  75. return $res->match_id;
  76. }
  77. }