| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 | <?phpnamespace App\Http\Controllers\Admin;use App\Models\Setting;use Illuminate\Http\Request;class SettingController extends Controller{    protected $redirect_index = '/admin/Setting/index';    protected $view_path = 'admin.settings.';    protected $pre_uri = '/admin/Setting/';    protected $model_name = '系统配置';    protected $model;    public function __construct()    {        parent::__construct();        $this->model = new Setting();    }    public function share()    {        $share_image = $this->model->firstOrCreate(['key' => 'share_image'], ['key_show' => '图片']);        $share_text = $this->model->firstOrCreate(['key' => 'share_text'], ['key_show' => '文本标签']);        $share_text_pos = $this->model->firstOrCreate(['key' => 'share_text_pos'], ['key_show' => '文本位置']);        list($pre_uri, $model, $model_name) = array($this->pre_uri, $this->model, $this->model_name);        return view($this->view_path . 'share', compact('pre_uri', 'model', 'model_name', 'share_image', 'share_text', 'share_text_pos'));    }    public function updateShare(Request $request)    {        if(!$request->isMethod('POST')) {            return $this->showWarning('访问错误');        }        if(!empty($request->input('share_image'))) {            $this->model->where('key', 'share_image')->update(['value' => $request->input('share_image')]);        }        if(!empty($request->input('share_text'))) {            $this->model->where('key', 'share_text')->update(['value' => $request->input('share_text')]);        }        if(!empty($request->input('share_text_pos'))) {            $this->model->where('key', 'share_text_pos')->update(['value' => $request->input('share_text_pos')]);        }        return $this->showMessage('操作成功');    }    public function system(Request $request)    {        $check_card_location = $this->model->firstOrCreate(['key' => 'check_card_location'], ['value' => '39.916527,116.397128']);        $check_card_radius = $this->model->firstOrCreate(['key' => 'check_card_radius'], ['value' => '1000']);        list($pre_uri, $model, $model_name) = array($this->pre_uri, $this->model, $this->model_name);        return view($this->view_path . 'system', compact('pre_uri', 'model', 'model_name', 'check_card_location', 'check_card_radius'));    }    public function updateSystem(Request $request)    {        if(!$request->isMethod('POST')) {            return $this->showWarning('访问错误');        }        $items = collect(['check_card_location', 'check_card_radius']);        foreach($items as $item) {            if(!empty($request->input($item))) {                $this->model->where('key', $item)->update(['value' => $request->input($item)]);            }        }        return $this->showMessage('操作成功');    }}
 |