jingcai-php/app/Model/Zq/JczqResult.php

108 lines
2.9 KiB
PHP
Executable File

<?php
namespace App\Model\Zq;
use App\Model\BaseModel;
use App\Utils\Helps;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\DB;
class JczqResult extends BaseModel
{
protected $appends = [
'issue_week',
];
public function match() {
return $this->belongsTo(ZqMatch::class, 'match_id', 'match_id');
}
public function getIssueWeekAttribute()
{
return self::getIssueNumWeek($this->issue_num);
}
public static function getIssueNumWeek($issueNum)
{
if (!$issueNum) {
return '';
}
$arr = explode('/', $issueNum);
return Arr::get($arr, 1);
}
/**
* 是否取消比赛
* @return bool
*/
public function canceled()
{
return $this->lottery_state == 'cancelLottery';
}
public function odds() {
return $this->hasOne(JczqOdds::class, 'odds_id', 'odds_id');
}
public static function getAutoOrderOdds($date, $chuanNum, $moneyRateMin, $moneyRateMax) {
$result = JczqResult::with('odds')
->where('issue_date', date('Y-m-d', strtotime('-1 day')))
->get();
if (count($result) < $chuanNum) {
return null;
}
$result = collect($result)->shuffle();
$odds = [];
foreach ($result as $item) {
$rateOdd = $item->getOddsForRate($moneyRateMin, $moneyRateMax, $chuanNum);
if (!$rateOdd) {
continue;
}
if (count($odds) >= $chuanNum) {
break;
}
$odds = $odds + $rateOdd;
}
return $odds;
}
public function getOddsForRate($moneyRateMin, $moneyRateMax, $chuanNum) {
if ($chuanNum == 1) {
$single = Arr::get($this->odds->spf_odds, 'single');
if ($single && $this->spf_odds >= $moneyRateMin && $this->spf_odds <= $moneyRateMax) {
return [$this->jczq_odds_id => [
'spf_odds' => [
$this->spf_field => $this->spf_odds
]
]];
}
$single = Arr::get($this->odds->rq_odds, 'single');
if ($single && $this->rq_odds >= $moneyRateMin && $this->rq_odds <= $moneyRateMax) {
return [$this->jczq_odds_id => [
'rq_odds' => [$this->rq_field => $this->rq_odds]
]];
}
return null;
}
if ($this->rq_odds >= $moneyRateMin && $this->rq_odds <= $moneyRateMax) {
return [$this->jczq_odds_id => [
'rq_odds' => [$this->rq_field => $this->rq_odds]
]];
}
if ($this->spf_odds >= $moneyRateMin && $this->spf_odds <= $moneyRateMax) {
return [$this->jczq_odds_id => [
'spf_odds' => [
$this->spf_field => $this->spf_odds
]
]];
}
return null;
}
}