2024-09-29 15:43:18 +08:00
|
|
|
<?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'];
|
|
|
|
}
|
2024-12-29 16:45:54 +08:00
|
|
|
// if(isset($array['timeout_cancel_form'])){
|
|
|
|
// $timeout_cancel = $array['timeout_cancel_form'];
|
|
|
|
// }
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
foreach($channelList as $channel) {
|
2024-12-29 16:45:54 +08:00
|
|
|
if(isset($array['timeout_cancel_form'])){
|
|
|
|
$timeout_cancel = $array['timeout_cancel_form'];
|
2025-01-02 16:08:36 +08:00
|
|
|
$where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['create_at','<=',date('Y-m-d H:i:s',time()-$timeout_cancel)]];
|
2024-12-29 16:45:54 +08:00
|
|
|
|
|
|
|
}else{
|
|
|
|
$where = [['status','=',4],['mid','=',$mid],['cid','=',$channel['id']],['expire_time','<=',date('Y-m-d H:i:s',time()+$timeout_cancel)]];
|
|
|
|
}
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
list($count, $total) = [0, $class->db()->where($where)->order('id asc')->count()];
|
|
|
|
$total_sum += $total;
|
|
|
|
// $data = $class->db()->where($where)->limit(100)->select()->toArray();
|
2024-11-02 15:27:08 +08:00
|
|
|
$class->db()->where($where)->order('id asc')->chunk(100, function (Collection $data) use (&$count, $total,$channel,$channelService,&$count_sum,$class) {
|
2024-09-29 15:43:18 +08:00
|
|
|
$array = $data->toArray();
|
2024-12-29 16:45:54 +08:00
|
|
|
if($array){
|
|
|
|
|
|
|
|
foreach ($array as $k => $vo) {
|
2025-01-02 16:08:36 +08:00
|
|
|
$class->db()->where(['order_id'=>$vo['order_id']] )->update(['apply_refund'=>1]);
|
2024-12-29 16:45:54 +08:00
|
|
|
if(isset($vo['num']) && $vo['num']>0) {
|
|
|
|
$vo['order_id'] = $vo['order_id'].'_'.$vo['num'];
|
|
|
|
}
|
|
|
|
|
2025-01-02 16:08:36 +08:00
|
|
|
|
2024-12-29 16:45:54 +08:00
|
|
|
$result = $channelService->call('cancel', $vo['cid'], $vo);
|
|
|
|
if ($result) {
|
|
|
|
$count_sum++;
|
|
|
|
$count++;
|
|
|
|
$this->setQueueProgress("拦截 {$vo['order_id']} 订单成功", $count / $total * 100);
|
|
|
|
}
|
2024-09-29 15:43:18 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-12-29 16:45:54 +08:00
|
|
|
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->setQueueSuccess("共处理 {$merchantList_num} 个商家,共有 {$total_sum} 个订单处理查询中, 完成{$count_sum} 个订单查询新状态更新!");
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|