customerModel = new CustomerModel(); $this->storeModel = new StoreModel(); } /** * @param Request $request * @return \think\response\View * @throws \think\db\exception\DbException */ public function index(Request $request) { $params = $request->param(); View::assign([ 'list' => $this->customerModel->findCustomerPage($params), 'params' => [ 'name' => format_string($params['name'] ?? null), 'mobile' => format_string($params['mobile'] ?? null), ] ]); return view(); } public function add(Request $request) { if($request->isAjax()) { $params = $request->param(); $isExist = $this->customerModel->doesItExist($params['mobile']); if($isExist) return $this->fail(lang("Fail to add. Data duplication")); $this->customerModel->save(); return $this->ok(true); } else { View::assign('stores', $this->storeModel->findAllStore()); return view(); } } public function edit(Request $request) { $params = $request->param(); if(!isset($params['id'])) return $this->fail(lang('ID not exist')); $this->customerModel->findById($params['id']); // View::assign(); } 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->customerModel->deleteByIds(explode(',',$params['ids'])); return $this->ok(); } }