hasOne('InvoiceItem',"id",'itemId'); } public static function getInvoiceOrderTotalFee($code){ $banance = (new InvoiceOrder)->where(['code'=>$code,'status'=>[1,2]])->field('sum(ifnull(total_amount-balance_amount,0)) as total_amount')->find(); return $banance['total_amount']??"0"; } public function getMergeCodeAttr($value,$data){ return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("merge_code",""); } public function getShortNameAttr($value,$data){ return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("short_name",""); } public function getCatCodeAttr($value,$data){ return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("cat_code",""); } public function getCatNameAttr($value,$data){ return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("cat_name",""); } public function getTaxAttr($value,$data){ return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("tax",""); } public function getInvGoodNameAttr($value,$data){ return OrderCategory::where(['code'=>$data['code'],'spuCode'=>$data['spuCode']])->value("inv_good_name",""); } public static function getNumAttr($val){ return strval(floatval($val)); } public static function setDiffInfoAttr($val){ return json_encode($val,JSON_UNESCAPED_UNICODE); } public static function getDiffInfoAttr($val){ return json_decode($val,true); } public static function getOrderInfo($code,$orderCode,$type){ if($type==1){ $info=InvoiceGood::alias('a') ->join('qrd_info b','a.orderCode=b.sequenceNo','left') ->join('order_category c','b.sequenceNo=c.code and b.goodNo=c.spuCode and c.order_type=1','left') ->where(["invNo"=>$code,"a.orderCode"=>$orderCode]) ->where([['a.goodNum','>',0],['a.is_del','=',0]]) ->field('b.sequenceNo,b.goodNo,b.goodName,a.goodNum,a.goodPrice,a.totalPrice,c.merge_code,c.cat_code,c.cat_name,c.short_name,c.tax,c.inv_good_name') ->findOrEmpty(); } else{ $payNo = PayInvoice::where(['hpNo'=>$code])->value("payNo",""); $info = PayInfo::alias('a') ->join('cgd_info b','a.cgdNo=b.sequenceNo','left') ->join('order_category c','b.sequenceNo=c.code and b.goodNo=c.spuCode and c.order_type=2','left') ->where([['a.status','=',1],['a.is_del','=',0],['a.payNo',"=",$payNo ],['a.cgdNo',"=",$orderCode]]) ->field('b.sequenceNo,b.goodNo,b.goodName,(b.goodNum-thNum) as goodNum,b.goodPrice,b.totalPrice, c.merge_code,c.cat_code,c.cat_name,c.short_name,c.tax,c.inv_good_name') ->findOrEmpty(); } if(!$info->isEmpty())$info['balance_amount']= bcsub($info['totalPrice'],InvoiceOrder::getInvoiceOrderTotalFee($info['sequenceNo']),2); return $info; } public static function CheckOrder($code,&$data){ $InvoiceOrder = InvoiceOrder::with(['ItemInfo'])->where(['code'=>$code,'status'=>[1,2]])->select(); if(!$InvoiceOrder->isEmpty()){ $hpinfo=[]; foreach ($InvoiceOrder as $item){ if(isset($hpinfo[$item->ItemInfo->invoiceCode]))continue; $hpinfo[$item->ItemInfo->invoiceCode] = $item->ItemInfo->invoiceCode; $hp = PayInvoice::with(["invoice"])->where(['hpNo'=>$item->ItemInfo->invoiceCode])->findOrEmpty(); $data[]=['type'=>'发票池关联采购单','username'=> $hp['apply_name'],'orderCode'=>$hp['hpNo'],'companyName'=>$hp['companyName']]; } } } }