企微短剧业务系统

MomentService.php 26KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Models\AndroidBindCorp;
  5. use App\Models\AndroidToolRequestLog;
  6. use App\Models\AuthorizeCorp;
  7. use App\Models\CustomerDetails;
  8. use App\Models\DjUser;
  9. use App\Models\MomentRecord;
  10. use App\Models\MomentTask;
  11. use App\Models\MomentFansInteract;
  12. use App\Models\Customer;
  13. use App\Models\System\AdminManageCorp;
  14. use App\Models\System\Users;
  15. use App\RedisModel;
  16. use App\Support\EmailQueue;
  17. class MomentService
  18. {
  19. /**
  20. * 设置朋友圈消息规则
  21. * */
  22. public static function setRule($ruleId, $params)
  23. {
  24. try {
  25. if(2 == $params['operate_type']){
  26. if(1 == $params['is_operation']) {
  27. $senders = MassMsgRuleService::getSenderListByOperatorGroupId($params['operator_group_id']);
  28. $params['sender_list'] = '';
  29. } else {
  30. $senders = json_decode($params['multiple_senders'], 1);
  31. $params['sender_list'] = $params['multiple_senders'];
  32. }
  33. $corpIdList = MassMsgRuleService::getCorpIdListBySenders($senders);
  34. $params['corpid'] = implode(',', $corpIdList);
  35. } else {
  36. # 校验附件信息合法性
  37. $attachmentsVerifyCode = MassMsgRuleService::attachmentsVerify($params['attachments'], $params['corpid']);
  38. if($attachmentsVerifyCode) return $attachmentsVerifyCode;
  39. }
  40. if($ruleId){ // 编辑朋友圈规则
  41. $ruleInfo = MomentTask::where('id', $ruleId)->first();
  42. if(!isset($ruleInfo->status) || !in_array($ruleInfo->status, [-2, -1, 1])) { // 判断是否为可编辑的状态
  43. return 2502;
  44. }
  45. unset($params['multiple_senders']);
  46. $result = MomentTask::where('id', $ruleId)->update($params);
  47. } else {
  48. # 设置新群发规则
  49. $momentMsgModel = new MomentTask();
  50. $momentMsgModel->admin_id = $params['admin_id'];
  51. $momentMsgModel->corpid = $params['corpid'];
  52. $momentMsgModel->name = $params['name'];
  53. $momentMsgModel->filter_type = $params['filter_type'];
  54. $momentMsgModel->send_type = $params['send_type'];
  55. $momentMsgModel->send_time = $params['send_time'];
  56. $momentMsgModel->sender_list = $params['sender_list'];
  57. $momentMsgModel->department_list = $params['department_list'];
  58. $momentMsgModel->customer_filter = $params['customer_filter'];
  59. $momentMsgModel->customer_tag_list = $params['customer_tag_list'];
  60. $momentMsgModel->content = $params['content'];
  61. $momentMsgModel->attachments = html_entity_decode($params['attachments']);
  62. $momentMsgModel->operate_type = $params['operate_type'];
  63. $momentMsgModel->operator_group_id = $params['operator_group_id'];
  64. $momentMsgModel->is_operation = $params['is_operation'];
  65. $result = $momentMsgModel->save();
  66. $ruleId = isset($momentMsgModel->id) ? $momentMsgModel->id : '';
  67. }
  68. if(!$result) return 2503;
  69. # 置入队列获取预估可见客户数
  70. if(2 == $params['operate_type']){
  71. RedisModel::lPush(MomentTask::MOMENT_MSG_ESTIMATED_MULTIPLE_CORP_USER_COUNT_RDS, $ruleId);
  72. } else {
  73. RedisModel::lPush(MomentTask::MOMENT_MSG_ESTIMATED_USER_COUNT_RDS, $ruleId);
  74. }
  75. } catch (\Exception $e) {
  76. Log::logError('朋友圈消息设置发生异常', [
  77. 'line' => $e->getLine(),
  78. 'msg' => $e->getMessage(),
  79. 'params' => $params
  80. ], 'SetMomentMsgRule');
  81. return 2501;
  82. }
  83. return 0;
  84. }
  85. /**
  86. * 朋友圈任务列表
  87. * */
  88. public static function taskList($corpid, $creatorId, $filterType, $sendTimeStart, $sendTimeEnd,$createTimeStart,$createTimeEnd,$sortColumn,$sortMethod, $page, $pageSize, &$errno)
  89. {
  90. try {
  91. list($list, $count) = MomentTask::getTaskLists($corpid, $creatorId, $filterType, $sendTimeStart, $sendTimeEnd,$createTimeStart,$createTimeEnd,$sortColumn,$sortMethod, $page, $pageSize);
  92. # 获取创建人信息
  93. $adminIds = $list->pluck('admin_id');
  94. $adminData = Users::select(['id','name'])->whereIn('id', $adminIds)->get();
  95. # 统计发送信息
  96. $ruleIds = $list->pluck('rule_id');
  97. $publishedStatData = MomentRecord::selectRaw("sum(case when publish_status=1 then 1 else 0 end) as published_count,
  98. sum(case when publish_status=0 then 1 else 0 end) as unpublished_count, count(1) as published_total, rule_id")
  99. ->whereIn('rule_id', $ruleIds)->groupBy(['rule_id'])->get();
  100. $errcodeConf = config('qyWechat.errcode');
  101. # 处理数据
  102. foreach($list as $datum) {
  103. # 创建人信息
  104. $adminInfo = $adminData->where('id', $datum->admin_id)->first();
  105. $datum->creator = isset($adminInfo->name) ? $adminInfo->name : '';
  106. # 统计发送情况
  107. $sendStatInfo = $publishedStatData->where('rule_id', $datum->rule_id)->first();
  108. $datum->published_count = isset($sendStatInfo->published_count) ? $sendStatInfo->published_count : 0;
  109. $datum->unpublished_count = isset($sendStatInfo->unpublished_count) ? $sendStatInfo->unpublished_count : 0;
  110. $datum->published_total = isset($sendStatInfo->published_total) ? $sendStatInfo->published_total : 0;
  111. # 附件信息处理
  112. $attachments = json_decode($datum->attachments, true);
  113. if(!empty($attachments)) {
  114. foreach ($attachments as $key=>&$attachment) {
  115. if(isset($attachment['msgtype']) && $attachment['msgtype'] == 'radar') { // 雷达附件信息回显
  116. $radarId = $attachment['radar']['radar_id'] ?? 0;
  117. $radarInfo = RadarService::getRadarContent($corpid, $radarId);
  118. if(empty($radarInfo)) {
  119. unset($attachment[$key]);
  120. continue;
  121. }
  122. $attachment['radar'] = $radarInfo;
  123. }
  124. }
  125. }
  126. $datum->err_msg = $errcodeConf[$datum->err_code] ?? null;
  127. $datum->attachments = json_encode($attachments, 256);
  128. unset($datum->admin_id);
  129. }
  130. } catch(\Exception $e) {
  131. Log::logError('获取朋友圈任务列表发生异常', [
  132. 'line' => $e->getLine(),
  133. 'msg' => $e->getMessage(),
  134. ], 'MomentTaskList');
  135. $errno = 2505;
  136. return [[], 0];
  137. }
  138. return [$list, $count];
  139. }
  140. /**
  141. * 朋友圈消息规则详情
  142. * @param $corpid string 企业ID
  143. * @param $ruleId integer 朋友圈消息规则ID
  144. * */
  145. public static function ruleDetail($corpid, $ruleId, &$errno)
  146. {
  147. try{
  148. $detail = MomentTask::selectRaw('id as rule_id, admin_id, corpid, name, filter_type, send_type, send_time, sender_list, department_list, customer_filter,
  149. content, customer_tag_list, estimated_user, invalid_sender_list, invalid_department_list, invalid_customer_tag_list, err_msg, attachments, status, enable, operate_type, operator_group_id, is_operation')
  150. ->whereRaw("FIND_IN_SET('".$corpid."', `corpid`)")->where('id', $ruleId)
  151. ->first();
  152. if(empty($detail)) return [];
  153. # 获取创建人信息
  154. $detail->creator = Users::where('id', $detail->admin_id)->value('name');
  155. # 附件信息处理
  156. $attachments = json_decode($detail->attachments, true);
  157. if(!empty($attachments)) {
  158. foreach ($attachments as $key=>&$attachment) {
  159. if(isset($attachment['msgtype']) && $attachment['msgtype'] == 'radar') { // 雷达附件信息回显
  160. $radarId = $attachment['radar']['radar_id'] ?? 0;
  161. $radarInfo = RadarService::getRadarContent($corpid, $radarId);
  162. if(empty($radarInfo)) {
  163. unset($attachment[$key]);
  164. continue;
  165. }
  166. $attachment['radar'] = $radarInfo;
  167. }
  168. }
  169. }
  170. $detail->attachments = json_encode($attachments, 256);
  171. # 获取执行朋友圈发送成员信息
  172. $publishUserList = MomentRecord::select(['sender', 'publish_status', 'err_msg', 'err_code'])->where('rule_id', $ruleId)->get();
  173. if($publishUserList->count()) {
  174. $userIds = $publishUserList->pluck('sender');
  175. $userList = DjUser::select('user_id', 'name', 'avatar')->whereIn('user_id', $userIds)->groupBy(['user_id'])->get();
  176. }
  177. foreach ($publishUserList as $publisher) {
  178. $publisherInfo = $userList->where('user_id', $publisher->sender)->first();
  179. $publisher->sender = isset($publisherInfo->name) ? $publisherInfo->name : '';
  180. $publisher->avatar = isset($publisherInfo->avatar) ? $publisherInfo->avatar : '';
  181. }
  182. $detail->published_count = $publishUserList->where('publish_status', 1)->count();
  183. $detail->unpublished_count = $publishUserList->where('publish_status', 0)->count();
  184. $detail->published_total = $publishUserList->count();
  185. $publisherUser = $publishUserList->where('publish_status', 1)->all();
  186. $unpublishedUser = $publishUserList->where('publish_status', 0)->all();
  187. $detail->publish_list = [
  188. 'published_user' => array_values($publisherUser),
  189. 'unpublished_user' => array_values($unpublishedUser)
  190. ];
  191. if($detail->operate_type == 2) {
  192. $detail->multiple_senders = $detail->sender_list;
  193. }
  194. } catch (\Exception $e) {
  195. Log::logError('群发详情获取过程发生异常', [
  196. 'line' => $e->getLine(),
  197. 'msg' => $e->getMessage(),
  198. 'rule_id' => $ruleId
  199. ], 'MomentRuleDetail');
  200. $errno = 2504;
  201. return [];
  202. }
  203. return $detail;
  204. }
  205. /**
  206. * 更新朋友圈消息状态
  207. * */
  208. public static function updateRuleStatus($corpid, $ruleId, $status)
  209. {
  210. # 验证规则是否存在
  211. $isExist = MomentTask::whereRaw('FIND_IN_SET("'.$corpid.'", `corpid`)')->where('id', $ruleId)->exists();
  212. if(!$isExist) return 2506;
  213. # 变更规则状态
  214. $result = MomentTask::where('id', $ruleId)->update(['enable' => $status]);
  215. if(!$result) return 2507;
  216. return 0;
  217. }
  218. /**
  219. * 给朋友圈消息未发送成员发送消息提醒
  220. * */
  221. public static function noticeUser($corpid, $ruleId)
  222. {
  223. try {
  224. # 查询未发送消息的成员user_id
  225. $unpublishedUserList = MomentRecord::select(['sender', 'publish_status', 'err_msg', 'err_code'])->where('rule_id', $ruleId)->whereRaw('FIND_IN_SET("'.$corpid.'", `corpid`)')
  226. ->where('rule_id', $ruleId)->where('publish_status', 0)->pluck('sender')->toArray();
  227. if(empty($unpublishedUserList)) return 2511;
  228. # 发送消息提醒
  229. $responseData = ApplicationMsgService::sendTextMsg($corpid, '请及时确认发送朋友圈消息。', $unpublishedUserList);
  230. if(isset($responseData['errcode']) && $responseData['errcode'] != 0) {
  231. $logData = [
  232. 'corpid' => $corpid,
  233. 'rule_id' => $ruleId,
  234. 'responseData' => $responseData
  235. ];
  236. EmailQueue::rPush('发送朋友圈消息提醒失败', json_encode($logData, JSON_UNESCAPED_UNICODE), ['xiaohua.hou@kuxuan-inc.com'], '发送朋友圈消息提醒失败');
  237. Log::logError('发送朋友圈消息提醒失败', $logData, 'noticeUserFailed');
  238. return 2512;
  239. }
  240. # 记录发送日志
  241. Log::logInfo('发送朋友圈消息提醒日志', [
  242. 'corpid' => $corpid,
  243. 'rule_id' => $ruleId,
  244. 'responseData' => $responseData
  245. ], 'noticeUserLog');
  246. } catch (\Exception $e) {
  247. EmailQueue::rPush('发送朋友圈消息提醒流程发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '发送朋友圈消息提醒流程发生异常');
  248. Log::logInfo('发送朋友圈消息提醒流程发生异常', [
  249. 'corpid' => $corpid,
  250. 'rule_id' => $ruleId,
  251. 'line' => $e->getLine(),
  252. 'msg' => $e->getMessage()
  253. ], 'noticeUserLog-Exception');
  254. return 2514;
  255. }
  256. return 0;
  257. }
  258. /**
  259. * 校验朋友圈消息的附件信息合法性
  260. * */
  261. public static function attachmentsVerify($attachments)
  262. {
  263. if(!is_array($attachments))
  264. $attachments = json_decode($attachments, true);
  265. # 校验是否只有一种附件类型
  266. $msgType = array_unique(array_column($attachments, 'msgtype'));
  267. $msgTypeCount = count($msgType);
  268. if($msgTypeCount > 1) return 2509;
  269. if($msgType == 'image') {
  270. $imgCount = count($attachments);
  271. if($imgCount > 9) return 2510;
  272. } elseif (in_array($msgType, ['link', 'video'])) {
  273. $imgCount = count($attachments);
  274. if($imgCount > 1) return 2513;
  275. }
  276. return 0;
  277. }
  278. /**
  279. * 获取朋友圈消息预计展示的客户数
  280. * */
  281. public static function getCustomerMatchCount($params, &$total)
  282. {
  283. try {
  284. $corpid = $params['corpid'];
  285. # 发送朋友圈成员userid处理
  286. if(!is_array($params['sender_list'])) {
  287. $senders = !empty($params['sender_list']) ? explode(',', $params['sender_list']) : [];
  288. } else {
  289. $senders = $params['sender_list'];
  290. }
  291. # 发送朋友圈部门id换取user_id
  292. $userList = array();
  293. if(!empty($params['department_list'])) {
  294. $departmentList = explode(',', $params['sender_list']);
  295. foreach($departmentList as $dpId) {
  296. $sendersByDepartment = DjUser::whereRaw('find_in_set("' . $dpId . '", `department`)')->where('corpid', $corpid)->pluck('user_id')->toArray();
  297. $userList = array_merge($userList, $sendersByDepartment);
  298. }
  299. }
  300. $senders = array_unique(array_merge($userList, $senders));
  301. $search = array();
  302. $customerFilter = $params['customer_filter'];
  303. if($customerFilter){
  304. $tagList = $params['customer_tag_list']; // 0全部客户 1筛选客户
  305. if(!empty($tagList)) {
  306. $search['tag_screen_type'] = 1;
  307. $search['tag_list'] = explode(',', $tagList);
  308. }
  309. }
  310. if(!empty($senders)) {
  311. $search['user_ids'] = $senders;
  312. }
  313. $total = CustomerDetails::getCustomerMatchCount($corpid, $search);
  314. } catch (\Exception $e) {
  315. Log::logError('获取朋友圈展示预估展示人数过程发生异常', [
  316. 'line' => $e->getLine(),
  317. 'msg' => $e->getMessage()
  318. ], 'MomentGetCustomerTotal-Exception');
  319. $total = 0;
  320. }
  321. return 0;
  322. }
  323. public static function getMultipleCorpCustomerMatchCount($params, &$total)
  324. {
  325. try {
  326. $data = $params;
  327. if(1 == $params['is_operation']) {
  328. $senders = MassMsgRuleService::getSenderListByOperatorGroupId($params['operator_group_id']);//从运营组中查询客服以及企微信息
  329. } else {
  330. $senders = json_decode($params['multiple_senders'], 1);
  331. }
  332. foreach ($senders as $item) {
  333. $singleTotal = 0;
  334. $data['corpid'] = $item['corpid'];
  335. $data['sender_list'] = implode(',', $item['user_list']);
  336. self::getCustomerMatchCount($data, $singleTotal);
  337. $total += $singleTotal;
  338. }
  339. } catch (\Exception $e) {
  340. Log::logError('多企微获取群发条件匹配的外部联系人数过程发生异常', [
  341. 'params' => $params,
  342. 'line' => $e->getLine(),
  343. 'msg' => $e->getMessage()
  344. ], 'GetMultipleCorpCustomer-Exception');
  345. EmailQueue::rPush('多企微获取朋友圈匹配的外部联系人数过程发生异常', $e->getTraceAsString(), ['xiaohua.hou@kuxuan-inc.com'], '猎羽');
  346. }
  347. return 0;
  348. }
  349. /**
  350. * 创建朋友圈任务
  351. * @param string $corpid 企业id
  352. * @param string $content 文本内容
  353. * @param array $attachments 附件内容
  354. * @param array $visibleRange 指定的发表范围
  355. * */
  356. public static function momentMsgTaskCreate($corpid, $content, $attachments, $visibleRange=null)
  357. {
  358. # 获取AccessToken
  359. $accessToken = AuthorizeCorp::getAccessToken($corpid);
  360. if(empty($accessToken)) {
  361. return false;
  362. }
  363. $postData = [
  364. 'text' => [
  365. 'content' => $content
  366. ],
  367. 'attachments' => $attachments
  368. ];
  369. if(!empty($visibleRange)) { // 指定了发表范围
  370. $postData['visible_range'] = $visibleRange;
  371. }
  372. $requestUri = config('qyWechat.add_moment_task');
  373. $requestUri .= $accessToken;
  374. $response = HttpService::httpPost($requestUri, json_encode($postData));
  375. $responseData = json_decode($response, true);
  376. Log::logInfo('【'.$corpid.'】朋友圈创建响应日志:', [
  377. 'corpid' => $corpid,
  378. 'postData' => $postData,
  379. 'responseData' => $responseData
  380. ], 'MomentMsgTaskCreateLog');
  381. return $responseData;
  382. }
  383. /**
  384. * 朋友圈点赞评论数据统计
  385. */
  386. public static function momentInteract($corpid, $moment_id, $userid)
  387. {
  388. $res = [
  389. 'like_total' => 0,
  390. 'comment_total' => 0,
  391. 'like_users' => null,
  392. 'comment_users' => null
  393. ];
  394. $list = MomentFansInteract::select('external_userid', 'create_time', 'interact_type')
  395. ->where('corpid', $corpid)
  396. ->where('moment_id', $moment_id)
  397. ->where('sender', $userid)
  398. ->orderBy('create_time', 'desc')
  399. ->get();
  400. if($list->isEmpty()){
  401. return $res;
  402. }
  403. //获取客户头像信息
  404. $external_userids = $list->pluck('external_userid')->all();
  405. $cust_info = Customer::suffix($corpid)->select('external_userid', 'name', 'avatar')
  406. ->whereIn('external_userid', $external_userids)
  407. ->get()
  408. ->keyBy('external_userid')
  409. ->toArray();
  410. foreach($list as $v){
  411. if($v->interact_type == 1){
  412. $res['like_total']++;
  413. if( isset($cust_info[$v->external_userid]) ){
  414. $res['like_users'][] = $cust_info[$v->external_userid];
  415. }
  416. } else {
  417. $res['comment_total']++;
  418. if( isset($cust_info[$v->external_userid]) ){
  419. $res['comment_users'][$v->external_userid] = $cust_info[$v->external_userid];
  420. }
  421. }
  422. }
  423. $res['comment_users'] = !empty($res['comment_users']) ? array_values($res['comment_users']) : null;
  424. return $res;
  425. }
  426. /**
  427. * 朋友圈发送记录列表
  428. * @param $corpid string 企微id
  429. * @param $userIdList array 员工id数组
  430. * @param $sendTimeStart string 起始发布时间
  431. * @param $sendTimeEnd string 截止发布时间
  432. * @param $page int 页码
  433. * @param $pageSize int 每页数据
  434. * @param $errno int
  435. * @return mixed
  436. */
  437. public static function momentRecordList(
  438. $corpid, $userIdList, $sendTimeStart, $sendTimeEnd, $page, $pageSize, &$errno
  439. )
  440. {
  441. $requestData = [
  442. 'corpid' => $corpid,
  443. 'user_id_list' => $userIdList,
  444. 'send_time_start' => $sendTimeStart,
  445. 'send_time_end' => $sendTimeEnd,
  446. 'page' => $page,
  447. 'page_size' => $pageSize
  448. ];
  449. try {
  450. list($list, $count) = MomentRecord::recordLists($corpid, $userIdList, $sendTimeStart, $sendTimeEnd, $page, $pageSize);
  451. $listArr = $list->toArray();
  452. // 提取朋友圈规则id列表
  453. $ruleIdList = array_unique(array_column($listArr, 'rule_id'));
  454. // 提取发布成员列表
  455. $senderList = array_unique(array_column($listArr, 'sender'));
  456. // 获取朋友圈规则信息
  457. $momentTaskList = MomentTask::query()
  458. ->whereIn('id', $ruleIdList)
  459. ->get();
  460. // 获取发布成员信息
  461. $senderDataList = DjUser::query()
  462. ->where('corpid', $corpid)
  463. ->whereIn('user_id', $senderList)
  464. ->get();
  465. # 处理数据
  466. foreach($list as $datum) {
  467. $momentTask = $momentTaskList->where('id', $datum->rule_id)->first();
  468. if(empty($momentTask)) {
  469. $datum->filter_type = null;
  470. $datum->content = null;
  471. $datum->attachments = null;
  472. } else {
  473. $datum->filter_type = $momentTask->filter_type;
  474. $datum->content = $momentTask->content;
  475. # 附件信息处理
  476. $attachments = json_decode($momentTask->attachments, true);
  477. if(!empty($attachments)) {
  478. foreach ($attachments as $key=>&$attachment) {
  479. if(isset($attachment['msgtype']) && $attachment['msgtype'] == 'radar') { // 雷达附件信息回显
  480. $radarId = $attachment['radar']['radar_id'] ?? 0;
  481. $radarInfo = RadarService::getRadarContent($corpid, $radarId);
  482. if(empty($radarInfo)) {
  483. unset($attachment[$key]);
  484. continue;
  485. }
  486. $attachment['radar'] = $radarInfo;
  487. }
  488. }
  489. }
  490. $datum->attachments = json_encode($attachments, 256);
  491. }
  492. $sender = $senderDataList->where('user_id', $datum->sender)->first();
  493. if(empty($sender)) {
  494. $datum->sender_avatar = null;
  495. $datum->sender_name = null;
  496. } else {
  497. $datum->sender_avatar = $sender->avatar;
  498. $datum->sender_name = $sender->name;
  499. }
  500. }
  501. } catch(\Exception $e) {
  502. Log::logError('获取朋友圈发布记录列表发生异常 请求参数:'.json_encode($requestData, 256), [
  503. 'line' => $e->getLine(),
  504. 'msg' => $e->getMessage(),
  505. ], 'momentRecordList');
  506. $errno = 2508;
  507. return [[], 0];
  508. }
  509. return [$list, $count];
  510. }
  511. /**
  512. * 判断是否为雷达朋友圈
  513. * @param array $attachments 朋友圈附件
  514. * */
  515. public static function isRadarMoment($attachments)
  516. {
  517. Log::logInfo('检验朋友圈消息是否为雷达类', [
  518. 'attachments' => $attachments
  519. ], 'IsRadarMoment');
  520. $isRadar = false;
  521. foreach ($attachments as $attachment) {
  522. if(isset($attachment['msgtype']) && $attachment['msgtype'] == 'radar') {
  523. Log::logInfo('此朋友圈消息为雷达类', [
  524. 'attachments' => $attachments
  525. ], 'IsRadarMoment');
  526. $isRadar = true;
  527. }
  528. }
  529. return $isRadar;
  530. }
  531. /**
  532. * 获取待确认发送的消息列表
  533. * */
  534. public static function senderConfirmList($deviceId)
  535. {
  536. # 查询支持无障碍模式的企微列表
  537. $corpidList = AndroidBindCorp::getcorpList($deviceId);
  538. $corpidList = json_decode(json_encode($corpidList), 1);
  539. # 查询待发送群发消息记录
  540. $msgList = MomentRecord::select('corpid')->where('show_total', 0)
  541. ->whereIn('corpid', $corpidList)
  542. ->where('created_at', '>=', date('Y-m-d H:i:s', strtotime('-60 minutes')))
  543. ->groupBy(['corpid'])
  544. ->get();
  545. $corpList = AuthorizeCorp::select('corpid', 'corp_name')->where('enable', 1)->get();
  546. // $userIdList = $msgList->pluck('sender');
  547. // $userList = DjUser::select('corpid', 'user_id', 'name')->whereIn('user_id', $userIdList)->get();
  548. foreach ($msgList as $item) {
  549. # 获取企微名称
  550. $corpInfo = $corpList->where('corpid', $item->corpid)->first();
  551. $item->companyName = $corpInfo->corp_name;
  552. # 获取客服名
  553. // $userInfo = $userList->where('user_id', $item->sender)->where('corpid', $item->corpid)->first();
  554. // $item->userName = $userInfo->name;
  555. }
  556. Log::logInfo('设备请求朋友圈日志', [
  557. 'type' => 3,
  558. 'device_id' => $deviceId,
  559. 'msg_list' => $msgList->toArray(),
  560. ], 'SenderConfirmList');
  561. return $msgList;
  562. }
  563. }