123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- <?php
- namespace app\cxinv\model;
- class Assoc extends Base
- {
- //设置字段信息
- protected $schema = [
- 'id' =>'bigint',//
- 'assocNo' =>'varchar',//关联编号
- 'apply_id' =>'int',//操作人id
- 'apply_name' =>'varchar',//操作人名称
- 'type' =>'tinyint',//操作类型 1 单票 2 单款
- 'orderCode' =>'varchar',//销售订单编号
- 'customerNo' =>'varchar',//客户编号
- 'viceCode' =>'varchar',//发票编号/回款编号
- 'order_total' =>'decimal',//订单总金额
- 'vice_total' =>'decimal',//发票面额/回款金额
- 'cancel_fee' =>'decimal',//核销金额
- 'status' =>'tinyint',//核销状态 1 审核中 2 核算完成3 退款退票
- 'is_del' =>'tinyint',//是否删除
- 'exam_remark' =>'varchar',//审核备注
- 'assoc_time' =>'varchar',//开票时间/回款时间
- 'updatetime' =>'datetime',//
- 'addtime' =>'datetime',//
- ];
- protected $createTime = 'addtime';
- protected $updateTime = 'updatetime';
- # 关联查询
- public static function CheckTrad($logNo,$status){
- $Ascc = self::where(["viceCode"=>$logNo,"is_del"=>0])->select();
- if($Ascc->isEmpty()) throw new \Exception("资金{$logNo}关联订单不存在");
- $Ascc->each(function($item) use($status){
- if($status==2) self::CheckFinsh($item);
- if($status==3||$status==5) self::CheckBack($item);
- if($status==4) self::CheckRefund($item);
- });
- }
- # 核销金额 付款完成
- public static function CheckFinsh($data){
- $qrd = QrdInfo::where(["sequenceNo"=>$data->orderCode,"is_del"=>0])->findOrEmpty();
- if($qrd->isEmpty()) throw new \Exception("关联订单{$data->orderCode}不存在");
- if($qrd->pay_fee<$data->cancel_fee) throw new \Exception("关联订单{$data->orderCode}核销金额大于支付金额");
- $qrd->pay_fee = $qrd->pay_fee-$data->cancel_fee;
- $qrd->apay_fee = $qrd->apay_fee+$data->cancel_fee;
- $qrd->pay_time = date("Y-m-d H:i:s");
- $qrd->pay_status = $qrd->wpay_fee==0 && $qrd->pay_fee==0?3:2;
- $qrdsav=$qrd->save();
- if(!$qrdsav) throw new \Exception("关联订单{$data->orderCode}更新失败");
- if($qrd->pay_status==3 && $qrd->is_comon==0 && $qrd->cxCode!=''){
- ComonOrder::where(['cxCode'=>$qrd['cxCode'],'status'=>-1])->save(['status'=>0]);
- }
- $data->status = 2;
- $data->assoc_time = date("Y-m-d H:i:s");
- $assup=$data->save();
- if(!$assup) throw new \Exception("关联信息{$data->AssocNo}更新失败");
- }
- # 付款流程解除
- public static function CheckBack($data){
- $qrd = QrdInfo::where(["sequenceNo"=>$data->orderCode,"is_del"=>0])->findOrEmpty();
- if($qrd->isEmpty()) throw new \Exception("关联订单{$data->orderCode}不存在");
- if($qrd->pay_fee<$data->cancel_fee) throw new \Exception("关联订单{$data->orderCode}核销金额大于支付金额");
- $qrd->wpay_fee = $qrd->wpay_fee+$data->cancel_fee;
- $qrd->pay_fee = $qrd->pay_fee-$data->cancel_fee;
- $qrd->pay_status = $qrd->apay_fee==0?1:2;
- $qrd->status =$qrd->pay_status==1 && $qrd->inv_status==1?0:1;
- $qrdsav=$qrd->save();
- if(!$qrdsav) throw new \Exception("关联订单{$data->orderCode}更新失败");
- if($qrd->pay_status==1 && $qrd->is_comon==0 && $qrd->cxCode!='') {
- ComonOrder::where(['cxCode'=>$qrd->cxCode,'status'=>0])->save(['status'=>-1]);
- }
- $data->status = 3;
- $assup=$data->save();
- if(!$assup) throw new \Exception("关联信息{$data->AssocNo}更新失败");
- }
- # 已付款数据退款
- public static function CheckRefund($data){
- $qrd = QrdInfo::where(["sequenceNo"=>$data->orderCode,"is_del"=>0])->findOrEmpty();
- if($qrd->isEmpty()) throw new \Exception("关联订单{$data->orderCode}不存在");
- if($qrd->apay_fee<$data->cancel_fee) throw new \Exception("关联订单{$data->orderCode}核销金额大于已支付金额");
- $qrd->apay_fee = $qrd->apay_fee-$data->cancel_fee;
- $qrd->wpay_fee = $qrd->wpay_fee+$data->cancel_fee;
- $qrd->pay_status = $qrd->apay_fee==0?1:2;
- $qrd->status =$qrd->pay_status==1 && $qrd->inv_status==1?0:1;
- $qrdsav=$qrd->save();
- if(!$qrdsav) throw new \Exception("关联订单{$data->orderCode}更新失败");
- if($qrd->pay_status==1 && $qrd->is_comon==0 && $qrd->cxCode!='') {
- ComonOrder::where(['cxCode'=>$qrd->cxCode,'status'=>0])->save(['status'=>-1]);
- }
- $data->status = 3;
- $assup=$data->save();
- if(!$assup) throw new \Exception("关联信息{$data->AssocNo}更新失败");
- }
- public static function CheckQrd($orderCode,&$data)
- {
- $asscoinfo =self::where(['orderCode'=>$orderCode,'status'=>[1,2],'is_del'=>0])->column
- ('viceCode','type');
- if(isset($asscoinfo[1])){
- $pool = InvoicePool::where('invNo',$asscoinfo[1])->findOrEmpty();
- $temp=['type'=>'结算销售单开票申请','username'=> $pool->apply_name,'orderCode'=>$asscoinfo[1],'companyName'=>$pool->inv_company];
- $data[]=$temp;
- }
- if(isset($asscoinfo[2])){
- $pool = TradePool::with(['company'])->where('logNo',$asscoinfo[2])->findOrEmpty();
- $temp=['type'=>'结算销售单资金认领','username'=> $pool->apply_name,'orderCode'=>$asscoinfo[2],'companyName'=>$pool->companyName];
- $data[]=$temp;
- }
- }
- }
|