feat : spu

This commit is contained in:
2025-03-26 16:05:12 +08:00
parent 0c5ed8b1c5
commit 87808f2c6e
5 changed files with 206 additions and 2 deletions

View File

@@ -104,8 +104,8 @@ class GoodCache
$stockKey = ApiRedisKey::goodStockKey($this->cycleId,$this->kitchenId);
foreach ($this->stockArr as $one) {
$this->redis->zAdd($stockKey,$one['stock'],$one['id']);
$this->redis->expire($stockKey,$this->expireTime);
}
$this->redis->expire($stockKey,$this->expireTime);
}
}
@@ -167,7 +167,7 @@ class GoodCache
}
if (!empty($stockArr)) {
$this->stockArr = $stockArr;
$this->stockArr = array_merge($this->stockArr,$stockArr);
}
foreach ($list as &$item) {

View File

@@ -0,0 +1,28 @@
<?php
declare(strict_types=1);
namespace App\Event;
class PayGoodOrderFinishEvent
{
/**
* @var int 订单 id
*/
public int $orderId;
/**
* @var int 支付订单 id
*/
public int $payOrderId;
/**
* @param int $orderId
* @param int $payOrderId
*/
public function __construct(int $orderId, int $payOrderId)
{
$this->orderId = $orderId;
$this->payOrderId = $payOrderId;
}
}

View File

@@ -0,0 +1,35 @@
<?php
declare(strict_types=1);
namespace App\Event;
class RefundGoodOrderFinishEvent
{
/**
* @var int 订单 id
*/
public int $orderId;
/**
* @var int 支付订单 id
*/
public int $payOrderId;
/**
* @var int 退款订单 id
*/
public int $refundOrderId;
/**
* @param int $orderId
* @param int $payOrderId
* @param int $refundOrderId
*/
public function __construct(int $orderId, int $payOrderId, int $refundOrderId)
{
$this->orderId = $orderId;
$this->payOrderId = $payOrderId;
$this->refundOrderId = $refundOrderId;
}
}

View File

@@ -0,0 +1,64 @@
<?php
declare(strict_types=1);
namespace App\Listener;
use App\Constants\Common\OrderCode;
use App\Constants\Common\RefundCode;
use App\Event\RefundGoodOrderFinishEvent;
use App\Lib\Log;
use App\Model\Order;
use App\Model\PayOrder;
use App\Model\RefundOrder;
use App\Model\UserCoupon;
use App\Service\ServiceTrait\Api\CouponTrait;
use Exception;
use Hyperf\Event\Annotation\Listener;
use Psr\Container\ContainerInterface;
use Hyperf\Event\Contract\ListenerInterface;
#[Listener]
class RefundGoodOrderFinishRollBackCouponListener implements ListenerInterface
{
use CouponTrait;
public function __construct(
protected ContainerInterface $container,
protected Order $orderModel,
protected RefundOrder $refundOrderModel,
protected Log $log,
) {}
public function listen(): array
{
return [
RefundGoodOrderFinishEvent::class,
];
}
public function process(object $event): void
{
try {
$isAll = $this->refundOrderModel
->where('order_id',$event->orderId)
->where('type',RefundCode::FULL_GOOD_REFUND)
->where('refund_status',RefundCode::REFUND_SUCCESS)
->count() ?? 0;
if ($isAll <= 0) return;
$orderInfo = $this->orderModel->find($event->orderId);
if (empty($orderInfo)) return;
if ($orderInfo->status != OrderCode::FINISH_REFUND) return;
if ($orderInfo->coupon_id <= 0) return;
$this->rollbackCoupon(OrderCode::ORDER_TYPE_GOOD,$orderInfo);
} catch (Exception $e) {
$this->log->error(__CLASS__.'RefundGoodOrderFinishRollBackCouponListener:error:'. $e->getMessage());
}
}
}

View File

@@ -0,0 +1,77 @@
<?php
declare(strict_types=1);
namespace App\Listener;
use App\Constants\Common\OrderCode;
use App\Constants\Common\RefundCode;
use App\Event\RefundGoodOrderFinishEvent;
use App\Lib\Log;
use App\Model\ChefStatement;
use App\Model\FinancesStatement;
use App\Model\Order;
use App\Model\OrderGood;
use App\Model\RefundOrder;
use Exception;
use Hyperf\Event\Annotation\Listener;
use Psr\Container\ContainerInterface;
use Hyperf\Event\Contract\ListenerInterface;
#[Listener]
class RefundGoodOrderFinishStatementListener implements ListenerInterface
{
public function __construct(
protected ContainerInterface $container,
protected RefundOrder $refundOrderModel,
protected Order $orderModel,
protected OrderGood $orderGoodModel,
protected ChefStatement $chefStatementModel,
protected FinancesStatement $financesStatementModel,
protected Log $log
) {}
public function listen(): array
{
return [
RefundGoodOrderFinishEvent::class,
];
}
/**
* @var Order
*/
protected Order $orderInfo;
protected array $orderGoodIds;
public function process(object $event): void
{
try {
$refundOrderInfo = $this->refundOrderModel->find($event->refundOrderId);
if (empty($refundOrderInfo) || $refundOrderInfo->status != RefundCode::REFUND_SUCCESS) throw new Exception('退款信息不存在');
$this->orderInfo = $this->orderModel->find($event->orderId);
if (empty($this->orderInfo) || !in_array($this->orderInfo->status,[OrderCode::FINISH_REFUND,OrderCode::UNCOMPLETED_REFUND])) throw new Exception('订单信息不存在');
$this->orderGoodIds = $this->orderGoodModel->where('order_id',$event->orderId)->pluck('id')->toArray();
if (empty($this->orderGoodIds)) throw new Exception('订单商品信息不存在');
$this->rollBackChefData();
$this->rollBackFinancesData();
} catch (Exception $e) {
$this->log->error(__CLASS__.':退款完成后生成订单结算数据失败:'.$e->getMessage());
}
}
private function rollBackChefData(): void
{
}
private function rollBackFinancesData(): void
{
}
}