ProductLabel.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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\product\ProductLabelRepository;
  13. use app\validate\admin\ProductLabelValidate;
  14. use think\App;
  15. use crmeb\basic\BaseController;
  16. class ProductLabel extends BaseController
  17. {
  18. protected $repository;
  19. public function __construct(App $app, ProductLabelRepository $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(['name', 'type', ['mer_id',0], 'status']);
  28. $data = $this->repository->getList($where,$page, $limit);
  29. return app('json')->success($data);
  30. }
  31. public function createForm()
  32. {
  33. return app('json')->success(formToData($this->repository->form(null, 'systemStoreProductLabelCreate')));
  34. }
  35. public function create(ProductLabelValidate $validate)
  36. {
  37. $data = $this->request->params(['label_name', 'status', 'sort', 'info']);
  38. $validate->check($data);
  39. if (!$this->repository->check($data['label_name'], 0))
  40. return app('json')->fail('名称重复');
  41. $this->repository->create($data);
  42. return app('json')->success('添加成功');
  43. }
  44. public function updateForm($id)
  45. {
  46. return app('json')->success(formToData($this->repository->updateForm($id, 'systemStoreProductLabelUpdate')));
  47. }
  48. public function update($id, ProductLabelValidate $validate)
  49. {
  50. $data = $this->request->params(['label_name', 'status', 'sort', 'info']);
  51. $validate->check($data);
  52. if (!$this->repository->check($data['label_name'], 0,$id))
  53. return app('json')->fail('名称重复');
  54. $getOne = $this->repository->getWhere(['product_label_id' => $id,'mer_id' => 0]);
  55. if (!$getOne) return app('json')->fail('数据不存在');
  56. $this->repository->update($id, $data);
  57. return app('json')->success('编辑成功');
  58. }
  59. public function detail($id)
  60. {
  61. $getOne = $this->repository->getWhere(['product_label_id' => $id,'mer_id' => 0, 'is_del' => 0]);
  62. if (!$getOne) return app('json')->fail('数据不存在');
  63. return app('json')->success($getOne);
  64. }
  65. public function delete($id)
  66. {
  67. $getOne = $this->repository->getWhere(['product_label_id' => $id,'mer_id' => 0]);
  68. if (!$getOne) return app('json')->fail('数据不存在');
  69. $this->repository->update($id,['is_del' => 1]);
  70. return app('json')->success('删除成功');
  71. }
  72. public function switchWithStatus($id)
  73. {
  74. $status = $this->request->param('status') == 1 ? 1 : 0;
  75. $getOne = $this->repository->getWhere(['product_label_id' => $id,'mer_id' => 0]);
  76. if (!$getOne) return app('json')->fail('数据不存在');
  77. $this->repository->update($id,['status' => $status]);
  78. return app('json')->success('修改成功');
  79. }
  80. public function getOptions()
  81. {
  82. $data = $this->repository->getOptions(0);
  83. return app('json')->success($data);
  84. }
  85. }