WorkChannelCategoryServices.php 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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\services\work;
  12. use app\services\other\CategoryServices;
  13. use crmeb\services\FormBuilder;
  14. use think\exception\ValidateException;
  15. /**
  16. * 渠道码分类
  17. * Class WorkChannelCategoryServices
  18. * @package app\services\work
  19. */
  20. class WorkChannelCategoryServices extends CategoryServices
  21. {
  22. const TYPE = 4;
  23. /**
  24. * @param array $where
  25. * @param array|string[] $field
  26. * @return array
  27. * @throws \think\db\exception\DataNotFoundException
  28. * @throws \think\db\exception\DbException
  29. * @throws \think\db\exception\ModelNotFoundException
  30. */
  31. public function getCateList(array $where = [], array $field = ['*'], array $with = [])
  32. {
  33. $where['group'] = self::TYPE;
  34. $where['owner_id'] = 0;
  35. return parent::getCateList($where, $field, $with);
  36. }
  37. /**
  38. * 获取标签全部分类
  39. * @param int $group
  40. * @param int $storeId
  41. * @return mixed
  42. */
  43. public function getCateAll(int $group = self::TYPE, int $storeId = 0)
  44. {
  45. return $this->dao->getCateList(['type' => 0, 'owner_id' => 0, 'relation_id' => $storeId, 'group' => $group]);
  46. }
  47. /**
  48. * 标签分类表单
  49. * @param array $cataData
  50. * @return mixed
  51. */
  52. public function cateForm(array $cataData = [])
  53. {
  54. $f[] = FormBuilder::input('name', '分类名称', $cataData['name'] ?? '')->maxlength(20)->required();
  55. $f[] = FormBuilder::number('sort', '排序', (int)($cataData['sort'] ?? 0))->min(0);
  56. return $f;
  57. }
  58. /**
  59. * 创建表单
  60. * @return array
  61. * @throws \FormBuilder\Exception\FormBuilderException
  62. */
  63. public function createForm()
  64. {
  65. return create_form('添加渠道二维码分类', $this->cateForm(), $this->url('/work/channel/cate'), 'POST');
  66. }
  67. /**
  68. * 修改分类标签表单
  69. * @param int $id
  70. * @return array
  71. * @throws \FormBuilder\Exception\FormBuilderException
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. */
  76. public function updateForm(int $id)
  77. {
  78. $cate = $this->dao->get($id);
  79. if (!$cate) {
  80. throw new ValidateException('渠道二维码分类没有查到');
  81. }
  82. return create_form('编辑渠道二维码分类', $this->cateForm($cate->toArray()), $this->url('work/channel/cate/' . $id), 'PUT');
  83. }
  84. }