| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- <?php
- namespace app\common\service;
- use app\common\model\AddressModel;
- use utils\RedisCache;
- /**
- * 地址管理 by wes
- * Class AddressService
- * @package app\common\service
- */
- class AddressService
- {
- protected static $instance = null;
- protected $model = null;
- public function __construct()
- {
- $this->model = new AddressModel();
- }
- /**
- * 静态化入口
- * @return static|null
- */
- public static function make()
- {
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 获取列表
- * @param $sid 上级ID
- * @return array|mixed
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\DbException
- * @throws \think\db\exception\ModelNotFoundException
- */
- public function getListByParent($sid)
- {
- $cacheKey = "caches:address:list_{$sid}";
- $data = RedisCache::get($cacheKey);
- if($data){
- return $data;
- }
- $data = $this->model->where(['pid'=> $sid])->field('id,name,first,pinyin')->select();
- $data = $data? $data->toArray():[];
- if($data){
- RedisCache::set($cacheKey, $data, rand(5,10));
- }
- return $data;
- }
- }
|