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('status' ,'in', '1,4')->count()]; # 卡密订单关联 $kami91server->db()->where('status' ,'in', '1,4')->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); } 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); } }elseif ($vo['status'] == 4){ #此处业务逻辑为,优化同时进单导致后期识别的订单,使用redis进行优化查询处理,待核实,1.状态为处理中的情况下,订单列表是否已成功或者失败或者提单,但是redis依旧存在卡密等待处理的记录 try{ $redis = RedisService::getInstance(); $redis_key = 'Kami_wait_'.$vo['order_id']; $getRedisData = $redis->get($redis_key); if($getRedisData){ $count++; $redis->delete($redis_key); $redis->push('submit', $getRedisData); $this->setQueueProgress("优化重提订单 {$vo['order_id']} ", $count / $total * 100); } }catch (\Exception $e){ } } } }); $this->setQueueSuccess("同步关联 {$count} 个订单完成!"); } }