Files
xk-api-yii/common/jobs/ProductOrderSyncPlatformJob.php

53 lines
1.6 KiB
PHP

<?php
namespace common\jobs;
use common\models\oldDb\ProductOrder;
use common\models\oldDb\ProductOrderLog;
use common\services\PlatformService;
use yii\queue\JobInterface;
use yii\queue\Queue;
//平台产生的产品订单状态同步
class ProductOrderSyncPlatformJob extends BaseJob implements JobInterface
{
public $orderId;
public $status;
public function rules(){
return [
[['orderId','status'],'required'],
[['status', 'integer']]
];
}
/**
* @param Queue $queue which pushed and is handling the job
*/
public function execute($queue)
{
try {
ProductOrderLog::saveLog($this->orderId,'产品订单状态同步平台队列start');
$this->setRequest();
$ProductOrder = ProductOrder::findOne([
'id' => $this->orderId,
'is_online' => 1,
]);
if (!$ProductOrder || !$ProductOrder->sync_order_no) {
throw new \Exception('订单不存在');
}
$result = (new PlatformService())->updateOrder([
'store_id' => 0,
'order_no' => $ProductOrder->sync_order_no,
'status' => $this->status
]);
ProductOrderLog::saveLog($this->orderId,'产品订单状态同步平台队列end');
} catch (\Exception $exception) {
ProductOrderLog::saveLog($this->orderId,'产品订单状态同步平台队列异常:'.$exception->getMessage());
return;
}
return $result;
}
}