1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- <?php
- namespace app\admin\model;
- use think\model\concern\SoftDelete;
- class InvoiceOrder extends \think\Model{
- use SoftDelete;
- protected $createTime='createTime';
- protected $updateTime='updateTime';
- protected $autoWriteTimestamp=true;
- protected $deleteTime='delete_time';
- protected $append=["merge_code","short_name","cat_code","cat_name","tax","inv_good_name"];
- public function ItemInfo(){
- return $this->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']];
- }
- }
- }
- }
|