setName('xQueue:Book'); // $this->setDescription('导入章节内容'); $this->setName('xQueue:KamiOrderChanelNotify')->setDescription('[ 卡密列表 - 自动同步 ] 对cardbuy购置的卡密同步响应数据进行异步处理订单回调状态'); } /** * @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%' ]; list($count, $total) = [0, $orderService->db()->where($where)->where($where1)->count()]; $kami91server = Kami91OrderService::instance(); $agiso =new \app\openapi\controller\agisoAcprSupplierApi\Order($this->app); $kami91 =new \app\openapi\controller\Kami91($this->app); $maSuDa = new \app\openapi\controller\maSuDaApi\Order($this->app); $MerchantService = MerchantService::instance(); $orderService->db()->where($where)->where($where1)->chunk(100, function (Collection $data) use (&$count, $total,$kami91server,$agiso,$MerchantService,$kami91,$maSuDa) { // var_dump($orderlist);die; foreach ($data->toArray() as $vo) { $info = $kami91server->db()->where(['order_id' => $vo['order_id']])->find(); if($info){ $count++; if(isset($info['status'])){ $getMerchantInfo = $MerchantService->get($vo['mid']); if($info['status'] == 4){ if( $vo['status'] == 7){ $request_data = []; if(empty($info['cardno'])){ $response = json_decode($vo['response'],true); if(isset($response['kami'])) { $cardno = $response['kami']['cardno']; $cardpwd = $response['kami']['cardpwd']??null; if(!isset($response['kami']['expired']) || !$response['kami']['expired'] ){ $expire_time = null; }else{ $expire_time = $this->validateExpireTime($response['kami']['expired']); } // $expire_time= $response['kami']['expired']; // $expire_time = null; $kami = [ 'cardno' =>$cardno, 'cardpwd' =>$cardpwd, 'expire_time' =>$expire_time, ]; $kami['status'] = 6; $where = [ 'order_id' => $vo['order_id'] ]; $result = $kami91server->up($where,$kami); }elseif(isset($vo['channel_callback_msg']) && str_contains($vo['channel_callback_msg'], "kami")){ $msg = json_decode($vo['channel_callback_msg'],true); $cardno = $msg['kami']['cardno']; $cardpwd = $msg['kami']['cardpwd']??null; if(!isset($msg['kami']['expired']) || !$msg['kami']['expired'] ){ $expire_time = null; }else{ $expire_time = $this->validateExpireTime($msg['kami']['expired']); } // $expire_time= $msg['kami']['expired']; // $expire_time = null; $kami = [ 'cardno' =>$cardno, 'cardpwd' =>$cardpwd, 'expire_time' =>$expire_time, ]; $kami['status'] = 6; $where = [ 'order_id' => $vo['order_id'] ]; $result =$kami91server->up($where,$kami); } }else{ $kami = [ 'cardno' => $info['cardno'], 'cardpwd' => $info['cardpwd']??null, 'expire_time' => $info['expire_time']??null ]; $where = [ 'order_id' => $vo['order_id'] ]; $result =$kami91server->up($where,['status' => 6]); } $param = [ 'order_id' => $vo['order_id'], 'merchant_order_id'=> $info['merchant_order_id'], 'status' => 2, 'actual_cash'=>$vo['actual_cash'], ]; if(!isset($kami)){ // $param['status'] =3; }else{ $kami['expired'] = $kami['expire_time']; $param['kami'] = $kami; } if(isset($info['api_key']) && $info['api_key'] == 'maSuDa'){ $info_param = json_decode($info['param'],true); $param['uid'] = $info_param['buyer_open_uid']; $param['pid'] = $info['pid']; $up_msg = $maSuDa->notify($info['notifyurl'], $param,$getMerchantInfo); if($up_msg == 'success'){ $kami91server->upStatus($vo['order_id'], 6, $up_msg); // $other_param = json_decode($getMerchantInfo['other_param'],true); // // #判断是否发卡 $other_param = json_decode($getMerchantInfo['other_param'],true); $secretKey = $other_param['maSuDa_secret_key']; $uid= $other_param['maSuDa_uid']; $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); if ($check == 'ok') { $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); $maSuDa->huidiao($vo['order_id']); }else{ #设置查询时间5s,避免重复发送,redis记录 try{ $redis = RedisService::getInstance(); $redis_key = 'mSD_query'.$info['merchant_order_id']; $getRedisData = $redis->set($redis_key,time(),600); #设置查询时间 }catch (\Exception $e){ } } } }elseif(isset($info['api_key']) && $info['api_key'] == 'agiso_old'){ $kami91server->upStatus($vo['order_id'], 2, 'success'); $kami91->huidiao($vo['order_id']); }else{ $up_msg=$agiso->notify($info['notifyurl'], $param,$getMerchantInfo); if($up_msg == 'success'){ $kami91server->upStatus($vo['order_id'], 2, $up_msg); $agiso->huidiao($vo['order_id']); } } } } if($info['status'] == '6') { $create_at = strtotime($info['create_at']) ; if($info['callback_msg'] != 'success' && $create_at > time() - 600){ if(isset($info['cardno']) && $info['cardno']){ $kami = [ 'cardno' => $info['cardno'], 'cardpwd' => $info['cardpwd'], 'expired' => $info['expire_time'] ]; } $param = [ 'order_id' => $vo['order_id'], 'merchant_order_id'=> $info['merchant_order_id'], 'status' => 2, 'actual_cash'=>$vo['actual_cash'], ]; if(!isset($kami)){ // $param['status'] =3; }else{ $param['kami'] = $kami; } if(isset($info['api_key']) && $info['api_key'] == 'maSuDa'){ $info_param = json_decode($info['param'],true); $param['uid'] = $info_param['buyer_open_uid']; $param['pid'] = $info['pid']; $other_param = json_decode($getMerchantInfo['other_param'],true); $secretKey = $other_param['maSuDa_secret_key']; $uid= $other_param['maSuDa_uid']; try{ $redis = RedisService::getInstance(); $redis_key = 'mSD_query'.$info['merchant_order_id']; $getRedisData = $redis->get($redis_key); if($getRedisData){ $times = time() - $getRedisData; if($times < 10){ $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); if ($check == 'ok') { $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); $maSuDa->huidiao($vo['order_id']); } }else{ $redis->set($redis_key,time(),600); $up_msg = $maSuDa->notify($info['notifyurl'], $param,$getMerchantInfo); if($up_msg == 'success'){ $kami91server->upStatus($vo['order_id'], 6, $up_msg); $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); if ($check == 'ok') { $redis->delete($redis_key); $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); $maSuDa->huidiao($vo['order_id']); } } } } #设置查询时间 }catch (\Exception $e){ $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); if ($check == 'ok') { $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); $maSuDa->huidiao($vo['order_id']); }else{ $up_msg = $maSuDa->notify($info['notifyurl'], $param,$getMerchantInfo); $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); if ($check == 'ok') { $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); $maSuDa->huidiao($vo['order_id']); } } } }elseif(isset($info['api_key']) && $info['api_key'] == 'agiso_old'){ $kami91server->upStatus($vo['order_id'], 2, 'success'); $kami91->huidiao($vo['order_id']); }else{ $up_msg=$agiso->notify($info['notifyurl'], $param,$getMerchantInfo); if($up_msg == 'success'){ $kami91server->upStatus($vo['order_id'], 2, $up_msg); $agiso->huidiao($vo['order_id']); } } }else{ #查询卡的状态是否已发送 #判断是否发送 if(isset($info['api_key']) && $info['api_key'] == 'maSuDa'){ $info_param = json_decode($info['param'],true); // $uid= $info_param['buyer_open_uid']; $other_param = json_decode($getMerchantInfo['other_param'],true); $secretKey = $other_param['maSuDa_secret_key']; $uid= $other_param['maSuDa_uid']; $check = $maSuDa->queryFaka($info['merchant_order_id'],$uid,$secretKey); if ($check == 'ok') { $kami91server->db()->where(['order_id' => $vo['order_id']])->update(['status' => 2]); $maSuDa->huidiao($vo['order_id']); }else{ #进行锁卡退款。 } }elseif(isset($info['api_key']) && $info['api_key'] == 'agiso_old'){ $kami91server->upStatus($vo['order_id'], 2, 'success'); $kami91->huidiao($vo['order_id']); }else{ $check = $agiso->queryFaka($vo['merchant_order_id']); if ($check == 'ok') { $msg = 'success'; if ($vo['response']) { } $kami91server->upStatus($vo['order_id'], 2, $msg); $kami91->huidiao($vo['order_id']); } } } } } elseif (empty($info['cardno'])){ $kami91->uphuidiao($vo['order_id']); } $this->setQueueProgress("处理完订单状态 {$vo['order_id']} ", $count / $total * 100); } } }); // $this->setQueueSuccess("处理完 {$count} 个订单状态完成!"); } private function validateExpireTime($expireTime) { if (strtotime($expireTime) === false) { return null; } return $expireTime; } }