2024-09-29 15:43:18 +08:00
< ? php
namespace app\queue\command\kami91order ;
use app\channel\service\ChannelService ;
use app\kami\service\LockCardService ;
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 KamiOrderStatusForceUpdate extends Command
{
protected function configure ()
{
// $this->setName('xQueue:Book');
// $this->setDescription('导入章节内容');
$this -> setName ( 'xQueue:KamiOrderStatusForceUpdate' ) -> 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 ();
// $where1 = [
// 'status' => 7
// ];
$where [] = [
'product_key' , 'like' , '%cardbuy%'
];
$cur = time ();
2025-06-03 18:55:03 +08:00
$time = 300 ;
2024-09-29 15:43:18 +08:00
$whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time ;
$channelService = ChannelService :: instance ();
list ( $count , $total ) = [ 0 , $orderService -> db () -> where ( $where ) -> whereRaw ( 'status = 7 and ' . $whereRaw ) -> count ()];
$LockCardService = LockCardService :: instance ();
$orderService -> db () -> where ( $where ) -> whereRaw ( 'status = 7 and ' . $whereRaw ) -> chunk ( 10 , function ( Collection $data ) use ( & $count , $total , $orderService , $channelService , $LockCardService ) {
// var_dump($orderlist);die;
foreach ( $data -> toArray () as $vo ) {
$count ++ ;
$channelInfo = $channelService -> get ( $vo [ 'cid' ]);
2025-03-17 03:38:44 +08:00
$response = $vo [ 'response' ] ? ? [];
if ( isset ( $response )){
$response = json_decode ( $response , true );
if ( ! is_array ( $response )){
$response = [];
}
}
2024-09-29 15:43:18 +08:00
if ( $channelInfo [ 'suoka_status' ] == 1 ){
if ( isset ( $response [ 'kami' ])) {
$suoka = $channelService -> call ( 'lockCard' , $vo [ 'cid' ], $vo );
if ( $suoka == 'ok' || $suoka == 'old_ok' ){
2025-06-03 18:55:03 +08:00
$orderService -> db () -> where ([ 'merchant_order_id' => $vo [ 'merchant_order_id' ]]) -> update ([ 'status' => 3 , 'merchant_callback_error' => 2 , 'channel_callback_at' => date ( 'Y-m-d H:i:s' ), 'channel_callback_msg' => json_encode ([ 'is_auto' => 1 , 'msg' => '自动化处理,已锁卡' ])]);
2024-09-29 15:43:18 +08:00
$this -> setQueueProgress ( " 订单 { $vo [ 'order_id' ] } 已经锁卡并退款处理 " , $count / $total * 100 );
} else {
2025-06-03 18:55:03 +08:00
$orderService -> db () -> where ([ 'merchant_order_id' => $vo [ 'merchant_order_id' ]]) -> update ([ 'status' => 2 , 'merchant_callback_error' => 2 , 'channel_callback_at' => date ( 'Y-m-d H:i:s' ), 'channel_callback_msg' => json_encode ([ 'is_auto' => 1 , 'msg' => '自动化处理,锁卡失败' ])]);
2024-09-29 15:43:18 +08:00
2025-06-03 18:55:03 +08:00
$this -> setQueueProgress ( " 订单 { $vo [ 'order_id' ] } 调用锁卡,锁卡失败,成功处理 " , $count / $total * 100 );
2024-09-29 15:43:18 +08:00
}
} else {
2025-06-03 18:55:03 +08:00
$orderService -> db () -> where ([ 'merchant_order_id' => $vo [ 'merchant_order_id' ]]) -> update ([ 'status' => 2 , 'merchant_callback_error' => 2 , 'channel_callback_at' => date ( 'Y-m-d H:i:s' ), 'channel_callback_msg' => json_encode ([ 'is_auto' => 1 , 'msg' => '自动化处理,无卡密信息,无法确定资损,成功处理' ])]);
2024-09-29 15:43:18 +08:00
2025-06-03 18:55:03 +08:00
$this -> setQueueProgress ( " 订单 { $vo [ 'order_id' ] } 无卡密信息,成功处理 " , $count / $total * 100 );
2024-09-29 15:43:18 +08:00
}
} elseif ( $channelInfo [ 'suoka_status' ] == 2 ){
if ( isset ( $response [ 'kami' ])) {
$cardno = $response [ 'kami' ][ 'cardno' ];
$cardpwd = $response [ 'kami' ][ 'cardpwd' ];
$expire_time = $response [ 'kami' ][ 'expired' ];
$suoka = $LockCardService -> call ( 'suoka' , $vo [ 'cid' ], $cardno , $cardpwd , $vo [ 'pid' ], $vo [ 'cash' ]);
if ( $suoka == 'ok' || $suoka == 'old_ok' ){
//
2025-06-03 18:55:03 +08:00
$orderService -> db () -> where ([ 'merchant_order_id' => $vo [ 'merchant_order_id' ]]) -> update ([ 'status' => 3 , 'merchant_callback_error' => 2 , 'channel_callback_at' => date ( 'Y-m-d H:i:s' ), 'channel_callback_msg' => json_encode ([ 'is_auto' => 1 , 'msg' => '自动化处理,已锁卡' ])]);
2024-09-29 15:43:18 +08:00
$this -> setQueueProgress ( " 订单 { $vo [ 'order_id' ] } 已经锁卡并退款处理 " , $count / $total * 100 );
} else {
2025-06-03 18:55:03 +08:00
$orderService -> db () -> where ([ 'merchant_order_id' => $vo [ 'merchant_order_id' ]]) -> update ([ 'status' => 2 , 'merchant_callback_error' => 2 , 'channel_callback_at' => date ( 'Y-m-d H:i:s' ), 'channel_callback_msg' => json_encode ([ 'is_auto' => 1 , 'msg' => '自动化处理,锁卡失败' ])]);
2024-09-29 15:43:18 +08:00
2025-06-03 18:55:03 +08:00
$this -> setQueueProgress ( " 订单 { $vo [ 'order_id' ] } 调用锁卡,锁卡失败,成功处理 " , $count / $total * 100 );
2024-09-29 15:43:18 +08:00
}
} else {
2025-06-03 18:55:03 +08:00
$orderService -> db () -> where ([ 'merchant_order_id' => $vo [ 'merchant_order_id' ]]) -> update ([ 'status' => 2 , 'merchant_callback_error' => 2 , 'channel_callback_at' => date ( 'Y-m-d H:i:s' ), 'channel_callback_msg' => json_encode ([ 'is_auto' => 1 , 'msg' => '自动化处理,无卡密信息,无法确定资损,成功处理' ])]);
2024-09-29 15:43:18 +08:00
2025-06-03 18:55:03 +08:00
$this -> setQueueProgress ( " 订单 { $vo [ 'order_id' ] } 无卡密信息,成功处理 " , $count / $total * 100 );
2024-09-29 15:43:18 +08:00
}
} else {
2025-06-03 18:55:03 +08:00
$orderService -> db () -> where ([ 'merchant_order_id' => $vo [ 'merchant_order_id' ]]) -> update ([ 'status' => 2 , 'merchant_callback_error' => 2 , 'channel_callback_at' => date ( 'Y-m-d H:i:s' ), 'channel_callback_msg' => json_encode ([ 'is_auto' => 1 , 'msg' => '自动化处理,渠道不支持锁卡,成功处理' ])]);
2024-09-29 15:43:18 +08:00
2025-06-03 18:55:03 +08:00
$this -> setQueueProgress ( " 订单 { $vo [ 'order_id' ] } 渠道不支持锁卡,成功处理 " , $count / $total * 100 );
2024-09-29 15:43:18 +08:00
}
}
});
$this -> setQueueSuccess ( " 处理 { $count } 个订单状态完成! " );
}
}