userModel = new UserModel(); $this->storeModel = new StoreModel(); parent::__construct($app); } public function index(Request $request) { $params = $request->param(); $format_params = [ 'store_id' => format_string($params['store_id'] ?? null), ]; View::assign([ 'list' => $this->userModel->findByPaginate($format_params), 'params' => $format_params, 'stores' => $this->storeModel->findAllStore(), ]); return view(); } public function add() { $params = $this->request->param(); $format_params = [ 'store_id' => format_string($params['store_id'] ?? null), ]; if ($this->request->isAjax()) { $exist = $this->userModel->doesItExist($params['mobile']); if ($exist) return $this->fail(lang("Data duplication")); $store = $this->storeModel->findById($params['store_id']); if (!$store) return $this->fail(lang('Store does not exist')); $res = $this->userModel->save([ 'username' => $params['username'], 'mobile' => $params['mobile'], 'password' => md5($params['password']), 'store_id' => $store->id, 'store_abbr'=> $store->abbr, 'rule' => $params['rule'], ]); return $res ? $this->ok(true) : $this->fail(false); } View::assign([ 'params' => $format_params, 'stores' => $this->storeModel->findAllStore(), ]); return view(); } public function edit() { $params = $this->request->param(); $user = $this->userModel->findById($params['id']); $format_params = [ 'store_id' => $user->store_id, ]; if (!$user) return $this->fail(lang('Data not exist')); if ($this->request->isAjax()) { $exist = $this->userModel->doesItExist($params['mobile']); if ($exist && $exist->id != $user->id) return $this->fail(lang("Data duplication")); $store = $this->storeModel->findById($params['store_id']); if (!$store) return $this->fail(lang('Store does not exist')); $res = $this->userModel->where('id', $params['id'])->update([ 'username' => $params['username'], 'mobile' => $params['mobile'], 'password' => $params['password'] == $user->passwrd ? $user->password : md5($params['password']), 'store_id' => $store->id, 'store_abbr'=> $store->abbr, 'rule' => $params['rule'], 'update_time'=> time() ]); return $res ? $this->ok(true) : $this->fail(false); } View::assign([ 'params' => $format_params, 'stores' => $this->storeModel->findAllStore(), 'user' => $user ]); return view(); } public function delete(\think\Request $request) { $params = $request->param(); if(!isset($params['ids'])) return $this->fail(lang("Please select the data you want to delete")); $this->userModel->deleteByIds(explode(',', $params['ids'])); return $this->ok(true); } public function total_data() { return "

Hello

"; } }