WechatUserGroupService.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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 crmeb\services;
  12. use EasyWeChat\Support\Collection;
  13. use EasyWeChat\User\Group;
  14. use FormBuilder\Exception\FormBuilderException;
  15. use FormBuilder\Factory\Elm;
  16. use FormBuilder\Form;
  17. use think\facade\Route;
  18. /**
  19. * Class WechatUserGroupService
  20. * @package crmeb\services
  21. * @author xaboy
  22. * @day 2020-04-27
  23. */
  24. class WechatUserGroupService
  25. {
  26. /**
  27. * @var Group
  28. */
  29. protected $userGroup;
  30. /**
  31. * WechatTemplateService constructor.
  32. */
  33. public function __construct()
  34. {
  35. $this->userGroup = WechatService::create()->getApplication()->user_group;
  36. }
  37. /**
  38. * @return Group
  39. * @author xaboy
  40. * @day 2020-04-29
  41. */
  42. public function userGroup()
  43. {
  44. return $this->userGroup;
  45. }
  46. /**
  47. * @return array
  48. * @author xaboy
  49. * @day 2020-04-27
  50. */
  51. public function lst()
  52. {
  53. return $this->userGroup->lists()->toArray();
  54. }
  55. /**
  56. * @param $groupName
  57. * @return Collection
  58. * @author xaboy
  59. * @day 2020-04-27
  60. */
  61. public function create($groupName)
  62. {
  63. return $this->userGroup->create($groupName);
  64. }
  65. /**
  66. * @param $id
  67. * @param $groupName
  68. * @return Collection
  69. * @author xaboy
  70. * @day 2020-04-27
  71. */
  72. public function update($id, $groupName)
  73. {
  74. return $this->userGroup->update($id, $groupName);
  75. }
  76. /**
  77. * @param $id
  78. * @return Collection
  79. * @author xaboy
  80. * @day 2020-04-27
  81. */
  82. public function delete($id)
  83. {
  84. return $this->userGroup->delete($id);
  85. }
  86. /**
  87. * @param null $id
  88. * @param string $name
  89. * @return Form
  90. * @throws FormBuilderException
  91. * @author xaboy
  92. * @day 2020-04-27
  93. */
  94. public function form($id = null, $name = '')
  95. {
  96. return Elm::createForm($id ? Route::buildUrl('updateWechatUserGroup', compact('id'))->build() : Route::buildUrl('createWechatUserGroup')->build(), [
  97. Elm::input('tag_name', '分组名称', $name)->required()
  98. ])->setTitle($id ? '编辑用户分组' : '添加用户分组');
  99. }
  100. }