GoodsCategoryService.php 894 B

12345678910111213141516171819202122232425262728293031323334353637
  1. <?php
  2. namespace app\common\service;
  3. use app\common\constant\CommonConstant;
  4. use app\common\model\GoodsCategory;
  5. /**
  6. * 商品分类服务类
  7. */
  8. class GoodsCategoryService
  9. {
  10. /**
  11. * 商品分类列表
  12. *
  13. * @param array $where
  14. * @param integer $child 是否有二级:0=第一级,1=二级
  15. **/
  16. public static function get_list($where = [], $child = 0)
  17. {
  18. $list = GoodsCategory::field('is_deleted,create_at', true)
  19. ->where('is_deleted', CommonConstant::IS_DELETED_0)
  20. ->where('pid', 0)
  21. ->where($where);
  22. if ($child == 1) {
  23. $list->with([
  24. 'childlist' => function ($query) {
  25. $query->field('is_deleted,create_at', true);
  26. }
  27. ]);
  28. }
  29. $list = $list->order('sort desc,id asc')
  30. ->select();
  31. return $list;
  32. }
  33. }