REAPI/app/queue/command/order/OrderCancel.php
mzeros b97c1ffe94 refactor(channel): 新增 Template通道类
- 新增 Template通道类,实现了一些通用的充值和查询功能
- 修改 Mykjapi 类,增加了一些注释和调试代码
- 更新 Order 控制器,增加了订单号的处理逻辑
- 调整 merchantApi/Order 控制器,优化了参数处理
- 修改 OrderCancel命令,增加了条件判断和日志记录
2024-12-29 16:45:54 +08:00

122 lines
3.9 KiB
PHP

<?php
namespace app\queue\command\order;
use app\channel\service\ChannelService;
use app\gateway\controller\api\Notify;
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 OrderCancel
* @package app\data\command
*/
class OrderCancel extends Command
{
protected function configure()
{
$this->setName('xQueue:OrderCancel')->setDescription('[ 订单列表 ] 主动拦截取消订单');
}
/**
* @param Input $input
* @param Output $output
* @throws \think\admin\Exception
*/
protected function execute(Input $input, Output $output)
{
ini_set('memory_limit', '1024M');
$channelService = ChannelService::instance();
$channelList = $channelService->db()->where(['cancel_status'=>1,'status'=>1])->select()->toArray();
if(!$channelList) $this->setQueueSuccess("未找到支持取消的渠道");
$merchantService = MerchantService::instance();
$merchantList = $merchantService->db()->where(['cancel_support'=>1,'status'=>1])->select()->toArray();
if(!$merchantList) $this->setQueueSuccess("未找到支持取消的商家");
$merchantList_num = count($merchantList);
$count_sum = 0;
$total_sum=0;
// $channelList_num = count($channelList);
// $count_sum = 0;
// $total_sum=0;
$class = OrderService::instance();
foreach ($merchantList as $merchant) {
$mid = $merchant['id'];
$other_param = $merchant['other_param'];
$array = json_decode($other_param,true);
$timeout_cancel = 3600;
if(isset($array['timeout_cancel'])){
$timeout_cancel = $array['timeout_cancel'];
}
// if(isset($array['timeout_cancel_form'])){
// $timeout_cancel = $array['timeout_cancel_form'];
// }
foreach($channelList as $channel) {
if(isset($array['timeout_cancel_form'])){
$timeout_cancel = $array['timeout_cancel_form'];
$where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['create_at','>=',date('Y-m-d H:i:s',time()-$timeout_cancel)]];
}else{
$where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['expire_time','<=',date('Y-m-d H:i:s',time()+$timeout_cancel)]];
}
list($count, $total) = [0, $class->db()->where($where)->order('id asc')->count()];
$total_sum += $total;
// $data = $class->db()->where($where)->limit(100)->select()->toArray();
$class->db()->where($where)->order('id asc')->chunk(100, function (Collection $data) use (&$count, $total,$channel,$channelService,&$count_sum,$class) {
$array = $data->toArray();
if($array){
foreach ($array as $k => $vo) {
$class->db()->where(['order_id','=',$vo['order_id']] )->update(['apply_refund'=>1]);
if(isset($vo['num']) && $vo['num']>0) {
$vo['order_id'] = $vo['order_id'].'_'.$vo['num'];
}
$result = $channelService->call('cancel', $vo['cid'], $vo);
if ($result) {
$count_sum++;
$count++;
$this->setQueueProgress("拦截 {$vo['order_id']} 订单成功", $count / $total * 100);
}
}
}
});
}
}
$this->setQueueSuccess("共处理 {$merchantList_num} 个商家,共有 {$total_sum} 个订单处理查询中, 完成{$count_sum} 个订单查询新状态更新!");
}
}