101 lines
3.2 KiB
PHP
Executable File
101 lines
3.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Jobs;
|
|
|
|
|
|
use App\Enums\BoolEnum;
|
|
use App\Enums\LottState;
|
|
use App\Enums\OrderType;
|
|
use App\Events\OrderWinedEvent;
|
|
use App\Model\Config;
|
|
use App\Model\Order;
|
|
use App\Model\OrderGuanResult;
|
|
use App\Model\Zq\JczqGuanOdds;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
use Illuminate\Support\Facades\Log;
|
|
|
|
class ComputeGuanOrderPrize implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
protected $orderId;
|
|
|
|
public function __construct($orderId)
|
|
{
|
|
$this->orderId = $orderId;
|
|
$this->queue = config('queue.names.compute_order_prize');
|
|
}
|
|
|
|
public function handle()
|
|
{
|
|
Log::info('ComputeGuanOrderPrize::start, orderId:' . $this->orderId);
|
|
|
|
$unPublishes = OrderGuanResult::where('order_id')->where('published', BoolEnum::NO)->count();
|
|
if ($unPublishes > 0) {
|
|
Log::error('ComputeGuanOrderPrize has no publish match, orderId:' . $this->orderId);
|
|
return;
|
|
}
|
|
$order = Order::find($this->orderId);
|
|
if ($order->lottery_state != LottState::WAIT) {
|
|
Log::error('ComputeGuanOrderPrize 订单状态不是待开奖状态, orderId:' . $this->orderId);
|
|
return;
|
|
}
|
|
|
|
$odds = $order->odds;
|
|
$jczqGuanOddsIds = array_keys($odds);
|
|
$guanResults = OrderGuanResult::where('order_id', $this->orderId)
|
|
->whereIn('jczq_guan_odds_id', $jczqGuanOddsIds)->get();
|
|
if (count($guanResults) != count($jczqGuanOddsIds)) {
|
|
Log::error('ComputeGuanOrderPrize 开奖结果和投注信息中的id对应不上', [
|
|
'order_id' => $this->orderId,
|
|
'order_odds' => $odds,
|
|
'order_odds_ids' => $jczqGuanOddsIds,
|
|
'result_odds_ids' => $guanResults->pluck('jczq_guan_odds_id')->toArray(),
|
|
]);
|
|
return;
|
|
}
|
|
|
|
$winOdds = JczqGuanOdds::whereIn('id', $jczqGuanOddsIds)->where('show_state', 'win')->first();
|
|
|
|
$winPrize = 0;
|
|
$winTaxPrize = 0;
|
|
|
|
if ($winOdds) {
|
|
$onePrize = $odds[$winOdds->id] * Config::lotteryUnitPrice();
|
|
|
|
$winPrize = $onePrize * $order->bets_num;
|
|
$winTaxPrize = Config::getAfterTaxPrizeIfOne($winPrize, $onePrize);
|
|
}
|
|
|
|
|
|
$gendanBrokerage = 0;
|
|
if ($order->type == OrderType::GENDAN) {
|
|
$gendanBrokerage = $winTaxPrize* Config::fadanAllFeeLv();
|
|
}
|
|
|
|
if ($winPrize > 0) {
|
|
$order->lottery_state = LottState::WIN;
|
|
$order->lottery_prize = $winPrize;
|
|
$order->lottery_tax_prize = $winTaxPrize;
|
|
$order->lottery_should_send_prize = $winTaxPrize;
|
|
$order->lottery_gendan_brokerage = 0;
|
|
$order->lottery_gendan_brokerage_all = 0;
|
|
} else {
|
|
$order->lottery_state = LottState::LOSS;
|
|
}
|
|
|
|
$order->win_date = date('Ymd');
|
|
$order->save();
|
|
$order->updateUnionOrderState($order->lottery_state);
|
|
if ($order->lottery_state == LottState::WIN) {
|
|
OrderWinedEvent::dispatch($order->id);
|
|
}
|
|
|
|
}
|
|
|
|
}
|