企微短剧业务系统

WarnController.php 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Models\CorpUserScaleWarningConf;
  4. use App\Service\WarnService;
  5. use Illuminate\Http\Request;
  6. use App\Http\Controllers\Controller;
  7. use Illuminate\Validation\Rule;
  8. class WarnController extends Controller
  9. {
  10. /**
  11. * 预警用户组列表
  12. * @param Request $request
  13. * @return array
  14. */
  15. public function groupList(Request $request)
  16. {
  17. $validator = \Validator::make($request->all(),[
  18. 'sys_group_id' => 'nullable|int',
  19. 'keyword' => 'nullable|string',
  20. ]);
  21. if ($validator->fails()) {
  22. return self::returnValue($validator->getMessageBag(), 3001);
  23. }
  24. $sysGroupId = $request->input('sys_group_id');
  25. $keyword = $request->input('keyword');
  26. $page = $request->input('page', 1);
  27. $pageSize = $request->input('page_size', 20);
  28. $isSelect = $request->input('is_select', 0);
  29. list($list, $total) = WarnService::groupList($sysGroupId, $keyword, $page, $pageSize, $isSelect);
  30. if(1 == $isSelect){
  31. return self::returnValue($list);
  32. } else {
  33. return self::returnPageValue($list, $total, $pageSize, $page);
  34. }
  35. }
  36. /**
  37. * 预警用户组添加
  38. * @param Request $request
  39. * @return array
  40. */
  41. public function groupAdd(Request $request)
  42. {
  43. $validator = \Validator::make($request->all(),[
  44. 'sys_group_id' => 'nullable|int',
  45. 'group_name' => 'required|string',
  46. 'user_list' => 'required|string',
  47. 'djuser_list' => 'nullable|string',
  48. ]);
  49. if ($validator->fails()) {
  50. return self::returnValue($validator->getMessageBag(), 3001);
  51. }
  52. $sysGroupId = $request->input('sys_group_id');
  53. $groupName = $request->input('group_name');
  54. $userList = $request->input('user_list');
  55. $djuserList = $request->input('djuser_list');
  56. list($res, $code) = WarnService::groupOperate($sysGroupId, $groupName, $userList, $djuserList);
  57. return self::returnValue($res, $code);
  58. }
  59. /**
  60. * 预警用户组数据详情
  61. * @param Request $request
  62. * @return array
  63. */
  64. public function groupDetail(Request $request)
  65. {
  66. $validator = \Validator::make($request->all(),[
  67. 'sys_group_id' => 'nullable|int',
  68. 'group_id' => 'required|int',
  69. ]);
  70. if ($validator->fails()) {
  71. return self::returnValue($validator->getMessageBag(), 3001);
  72. }
  73. $sysGroupId = $request->input('sys_group_id');
  74. $groupId = $request->input('group_id');
  75. list($res, $code) = WarnService::groupDetail($sysGroupId, $groupId);
  76. return self::returnValue($res, $code);
  77. }
  78. /**
  79. * 预警用户组编辑
  80. * @param Request $request
  81. * @return array
  82. */
  83. public function groupEdit(Request $request)
  84. {
  85. $validator = \Validator::make($request->all(),[
  86. 'sys_group_id' => 'nullable|int',
  87. 'group_name' => 'required|string',
  88. 'user_list' => 'required|string',
  89. 'djuser_list' => 'nullable|string',
  90. 'group_id' => 'required|int',
  91. ]);
  92. if ($validator->fails()) {
  93. return self::returnValue($validator->getMessageBag(), 3001);
  94. }
  95. $sysGroupId = $request->input('sys_group_id');
  96. $groupName = $request->input('group_name');
  97. $userList = $request->input('user_list');
  98. $djuserList = $request->input('djuser_list');
  99. $groupId = $request->input('group_id');
  100. list($res, $code) = WarnService::groupOperate($sysGroupId, $groupName, $userList, $djuserList, $groupId);
  101. return self::returnValue($res, $code);
  102. }
  103. /**
  104. * 预警组开启和禁用
  105. * @param Request $request
  106. * @return array
  107. */
  108. public function groupEableOp(Request $request)
  109. {
  110. $validator = \Validator::make($request->all(),[
  111. 'sys_group_id' => 'nullable|int',
  112. 'group_id' => 'required|int',
  113. 'enable' => ['required',Rule::in([0, 1])],
  114. ]);
  115. if ($validator->fails()) {
  116. return self::returnValue($validator->getMessageBag(), 3001);
  117. }
  118. $sysGroupId = $request->input('sys_group_id');
  119. $groupId = $request->input('group_id');
  120. $enable = $request->input('enable');
  121. list($res, $code) = WarnService::groupEableOp($sysGroupId, $groupId, $enable);
  122. return self::returnValue($res, $code);
  123. }
  124. /**
  125. * 预警规则配置列表
  126. * @param Request $request
  127. * @return array
  128. */
  129. public function ruleConfList(Request $request)
  130. {
  131. $validator = \Validator::make($request->all(),[
  132. 'sys_group_id' => 'nullable|int',
  133. ]);
  134. if ($validator->fails()) {
  135. return self::returnValue($validator->getMessageBag(), 3001);
  136. }
  137. $sysGroupId = $request->input('sys_group_id');
  138. $res = WarnService::ruleConfList($sysGroupId);
  139. return self::returnValue($res);
  140. }
  141. /**
  142. * 预警规则配置操作
  143. * @param Request $request
  144. * @return array
  145. */
  146. public function ruleConfOperate(Request $request)
  147. {
  148. $validator = \Validator::make($request->all(),[
  149. 'sys_group_id' => 'nullable|int',
  150. 'rule_id' => 'required|string',
  151. 'set_val' => 'nullable|int',
  152. ]);
  153. if ($validator->fails()) {
  154. return self::returnValue($validator->getMessageBag(), 3001);
  155. }
  156. $sysGroupId = $request->input('sys_group_id');
  157. $ruleId = $request->input('rule_id');
  158. $setVal = $request->input('set_val');
  159. list($res, $code) = WarnService::ruleConfOperate($sysGroupId, $ruleId, $setVal);
  160. return self::returnValue($res, $code);
  161. }
  162. /**
  163. * 预警人员列表
  164. * @param Request $request
  165. * @return array
  166. */
  167. public function userList(Request $request)
  168. {
  169. $validator = \Validator::make($request->all(),[
  170. 'sys_group_id' => 'nullable|int',
  171. 'keyword' => 'nullable|string',
  172. ]);
  173. if ($validator->fails()) {
  174. return self::returnValue($validator->getMessageBag(), 3001);
  175. }
  176. $sysGroupId = $request->input('sys_group_id');
  177. $keyword = $request->input('keyword');
  178. $page = $request->input('page', 1);
  179. $pageSize = $request->input('page_size', 20);
  180. list($list, $total) = WarnService::userList($sysGroupId, $keyword, $page, $pageSize);
  181. return self::returnPageValue($list, $total, $pageSize, $page);
  182. }
  183. /**
  184. * 预警人员操作
  185. * @param Request $request
  186. * @return array
  187. */
  188. public function userOperate(Request $request)
  189. {
  190. $validator = \Validator::make($request->all(),[
  191. 'sys_group_id' => 'nullable|int',
  192. 'name' => 'required|string',
  193. 'phone' => 'required|string',
  194. 'enable' => ['required',Rule::in([0, 1])],
  195. 'user_id' => 'nullable|int'
  196. ]);
  197. if ($validator->fails()) {
  198. return self::returnValue($validator->getMessageBag(), 3001);
  199. }
  200. $sysGroupId = $request->input('sys_group_id');
  201. $name = $request->input('name');
  202. $phone = $request->input('phone');
  203. $enable = $request->input('enable');
  204. $userId = $request->input('user_id');
  205. list($res, $code) = WarnService::userOperate($sysGroupId, $name, $phone, $enable, $userId);
  206. return self::returnValue($res, $code);
  207. }
  208. /**
  209. * 预警客服列表
  210. * @param Request $request
  211. * @return array
  212. */
  213. public function djuserList(Request $request)
  214. {
  215. $validator = \Validator::make($request->all(),[
  216. 'sys_group_id' => 'nullable|int'
  217. ]);
  218. if ($validator->fails()) {
  219. return self::returnValue($validator->getMessageBag(), 3001);
  220. }
  221. $sysGroupId = $request->input('sys_group_id');
  222. $isActive = $request->input('is_active');
  223. $res = WarnService::djuserList($sysGroupId, $isActive);
  224. return self::returnValue($res);
  225. }
  226. /**
  227. * 企微用户规模预警 阈值列表(没有用到)
  228. * @return array
  229. */
  230. public function corpUserScaleWarnThresholdList() {
  231. $list = CorpUserScaleWarningConf::THRESHOLD_LIST;
  232. return self::returnValue($list);
  233. }
  234. /**
  235. * 企微用户规模预警规则设置(废弃)
  236. * @param Request $request
  237. */
  238. public function setCorpUserScaleWarnConf(Request $request) {
  239. $validator = \Validator::make($request->all(),[
  240. 'sys_group_id' => 'required|int',
  241. 'conf_list' => 'required|string',
  242. ]);
  243. if ($validator->fails()) {
  244. return self::returnValue($validator->getMessageBag(), 3001);
  245. }
  246. $sysGroupId = $request->input('sys_group_id');
  247. $confList = $request->input('conf_list');
  248. $isSystemAdmin = $request->input("is_system_admin"); //是否是系统管理员,中间件赋值
  249. $adminId = $request->input('admin_id');
  250. list($res, $code) = WarnService::setCorpUserScaleWarnConf($sysGroupId, $adminId, $confList, $isSystemAdmin);
  251. return self::returnValue($res, $code);
  252. }
  253. /**
  254. * 企微用户规模预警规则展示
  255. * @param Request $request
  256. */
  257. public function getCorpUserScaleWarnConf(Request $request) {
  258. $validator = \Validator::make($request->all(),[
  259. 'sys_group_id' => 'required|int'
  260. ]);
  261. if ($validator->fails()) {
  262. return self::returnValue($validator->getMessageBag(), 3001);
  263. }
  264. $sysGroupId = $request->input('sys_group_id');
  265. $adminId = $request->input('admin_id');
  266. $isSystemAdmin = $request->input("is_system_admin"); //是否是系统管理员,中间件赋值
  267. $data = WarnService::getCorpUserScaleWarnConf($sysGroupId, $adminId, $isSystemAdmin);
  268. return self::returnValue($data);
  269. }
  270. /**
  271. * 企微用户规模预警规则设置(单条设置)
  272. * @param Request $request
  273. */
  274. public static function setCorpUserScaleWarnConfNew(Request $request) {
  275. $validator = \Validator::make($request->all(),[
  276. 'sys_group_id' => 'required|int',
  277. 'threshold' => 'required|in:4700,4800,9700,9800,14700,14800,19700,19800',
  278. 'corp_list' => 'nullable|array',
  279. ]);
  280. if ($validator->fails()) {
  281. return self::returnValue($validator->getMessageBag(), 3001);
  282. }
  283. $sysGroupId = $request->input('sys_group_id');
  284. $threshold = $request->input('threshold');
  285. $corpList = $request->input('corp_list');
  286. $isSystemAdmin = $request->input("is_system_admin"); //是否是系统管理员,中间件赋值
  287. $adminId = $request->input('admin_id');
  288. list($res, $code) = WarnService::setCorpUserScaleWarnConfNew($sysGroupId, $adminId, $isSystemAdmin, $threshold, $corpList);
  289. return self::returnValue($res, $code);
  290. }
  291. }