setName('xQueue:Book'); // $this->setDescription('导入章节内容'); $this->setName('xQueue:KamiOrderStatusForceUpdate')->setDescription('[ 淘宝订单 - 自动同步 ] 强行更新'); } /** * @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%' ]; $cur = time(); $time = 300; $whereRaw = $cur . '-unix_timestamp(create_at) >=' . $time; $channelService = ChannelService::instance(); list($count, $total) = [0, $orderService->db()->where($where)->whereRaw('status = 7 and ' . $whereRaw)->count()]; $LockCardService = LockCardService::instance(); $orderService->db()->where($where)->whereRaw('status = 7 and ' . $whereRaw)->chunk(10, function (Collection $data) use (&$count, $total, $orderService,$channelService,$LockCardService) { // var_dump($orderlist);die; foreach ($data->toArray() as $vo) { $count++; $channelInfo = $channelService->get($vo['cid']); $response = $vo['response']??[]; if(isset($response)){ $response = json_decode($response,true); if(!is_array($response)){ $response = []; } } if($channelInfo['suoka_status'] == 1){ if (isset($response['kami'])) { $suoka = $channelService->call('lockCard', $vo['cid'], $vo); if($suoka == 'ok' || $suoka == 'old_ok'){ $orderService->db()->where(['merchant_order_id'=>$vo['merchant_order_id']])->update(['status'=>3,'merchant_callback_error'=>2,'channel_callback_at'=>date('Y-m-d H:i:s'),'channel_callback_msg'=>json_encode(['is_auto'=>1,'msg'=>'自动化处理,已锁卡'])]); $this->setQueueProgress("订单 {$vo['order_id']} 已经锁卡并退款处理", $count / $total * 100); }else{ $orderService->db()->where(['merchant_order_id'=>$vo['merchant_order_id']])->update(['status'=>2,'merchant_callback_error'=>2,'channel_callback_at'=>date('Y-m-d H:i:s'),'channel_callback_msg'=>json_encode(['is_auto'=>1,'msg'=>'自动化处理,锁卡失败'])]); $this->setQueueProgress("订单 {$vo['order_id']} 调用锁卡,锁卡失败,成功处理", $count / $total * 100); } }else{ $orderService->db()->where(['merchant_order_id'=>$vo['merchant_order_id']])->update(['status'=>2,'merchant_callback_error'=>2,'channel_callback_at'=>date('Y-m-d H:i:s'),'channel_callback_msg'=>json_encode(['is_auto'=>1,'msg'=>'自动化处理,无卡密信息,无法确定资损,成功处理'])]); $this->setQueueProgress("订单 {$vo['order_id']} 无卡密信息,成功处理", $count / $total * 100); } }elseif($channelInfo['suoka_status'] == 2){ if (isset($response['kami'])) { $cardno = $response['kami']['cardno']; $cardpwd = $response['kami']['cardpwd']; $expire_time = $response['kami']['expired']; $suoka = $LockCardService->call('suoka', $vo['cid'],$cardno,$cardpwd,$vo['pid'],$vo['cash']); if($suoka == 'ok' || $suoka == 'old_ok'){ // $orderService->db()->where(['merchant_order_id'=>$vo['merchant_order_id']])->update(['status'=>3,'merchant_callback_error'=>2,'channel_callback_at'=>date('Y-m-d H:i:s'),'channel_callback_msg'=>json_encode(['is_auto'=>1,'msg'=>'自动化处理,已锁卡'])]); $this->setQueueProgress("订单 {$vo['order_id']} 已经锁卡并退款处理", $count / $total * 100); }else{ $orderService->db()->where(['merchant_order_id'=>$vo['merchant_order_id']])->update(['status'=>2,'merchant_callback_error'=>2,'channel_callback_at'=>date('Y-m-d H:i:s'),'channel_callback_msg'=>json_encode(['is_auto'=>1,'msg'=>'自动化处理,锁卡失败'])]); $this->setQueueProgress("订单 {$vo['order_id']} 调用锁卡,锁卡失败,成功处理", $count / $total * 100); } }else{ $orderService->db()->where(['merchant_order_id'=>$vo['merchant_order_id']])->update(['status'=>2,'merchant_callback_error'=>2,'channel_callback_at'=>date('Y-m-d H:i:s'),'channel_callback_msg'=>json_encode(['is_auto'=>1,'msg'=>'自动化处理,无卡密信息,无法确定资损,成功处理'])]); $this->setQueueProgress("订单 {$vo['order_id']} 无卡密信息,成功处理", $count / $total * 100); } } else{ $orderService->db()->where(['merchant_order_id'=>$vo['merchant_order_id']])->update(['status'=>2,'merchant_callback_error'=>2,'channel_callback_at'=>date('Y-m-d H:i:s'),'channel_callback_msg'=>json_encode(['is_auto'=>1,'msg'=>'自动化处理,渠道不支持锁卡,成功处理'])]); $this->setQueueProgress("订单 {$vo['order_id']} 渠道不支持锁卡,成功处理", $count / $total * 100); } } }); $this->setQueueSuccess("处理 {$count} 个订单状态完成!"); } }