企微短剧业务系统

AbnormalAccountController.php 4.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: shensong
  5. * Date: 2022/12/27
  6. * Time: 16:31
  7. */
  8. namespace App\Http\Controllers\Api;
  9. use App\Http\Controllers\Controller;
  10. use App\Log;
  11. use App\Models\AbnormalAccountConfDetail;
  12. use App\Service\AbnormalAccountWarnConfService;
  13. use Illuminate\Http\Request;
  14. class AbnormalAccountController extends Controller
  15. {
  16. # 设置监控规则配置
  17. public function setConf(Request $request)
  18. {
  19. $validator = \Validator::make($request->all(),[
  20. 'monitor_user_list' => 'required|string',
  21. 'notice_list' => 'required|string',
  22. 'notice_type' => 'required|in:1,2',
  23. 'content' => 'required|string',
  24. 'conf_id' => 'nullable|integer',
  25. 'time_interval' => 'nullable|numeric',
  26. 'time_interval_unit' => 'nullable|numeric|in:1,2,3',
  27. 'warn_type' => 'nullable|numeric|in:1,2'
  28. ]);
  29. if ($validator->fails()) {
  30. return self::returnValue($validator->getMessageBag(), 1102);
  31. }
  32. $params['sys_group_id'] = $request->input('sys_group_id');
  33. $params['monitor_user_list'] = $request->input('monitor_user_list');
  34. $params['notice_list'] = $request->input('notice_list');
  35. $params['notice_type'] = $request->input('notice_type');
  36. $params['time_interval'] = $request->input('time_interval');
  37. $params['time_interval_unit']= $request->input('time_interval_unit', 1);
  38. $params['warn_type'] = $request->input('warn_type', 1);
  39. $content = $request->input('content');
  40. $confId = $request->input('conf_id');
  41. Log::logInfo('客服号异常预警配置', $request->all(), 'abnormal_account_conf');
  42. $errno = 0;
  43. $data = AbnormalAccountWarnConfService::setConf($confId, $params, $content, $errno);
  44. return self::returnValue($data, $errno);
  45. }
  46. # 监控配置列表
  47. public function confList(Request $request)
  48. {
  49. $validator = \Validator::make($request->all(),[
  50. 'page' => 'required|numeric',
  51. 'page_size' => 'required|numeric',
  52. 'warn_type' => 'nullable|numeric|in:1,2'
  53. ]);
  54. if ($validator->fails()) {
  55. return self::returnValue($validator->getMessageBag(), 1102);
  56. }
  57. $warnType = $request->input('warn_type', 1);
  58. $sysGroupId = $request->input('sys_group_id');
  59. $page = $request->input('page', 1);
  60. $pageSize = $request->input('page_size', 20);
  61. list($data, $total) = AbnormalAccountWarnConfService::confList($sysGroupId, $warnType, $page, $pageSize);
  62. if(1 == $warnType) {
  63. $extra = [
  64. 'notice' => in_array($sysGroupId, [2, 3, 38, 51]) ? 1 : 0,
  65. 'message' => '客服绑定投放账号近1小时内消耗金额小于'.AbnormalAccountConfDetail::THRESHOLD_VALUE.'元时不予预警',
  66. ];
  67. } else {
  68. $extra = [];
  69. }
  70. return self::returnPageValue($data, $total, $pageSize, $page, $extra);
  71. }
  72. # 监控配置详情
  73. public function confDetail(Request $request)
  74. {
  75. $validator = \Validator::make($request->all(),[
  76. 'conf_id' => 'required|integer',
  77. ]);
  78. if ($validator->fails()) {
  79. return self::returnValue($validator->getMessageBag(), 1102);
  80. }
  81. $confId = $request->input('conf_id');
  82. $sysGroupId = $request->input('sys_group_id');
  83. $data = AbnormalAccountWarnConfService::confDetail($sysGroupId, $confId);
  84. return self::returnValue($data);
  85. }
  86. # 监控配置启用禁用状态
  87. public function updateConfStatus(Request $request)
  88. {
  89. $validator = \Validator::make($request->all(),[
  90. 'conf_id' => 'required|integer',
  91. 'status' => 'required|in:1,2'
  92. ]);
  93. if ($validator->fails()) {
  94. return self::returnValue($validator->getMessageBag(), 1102);
  95. }
  96. $confId = $request->input('conf_id');
  97. $status = $request->input('status');
  98. $errno = 0;
  99. $data = AbnormalAccountWarnConfService::updateConfStatus($confId, $status, $errno);
  100. return self::returnValue($data, $errno);
  101. }
  102. }