270 lines
7.2 KiB
PHP
Executable File
270 lines
7.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Service;
|
|
|
|
use App\Enums\PlayType;
|
|
use App\Exceptions\JingCaiException;
|
|
use App\Model\Lq\JclqOdds;
|
|
use App\Model\Zq\JczqOdds;
|
|
use App\Utils\ThrowException;
|
|
use Illuminate\Support\Arr;
|
|
|
|
class PlayTypeService
|
|
{
|
|
|
|
public function validPlayType($playType, $data)
|
|
{
|
|
$matchNum = count($data);
|
|
if ($matchNum == 1) {
|
|
$oddsDataId = array_key_first($data);
|
|
$jczqOdds = JczqOdds::find($oddsDataId);
|
|
ThrowException::isTrue(!$jczqOdds, '数据不存在');
|
|
|
|
$oddsDataInfo = Arr::get($data, $oddsDataId);
|
|
foreach ($oddsDataInfo as $playType => $v) {
|
|
$single = Arr::get($jczqOdds, $playType.'.single');
|
|
ThrowException::isTrue(!$single, '请选择1场单关或任意2场比赛进行投注');
|
|
}
|
|
}
|
|
|
|
|
|
switch ($playType) {
|
|
case PlayType::MIXED:
|
|
$this->validMixed($data);
|
|
return;
|
|
case PlayType::SINGLE:
|
|
$this->validSingle($data);
|
|
return;
|
|
case PlayType::SPFRQ:
|
|
$this->validSpfRq($data);
|
|
return;
|
|
case PlayType::SPF:
|
|
return;
|
|
case PlayType::RQ:
|
|
return;
|
|
case PlayType::BQC:
|
|
$this->validBqc($data);
|
|
return;
|
|
case PlayType::BF:
|
|
$this->validBf($data);
|
|
return;
|
|
case PlayType::JQ:
|
|
$this->validJq($data);
|
|
return;
|
|
case PlayType::BJDC_BF:
|
|
case PlayType::BJDC_SPF:
|
|
case PlayType::BJDC_RQ:
|
|
case PlayType::BJDC_BQC:
|
|
case PlayType::BJDC_SXPDS:
|
|
case PlayType::BJDC_JQ:
|
|
return;
|
|
}
|
|
JingCaiException::throwJingcai('无效的玩法');
|
|
}
|
|
|
|
/**
|
|
* 混合投注
|
|
* @param $playType
|
|
* @param $data
|
|
*/
|
|
public function validMixed($data)
|
|
{
|
|
$this->validSpfRq($data);
|
|
$this->validBqc($data);
|
|
$this->validBf($data);
|
|
$this->validJq($data);
|
|
}
|
|
|
|
/**
|
|
* 胜平负/让球
|
|
* @param $playType
|
|
* @param $data
|
|
*/
|
|
public function validSpfRq($data)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* 全场比分
|
|
* @param $playType
|
|
* @param $data
|
|
*/
|
|
public function validBf($data)
|
|
{
|
|
$hasBf = false;
|
|
foreach ($data as $id => $item) {
|
|
if (isset($item[PlayType::BF])) {
|
|
$hasBf = true;
|
|
break;
|
|
}
|
|
}
|
|
if ($hasBf && count($data) > 4) {
|
|
// JingCaiException::throwJingcai("比分玩法最多选4场");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 总进球
|
|
* @param $playType
|
|
* @param $data
|
|
*/
|
|
public function validJq($data)
|
|
{
|
|
|
|
}
|
|
|
|
/**
|
|
* 半全场
|
|
* @param $playType
|
|
* @param $data
|
|
*/
|
|
public function validBqc($data)
|
|
{
|
|
$hasBqc = false;
|
|
foreach ($data as $id => $item) {
|
|
if (isset($item[PlayType::BQC])) {
|
|
$hasBqc = true;
|
|
break;
|
|
}
|
|
}
|
|
if ($hasBqc && count($data) > 4) {
|
|
// JingCaiException::throwJingcai("半全场玩法最多选4场");
|
|
}
|
|
}
|
|
|
|
public function validSingle($data)
|
|
{
|
|
if (count($data) > 1) {
|
|
JingCaiException::throwJingcai("此玩法只支持一场比赛");
|
|
}
|
|
if (count($data) < 1) {
|
|
JingCaiException::throwJingcai('请选择一场比赛进行投注');
|
|
}
|
|
$match = array_pop($data);
|
|
$spf = Arr::get($match, 'spf_odds');
|
|
$rq = Arr::get($match, 'rq_odds');
|
|
if (!$spf && !$rq) {
|
|
JingCaiException::throwJingcai('请选择一场比赛进行投注');
|
|
}
|
|
$match = $this->singleSelectMatch($spf, $rq);
|
|
throw_if(!$match, JingCaiException::create('没有符合匹配的赛事'));
|
|
}
|
|
|
|
/**
|
|
* 单场决胜,匹配场次
|
|
* @param $spf
|
|
* @param $rq
|
|
* @return |null
|
|
*/
|
|
public function singleSelectMatch($spf, $rq)
|
|
{
|
|
$swin = 1.75;
|
|
$rloss = 1.8;
|
|
if ((isset($spf['win']) && $spf['win'] == $swin) || (isset($rq['loss']) && $rq['loss'] == $rloss)) {
|
|
$temp = $swin;
|
|
$swin = $rloss;
|
|
$rloss = $temp;
|
|
}
|
|
$query = JczqOdds::selling()
|
|
->whereRaw("spf_odds->'$.win'={$swin} and rq_odds->'$.loss'={$rloss}");
|
|
if (isset($rq)) {
|
|
foreach ($rq as $k => $val) {
|
|
if ($k == 'loss') {
|
|
continue;
|
|
}
|
|
$query->whereRaw("rq_odds->'$.{$k}'={$val}");
|
|
}
|
|
}
|
|
if ($spf) {
|
|
foreach ($spf as $k => $val) {
|
|
if ($k == 'win') {
|
|
continue;
|
|
}
|
|
$query->whereRaw("spf_odds->'$.{$k}'={$val}");
|
|
}
|
|
}
|
|
$oddses = $query->get();
|
|
$one = collect($oddses)->shuffle()->first();
|
|
if (!$one) {
|
|
return null;
|
|
}
|
|
$oneOdds = $one->toArray();
|
|
unset($oneOdds['spf_odds']['loss']);
|
|
unset($oneOdds['spf_odds']['draw']);
|
|
unset($oneOdds['spf_odds']['single']);
|
|
unset($oneOdds['rq_odds']['win']);
|
|
unset($oneOdds['rq_odds']['draw']);
|
|
unset($oneOdds['rq_odds']['single']);
|
|
unset($oneOdds['rq_odds']['handicap']);
|
|
|
|
unset($oneOdds['spf_odds_last']);
|
|
unset($oneOdds['rq_odds_last']);
|
|
unset($oneOdds['bf_odds_last']);
|
|
unset($oneOdds['bf_odds']);
|
|
unset($oneOdds['jq_odds']);
|
|
unset($oneOdds['jq_odds_last']);
|
|
unset($oneOdds['bqc_odds']);
|
|
unset($oneOdds['bqc_odds_last']);
|
|
return $oneOdds;
|
|
}
|
|
|
|
|
|
public function validLqPlayType($playType, $data) {
|
|
$oddsId = array_key_first($data);
|
|
$jclqOdds = JclqOdds::find($oddsId);
|
|
$oddInfo = $data[$oddsId];
|
|
foreach ($oddInfo as $play =>$v) {
|
|
$info = $jclqOdds->{$play};
|
|
ThrowException::isTrue(!$info, '无此玩法:'.$play);
|
|
}
|
|
|
|
switch ($playType) {
|
|
case PlayType::MIXED:
|
|
$this->validLqMixed($data);
|
|
return;
|
|
case PlayType::LQ_SFRF:
|
|
return;
|
|
case PlayType::LQ_SF:
|
|
return;
|
|
case PlayType::LQ_RF:
|
|
$this->validLqSfRf($data);
|
|
return;
|
|
case PlayType::LQ_DXF:
|
|
$this->validLqDxf($data);
|
|
return;
|
|
case PlayType::LQ_SFC:
|
|
$this->validLqSfc($data);
|
|
return;
|
|
}
|
|
JingCaiException::throwJingcai('无效的玩法');
|
|
}
|
|
public function validLqMixed($data) {
|
|
|
|
}
|
|
public function validLqSfRf($data) {
|
|
|
|
}
|
|
public function validLqDxf($data) {
|
|
|
|
}
|
|
public function validLqSfc($data) {
|
|
|
|
}
|
|
|
|
public function validBjdcPlayType($playType, $data)
|
|
{
|
|
|
|
switch ($playType) {
|
|
|
|
case PlayType::BJDC_BF:
|
|
case PlayType::BJDC_SPF:
|
|
case PlayType::BJDC_RQ:
|
|
case PlayType::BJDC_BQC:
|
|
case PlayType::BJDC_SXPDS:
|
|
case PlayType::BJDC_JQ:
|
|
return;
|
|
}
|
|
JingCaiException::throwJingcai('无效的玩法');
|
|
}
|
|
}
|