model = new PaymentChannelModel(); parent::__construct($app); } public function index() { View::assign("list",$this->model->findAll()); return view(); } public function add() { if ($this->request->isAjax()) { $params = $this->request->param(); $this->model->save([ 'name' => $params['name'], 'icon' => $params['icon'], ]); return $this->ok(true); } return view(); } public function delete(Request $request) { $params = $request->param(); if(!isset($params['ids'])) return $this->fail(lang("Please select the data you want to delete")); $this->model->deleteByIds(explode(',',$params['ids'])); return $this->ok(true); } public function edit() { $params = $this->request->param(); if(!isset($params['id'])) return $this->fail(lang('ID not exist')); $channel = $this->model->findById($params['id']); if($this->request->isAjax()) { $res = $this->model->where('id',$params['id'])->update([ 'icon' => $params['icon'], 'name' => $params['name'], 'update_time' => time() ]); return $this->ok($res); } View::assign('channel', $channel); return view(); } /** * @return \think\response\Json */ public function upload() { // 获取表单上传文件 例如上传了001.jpg $file = request()->file('file'); // 上传到本地服务器 $save_name = \think\facade\Filesystem::disk('public')->putFile( 'icon', $file); return $this->ok(str_replace('\\',"/",'/storage/'.$save_name)); } }