feat: sku
This commit is contained in:
@@ -10,12 +10,17 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Good;
|
||||
|
||||
use App\Cache\Redis\Api\ApiRedisKey;
|
||||
use App\Cache\Redis\Api\GoodCache;
|
||||
use App\Constants\Common\GoodCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Sku;
|
||||
use App\Model\Spu;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
|
||||
class SkuService extends BaseService
|
||||
{
|
||||
@@ -27,6 +32,12 @@ class SkuService extends BaseService
|
||||
#[Inject]
|
||||
protected Sku $skuModel;
|
||||
|
||||
/**
|
||||
* @var Spu
|
||||
*/
|
||||
#[Inject]
|
||||
protected Spu $spuModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
@@ -56,12 +67,22 @@ class SkuService extends BaseService
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @var GoodCache
|
||||
*/
|
||||
#[Inject]
|
||||
protected GoodCache $goodCache;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function add(): array
|
||||
{
|
||||
$spuId = $this->request->input('spu_id');
|
||||
$spuInfo = $this->spuModel->getInfoById($spuId);
|
||||
if (empty($spuInfo)) throw new ErrException('请选择spu');
|
||||
|
||||
$insertModel = new Sku();
|
||||
|
||||
@@ -87,13 +108,16 @@ class SkuService extends BaseService
|
||||
|
||||
if (!$insertModel->save()) throw new ErrException('添加失败');
|
||||
|
||||
//todo 生成缓存
|
||||
//删除缓存
|
||||
$this->goodCache->delCache($spuInfo->kitchen_id,$spuInfo->cycle_id);
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
@@ -103,6 +127,9 @@ class SkuService extends BaseService
|
||||
|
||||
if (empty($skuInfo)) throw new ErrException('原数据不存在,无法修改');
|
||||
|
||||
$spuInfo = $this->spuModel->getInfoById($skuInfo->spu_id);
|
||||
if (empty($spuInfo)) throw new ErrException('数据出错');
|
||||
|
||||
$stock = $this->request->input('stock');
|
||||
$forceCleanStockCache = 0;
|
||||
if ($skuInfo->order_num > 0) { //已产生订单 修改库存需要强制删除库存缓存
|
||||
@@ -142,26 +169,33 @@ class SkuService extends BaseService
|
||||
if (!$skuInfo->save()) throw new ErrException('修改失败');
|
||||
|
||||
if ($forceCleanStockCache == 1) return $this->return->success();
|
||||
//todo 修改缓存
|
||||
|
||||
//删除缓存
|
||||
$this->goodCache->delCache($spuInfo->kitchen_id,$spuInfo->cycle_id);
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function del(): array
|
||||
{
|
||||
$id = (int)$this->request->input('id');
|
||||
$skuInfo = $this->skuModel->getInfoById($id);
|
||||
|
||||
if (empty($skuInfo)) throw new ErrException('数据已删除,无法修改');
|
||||
|
||||
$spuInfo = $this->spuModel->getInfoById($skuInfo->spu_id);
|
||||
if (empty($spuInfo)) throw new ErrException('数据出错');
|
||||
|
||||
$skuInfo->is_del = GoodCode::SKU_IS_DELETE;
|
||||
|
||||
if (!$skuInfo->save()) throw new ErrException('删除失败');
|
||||
|
||||
//todo 删除缓存
|
||||
//删除缓存
|
||||
$this->goodCache->delCache($spuInfo->kitchen_id,$spuInfo->cycle_id);
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -186,4 +220,5 @@ class SkuService extends BaseService
|
||||
|
||||
return $this->return->success('success',$res);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user