123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- <?php
- // +----------------------------------------------------------------------
- // | LARAVEL8.0 框架 [ LARAVEL ][ RXThinkCMF ]
- // +----------------------------------------------------------------------
- // | 版权所有 2017~2021 LARAVEL研发中心
- // +----------------------------------------------------------------------
- // | 官方网站: http://www.laravel.cn
- // +----------------------------------------------------------------------
- // | Author: laravel开发员 <laravel.qq.com>
- // +----------------------------------------------------------------------
- namespace App\Services;
- use App\Models\CityModel;
- use App\Models\ConfigModel;
- /**
- * 地址管理-服务类
- * @author laravel开发员
- * @since 2020/11/11
- * @package App\Services
- */
- class CityService extends BaseService
- {
- // 静态对象
- protected static $instance = null;
- /**
- * 构造函数
- * @author laravel开发员
- * @since 2020/11/11
- * ConfigService constructor.
- */
- public function __construct()
- {
- $this->model = new CityModel();
- }
- /**
- * 静态入口
- */
- public static function make(){
- if(!self::$instance){
- self::$instance = new static();
- }
- return self::$instance;
- }
- /**
- * 获取
- * @param $name
- * @return array|int|mixed
- */
- public function getFieldByName($name, $field='id')
- {
- if(empty($name)){
- return 0;
- }
- $cacheKey = "caches:address:city_{$field}_".md5($name);
- $data = RedisService::get($cacheKey);
- if($data){
- return isset($data[$field])? $data[$field] : 0;
- }
- $data = $provinceId = $this->model->where('name','like',"%{$name}%")->select(['id','pid','name','level','citycode'])->first();
- $data = $data? $data->toArray() : [];
- if($data){
- RedisService::set($cacheKey, [], 3600);
- }
- return $data;
- }
- }
|