233 lines
9.0 KiB
PHP
233 lines
9.0 KiB
PHP
<?php
|
|
|
|
namespace app\queue\command\kuaishou;
|
|
|
|
|
|
use app\gateway\service\RedisService;
|
|
|
|
use app\merchant\service\OrderHistoryService;
|
|
use app\merchant\service\OrderLastHistoryService;
|
|
use app\merchant\service\OrderLastweekHistoryService;
|
|
use app\merchant\service\OrderService;
|
|
use app\merchant\service\OrderTwoHistoryService;
|
|
use app\robot\controller\api\Qqbot;
|
|
use dever\Log;
|
|
use think\admin\Command;
|
|
use think\console\Input;
|
|
use think\console\Output;
|
|
use think\Collection;
|
|
use think\facade\Db;
|
|
|
|
/**
|
|
* 快手商家更新令牌
|
|
* Class KamiOrderStatusSync
|
|
* @package app\data\command
|
|
*/
|
|
class KsBotInterceptNotify extends Command
|
|
{
|
|
protected $redis = false;
|
|
protected function configure()
|
|
{
|
|
$this->setName('xQueue:KsBotInterceptNotify')->setDescription('[ 快手商家 ] 查询拦截订单定时推送并反馈');
|
|
}
|
|
|
|
/**
|
|
* @param Input $input
|
|
* @param Output $output
|
|
* @throws \think\admin\Exception
|
|
*/
|
|
protected function execute(Input $input, Output $output)
|
|
{
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
// Db::name('merchant_order_lj')->where('order_id','=', $value['order_id'])->find()
|
|
|
|
|
|
// $cur = time();
|
|
// $time = 180;
|
|
// $whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time;
|
|
|
|
|
|
list($count, $total) = [0, Db::name('merchant_order_lj')->whereRaw('status = 4')->count()];
|
|
$countFaild = 0;
|
|
$countSuccess = 0 ;
|
|
|
|
|
|
Db::name('merchant_order_lj')->whereRaw('status = 4')->chunk(100, function (Collection $data) use (&$count, $total,&$countFaild,&$countSuccess) {
|
|
|
|
// var_dump($orderlist);die;
|
|
$url = 'send_group_msg';
|
|
$param = array();
|
|
$qqBotService = new Qqbot($this->app);
|
|
|
|
foreach ($data->toArray() as $vo) {
|
|
$count++;
|
|
$orderInfo = $this->getOrder($vo['order_id']);
|
|
if ($orderInfo['status'] == '2') {
|
|
$countFaild++;
|
|
$update = [
|
|
'status' => 3
|
|
];
|
|
Db::name('merchant_order_lj')->where('order_id', '=', $vo['order_id'])->update($update);
|
|
|
|
$param['group_id'] = '687976099';#群组号
|
|
$atqq = '949734474';
|
|
|
|
$param['message'] = "[CQ:at,qq=" . $atqq . "] " . $vo['account'] . " 拦截失败,已经充值成功。 ";
|
|
$send = $qqBotService->send($url, $param);
|
|
if (isset($send['status']) && $send['status'] == 'ok') {
|
|
$this->setQueueProgress(" {$vo['order_id']} 拦截失败并通知客服", $count / $total * 100);
|
|
} else {
|
|
$this->setQueueProgress(" {$vo['order_id']} 拦截失败机器人异常,未发生通知", $count / $total * 100);
|
|
}
|
|
|
|
} elseif ($orderInfo['status'] == '3') {
|
|
$countSuccess++;
|
|
$update = [
|
|
'status' => 2
|
|
];
|
|
Db::name('merchant_order_lj')->where('order_id', '=', $vo['order_id'])->update($update);
|
|
$this->setQueueProgress(" {$vo['order_id']} 拦截成功", $count / $total * 100);
|
|
|
|
// $param['group_id'] = '869366904';#群组号
|
|
// $atqq = '949734474';
|
|
//
|
|
// $param['message'] = "[CQ:at,qq=".$atqq."] ".$vo['account']." 拦截成功,系统正在操作退款。 ";
|
|
// $send = $this->send($url, $param);
|
|
// if(isset($send['status']) && $send['status'] == 'ok'){
|
|
// $this->setQueueProgress(" {$vo['order_id']} 拦截失败并通知客服", $count / $total * 100);
|
|
// }else{
|
|
// $this->setQueueProgress(" {$vo['order_id']} 拦截失败机器人异常,未发生通知", $count / $total * 100);
|
|
// }
|
|
} elseif ($orderInfo['status'] == '4') {
|
|
$this->redis();
|
|
|
|
$is_send=true;
|
|
|
|
if ($this->redis->get('rediskey-' . $vo['order_id'])) {
|
|
$is_send = false;
|
|
}
|
|
// $timeout_staus = 2;
|
|
if ($this->redis->get('rediskey-1H-' . $vo['order_id'])) {
|
|
$is_send = false;
|
|
}
|
|
|
|
//
|
|
if ($this->redis->get('rediskey-TOP-' . $vo['order_id'])) {
|
|
$is_send = false;
|
|
}
|
|
|
|
if (!$this->redis->get('rediskey-lj-' . $vo['order_id'])) {
|
|
|
|
if($vo['cid']==6){
|
|
$url = 'https://d.reapi.bao111.com/gateway/api.bxtlanjie/order';
|
|
|
|
if(isset($value['order_id']) && $value['order_id']){
|
|
try {
|
|
|
|
#推送到redis队列
|
|
$msg = http_post($url, $value);
|
|
// var_dump($msg);
|
|
// var_dump($msg);
|
|
if($msg != 'ok'){
|
|
Log::write('gateway', 'failorder_d', $value);
|
|
}else{
|
|
$send=['status'=>'ok'] ;
|
|
}
|
|
|
|
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
Log::write('errorTip', 'failorder_d', $e->getMessage());
|
|
}
|
|
}
|
|
}elseif($is_send){
|
|
$chanelGroup = $qqBotService->getChanelGroup($vo['cid'], $vo['mid']);
|
|
$param['group_id'] = $chanelGroup['group_id'];#群组号
|
|
$cur = time();
|
|
$create_at= strtotime($vo['create_at']);
|
|
$cssj = $cur - $create_at;
|
|
// $cssj = $cur . '-unix_timestamp(create_at)';
|
|
$numtiem = 600;
|
|
$num = intval($cssj / $numtiem);
|
|
|
|
if ($num > 10) {
|
|
$param['message'] = $chanelGroup['atqq'] . "[CQ:at,qq=530979976] 请人工介入核实,以下为客户申请拦截订单,此次为第" . $num . "次提醒,请优先处理 \r " . $vo['account'];
|
|
$send = $qqBotService->send($url, $param);
|
|
} elseif ($num <= 1) {
|
|
$send = ['status'=>'ok'];
|
|
|
|
}else {
|
|
$param['message'] = $chanelGroup['atqq'] . " 以下为客户申请拦截订单,此次为第" . $num . "次提醒,请优先处理 \r " . $vo['account'];
|
|
$send = $qqBotService->send($url, $param);
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
if (isset($send['status']) && $send['status'] == 'ok') {
|
|
$this->setQueueProgress(" {$vo['order_id']} 重新拦截并推送渠道成功", $count / $total * 100);
|
|
} elseif(!$is_send) {
|
|
$this->setQueueProgress(" {$vo['order_id']} 为机器人超时拦截,停止推送", $count / $total * 100);
|
|
}else {
|
|
$this->setQueueProgress(" {$vo['order_id']} 重新拦截并推送渠道失败", $count / $total * 100);
|
|
}
|
|
$this->redis->set('rediskey-lj-' . $vo['order_id'], '1', 10 * 60);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
});
|
|
$chulizhong = $count - $countSuccess - $countFaild;
|
|
$this->setQueueSuccess("总计 {$total} 个拦截订单, 拦截成功 {$countSuccess} 个订单,失败 {$countFaild} 笔订单 ,还有 {$chulizhong}正在拦截!");
|
|
}
|
|
|
|
protected function getOrder($order_id)
|
|
{
|
|
$orderService = OrderService::instance();
|
|
$order = $orderService->get($order_id);
|
|
if (!$order) {
|
|
$orderLastweekHistoryService = OrderLastweekHistoryService::instance();
|
|
$order = $orderLastweekHistoryService->get($order_id);
|
|
}
|
|
if (!$order) {
|
|
$orderLastHistoryService = OrderLastHistoryService::instance();
|
|
$order = $orderLastHistoryService->get($order_id);
|
|
}
|
|
if (!$order) {
|
|
$orderTwoHistoryService = OrderTwoHistoryService::instance();
|
|
$order = $orderTwoHistoryService->get($order_id);
|
|
}
|
|
if (!$order) {
|
|
$orderHistoryService = OrderHistoryService::instance();
|
|
$order = $orderHistoryService->get($order_id);
|
|
}
|
|
return $order;
|
|
}
|
|
|
|
# 查找订单
|
|
|
|
public function send($url, $param)
|
|
{
|
|
$geturl = 'http://127.0.0.1:7374/' . $url;
|
|
return http_post($geturl, $param);
|
|
|
|
}
|
|
|
|
protected function redis()
|
|
{
|
|
if (!$this->redis) {
|
|
$this->redis = RedisService::getInstance();
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|