cxfoot/modules/api/models/StoreCityForm.php
2023-10-24 14:54:18 +08:00

58 lines
1.3 KiB
PHP

<?php
/**
* @author Any
* @description KISS
* @date 2022年7月12日
* @version 1.0.0
*
* _____LOG_____
*
*/
namespace app\modules\api\models;
use app\models\District;
use app\models\Store;
use app\components\FlashStorage;
class StoreCityForm extends ApiModel
{
// 获取名称
public function getCacheName($levels='city'){
$level_md5 = md5(json_encode($levels));
$cache_key = "_dh_ul_cil_scf_v1_{$level_md5}";
return $cache_key;
}
public function search()
{
$levels = 'city';
$cache_key = $this->getCacheName($levels);
$data = FlashStorage::getCache($cache_key);
if($data !== false){
return $this->apiReturnSuccess('ok', $data);
}
$city_ids = Store::find()
->where([
'is_delete' => 0,
])
->select('city_id')
->column();
$filter = [
'id' => $city_ids
];
$data = District::_getCityIndexList($levels, $filter);
$res = [];
foreach ($data as $key=>$val){
$res[] = [
'index' => $key,
'data' => $val,
];
}
FlashStorage::setCache($cache_key, $res,3600);
return $this->apiReturnSuccess('ok', $res);
}
}