StoreAttrTemplate.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  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\merchant\store;
  12. use crmeb\basic\BaseController;
  13. use app\common\repositories\store\StoreAttrTemplateRepository;
  14. use app\validate\merchant\StoreAttrTemplateValidate;
  15. use think\App;
  16. use think\db\exception\DataNotFoundException;
  17. use think\db\exception\DbException;
  18. use think\db\exception\ModelNotFoundException;
  19. /**
  20. * Class StoreAttrTemplate
  21. * @package app\controller\merchant\store
  22. * @author xaboy
  23. * @day 2020-05-06
  24. */
  25. class StoreAttrTemplate extends BaseController
  26. {
  27. /**
  28. * @var StoreAttrTemplateRepository
  29. */
  30. protected $repository;
  31. /**
  32. * StoreAttrTemplate constructor.
  33. * @param App $app
  34. * @param StoreAttrTemplateRepository $repository
  35. */
  36. public function __construct(App $app, StoreAttrTemplateRepository $repository)
  37. {
  38. parent::__construct($app);
  39. $this->repository = $repository;
  40. }
  41. /**
  42. * @return mixed
  43. * @throws DbException
  44. * @throws DataNotFoundException
  45. * @throws ModelNotFoundException
  46. * @author xaboy
  47. * @day 2020-05-06
  48. */
  49. public function lst()
  50. {
  51. [$page, $limit] = $this->getPage();
  52. $data = $this->repository->getList($this->request->merId(), [], $page, $limit);
  53. return app('json')->success($data);
  54. }
  55. public function getlist()
  56. {
  57. return app('json')->success($this->repository->list($this->request->merId()));
  58. }
  59. /**
  60. * @param StoreAttrTemplateValidate $validate
  61. * @return mixed
  62. * @author xaboy
  63. * @day 2020-05-06
  64. */
  65. public function create(StoreAttrTemplateValidate $validate)
  66. {
  67. $data = $this->checkParams($validate);
  68. $data['mer_id'] = $this->request->merId();
  69. $this->repository->create($data);
  70. return app('json')->success('添加成功');
  71. }
  72. /**
  73. * @param $id
  74. * @param StoreAttrTemplateValidate $validate
  75. * @return mixed
  76. * @throws DbException
  77. * @author xaboy
  78. * @day 2020-05-06
  79. */
  80. public function update($id, StoreAttrTemplateValidate $validate)
  81. {
  82. $merId = $this->request->merId();
  83. if (!$this->repository->merExists($merId, $id))
  84. return app('json')->fail('数据不存在');
  85. $data = $this->checkParams($validate);
  86. $data['mer_id'] = $merId;
  87. $this->repository->update($id, $data);
  88. return app('json')->success('编辑成功');
  89. }
  90. /**
  91. * @param $id
  92. * @return mixed
  93. * @throws DbException
  94. * @author xaboy
  95. * @day 2020-05-06
  96. */
  97. public function delete($id)
  98. {
  99. $merId = $this->request->merId();
  100. if (!$this->repository->merExists($merId, $id))
  101. return app('json')->fail('数据不存在');
  102. $this->repository->delete($id, $merId);
  103. return app('json')->success('删除成功');
  104. }
  105. /**
  106. * @param StoreAttrTemplateValidate $validate
  107. * @return array
  108. * @author xaboy
  109. * @day 2020-05-06
  110. */
  111. public function checkParams(StoreAttrTemplateValidate $validate)
  112. {
  113. $data = $this->request->params(['template_name', ['template_value', []]]);
  114. $validate->check($data);
  115. return $data;
  116. }
  117. }