fix:category
This commit is contained in:
@@ -10,17 +10,53 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Service\Admin\Good;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Model\Category;
|
||||
use App\Service\Admin\BaseService;
|
||||
use App\Service\ServiceTrait\Common\OssTrait;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
|
||||
class CategoryService extends BaseService
|
||||
{
|
||||
use OssTrait;
|
||||
|
||||
/**
|
||||
* @var Category $categoryModel
|
||||
*/
|
||||
#[Inject]
|
||||
protected Category $categoryModel;
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$list = $this->categoryModel->get(['category.id','category.name','category.image_id']);
|
||||
|
||||
if (empty($list)) return $this->return->success('success',['list' => []]);
|
||||
|
||||
return $this->return->success('success',['list' => $list->toArray()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 添加
|
||||
* @return array
|
||||
* @throws Exception
|
||||
*/
|
||||
public function add()
|
||||
{
|
||||
$name = $this->request->input('name');
|
||||
$imageId = $this->request->input('image_id');
|
||||
|
||||
$this->updateOssObjects([$imageId]);
|
||||
|
||||
$category = new Category();
|
||||
$category->name = $name;
|
||||
$category->image_id = $imageId;
|
||||
|
||||
if (!$category->save()) throw new ErrException('商品种类添加失败');
|
||||
|
||||
return $this->return->success();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user