12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- <?php
- namespace App\Http\Controllers\AdminApi;
- use App\Models\SysModels\Config;
- use App\Http\Controllers\AdminController;
- use App\Servers\Common\RedisDataServer;
- 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);
- //清除redis数据
- RedisDataServer::creatServer()->delData('gw_configs');
- return $this->apiResponseSuccess('更新成功');
- }else{
- $configs = Config::whereIn('key',['logo','cn_title','en_title','tel','email','cn_address','en_address','wx_image','icp','put_on_record','lon','lat'])->pluck('value','key');
- return $this->apiResponseSuccess('获取成功',$configs);
- }
- }
- /**
- * 获取&更新留言短信通知手机号
- * @return \Illuminate\Http\JsonResponse
- */
- function setSmsPhone(){
- if(request()->isMethod('post')){
- $sms_phone = request()->input(['sms_phone']);
- if(!is_array($sms_phone)) return $this->apiResponseError('数据格式错误');
- $data['sms_phone'] = implode(',',$sms_phone);
- //更新config数据
- $this->update($data);
- return $this->apiResponseSuccess('更新成功');
- }else{
- $sms_phone = Config::where('key','sms_phone')->value('value');
- $data['sms_phone'] = array_filter(explode(',',$sms_phone));
- return $this->apiResponseSuccess('获取成功',$data);
- }
- }
- /**
- * 更新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;
- }
- }
|