first commit
This commit is contained in:
141
pgserver/application/admin/controller/Regions.php
Normal file
141
pgserver/application/admin/controller/Regions.php
Normal file
@@ -0,0 +1,141 @@
|
||||
<?php
|
||||
|
||||
namespace app\admin\controller;
|
||||
|
||||
use think\Db;
|
||||
use app\model\Region;
|
||||
|
||||
class Regions extends Base{
|
||||
|
||||
/**
|
||||
* @api {post} admin/Regions/getBuildingCity 获取询价所在城市
|
||||
*/
|
||||
public function getBuildingCity(){
|
||||
$result = cache('building_city');
|
||||
$building = cache('building');
|
||||
if (empty($result) || empty($building)) {
|
||||
$building = Db::name('system_config')->where(['name' => 'BUILDING_CITY'])->value('value');
|
||||
$result = Region::getAll(['level' => 2, 'status' => 1, 'id' => explode(',', $building)], 'id,shortname');
|
||||
cache('building_city', $result, 3600);
|
||||
}
|
||||
if ($result !== false)
|
||||
return $this->buildSuccess($result);
|
||||
return $this->buildFailed( '城市读取失败!');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @api {post} admin/Regions/reqDistrict 获取城区/片区
|
||||
*/
|
||||
public function reqDistrict()
|
||||
{
|
||||
$parentId = $this->request->post('id');
|
||||
if (empty($parentId))
|
||||
return $this->buildFailed( '缺少参数!');
|
||||
$result = Region::getAll(['parentid' => $parentId, 'status' => 1], 'id,shortname');
|
||||
if ($result !== false)
|
||||
return $this->buildSuccess($result);
|
||||
return $this->buildFailed('读取失败!');
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} admin/Regions/addRegionConfig 新增编辑区域配置
|
||||
*/
|
||||
public function addRegionConfig()
|
||||
{
|
||||
$data = $this->request->post('');
|
||||
if (empty($data)) return $this->buildFailed('参数不能为空!');
|
||||
if (empty($data['city_id'])) return $this->buildFailed('请选择城市!');
|
||||
if (empty($data['area_ids'])) return $this->buildFailed('请选择区域!');
|
||||
if (empty($data['type'])) return $this->buildFailed('请选择区域类型!');
|
||||
if (empty($data['money'])) return $this->buildFailed('价格不能为空或0!');
|
||||
|
||||
if($data['city_id'] == '440300'){ //深圳
|
||||
$res = Region::SZ_area;
|
||||
}elseif($data['city_id'] == '110100'){ //北京
|
||||
$res = Region::BJ_area;
|
||||
}elseif($data['city_id'] == '441900'){ //东莞
|
||||
$res = Region::DONGGUAN_area;
|
||||
}
|
||||
$area = [];
|
||||
foreach ($res as $key => $value) {
|
||||
if (in_array($key, $data['area_ids'])) {
|
||||
$area[] = $value;
|
||||
}
|
||||
}
|
||||
$data['area'] = implode('、', $area);
|
||||
$data['area_ids'] = implode(',', $data['area_ids']);
|
||||
$city = Db::name('region')->where('id', $data['city_id'])->value('name');
|
||||
$data['city'] = $city;
|
||||
|
||||
if (empty($data['id'])) {
|
||||
$data['create_time'] = $data['update_time'] = time();
|
||||
$data['create_uid'] = 1;
|
||||
if (!Db::name('region_config')->insert($data)) {
|
||||
return $this->buildFailed('操作失败!');
|
||||
}
|
||||
} else {
|
||||
$data['update_time'] = time();
|
||||
$id = $data['id'];
|
||||
unset($data['id']);
|
||||
if (!Db::name('region_config')->where('id', $id)->update($data)) {
|
||||
return $this->buildFailed('操作失败!');
|
||||
}
|
||||
}
|
||||
return $this->buildSuccess();
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} admin/Regions/index 区域配置列表
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$city = $this->request->post('city');
|
||||
$where = [];
|
||||
$where[] = ['status', '=', 1];
|
||||
if ($city) {
|
||||
$where[] = ['city_id', '=', $city];
|
||||
}
|
||||
$res = Db::name('region_config')->field('id,city,area,type,money,update_time')->where($where)->order('update_time', 'desc')->paginate($this->getPage())->toArray();
|
||||
if (!empty($res['data'])) {
|
||||
foreach ($res['data'] as &$value) {
|
||||
$value['update_time'] = !empty($value['update_time']) ? date('Y-m-d H:i:s', $value['update_time']) : '';
|
||||
$value['type'] = getDictionaryName('REGION_CONFIG_TYPE', $value['type']);
|
||||
}
|
||||
}
|
||||
return $this->buildSuccess(['list' => $res['data'], 'count' => $res['total']]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} admin/Regions/getInfo 区域配置信息
|
||||
*/
|
||||
public function getInfo()
|
||||
{
|
||||
$id = $this->request->post('id');
|
||||
if (empty($id)) return $this->buildFailed('参数不能为空!');
|
||||
$res = Db::name('region_config')->where('id', $id)->field('id,city,city_id,area,area_ids,type,money')->find();
|
||||
$res['area_ids'] = explode(',', $res['area_ids']);
|
||||
return $this->buildSuccess($res);
|
||||
}
|
||||
|
||||
/**
|
||||
* @api {post} admin/Regions/getSmallArea 获取小片区
|
||||
*/
|
||||
public function getSmallArea(){
|
||||
$id = $this->request->post('id');
|
||||
if(!$id) return $this->buildFailed('参数错误');
|
||||
$res = [];
|
||||
if($id == '440300'){ //深圳
|
||||
$res = Region::SZ_area;
|
||||
}elseif($id == '110100'){ //北京
|
||||
$res = Region::BJ_area;
|
||||
}elseif($id == '420100'){ //武汉
|
||||
$res = Region::WH_area;
|
||||
}elseif($id == '441900'){ //东莞
|
||||
$res = Region::DONGGUAN_area;
|
||||
}
|
||||
return $this->buildSuccess($res);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user