StZqOdds.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Model;
  3. use function foo\func;
  4. use Illuminate\Support\Facades\DB;
  5. use Illuminate\Database\Eloquent\Model;
  6. /**
  7. * Class StZqOdds
  8. * @package App\Http\Model
  9. * 足球 赔率
  10. */
  11. class StZqOdds extends Model
  12. {
  13. protected $table = 'st_zq_odds';
  14. public $timestamps = false;
  15. protected $fillable = ['match_id','others_match_id','odds_code','status','sort','p_code','odds','condition','odds_only','sole','source','type','team','lg_id','others_lg_id','ctime','utime','expire_time'];
  16. /*
  17. * 获取一段时间内所有的赔率
  18. */
  19. public static function getOddsID($models){
  20. $Odds_data = $models['model_odds']::select('id','sole','source')
  21. ->where([['utime','>',date('Y-m-d H:i:s' , strtotime("-1 day"))]])
  22. ->get()
  23. ->toArray();
  24. return $Odds_data;
  25. }
  26. /*
  27. * 更新赛事下赔率状态
  28. */
  29. public static function upOddsStatus($model=[],$others_match_id='',$others_lg_id=[],$source='',$odds_only=[]){
  30. $where = [];
  31. //普通 赔率
  32. if(!empty($others_match_id) and !empty($source)){
  33. $where = [
  34. ['others_match_id','=',$others_match_id],
  35. ['source','=',$source]
  36. ];
  37. //获取当前 赛事 所有 赔率only
  38. $odds_data = $model['model_odds']::select('odds_only')
  39. ->where($where)
  40. ->get()
  41. ->toArray();
  42. }
  43. //冠军联赛 赔率
  44. if(!empty($others_lg_id) and !empty($source)){
  45. //获取当前 赛事 所有 赔率only
  46. $odds_data = $model['model_odds']::select('odds_only')
  47. ->whereIn('others_lg_id',$others_lg_id)
  48. ->where(['source','=',$source])
  49. ->get()
  50. ->toArray();
  51. }
  52. if(empty($odds_data)) return true;
  53. //去除 本次请求的 赔率only
  54. if(is_array($odds_data) and !empty($odds_only)){
  55. foreach ($odds_data as $k => $v){
  56. foreach ($odds_only as $kk => $vv){
  57. if($v['odds_only'] == $vv) unset($odds_data[$k]);
  58. }
  59. }
  60. }
  61. if(empty($odds_data)) return true;
  62. //降维 获取所有only
  63. $only = [];
  64. if(is_array($odds_data)){
  65. foreach ($odds_data as $k => $v){
  66. $only[] = $v['odds_only'];
  67. }
  68. }
  69. //批量更新 赔率状态
  70. $ds = $model['model_odds']::whereIn('odds_only', $only)
  71. ->update(['status' => -1]);
  72. if($ds > 0 ) return true;
  73. }
  74. }