feat : spu
This commit is contained in:
@@ -213,13 +213,15 @@ abstract class BaseRefundOrderService
|
||||
$this->refundInfo = new RefundOrder();
|
||||
|
||||
$this->refundInfo->user_id = $this->orderInfo->user_id;
|
||||
$this->refundInfo->order_type = $this->type;
|
||||
$this->refundInfo->order_type = OrderCode::ORDER_TYPE_GOOD;
|
||||
$this->refundInfo->order_id = $this->orderId;
|
||||
$this->refundInfo->pay_id = $this->payInfo->id;
|
||||
$this->refundInfo->type = $this->type;
|
||||
if ($this->type == RefundCode::PARTIAL_GOOD_REFUND) $this->refundInfo->good_ids = json_encode($this->orderGoodIds);
|
||||
$this->refundInfo->refund_status = RefundCode::WAIT_REFUND;
|
||||
$this->refundInfo->refund_money = $this->refundAmount;
|
||||
$this->refundInfo->refund_type = $this->payInfo->recharge_type;
|
||||
$this->refundInfo->refund_order_sno = $this->generateRefundOrderNo($this->type, $this->orderInfo->user_id);
|
||||
$this->refundInfo->refund_order_sno = $this->generateRefundOrderNo(OrderCode::ORDER_TYPE_GOOD, $this->orderInfo->user_id);
|
||||
$this->refundInfo->reason = $this->reason;
|
||||
|
||||
if (!$this->refundInfo->save()) throw new Exception('退款订单创建失败');
|
||||
|
||||
@@ -10,7 +10,8 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Amqp\Refund;
|
||||
|
||||
use App\Constants\Common\OrderCode;
|
||||
use App\Event\RefundGoodOrderFinishEvent;
|
||||
use App\Lib\Log;
|
||||
use App\Model\Order;
|
||||
use App\Model\PayOrder;
|
||||
use App\Model\RefundOrder;
|
||||
@@ -19,8 +20,10 @@ use App\Service\ServiceTrait\Api\CouponTrait;
|
||||
use App\Service\ServiceTrait\Api\OrderTrait;
|
||||
use App\Service\ServiceTrait\Api\RefundOrderTrait;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class RefundGoodOrderFinishService
|
||||
{
|
||||
@@ -44,6 +47,11 @@ class RefundGoodOrderFinishService
|
||||
*/
|
||||
public int $orderType;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public array $callbackData;
|
||||
|
||||
/**
|
||||
* @var Order
|
||||
*/
|
||||
@@ -59,23 +67,47 @@ class RefundGoodOrderFinishService
|
||||
*/
|
||||
protected RefundOrder $refundInfo;
|
||||
|
||||
/**
|
||||
* @var EventDispatcherInterface
|
||||
*/
|
||||
#[Inject]
|
||||
private EventDispatcherInterface $eventDispatcher;
|
||||
|
||||
/**
|
||||
* @var Log
|
||||
*/
|
||||
#[Inject]
|
||||
protected Log $log;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
protected bool $rollBackStockFlag;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function handle(): void
|
||||
{
|
||||
$this->checkRefundOrder();
|
||||
|
||||
$this->rollBackStockFlag = $this->orderInfo->cycle_id == $this->initTodayCycleId();
|
||||
|
||||
Db::transaction(function (){
|
||||
$this->manageRefundOrder();
|
||||
|
||||
$this->manageOrderByRefund();
|
||||
|
||||
$this->manageSubCateringLog();
|
||||
|
||||
if ($this->orderInfo->coupin_id > 0) $this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$this->orderInfo);
|
||||
});
|
||||
|
||||
// $this->sendStockMq($this->orderInfo->id,$this->orderInfo->status);
|
||||
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));
|
||||
|
||||
}
|
||||
}
|
||||
@@ -35,6 +35,8 @@ class SystemConfigService extends BaseService
|
||||
{
|
||||
$res = [
|
||||
'logo' => $this->configCache->getConfigValueByKey(ConfigCode::APP_LOGO),
|
||||
'sundry_unit_price' => $this->configCache->getConfigValueByKey(ConfigCode::SUNDRY_UNIT_PRICE),
|
||||
'today_cut_off_time' => $this->configCache->getConfigValueByKey(ConfigCode::TODAY_CUT_OFF_TIME_KEY),
|
||||
];
|
||||
|
||||
return $this->return->success('success', $res);
|
||||
|
||||
@@ -9,12 +9,15 @@ use App\Model\OrderMealCateringLog;
|
||||
use App\Model\OrderOptionCateringLog;
|
||||
use App\Model\Sku;
|
||||
use App\Model\Spu;
|
||||
use App\Service\ServiceTrait\Common\CycleTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
trait CateringTrait
|
||||
{
|
||||
use CycleTrait;
|
||||
|
||||
/**
|
||||
* @var OrderOptionCateringLog
|
||||
*/
|
||||
@@ -54,6 +57,8 @@ trait CateringTrait
|
||||
*/
|
||||
private function manageSubCateringLog(): void
|
||||
{
|
||||
if (!$this->rollBackStockFlag) return;
|
||||
|
||||
match ($this->orderInfo->type) {
|
||||
OrderCode::ORDER_TYPE_MEAL => $this->manageSubMealCateringLog(),
|
||||
OrderCode::ORDER_TYPE_OPTIONAL => $this->manageSubOptionCateringLog(),
|
||||
|
||||
@@ -6,7 +6,9 @@ use App\Constants\Common\OrderCode;
|
||||
use App\Constants\Common\PayCode;
|
||||
use App\Constants\Common\RefundCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\OrderGood;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
@@ -17,9 +19,9 @@ trait RefundOrderTrait
|
||||
*/
|
||||
protected function checkRefundOrder(): void
|
||||
{
|
||||
$this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderNo,self::PayType);
|
||||
$this->refundInfo = $this->refundOrderModel->getInfoByOrderSnoAndType($this->orderSno,$this->payType);
|
||||
$this->orderInfo = $this->orderModel->getInfoById($this->refundInfo->order_id);
|
||||
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,self::OrderType,self::PayType);
|
||||
$this->payInfo = $this->payOrderModel->getInfoByOrderIdAndTypeAndRType($this->orderInfo->id,$this->orderType,$this->payType);
|
||||
|
||||
if (empty($this->orderInfo) || empty($this->payInfo) || empty($this->refundInfo)) throw new ErrException('订单不存在');
|
||||
|
||||
@@ -48,6 +50,12 @@ trait RefundOrderTrait
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @var OrderGood
|
||||
*/
|
||||
#[Inject]
|
||||
protected OrderGood $orderGoodModel;
|
||||
|
||||
/**
|
||||
* @return void
|
||||
* @throws ContainerExceptionInterface
|
||||
@@ -62,13 +70,17 @@ trait RefundOrderTrait
|
||||
|
||||
if ($isRefundMoney == $this->payInfo->pay_money) {
|
||||
$this->orderInfo->status = OrderCode::FINISH_REFUND;
|
||||
$this->orderInfo->is_refund_all = 1;//todo 感觉可以删除这个值
|
||||
} else {
|
||||
$this->orderInfo->status = OrderCode::UNCOMPLETED_REFUND;
|
||||
}
|
||||
|
||||
if (!$this->orderInfo->save()) throw new Exception('更新退款订单失败');
|
||||
|
||||
match ($this->refundInfo->type) {
|
||||
RefundCode::FULL_GOOD_REFUND => $this->orderGoodModel->where('order_id',$this->refundInfo->order_id)->update(['refund_status' => OrderCode::FINISH_REFUND]),
|
||||
RefundCode::PARTIAL_GOOD_REFUND => $this->orderGoodModel->whereIn('id',json_decode($this->refundInfo->good_ids,true))->update(['refund_status' => OrderCode::FINISH_REFUND]),
|
||||
};
|
||||
|
||||
}catch (Exception $e) {
|
||||
$this->log->error(__CLASS__.':Function:manageGoodOrder:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
throw new ErrException('Function:RefundFinish:'.$e->getMessage().':orderId:'.$this->orderInfo->id);
|
||||
|
||||
Reference in New Issue
Block a user