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

86 lines
2.4 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\queue\command\taobao;
use app\merchant\service\MerchantService;
use app\merchant\service\OrderService;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
use think\Collection;
/**
* 主动更新退款订单详情
* Class KamiOrderStatusSync
* @package app\data\command
*/
class TaobaoFailOrderSecondNotify extends Command
{
protected function configure()
{
$this->setName('xQueue:TaobaoFailOrderSecondNotify')->setDescription('[ 淘宝直充 - 自动同步 ] 失败订单二次通知');
}
/**
* @param Input $input
* @param Output $output
* @throws \think\admin\Exception
*/
protected function execute(Input $input, Output $output)
{
ini_set('memory_limit', '1024M');
$merchants=MerchantService::instance()->db()->where(['merchant_type'=>8,'status'=>1])->select()->toArray();
if(!$merchants) $this->setQueueSuccess("未找到需要处理的天猫商家");
$merchant_num = count($merchants);
$count_sum = 0;
$total_sum=0;
foreach($merchants as $merchant){
$OrderService = OrderService::instance();
$cur = time();
$time = 60*25;
$whereRaw = $cur . '-unix_timestamp(create_at) <=' . $time;
list($count, $total) = [0, $OrderService->db()->whereRaw('status in(2,3) and unix_timestamp(merchant_callback_at) - unix_timestamp(create_at) <= 3 and mid ='.$merchant['id'].' and '.$whereRaw)->whereLike('merchant_callback_msg', 'success')->count()];
$total_sum+=$total;
$OrderService->db()->whereRaw('status in(2,3) and unix_timestamp(merchant_callback_at) - unix_timestamp(create_at) <= 3 and mid ='.$merchant['id'].' and '.$whereRaw)->whereLike('merchant_callback_msg', 'success')->chunk(100, function (Collection $data) use (&$count, $total,$OrderService,&$count_sum) {
foreach ($data->toArray() as $vo) {
$OrderService->callSend($vo, 1, false);
$count++;
$count_sum++;
$this->setQueueProgress("订单二次回调 {$vo['order_id']} ", $count / $total * 100);
}
});
}
$this->setQueueSuccess("共处理 {$merchant_num} 个商家,共获取到个 {$total_sum} 售后退款订单,更新了 {$count_sum} 个售后订单信息!");
}
}