Product.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\admin\controller;
  3. use app\BaseController;
  4. use app\common\model\ProductCategoryModel;
  5. use app\common\model\ProductModel;
  6. use think\App;
  7. use think\facade\View;
  8. use think\Request;
  9. class Product extends BaseController
  10. {
  11. private $productModel;
  12. private $categoryModel;
  13. public function __construct(App $app)
  14. {
  15. parent::__construct($app);
  16. $this->productModel = new ProductModel();
  17. $this->categoryModel = new ProductCategoryModel();
  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. $format_params = [
  27. 'bar_code' => format_string($params['bar_code'] ?? null),
  28. 'category_id' => format_string($params['category_id'] ?? null),
  29. 'is_serve' => format_string($params['is_serve'] ?? null),
  30. ];
  31. View::assign([
  32. 'list' => $this->productModel->findByPaginate($format_params),
  33. 'params' => $format_params,
  34. 'all_category' => recursion($this->categoryModel->findAll(),0),
  35. ]);
  36. return view();
  37. }
  38. public function add(Request $request) {
  39. return view();
  40. }
  41. public function edit(Request $request) {
  42. return view();
  43. }
  44. public function delete(Request $request) {
  45. $params = $request->param();
  46. if(!isset($params['ids']))
  47. return $this->fail(lang("Please select the data you want to delete"));
  48. $this->productModel->deleteByIds(explode(',',$params['ids']));
  49. return $this->ok();
  50. }
  51. }