PriceRule.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\controller\admin\store;
  12. use app\common\repositories\store\PriceRuleRepository;
  13. use app\validate\admin\PriceRuleValidate;
  14. use crmeb\basic\BaseController;
  15. use think\App;
  16. class PriceRule extends BaseController
  17. {
  18. protected $repository;
  19. /**
  20. * Product constructor.
  21. * @param App $app
  22. * @param PriceRuleRepository $repository
  23. */
  24. public function __construct(App $app, PriceRuleRepository $repository)
  25. {
  26. parent::__construct($app);
  27. $this->repository = $repository;
  28. }
  29. public function lst()
  30. {
  31. $where = $this->request->params(['cate_id', 'keyword', 'is_show']);
  32. [$page, $limit] = $this->getPage();
  33. return app('json')->success($this->repository->lst($where, $page, $limit));
  34. }
  35. public function update($id)
  36. {
  37. $data = $this->getParams();
  38. if (!$this->repository->exists((int)$id)) {
  39. return app('json')->fail('数据不存在');
  40. }
  41. $this->repository->updateRule((int)$id, $data);
  42. return app('json')->success('编辑成功');
  43. }
  44. public function create()
  45. {
  46. $data = $this->getParams();
  47. $this->repository->createRule($data);
  48. return app('json')->success('添加成功');
  49. }
  50. public function delete($id)
  51. {
  52. if (!$this->repository->exists((int)$id)) {
  53. return app('json')->fail('数据不存在');
  54. }
  55. $this->repository->delete((int)$id);
  56. return app('json')->success('删除成功');
  57. }
  58. public function getParams()
  59. {
  60. $data = $this->request->params(['rule_name', 'cate_id', 'sort', 'is_show', 'content']);
  61. app()->make(PriceRuleValidate::class)->check($data);
  62. return $data;
  63. }
  64. public function switchStatus($id)
  65. {
  66. $status = $this->request->param('is_show') == 1 ?: 0;
  67. if (!$this->repository->exists((int)$id))
  68. return app('json')->fail('数据不存在');
  69. $this->repository->update($id, ['is_show' => $status]);
  70. return app('json')->success('修改成功');
  71. }
  72. }