Category.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace addons\shopro\controller;
  3. use app\admin\model\shopro\Category as CategoryModel;
  4. use think\Db;
  5. class Category extends Common
  6. {
  7. protected $noNeedLogin = ['*'];
  8. protected $noNeedRight = ['*'];
  9. public function lists(){
  10. $category = Db::name('shopro_category')->where('parent_id', 1)->where('status','normal')->order('weigh', 'desc')->order('id', 'desc')->select();
  11. $category = list_domain_image($category,['image']);
  12. $this->success('商城分类', $category);
  13. }
  14. //没用到
  15. public function index()
  16. {
  17. $id = $this->request->param('id', 0);
  18. $category = CategoryModel::where('parent_id', 0)->normal()->order('weigh', 'desc')->order('id', 'desc');
  19. if ($id) {
  20. // 指定 id 分类,否则获取 权重最高的一级分类
  21. $category = $category->where('id', $id);
  22. }
  23. $category = $category->find();
  24. if (!$category) {
  25. $this->error(__('No Results were found'));
  26. }
  27. $childrenString = $category->getChildrenString($category);
  28. $categories = CategoryModel::where('id', $category->id)->normal()->with([$childrenString])->find();
  29. $this->success('商城分类', $categories);
  30. }
  31. }