feat : refund
This commit is contained in:
@@ -44,6 +44,11 @@ abstract class BaseRefundOrderService
|
||||
*/
|
||||
public int $type;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $adminId = 0;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -213,6 +218,7 @@ abstract class BaseRefundOrderService
|
||||
$this->refundInfo = new RefundOrder();
|
||||
|
||||
$this->refundInfo->user_id = $this->orderInfo->user_id;
|
||||
$this->refundInfo->action_admin_id = $this->adminId;
|
||||
$this->refundInfo->order_type = OrderCode::ORDER_TYPE_GOOD;
|
||||
$this->refundInfo->order_id = $this->orderId;
|
||||
$this->refundInfo->pay_id = $this->payInfo->id;
|
||||
|
||||
@@ -10,6 +10,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
use App\Constants\Common\RefundCode;
|
||||
use App\Event\RefundGoodOrderFinishEvent;
|
||||
use App\Lib\Log;
|
||||
use App\Model\Order;
|
||||
@@ -103,11 +104,23 @@ class RefundGoodOrderFinishService
|
||||
$this->manageSubCateringLog();
|
||||
});
|
||||
|
||||
if ($this->rollBackStockFlag) {
|
||||
$this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||
}
|
||||
|
||||
$this->eventDispatcher->dispatch(new RefundGoodOrderFinishEvent($this->orderInfo->id, $this->payInfo->id, $this->refundInfo->id));
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
private function rollBackStock(): void
|
||||
{
|
||||
if (!$this->rollBackStockFlag) return;
|
||||
|
||||
//判断是不是用户行为才退库存
|
||||
if ($this->refundInfo->action_admin_id != 0) return;
|
||||
|
||||
$this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,6 @@ class PlaceOrderService extends BaseOrderService
|
||||
foreach ($this->cartFirstData as $goodId => $stock) {
|
||||
$this->rollbackStockCache[$goodId] = $stock;
|
||||
if (!($this->redis->zIncrBy($this->stockKey,-$stock,$goodId))) {
|
||||
echo '123';
|
||||
throw new Exception('cache error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,8 +15,10 @@ use App\Constants\Common\RefundCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Order;
|
||||
use App\Model\PayOrder;
|
||||
use App\Service\Amqp\Refund\FullRefundOrderService;
|
||||
use App\Service\Api\BaseService;
|
||||
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -46,18 +48,26 @@ class RefundOrderService extends BaseService
|
||||
{
|
||||
//todo 考虑是否枷锁
|
||||
$orderId = (int)$this->request->input('order_id');
|
||||
$type = (int)$this->request->input('order_type');
|
||||
|
||||
$orderInfo = $this->orderModel->getInfoById($orderId);
|
||||
|
||||
if ($orderInfo->user_id != $this->userId) throw new ErrException('该订单不是您的订单,请勿操作');
|
||||
|
||||
if ($orderInfo->status != OrderCode::PAYED) throw new ErrException('该订单状态已变更,请勿重复操作,刷新后无法退款请联系客服');
|
||||
|
||||
$payInfo = $this->payOrderModel->getInfoByOrderIdAndType($orderInfo->id,OrderCode::ORDER_TYPE_GOOD);
|
||||
if (empty($payInfo)) throw new ErrException('订单支付信息不存在');
|
||||
try {
|
||||
$orderId = (int)$this->request->input('order_id');
|
||||
|
||||
//立即取消
|
||||
$this->joinRefundQueue($orderId, RefundCode::FULL_GOOD_REFUND, '用户主动取消订单');
|
||||
$service = new FullRefundOrderService();
|
||||
$service->orderId = $orderId;
|
||||
$service->reason = '用户主动退款订单';
|
||||
$service->type = RefundCode::FULL_GOOD_REFUND;
|
||||
|
||||
return $this->return->success();
|
||||
$service->handle();
|
||||
|
||||
return $this->return->success();
|
||||
}catch (Exception $e) {
|
||||
throw new ErrException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -365,15 +365,17 @@ trait OrderTrait
|
||||
/**
|
||||
* @param int $orderId
|
||||
* @param int $orderStatus
|
||||
* @param array $refundGoodIds
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
protected function sendStockMq(int $orderId,int $orderStatus): void
|
||||
protected function sendStockMq(int $orderId,int $orderStatus,array $refundGoodIds = []): void
|
||||
{
|
||||
$message = new OrderGoodStockProducer([
|
||||
'order_id' => $orderId,
|
||||
'type' => $orderStatus
|
||||
'type' => $orderStatus,
|
||||
'refund_goods' => $refundGoodIds
|
||||
]);
|
||||
$producer = ApplicationContext::getContainer()->get(Producer::class);
|
||||
$producer->produce($message);
|
||||
|
||||
Reference in New Issue
Block a user