283 lines
7.4 KiB
PHP
283 lines
7.4 KiB
PHP
![]() |
<?php
|
|||
|
|
|||
|
namespace app\robot\controller\api;
|
|||
|
set_time_limit(0);
|
|||
|
ini_set('memory_limit','512M');
|
|||
|
ini_set('default_socket_timeout', -1); //不超时
|
|||
|
use app\merchant\service\OrderService;
|
|||
|
|
|||
|
use app\merchant\service\MerchantService;
|
|||
|
use app\gateway\service\RedisService;
|
|||
|
|
|||
|
|
|||
|
use dever\Log;
|
|||
|
use think\exception\HttpResponseException;
|
|||
|
|
|||
|
|
|||
|
class Qqbot extends Core
|
|||
|
{
|
|||
|
# 是否检测数据
|
|||
|
protected bool $check = false;
|
|||
|
protected $redis = false;
|
|||
|
# 查询接口 一般用于查询数据,同步执行
|
|||
|
|
|||
|
/**
|
|||
|
* @return array|bool
|
|||
|
*/
|
|||
|
public function getNeedOrder($where,$field)
|
|||
|
{
|
|||
|
$orderService = OrderService::instance();
|
|||
|
|
|||
|
$data = $orderService->db()->field($field)->where($where)->select()->toArray();
|
|||
|
return $data;
|
|||
|
}
|
|||
|
public function upOrderExpireTime()
|
|||
|
{
|
|||
|
$orderService = OrderService::instance();
|
|||
|
|
|||
|
$field="order_id,param";//需要数据库返回的字段
|
|||
|
|
|||
|
$data = $orderService->db()->field($field)->whereNull('expire_time')->select()->toArray();
|
|||
|
// print_r($data);die;
|
|||
|
if($data){
|
|||
|
foreach($data as $key=>$value){
|
|||
|
$value['param'] = json_decode($value['param'], true);
|
|||
|
// $timeout = $value['param']['expireTime'];
|
|||
|
|
|||
|
$timeout = date('Y-m-d H:i:s', $value['param']['expireTime']/1000);
|
|||
|
$where= array('order_id' =>$value['order_id']);
|
|||
|
$data = array('expire_time' =>$timeout);
|
|||
|
$orderService->db()->where($where)->update($data);
|
|||
|
// print_r($data);die;
|
|||
|
// array_push($redisData,$orders[$key]['account']);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return 'ok';
|
|||
|
}
|
|||
|
/**
|
|||
|
*$params:发给的机器人字段数组格式;$type=true判断是否在缓存中,false不判断全部返回
|
|||
|
* */
|
|||
|
public function transOrder($time){
|
|||
|
$this->redis();
|
|||
|
$where=[['status','=',4],['cid','=','2'],['expire_time','<=',date('Y-m-d H:i:s',time()+$time*60*60)]];
|
|||
|
|
|||
|
|
|||
|
$field="order_id,account";//需要数据库返回的字段
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
$orders=$this->getNeedOrder($where,$field);
|
|||
|
|
|||
|
$redisData=[];
|
|||
|
if($orders){
|
|||
|
foreach($orders as $key=>$value){
|
|||
|
if(!$this->redis->get('rediskey-'.$orders[$key]['order_id'])){
|
|||
|
array_push($redisData,$orders[$key]['account']);
|
|||
|
$this->redis->set('rediskey-'.$orders[$key]['order_id'],'1',30*60);
|
|||
|
}
|
|||
|
if(!$this->redis->get('rediskey-1H-'.$orders[$key]['order_id']) && $time == '1'){
|
|||
|
array_push($redisData,$orders[$key]['account']);
|
|||
|
$this->redis->set('rediskey-1H-'.$orders[$key]['order_id'],'1',30*60);
|
|||
|
}
|
|||
|
if(!$this->redis->get('rediskey-TOP-'.$orders[$key]['order_id']) && $time == '0.5'){
|
|||
|
array_push($redisData,$orders[$key]['order_id']);
|
|||
|
$this->redis->set('rediskey-TOP-'.$orders[$key]['order_id'],'1',30*60);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
return $redisData?implode("\n",$redisData):'';
|
|||
|
}
|
|||
|
protected function redis()
|
|||
|
{
|
|||
|
if (!$this->redis) {
|
|||
|
$this->redis = RedisService::getInstance();
|
|||
|
}
|
|||
|
}
|
|||
|
/**
|
|||
|
*
|
|||
|
*/
|
|||
|
public function send($url,$param)
|
|||
|
{
|
|||
|
$geturl = 'http://124.70.52.119:7374/'.$url;
|
|||
|
$header['Content-Type'] = 'application/x-www-form-urlencoded';
|
|||
|
return $this->curl('post', $geturl, http_build_query($param), false, $header);
|
|||
|
|
|||
|
}
|
|||
|
public function timeout_order()
|
|||
|
{
|
|||
|
#发送群聊消息
|
|||
|
$url = 'send_group_msg';
|
|||
|
|
|||
|
#
|
|||
|
$param = array();
|
|||
|
$param['group_id'] = '248553382';#群组号
|
|||
|
$needField = ['account'];
|
|||
|
|
|||
|
$atqq = '389839316';#需要艾特的qq
|
|||
|
$time = '6'; #超时拦截时间
|
|||
|
|
|||
|
$get_timeout_order = $this->transOrder($time);
|
|||
|
|
|||
|
|
|||
|
if(!$get_timeout_order){
|
|||
|
// Log::write('robot', 'qqbot', '无');
|
|||
|
// Log::write($key, $name, $content)
|
|||
|
die;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
$param['message'] = "[CQ:at,qq=".$atqq."] 以下为超过42小时订单 \r ".$get_timeout_order;
|
|||
|
|
|||
|
|
|||
|
$send = $this->send($url, $param);
|
|||
|
|
|||
|
|
|||
|
Log::write('robot', 'qqbot', $send);
|
|||
|
|
|||
|
return $send;
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
public function timeout_order1()
|
|||
|
{
|
|||
|
#发送群聊消息
|
|||
|
$url = 'send_group_msg';
|
|||
|
|
|||
|
#
|
|||
|
$param = array();
|
|||
|
$param['group_id'] = '248553382';#群组号
|
|||
|
$needField = ['account'];
|
|||
|
|
|||
|
$atqq = '389839316';#需要艾特的qq
|
|||
|
$time = '1'; #超时拦截时间
|
|||
|
$atqq1 = '530979976';#需要艾特的qq1
|
|||
|
|
|||
|
$get_timeout_order = $this->transOrder($time);
|
|||
|
|
|||
|
|
|||
|
if(!$get_timeout_order){
|
|||
|
// Log::write('robot', 'qqbot', '无');
|
|||
|
// Log::write($key, $name, $content)
|
|||
|
die;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
$param['message'] = "[CQ:at,qq=".$atqq."][CQ:at,qq=".$atqq1."] 以下为1小时内超时订单,请第一时间处理 \r ".$get_timeout_order;
|
|||
|
|
|||
|
|
|||
|
$send = $this->send($url, $param);
|
|||
|
|
|||
|
|
|||
|
Log::write('robot', 'qqbot', $send);
|
|||
|
|
|||
|
return $send;
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
public function timeout_order2()
|
|||
|
{
|
|||
|
#发送群聊消息
|
|||
|
$url = 'send_group_msg';
|
|||
|
|
|||
|
#
|
|||
|
$param = array();
|
|||
|
$param['group_id'] = '248553382';#群组号
|
|||
|
$needField = ['account'];
|
|||
|
|
|||
|
$atqq = '389839316';#需要艾特的qq
|
|||
|
$time = '0.5'; #超时拦截时间
|
|||
|
$atqq1 = '530979976';#需要艾特的qq1
|
|||
|
$atqq2 = '1438565523';#技术核实
|
|||
|
|
|||
|
$get_timeout_order = $this->transOrder($time);
|
|||
|
|
|||
|
// $get_timeout_order ='测试';
|
|||
|
if(!$get_timeout_order){
|
|||
|
// Log::write('robot', 'qqbot', '无');
|
|||
|
// Log::write($key, $name, $content)
|
|||
|
die;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
|
|||
|
$param['message'] = "[CQ:at,qq=".$atqq."][CQ:at,qq=".$atqq1."][CQ:at,qq=".$atqq2."] 以下为半小时内超时订单,异常订单,请核实 \r ".$get_timeout_order;
|
|||
|
|
|||
|
|
|||
|
$send = $this->send($url, $param);
|
|||
|
|
|||
|
|
|||
|
Log::write('robot', 'qqbot', $send);
|
|||
|
|
|||
|
|
|||
|
|
|||
|
return $send;
|
|||
|
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
#回调消息处理
|
|||
|
public function notify()
|
|||
|
{
|
|||
|
$input = input();
|
|||
|
var_dump($input);die;
|
|||
|
Log::write('robot', 'qqbot', $input);
|
|||
|
if(isset($input['group_id'])&&$input['group_id']='300904161'&&isset($input['message']['0']['data']['qq'])&&$input['message']['0']['qq']='3093978570'){
|
|||
|
$sju = $input['message']['1']['data']['text'];
|
|||
|
if(strlen($phone)!=11){
|
|||
|
return false; }
|
|||
|
if(preg_match("/^1[3456789]{1}[0-9]{9}$/",$phone)){
|
|||
|
return true;
|
|||
|
}else{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
|
|||
|
$reply = array(
|
|||
|
'reply' => '已经登记拦截'
|
|||
|
);
|
|||
|
// print_r(json_encode($ksorderfk));exit;
|
|||
|
|
|||
|
throw new HttpResponseException(json($reply));
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
#手机状态监控
|
|||
|
public function phoneInfo()
|
|||
|
{
|
|||
|
#发送群聊消息
|
|||
|
$url = 'get_device_battery';
|
|||
|
#
|
|||
|
$param = array();
|
|||
|
$send = $this->send($url, $param);
|
|||
|
$data = json_decode($send,true);
|
|||
|
|
|||
|
if($data['status'] =='ok'){
|
|||
|
#更新电池状态
|
|||
|
#TODO
|
|||
|
if($data['data']['battery'] <= '20'){
|
|||
|
#判断如果电池电量小于20,则发送钉钉机器人提醒。
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}else{
|
|||
|
#状态不为ok,发送钉钉机器人预警,并且记录日志
|
|||
|
}
|
|||
|
|
|||
|
return 'ok';
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
}
|