企微短剧业务系统

GroupChatJoinWayController.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Service\GroupChatJoinWayService;
  4. use Illuminate\Http\Request;
  5. use App\Http\Controllers\Controller;
  6. use Illuminate\Validation\Rule;
  7. class GroupChatJoinWayController extends Controller
  8. {
  9. /**
  10. * 创建群活码
  11. * */
  12. public function setRule(Request $request)
  13. {
  14. $validator = \Validator::make($request->all(), [
  15. 'corpid' => 'required|string',
  16. 'chat_id_list' => 'required|string',
  17. 'name' => 'required|string',
  18. 'group_id' => 'nullable|int',
  19. 'join_type' => ['required', Rule::in([1, 2])],
  20. 'is_limit' => ['required', Rule::in([0, 1])],
  21. ]);
  22. if ($validator->fails()) {
  23. return self::returnValue($validator->getMessageBag(), 1102);
  24. }
  25. $params = [];
  26. $params['corpid'] = $request->input('corpid');
  27. $params['admin_id'] = $request->input('admin_id');
  28. $params['name'] = $request->input('name');
  29. $params['group_id'] = $request->input('group_id');
  30. $params['join_type'] = $request->input('join_type', 2); // 进群方式 1:顺序进群 2:随机进群
  31. $params['is_limit'] = $request->input('is_limit'); // 是否设置加群上限 0:否 1:是
  32. $params['user_list'] = $request->input('user_list'); // 生效成员。当客户点击客服时,会引导客户随机添加一名客服成员的企业微信
  33. $params['leading_words'] = $request->input('leading_words'); // 引导语
  34. $params['chat_id_list'] = json_decode($request->input('chat_id_list'), true); // 客户群ID列表
  35. # 设置群活码规则
  36. $errno = GroupChatJoinWayService::setRule($params);
  37. return self::returnValue([], $errno);
  38. }
  39. /**
  40. * 群活码编辑
  41. * */
  42. public function editRule(Request $request)
  43. {
  44. $validator = \Validator::make($request->all(), [
  45. 'corpid' => 'required|string',
  46. 'config_id' => 'required|string',
  47. 'chat_id_list' => 'required|string',
  48. 'name' => 'required|string',
  49. 'rule_id' => 'required|int',
  50. 'group_id' => 'nullable|int',
  51. 'join_type' => ['required', Rule::in([1, 2])],
  52. 'is_limit' => ['required', Rule::in([0, 1])],
  53. ]);
  54. if ($validator->fails()) {
  55. return self::returnValue($validator->getMessageBag(), 1102);
  56. }
  57. $params = [];
  58. $ruleId = $request->input('rule_id');
  59. $configId = $request->input('config_id');
  60. $params['corpid'] = $request->input('corpid');
  61. $params['admin_id'] = $request->input('admin_id');
  62. $params['name'] = $request->input('name');
  63. $params['group_id'] = $request->input('group_id');
  64. $params['join_type'] = $request->input('join_type', 2); // 进群方式 1:顺序进群 2:随机进群
  65. $params['is_limit'] = $request->input('is_limit'); // 是否设置加群上限 0:否 1:是
  66. $params['user_list'] = $request->input('user_list'); // 生效成员。当客户点击客服时,会引导客户随机添加一名客服成员的企业微信
  67. $params['leading_words'] = $request->input('leading_words'); // 引导语
  68. $params['chat_id_list'] = json_decode($request->input('chat_id_list'), true); // 客户群ID列表
  69. # 设置群活码规则
  70. $errno = GroupChatJoinWayService::editRule($params, $ruleId, $configId);
  71. return self::returnValue([], $errno);
  72. }
  73. /**
  74. * 群活码规则列表
  75. * */
  76. public function ruleList(Request $request)
  77. {
  78. $validator = \Validator::make($request->all(), [
  79. 'corpid' => 'required|string',
  80. ]);
  81. if ($validator->fails()) {
  82. return self::returnValue($validator->getMessageBag(), 1102);
  83. }
  84. $corpid = $request->input('corpid');
  85. $groupId = $request->input('group_id');
  86. $name = $request->input('name');
  87. $page = $request->input('page', 1);
  88. $pageSize = $request->input('page_size', 20);
  89. list($data, $total) = GroupChatJoinWayService::ruleList($corpid, $groupId, $name, $page, $pageSize);
  90. return self::returnPageValue($data, $total, $pageSize, $page);
  91. }
  92. /**
  93. * 群活码详情
  94. * */
  95. public function ruleDetail(Request $request)
  96. {
  97. $validator = \Validator::make($request->all(), [
  98. 'corpid' => 'required|string',
  99. 'rule_id' => 'required|int',
  100. ]);
  101. if ($validator->fails()) {
  102. return self::returnValue($validator->getMessageBag(), 1102);
  103. }
  104. $corpid = $request->input('corpid');
  105. $ruleId = $request->input('rule_id');
  106. # 获取群活码规则详情
  107. $errno = 0;
  108. $detail = GroupChatJoinWayService::ruleDetail($corpid, $ruleId, $errno);
  109. return self::returnValue($detail, $errno);
  110. }
  111. /**
  112. * 群活码禁用
  113. * */
  114. public function delQrcode(Request $request)
  115. {
  116. $validator = \Validator::make($request->all(), [
  117. 'corpid' => 'required|string',
  118. 'rule_id' => 'required|int',
  119. ]);
  120. if ($validator->fails()) {
  121. return self::returnValue($validator->getMessageBag(), 1102);
  122. }
  123. $corpid = $request->input('corpid');
  124. $ruleId = $request->input('rule_id');
  125. # 群活码禁用
  126. $errno = GroupChatJoinWayService::delQrcode($corpid, $ruleId);
  127. return self::returnValue([], $errno);
  128. }
  129. /**
  130. * 群活码总概数据
  131. * */
  132. public function condition(Request $request)
  133. {
  134. $validator = \Validator::make($request->all(), [
  135. 'corpid' => 'required|string',
  136. 'rule_id' => 'required|int',
  137. ]);
  138. if ($validator->fails()) {
  139. return self::returnValue($validator->getMessageBag(), 1102);
  140. }
  141. $corpid = $request->input('corpid');
  142. $ruleId = $request->input('rule_id');
  143. # 获取群活码总概数据
  144. $data = GroupChatJoinWayService::getCondition($corpid, $ruleId);
  145. return self::returnValue($data);
  146. }
  147. /**
  148. * 群活码每日数据分析
  149. * */
  150. public function dailyReport(Request $request)
  151. {
  152. $validator = \Validator::make($request->all(), [
  153. 'corpid' => 'required|string',
  154. 'rule_id' => 'required|int',
  155. 'start_date' => 'required|date_format:Y-m-d',
  156. 'end_date' => 'required|date_format:Y-m-d',
  157. ]);
  158. if ($validator->fails()) {
  159. return self::returnValue($validator->getMessageBag(), 1102);
  160. }
  161. $corpid = $request->input('corpid');
  162. $ruleId = $request->input('rule_id');
  163. $startDate = $request->input('start_date');
  164. $endDate = $request->input('end_date');
  165. # 群活码每日数据分析
  166. $data = GroupChatJoinWayService::getDailyReport($corpid, $ruleId, $startDate, $endDate);
  167. return self::returnValue($data);
  168. }
  169. /**
  170. * 群活码扫码进群客户列表
  171. * */
  172. public function customerList(Request $request)
  173. {
  174. $validator = \Validator::make($request->all(), [
  175. 'corpid' => 'required|string',
  176. 'rule_id' => 'required|int',
  177. ]);
  178. if ($validator->fails()) {
  179. return self::returnValue($validator->getMessageBag(), 1102);
  180. }
  181. $corpid = $request->input('corpid');
  182. $ruleId = $request->input('rule_id');
  183. $keyword = $request->input('keyword');
  184. $page = $request->input('page', 1);
  185. $pageSize = $request->input('page_size', 20);
  186. # 获取群活码扫码进群客户列表
  187. list($list, $count) = GroupChatJoinWayService::getMemberList($corpid, $ruleId, $keyword, $page, $pageSize);
  188. return self::returnPageValue($list, $count, $pageSize, $page);
  189. }
  190. /**
  191. * 群活码配置群的数据分析
  192. * */
  193. public function analysis(Request $request)
  194. {
  195. $validator = \Validator::make($request->all(), [
  196. 'corpid' => 'required|string',
  197. 'rule_id' => 'required|int',
  198. ]);
  199. if ($validator->fails()) {
  200. return self::returnValue($validator->getMessageBag(), 1102);
  201. }
  202. $corpid = $request->input('corpid');
  203. $ruleId = $request->input('rule_id');
  204. # 群活码配置群的数据分析
  205. $data = GroupChatJoinWayService::chatGroupAnalysis($corpid, $ruleId);
  206. return self::returnValue($data);
  207. }
  208. /**
  209. * 扫码数据上报
  210. * */
  211. public function scan(Request $request)
  212. {
  213. $validator = \Validator::make($request->all(), [
  214. 'corpid' => 'required|string',
  215. 'rule_id' => 'required|int',
  216. ]);
  217. if ($validator->fails()) {
  218. return self::returnValue($validator->getMessageBag(), 1102);
  219. }
  220. $corpid = $request->input('corpid');
  221. $ruleId = $request->input('rule_id');
  222. # 增加扫码次数
  223. $errno = GroupChatJoinWayService::scanNumIncr($corpid, $ruleId);
  224. return self::returnValue([], $errno);
  225. }
  226. /**
  227. * 创建临时渠道码
  228. * */
  229. public function contactQrcode(Request $request)
  230. {
  231. $validator = \Validator::make($request->all(), [
  232. 'corpid' => 'required|string',
  233. 'rule_id' => 'required|int',
  234. ]);
  235. if ($validator->fails()) {
  236. return self::returnValue($validator->getMessageBag(), 1102);
  237. }
  238. $corpid = $request->input('corpid');
  239. $ruleId = $request->input('rule_id');
  240. # 生成临时渠道活码
  241. $errno = 0;
  242. $data = GroupChatJoinWayService::createTempContactQrcode($corpid, $ruleId, $errno);
  243. return self::returnValue($data, $errno);
  244. }
  245. /**
  246. * 获取群组下的群活码规则数
  247. * */
  248. public function chatGroupCountOfGroup(Request $request)
  249. {
  250. $validator = \Validator::make($request->all(), [
  251. 'corpid' => 'required|string',
  252. 'group_id' => 'required|int',
  253. ]);
  254. if ($validator->fails()) {
  255. return self::returnValue($validator->getMessageBag(), 1102);
  256. }
  257. $corpid = $request->input('corpid');
  258. $groupId = $request->input('group_id');
  259. $count = GroupChatJoinWayService::chatGroupCountOfGroup($corpid, $groupId);
  260. return self::returnValue(['count' => $count]);
  261. }
  262. /**
  263. * 群活码二维码
  264. * */
  265. public function detail(Request $request)
  266. {
  267. $validator = \Validator::make($request->all(), [
  268. 'corpid' => 'required|string',
  269. 'rule_id' => 'required|int',
  270. ]);
  271. if ($validator->fails()) {
  272. return self::returnValue($validator->getMessageBag(), 1102);
  273. }
  274. $corpid = $request->input('corpid');
  275. $ruleId = $request->input('rule_id');
  276. # 获取群活码规则详情
  277. $errno = 0;
  278. $qrcode = GroupChatJoinWayService::qrcodeDetail($corpid, $ruleId, $errno);
  279. return self::returnValue(['qrcode' => $qrcode], $errno);
  280. }
  281. }