2024-09-29 15:43:18 +08:00
|
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace app\queue\command\kami91order;
|
|
|
|
|
|
|
|
|
|
|
2025-02-15 19:00:17 +08:00
|
|
|
|
use app\gateway\service\RedisService;
|
2024-09-29 15:43:18 +08:00
|
|
|
|
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 Book
|
|
|
|
|
* @package app\data\command
|
|
|
|
|
*/
|
|
|
|
|
class KamiOrderAssociation extends Command
|
|
|
|
|
{
|
|
|
|
|
protected function configure()
|
|
|
|
|
{
|
2025-05-06 15:09:26 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
$this->setName('xQueue:KamiOrderAssociation')->setDescription('[ 卡密列表 - 自动同步 ] 关联系统订单');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param Input $input
|
|
|
|
|
* @param Output $output
|
|
|
|
|
* @throws \think\admin\Exception
|
|
|
|
|
*/
|
|
|
|
|
protected function execute(Input $input, Output $output)
|
|
|
|
|
{
|
|
|
|
|
ini_set('memory_limit', '1024M');
|
|
|
|
|
|
|
|
|
|
$kami91server = Kami91OrderService::instance();
|
2025-05-06 15:09:26 +08:00
|
|
|
|
// $where = [
|
|
|
|
|
// 'status' => '1' ,
|
|
|
|
|
// ];
|
2025-02-15 19:02:39 +08:00
|
|
|
|
// $where[] = [
|
|
|
|
|
// 'product_key','like','%cardbuy%'
|
|
|
|
|
// ];
|
|
|
|
|
#优化掉无用的like,此处全部为需要处理的卡密订单
|
2025-05-06 15:09:26 +08:00
|
|
|
|
list($count, $total) = [0, $kami91server->db()->where('status' ,'in', '1,4')->count()];
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
2025-05-06 15:09:26 +08:00
|
|
|
|
# 卡密订单关联
|
|
|
|
|
$kami91server->db()->where('status' ,'in', '1,4')->chunk(100, function (Collection $data) use (&$count, $total) {
|
2024-09-29 15:43:18 +08:00
|
|
|
|
// var_dump($orderlist);die;
|
|
|
|
|
foreach ($data->toArray() as $vo) {
|
2025-02-15 19:00:17 +08:00
|
|
|
|
$merchant_order_id = $vo['merchant_order_id'];
|
2024-09-29 15:43:18 +08:00
|
|
|
|
|
|
|
|
|
// $orderService = OrderService::instance();
|
2025-02-15 19:00:17 +08:00
|
|
|
|
if(str_ends_with($merchant_order_id, '-00')){
|
|
|
|
|
$merchant_order_id = substr($merchant_order_id, 0, -3);
|
|
|
|
|
}
|
2025-05-06 15:09:26 +08:00
|
|
|
|
if($vo['status'] == 1 ){
|
|
|
|
|
$order = OrderService::instance()->get('', $merchant_order_id, $vo['mid']);
|
|
|
|
|
|
|
|
|
|
if ($order) {
|
|
|
|
|
$count++;
|
|
|
|
|
$upData = array();
|
|
|
|
|
$upData['order_id'] = $order['order_id'];
|
|
|
|
|
$upData['status'] = 4;
|
|
|
|
|
if($vo['pid'] == '999999'){
|
|
|
|
|
#此为默认卡密订单无用,需要更新产品信息
|
|
|
|
|
$upData['product_key'] = $order['product_key'];
|
|
|
|
|
$upData['pid'] = $order['pid'];
|
|
|
|
|
}
|
|
|
|
|
Kami91OrderService::instance()->db()->where(array('merchant_order_id' => $vo['merchant_order_id']))->update($upData);
|
|
|
|
|
try{
|
|
|
|
|
$redis = RedisService::getInstance();
|
|
|
|
|
$redis_key = 'Kami_wait_'.$order['order_id'];
|
|
|
|
|
$getRedisData = $redis->get($redis_key);
|
|
|
|
|
if($getRedisData){
|
|
|
|
|
$redis->delete($redis_key);
|
|
|
|
|
$redis->push('submit', $getRedisData);
|
|
|
|
|
}
|
|
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
$this->setQueueProgress("同步关联订单 {$vo['order_id']} ", $count / $total * 100);
|
2025-02-15 19:02:39 +08:00
|
|
|
|
}
|
2025-05-06 15:09:26 +08:00
|
|
|
|
}elseif ($vo['status'] == 4){
|
|
|
|
|
#此处业务逻辑为,优化同时进单导致后期识别的订单,使用redis进行优化查询处理,待核实,1.状态为处理中的情况下,订单列表是否已成功或者失败或者提单,但是redis依旧存在卡密等待处理的记录
|
2025-02-15 19:00:17 +08:00
|
|
|
|
try{
|
|
|
|
|
$redis = RedisService::getInstance();
|
2025-05-06 15:09:26 +08:00
|
|
|
|
$redis_key = 'Kami_wait_'.$vo['order_id'];
|
2025-02-15 19:00:17 +08:00
|
|
|
|
$getRedisData = $redis->get($redis_key);
|
|
|
|
|
if($getRedisData){
|
2025-05-06 15:09:26 +08:00
|
|
|
|
$count++;
|
2025-02-15 19:00:17 +08:00
|
|
|
|
$redis->delete($redis_key);
|
|
|
|
|
$redis->push('submit', $getRedisData);
|
2025-05-06 15:09:26 +08:00
|
|
|
|
$this->setQueueProgress("优化重提订单 {$vo['order_id']} ", $count / $total * 100);
|
2025-02-15 19:00:17 +08:00
|
|
|
|
}
|
|
|
|
|
}catch (\Exception $e){
|
|
|
|
|
|
|
|
|
|
}
|
2025-05-06 15:09:26 +08:00
|
|
|
|
|
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
}
|
2025-05-06 15:09:26 +08:00
|
|
|
|
|
2024-09-29 15:43:18 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
$this->setQueueSuccess("同步关联 {$count} 个订单完成!");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|