企微短剧业务系统

ChatGroupController.php 32KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/7/27
  6. * Time: 10:34
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Http\Controllers\Controller;
  10. use App\Log;
  11. use App\Service\AndroidToolService;
  12. use App\Service\ChatGroup\ChatGroupMassMsgRuleService;
  13. use App\Service\ChatGroup\ChatGroupRuleService;
  14. use App\Service\ChatGroup\ChatGroupService;
  15. use Illuminate\Http\Request;
  16. use Illuminate\Validation\Rule;
  17. class ChatGroupController extends Controller
  18. {
  19. // 设置客户群群发规则
  20. public function setChatGroupMassMsg(Request $request)
  21. {
  22. $validator = \Validator::make($request->all(),[
  23. 'corpid' => 'required|string',
  24. 'name' => 'required|string',
  25. 'send_type' => ['required', Rule::in([1, 2])],
  26. 'send_mode' => ['required', Rule::in([1, 2])],
  27. 'send_time' => 'required|date_format:Y-m-d H:i:s',
  28. 'content' => ['required_without:attachments', 'nullable'],
  29. 'attachments' => ['required_without:content', 'nullable'],
  30. ]);
  31. if ($validator->fails()) {
  32. return self::returnValue($validator->getMessageBag(), 1102);
  33. }
  34. $params = array();
  35. $ruleId = $request->input('rule_id');
  36. $params['corpid'] = $request->input('corpid');
  37. $params['admin_id'] = $request->input('admin_id');
  38. $params['name'] = $request->input('name');
  39. $params['send_type'] = $request->input('send_type'); // 发送类型 1:立即发送 2:定时发送
  40. $params['send_time'] = $request->input('send_time'); // 发送时间
  41. $params['senders'] = $request->input('senders'); // 群主集合
  42. $params['content'] = $request->input('content'); // 内容
  43. $params['attachments'] = $request->input('attachments'); // 附件
  44. $params['send_mode'] = $request->input('send_mode'); // 发送方式 1按群主 2按群聊
  45. $params['chat_groups'] = $request->input('chat_groups'); // 群聊集合
  46. $params['item_id'] = $request->input('item_id'); // 商品ID
  47. $params['operate_type'] = $request->input('operate_type', 1);# 运营类型 1单主体 2多主体
  48. # 设置群发规则
  49. $errNo = ChatGroupRuleService::setChatGroupMassMsg($ruleId, $params);
  50. return self::returnValue([], $errNo);
  51. }
  52. /**
  53. * 客户群列表
  54. * */
  55. public function groupList(Request $request)
  56. {
  57. $validator = \Validator::make($request->all(),[
  58. 'corpid' => 'required|string',
  59. ]);
  60. if ($validator->fails()) {
  61. return self::returnValue($validator->getMessageBag(), 1102);
  62. }
  63. $corpid = $request->input('corpid');
  64. $owner = $request->input('owner');
  65. $keyword = $request->input('keyword');
  66. $page = $request->input('page', 1);
  67. $pageSize = $request->input('page_size', 20);
  68. if($pageSize == 500) $pageSize = 20000; // 用于数据导出
  69. # 获取群列表
  70. list($list, $count) = ChatGroupRuleService::groupList($corpid, $owner, $keyword, $page, $pageSize);
  71. return self::returnPageValue($list, $count, $pageSize, $page);
  72. }
  73. /**
  74. * 查询所有群聊的去重客户数
  75. * */
  76. public function uniqueMemberCount(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. $count = ChatGroupRuleService::getUniqueMemberCount($corpid);
  86. return self::returnValue(['member_count' => $count]);
  87. }
  88. /**
  89. * 客户群概况
  90. * */
  91. public function condition(Request $request)
  92. {
  93. $validator = \Validator::make($request->all(), [
  94. 'corpid' => 'required|string',
  95. 'chat_id' => 'required|string',
  96. ]);
  97. if ($validator->fails()) {
  98. return self::returnValue($validator->getMessageBag(), 1102);
  99. }
  100. $corpid = $request->input('corpid');
  101. $chatId = $request->input('chat_id');
  102. # 获取群概况
  103. $condition = ChatGroupRuleService::groupCondition($corpid, $chatId);
  104. return self::returnValue($condition);
  105. }
  106. /**
  107. * 客户群成员列表
  108. * */
  109. public function memberList(Request $request)
  110. {
  111. $validator = \Validator::make($request->all(), [
  112. 'corpid' => 'required|string',
  113. 'chat_id' => 'required|string',
  114. ]);
  115. if ($validator->fails()) {
  116. return self::returnValue($validator->getMessageBag(), 1102);
  117. }
  118. $corpid = $request->input('corpid');
  119. $chatId = $request->input('chat_id');
  120. $page = $request->input('page', 1);
  121. $pageSize = $request->input('page_size', 20);
  122. $status = $request->input('status');
  123. $keyword = $request->input('keyword');
  124. $joinTimeStart = $request->input('join_time_start');
  125. $joinTimeEnd = $request->input('join_time_end');
  126. # 获取客户群成员列表
  127. list($list, $count) = ChatGroupRuleService::getMemberList($corpid, $chatId, $status, $keyword, $joinTimeStart
  128. , $joinTimeEnd, $page, $pageSize);
  129. return self::returnPageValue($list, $count, $pageSize, $page);
  130. }
  131. // 群发消息列表
  132. public function ruleLists(Request $request)
  133. {
  134. $validator = \Validator::make($request->all(),[
  135. 'corpid' => 'required|string',
  136. 'send_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  137. 'send_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  138. 'create_time_start' => 'nullable|date_format:Y-m-d H:i:s',
  139. 'create_time_end' => 'nullable|date_format:Y-m-d H:i:s',
  140. ]);
  141. if ($validator->fails()) {
  142. return self::returnValue($validator->getMessageBag(), 1102);
  143. }
  144. $corpid = $request->input('corpid');
  145. $creatorId = $request->input('creator_id');
  146. $sendTimeStart = $request->input('send_time_start');
  147. $sendTimeEnd = $request->input('send_time_end');
  148. $page = $request->input('page', 1);
  149. $pageSize = $request->input('page_size', 20);
  150. $ruleName = $request->input('rule_name');
  151. $createTimeStart = $request->input('create_time_start');
  152. $createTimeEnd = $request->input('create_time_end');
  153. $sortColumn = $request->input('sort_column','send_time');
  154. $sortMethod = $request->input('sort_method','desc');
  155. # 获取群发规则列表
  156. $errno = 0;
  157. list($list, $count) = ChatGroupMassMsgRuleService::ruleList(
  158. $corpid, $creatorId, $sendTimeStart, $sendTimeEnd, $createTimeStart,$createTimeEnd,$sortColumn,$sortMethod,
  159. $page, $pageSize, $errno, $ruleName
  160. );
  161. if($errno) return self::returnValue([], $errno);
  162. return self::returnPageValue($list, $count, $pageSize, $page);
  163. }
  164. /**
  165. * 客户群群发详情
  166. * */
  167. public function ruleDetail(Request $request)
  168. {
  169. $validator = \Validator::make($request->all(),[
  170. 'corpid' => 'required|string',
  171. 'rule_id' => 'required|integer',
  172. ]);
  173. if ($validator->fails()) {
  174. return self::returnValue($validator->getMessageBag(), 1102);
  175. }
  176. $corpid = $request->input('corpid');
  177. $ruleId = $request->input('rule_id');
  178. # 获取群发消息详情
  179. $errno = 0;
  180. $detail = ChatGroupMassMsgRuleService::ruleDetailNew($corpid, $ruleId, $errno);
  181. return self::returnValue($detail, $errno);
  182. }
  183. // 群发规则禁用启用
  184. public function updateStatus(Request $request)
  185. {
  186. $validator = \Validator::make($request->all(),[
  187. 'corpid' => 'required|string',
  188. 'rule_id' => 'required|integer',
  189. 'status' => ['required', Rule::in([0, 1])],
  190. ]);
  191. if ($validator->fails()) {
  192. return self::returnValue($validator->getMessageBag(), 1102);
  193. }
  194. $corpid = $request->input('corpid');
  195. $status = $request->input('status');
  196. $ruleId = $request->input('rule_id');
  197. $errno = ChatGroupMassMsgRuleService::updateRuleStatus($corpid, $ruleId, $status);
  198. return self::returnValue([], $errno);
  199. }
  200. // 给群发消息未发送成员发送消息提醒
  201. public function noticeUser(Request $request)
  202. {
  203. $validator = \Validator::make($request->all(),[
  204. 'corpid' => 'required|string',
  205. 'rule_id' => 'required|integer',
  206. ]);
  207. if ($validator->fails()) {
  208. return self::returnValue($validator->getMessageBag(), 1102);
  209. }
  210. $corpid = $request->input('corpid');
  211. $ruleId = $request->input('rule_id');
  212. $errno = ChatGroupMassMsgRuleService::noticeUser($corpid, $ruleId);
  213. return self::returnValue([], $errno);
  214. }
  215. /**
  216. * 客户群群发详情
  217. * */
  218. public function chatGroupReceiveDetail(Request $request)
  219. {
  220. $validator = \Validator::make($request->all(),[
  221. 'rule_id' => 'required|integer',
  222. ]);
  223. if ($validator->fails()) {
  224. return self::returnValue($validator->getMessageBag(), 1102);
  225. }
  226. $ruleId = $request->input('rule_id');
  227. $chatGroupName = $request->input('chat_group_name');
  228. $senderList = $request->input('sender_list');
  229. $status = $request->input('status');
  230. $page = $request->input('page', 1);
  231. $pageSize = $request->input('page_size', 20);
  232. if($pageSize==500) $pageSize = 10000;
  233. $errno = 0;
  234. list($list, $count) = ChatGroupMassMsgRuleService::chatGroupReceiveDetailNew(
  235. $ruleId, $chatGroupName, $senderList, $status, $errno, $page, $pageSize
  236. );
  237. if($errno){
  238. return self::returnValue([], $errno);
  239. }
  240. return self::returnPageValue($list, $count, $pageSize, $page);
  241. }
  242. public function chatGroupOwnerList(Request $request)
  243. {
  244. $validator = \Validator::make($request->all(),[
  245. 'corpid' => 'required',
  246. 'user_name' => 'nullable|string'
  247. ]);
  248. if ($validator->fails()) {
  249. return self::returnValue($validator->getMessageBag(), 1102);
  250. }
  251. $corpid = $request->input('corpid');
  252. $userName = $request->input('user_name');
  253. $data = ChatGroupService::ownerList($corpid, $userName);
  254. return self::returnValue($data);
  255. }
  256. /**
  257. * 获取账号下各企微的群主列表
  258. * */
  259. public function ownerListOfCompany(Request $request)
  260. {
  261. $validator = \Validator::make($request->all(),[
  262. 'user_name' => 'nullable|string'
  263. ]);
  264. if ($validator->fails()) {
  265. return self::returnValue($validator->getMessageBag(), 1102);
  266. }
  267. $userName = $request->input('user_name');
  268. $sysGroupId = $request->input('sys_group_id');
  269. $data = ChatGroupService::ownerListOfCompany($userName, $sysGroupId);
  270. return self::returnValue($data);
  271. }
  272. /**
  273. * 检索框群列表
  274. * @param Request $request
  275. * @return array
  276. */
  277. public function chatGroupList(Request $request)
  278. {
  279. $validator = \Validator::make($request->all(),[
  280. 'corpid' => 'required',
  281. 'start_time' => 'nullable|date_format:Y-m-d H:i:s',
  282. 'end_time' => 'nullable|date_format:Y-m-d H:i:s',
  283. ]);
  284. if ($validator->fails()) {
  285. return self::returnValue($validator->getMessageBag(), 1102);
  286. }
  287. $corpid = $request->input('corpid');
  288. $keyword = $request->input('keyword');
  289. $startTime = $request->input('start_time');
  290. $endTime = $request->input('end_time');
  291. $owner = $request->input('owner');
  292. $isActive = $request->input('is_active', 0);
  293. $data = ChatGroupService::chatGroupList($corpid, $keyword, $startTime, $endTime, $owner, $isActive);
  294. return self::returnValue($data);
  295. }
  296. /**
  297. * 简单群主列表
  298. * @param Request $request
  299. * @return array
  300. */
  301. public function chatGroupOwnerIndex(Request $request)
  302. {
  303. $validator = \Validator::make($request->all(),[
  304. 'corpid' => 'required',
  305. 'user_name' => 'nullable|string'
  306. ]);
  307. if ($validator->fails()) {
  308. return self::returnValue($validator->getMessageBag(), 1102);
  309. }
  310. $corpid = $request->input('corpid');
  311. $userName = $request->input('user_name');
  312. $data = ChatGroupService::ownerIndex($corpid, $userName);
  313. return self::returnValue($data);
  314. }
  315. /**
  316. * 配置邀请入群规则
  317. * */
  318. public function setInviteRule(Request $request)
  319. {
  320. $validator = \Validator::make($request->all(),[
  321. 'corpid' => 'required|string',
  322. 'title' => 'required|string',
  323. 'invite_config' => 'required|string',
  324. 'is_for_all' => ['required', Rule::in([0, 1])],
  325. ]);
  326. if ($validator->fails()) {
  327. return self::returnValue($validator->getMessageBag(), 1102);
  328. }
  329. $params = array();
  330. $ruleId = $request->input('rule_id');
  331. $params['admin_id'] = $request->input('admin_id', 1);
  332. $params['sys_group_id'] = $request->input('sys_group_id');
  333. $params['corpid'] = $request->input('corpid');
  334. $params['is_for_all'] = $request->input('is_for_all');// 是否通用于全部员工 0:否 1:是
  335. $params['users'] = $request->input('users');// 使用成员,当通用于全部员工是,该字段可为空
  336. $params['title'] = $request->input('title');
  337. $params['join_type'] = $request->input('join_type', 1);// 进群方式 1顺序进群 2随机进群
  338. $params['invite_config'] = $request->input('invite_config');// 渠道群管理
  339. $params['customer_filter'] = $request->input('customer_filter');// 客户筛选 0:全部客户 1:筛选客户
  340. $params['filter_type'] = $request->input('filter_type', 1);// 筛选用户方式 1客户添加N小时后拉群 2按指定添加起止时间筛选
  341. $params['add_time_st'] = $request->input('add_time_st');// 客户添加时间筛选的起始时间
  342. $params['add_time_et'] = $request->input('add_time_et');// 客户添加时间筛选的截止时间
  343. $params['add_time_later'] = $request->input('add_time_later');// 添加客服多久后拉群,单位:小时
  344. $params['invite_type'] = $request->input('invite_type');// 邀请类型。1直接邀请 2定时邀请
  345. $params['invite_time'] = $request->input('invite_time');// 邀请入群时间点
  346. $params['owner_type'] = $request->input('owner_type');// 群主类型 1.本群主群聊 2.指定其他群主群聊
  347. $params['announcement'] = $request->input('announcement');// 群公告
  348. $params['pay_status'] = $request->input('pay_status');// 是否付费
  349. $params['pay_num_min'] = $request->input('pay_num_min');// 最小付费次数
  350. $params['pay_num_max'] = $request->input('pay_num_max');// 最大付费次数
  351. // 标签筛选方式 0未设置标签筛选 1所选标签满足其一 2所选标签全部满足 3无任何标签
  352. $params['tag_screen_type'] = $request->input('tag_screen_type', 0);
  353. $params['tag_list'] = $request->input('tag_list');
  354. $params['gender'] = $request->input('gender');// 客户性别 0未知 1男性 2女性
  355. $params['upper_limit'] = $request->input('upper_limit');// 建群数量上限
  356. $params['continuously_attract_groups'] = $request->input('continuously_attract_groups', 0);// 是否为持续拉取客户入群任务 1是 0否
  357. $params['supplementary_invite_time'] = $request->input('supplementary_invite_time');// 补充邀请入群时间点
  358. $params['supplementary_invite'] = $request->input('supplementary_invite', 0); // 补充邀请入群开启状态 1开启 0关闭
  359. $params['supplementary_invite_cycle'] = $request->input('supplementary_invite_cycle', 1);// 补充邀请入群时间间隔(单位天)
  360. # 设置新用户邀请入群规则
  361. $errNo = ChatGroupService::setInviteRule($ruleId, $params);
  362. Log::logInfo('配置邀请入群规则', [
  363. 'rule_id' => $ruleId, 'params' => $params, 'errno' => $errNo
  364. ], 'setInviteRule');
  365. return self::returnValue([], $errNo);
  366. }
  367. /**
  368. * 邀请入群规则列表
  369. * */
  370. public function inviteRuleList(Request $request)
  371. {
  372. $validator = \Validator::make($request->all(),[
  373. 'corpid' => 'required|string',
  374. ]);
  375. if ($validator->fails()) {
  376. return self::returnValue($validator->getMessageBag(), 1102);
  377. }
  378. $sysGroupId = $request->input('sys_group_id');
  379. $corpid = $request->input('corpid');
  380. $userId = $request->input('user_id');
  381. $status = $request->input('status');
  382. $keyword = $request->input('keyword');
  383. $page = $request->input('page', 1);
  384. $pageSize = $request->input('page_size', 20);
  385. # 获取列表
  386. list($list, $count) = ChatGroupService::getInviteRuleList($corpid, $userId, $sysGroupId, $keyword, $status, $page, $pageSize);
  387. return self::returnPageValue($list, $count, $pageSize, $page);
  388. }
  389. /**
  390. * 邀请入群规则详情
  391. * */
  392. public function inviteRuleDetail(Request $request)
  393. {
  394. $validator = \Validator::make($request->all(),[
  395. 'rule_id' => 'required|integer',
  396. ]);
  397. if ($validator->fails()) {
  398. return self::returnValue($validator->getMessageBag(), 1102);
  399. }
  400. $sysGroupId = $request->input('sys_group_id');
  401. $ruleId = $request->input('rule_id');
  402. # 获取规则详情
  403. $detail = ChatGroupService::inviteRuleDetail($ruleId, $sysGroupId);
  404. return self::returnValue($detail);
  405. }
  406. /**
  407. * 删除邀请入群规则
  408. * */
  409. public function inviteRuleDel(Request $request)
  410. {
  411. $validator = \Validator::make($request->all(),[
  412. 'rule_id' => 'required|integer',
  413. ]);
  414. if ($validator->fails()) {
  415. return self::returnValue($validator->getMessageBag(), 1102);
  416. }
  417. $adminId = $request->input('admin_id');
  418. $sysGroupId = $request->input('sys_group_id');
  419. $ruleId = $request->input('rule_id');
  420. # 删除规则
  421. $errno = ChatGroupService::inviteRuleDel($ruleId, $sysGroupId, $adminId);
  422. return self::returnValue([], $errno);
  423. }
  424. /**
  425. * 修改邀请入群规则状态
  426. * */
  427. public function inviteRuleStatusChange(Request $request)
  428. {
  429. $validator = \Validator::make($request->all(),[
  430. 'corpid' => 'required|string',
  431. 'rule_id' => 'required|integer',
  432. 'status' => ['required', Rule::in([0, 1])],
  433. ]);
  434. if ($validator->fails()) {
  435. return self::returnValue($validator->getMessageBag(), 1102);
  436. }
  437. $adminId = $request->input('admin_id');
  438. $sysGroupId = $request->input('sys_group_id');
  439. $status = $request->input('status');
  440. $ruleId = $request->input('rule_id');
  441. $errno = ChatGroupService::updateRuleStatus($ruleId, $adminId, $status, $sysGroupId);
  442. return self::returnValue([], $errno);
  443. }
  444. public function resetSupplementaryInviteTime(Request $request) {
  445. $validator = \Validator::make($request->all(),[
  446. 'corpid' => 'required|string',
  447. 'rule_id' => 'required|integer',
  448. ]);
  449. if ($validator->fails()) {
  450. return self::returnValue($validator->getMessageBag(), 1102);
  451. }
  452. $adminId = $request->input('admin_id');
  453. $sysGroupId = $request->input('sys_group_id');
  454. $ruleId = $request->input('rule_id');
  455. $errno = ChatGroupService::resetSupplementaryInviteTime($ruleId, $adminId, $sysGroupId);
  456. return self::returnValue([], $errno);
  457. }
  458. /**
  459. * 客户群数据--按客户群统计
  460. * */
  461. public function chatGroupStatistic(Request $request)
  462. {
  463. $sysGroupId = $request->input('sys_group_id');
  464. $keyword = $request->input('keyword');
  465. $corpid = $request->input('corpid');
  466. $owner = $request->input('owner');
  467. $minMember = $request->input('min_member');
  468. $maxMember = $request->input('max_member');
  469. $ownerList = $request->input('owner_list');
  470. $createTimeSt = $request->input('create_time_st');
  471. $createTimeEt = $request->input('create_time_et');
  472. $page = $request->input('page', 1);
  473. $pageSize = $request->input('page_size', 20);
  474. # 数据统计
  475. list($list, $count) = ChatGroupService::chatGroupStatistic(
  476. $sysGroupId, $owner, $ownerList, $keyword, $corpid, $createTimeSt, $createTimeEt,
  477. $minMember, $maxMember, $page, $pageSize
  478. );
  479. return self::returnPageValue($list, $count, $pageSize, $page);
  480. }
  481. /**
  482. * 客户群数据概览--按客户群统计
  483. * */
  484. public function chatGroupCondition(Request $request)
  485. {
  486. $sysGroupId = $request->input('sys_group_id');
  487. $owner = $request->input('owner');
  488. $ownerList = $request->input('owner_list');
  489. $corpid = $request->input('corpid');
  490. $createTimeSt = $request->input('create_time_st');
  491. $createTimeEt = $request->input('create_time_et');
  492. $minMember = $request->input('min_member');
  493. $maxMember = $request->input('max_member');
  494. # 数据汇总
  495. $data = ChatGroupService::chatGroupCondition(
  496. $sysGroupId, $owner, $ownerList, $corpid, $createTimeSt, $createTimeEt, $minMember, $maxMember
  497. );
  498. return self::returnValue($data);
  499. }
  500. public static function syncCorpChatGroup(Request $request) {
  501. $validator = \Validator::make($request->all(),[
  502. 'corpid' => 'required',
  503. ]);
  504. if ($validator->fails()) {
  505. return self::returnValue($validator->getMessageBag(), 1102);
  506. }
  507. $corpid = $request->input('corpid');
  508. list($res, $code) = ChatGroupService::syncCorpChatGroup($corpid);
  509. return self::returnValue($res, $code);
  510. }
  511. # 接收客户端上传的待创建群聊信息
  512. public function receiveCreateChatGroupData(Request $request) {
  513. $validator = \Validator::make($request->all(), [
  514. 'device_id' => 'required|string',
  515. 'corpid' => 'required|string',
  516. 'user_name' => 'required|string',
  517. 'group_list' => 'required'
  518. ]);
  519. if ($validator->fails()) {
  520. return self::returnValue(['error' => $validator->errors()], 1102);
  521. }
  522. $deviceId = $request->input('device_id');
  523. $corpid = $request->input('corpid');
  524. $userName = $request->input('user_name');
  525. $groupList = $request->input('group_list');
  526. list($response, $errcode) = ChatGroupService::receiveCreateChatGroupData($deviceId, $corpid, $userName, $groupList);
  527. Log::logInfo('接收待创建群聊任务', [
  528. 'device_id' => $deviceId,
  529. 'corpid' => $corpid,
  530. 'user_name' => $userName,
  531. 'group_list' => $groupList,
  532. 'response' => $response
  533. ], 'receiveCreateChatGroupData');
  534. return self::returnValue($response, $errcode);
  535. }
  536. public function getCreateGroupTask(Request $request) {
  537. $validator = \Validator::make($request->all(), [
  538. 'device_id' => 'required|string',
  539. ]);
  540. if ($validator->fails()) {
  541. return self::returnValue(['error' => $validator->errors()], 1102);
  542. }
  543. $deviceId = $request->input('device_id');
  544. $taskList = ChatGroupService::getCreateGroupTask($deviceId);
  545. Log::logInfo('创建群聊任务返回', [
  546. 'device_id' => $deviceId,
  547. 'response' => $taskList
  548. ], 'getCreateGroupTask');
  549. return self::returnValue($taskList);
  550. }
  551. # 添加客户群欢迎语素材
  552. public function setWelcomeTemplate(Request $request) {
  553. $validator = \Validator::make($request->all(), [
  554. 'corpid' => 'required|string',
  555. 'name' => 'required|string',
  556. 'content' => ['required_without:attachments', 'nullable'],
  557. 'attachments' => ['required_without:content', 'nullable'],
  558. ]);
  559. if ($validator->fails()) {
  560. return self::returnValue($validator->getMessageBag(), 1102);
  561. }
  562. $params = array();
  563. $params['corpid'] = $request->input('corpid');
  564. $params['admin_id'] = $request->input('admin_id');
  565. $params['sys_group_id'] = $request->input('sys_group_id');
  566. $params['template_id'] = $request->input('template_id');
  567. $params['name'] = $request->input('name');
  568. $params['content'] = $request->input('content');
  569. $params['attachments'] = $request->input('attachments');
  570. $error = 0;
  571. ChatGroupService::setWelcomeTemplate($params, $error);
  572. return self::returnValue('', $error);
  573. }
  574. # 客户群欢迎语素材列表
  575. public function welcomeTemplateList(Request $request) {
  576. $validator = \Validator::make($request->all(), [
  577. 'corpid' => 'required|string',
  578. ]);
  579. if ($validator->fails()) {
  580. return self::returnValue($validator->getMessageBag(), 1102);
  581. }
  582. $corpid = $request->input('corpid');
  583. $sysGroupId = $request->input('sys_group_id');
  584. $keyword = $request->input('keyword');
  585. $creatorId = $request->input('creator_id');
  586. $page = $request->input('page');
  587. $pageSize = $request->input('page_size');
  588. list($list, $count) = ChatGroupService::welcomeTemplateList($corpid, $sysGroupId, $keyword, $creatorId, $page, $pageSize);
  589. return self::returnPageValue($list, $count, $pageSize, $page);
  590. }
  591. # 客户群欢迎语素材详情
  592. public function welcomeTemplateDetail(Request $request) {
  593. $validator = \Validator::make($request->all(), [
  594. 'corpid' => 'required|string',
  595. 'template_id' => 'required',
  596. ]);
  597. if ($validator->fails()) {
  598. return self::returnValue($validator->getMessageBag(), 1102);
  599. }
  600. $corpid = $request->input('corpid');
  601. $sysGroupId = $request->input('sys_group_id');
  602. $templateId = $request->input('template_id');
  603. $data = ChatGroupService::welcomeTemplateDetail($sysGroupId, $corpid, $templateId);
  604. return self::returnValue($data);
  605. }
  606. # 删除客户群欢迎语素材
  607. public function delWelcomeTemplate(Request $request) {
  608. $validator = \Validator::make($request->all(), [
  609. 'corpid' => 'required|string',
  610. 'template_id' => 'required',
  611. ]);
  612. if ($validator->fails()) {
  613. return self::returnValue($validator->getMessageBag(), 1102);
  614. }
  615. $corpid = $request->input('corpid');
  616. $sysGroupId = $request->input('sys_group_id');
  617. $templateId = $request->input('template_id');
  618. $errcode = 0;
  619. ChatGroupService::delWelcomeTemplate($sysGroupId, $corpid, $templateId, $errcode);
  620. return self::returnValue('', $errcode);
  621. }
  622. # 转发客服列表
  623. public function forwardMemberList(Request $request) {
  624. $sysGroupId = $request->input('sys_group_id');
  625. $keyword = $request->input('keyword');
  626. $list = AndroidToolService::getForwardMemberList($sysGroupId, $keyword);
  627. return self::returnValue($list);
  628. }
  629. # 配置创建转发群聊规则
  630. public function setForwardChatGroupCreateRule(Request $request) {
  631. $validator = \Validator::make($request->all(),[
  632. 'title' => 'required|string',
  633. 'template_group_name' => 'required|string',
  634. 'group_num' => 'required',
  635. 'create_type' => 'required'
  636. ]);
  637. if ($validator->fails()) {
  638. return self::returnValue($validator->getMessageBag(), 1102);
  639. }
  640. $params = array();
  641. $ruleId = $request->input('rule_id');
  642. $params['admin_id'] = $request->input('admin_id', 1);
  643. $params['sys_group_id'] = $request->input('sys_group_id');
  644. $params['corpid'] = $request->input('corpid');
  645. $params['is_for_all'] = $request->input('is_for_all');
  646. $params['users'] = $request->input('users');// 使用成员,当通用于全部员工是,该字段可为空
  647. $params['title'] = $request->input('title');// 规则名称
  648. $params['create_type'] = $request->input('create_type');// 邀请类型。1直接邀请 2定时邀请
  649. $params['do_time'] = $request->input('do_time');// 邀请入群时间点
  650. $params['template_group_name'] = $request->input('template_group_name');// 模板群聊名称
  651. $params['group_num'] = $request->input('group_num', 1);// 创建群聊数
  652. $params['forward_users'] = $request->input('forward_users');// 转发客服(系统自增ID列表)
  653. # 设置新用户邀请入群规则
  654. $errNo = ChatGroupService::setForwardChatGroupCreateRule($ruleId, $params);
  655. Log::logInfo('配置转发消息客服入群规则', [
  656. 'rule_id' => $ruleId, 'params' => $params, 'errno' => $errNo
  657. ], 'setForwardChatGroupCreateRule');
  658. return self::returnValue([], $errNo);
  659. }
  660. # 转发群聊创建规则列表
  661. public function forwardChatGroupCreateRuleList(Request $request) {
  662. $validator = \Validator::make($request->all(),[
  663. 'corpid' => 'required|string',
  664. ]);
  665. if ($validator->fails()) {
  666. return self::returnValue($validator->getMessageBag(), 1102);
  667. }
  668. $sysGroupId = $request->input('sys_group_id');
  669. $corpid = $request->input('corpid');
  670. $userId = $request->input('user_id');
  671. $status = $request->input('status');
  672. $keyword = $request->input('keyword');
  673. $page = $request->input('page', 1);
  674. $pageSize = $request->input('page_size', 20);
  675. # 获取列表
  676. list($list, $count) = ChatGroupService::forwardChatGroupCreateRuleList($corpid, $userId, $sysGroupId, $keyword, $status, $page, $pageSize);
  677. return self::returnPageValue($list, $count, $pageSize, $page);
  678. }
  679. # 转发群聊创建规则详情
  680. public function forwardChatGroupCreateRuleDetail(Request $request) {
  681. $validator = \Validator::make($request->all(),[
  682. 'rule_id' => 'required|integer',
  683. ]);
  684. if ($validator->fails()) {
  685. return self::returnValue($validator->getMessageBag(), 1102);
  686. }
  687. $sysGroupId = $request->input('sys_group_id');
  688. $ruleId = $request->input('rule_id');
  689. # 获取规则详情
  690. $detail = ChatGroupService::forwardChatGroupCreateRuleDetail($ruleId);
  691. return self::returnValue($detail);
  692. }
  693. # 转发群聊创建规则状态调整
  694. public function forwardChatGroupCreateRuleChangeStatus(Request $request) {
  695. $validator = \Validator::make($request->all(),[
  696. 'corpid' => 'required|string',
  697. 'rule_id' => 'required|integer',
  698. 'status' => ['required', Rule::in([0, 1])],
  699. ]);
  700. if ($validator->fails()) {
  701. return self::returnValue($validator->getMessageBag(), 1102);
  702. }
  703. $adminId = $request->input('admin_id');
  704. $sysGroupId = $request->input('sys_group_id');
  705. $status = $request->input('status');
  706. $ruleId = $request->input('rule_id');
  707. $errno = ChatGroupService::forwardChatGroupCreateRuleChangeStatus($ruleId, $adminId, $status, $sysGroupId);
  708. return self::returnValue([], $errno);
  709. }
  710. # 转发群里哦啊创建规则删除
  711. public function forwardChatGroupCreateRuleDelete(Request $request) {
  712. $validator = \Validator::make($request->all(),[
  713. 'rule_id' => 'required|integer',
  714. ]);
  715. if ($validator->fails()) {
  716. return self::returnValue($validator->getMessageBag(), 1102);
  717. }
  718. $adminId = $request->input('admin_id');
  719. $sysGroupId = $request->input('sys_group_id');
  720. $ruleId = $request->input('rule_id');
  721. # 删除规则
  722. $errno = ChatGroupService::forwardChatGroupCreateRuleDelete($ruleId, $sysGroupId, $adminId);
  723. return self::returnValue([], $errno);
  724. }
  725. }