REAPI/app/queue/command/monitor/ChannelOrderStatusMonitor.php

118 lines
3.0 KiB
PHP
Raw Normal View History

<?php
namespace app\queue\command\monitor;
use app\channel\service\ChannelService;
use app\gateway\service\RedisService;
use app\merchant\service\OrderService;
use app\robot\controller\WxWorkBot;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
/**
* 渠道订单问题监控预警
* Class ChannelOrderStatusMonitor
* @package app\data\command
*/
class ChannelOrderStatusMonitor extends Command
{
protected $redis = false;
protected function configure()
{
$this->setName('xQueue:ChannelOrderStatusMonitor')->setDescription('[ 监控系统 ] 渠道订单问题监控预警');
}
/**
* @param Input $input
* @param Output $output
* @throws \think\admin\Exception
*/
protected function execute(Input $input, Output $output)
{
ini_set('memory_limit', '1024M');
$this->redis();
$channelService = ChannelService::instance();
$RobotService = new WxWorkBot($this->app);
$channelList = $channelService->db()->where(['status'=>1])->whereLike('other_data','%Monitor_OrderStatus_status%')->select()->toArray();
if(!$channelList) $this->setQueueSuccess("未找到支持监控订单的渠道");
$channelList_num = count($channelList);
$count_sum = 0;
$day = date('Y-m-d', strtotime('-1 day'));
$tip_info=[];
// $key = '41b42bd4-c9f9-4617-9531-0a358dd97a82';
foreach($channelList as $channel) {
$other_param = json_decode($channel['other_data'],true);
if(!$other_param){
continue;
}
$roomid = $other_param['QYWX_roomid']??null;
if(!$roomid || $other_param['Monitor_OrderStatus_status'] !=1){
continue;
}
$sender = $other_param['QYWX_sender']??null;
if(isset($other_param['Monitor_OrderStatus_OrderFailRate'])){
$orderFailRate = $this->orderFailRate($channel,$other_param['Monitor_OrderStatus_OrderFailRate']);
}
}
if(!empty($tip_info)){
$errorMsg = "渠道余额监控预警<font color=\"warning\">".$count_sum ."列</font>,请相关同事注意。\n
>";
$errorMsg .= implode(">", $tip_info);
$RobotService->send_markdown($errorMsg,$key);
}
$this->setQueueSuccess("共处理 {$channelList_num} 个渠道, 完成{$count_sum} 个查询处理!");
}
#获取订单失败率
public function orderFailRate($channel,$rate)
{
$OrderService = OrderService::instance();
$cur = time();
$time = 300;
$whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time;
return $OrderService->db()->whereRaw('status = 4 and ' . $whereRaw)->order('id asc')->select();
return true;
// $this->redis->set('queue:channel:order:status:monitor:success', $msg);
}
protected function redis()
{
if (!$this->redis) {
$this->redis = RedisService::getInstance();
}
}
}