Commit 9086adf8 by 汪伟伟

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

parent ac3b1101
......@@ -215,22 +215,32 @@ class TaskController extends AdminController
public function getCity(Request $request)
{
// $provinceId = $request->get('q');
$data = json_decode(file_get_contents(base_path('app/china_all_area.json')), true);
$city = [];
$already = \App\Models\Task::query()->orderBy('created_at','desc')->pluck('city_id')->toArray();
$already = array_unique($already);
foreach ($data['100000'] as $key => $value) {
if (isset($data[$key])) {
foreach ($data[$key] as $k => $val) {
if (!in_array($k,$already)){
$city[] = [
'id' => $k,
'text' => $val
];
}
}
}
}
return $city;
$left = [];
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
$images .= $url . ',';
}
}
$query = \App\Models\Task::query();
$form = Form::make();
foreach ($param['city_id'] as $city) {
if ($city) {
foreach ($param['year'] as $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 = [
'name' => $param['name'],
'level' => $param['level'],
......@@ -373,12 +389,11 @@ class TaskController extends AdminController
'price' => $param['price'] ?? 0,
'images' => $images,
];
$query->create($insertData);
\App\Models\Task::query()->create($insertData);
}
}
}
}
$form = Form::make();
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