GuaranteeTemplate.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. <?php
  2. namespace app\controller\merchant\store\guarantee;
  3. use app\common\repositories\store\GuaranteeRepository;
  4. use app\common\repositories\store\GuaranteeTemplateRepository;
  5. use app\validate\admin\GuaranteeTemplateValidate;
  6. use think\App;
  7. use ln\basic\BaseController;
  8. class GuaranteeTemplate extends BaseController
  9. {
  10. /**
  11. * @var GuaranteeTemplateRepository
  12. */
  13. protected $repository;
  14. /**
  15. * Product constructor.
  16. * @param App $app
  17. * @param GuaranteeTemplateRepository $repository
  18. */
  19. public function __construct(App $app, GuaranteeTemplateRepository $repository)
  20. {
  21. parent::__construct($app);
  22. $this->repository = $repository;
  23. }
  24. public function lst()
  25. {
  26. [$page, $limit] = $this->getPage();
  27. $where = $this->request->params(['date','keyword']);
  28. $where['is_del'] = 0;
  29. $where['mer_id'] = $this->request->merId();
  30. $data = $this->repository->getList($where,$page, $limit);
  31. return app('json')->success($data);
  32. }
  33. public function create(GuaranteeTemplateValidate $validate)
  34. {
  35. $data = $this->request->params(['template_name','template_value',['status',1],'sort']);
  36. $validate->check($data);
  37. $data['mer_id'] = $this->request->merId();
  38. $this->repository->create($data);
  39. return app('json')->success('添加成功');
  40. }
  41. public function detail($id)
  42. {
  43. $ret = $this->repository->detail($id,$this->request->merId());
  44. return app('json')->success($ret);
  45. }
  46. public function update($id,GuaranteeTemplateValidate $validate)
  47. {
  48. $data = $this->request->params(['template_name','template_value',['status',1],'sort']);
  49. $validate->check($data);
  50. $this->repository->detail($id,$this->request->merId());
  51. $data['mer_id'] = $this->request->merId();
  52. $this->repository->edit($id,$data);
  53. return app('json')->success('编辑成功');
  54. }
  55. public function delete($id)
  56. {
  57. $this->repository->detail($id,$this->request->merId());
  58. $this->repository->delete($id);
  59. return app('json')->success('删除成功');
  60. }
  61. /**
  62. * TODO 添加模板筛选的条款数据
  63. * @return \think\response\Json
  64. * @author Qinii
  65. * @day 5/25/21
  66. */
  67. public function select()
  68. {
  69. $where['keyword'] = $this->request->param('keyword');
  70. $where['is_del'] = 0;
  71. $where['status'] = 1;
  72. $data = app()->make(GuaranteeRepository::class)->select($where);
  73. return app('json')->success($data);
  74. }
  75. public function sort($id)
  76. {
  77. $ret = $this->repository->detail($id,$this->request->merId());
  78. if(!$ret) return app('json')->fail('数据不存在');
  79. $data = [
  80. 'sort' => $this->request->param('sort'),
  81. ];
  82. $this->repository->update($id,$data);
  83. return app('json')->success('修改成功');
  84. }
  85. /**
  86. * TODO 商品选择模板的下拉数据
  87. * @return \think\response\Json
  88. * @author Qinii
  89. * @day 5/25/21
  90. */
  91. public function list()
  92. {
  93. $data = $this->repository->list($this->request->merId());
  94. return app('json')->success($data);
  95. }
  96. public function switchStatus($id)
  97. {
  98. $ret = $this->repository->detail($id,$this->request->merId());
  99. if(!$ret) return app('json')->fail('数据不存在');
  100. $data = [
  101. 'status' => $this->request->param('status') == 1 ?: 0,
  102. ];
  103. $this->repository->update($id,$data);
  104. return app('json')->success('修改成功');
  105. }
  106. }