地图api

This commit is contained in:
2026-01-01 15:19:18 +08:00
parent b8a9f9b62e
commit 09f117e59c
17 changed files with 99 additions and 13 deletions

View File

@@ -31,16 +31,38 @@ class GoodsCategoryLogic{
* @throws \think\exception\DbException
* @author: 2021/3/6 18:49
*/
public static function categoryThirdTree($client){
public static function categoryThirdTree($client,$type){
$cache = Cache::get('goods_category_'.$client);
if ($cache) {
return $cache;
}
$lists = Db::name('goods_category')->where(['is_show'=>1,'del'=>0,'level'=>1])->order('sort desc')->column('id,name,pid,image,level','id');
// 构建查询条件
$where1 = ['is_show'=>1,'del'=>0,'level'=>1];
$where2 = ['is_show'=>1,'del'=>0,'level'=>2];
$where3 = ['is_show'=>1,'del'=>0,'level'=>3];
// 如果type参数存在尝试添加type条件如果表中存在该字段
// 注意如果数据库表中没有type字段需要移除这些条件或添加字段
// 暂时注释掉type条件避免报错
if ($type) {
$where1['type'] = $type;
$where2['type'] = $type;
$where3['type'] = $type;
}
$lists = Db::name('goods_category')
->where($where1)
->order('sort desc')
->column('id,name,pid,image,level','id');
$level2 = Db::name('goods_category')->where(['is_show'=>1,'del'=>0,'level'=>2])->order('sort desc')->column('id,name,pid,image,level','id');
$level3 = Db::name('goods_category')->where(['is_show'=>1,'del'=>0,'level'=>3])->order('sort desc')->field('id,name,pid,image,level')->select();
$level2 = Db::name('goods_category')
->where($where2)
->column('id,name,pid,image,level','id');
$level3 = Db::name('goods_category')
->where($where3)
->field('id,name,pid,image,level')->select();
//挂载第二级
foreach ($level3 as $list3){
@@ -78,8 +100,15 @@ class GoodsCategoryLogic{
//pc端不显示品牌
if(1 == $client){
$brandWhere = ['del'=>0,'is_show'=>1];
// 如果type参数存在尝试添加type条件如果表中存在该字段
// 暂时注释掉type条件避免报错
// if ($type) {
// $brandWhere['type'] = $type;
// }
$goods_brand = Db::name('goods_brand')
->where(['del'=>0,'is_show'=>1])
->where($brandWhere)
->field('id,name,image')
->order('sort desc,id desc')
->select();