setName('queuecus') ->setDescription('the queuecus command'); } protected function execute(Input $input, Output $output) { // 指令输出 $redis = Cache::store("redis"); while($redis->handler()->llen('createOrderJob1')>0){ $data = $redis->handler()->rpop('createOrderJob1'); $user_info = json_decode($data,true); $rel =$this->checkJob($user_info); if($rel){ $this->doData($user_info); } $output->writeln('queuecus'); } } protected function doData($data){ $result = OcrByInvoice(["url"=>$data['image']]); $result = json_decode($result,true); if(isset($result['code'])&&$result['code']==0 ){ $obj = $result['data']; if(isset($obj['error_code'])){ Db::name("invoice_img")->where([['id',"=",$data['id']],['status',"=",1]])->save (["remark"=>json_encode($obj,JSON_UNESCAPED_UNICODE)]); $sql ="update cfp_pay_stages set remark=CONCAT(ifnull(remark,''),'识别失败;') where id={$data['payid']}"; Db::query($sql); $this->failed($data); return false; } try{ // $ist = Db::name("invoice")->where([['code',"=",$object['code']],["number","=",$object['number']]]) // ->find(); // if($ist){ // if($ist['id']!=$data['id']){ // Db::name("invoice_img")->where([['id',"=",$data['id']],['status',"=",1]])->save(["remark"=>"已存在发票{$object['code']}"]); // $sql ="update cfp_pay_stages set remark=CONCAT(remark,'已存在发票{$object['code']};') where id={$data['payid']}"; // Db::query($sql); // $this->failed($data); // return false; // } // } $object = $result['data']["result"]; $obje=json_encode($object,JSON_UNESCAPED_UNICODE); Db::name("invoice_img")->where([['id',"=",$data['id']],['status',"=",1]])->save(["status"=>0,'invoice_info'=>$obje,"remark"=>""]); $info = Db::name("invoice_info")->where("invid","=",$data['id'])->find(); if(empty($info)){ $info=[]; } Log::write(Db::name("invoice_img")->getLastSql()); $info['payid']= $data['payid']; $info['invid']= $data['id']; $info['type']= $object['type']; $info['code']= $object['code']; $info['number']= $object['number']; $info['check_code']= $object['check_code']; $info['issue_date']= $object['issue_date']; $info['buyer_name']= $object['buyer_name']; $info['buyer_id']= $object['buyer_id']; $info['buyer_address']= $object['buyer_address']; $info['buyer_bank']= $object['buyer_bank']; $info['seller_name']= $object['seller_name']; $info['seller_id']= $object['seller_id']; $info['seller_address']= $object['seller_address']; $info['seller_bank']= $object['seller_bank']; // $info['subtotal_amount']= str_replace("¥",'',$object['subtotal_amount']); // $info['subtotal_tax']=str_replace("¥",'',$object['subtotal_tax']); // $info['total']= str_replace("¥",'',$object['total']); $info['subtotal_amount']= $object['subtotal_amount']; $info['subtotal_tax']=$object['subtotal_tax']; $info['total']= $object['total']; $info['item_list']= json_encode($object['item_list'],JSON_UNESCAPED_UNICODE); $info['status']= 0; $info['change_field']= ""; Db::name("invoice_info")->save($info); $num =Db::name("invoice_img")->where([['payid',"=", $data['payid']],["is_del","=",0],['status',"<>",0]]) ->count(); if($num<=0){ Db::name("pay_stages")->where("id","=",$data['payid'])->save(["status"=>5,"remark"=>""]); } return true; }catch (\Exception $e){ echo $e->getMessage(); return false; } }else{ Log::write(var_export( $result,true)); Db::name("invoice_img")->where([['id',"=",$data['id']],['status',"=",1]])->save (["remark"=>json_encode($result,JSON_UNESCAPED_UNICODE)]); $sql ="update cfp_pay_stages set remark=CONCAT(remark,'识别失败;') where id={$data['payid']}"; Db::query($sql); $this->failed($data); return false; } } private function checkJob($data){ $list= Db::name("invoice_img")->where("id","=",$data['id'])->find(); if($list['status']==0){ return false; } return true; } public function failed($data){ Db::name("invoice_img")->where([['id',"=",$data['id']],['status',"=",1]])->save(['status'=>2]); $num =Db::name("invoice_img")->where([['payid',"=", $data['payid']],["is_del","=",0],['status',"=",2]]) ->count(); if($num>0){ Db::name("pay_stages")->where("id","=",$data['payid'])->save(["status"=>9]); } } }