66 lines
2.3 KiB
PHP
66 lines
2.3 KiB
PHP
<?php
|
|
namespace common\jobs;
|
|
|
|
use common\enums\ProductOrderEnum;
|
|
use common\models\newDb\AccountBalanceModel;
|
|
use common\models\oldDb\ProductOrder;
|
|
use common\models\oldDb\ProductOrderLog;
|
|
use yii\queue\JobInterface;
|
|
use yii\queue\Queue;
|
|
|
|
|
|
//产品订单自动收货
|
|
class ProductOrderAutoReceivedJob extends BaseJob implements JobInterface
|
|
{
|
|
public $orderId;
|
|
|
|
/**
|
|
* @param Queue $queue which pushed and is handling the job
|
|
*/
|
|
public function execute($queue)
|
|
{
|
|
try {
|
|
echo $this->orderId. "产品订单自动收货队列开始执行\n";
|
|
ProductOrderLog::saveLog($this->orderId,'产品订单自动收货队列start');
|
|
$this->setRequest();
|
|
//判断是否已发货状态且到达自动收货时间
|
|
$ProductOrder = ProductOrder::findOne([
|
|
'id' => $this->orderId,
|
|
'is_pay' => 1,
|
|
'is_send' => 1, // 已发货
|
|
'status' => 2 //待收货
|
|
]);
|
|
|
|
if (!$ProductOrder) {
|
|
echo $this->orderId. "产品订单自动收货队列-订单不存在或已确认\n";
|
|
ProductOrderLog::saveLog($this->orderId,'订单不存在或已确认');
|
|
throw new \Exception('订单不存在');
|
|
}
|
|
|
|
if ($ProductOrder->order_type === 5) {
|
|
$client = new \GuzzleHttp\Client();
|
|
$response = $client->post( 'https://api.xiaokang88.com/open-api/client-confirm', [
|
|
'json' => [
|
|
'order_id' => $this->orderId,
|
|
]
|
|
]);
|
|
$body = json_decode($response->getBody()->getContents(), true);
|
|
if ($body['code'] != 0) {
|
|
exit($body['message']);
|
|
}
|
|
}
|
|
|
|
$ProductOrder->status = ProductOrderEnum::CONFIRM;
|
|
$ProductOrder->received_time = time();
|
|
$ProductOrder->save();
|
|
|
|
|
|
ProductOrderLog::saveLog($this->orderId,'产品订单自动收货队列end');
|
|
|
|
echo $this->orderId. "产品订单自动收货队列执行成功\n";
|
|
} catch (\Exception $exception) {
|
|
ProductOrderLog::saveLog($this->orderId,'产品订单自动收货队列异常:'.$exception->getMessage().'------'.$exception->getLine());
|
|
return;
|
|
}
|
|
}
|
|
} |