diff --git a/app/data/controller/api/Goods.php b/app/data/controller/api/Goods.php index 3fcaee196..a238aa2e0 100644 --- a/app/data/controller/api/Goods.php +++ b/app/data/controller/api/Goods.php @@ -24,7 +24,7 @@ class Goods extends Controller */ public function getCate() { - $this->success('获取分类成功', ShopGoodsCate::getTreeData()); + $this->success('获取分类成功', ShopGoodsCate::treeJson()); } /** diff --git a/app/data/controller/shop/Goods.php b/app/data/controller/shop/Goods.php index 642c83eb1..173c784c5 100644 --- a/app/data/controller/shop/Goods.php +++ b/app/data/controller/shop/Goods.php @@ -70,7 +70,7 @@ class Goods extends Controller protected function _page_filter(array &$data) { $this->marks = ShopGoodsMark::items(); - $this->cates = ShopGoodsCate::getLevelData(); + $this->cates = ShopGoodsCate::treeTable(true); GoodsService::instance()->bindData($data, false); } @@ -136,7 +136,7 @@ class Goods extends Controller $data['cateids'] = str2arr($data['cateids'] ?? ''); // 其他表单数据 $this->marks = ShopGoodsMark::items(); - $this->cates = ShopGoodsCate::getLevelData(); + $this->cates = ShopGoodsCate::treeTable(); $this->trucks = ExpressService::instance()->templates(); $this->upgrades = UserUpgradeService::instance()->levels(); $this->payments = BaseUserPayment::mk()->where(['status' => 1, 'deleted' => 0])->order('sort desc,id desc')->column('type,code,name', 'code'); diff --git a/app/data/model/ShopGoodsCate.php b/app/data/model/ShopGoodsCate.php index 44334cfa8..cdc632b17 100644 --- a/app/data/model/ShopGoodsCate.php +++ b/app/data/model/ShopGoodsCate.php @@ -41,7 +41,7 @@ class ShopGoodsCate extends Model * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ - public static function getTreeData(): array + public static function treeJson(): array { $query = static::mk()->where(['deleted' => 0, 'status' => 1])->order('sort desc,id desc'); return DataExtend::arr2tree($query->withoutField('sort,status,deleted,create_at')->select()->toArray()); @@ -52,7 +52,7 @@ class ShopGoodsCate extends Model * @param bool $simple 仅子级别 * @return array */ - public static function getLevelData(bool $simple = false): array + public static function treeTable(bool $simple = false): array { $query = static::mk()->where(['status' => 1])->order('sort desc,id asc'); $cates = array_column(DataExtend::arr2table($query->column('id,pid,name', 'id')), null, 'id'); diff --git a/app/data/service/GoodsService.php b/app/data/service/GoodsService.php index dc4408547..6de3de24e 100644 --- a/app/data/service/GoodsService.php +++ b/app/data/service/GoodsService.php @@ -70,7 +70,7 @@ class GoodsService extends Service public function bindData(array &$data = [], bool $simple = true): array { $marks = ShopGoodsMark::items(); - $cates = ShopGoodsCate::getLevelData(); + $cates = ShopGoodsCate::treeTable(); $codes = array_unique(array_column($data, 'code')); $items = ShopGoodsItem::mk()->whereIn('goods_code', $codes)->where(['status' => 1])->select()->toArray(); foreach ($data as &$vo) {