feat: sku
This commit is contained in:
@@ -11,6 +11,7 @@ declare(strict_types=1);
|
||||
namespace App\Service\Admin\Good;
|
||||
|
||||
use App\Constants\Admin\UserCode;
|
||||
use App\Constants\Common\GoodCode;
|
||||
use App\Constants\Common\SiteCode;
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\AdminUser;
|
||||
@@ -21,6 +22,7 @@ use App\Model\Spu;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Admin\GetUserInfoTrait;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class SpuService extends BaseService
|
||||
@@ -51,10 +53,17 @@ class SpuService extends BaseService
|
||||
$this->cityId = (int)$this->userInfo['city_id'];
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle(): array
|
||||
{
|
||||
$limit = (int)$this->request->input('limit', 10);
|
||||
$cycleId = (int)$this->request->input('cycle_id');
|
||||
|
||||
$list = $this->spuModel->where('cycle_id',$cycleId)->where('city_id',$this->cityId)->paginate($limit)->toArray();
|
||||
|
||||
return $this->return->success('success', ['list' => $list]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -75,7 +84,9 @@ class SpuService extends BaseService
|
||||
|
||||
if (empty($cycleInfo)) throw new ErrException('没有该周期,请刷新后重新上传');
|
||||
|
||||
$info = $this->spuModel->getInfoByCityIdAndCycleId($this->cityId, $cycleInfo->id);
|
||||
$title = $this->request->input('title');
|
||||
|
||||
$info = $this->spuModel->getInfoByCityIdAndCycleId($this->cityId, $cycleInfo->id,$title);
|
||||
|
||||
if (!empty($info)) throw new ErrException('该菜品在当前城市已存在');
|
||||
|
||||
@@ -87,7 +98,7 @@ class SpuService extends BaseService
|
||||
$insertModel->cycle_id = $cycleInfo->id;
|
||||
$insertModel->kitchen_id = $this->request->input('kitchen_id');
|
||||
$insertModel->chef_id = $this->request->input('chef_id');
|
||||
$insertModel->title = $this->request->input('title');
|
||||
$insertModel->title = $title;
|
||||
$insertModel->sub_title = $this->request->input('sub_title','');
|
||||
$insertModel->category_id = $this->request->input('category_id');
|
||||
$insertModel->saleable = $this->request->input('saleable');
|
||||
@@ -132,9 +143,9 @@ class SpuService extends BaseService
|
||||
*/
|
||||
public function edit(): array
|
||||
{
|
||||
$editId = $this->request->input('edit_id');
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->spuModel->getInfoById($editId);
|
||||
$info = $this->spuModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
$this->checkInfo();
|
||||
@@ -154,19 +165,23 @@ class SpuService extends BaseService
|
||||
/**
|
||||
* spu 删除
|
||||
* @return array
|
||||
* @throws \Exception
|
||||
* @throws Exception
|
||||
*/
|
||||
public function del(): array
|
||||
{
|
||||
$id = $this->request->input('id');
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->spuModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据已删除');
|
||||
|
||||
//todo 需要联动删除sku 已经有用户下单sku该怎么办
|
||||
|
||||
//删除所有 sku
|
||||
$this->skuModel->where('spu_id',$info->id)->update(['is_del' => GoodCode::SKU_IS_DELETE]);
|
||||
|
||||
//没有直接删除菜
|
||||
$info->delete();
|
||||
$info->is_del = GoodCode::SPU_IS_DELETE;
|
||||
$info->save();
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
@@ -177,7 +192,7 @@ class SpuService extends BaseService
|
||||
*/
|
||||
public function view(): array
|
||||
{
|
||||
$id = $this->request->input('id');
|
||||
$id = (int)$this->request->input('id');
|
||||
|
||||
$info = $this->spuModel->getInfoById($id);
|
||||
if (empty($info)) throw new ErrException('数据不存在');
|
||||
|
||||
Reference in New Issue
Block a user