StoreProductLabelCateServices.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2021 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\product\label;
  12. use app\dao\other\CategoryDao;
  13. use app\services\BaseServices;
  14. use crmeb\services\FormBuilder as Form;
  15. use think\facade\Route as Url;
  16. /**
  17. * 商品标签分类
  18. * Class StoreProductLabelCateServices
  19. * @package app\services\product\brand
  20. * @mixin CategoryDao
  21. */
  22. class StoreProductLabelCateServices extends BaseServices
  23. {
  24. /**
  25. * 在分类库中2
  26. */
  27. const GROUP = 2;
  28. /**
  29. * UserLabelCateServices constructor.
  30. * @param CategoryDao $dao
  31. */
  32. public function __construct(CategoryDao $dao)
  33. {
  34. $this->dao = $dao;
  35. }
  36. /**
  37. * 获取标签组列表(带标签)
  38. * @param array $where
  39. * @return array
  40. */
  41. public function getProductLabelCateList(array $where)
  42. {
  43. [$page, $limit] = $this->getPageValue();
  44. $count = $this->dao->count($where);
  45. $list = $this->dao->getCateList($where, $page, $limit, ['*'], ['productLabel']);
  46. if ($list) {
  47. foreach ($list as &$item) {
  48. $item['add_time'] = $item['add_time'] ? date('Y-m-d H:i:s', $item['add_time']) : '';
  49. }
  50. }
  51. return compact('list', 'count');
  52. }
  53. /**
  54. * 获取所有的商品标签分类
  55. * @param int $type
  56. * @param int $relation_id
  57. * @return array
  58. * @throws \think\db\exception\DataNotFoundException
  59. * @throws \think\db\exception\DbException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. */
  62. public function getAllProductLabelCate(int $type = 0, int $relation_id = 0)
  63. {
  64. $where = [
  65. 'type' => $type,
  66. 'relation_id' => $relation_id,
  67. 'group' => self::GROUP
  68. ];
  69. return $this->dao->getAll($where);
  70. }
  71. /**
  72. * 创建新增表单
  73. * @return array
  74. * @throws \FormBuilder\Exception\FormBuilderException
  75. */
  76. public function createForm()
  77. {
  78. return create_form('添加标签组', $this->form(), Url::buildUrl('/product/label_cate'), 'POST');
  79. }
  80. /**
  81. * 创建编辑表单
  82. * @param $id
  83. * @return array
  84. * @throws \FormBuilder\Exception\FormBuilderException
  85. */
  86. public function editForm(int $id)
  87. {
  88. $info = $this->dao->get($id);
  89. return create_form('编辑标签组', $this->form($info), $this->url('/product/label_cate/' . $id), 'PUT');
  90. }
  91. /**
  92. * 生成表单参数
  93. * @param array $info
  94. * @return array
  95. * @throws \FormBuilder\Exception\FormBuilderException
  96. */
  97. public function form($info = [])
  98. {
  99. $f[] = Form::input('name', '标签组名称', $info['name'] ?? '')->maxlength(30)->required();
  100. $f[] = Form::number('sort', '排序', (int)($info['sort'] ?? 0))->min(0)->min(0);
  101. return $f;
  102. }
  103. }