Goodscategory.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. /**
  3. * Niushop商城系统 - 团队十年电商经验汇集巨献!
  4. * =========================================================
  5. * Copy right 2019-2029 杭州牛之云科技有限公司, 保留所有权利。
  6. * ----------------------------------------------
  7. * 官方网址: https://www.niushop.com
  8. * 这不是一个自由软件!您只能在不用于商业目的的前提下对程序代码进行修改和使用。
  9. * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
  10. * =========================================================
  11. */
  12. namespace app\shopapi\controller;
  13. use app\model\goods\GoodsCategory as GoodscategoryModel;
  14. /**
  15. * 商品分类管理 控制器
  16. */
  17. class Goodscategory extends BaseApi
  18. {
  19. public function __construct()
  20. {
  21. //执行父类构造函数
  22. parent::__construct();
  23. }
  24. /**
  25. * 获取商品分类
  26. */
  27. public function getCategoryByParent()
  28. {
  29. $pid = isset($this->params[ 'pid' ]) ? $this->params[ 'pid' ] : 0;// 上级id
  30. $level = isset($this->params[ 'level' ]) ? $this->params[ 'level' ] : 0;// 层级
  31. $goods_category_model = new GoodscategoryModel();
  32. if (!empty($level)) {
  33. $condition[] = [ 'level', '=', $level ];
  34. }
  35. if (!empty($pid)) {
  36. $condition[] = [ 'pid', '=', $pid ];
  37. }
  38. $list = $goods_category_list = $goods_category_model->getCategoryByParent($condition, 'category_id,category_name,pid,level,category_id_1,category_id_2,category_id_3');
  39. return $this->response($list);
  40. }
  41. }