72 lines
2.3 KiB
PHP
72 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace common\jobs;
|
|
|
|
use common\forms\ProductRefundForm;
|
|
use common\helpers\FuncHelper;
|
|
use common\models\oldDb\ProductOrder;
|
|
use common\models\oldDb\ProductOrderLog;
|
|
use common\models\oldDb\ProductOrderRefund;
|
|
use yii\base\Exception;
|
|
use yii\queue\JobInterface;
|
|
use yii\queue\Queue;
|
|
|
|
//产品订单退款
|
|
class ProductRefundJob extends BaseJob implements JobInterface
|
|
{
|
|
public $orderId;
|
|
|
|
/**
|
|
* @param Queue $queue which pushed and is handling the job
|
|
*/
|
|
public function execute($queue)
|
|
{
|
|
ProductOrderLog::saveLog($this->orderId,'订单自动退款队列start');
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
$this->setRequest();
|
|
$ProductOrder = ProductOrder::find()->where([
|
|
'id' => $this->orderId,
|
|
'is_pay' => 1,
|
|
'cancel_status' => 0,
|
|
])->one();
|
|
if(!$ProductOrder){
|
|
throw new Exception('产品订单不存在');
|
|
}
|
|
|
|
|
|
//生成记录
|
|
$ProductOrderRefund = new ProductOrderRefund();
|
|
$ProductOrderRefund->user_id = $ProductOrder->user_id;
|
|
$ProductOrderRefund->order_id = $ProductOrder->id;
|
|
$ProductOrderRefund->refund_no = FuncHelper::generate_order_no('RF');
|
|
$ProductOrderRefund->refund_price = $ProductOrder->total_pay_price;
|
|
$ProductOrderRefund->remark = '超时未接诊自动退款';
|
|
$ProductOrderRefund->saveOrFail();
|
|
|
|
//取消状态
|
|
$ProductOrder->cancel_status = 1;
|
|
$ProductOrder->cancel_time = time();
|
|
$ProductOrder->cancel_remark = '超时未接诊自动取消';
|
|
|
|
//退款状态
|
|
$ProductOrder->refund_status = 1;
|
|
$ProductOrder->refund_time = time();
|
|
$ProductOrder->saveOrFail();
|
|
|
|
|
|
|
|
//退款操作
|
|
$ProductRefundForm = new ProductRefundForm();
|
|
$ProductRefundForm->refundMoney($ProductOrderRefund);
|
|
|
|
$t->commit();
|
|
ProductOrderLog::saveLog($this->orderId,'订单自动退款队列end');
|
|
|
|
} catch (\Exception $exception) {
|
|
$t->rollBack();
|
|
ProductOrderLog::saveLog($this->orderId,'订单自动退款队列异常:'.$exception->getMessage());
|
|
return;
|
|
}
|
|
}
|
|
} |