作者:lch198548,来自原文地址
ECSHOP 小程序接口
整个接口基于THINKPHP5开发
部分文件目录
分类接口源码:
-
<?php
-
namespace app\common\model;
-
use think\Model;
-
class Category extends Model
-
{
-
protected static $allChildrenIds = [];
-
public function getChildrenIds($cat_id,$include = 1){
-
if(empty($cat_id)){
-
return [];
-
}
-
if(is_int($cat_id) || is_string($cat_id)){
-
$cat_id = [$cat_id];
-
}
-
$cat_id = array_unique($cat_id);
-
sort($cat_id);
-
$cat_id_str = implode('_', $cat_id);
-
if(isset(self::$allChildrenIds[$cat_id_str])){
-
return self::$allChildrenIds[$cat_id_str];
-
}
-
$catIds = [];
-
$childrenIds = $cat_id;
-
if($include == 1){
-
$catIds = $cat_id;
-
}
-
while($childrenIds){
-
$childrenIds = $this->where(['parent_id' => ['in',$childrenIds]])->column('cat_id');
-
if(!empty($childrenIds)){
-
$catIds = array_merge($catIds,$childrenIds);
-
}
-
}
-
self::$allChildrenIds[$cat_id_str] = $catIds;
-
return $catIds;
-
}
-
-
public function getChildrenList($cat_id = 0){
-
$categoryList = $this->field('cat_id,cat_name')->where(['parent_id' => $cat_id,'is_show' => 1])->order('sort_order desc')->select();
-
foreach($categoryList as &$category){
-
if($cat_id){
-
$category['cat_url'] = $this->getUrl($category['cat_id']);
-
}
-
}
-
return $categoryList;
-
}
-
-
public function getUrl($cat_id) {
-
return '../category/goods?cat_id=' . $cat_id;
-
}
-
}
查看ECSHOP小程序演示(微信扫一扫)
|