REAPI/app/queue/command/kami91order/KamiOrderTimeoutRefund.php

68 lines
1.8 KiB
PHP
Raw Normal View History

2024-09-29 15:43:18 +08:00
<?php
namespace app\queue\command\kami91order;
use app\merchant\service\OrderService;
//use app\order\service\Kami91OrderService;
use think\admin\Command;
use think\console\Input;
use think\console\Output;
use think\Collection;
/**
* 超时订单退款
* Class KamiOrderTimeoutRefund
* @package app\data\command
*/
class KamiOrderTimeoutRefund extends Command
{
protected function configure()
{
// $this->setName('xQueue:Book');
// $this->setDescription('导入章节内容');
$this->setName('xQueue:KamiOrderTimeoutRefund')->setDescription('[ 卡密列表 - 自动同步 ] 超时订单退款');
}
/**
* @param Input $input
* @param Output $output
* @throws \think\admin\Exception
*/
protected function execute(Input $input, Output $output)
{
ini_set('memory_limit', '1024M');
$orderService = OrderService::instance();
$cur = time();
$time = 60 * '2';
$whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time;
list($count, $total) = [0, $orderService->db()->whereRaw('status = 1 and ' . $whereRaw)->count()];
$orderService->db()->whereRaw('status = 1 and ' . $whereRaw)->chunk(100, function (Collection $data) use (&$count, $total, $orderService) {
// var_dump($orderlist);die;
foreach ($data->toArray() as $vo) {
if ($vo['request'] && $vo['status'] == 1) {
$count++;
$vo['request'] = json_decode($vo['request'], true);
\app\order\service\OrderService::instance()->setCallback(1, $vo['order_id'], 3);
}
$this->setQueueProgress("超时订单退款 {$vo['order_id']} ", $count / $total * 100);
}
});
$this->setQueueSuccess("完成 {$count} 个超时订单退款!");
}
}