Category.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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. $data[] = [
  13. 'id' => 0,
  14. 'name' => '全部',
  15. 'parent_id' => 0,
  16. 'style' => null,
  17. 'image' => '',
  18. 'description' => '',
  19. 'status' => 'normal',
  20. 'weigh' => 0,
  21. 'createtime' => 0,
  22. 'updatetime' => 0,
  23. ];
  24. $data = array_merge($data,$category);
  25. $this->success('商城分类', $data);
  26. }
  27. //没用到
  28. public function index()
  29. {
  30. $id = $this->request->param('id', 0);
  31. $category = CategoryModel::where('parent_id', 0)->normal()->order('weigh', 'desc')->order('id', 'desc');
  32. if ($id) {
  33. // 指定 id 分类,否则获取 权重最高的一级分类
  34. $category = $category->where('id', $id);
  35. }
  36. $category = $category->find();
  37. if (!$category) {
  38. $this->error(__('No Results were found'));
  39. }
  40. $childrenString = $category->getChildrenString($category);
  41. $categories = CategoryModel::where('id', $category->id)->normal()->with([$childrenString])->find();
  42. $this->success('商城分类', $categories);
  43. }
  44. }