Commit 9086adf8 by 汪伟伟

指标名称重复判断,地区下拉框先加载之前用过的地区

parent ac3b1101
...@@ -215,22 +215,32 @@ class TaskController extends AdminController ...@@ -215,22 +215,32 @@ class TaskController extends AdminController
public function getCity(Request $request) public function getCity(Request $request)
{ {
// $provinceId = $request->get('q'); // $provinceId = $request->get('q');
$data = json_decode(file_get_contents(base_path('app/china_all_area.json')), true); $data = json_decode(file_get_contents(base_path('app/china_all_area.json')), true);
$city = []; $city = [];
$already = \App\Models\Task::query()->orderBy('created_at','desc')->pluck('city_id')->toArray();
$already = array_unique($already);
foreach ($data['100000'] as $key => $value) { foreach ($data['100000'] as $key => $value) {
if (isset($data[$key])) { if (isset($data[$key])) {
foreach ($data[$key] as $k => $val) { foreach ($data[$key] as $k => $val) {
if (!in_array($k,$already)){
$city[] = [ $city[] = [
'id' => $k, 'id' => $k,
'text' => $val 'text' => $val
]; ];
} }
}
} }
} }
$left = [];
return $city; foreach ($already as $a){
$left[]=[
'id'=>$a,
'text'=>CityAreaService::getAreaName($a)
];
}
// dd($left,array_merge($left,$city));
return array_merge($left,$city);
} }
...@@ -356,12 +366,18 @@ class TaskController extends AdminController ...@@ -356,12 +366,18 @@ class TaskController extends AdminController
$images .= $url . ','; $images .= $url . ',';
} }
} }
$form = Form::make();
$query = \App\Models\Task::query();
foreach ($param['city_id'] as $city) { foreach ($param['city_id'] as $city) {
if ($city) { if ($city) {
foreach ($param['year'] as $y) { foreach ($param['year'] as $y) {
if ($y) { if ($y) {
if (\App\Models\Task::query()
->where('name', $param['name'])
->where('city_id', $city)
->where('year', $y)
->exists()) {
return $form->response()->error('指标名称重复:' . $param['name'] . ' ' . CityAreaService::getAreaName($city) . ' ' . $y);
}
$insertData = [ $insertData = [
'name' => $param['name'], 'name' => $param['name'],
'level' => $param['level'], 'level' => $param['level'],
...@@ -373,12 +389,11 @@ class TaskController extends AdminController ...@@ -373,12 +389,11 @@ class TaskController extends AdminController
'price' => $param['price'] ?? 0, 'price' => $param['price'] ?? 0,
'images' => $images, 'images' => $images,
]; ];
$query->create($insertData); \App\Models\Task::query()->create($insertData);
} }
} }
} }
} }
$form = Form::make();
return $form->response()->success('操作成功')->redirect('tasks'); return $form->response()->success('操作成功')->redirect('tasks');
} }
......
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