storeModel = new StoreModel(); parent::__construct($app); } public function index(Request $request) { $params = $request->param(); View::assign([ 'list' => $this->storeModel->findByPaginate($params), 'params' => $params, ]); return view(); } public function add(Request $request) { if($request->isAjax()) { $params = $request->param(); list($name,$abbr,$address) = [$params['name'],$params['abbr'],$params['address']]; $store = $this->storeModel->doesItExist($abbr); if ($store) return $this->fail(lang('Fail to add. Data duplication')); $res = $this->storeModel->save([ 'name' => $name, 'abbr' => $abbr, 'address' => $address ]); return $this->ok($res); } return view(); } public function edit(Request $request) { $params = $request->param(); if(!isset($params['id'])) return $this->fail(lang('ID not exist')); $store = $this->storeModel->findById($params['id']); if (!$store) return $this->fail(lang('Data not exist')); if ($request->isAjax()) { $exist_store = $this->storeModel->doesItExist($params['abbr']); if ($exist_store && $exist_store->id != $params['id']) return $this->fail(lang('Data duplication')); $res = $this->storeModel->where('id',$params['id'])->update([ 'name' => $params['name'], 'abbr' => $params['abbr'], 'address' => $params['address'], 'update_time' => time() ]); return $this->ok($res); } View::assign('store', $store); 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->storeModel->deleteByIds(explode(',', $params['ids'])); return $this->ok(true); } public function total_data(Request $request) { $params = $request->param(); if(!isset($params['id'])) return $this->fail(lang('ID not exist')); $store = $this->storeModel->findById($params['id']); if (!$store) return $this->fail(lang('Data not exist')); View::assign('store', $store); return view(); } }