ProductLabel.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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\product\ProductLabelRepository;
  13. use app\validate\admin\ProductLabelValidate;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. /**
  17. * 商品标签
  18. */
  19. class ProductLabel extends BaseController
  20. {
  21. protected $repository;
  22. public function __construct(App $app, ProductLabelRepository $repository)
  23. {
  24. parent::__construct($app);
  25. $this->repository = $repository;
  26. }
  27. /**
  28. * 列表
  29. * @return \think\response\Json
  30. * @author Qinii
  31. */
  32. public function lst()
  33. {
  34. [$page, $limit] = $this->getPage();
  35. $where = $this->request->params(['name', 'type', ['mer_id', 0], 'status']);
  36. $data = $this->repository->getList($where, $page, $limit);
  37. return app('json')->success($data);
  38. }
  39. /**
  40. * 创建表单
  41. * @return \think\response\Json
  42. * @author Qinii
  43. */
  44. public function createForm()
  45. {
  46. return app('json')->success(formToData($this->repository->form(null, 'systemStoreProductLabelCreate')));
  47. }
  48. /**
  49. * 创建
  50. * @param ProductLabelValidate $validate
  51. * @return \think\response\Json
  52. * @author Qinii
  53. */
  54. public function create(ProductLabelValidate $validate)
  55. {
  56. $data = $this->request->params(['label_name', 'status', 'sort', 'info']);
  57. $validate->check($data);
  58. if (!$this->repository->check($data['label_name'], 0))
  59. return app('json')->fail('名称重复');
  60. $this->repository->create($data);
  61. return app('json')->success('添加成功');
  62. }
  63. /**
  64. * 修改表单
  65. * @param $id
  66. * @return \think\response\Json
  67. * @author Qinii
  68. */
  69. public function updateForm($id)
  70. {
  71. return app('json')->success(formToData($this->repository->updateForm($id, 'systemStoreProductLabelUpdate')));
  72. }
  73. /**
  74. * 修改
  75. * @param $id
  76. * @param ProductLabelValidate $validate
  77. * @return \think\response\Json
  78. * @author Qinii
  79. */
  80. public function update($id, ProductLabelValidate $validate)
  81. {
  82. $data = $this->request->params(['label_name', 'status', 'sort', 'info']);
  83. $validate->check($data);
  84. if (!$this->repository->check($data['label_name'], 0, $id))
  85. return app('json')->fail('名称重复');
  86. $getOne = $this->repository->getWhere(['product_label_id' => $id, 'mer_id' => 0]);
  87. if (!$getOne) return app('json')->fail('数据不存在');
  88. $this->repository->update($id, $data);
  89. return app('json')->success('编辑成功');
  90. }
  91. /**
  92. *
  93. * @param $id
  94. * @return \think\response\Json
  95. * @author Qinii
  96. */
  97. public function detail($id)
  98. {
  99. $getOne = $this->repository->getWhere(['product_label_id' => $id, 'mer_id' => 0, 'is_del' => 0]);
  100. if (!$getOne) return app('json')->fail('数据不存在');
  101. return app('json')->success($getOne);
  102. }
  103. /**
  104. * 删除
  105. * @param $id
  106. * @return \think\response\Json
  107. * @author Qinii
  108. */
  109. public function delete($id)
  110. {
  111. $getOne = $this->repository->getWhere(['product_label_id' => $id, 'mer_id' => 0]);
  112. if (!$getOne) return app('json')->fail('数据不存在');
  113. $this->repository->delete($id);
  114. return app('json')->success('删除成功');
  115. }
  116. /**
  117. * 状态修改
  118. * @param $id
  119. * @return \think\response\Json
  120. * @author Qinii
  121. */
  122. public function switchWithStatus($id)
  123. {
  124. $status = $this->request->param('status') == 1 ? 1 : 0;
  125. $getOne = $this->repository->getWhere(['product_label_id' => $id, 'mer_id' => 0]);
  126. if (!$getOne) return app('json')->fail('数据不存在');
  127. $this->repository->update($id, ['status' => $status]);
  128. return app('json')->success('修改成功');
  129. }
  130. /**
  131. * 获取商品标签
  132. * @return \think\response\Json
  133. * @author Qinii
  134. */
  135. public function getOptions()
  136. {
  137. $data = $this->repository->getOptions(0);
  138. return app('json')->success($data);
  139. }
  140. }