feat : sts
This commit is contained in:
@@ -17,10 +17,12 @@ use App\Constants\Common\GoodCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminUser;
|
||||
use App\Model\Chef;
|
||||
use App\Model\Purchase;
|
||||
use App\Model\Sku;
|
||||
use App\Model\Spu;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Hyperf\DbConnection\Db;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
@@ -215,10 +217,14 @@ class SkuService extends BaseService
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @var Purchase
|
||||
*/
|
||||
#[Inject]
|
||||
protected Purchase $purchaseModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function del(): array
|
||||
{
|
||||
@@ -229,12 +235,28 @@ class SkuService extends BaseService
|
||||
$spuInfo = $this->spuModel->getInfoById($skuInfo->spu_id);
|
||||
if (empty($spuInfo)) throw new ErrException('数据出错');
|
||||
|
||||
$skuInfo->is_del = GoodCode::SKU_IS_DELETE;
|
||||
$purchaseInfo = $this->purchaseModel->getListByCycleIdAndKitchenId($skuInfo->cycle_id,$spuInfo->kitchen_id);
|
||||
$purchaseIds = [];
|
||||
if (!empty($purchaseInfo)) {
|
||||
foreach ($purchaseInfo->toArray() as $one) {
|
||||
$oneSkuArr = explode(',',$one['sku_ids']);
|
||||
if (!in_array($skuInfo->id,$oneSkuArr)) continue;
|
||||
|
||||
if (!$skuInfo->save()) throw new ErrException('删除失败');
|
||||
$purchaseIds = $one['id'];
|
||||
}
|
||||
}
|
||||
|
||||
//删除缓存
|
||||
$this->goodCache->delCache($spuInfo->kitchen_id,$spuInfo->cycle_id);
|
||||
Db::transaction(function () use ($id,$purchaseIds,$spuInfo,$skuInfo) {
|
||||
$skuInfo->is_del = GoodCode::SKU_IS_DELETE;
|
||||
|
||||
if (!$skuInfo->save()) throw new ErrException('删除失败');
|
||||
|
||||
if (!empty($purchaseIds) && !$this->purchaseModel->whereIn('id',$purchaseIds)->delete()) throw new ErrException('删除联动数据失败');
|
||||
|
||||
//删除缓存
|
||||
$this->goodCache->delCache($spuInfo->kitchen_id,$spuInfo->cycle_id);
|
||||
$this->goodCache->delPurchaseCache($spuInfo->kitchen_id,$spuInfo->cycle_id);
|
||||
});
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user