| 123456789101112131415161718192021222324252627282930313233343536373839404142434445 |
- <?php
- namespace App\Http\Controllers\AdminApi;
- use App\Models\SysModels\Config;
- use App\Http\Controllers\AdminController;
- class ConfigController extends AdminController
- {
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * 获取&更新基础配置信息
- * @return \Illuminate\Http\JsonResponse
- */
- function setConfig(){
- if(request()->isMethod('post')){
- $data = request()->all();
- //更新config数据
- $this->update($data);
- return $this->apiResponseSuccess('更新成功');
- }else{
- $configs = Config::whereIn('key',['logo','title','tel','email','address','wx_image','icp','put_on_record'])->pluck('value','key');
- return $this->apiResponseSuccess('获取成功',$configs);
- }
- }
- /**
- * 更新config数据
- * @param $data
- * @return bool
- */
- function update($data){
- foreach ($data as $key => $value ){
- // 查找当前数据是否存在
- if( Config::where('key', $key)->where('value', $value)->count() ){ continue; }
- Config::where('key', $key)->update([ 'value' => $value ]);
- }
- return true;
- }
- }
|