REAPI/app/queue/command/kami91order/KamiOrderChanelNotify.php
mzeros b8c34de8c8 refactor(merchant): 优化账户数据处理和订单逻辑
- 添加 endsWithDoubleZero 函数,用于处理数值字符串末尾的两个零
- 修改 Core.php 中的 queue 方法,增加对卡库提单的特殊处理逻辑
-调整 Feedov.php 中的订单查询和充值逻辑,提高系统稳定性
- 优化数据库配置,连接测试数据库以确保数据安全
2025-02-15 19:00:17 +08:00

237 lines
9.2 KiB
PHP

<?php
namespace app\queue\command\kami91order;
use app\merchant\service\MerchantService;
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 KamiOrderStatusSync
* @package app\data\command
*/
class KamiOrderChanelNotify extends Command
{
protected function configure()
{
// $this->setName('xQueue:Book');
// $this->setDescription('导入章节内容');
$this->setName('xQueue:KamiOrderChanelNotify')->setDescription('[ 卡密列表 - 自动同步 ] 对cardbuy购置的卡密同步响应数据进行异步处理订单回调状态');
}
/**
* @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%'
];
list($count, $total) = [0, $orderService->db()->where($where)->where($where1)->count()];
$kami91server = Kami91OrderService::instance();
$agiso =new \app\openapi\controller\agisoAcprSupplierApi\Order($this->app);
$kami91 =new \app\openapi\controller\Kami91($this->app);
$MerchantService = MerchantService::instance();
$orderService->db()->where($where)->where($where1)->chunk(100, function (Collection $data) use (&$count, $total,$kami91server,$agiso,$MerchantService,$kami91) {
// var_dump($orderlist);die;
foreach ($data->toArray() as $vo) {
$info = $kami91server->db()->where(['order_id' => $vo['order_id']])->find();
if($info){
$count++;
if(isset($info['status'])){
$getMerchantInfo = $MerchantService->get($vo['mid']);
if($info['status'] == 4){
if($vo['status'] == 2 || $vo['status'] == 7){
$request_data = [];
if(empty($info['cardno'])){
$response = json_decode($vo['response'],true);
if(isset($response['kami'])) {
$cardno = $response['kami']['cardno'];
$cardpwd = $response['kami']['cardpwd'];
$expire_time = $this->validateExpireTime($response['kami']['expired']);
// $expire_time= $response['kami']['expired'];
// $expire_time = null;
$kami = [
'cardno' =>$cardno,
'cardpwd' =>$cardpwd,
'expire_time' =>$expire_time,
];
$kami['status'] = 6;
$where = [
'order_id' => $vo['order_id']
];
$result = $kami91server->up($where,$kami);
}elseif(isset($vo['channel_callback_msg']) && str_contains($vo['channel_callback_msg'], "kami")){
$msg = json_decode($vo['channel_callback_msg'],true);
$cardno = $msg['kami']['cardno'];
$cardpwd = $msg['kami']['cardpwd'];
$expire_time = $this->validateExpireTime($msg['kami']['expired']);
// $expire_time= $msg['kami']['expired'];
// $expire_time = null;
$kami = [
'cardno' =>$cardno,
'cardpwd' =>$cardpwd,
'expire_time' =>$expire_time,
];
$kami['status'] = 6;
$where = [
'order_id' => $vo['order_id']
];
$result =$kami91server->up($where,$kami);
}
}else{
$kami = [
'cardno' => $info['cardno'],
'cardpwd' => $info['cardpwd'],
'expire_time' => $info['expire_time']
];
$where = [
'order_id' => $vo['order_id']
];
$result =$kami91server->up($where,['status' => 6]);
}
$param = [
'order_id' => $vo['order_id'],
'merchant_order_id'=> $info['merchant_order_id'],
'status' => 2,
'actual_cash'=>$vo['actual_cash'],
];
if(!isset($kami)){
// $param['status'] =3;
}else{
$kami['expired'] = $kami['expire_time'];
$param['kami'] = $kami;
}
$up_msg=$agiso->notify($info['notifyurl'], $param,$getMerchantInfo);
if($up_msg == 'success'){
$kami91server->upStatus($vo['order_id'], 2, $up_msg);
$agiso->huidiao($vo['order_id']);
}
}
}
if($info['status'] == '6') {
$create_at = strtotime($info['create_at']) ;
if($info['callback_msg'] != 'success' && $create_at > time() - 600){
if(isset($info['cardno']) && $info['cardno']){
$kami = [
'cardno' => $info['cardno'],
'cardpwd' => $info['cardpwd'],
'expired' => $info['expire_time']
];
}
$param = [
'order_id' => $vo['order_id'],
'merchant_order_id'=> $info['merchant_order_id'],
'status' => 2,
'actual_cash'=>$vo['actual_cash'],
];
if(!isset($kami)){
// $param['status'] =3;
}else{
$param['kami'] = $kami;
}
$up_msg=$agiso->notify($info['notifyurl'], $param,$getMerchantInfo);
if($up_msg == 'success'){
$kami91server->upStatus($vo['order_id'], 2, $up_msg);
$agiso->huidiao($vo['order_id']);
}
}else{
#查询卡的状态是否已发送
$check = $agiso->queryFaka($vo['merchant_order_id']);
if ($check == 'ok') {
$msg = 'success';
if ($vo['response']) {
}
$kami91server->upStatus($vo['order_id'], 2, $msg);
$kami91->huidiao($vo['order_id']);
}
}
}
} elseif (empty($info['cardno'])){
$kami91->uphuidiao($vo['order_id']);
}
$this->setQueueProgress("处理完订单状态 {$vo['order_id']} ", $count / $total * 100);
}
}
});
//
$this->setQueueSuccess("处理完 {$count} 个订单状态完成!");
}
private function validateExpireTime($expireTime)
{
if (strtotime($expireTime) === false) {
return null;
}
return $expireTime;
}
}