REAPI/app/queue/command/taobao/TaobaoErrorOrderRefund.php

219 lines
7.9 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\queue\command\taobao;
use app\gateway\service\RedisService;
use app\merchant\service\MerchantService;
use app\merchant\service\OrderService;
use app\openapi\controller\Coretb;
use app\robot\controller\api\Qqbot;
use dever\Log;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
use think\Collection;
/**
* 库存不足自动下架
* Class KamiOrderStatusSync
* @package app\data\command
*/
class TaobaoErrorOrderRefund extends Command
{
protected $redis = false;
protected function configure()
{
$this->setName('xQueue:TaobaoErrorOrderRefund')->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();
$orderService = OrderService::instance();
$where1 = [
'status' => '3' ,
];
$where[] = [
'product_key','like','%cardbuy%'
];
$ck[] = [
'response','like','%ret_msg%'
];
$ck1[] = [
'create_at','>',date("Y-m-d H:i:s",strtotime(date("Y-m-d H:i:s")) - 10)
];
$field = "id,order_id,merchant_order_id,cid,response";//需要数据库返回的字段
list($count, $total) = [0, $orderService->db()->field($field)->where($where1)->where($where)->where($ck)->where($ck1)->order('id desc')->count()];
$mid = '1';
$merchant = MerchantService::instance()->get($mid);
$orderService->db()->field($field)->where($where1)->where($where)->where($ck)->where($ck1)->order('id desc')->chunk(100, function (Collection $data) use (&$count, $total,$merchant) {
// var_dump($orderlist);die;
$array = $data->toArray();
$url = 'send_group_msg';
#
$param = array();
$atqq = '373103766';#需要艾特的qq
$atqq1 = '785557837';
$param['group_id'] = '770225115';#群组号
$send = new Qqbot($this->app);
$up = true;
$json = json_encode($array,JSON_UNESCAPED_UNICODE);
if (str_contains($json,"您的资金不足,请联系您的上级" )) {
$itemId = [
0 => '767466259222',
1 => '767466359547',
2 => '767452201528',
3 => '767450321268',
4 => '767449685071',
5 => '767462566926',
6 => '767461794349',
7 => '767448993185',
8 => '767444593836',
9 => '767372188152',
];
$errorItem = '';
foreach ($itemId as $vo) {
$upItemStatus = $this->DownItemStatus($vo, $merchant['access_token']);
$json = json_encode($upItemStatus);
$array = json_decode($json,true);
if(isset($array['result']) && $array['result'] = 'success'){
$up = false;
}else{
$up = true;
$errorItem = $errorItem." \r " .$vo;
}
}
if(empty($errorItem)){
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密资金不足,已经自动下架全部商品,新及时核实并处理 " ;
$response = $send->send($url, $param);
if (isset($response['status']) && $response['status'] == 'ok') {
$this->setQueueProgress(" 众茂卡密资金不足并通知客服成功", $count / $total * 100);
} else {
$this->setQueueProgress(" 众茂卡密资金不足并通知客服失败", $count / $total * 100);
}
}else{
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密资金不足,已经自动下架部分商品,还有商品 ".$errorItem."没有下架成功,,新及时核实并处理 " ;
$response = $send->send($url, $param);
if (isset($response['status']) && $response['status'] == 'ok') {
$this->setQueueProgress(" 众茂卡密资金不足并通知客服成功", $count / $total * 100);
} else {
$this->setQueueProgress(" 众茂卡密资金不足并通知客服失败", $count / $total * 100);
}
}
}
if (str_contains($json,"限购" )) {
$itemId = [
0 => '767466259222',
1 => '767466359547',
2 => '767452201528',
3 => '767450321268',
4 => '767449685071',
5 => '767462566926',
6 => '767461794349',
7 => '767448993185',
8 => '767444593836',
9 => '767372188152',
];
$errorItem = '';
if($up){
foreach ($itemId as $vo) {
$upItemStatus = $this->DownItemStatus($vo, $merchant['access_token']);
$json = json_encode($upItemStatus);
$array = json_decode($json,true);
if(isset($array['result']) && $array['result'] = 'success'){
$up = false;
}else{
$errorItem = $errorItem." \r " .$vo;
}
}
if(empty($errorItem)){
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密出现限购,已经自动下架全部商品,请及时核实并处理 " ;
$response = $send->send($url, $param);
if (isset($response['status']) && $response['status'] == 'ok') {
$this->setQueueProgress(" 众茂卡密出现限购并通知客服成功", $count / $total * 100);
} else {
$this->setQueueProgress(" 众茂卡密出现限购并通知客服失败", $count / $total * 100);
}
}else{
$param['message'] = "[CQ:at,qq=" . $atqq . "][CQ:at,qq=" . $atqq1 . "] 众茂卡密出现限购,已经自动下架部分商品,还有商品 ".$errorItem."没有下架成功,请及时核实并处理 " ;
$response = $send->send($url, $param);
if (isset($response['status']) && $response['status'] == 'ok') {
$this->setQueueProgress(" 众茂卡密出现限购并通知客服成功", $count / $total * 100);
} else {
$this->setQueueProgress(" 众茂卡密出现限购并通知客服失败", $count / $total * 100);
}
}
}
}
});
$this->setQueueSuccess("共发现 {$total} 个异常失败订单!");
}
protected function redis()
{
if (!$this->redis) {
$this->redis = RedisService::getInstance();
}
}
public function DownItemStatus($itemId,$access_token)
{
$request = [];
$request['agentId'] = '34615444';
$request['agentkey'] = '2e59a0c00b4fafd9ae46bedced6eccc3';
$request['itemId'] = $itemId;
$request['access_token'] = $access_token;
return Coretb::taobaosdk('itemDownshelf', $request);
}
public function send($url, $param)
{
$geturl = 'http://127.0.0.1:7374/' . $url;
return http_post($geturl, $param);
}
}