WechatUserGroupService.php 2.1 KB

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