企微短剧业务系统

WarnService.php 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664
  1. <?php
  2. namespace App\Service;
  3. use App\Log;
  4. use App\Models\AuthorizeCorp;
  5. use App\Models\CorpUserScaleWarningConf;
  6. use App\Models\DjUser;
  7. use App\Models\System\AdminManageCorp;
  8. use App\Models\System\Users;
  9. use App\Models\WarnGroup;
  10. use App\Models\WarnGroupDjuser;
  11. use App\Models\WarnGroupUser;
  12. use App\Models\WarnRule;
  13. use App\Models\WarnRuleConf;
  14. use App\Models\WarnUser;
  15. use App\RedisModel;
  16. use Illuminate\Support\Facades\Auth;
  17. class WarnService
  18. {
  19. public static function groupList($sysGroupId, $keyword, $page, $pageSize, $isSelect = 0)
  20. {
  21. // 获取系统分组id
  22. self::getSysGroupId($sysGroupId);
  23. $query = WarnGroup::query()
  24. ->select(['id', 'name', 'enable'])
  25. ->where('sys_group_id', $sysGroupId)
  26. ->where(function ($query) use ($keyword) {
  27. if (!empty($keyword)) $query->where('name', 'like', '%'.$keyword.'%');
  28. });
  29. $total = $query->count();
  30. if ($total == 0) return [[], 0];
  31. if(1 == $isSelect){
  32. $groupList = $query->where('enable', 1)
  33. ->orderByDesc('created_at')
  34. ->get();
  35. } else {
  36. $groupList = $query
  37. ->orderByDesc('created_at')
  38. ->offset(($page - 1) * $pageSize)
  39. ->limit($pageSize)
  40. ->get();
  41. $groupIds = $groupList->pluck('id')->all();
  42. // 获取预警人员
  43. $groupUserArr = WarnGroupUser::getUserList($groupIds);
  44. // 获取客服信息
  45. $groupDjuserArr = WarnGroupDjuser::getDjserList($groupIds);
  46. foreach ($groupList as $groupInfo) {
  47. $groupInfo->user_list = $groupUserArr[$groupInfo->id] ?? [];
  48. $groupInfo->djuser_list = $groupDjuserArr[$groupInfo->id] ?? [];
  49. }
  50. }
  51. return [$groupList, $total];
  52. }
  53. public static function groupOperate($sysGroupId, $groupName, $userList, $djuserList, $groupId = null)
  54. {
  55. // 检测预警组名称
  56. if (empty($groupName)) return [false, 3201];
  57. // 检测预警用户是否是json
  58. $userArr = json_decode($userList, true);
  59. if (!is_array($userArr)) return [false, 3202];
  60. // 检测预警用户数据
  61. $userArr = array_unique($userArr);
  62. $traUserCount = count($userArr);
  63. $hasUserCount = WarnUser::query()
  64. ->whereIn('id', $userArr)
  65. ->where('enable', 1)
  66. ->count();
  67. if ($traUserCount != $hasUserCount) return [false, 3202];
  68. // 检测客服信息是否是json
  69. $djuserArr = json_decode($djuserList, true);
  70. if (!is_array($djuserArr)) return [false, 3202];
  71. $djuserStrArr = array_unique(array_map(function ($djuser) {
  72. return "('{$djuser['user_id']}', '{$djuser['corpid']}')";
  73. }, $djuserArr));
  74. // 检测客服数据
  75. $djusersWhereStr = implode(',', $djuserStrArr);
  76. $traDjuserCount = count($djuserStrArr);
  77. if($traDjuserCount > 0){
  78. $hasDjuserCount = DjUser::query()
  79. ->whereRaw("(user_id, corpid) IN ({$djusersWhereStr})")
  80. ->where('enable', 1)
  81. ->count();
  82. } else {
  83. $hasDjuserCount = 0;
  84. }
  85. if ($traDjuserCount != $hasDjuserCount) return [false, 3202];
  86. // 检测预警组名称是否存在
  87. $isExist = WarnGroup::query()
  88. ->where('sys_group_id', $sysGroupId)
  89. ->where('name', $groupName)
  90. ->where(function ($query) use ($groupId) {
  91. if (!is_null($groupId)) $query->where('id', '!=', $groupId);
  92. })
  93. ->where('enable', 1)
  94. ->exists();
  95. if ($isExist) return [false, 3204];
  96. // 获取系统分组id
  97. self::getSysGroupId($sysGroupId);
  98. // 库存储
  99. \DB::begintransaction();
  100. try {
  101. if (is_null($groupId)) {
  102. // 插入
  103. $res = WarnGroup::query()->create([
  104. 'sys_group_id' => $sysGroupId,
  105. 'name' => $groupName,
  106. 'user_list' => implode(',', $userArr),
  107. 'dj_user_list' => json_encode($djuserArr, 256),
  108. ]);
  109. $groupId = $res->id;
  110. } else {
  111. // 更新
  112. // 检测数据是否存在
  113. $userGroupInfo = WarnGroup::query()
  114. ->where('sys_group_id', $sysGroupId)
  115. ->where('id', $groupId)
  116. ->first();
  117. if (empty($userGroupInfo)) {
  118. \DB::rollBack();
  119. return [[], 3205];
  120. }
  121. $userGroupInfo->update([
  122. 'name' => $groupName,
  123. 'user_list' => implode(',', $userArr),
  124. 'dj_user_list' => json_encode($djuserArr, 256),
  125. ]);
  126. }
  127. // 操作预警用户
  128. WarnGroupUser::groupUserOperate($groupId, $userArr);
  129. // 操作客服
  130. WarnGroupDjuser::groupDjuserOperate($groupId, $djuserArr);
  131. \DB::commit();
  132. return [true, 0];
  133. } catch (\Throwable $e) {
  134. Log::logError(
  135. '预警用户组操作有误~'.$e->getMessage().PHP_EOL.$e->getTraceAsString(),
  136. [
  137. 'sysGroupId' => $sysGroupId,
  138. 'groupName' => $groupName,
  139. 'userList' => $userList,
  140. 'groupId' => $groupId
  141. ],
  142. 'WarnService'
  143. );
  144. \DB::rollBack();
  145. return [false, 3106];
  146. }
  147. }
  148. public static function groupDetail($sysGroupId, $groupId)
  149. {
  150. // 获取系统分组id
  151. self::getSysGroupId($sysGroupId);
  152. // 检测数据是否存在
  153. $userGroupInfo = WarnGroup::query()
  154. ->select(['id', 'name', 'enable'])
  155. ->where('sys_group_id', $sysGroupId)
  156. ->where('id', $groupId)
  157. ->first();
  158. if (empty($userGroupInfo)) return [[], 3205];
  159. // 获取预警人员
  160. $groupUserArr = WarnGroupUser::getUserList($groupId);
  161. $userGroupInfo->user_list = $groupUserArr[$groupId] ?? [];
  162. // 获取客服信息
  163. $groupDjuserArr = WarnGroupDjuser::getDjserList($groupId);
  164. $userGroupInfo->djuser_list = $groupDjuserArr[$groupId] ?? [];
  165. return [$userGroupInfo, 0];
  166. }
  167. public static function groupEableOp($sysGroupId, $groupId, $enable)
  168. {
  169. // 获取系统分组id
  170. self::getSysGroupId($sysGroupId);
  171. // 检测数据是否存在
  172. $userGroupInfo = WarnGroup::query()
  173. ->where('sys_group_id', $sysGroupId)
  174. ->where('id', $groupId)
  175. ->first();
  176. if (empty($userGroupInfo)) return [[], 3205];
  177. try {
  178. $userGroupInfo->update(['enable' => $enable]);
  179. return [true, 0];
  180. } catch (\Throwable $e) {
  181. Log::logError(
  182. '预警用户组操作有误~'.$e->getMessage().PHP_EOL.$e->getTraceAsString(),
  183. [
  184. 'sysGroupId' => $sysGroupId,
  185. 'groupId' => $groupId,
  186. 'enable' => $enable
  187. ],
  188. 'WarnService'
  189. );
  190. return [false, 3106];
  191. }
  192. }
  193. public static function ruleConfList($sysGroupId)
  194. {
  195. // 规则列表
  196. $ruleList = WarnRule::query()
  197. ->select(['rule_id', 'rule', 'defval'])
  198. ->orderBy('id', 'ASC')
  199. ->get();
  200. if ($ruleList->isEmpty()) return [];
  201. // 获取系统分组id
  202. self::getSysGroupId($sysGroupId);
  203. // 规则配置列表
  204. $ruleConfList = WarnRuleConf::query()
  205. ->where('sys_group_id', $sysGroupId)
  206. ->whereIn('rule_id', $ruleList->pluck('rule_id'))
  207. ->pluck('setval', 'rule_id');
  208. foreach ($ruleList as $rule) {
  209. $rule->setval = $ruleConfList->get($rule->rule_id) ?? $rule->defval;
  210. unset($rule->defval);
  211. }
  212. return $ruleList;
  213. }
  214. public static function ruleConfOperate($sysGroupId, $ruleId, $setVal)
  215. {
  216. // 获取系统分组id
  217. self::getSysGroupId($sysGroupId);
  218. try {
  219. WarnRuleConf::query()
  220. ->updateOrCreate([
  221. 'sys_group_id' => $sysGroupId,
  222. 'rule_id' => $ruleId,
  223. ], [
  224. 'setval' => $setVal
  225. ]);
  226. return [true, 0];
  227. } catch (\Throwable $e) {
  228. Log::logError(
  229. '预警配置操作异常~ '.$e->getMessage().PHP_EOL.$e->getTraceAsString(),
  230. [
  231. 'sysGroupId' => $sysGroupId,
  232. 'ruleId' => $ruleId,
  233. 'setVal' => $setVal,
  234. ],
  235. 'WarnService'
  236. );
  237. return [false, 3106];
  238. }
  239. }
  240. public static function userList($sysGroupId, $keyword, $page, $pageSize)
  241. {
  242. // 获取系统分组id
  243. self::getSysGroupId($sysGroupId);
  244. $query = WarnUser::query()
  245. ->select(['id', 'name', 'phone'])
  246. ->where('sys_group_id', $sysGroupId)
  247. ->where(function ($query) use ($keyword) {
  248. if (!empty($keyword)) $query->where('name', 'like', '%'.$keyword.'%');
  249. })
  250. ->where('enable', 1);
  251. $total = $query->count();
  252. if ($total == 0) return [[], 0];
  253. $userList = $query
  254. ->orderByDesc('created_at')
  255. ->offset(($page - 1) * $pageSize)
  256. ->limit($pageSize)
  257. ->get();
  258. return [$userList, $total];
  259. }
  260. public static function userOperate($sysGroupId, $name, $phone, $enable, $userId)
  261. {
  262. // 获取系统分组id
  263. self::getSysGroupId($sysGroupId);
  264. // 检测手机号是否合法
  265. $isMob="/^1[3456789]{1}\d{9}$/";
  266. if(!preg_match($isMob, $phone)) return [false, 3203];
  267. // 检测预警人员手机号码是否存在
  268. $isExist = WarnUser::query()
  269. ->where('sys_group_id', $sysGroupId)
  270. ->where('phone', $phone)
  271. ->where(function ($query) use ($userId) {
  272. if (!empty($userId)) $query->where('id', '!=', $userId);
  273. })
  274. ->where('enable', 1)
  275. ->exists();
  276. if ($isExist) return [false, 3207];
  277. $hasPhone = $phone;
  278. if (!empty($userId)) {
  279. $userInfo = WarnUser::query()->find($userId);
  280. if (empty($userInfo)) return [false, 3208];
  281. $hasPhone = $userInfo->phone;
  282. }
  283. try {
  284. WarnUser::query()->updateOrCreate([
  285. 'sys_group_id' => $sysGroupId,
  286. 'phone' => $hasPhone
  287. ], [
  288. 'name' => $name,
  289. 'phone' => $phone,
  290. 'enable' => $enable
  291. ]);
  292. if(!empty($userId) && 0 == $enable) {
  293. # 禁用 查询预警组中所有使用该预警人的记录,然后在记录中删除该预警人
  294. $groupList = WarnGroup::query()->whereRaw('find_in_set('.$userId.', `user_list`)')->get();
  295. if($groupList->isNotEmpty()){
  296. foreach($groupList as $groupInfo) {
  297. $userList = explode(',', $groupInfo->user_list);
  298. $key = array_search($userId, $userList);
  299. unset($userList[$key]);
  300. $newUserList = implode(',', $userList);
  301. WarnGroup::query()->where('id', $groupInfo->id)->update(['user_list' => $newUserList]);
  302. }
  303. }
  304. WarnGroupUser::query()->where('user_id', $userId)->where('enable', 1)->update(['enable' => 0]);
  305. }
  306. return [true, 0];
  307. } catch (\Throwable $e) {
  308. Log::logError(
  309. '预警人员操作异常~ '.$e->getMessage().PHP_EOL.$e->getTraceAsString(),
  310. [
  311. 'sysGroupId' => $sysGroupId,
  312. 'ruleId' => $name,
  313. 'setVal' => $phone,
  314. 'enable' => $enable,
  315. 'userId' => $userId
  316. ],
  317. 'WarnService'
  318. );
  319. return [false, 3106];
  320. }
  321. }
  322. public static function djuserList($sysGroupId, $isActive)
  323. {
  324. // 获取系统分组id
  325. self::getSysGroupId($sysGroupId);
  326. $corpIdList = AdminManageCorp::query()
  327. ->where('sys_user_id', $sysGroupId)
  328. ->where('is_delete', 0)
  329. ->pluck('corpid')
  330. ->all();
  331. if (empty($corpIdList)) return [];
  332. $corpList = AuthorizeCorp::query()
  333. ->select(['id', 'corpid', 'corp_name'])
  334. ->whereIn('id', $corpIdList)
  335. ->where('enable', 1)
  336. ->get()
  337. ->keyBy('id')
  338. ->toArray();
  339. $userList = DjUser::query()
  340. ->select(['user_id', 'corpid', 'name', 'avatar', 'is_active', 'expire_time'])
  341. ->whereIn('corpid', array_column($corpList, 'corpid'))
  342. ->where('enable', 1)
  343. ->where('status', 1)
  344. ->where(function($query) use ($isActive) {
  345. if($isActive) $query->where('active_code', '>', '');
  346. })
  347. ->get()
  348. ->toArray();
  349. $corpUserList = [];
  350. foreach ($userList as &$user) {
  351. $user['active_desc'] = '';
  352. if(!$user['is_active']) {
  353. $user['active_time'] = $user['expire_time'] = null;
  354. $user['active_desc'] = '未激活';
  355. } else {
  356. if($user['expire_time']) {
  357. $expireTimestamp = strtotime($user['expire_time']);
  358. if($expireTimestamp <= time()) {
  359. $user['active_desc'] = '未激活';
  360. } else {
  361. if($expireTimestamp - time() <= 86400 * 15) {
  362. $user['active_desc'] = '即将过期';
  363. }
  364. }
  365. }
  366. }
  367. $corpUserList[$user['corpid']][] = $user;
  368. }
  369. $djuserList = [];
  370. foreach ($corpIdList as $corpId) {
  371. $corpInfo = $corpList[$corpId] ?? [];
  372. if (empty($corpInfo)) continue;
  373. $corpInfo['user_list'] = $corpUserList[$corpInfo['corpid']] ?? [];
  374. $djuserList[] = $corpInfo;
  375. }
  376. return $djuserList;
  377. }
  378. private static function getSysGroupId(&$sysGroupId)
  379. {
  380. $userInfo = Users::query()->find(Auth::id());
  381. if (!$userInfo->is_system_admin) $sysGroupId = $userInfo->group_admin_id;
  382. }
  383. public static function setCorpUserScaleWarnConf($sysGroupId, $adminId, $confList, $isSystemAdmin) {
  384. # 对规则配置数据项进行校验
  385. $thresholdList = CorpUserScaleWarningConf::THRESHOLD_LIST;
  386. $relationCorpIdList = AdminManageCorp::query()
  387. ->where("sys_user_id",$sysGroupId)
  388. ->where("is_delete",0)
  389. ->pluck("corpid")->toArray();
  390. $relationCorpList = AuthorizeCorp::query()->select('corpid')
  391. ->whereIn('id', $relationCorpIdList)
  392. ->where('enable', 1)->get();
  393. $confList = json_decode($confList, 1);
  394. foreach($confList as $confInfo) {
  395. if(!isset($confInfo['threshold']) || !isset($confInfo['corp_list']) || !in_array($confInfo['threshold'], $thresholdList)) {
  396. return ['规则配置数据项有误1', 3209];
  397. }
  398. # 系统管理员调过企微操作权限验证
  399. if($isSystemAdmin != Users::SYSTEM_ADMIN && !empty($confInfo['corp_list'])) {
  400. $corpList = $relationCorpList->whereIn('corpid', array_column($confInfo['corp_list'], 'corpid'))->all();
  401. $corpList = !empty($corpList) ? array_column($corpList, 'corpid') : [];
  402. if(count($corpList) < count($confInfo['corp_list'])) {
  403. return ['规则配置数据项有误2', 3209];
  404. }
  405. }
  406. }
  407. $updateTime = date('Y-m-d H:i:s');
  408. if($isSystemAdmin == Users::SYSTEM_ADMIN) {
  409. $sysGroupId = $adminId;
  410. }
  411. \DB::begintransaction();
  412. # 将配置数据拆分处理
  413. foreach($confList as $confInfo) {
  414. CorpUserScaleWarningConf::query()->where('sys_group_id', $sysGroupId)
  415. ->where('warning_threshold', $confInfo['threshold'])->where('enable', 1)
  416. ->update(['enable' => 0]);
  417. if(!empty($confInfo['corp_list'])) {
  418. $corpIdList = array_column($confInfo['corp_list'], 'corpid');
  419. foreach($corpIdList as $corpid) {
  420. $res = CorpUserScaleWarningConf::query()->updateOrCreate([
  421. 'sys_group_id' => $sysGroupId,
  422. 'corpid' => $corpid,
  423. 'warning_threshold' => $confInfo['threshold'],
  424. ],[
  425. 'enable' => 1,
  426. 'update_time' => $updateTime,
  427. ]);
  428. if(!$res) {
  429. \DB::rollBack();
  430. return ['更新数据异常,请联系管理员', 500];
  431. }
  432. }
  433. }
  434. }
  435. \DB::commit();
  436. return ['保存成功', 0];
  437. }
  438. public static function getCorpUserScaleWarnConf($sysGroupId, $adminId, $isSystemAdmin) {
  439. if($isSystemAdmin == Users::SYSTEM_ADMIN) {
  440. $sysGroupId = $adminId;
  441. }
  442. $query = CorpUserScaleWarningConf::query()->where('sys_group_id', $sysGroupId)
  443. ->where('enable', 1);
  444. if($isSystemAdmin != Users::SYSTEM_ADMIN) {
  445. $relationCorpIdList = AdminManageCorp::query()
  446. ->where("sys_user_id",$sysGroupId)
  447. ->where("is_delete",0)
  448. ->pluck("corpid")->toArray();
  449. $relationCorpList = AuthorizeCorp::query()->select('corpid')
  450. ->whereIn('id', $relationCorpIdList)
  451. ->where('enable', 1)->get();
  452. $corpIdList = $relationCorpList->isNotEmpty() ? array_column($relationCorpList->toArray(), 'corpid') : [];
  453. $query = $query->whereIn('corpid', $corpIdList);
  454. }
  455. # 查询所有有效数据
  456. $data = $query->get();
  457. $corpDataList = null;
  458. if($data->isNotEmpty()) {
  459. # 提取企微ID列表
  460. $corpIdList = array_column($data->toArray(), 'corpid');
  461. # 企微id去重
  462. $uniqueCorpIdList = array_unique($corpIdList);
  463. # 批量查询企微信息
  464. $corpDataList = AuthorizeCorp::getAllCorpList($uniqueCorpIdList);
  465. }
  466. $corpIdList = array_unique(array_column($data->toArray(), 'corpid'));
  467. $corpUserScaleList = CorpService::getMultipleCorpUserScaleFromRds($corpIdList);
  468. $result = [];
  469. foreach (CorpUserScaleWarningConf::THRESHOLD_LIST as $threshold) {
  470. $rows = $data->where('warning_threshold', $threshold)->all();
  471. $corpList = !empty($rows) ? array_column($rows, 'corpid') : [];
  472. # 获取企微用户规模
  473. $corpData = array_map(function($corpid) use ($corpDataList, $threshold, $corpUserScaleList) {
  474. $userScale = $corpUserScaleList[$corpid] ?? 0;
  475. $corpInfo = $corpDataList->where('corpid', $corpid)->first();
  476. $corpName = !empty($corpInfo) ? $corpInfo->corp_name : '';
  477. $rate = round($userScale / $threshold, 2);
  478. if($rate < 0.8) {
  479. $type = '1';
  480. } else if ($rate < 1) {
  481. $type = '2';
  482. } else {
  483. $type = '3';
  484. }
  485. return ['corpid' => $corpid, 'corp_name' => $corpName, 'user_scale' => $userScale, 'type' => $type];
  486. }, $corpList);
  487. array_multisort(array_column($corpData, 'user_scale'), SORT_DESC, $corpData);
  488. $result[] = [
  489. 'threshold' => $threshold,
  490. 'corp_list' => $corpData
  491. ];
  492. }
  493. return $result;
  494. }
  495. public static function setCorpUserScaleWarnConfNew($sysGroupId, $adminId, $isSystemAdmin, $threshold, $corpIdList) {
  496. $relationCorpIdList = AdminManageCorp::query()
  497. ->where("sys_user_id",$sysGroupId)
  498. ->where("is_delete",0)
  499. ->pluck("corpid")->toArray();
  500. $relationCorpList = AuthorizeCorp::query()->select('corpid')
  501. ->whereIn('id', $relationCorpIdList)
  502. ->where('enable', 1)->get();
  503. # 过滤空数据
  504. $corpIdList = array_filter($corpIdList);
  505. # 系统管理员调过企微操作权限验证
  506. if($isSystemAdmin != Users::SYSTEM_ADMIN && !empty($corpIdList)) {
  507. $corpList = $relationCorpList->whereIn('corpid', $corpIdList)->all();
  508. $corpList = !empty($corpList) ? array_column($corpList, 'corpid') : [];
  509. if(count($corpList) < count($corpList)) {
  510. return ['规则配置数据项有误2', 3209];
  511. }
  512. }
  513. $updateTime = date('Y-m-d H:i:s');
  514. if($isSystemAdmin == Users::SYSTEM_ADMIN) {
  515. $sysGroupId = $adminId;
  516. }
  517. \DB::begintransaction();
  518. CorpUserScaleWarningConf::query()->where('sys_group_id', $sysGroupId)
  519. ->where('warning_threshold', $threshold)->where('enable', 1)
  520. ->update(['enable' => 0]);
  521. if(!empty($corpIdList)) {
  522. foreach($corpIdList as $corpid) {
  523. $res = CorpUserScaleWarningConf::query()->updateOrCreate([
  524. 'sys_group_id' => $sysGroupId,
  525. 'corpid' => $corpid,
  526. 'warning_threshold' => $threshold,
  527. ],[
  528. 'enable' => 1,
  529. 'update_time' => $updateTime,
  530. ]);
  531. if(!$res) {
  532. \DB::rollBack();
  533. return ['更新数据异常,请联系管理员', 500];
  534. }
  535. }
  536. }
  537. \DB::commit();
  538. return ['保存成功', 0];
  539. }
  540. public static function getNoticeDataList($corpid, $userId, $noticeList, $noticeType) {
  541. # 获取企微名称
  542. $corp = AuthorizeCorp::query()->where('corpid', $corpid)->where('enable', 1)->value('corp_name');
  543. # 获取客服名称
  544. $userName = DjUser::query()->where('corpid', $corpid)->where('user_id', $userId)->where('enable', 1)->value('name');
  545. # 获取需要接收预警通知的用户信息
  546. $noticeList = explode(',', $noticeList);
  547. if($noticeType == 1) { // 预警人
  548. $noticeUserList = WarnUser::query()->whereIn('id', $noticeList)->where('enable', 1)->get();
  549. $noticeCorpUserList = [];
  550. } elseif ($noticeType == 2) { // 预警组
  551. $noticeGroupInfo = WarnGroup::query()->whereIn('id', $noticeList)->where('enable', 1)->first();
  552. $noticeUserIdList = $noticeGroupInfo->user_list;
  553. $noticeUserIdList = explode(',', $noticeUserIdList);
  554. $noticeUserList = WarnUser::query()->whereIn('id', $noticeUserIdList)->where('enable', 1)->get();
  555. $noticeCorpUserList = json_decode($noticeGroupInfo->dj_user_list, true);
  556. }
  557. return ['corp' => $corp, 'userName' => $userName, 'noticeUserList' => $noticeUserList, 'noticeCorpUserList' => $noticeCorpUserList];
  558. }
  559. }