| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- namespace app\admin\controller;
- use app\BaseController;
- use app\common\model\StoreModel;
- use think\App;
- use think\facade\View;
- use think\Request;
- class Store extends BaseController
- {
- private $storeModel;
- public function __construct(App $app)
- {
- $this->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();
- }
- }
|