StZqOdds.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace App\Http\Model;
  3. //use function foo\func;
  4. use Illuminate\Database\Capsule\Manager as 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=[],$is_stringscene=0){
  30. $where = [];
  31. //普通 赔率
  32. if(!empty($others_match_id) and !empty($source)){
  33. $where = [
  34. ['others_match_id','=',$others_match_id],
  35. ['is_stringscene','=',$is_stringscene],
  36. ['source','=',$source]
  37. ];
  38. //获取当前 赛事 所有 赔率only
  39. $odds_data = $model['model_odds']::select('odds_only')
  40. ->where($where)
  41. ->get()
  42. ->toArray();
  43. }
  44. //冠军联赛 赔率
  45. if(!empty($others_lg_id) and !empty($source)){
  46. //获取当前 赛事 所有 赔率only
  47. $odds_data = $model['model_odds']::select('odds_only')
  48. ->whereIn('others_lg_id',$others_lg_id)
  49. ->where('source',$source)
  50. ->get()
  51. ->toArray();
  52. }
  53. if(empty($odds_data)) return true;
  54. //去除 本次请求的 赔率only
  55. if(is_array($odds_data) and !empty($odds_only)){
  56. foreach ($odds_data as $k => $v){
  57. foreach ($odds_only as $kk => $vv){
  58. if($v['odds_only'] == $vv) unset($odds_data[$k]);
  59. }
  60. }
  61. }
  62. if(empty($odds_data)) return true;
  63. //降维 获取所有only
  64. $only = [];
  65. if(is_array($odds_data)){
  66. foreach ($odds_data as $k => $v){
  67. $only[] = $v['odds_only'];
  68. }
  69. }
  70. //批量更新 赔率状态
  71. $del = $model['model_odds']::whereIn('odds_only', $only)
  72. ->delete();
  73. if($del) return true;
  74. }
  75. }