Stlqresult.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Support\Facades\DB;
  4. class Stlqresult extends BaseModel
  5. {
  6. protected $table = 'st_lq_result';
  7. public $timestamps = false;
  8. protected $fillable = ['lg_id','home_team','guest_team','home_rate','guest_rate','home_score','status','first_score','last_score','match_score','guest_score','match_winer','update_time','match_time','match_process','tag','u_home_score','u_guest_score','match_id','all_goal','source'];
  9. function resultbklist($list = 10, $page, $where = '', $orwhere = '',$if_order)
  10. {
  11. $match_ids = \App\Models\MoneyBuyMatch::select('match_id')->where('game_code','lq')->get()->toArray();
  12. $match_ids = array_column($match_ids,'match_id');
  13. //去重
  14. $match_ids = array_unique($match_ids);
  15. if($if_order == 1){
  16. if (is_array ($where) && count ($where) > 0) {
  17. $data = $this->join('st_lq_league','st_lq_result.lg_id','=','st_lq_league.id')->join('st_lq_competition','st_lq_competition.id','=','st_lq_result.match_id')->select($this->table.'.id',$this->table.'.lg_id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.home_rate',$this->table.'.guest_rate',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.all_goal','st_lq_competition.status',$this->table.'.first_score',$this->table.'.last_score',$this->table.'.match_score',$this->table.'.match_winer',$this->table.'.update_time',$this->table.'.match_time',$this->table.'.match_process',$this->table.'.tag',$this->table.'.match_id',$this->table.'.u_home_score',$this->table.'.start_time',$this->table.'.u_guest_score',$this->table.'.manual_result','st_lq_league.name_chinese')->orderby($this->table.'.id','desc')->where($where)->wherein('st_lq_competition.id',$match_ids)->paginate ($list);
  18. } else {
  19. $data = $this->join('st_lq_league','st_lq_result.lg_id','=','st_lq_league.id')->join('st_lq_competition','st_lq_competition.id','=','st_lq_result.match_id')->select($this->table.'.id',$this->table.'.lg_id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.home_rate',$this->table.'.guest_rate',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.all_goal','st_lq_competition.status',$this->table.'.first_score',$this->table.'.last_score',$this->table.'.match_score',$this->table.'.match_winer',$this->table.'.update_time',$this->table.'.match_time',$this->table.'.match_process',$this->table.'.tag',$this->table.'.match_id',$this->table.'.u_home_score',$this->table.'.start_time',$this->table.'.u_guest_score',$this->table.'.manual_result','st_lq_league.name_chinese')->orderby($this->table.'.id','desc')->wherein('st_lq_competition.id',$match_ids)->paginate ($list);
  20. }
  21. }else{
  22. if (is_array ($where) && count ($where) > 0) {
  23. $data = $this->join('st_lq_league','st_lq_result.lg_id','=','st_lq_league.id')->join('st_lq_competition','st_lq_competition.id','=','st_lq_result.match_id')->select($this->table.'.id',$this->table.'.lg_id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.home_rate',$this->table.'.guest_rate',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.all_goal','st_lq_competition.status',$this->table.'.first_score',$this->table.'.last_score',$this->table.'.match_score',$this->table.'.match_winer',$this->table.'.update_time',$this->table.'.match_time',$this->table.'.match_process',$this->table.'.tag',$this->table.'.match_id',$this->table.'.u_home_score',$this->table.'.start_time',$this->table.'.u_guest_score',$this->table.'.manual_result','st_lq_league.name_chinese')->orderby($this->table.'.id','desc')->where($where)->paginate ($list);
  24. } else {
  25. $data = $this->join('st_lq_league','st_lq_result.lg_id','=','st_lq_league.id')->join('st_lq_competition','st_lq_competition.id','=','st_lq_result.match_id')->select($this->table.'.id',$this->table.'.lg_id',$this->table.'.home_team',$this->table.'.guest_team',$this->table.'.home_rate',$this->table.'.guest_rate',$this->table.'.home_score',$this->table.'.guest_score',$this->table.'.all_goal','st_lq_competition.status',$this->table.'.first_score',$this->table.'.last_score',$this->table.'.match_score',$this->table.'.match_winer',$this->table.'.update_time',$this->table.'.match_time',$this->table.'.match_process',$this->table.'.tag',$this->table.'.match_id',$this->table.'.u_home_score',$this->table.'.start_time',$this->table.'.u_guest_score',$this->table.'.manual_result','st_lq_league.name_chinese')->orderby($this->table.'.id','desc')->paginate ($list);
  26. }
  27. }
  28. $newsim = new \App\Models\SportsNoteList();
  29. $simplex = $newsim->getsim('lq');
  30. $newstr = new \App\Models\MoneyBuyStr();
  31. $str = $newstr->strmatchs('lq');
  32. //print_r($str);exit;
  33. for ($i=0; $i < count($data); $i++) {
  34. $data[$i]->numsim = 0;
  35. for ($j=0; $j < count($simplex); $j++) {
  36. if($simplex[$j]['match_id'] == $data[$i]->match_id){
  37. $data[$i]->numsim = $data[$i]->numsim+1;
  38. }
  39. }
  40. $data[$i]->numstr = 0;
  41. for ($a=0; $a < count($str); $a++) {
  42. if(in_array($data[$i]->match_id,$str[$a]['match_ids'])){
  43. $data[$i]->numstr = $data[$i]->numstr+1;
  44. }
  45. }
  46. $data[$i]->manual_result = json_decode($data[$i]->manual_result,true);
  47. }
  48. return $data->toArray ();
  49. }
  50. //根据match_id查询比赛1-4节比分
  51. function allscore($match_id,$count=4){
  52. for ($i=1; $i < $count; $i++) {
  53. $where = array(
  54. 'match_id'=>$match_id,
  55. 'match_process'=>$i,
  56. );
  57. $data[] = $this->where($where)->select($this->table.'.home_score',$this->table.'.guest_score')->first();
  58. }
  59. return $data;
  60. }
  61. //根据match_id查询
  62. function onlyselect($match_id){
  63. $data = $this->where('match_id',$match_id)->select('lg_id','home_team','guest_team','home_rate','guest_rate','all_goal','first_score','last_score','match_score','match_winer','match_time','tag','match_id','u_home_score','u_guest_score','source')->first();
  64. if (!$data) {
  65. return -5040000102; //无相关信息
  66. }
  67. return $data->toArray();
  68. }
  69. //更新状态
  70. function updatastatus($match_id,$data){
  71. $res = $this->where ('match_id', $match_id)->update ($data);
  72. if (!$res) {
  73. return -7010101202; //更新失败
  74. }
  75. return 1;
  76. }
  77. //查询赛事
  78. function matchjg($match_id){
  79. $data = $this->where('match_id',$match_id)->select('id','home_team','guest_team')->first();
  80. if (!$data) {
  81. return -5040000102; //无相关信息
  82. }
  83. return $data->toArray();
  84. }
  85. //更新状态
  86. function updatestatus($field,$where,$data){
  87. $res=$this->where($field,$where)->update($data);
  88. if(!$res) {
  89. return -7020050022;//更新失败
  90. }
  91. return 1;
  92. }
  93. }
  94. ?>