| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 |
- <?php
- namespace app\common\repositories\system;
- use app\common\dao\system\CacheDao;
- use app\common\repositories\BaseRepository;
- use think\db\exception\DbException;
- use think\exception\ValidateException;
- use think\facade\Cache;
- /**
- * Class CacheRepository
- * @package app\common\repositories\system
- * @author zfy
- * @day 2020-04-24
- * @mixin CacheDao
- */
- class CacheRepository extends BaseRepository
- {
- /**
- * CacheRepository constructor.
- * @param CacheDao $dao
- */
- public function __construct(CacheDao $dao)
- {
- $this->dao = $dao;
- }
- /**
- * @param string $key
- * @param $result
- * @param int $expire_time
- * @throws DbException
- * @author zfy
- * @day 2020-04-24
- */
- public function save(string $key, $result, int $expire_time = 0)
- {
- if (!$this->dao->fieldExists('key', $key)) {
- $this->dao->create(compact('key', 'result', 'expire_time'));
- } else {
- $this->dao->keyUpdate($key, compact('result', 'expire_time'));
- }
- }
- public function addres()
- {
- $re = (Cache::get('AAAAAA'));
- unset($re['省市编码']);
- if(!$re) throw new ValidateException('无数据');
- $shen = [];
- $shi =[];
- $qu = [];
- foreach ($re as $key => $value){
- $item = explode(',',$value);
- $cout = count($item);
- if($cout == 2){
- $shen[$item[1]] = [
- 'value' => $key ,
- 'label' => $item[1],
- ];
- }
- if($cout == 3){
- if($item[1] == ''){
- $shen[$item[2]] = [
- 'value' => $key ,
- 'label' => $item[2],
- ];
- $item[1] = $item[2];
- }
- $_v = [
- 'value' => $key,
- 'label' => $item[2]
- ];
- $shi[$item[1]][] = $_v;
- }
- if($cout == 4){
- $_v = [
- 'value' => $key,
- 'label' => $item[3]
- ];
- $qu[$item[2]][] = $_v;
- }
- }
- $data = [];
- foreach ($shen as $s => $c){
- foreach ($shi as $i => $c_){
- if($c['label'] == $i){
- if($c['label'] == $i) {
- $san = [];
- foreach ($c_ as $key => $value) {
- if (isset($qu[$value['label']])) {
- $value['child'] = $qu[$value['label']];
- $san[] = $value;
- }
- }
- }
- $c['child'] = $san;
- }
- }
- $zls[$s] = $c;
- }
- $data = array_values($zls);
- file_put_contents('address.js',json_encode($data,JSON_UNESCAPED_UNICODE));
- //$this->save('applyments_addres',$data);
- }
- }
|