feat : spu
This commit is contained in:
@@ -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) {
|
||||
|
||||
28
app/Event/PayGoodOrderFinishEvent.php
Normal file
28
app/Event/PayGoodOrderFinishEvent.php
Normal 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;
|
||||
}
|
||||
}
|
||||
35
app/Event/RefundGoodOrderFinishEvent.php
Normal file
35
app/Event/RefundGoodOrderFinishEvent.php
Normal 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;
|
||||
}
|
||||
}
|
||||
64
app/Listener/RefundGoodOrderFinishRollBackCouponListener.php
Normal file
64
app/Listener/RefundGoodOrderFinishRollBackCouponListener.php
Normal 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());
|
||||
}
|
||||
}
|
||||
}
|
||||
77
app/Listener/RefundGoodOrderFinishStatementListener.php
Normal file
77
app/Listener/RefundGoodOrderFinishStatementListener.php
Normal 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
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user