ConfigController.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\Http\Controllers\AdminApi;
  3. use App\Models\SysModels\Config;
  4. use App\Http\Controllers\AdminController;
  5. class ConfigController extends AdminController
  6. {
  7. public function __construct()
  8. {
  9. parent::__construct();
  10. }
  11. /**
  12. * 获取&更新基础配置信息
  13. * @return \Illuminate\Http\JsonResponse
  14. */
  15. function setConfig(){
  16. if(request()->isMethod('post')){
  17. $data = request()->all();
  18. //更新config数据
  19. $this->update($data);
  20. return $this->apiResponseSuccess('更新成功');
  21. }else{
  22. $configs = Config::whereIn('key',['logo','title','tel','email','address','wx_image','icp','put_on_record'])->pluck('value','key');
  23. return $this->apiResponseSuccess('获取成功',$configs);
  24. }
  25. }
  26. /**
  27. * 更新config数据
  28. * @param $data
  29. * @return bool
  30. */
  31. function update($data){
  32. foreach ($data as $key => $value ){
  33. // 查找当前数据是否存在
  34. if( Config::where('key', $key)->where('value', $value)->count() ){ continue; }
  35. Config::where('key', $key)->update([ 'value' => $value ]);
  36. }
  37. return true;
  38. }
  39. }