feat : refund
This commit is contained in:
24
app/Service/Amqp/Refund/BalanceOrderRefundService.php
Normal file
24
app/Service/Amqp/Refund/BalanceOrderRefundService.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
class BalanceOrderRefundService
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $orderId;
|
||||
|
||||
public function handle()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
41
app/Service/Amqp/Refund/GoodOrderAllRefundService.php
Normal file
41
app/Service/Amqp/Refund/GoodOrderAllRefundService.php
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Model\Order;
|
||||
use App\Model\PayOrder;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class GoodOrderAllRefundService extends RefundBaseService
|
||||
{
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$this->type = OrderCode::ORDER_TYPE_GOOD;
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
$this->getOrderInfo();
|
||||
|
||||
$this->getPayOrder();
|
||||
|
||||
$this->getRefundAmount();
|
||||
|
||||
if ($this->refundAmount <= 0) throw new Exception('退款金额不能小于等于0');
|
||||
}
|
||||
}
|
||||
22
app/Service/Amqp/Refund/GoodOrderPartRefundService.php
Normal file
22
app/Service/Amqp/Refund/GoodOrderPartRefundService.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
/**
|
||||
* This service file is part of item.
|
||||
*
|
||||
* @author ctexthuang
|
||||
* @contact ctexthuang@qq.com
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
use App\Model\Order;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class GoodOrderPartRefundService
|
||||
{
|
||||
public function handle()
|
||||
{
|
||||
//todo Write logic
|
||||
}
|
||||
}
|
||||
114
app/Service/Amqp/Refund/RefundBaseService.php
Normal file
114
app/Service/Amqp/Refund/RefundBaseService.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Model\Order;
|
||||
use App\Model\PayOrder;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class RefundBaseService
|
||||
{
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public int $orderId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
protected int $type;
|
||||
|
||||
/**
|
||||
* @var PayOrder
|
||||
*/
|
||||
#[Inject]
|
||||
protected PayOrder $payOrderModel;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
#[Inject]
|
||||
protected Order $orderModel;
|
||||
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected mixed $payInfo;
|
||||
|
||||
/**
|
||||
* @var mixed
|
||||
*/
|
||||
protected mixed $orderInfo;
|
||||
|
||||
/**
|
||||
* @var float
|
||||
*/
|
||||
protected float $refundAmount;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function getPayOrder()
|
||||
{
|
||||
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndType($this->orderId, $this->type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function getOrderInfo()
|
||||
{
|
||||
$this->orderInfo = match ($this->type) {
|
||||
OrderCode::ORDER_TYPE_GOOD => $this->orderModel->getInfoById($this->orderId),
|
||||
default => null,
|
||||
};
|
||||
}
|
||||
|
||||
protected function getAllRefundByOrderId()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
protected function checkInfo()
|
||||
{
|
||||
if (!$this->payInfo || !$this->orderInfo) {
|
||||
throw new Exception('订单信息不存在');
|
||||
}
|
||||
}
|
||||
|
||||
protected function getUser()
|
||||
{
|
||||
//todo 获取用户信息
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
protected function getRefundAmount(): void
|
||||
{
|
||||
//todo 等于支付金额 减去 已退款金额
|
||||
$this->refundAmount = 0;
|
||||
}
|
||||
|
||||
protected function insertRefund()
|
||||
{
|
||||
//todo 写入退款记录
|
||||
}
|
||||
|
||||
protected function updateOrderInfo()
|
||||
{
|
||||
//todo 更新订单信息
|
||||
}
|
||||
|
||||
protected function refund()
|
||||
{
|
||||
//todo 退款 参考调起支付
|
||||
}
|
||||
}
|
||||
30
app/Service/Amqp/Refund/RefundFactory.php
Normal file
30
app/Service/Amqp/Refund/RefundFactory.php
Normal file
@@ -0,0 +1,30 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
class RefundFactory
|
||||
{
|
||||
/**
|
||||
* @return GoodOrderAllRefundService
|
||||
*/
|
||||
public function newGoodOrderRefundAll(): GoodOrderAllRefundService
|
||||
{
|
||||
return new GoodOrderAllRefundService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return GoodOrderPartRefundService
|
||||
*/
|
||||
public function newGoodOrderRefundPart(): GoodOrderPartRefundService
|
||||
{
|
||||
return new GoodOrderPartRefundService();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BalanceOrderRefundService
|
||||
*/
|
||||
public function newBalanceOrderRefund(): BalanceOrderRefundService
|
||||
{
|
||||
return new BalanceOrderRefundService();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user