jingcai-php/app/Jobs/HandleOrderPaySuccess.php

61 lines
1.8 KiB
PHP
Executable File

<?php
namespace App\Jobs;
use App\Enums\LottState;
use App\Enums\PayState;
use App\Model\Order;
use App\Service\External\WechatService;
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 HandleOrderPaySuccess implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $orderId;
public function __construct($orderId)
{
$this->orderId = $orderId;
$this->queue = config('queue.names.handle_order_pay_success');
}
public function handle()
{
$order = Order::where('pay_state', PayState::SUCCESS)
->where('lottery_state', LottState::PENDING)
->find($this->orderId);
if (!$order) {
Log::error('HandleOrderPaySuccess not found order ', [
'order_id' => $this->orderId
]);
return ;
}
if ($order->pay_state != PayState::SUCCESS) {
Log::error('HandleOrderPaySuccess order pay_state error ', [
'order_id' => $this->orderId,
'pay_state' => $order->pay_state,
]);
return ;
}
if ($order->lottery_state != LottState::PENDING) {
Log::error('HandleOrderPaySuccess order lottery_state error ', [
'order_id' => $this->orderId,
'lottery_state' => $order->lottery_state,
]);
return ;
}
Log::info('HandleOrderPaySuccess orderId:'. $this->orderId);
/** @var WechatService $wechatService */
$wechatService = app(WechatService::class);
$wechatService->sendTemplateMessage($order);
}
}