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} 个订单完成!"); } }