feat : refund
This commit is contained in:
51
app/Service/Api/Order/CancelOrderService.php
Normal file
51
app/Service/Api/Order/CancelOrderService.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Order;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class CancelOrderService extends BaseService
|
||||
{
|
||||
use OrderChangeStatusTrait;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$orderId = (int)$this->request->input('order_id');
|
||||
$type = (int)$this->request->input('type');
|
||||
|
||||
$orderInfo = $this->orderModel->getInfoById($orderId);
|
||||
|
||||
if ($orderInfo->status != OrderCode::WAIT_PAY) throw new ErrException('该订单状态已变更,请勿重复操作');
|
||||
|
||||
//立即取消
|
||||
$this->joinCancelDelayQueue($orderId, $type,1);
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@ use App\Exception\ErrException;
|
||||
use App\Extend\DateUtil;
|
||||
use App\Model\Order;
|
||||
use App\Model\OrderGood;
|
||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||
use Exception;
|
||||
use Hyperf\Amqp\Producer;
|
||||
use Hyperf\Context\ApplicationContext;
|
||||
@@ -26,6 +27,8 @@ use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class PlaceOrderService extends BaseOrderService
|
||||
{
|
||||
use OrderChangeStatusTrait;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
@@ -61,28 +64,17 @@ class PlaceOrderService extends BaseOrderService
|
||||
$this->placeOrder();
|
||||
|
||||
// 加入取消延迟队列
|
||||
$this->joinCancelDelayQueue();
|
||||
$this->joinCancelDelayQueue(
|
||||
$this->orderId,
|
||||
OrderCode::ORDER_TYPE_GOOD,
|
||||
(int)$this->configCache->getConfigValue(ConfigCode::ORDER_CANCEL_TIME_KEY) * DateUtil::MINUTE * DateUtil::MS
|
||||
);
|
||||
|
||||
$this->sendStockMq($this->orderId,OrderCode::WAIT_PAY);
|
||||
|
||||
return $this->return->success('success',$this->orderRes);
|
||||
}
|
||||
|
||||
/**
|
||||
* 加入取消队列
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function joinCancelDelayQueue(): void
|
||||
{
|
||||
$message = new CancelOrderProducer([
|
||||
'order_id' => $this->orderId,
|
||||
'type' => OrderCode::ORDER_TYPE_GOOD
|
||||
]);
|
||||
$message->setDelayMs((int)$this->configCache->getConfigValue(ConfigCode::ORDER_CANCEL_TIME_KEY) * DateUtil::MINUTE * DateUtil::MS);
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$producer->produce($message);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
|
||||
51
app/Service/Api/Order/RefundOrderService.php
Normal file
51
app/Service/Api/Order/RefundOrderService.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Api\Order;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class RefundOrderService extends BaseService
|
||||
{
|
||||
use OrderChangeStatusTrait;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$orderId = (int)$this->request->input('order_id');
|
||||
$type = (int)$this->request->input('type');
|
||||
|
||||
$orderInfo = $this->orderModel->getInfoById($orderId);
|
||||
|
||||
if ($orderInfo->status != OrderCode::PAYED) throw new ErrException('该订单状态已变更,请勿重复操作,刷新后无法退款请联系客服');
|
||||
|
||||
//立即取消
|
||||
$this->joinRefundQueue($orderId, $type);
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user