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