123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124 |
- <?php
- /**
- * Created by PhpStorm.
- * User: shensong
- * Date: 2022/12/27
- * Time: 16:31
- */
- namespace App\Http\Controllers\Api;
- use App\Http\Controllers\Controller;
- use App\Log;
- use App\Models\AbnormalAccountConfDetail;
- use App\Service\AbnormalAccountWarnConfService;
- use Illuminate\Http\Request;
- class AbnormalAccountController extends Controller
- {
- # 设置监控规则配置
- public function setConf(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'monitor_user_list' => 'required|string',
- 'notice_list' => 'required|string',
- 'notice_type' => 'required|in:1,2',
- 'content' => 'required|string',
- 'conf_id' => 'nullable|integer',
- 'time_interval' => 'nullable|numeric',
- 'time_interval_unit' => 'nullable|numeric|in:1,2,3',
- 'warn_type' => 'nullable|numeric|in:1,2'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $params['sys_group_id'] = $request->input('sys_group_id');
- $params['monitor_user_list'] = $request->input('monitor_user_list');
- $params['notice_list'] = $request->input('notice_list');
- $params['notice_type'] = $request->input('notice_type');
- $params['time_interval'] = $request->input('time_interval');
- $params['time_interval_unit']= $request->input('time_interval_unit', 1);
- $params['warn_type'] = $request->input('warn_type', 1);
- $content = $request->input('content');
- $confId = $request->input('conf_id');
- Log::logInfo('客服号异常预警配置', $request->all(), 'abnormal_account_conf');
- $errno = 0;
- $data = AbnormalAccountWarnConfService::setConf($confId, $params, $content, $errno);
- return self::returnValue($data, $errno);
- }
- # 监控配置列表
- public function confList(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'page' => 'required|numeric',
- 'page_size' => 'required|numeric',
- 'warn_type' => 'nullable|numeric|in:1,2'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $warnType = $request->input('warn_type', 1);
- $sysGroupId = $request->input('sys_group_id');
- $page = $request->input('page', 1);
- $pageSize = $request->input('page_size', 20);
- list($data, $total) = AbnormalAccountWarnConfService::confList($sysGroupId, $warnType, $page, $pageSize);
- if(1 == $warnType) {
- $extra = [
- 'notice' => in_array($sysGroupId, [2, 3, 38, 51]) ? 1 : 0,
- 'message' => '客服绑定投放账号近1小时内消耗金额小于'.AbnormalAccountConfDetail::THRESHOLD_VALUE.'元时不予预警',
- ];
- } else {
- $extra = [];
- }
- return self::returnPageValue($data, $total, $pageSize, $page, $extra);
- }
- # 监控配置详情
- public function confDetail(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'conf_id' => 'required|integer',
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $confId = $request->input('conf_id');
- $sysGroupId = $request->input('sys_group_id');
- $data = AbnormalAccountWarnConfService::confDetail($sysGroupId, $confId);
- return self::returnValue($data);
- }
- # 监控配置启用禁用状态
- public function updateConfStatus(Request $request)
- {
- $validator = \Validator::make($request->all(),[
- 'conf_id' => 'required|integer',
- 'status' => 'required|in:1,2'
- ]);
- if ($validator->fails()) {
- return self::returnValue($validator->getMessageBag(), 1102);
- }
- $confId = $request->input('conf_id');
- $status = $request->input('status');
- $errno = 0;
- $data = AbnormalAccountWarnConfService::updateConfStatus($confId, $status, $errno);
- return self::returnValue($data, $errno);
- }
- }
|