提交 83e1c226 编写于 作者: G gongfuxiang

读取商品分类所有子分类追加级别限定

上级 ac22d2d3
......@@ -382,11 +382,11 @@ class GoodsService
* @version 1.0.0
* @date 2018-08-29
* @desc description
* @param [array] $ids [分类id数组]
* @param [int] $is_enable [是否启用 null, 0否, 1是]
* @param [string] $order_by [排序, 默认sort asc]
* @param [array] $ids [分类id数组]
* @param [int] $is_enable [是否启用 null, 0否, 1是]
* @param [int] $level [指定级别 null, 整数、默认则全部下级]
*/
public static function GoodsCategoryItemsIds($ids = [], $is_enable = null, $order_by = 'sort asc')
public static function GoodsCategoryItemsIds($ids = [], $is_enable = null, $level = null)
{
if(!is_array($ids))
{
......@@ -397,13 +397,32 @@ class GoodsService
{
$where['is_enable'] = $is_enable;
}
$data = Db::name('GoodsCategory')->where($where)->order($order_by)->column('id');
if(!empty($data))
// 级别记录处理
if($level !== null)
{
if(is_array($level))
{
$level['temp'] += 1;
} else {
$level = [
'value' => $level,
'temp' => 1,
];
}
}
// 是否超过级别限制
if($level === null || $level['temp'] < $level['value'])
{
$temp = self::GoodsCategoryItemsIds($data, $is_enable, $order_by);
if(!empty($temp))
$data = Db::name('GoodsCategory')->where($where)->column('id');
if(!empty($data))
{
$data = array_merge($data, $temp);
$temp = self::GoodsCategoryItemsIds($data, $is_enable, $level);
if(!empty($temp))
{
$data = array_merge($data, $temp);
}
}
}
$data = empty($data) ? $ids : array_unique(array_merge($ids, $data));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册