feat : spu

This commit is contained in:
2025-03-26 10:23:08 +08:00
parent 60d8fa5d14
commit 9c76c92b05
5 changed files with 77 additions and 8 deletions

View File

@@ -7,7 +7,7 @@ class CategoryCode
/** /**
* 商品分类 1=菜品 2=主食 3=加饭 * 商品分类 1=菜品 2=主食 3=加饭
*/ */
CONST DISH = 1; CONST int DISH = 1;
CONST STAPLE = 2; CONST int STAPLE = 2;
CONST EXTRA_STAPLE = 3; CONST int EXTRA_STAPLE = 3;
} }

View File

@@ -10,12 +10,17 @@ declare(strict_types=1);
namespace App\Service\Admin\Order; namespace App\Service\Admin\Order;
use App\Constants\Common\OrderCode;
use App\Constants\Common\RefundCode; use App\Constants\Common\RefundCode;
use App\Exception\ErrException; use App\Exception\ErrException;
use App\Model\Order;
use App\Service\Admin\BaseService; use App\Service\Admin\BaseService;
use App\Service\Amqp\Refund\FullRefundOrderService; use App\Service\Amqp\Refund\FullRefundOrderService;
use App\Service\Amqp\Refund\PartialRefundOrderService; use App\Service\Amqp\Refund\PartialRefundOrderService;
use App\Service\ServiceTrait\Common\OrderChangeStatusTrait;
use Exception; use Exception;
use Hyperf\Amqp\Producer;
use Hyperf\Di\Annotation\Inject;
use Psr\Container\ContainerExceptionInterface; use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface; use Psr\Container\NotFoundExceptionInterface;
@@ -70,13 +75,37 @@ class RefundService extends BaseService
} }
} }
use OrderChangeStatusTrait;
/**
* @var Order
*/
#[Inject]
protected Order $orderModel;
/** /**
* @return array * @return array
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/ */
public function refundBatch(): array public function refundBatch(): array
{ {
$siteId = $this->request->input('site_id'); $kitchenId = $this->request->input('kitchen_id');
$cycleId = (int)$this->request->input('cycle_id'); $cycleId = (int)$this->request->input('cycle_id');
$reason = $this->request->input('reason');
$orderIds = $this->orderModel
->where('kitchen_id', $kitchenId)
->where('cycle_id', $cycleId)
->where('status', OrderCode::FINISH)
->pluck('id')
->toArray();
if (empty($orderIds)) throw new ErrException('暂无数据');
foreach ($orderIds as $orderId) {
$this->joinRefundQueue($orderId,RefundCode::FULL_GOOD_REFUND,$reason);
}
return $this->return->success(); return $this->return->success();
} }

View File

@@ -10,8 +10,10 @@ declare(strict_types=1);
namespace App\Service\Api\Good; namespace App\Service\Api\Good;
use App\Cache\Redis\Api\ApiRedisKey;
use App\Cache\Redis\Api\GoodCache; use App\Cache\Redis\Api\GoodCache;
use App\Cache\Redis\Api\SiteCache; use App\Cache\Redis\Api\SiteCache;
use App\Cache\Redis\RedisCache;
use App\Service\Api\BaseService; use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\CycleTrait; use App\Service\ServiceTrait\Common\CycleTrait;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@@ -34,6 +36,12 @@ class MealListService extends BaseService
#[Inject] #[Inject]
protected SiteCache $siteCache; protected SiteCache $siteCache;
/**
* @var RedisCache
*/
#[Inject]
protected RedisCache $redisCache;
/** /**
* @return array|array[] * @return array|array[]
@@ -54,6 +62,15 @@ class MealListService extends BaseService
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id']; $this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
$data = $this->goodCache->getMealGoodList(); $data = $this->goodCache->getMealGoodList();
if (empty($data)) return $this->return->success('success', ['list' => []]);
$stockKey = ApiRedisKey::goodStockKey($cycleId,(int)$siteInfo['kitchen_id']);
foreach ($data as &$item) {
foreach ($item['sku_list'] as &$v) {
$v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0;
}
}
return $this->return->success('success', ['list' => $data]); return $this->return->success('success', ['list' => $data]);
} }
} }

View File

@@ -10,8 +10,10 @@ declare(strict_types=1);
namespace App\Service\Api\Good; namespace App\Service\Api\Good;
use App\Cache\Redis\Api\ApiRedisKey;
use App\Cache\Redis\Api\GoodCache; use App\Cache\Redis\Api\GoodCache;
use App\Cache\Redis\Api\SiteCache; use App\Cache\Redis\Api\SiteCache;
use App\Cache\Redis\RedisCache;
use App\Service\Api\BaseService; use App\Service\Api\BaseService;
use App\Service\ServiceTrait\Common\CycleTrait; use App\Service\ServiceTrait\Common\CycleTrait;
use Hyperf\Di\Annotation\Inject; use Hyperf\Di\Annotation\Inject;
@@ -34,6 +36,12 @@ class OptionalListService extends BaseService
#[Inject] #[Inject]
protected SiteCache $siteCache; protected SiteCache $siteCache;
/**
* @var RedisCache
*/
#[Inject]
protected RedisCache $redisCache;
/** /**
* @return array * @return array
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
@@ -53,6 +61,15 @@ class OptionalListService extends BaseService
$this->goodCache->kitchenId = (int)$siteInfo['kitchen_id']; $this->goodCache->kitchenId = (int)$siteInfo['kitchen_id'];
$data = $this->goodCache->getOptionalGoodList(); $data = $this->goodCache->getOptionalGoodList();
if (empty($data)) return $this->return->success('success', ['list' => []]);
$stockKey = ApiRedisKey::goodStockKey($cycleId,(int)$siteInfo['kitchen_id']);
foreach ($data as &$item) {
foreach ($item['sku_list'] as &$v) {
$v['surplus_stock'] = $this->redisCache->zScore($stockKey,$v['id']) ?? 0;
}
}
return $this->return->success('success', ['list' => $data]); return $this->return->success('success', ['list' => $data]);
} }
} }

View File

@@ -22,6 +22,12 @@ trait OrderChangeStatusTrait
#[Inject] #[Inject]
protected ConfigCache $configCache; protected ConfigCache $configCache;
/**
* @var Producer
*/
#[Inject]
protected Producer $producer;
/** /**
* 加入取消队列 * 加入取消队列
* @param int $orderId * @param int $orderId
@@ -38,8 +44,8 @@ trait OrderChangeStatusTrait
'type' => $type 'type' => $type
]); ]);
$message->setDelayMs($millisecond); $message->setDelayMs($millisecond);
$producer = ApplicationContext::getContainer()->get(Producer::class); // $producer = ApplicationContext::getContainer()->get(Producer::class);
$producer->produce($message); $this->producer->produce($message);
} }
/** /**
@@ -57,7 +63,7 @@ trait OrderChangeStatusTrait
'type' => $type, 'type' => $type,
'reason' => $reason 'reason' => $reason
]); ]);
$producer = ApplicationContext::getContainer()->get(Producer::class); // $producer = ApplicationContext::getContainer()->get(Producer::class);
$producer->produce($message); $this->producer->produce($message);
} }
} }