Customer.php 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use app\common\model\CustomerModel;
  5. use app\common\model\StoreModel;
  6. use think\App;
  7. use think\facade\View;
  8. use think\Request;
  9. class Customer extends BaseController
  10. {
  11. private $customerModel;
  12. private $storeModel;
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->customerModel = new CustomerModel();
  17. $this->storeModel = new StoreModel();
  18. }
  19. /**
  20. * @param Request $request
  21. * @return \think\response\View
  22. * @throws \think\db\exception\DbException
  23. */
  24. public function index(Request $request) {
  25. $params = $request->param();
  26. View::assign([
  27. 'list' => $this->customerModel->findCustomerPage($params),
  28. 'params' => [
  29. 'name' => format_string($params['name'] ?? null),
  30. 'mobile' => format_string($params['mobile'] ?? null),
  31. ]
  32. ]);
  33. return view();
  34. }
  35. public function add(Request $request) {
  36. if($request->isAjax()) {
  37. $params = $request->param();
  38. $isExist = $this->customerModel->doesItExist($params['mobile']);
  39. if($isExist) return $this->fail(lang("Fail to add. Data duplication"));
  40. $this->customerModel->save();
  41. return $this->ok(true);
  42. } else {
  43. View::assign('stores', $this->storeModel->findAllStore());
  44. return view();
  45. }
  46. }
  47. public function edit(Request $request) {
  48. $params = $request->param();
  49. if(!isset($params['id']))
  50. return $this->fail(lang('ID not exist'));
  51. $this->customerModel->findById($params['id']);
  52. // View::assign();
  53. }
  54. public function delete(Request $request) {
  55. $params = $request->param();
  56. if(!isset($params['ids']))
  57. return $this->fail(lang("Please select the data you want to delete"));
  58. $this->customerModel->deleteByIds(explode(',',$params['ids']));
  59. return $this->ok();
  60. }
  61. }