Explorar o código

优化:商品规格管理

Martin %!s(int64=5) %!d(string=hai) anos
pai
achega
326dd66cb8
Modificáronse 3 ficheiros con 30 adicións e 21 borrados
  1. 10 5
      app/store/controller/Goods.php
  2. 11 2
      app/store/model/Goods.php
  3. 9 14
      app/store/model/Spec.php

+ 10 - 5
app/store/controller/Goods.php

@@ -67,7 +67,10 @@ class Goods extends Controller
 
 
     /**
     /**
      * 添加商品
      * 添加商品
-     * @return array|string
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
      */
     public function add()
     public function add()
     {
     {
@@ -79,9 +82,12 @@ class Goods extends Controller
     }
     }
 
 
     /**
     /**
-     * 商品编辑
-     * @param $goodsId
-     * @return array|string
+     * 编辑商品
+     * @param int $goodsId
+     * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
      */
     public function edit(int $goodsId)
     public function edit(int $goodsId)
     {
     {
@@ -122,5 +128,4 @@ class Goods extends Controller
         }
         }
         return $this->renderSuccess('删除成功');
         return $this->renderSuccess('删除成功');
     }
     }
-
 }
 }

+ 11 - 2
app/store/model/Goods.php

@@ -64,6 +64,9 @@ class Goods extends GoodsModel
      * 添加商品
      * 添加商品
      * @param array $data
      * @param array $data
      * @return bool
      * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
      */
     public function add(array $data)
     public function add(array $data)
     {
     {
@@ -91,6 +94,9 @@ class Goods extends GoodsModel
      * 创建商品数据
      * 创建商品数据
      * @param array $data
      * @param array $data
      * @return array
      * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
      */
     private function createData(array $data)
     private function createData(array $data)
     {
     {
@@ -138,8 +144,11 @@ class Goods extends GoodsModel
 
 
     /**
     /**
      * 编辑商品
      * 编辑商品
-     * @param $data
-     * @return bool|mixed
+     * @param array $data
+     * @return bool
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
      */
     public function edit(array $data)
     public function edit(array $data)
     {
     {

+ 9 - 14
app/store/model/Spec.php

@@ -24,10 +24,13 @@ use app\store\model\SpecValue as SpecValueModel;
 class Spec extends SpecModel
 class Spec extends SpecModel
 {
 {
     /**
     /**
-     * 规格组写入数据库并生成id
+     * 规格组写入数据库并生成ID集
      * 此时的$specList是用户端传来的
      * 此时的$specList是用户端传来的
      * @param array $specList
      * @param array $specList
      * @return array
      * @return array
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
      */
     public static function getNewSpecList(array $specList)
     public static function getNewSpecList(array $specList)
     {
     {
@@ -54,8 +57,8 @@ class Spec extends SpecModel
 
 
     /**
     /**
      * 新增规格组记录
      * 新增规格组记录
-     * @param $item
-     * @return Spec|\think\Model
+     * @param array $item
+     * @return static|\think\Model
      */
      */
     private static function add(array $item)
     private static function add(array $item)
     {
     {
@@ -71,20 +74,12 @@ class Spec extends SpecModel
      * 根据规格组名称集获取列表
      * 根据规格组名称集获取列表
      * @param array $names
      * @param array $names
      * @return \think\Collection
      * @return \think\Collection
+     * @throws \think\db\exception\DataNotFoundException
+     * @throws \think\db\exception\DbException
+     * @throws \think\db\exception\ModelNotFoundException
      */
      */
     private static function getListByNames(array $names)
     private static function getListByNames(array $names)
     {
     {
         return (new static)->where('spec_name', 'in', $names)->select();
         return (new static)->where('spec_name', 'in', $names)->select();
     }
     }
-
-    /**
-     * 获取指定管理员的所有规格id
-     * @param int $specId
-     * @return array
-     */
-    public static function getSpecIdsByUserId(int $specId)
-    {
-        return (new static)->where('store_user_id', '=', $specId)->column('spec_id');
-    }
-
 }
 }