StoreBrand.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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\supplier\product;
  12. use app\controller\supplier\AuthController;
  13. use app\services\product\brand\StoreBrandServices;
  14. use think\facade\App;
  15. /**
  16. * 商品品牌控制器
  17. * Class StoreBrand
  18. * @package app\controller\supplier\product
  19. */
  20. class StoreBrand extends AuthController
  21. {
  22. /**
  23. * @var StoreBrandServices
  24. */
  25. protected $service;
  26. /**
  27. * StoreCategory constructor.
  28. * @param App $app
  29. * @param StoreBrandServices $service
  30. */
  31. public function __construct(App $app, StoreBrandServices $service)
  32. {
  33. parent::__construct($app);
  34. $this->service = $service;
  35. }
  36. /**
  37. * 品牌列表
  38. * @return mixed
  39. * @throws \think\db\exception\DataNotFoundException
  40. * @throws \think\db\exception\DbException
  41. * @throws \think\db\exception\ModelNotFoundException
  42. */
  43. public function index()
  44. {
  45. $where = $this->request->getMore([
  46. ['brand_name', ''],
  47. ['pid', 0]
  48. ]);
  49. $where['is_del'] = 0;
  50. $data = $this->service->getList($where);
  51. return $this->success($data);
  52. }
  53. /**
  54. * 获取品牌cascader格式数据
  55. * @param $type
  56. * @return mixed
  57. * @throws \think\db\exception\DataNotFoundException
  58. * @throws \think\db\exception\DbException
  59. * @throws \think\db\exception\ModelNotFoundException
  60. */
  61. public function cascader_list($type = 1)
  62. {
  63. return $this->success($this->service->cascaderList($type));
  64. }
  65. /**
  66. * 修改状态
  67. * @param string $is_show
  68. * @param string $id
  69. */
  70. public function set_show($is_show = '', $id = '')
  71. {
  72. if ($is_show == '' || $id == '') return $this->fail('缺少参数');
  73. $this->service->setShow($id, $is_show);
  74. return $this->success($is_show == 1 ? '显示成功' : '隐藏成功');
  75. }
  76. /**
  77. * 保存新增品牌
  78. * @return mixed
  79. */
  80. public function save()
  81. {
  82. $data = $this->request->postMore([
  83. ['fid', []],
  84. ['brand_name', ''],
  85. ['sort', 0],
  86. ['is_show', 0]
  87. ]);
  88. if (!$data['brand_name']) {
  89. return $this->fail('请输入品牌名称');
  90. }
  91. if (iconv_strlen($data['brand_name'], 'UTF-8') > 10) {
  92. return $this->fail('品牌名称过长');
  93. }
  94. $this->service->createData($data);
  95. return $this->success('添加品牌成功!');
  96. }
  97. /**
  98. * 更新品牌
  99. * @param $id
  100. * @return mixed
  101. */
  102. public function update($id)
  103. {
  104. $data = $this->request->postMore([
  105. ['fid', []],
  106. ['brand_name', ''],
  107. ['sort', 0],
  108. ['is_show', 0]
  109. ]);
  110. if (!$data['brand_name']) {
  111. return $this->fail('请输入品牌名称');
  112. }
  113. if (iconv_strlen($data['brand_name'], 'UTF-8') > 10) {
  114. return $this->fail('品牌名称过长');
  115. }
  116. $this->service->editData($id, $data);
  117. return $this->success('修改成功!');
  118. }
  119. /**
  120. * 删除品牌
  121. * @param $id
  122. * @return mixed
  123. */
  124. public function delete($id)
  125. {
  126. $this->service->del((int)$id);
  127. return $this->success('删除成功!');
  128. }
  129. }