全栈小学生 0e47055ccb v1.0.0-beta.1
2023-04-15 17:12:49 +08:00

64 lines
2.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
// +----------------------------------------------------------------------
// | Niucloud-admin 企业快速开发的saas管理平台
// +----------------------------------------------------------------------
// | 官方网址https://www.niucloud-admin.com
// +----------------------------------------------------------------------
// | niucloud团队 版权所有 开源版本可自由商用
// +----------------------------------------------------------------------
// | Author: Niucloud Team
// +----------------------------------------------------------------------
namespace app\service\admin\sys;
use app\model\sys\SysArea;
use app\service\admin\BaseAdminService;
use think\facade\Cache;
/**
* 地区服务层
* Class AreaService
* @package app\service\admin\sys
*/
class AreaService extends BaseAdminService
{
public static $cache_tag_name = 'area_cache';
public function __construct()
{
parent::__construct();
$this->model = new SysArea();
}
/**
* 获取地区信息
* @param int $pid //上级pid
* @return mixed
*/
public function getListByPid(int $pid = 0)
{
$cache_name = self::$cache_tag_name.'_pid_'.$pid;
return Cache::tag([self::$cache_tag_name])->remember($cache_name, function() use($pid) {
$list = $this->model->where([['pid', '=', $pid]])->field('id, pid, name, shortname, longitude, latitude, level, sort, status')->select()->toArray();
return $list;
});
}
/**
* 查询地区树列表
* @param int $level //层级1,2,3
* @return mixed
*/
public function getAreaTree(int $level = 3)
{
$cache_name = self::$cache_tag_name.'_tree_'.$level;
return Cache::tag([self::$cache_tag_name])->remember($cache_name, function() use($level) {
$list = $this->model->where([['level', '<=', $level]])->field('id, pid, name, shortname, longitude, latitude, level, sort, status')->select()->toArray();
$tree = list_to_tree($list, 'id', 'pid');
return $tree;
});
}
}