46 lines
1.2 KiB
PHP
46 lines
1.2 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'] ?? 0,
|
|
'unit' => $_value['unit'] ?? '未知',
|
|
];
|
|
}, $settings));
|
|
}
|
|
|
|
public function updateStatistics(Request $request){
|
|
$input = $request->input();
|
|
foreach ($input as $key => $value){
|
|
if(Setting::where('slug', $key)->exists()){
|
|
Setting::where('slug', $key)->update(['value->value'=>$value]);
|
|
}
|
|
}
|
|
|
|
(new OperationLogService())->inLog(OperationType::Update, '修改-全市基础数据统计', null, $input);
|
|
|
|
return $this->success();
|
|
}
|
|
}
|