57 lines
1.7 KiB
PHP
57 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Peidikeji\Setting\Models\Setting;
|
|
use Illuminate\Http\Request;
|
|
use App\Services\OperationLogService;
|
|
use App\Enums\OperationType;
|
|
|
|
class CityDataController extends Controller
|
|
{
|
|
/**
|
|
* 基础数据统计
|
|
*
|
|
* @return void
|
|
*/
|
|
public function statistics()
|
|
{
|
|
$settings = Setting::where('slug', 'like', 'city_data_%')->get()->toArray();
|
|
|
|
return $this->json(array_map(function ($item) {
|
|
$_value = json_decode($item['value'], true);
|
|
|
|
return [
|
|
'name' => $item['name'],
|
|
'slug' => $item['slug'],
|
|
'value' => $_value['value'] ?? $_value,
|
|
'unit' => $_value['unit'] ?? '万元',
|
|
];
|
|
}, $settings));
|
|
}
|
|
|
|
public function updateStatistics(Request $request){
|
|
$input = $request->input();
|
|
foreach ($input as $key => $value){
|
|
//如果是更新图表数据
|
|
if(in_array($key, [
|
|
'city_data_chart_nongye',
|
|
'city_data_chart_yuye',
|
|
'city_data_chart_xumuye',
|
|
'city_data_chart_lingye',
|
|
'city_data_chart_activity'
|
|
])){
|
|
Setting::where('slug', $key)->update(['value'=>json_encode($value)]);
|
|
}else{//更新全市基础数据
|
|
if(Setting::where('slug', $key)->exists()){
|
|
Setting::where('slug', $key)->update(['value->value'=>$value]);
|
|
}
|
|
}
|
|
}
|
|
|
|
(new OperationLogService())->inLog(OperationType::Update, '修改-全市基础数据统计', null, $input);
|
|
|
|
return $this->success();
|
|
}
|
|
}
|