66 lines
1.8 KiB
PHP
66 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace common\forms;
|
|
|
|
use common\core\BaseModel;
|
|
use common\enums\ProductOrderEnum;
|
|
use common\models\oldDb\ProductOrder;
|
|
use common\models\oldDb\ProductOrderRefund;
|
|
use yii\base\Exception;
|
|
|
|
class ProductRefundCancelForm extends BaseModel
|
|
{
|
|
public function rules()
|
|
{
|
|
return [
|
|
|
|
];
|
|
}
|
|
|
|
// 撤销退款申请
|
|
public function cancel($order_id)
|
|
{
|
|
$productOrder = ProductOrder::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'id' => $order_id
|
|
])->one();
|
|
|
|
if(!$productOrder || $productOrder->cancel_status || $productOrder->is_pay != 1 || $productOrder->refund_status!=1){
|
|
throw new Exception('订单不存在');
|
|
}
|
|
|
|
$productOrderRefund = ProductOrderRefund::find()->where([
|
|
'user_id' => \Yii::$app->user->identity->getId(),
|
|
'order_id' => $order_id,
|
|
'is_refund' => 0, //未退款
|
|
'status' => 0 //申请退款中
|
|
])->one();
|
|
|
|
if(!$productOrderRefund){
|
|
throw new Exception('订单不存在');
|
|
}
|
|
|
|
$t = \Yii::$app->db->beginTransaction();
|
|
try {
|
|
if($productOrder->is_send ==1){
|
|
$productOrder->status = ProductOrderEnum::ACCEPTED;
|
|
} else {
|
|
$productOrder->status = ProductOrderEnum::WAIT_SEND;
|
|
}
|
|
$productOrder->refund_status = 0;
|
|
$productOrder->refund_time = 0;
|
|
$productOrder->saveOrFail();
|
|
|
|
$productOrderRefund->status = 2;
|
|
$productOrderRefund->saveOrFail();
|
|
|
|
$t->commit();
|
|
|
|
return ['撤销退款申请成功'];
|
|
} catch (\Exception $exception) {
|
|
$t->rollBack();
|
|
throw $exception;
|
|
}
|
|
|
|
}
|
|
} |