| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use app\common\model\StoreModel;
- use app\common\model\UserModel;
- use app\Request;
- use think\App;
- use think\facade\View;
- class User extends BaseController
- {
- private $userModel;
- private $storeModel;
- public function __construct(App $app)
- {
- $this->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 "<p>Hello</p>";
- }
- }
|