Commit 71591851 by LiuJunYi

三级联动(地区)接口

parent 718829d0
......@@ -18,6 +18,7 @@ use app\common\model\Tags as TagsModel;
use app\common\model\User as UserModel;
use app\common\model\Reservations as ReservationsModel;
use think\Validate;
use app\common\model\Region as RegionModel;
class Project extends Base
{
......@@ -374,12 +375,14 @@ class Project extends Base
$data['catalog_id'] = collection(CatalogsModel::order('sort', 'desc')->select())->visible(['id', 'name'])->toArray();
$data['city'] = collection(CitysModel::order('sort', 'desc')->select())->visible(['id', 'name'])->toArray();
$data['tags'] = collection(TagsModel::order('sort', 'desc')->select())->visible(['id', 'name'])->toArray();
$data['level_1'] = collection(RegionModel::where(['level' => 1, 'pid' => 0])->select())->visible(['id', 'title'])->toArray();
if (!$data) return ['code' => 1, 'msg' => '没有更多'];
array_unshift($data['type'], ['id' => '0', 'name' => "全部项目"]);
array_unshift($data['catalog_id'], ['id' => '0', 'name' => "全部分类"]);
array_unshift($data['city'], ['id' => '2', 'name' => "国外"]);
array_unshift($data['city'], ['id' => '1', 'name' => "国内"]);
array_unshift($data['city'], ['id' => '0', 'name' => "全部地区"]);
array_unshift($data['level_1'], ['id' => '0', 'title' => "全部"]);
return ['code' => 0, 'msg' => 'success', 'data' => $data];
}
......@@ -480,4 +483,24 @@ class Project extends Base
]);
return ['code' => 0, 'msg' => '预约成功'];
}
/**
* 三级联动(地区)
* @url /api/Project/queryRegion
* @param id
* @return json
*/
public function queryRegion()
{
if (input('id') == 0) {
return ['code' => 1, 'msg' => 'success', 'data' => [['id' => 0, 'title' => '全部']]];
}
$list = RegionModel::where('pid', input('id'))->select();
if(!$list){
return ['code' => 1, 'msg' => 'success', 'data' => [['id' => 0, 'title' => '全部']]];
}
$list = collection($list)->visible(['id', 'title'])->toArray();
array_unshift($list,['id' => 0, 'title' => '全部']);
return ['code' => 1, 'msg' => 'success', 'data' => $list];
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment