GroupChatAuth.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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\admin\v1\work;
  12. use app\controller\admin\AuthController;
  13. use app\services\work\WorkGroupChatAuthServices;
  14. use app\validate\admin\work\GroupChatAuthValidate;
  15. use EasyWeChat\Kernel\Exceptions\InvalidConfigException;
  16. use GuzzleHttp\Exception\GuzzleException;
  17. use think\db\exception\DataNotFoundException;
  18. use think\db\exception\DbException;
  19. use think\db\exception\ModelNotFoundException;
  20. use think\facade\App;
  21. /**
  22. * 自动拉群
  23. * Class GroupChatAuth
  24. * @package app\controller\admin\v1\work
  25. */
  26. class GroupChatAuth extends AuthController
  27. {
  28. /**
  29. * GroupChatAuth constructor.
  30. * @param App $app
  31. * @param WorkGroupChatAuthServices $services
  32. */
  33. public function __construct(App $app, WorkGroupChatAuthServices $services)
  34. {
  35. parent::__construct($app);
  36. $this->services = $services;
  37. }
  38. /**
  39. * 列表
  40. * @return mixed
  41. * @throws DataNotFoundException
  42. * @throws DbException
  43. * @throws ModelNotFoundException
  44. */
  45. public function index()
  46. {
  47. $where = $this->request->getMore([
  48. ['create_time', ''],
  49. ['name', ''],
  50. ]);
  51. return $this->success($this->services->getList($where));
  52. }
  53. /**
  54. * 保存
  55. * @return mixed
  56. */
  57. public function save()
  58. {
  59. $data = $this->request->postMore([
  60. ['name', ''],
  61. ['auth_group_chat', 0],
  62. ['chat_id', []],
  63. ['group_name', ''],
  64. ['group_num', 0],
  65. ['welcome_words', []],
  66. ['admin_user', []],
  67. ['owner', '']
  68. ]);
  69. validate(GroupChatAuthValidate::class)->check($data);
  70. $this->services->saveGroupChatAuth($data);
  71. return $this->success('添加自动拉群成功');
  72. }
  73. /**
  74. * 更新
  75. * @param $id
  76. * @return mixed
  77. */
  78. public function update($id)
  79. {
  80. $data = $this->request->postMore([
  81. ['name', ''],
  82. ['auth_group_chat', 0],
  83. ['chat_id', []],
  84. ['group_name', ''],
  85. ['group_num', 0],
  86. ['label', []],
  87. ]);
  88. validate(GroupChatAuthValidate::class)->check($data);
  89. $this->services->saveGroupChatAuth($data, (int)$id);
  90. return $this->success('修改自动拉群成功');
  91. }
  92. /**
  93. * 查看详情
  94. * @param $id
  95. * @return mixed
  96. * @throws DataNotFoundException
  97. * @throws DbException
  98. * @throws ModelNotFoundException
  99. */
  100. public function read($id)
  101. {
  102. if (!$id) {
  103. return $this->fail('缺少参数');
  104. }
  105. return $this->success($this->services->getGrouChatAuthInfo((int)$id));
  106. }
  107. /**
  108. * 删除
  109. * @param $id
  110. * @return mixed
  111. * @throws InvalidConfigException
  112. * @throws GuzzleException
  113. * @throws DataNotFoundException
  114. * @throws DbException
  115. * @throws ModelNotFoundException
  116. */
  117. public function delete($id)
  118. {
  119. if (!$id) {
  120. return $this->fail('缺少参数');
  121. }
  122. if ($this->services->deleteGroupChatAuth((int)$id)) {
  123. return $this->success('删除自动拉群成功');
  124. } else {
  125. return $this->fail('删除自动拉群失败');
  126. }
  127. }
  128. }