PriceRule.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2024 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. /**
  17. * 价格说明
  18. */
  19. class PriceRule extends BaseController
  20. {
  21. protected $repository;
  22. /**
  23. * Product constructor.
  24. * @param App $app
  25. * @param PriceRuleRepository $repository
  26. */
  27. public function __construct(App $app, PriceRuleRepository $repository)
  28. {
  29. parent::__construct($app);
  30. $this->repository = $repository;
  31. }
  32. /**
  33. * 列表
  34. * @return \think\response\Json
  35. * @author Qinii
  36. */
  37. public function lst()
  38. {
  39. $where = $this->request->params(['cate_id', 'keyword', 'is_show']);
  40. [$page, $limit] = $this->getPage();
  41. return app('json')->success($this->repository->lst($where, $page, $limit));
  42. }
  43. /**
  44. * 编辑
  45. * @param $id
  46. * @return \think\response\Json
  47. * @author Qinii
  48. */
  49. public function update($id)
  50. {
  51. $data = $this->getParams();
  52. if (!$this->repository->exists((int)$id)) {
  53. return app('json')->fail('数据不存在');
  54. }
  55. $this->repository->updateRule((int)$id, $data);
  56. return app('json')->success('编辑成功');
  57. }
  58. /**
  59. * 添加
  60. * @return \think\response\Json
  61. * @author Qinii
  62. */
  63. public function create()
  64. {
  65. $data = $this->getParams();
  66. $this->repository->createRule($data);
  67. return app('json')->success('添加成功');
  68. }
  69. /**
  70. * 删除
  71. * @param $id
  72. * @return \think\response\Json
  73. * @author Qinii
  74. */
  75. public function delete($id)
  76. {
  77. if (!$this->repository->exists((int)$id)) {
  78. return app('json')->fail('数据不存在');
  79. }
  80. $this->repository->delete((int)$id);
  81. return app('json')->success('删除成功');
  82. }
  83. /**
  84. * 获取参数
  85. * @return array|mixed|string|string[]
  86. * @author Qinii
  87. */
  88. public function getParams()
  89. {
  90. $data = $this->request->params(['rule_name', 'cate_id', 'sort', 'is_show', 'content']);
  91. app()->make(PriceRuleValidate::class)->check($data);
  92. return $data;
  93. }
  94. /**
  95. * 修改状态
  96. * @param $id
  97. * @return \think\response\Json
  98. * @author Qinii
  99. */
  100. public function switchStatus($id)
  101. {
  102. $status = $this->request->param('is_show') == 1 ?: 0;
  103. if (!$this->repository->exists((int)$id))
  104. return app('json')->fail('数据不存在');
  105. $this->repository->update($id, ['is_show' => $status]);
  106. return app('json')->success('修改成功');
  107. }
  108. }