REAPI/app/queue/command/kami91order/KamiOrderAssociation.php
mzeros 84856367e9 feat(openapi): 新增码速达API接口
- 添加AfterSales类处理售后服务相关接口
- 新增ContentTemplate控制器和模型用于内容模板管理
- 添加diandian渠道服务类
- 更新Feedov控制器和添加FeedovHfAuto命令类
- 新增autoCard视图用于自动发卡设置
2025-03-11 00:17:40 +08:00

91 lines
3.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\queue\command\kami91order;
use app\gateway\service\RedisService;
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()
{
// $this->setName('xQueue:Book');
// $this->setDescription('导入章节内容');
$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();
$where = [
'status' => '1' ,
];
// $where[] = [
// 'product_key','like','%cardbuy%'
// ];
#优化掉无用的like此处全部为需要处理的卡密订单
list($count, $total) = [0, $kami91server->db()->where($where)->count()];
# 阿奇索卡密订单关联
$kami91server->db()->where($where)->chunk(100, function (Collection $data) use (&$count, $total) {
// var_dump($orderlist);die;
foreach ($data->toArray() as $vo) {
$merchant_order_id = $vo['merchant_order_id'];
// $orderService = OrderService::instance();
if(str_ends_with($merchant_order_id, '-00')){
$merchant_order_id = substr($merchant_order_id, 0, -3);
}
$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);
}
}
});
$this->setQueueSuccess("同步关联 {$count} 个订单完成!");
}
}