|
@@ -3,53 +3,40 @@ declare (strict_types = 1);
|
|
|
|
|
|
namespace app\admin\listener;
|
|
|
|
|
|
-use app\admin\model\Assoc;use app\admin\model\InvoiceInfo;use app\admin\model\InvoicePay;use app\admin\model\InvoicePool;use app\admin\model\InvoiceTicket;use app\admin\model\Pay;use app\admin\model\PayInfo;use app\admin\model\PayInvoice;use app\admin\model\QrdInfo;
|
|
|
+use app\admin\model\Assoc;
|
|
|
+use app\admin\model\InvoiceInfo;
|
|
|
+use app\admin\model\InvoicePay;
|
|
|
+use app\admin\model\InvoicePool;
|
|
|
+use app\admin\model\InvoiceTicket;
|
|
|
+use app\admin\model\Pay;
|
|
|
+use app\admin\model\PayInfo;
|
|
|
+use app\admin\model\PayInvoice;
|
|
|
+use app\admin\model\QrdInfo;use app\admin\model\TagLog;
|
|
|
class ComonQrd
|
|
|
{
|
|
|
- protected function checkPay($data){
|
|
|
- $payinfo = Pay::where('payNo',$data['payNo'])->findOrEmpty();
|
|
|
- if($payinfo->isEmpty()) return;
|
|
|
- if($payinfo->is_comon!=1)return;
|
|
|
- $this->CheckComonOrder($payinfo);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public function CheckComonOrder($payinfo){
|
|
|
- if($payinfo->status==3||$payinfo->status==4 ){
|
|
|
- PayInfo::alias('a')
|
|
|
- ->leftJoin('ComonOrder b','a.cgdNo=b.cgdNo')
|
|
|
- ->where(['payNo'=>$payinfo->payNo,'is_del'=>0,'a.status'=>0])
|
|
|
- ->update(['b.status'=>0]);
|
|
|
- }else{
|
|
|
- if($payinfo->inv_status==3 &&$payinfo->pay_status==3){
|
|
|
- PayInfo::alias('a')
|
|
|
- ->leftJoin('ComonOrder b','a.cgdNo=b.cgdNo')
|
|
|
- ->where(['payNo'=>$payinfo->payNo,'is_del'=>0,'a.status'=>1])
|
|
|
- ->update(["b.status"=>2]);
|
|
|
- }elseif($payinfo->inv_status!=3|| $payinfo->pay_status!=3){
|
|
|
- PayInfo::alias('a')
|
|
|
- ->leftJoin('ComonOrder b','a.cgdNo=b.cgdNo')
|
|
|
- ->where(['payNo'=>$payinfo->payNo,'is_del'=>0,'a.status'=>1])
|
|
|
- ->update(['b.status'=>1]);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 事件监听处理
|
|
|
* @return mixed
|
|
|
*/
|
|
|
public function handle($event)
|
|
|
{
|
|
|
-// if($event['type']=="pay")$this->payComon($event);
|
|
|
- if($event['type']=="inv")$this->InvToPay($event);
|
|
|
- if($event['type']=="rinv")$this->InvToPay($event,false);
|
|
|
-// if($event['type']=="check")$this->checkPay($event);
|
|
|
+ if($event['type']=='pay')$this->payComon($event);
|
|
|
+ if($event['type']=='repay')$this->repayComon($event);
|
|
|
+ if($event['type']=='inv'){
|
|
|
+ $this->invComon($event);
|
|
|
+ $this->InvToPay($event);
|
|
|
+ }
|
|
|
+ if($event['type']=='rinv'){
|
|
|
+ $this->returnInv($event);
|
|
|
+ $this->InvToPay($event,false);
|
|
|
+ }
|
|
|
+ if($event['type']=='check')$this->checkPay($event);
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
public function InvToPay($data,$bool=True){
|
|
|
$invinfo =InvoicePool::where(['invNo'=>$data['invNo']])->findOrEmpty();
|
|
|
if($invinfo->isEmpty())return;
|
|
|
+ if($invinfo->inv_out =='GS2203161855277894')return;
|
|
|
if($bool){
|
|
|
if($invinfo->status!=4 ||$invinfo->is_comon!=1 )return;
|
|
|
$assoc_status=2;
|
|
@@ -57,7 +44,7 @@ class ComonQrd
|
|
|
$assoc_status=3;
|
|
|
if(in_array($invinfo->status,[5,6,7,8,9])||$invinfo->is_comon!=1 )return;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$assoc = Assoc::where(["viceCode"=>$data['invNo'],"status"=>$assoc_status,"is_del"=>0,"type"=>1])->select();
|
|
|
if($assoc->isEmpty()) return;
|
|
|
$orderArr = QrdInfo::whereIn("sequenceNo",array_column($assoc->toArray(),"orderCode"))->select();
|
|
@@ -80,7 +67,6 @@ class ComonQrd
|
|
|
$qrd=[
|
|
|
'id'=>$item->id,
|
|
|
'wpay_fee'=>$item->wpay_fee,
|
|
|
-// 'apay_fee'=>$item->apay_fee,
|
|
|
'pay_status'=>$item->pay_status,
|
|
|
'pay_tag_fee'=>$item->pay_tag_fee,
|
|
|
'pay_tag' => 1
|
|
@@ -98,7 +84,7 @@ class ComonQrd
|
|
|
$qrd['pay_status'] = ($qrd['wpay_fee']==0 &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?1:2);
|
|
|
}
|
|
|
}else{
|
|
|
-
|
|
|
+
|
|
|
$tag_temp['tag_fee']= $payArr[$item->sequenceNo];
|
|
|
$tag_fee = ($item->pay_tag_fee>$payArr[$item->sequenceNo])?$payArr[$item->sequenceNo]:$item->pay_tag_fee;
|
|
|
$qrd['pay_tag_fee']=$item->pay_tag_fee-$tag_fee;
|
|
@@ -111,6 +97,164 @@ class ComonQrd
|
|
|
(new \app\admin\model\QrdInfo)->saveAll($qrdSave);
|
|
|
(new \app\admin\model\TagLog)->saveAll($tag);
|
|
|
}
|
|
|
+
|
|
|
+ public function payComon($data){
|
|
|
+ $payinfo = Pay::where("payNo",$data['payNo'])->findOrEmpty();
|
|
|
+ if($payinfo->isEmpty()) return;
|
|
|
+ if($payinfo->is_comon!=1)return;
|
|
|
+ if(!in_array($payinfo->status,[1,2]))return;
|
|
|
+ $qrdNo = PayInfo::alias("a")->leftJoin("ComonOrder b","a.cgdNo=b.cgdNo")->where(["payNo"=>$data['payNo'],"is_del"=>0,"a.status"=>1])->column("orderCode");
|
|
|
+ $qrdinfo = QrdInfo::where([["sequenceNo","in",$qrdNo],["wpay_fee",">",0]])->select();
|
|
|
+ if($qrdinfo->isEmpty())return;
|
|
|
+ $this->CheckComonOrder($payinfo);
|
|
|
+ $tag=[];
|
|
|
+ $qrdSave=[];
|
|
|
+ foreach ($qrdinfo as $item){
|
|
|
+ $tag_temp=[
|
|
|
+ "code"=>$item->sequenceNo,
|
|
|
+ "tag_id"=>10,
|
|
|
+ "creater"=>"system",
|
|
|
+ "createrid"=>0,
|
|
|
+ "tag_fee"=>0,
|
|
|
+ "tag_img"=>"",
|
|
|
+ "status"=>1
|
|
|
+ ];
|
|
|
+ $qrd=[
|
|
|
+ "id"=>$item->id,
|
|
|
+ "wpay_fee"=>$item->wpay_fee,
|
|
|
+ "apay_fee"=>$item->apay_fee,
|
|
|
+ "pay_status"=>$item->pay_status,
|
|
|
+ "pay_tag_fee"=>0,
|
|
|
+ "pay_tag" => 1
|
|
|
+ ];
|
|
|
+ if($item->wpay_fee>$data['pay_fee']){
|
|
|
+ $tag_temp['tag_fee'] = $data['pay_fee'];
|
|
|
+ $qrd['pay_tag_fee'] = $data['pay_fee'];
|
|
|
+ $qrd['wpay_fee'] = $item->wpay_fee-$data['pay_fee'];
|
|
|
+ $qrd['apay_fee'] = $item->apay_fee+$data['pay_fee'];
|
|
|
+ $qrd['pay_status'] = ($qrd['wpay_fee']==0 &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?1:2);
|
|
|
+ $data['pay_fee']=0;
|
|
|
+ }else{
|
|
|
+ $data['pay_fee']=$data['pay_fee']-$item->wpay_fee;
|
|
|
+ $tag_temp['tag_fee'] =$item->wpay_fee;
|
|
|
+ $qrd['pay_tag_fee'] = $item->wpay_fee;
|
|
|
+ $qrd['wpay_fee'] = 0;
|
|
|
+ $qrd['apay_fee'] = $item->apay_fee+$item->wpay_fee;
|
|
|
+ $qrd['pay_status'] = ($qrd['wpay_fee']==0 &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?1:2);
|
|
|
+ }
|
|
|
+ $qrdSave[]=$qrd;
|
|
|
+ $tag[]=$tag_temp;
|
|
|
+ if($data['pay_fee']==0) break;
|
|
|
+ }
|
|
|
+ (new \app\admin\model\QrdInfo)->saveAll($qrdSave);
|
|
|
+ (new \app\admin\model\TagLog)->saveAll($tag);
|
|
|
+ }
|
|
|
+ public function repayComon($data)
|
|
|
+ {
|
|
|
+ $payinfo = Pay::where('payNo', $data['payNo'])->findOrEmpty();
|
|
|
+ if ($payinfo->isEmpty()) return;
|
|
|
+ if ($payinfo->is_comon != 1) return;
|
|
|
+ if (!in_array($payinfo->status, [1, 2])) return;
|
|
|
+ $qrdNo = PayInfo::alias('a')->leftJoin('ComonOrder b', 'a.cgdNo=b.cgdNo')->where(['payNo' => $data['payNo'], 'is_del' => 0, 'a.status' => 1])->column('orderCode');
|
|
|
+ $qrdinfo = QrdInfo::where([['sequenceNo', 'in', $qrdNo], ['pay_tag_fee', '>', 0], ['pay_tag', '=', 1]])
|
|
|
+ ->select();
|
|
|
+ if ($qrdinfo->isEmpty()) return;
|
|
|
+ $this->CheckComonOrder($payinfo);
|
|
|
+ $tag = [];
|
|
|
+ $qrdSave = [];
|
|
|
+ foreach ($qrdinfo as $item) {
|
|
|
+ $qrd = [
|
|
|
+ 'id' => $item->id,
|
|
|
+ 'wpay_fee' => $item->wpay_fee,
|
|
|
+ 'apay_fee' => $item->apay_fee,
|
|
|
+ 'pay_status' => $item->pay_status,
|
|
|
+ 'pay_tag_fee' => 0,
|
|
|
+ 'pay_tag' => 1
|
|
|
+ ];
|
|
|
+ if ($item->pay_tag_fee > $data['pay_fee']) {
|
|
|
+ $qrd['pay_tag_fee'] = $item->pay_tag_fee -$data['pay_fee'];
|
|
|
+ $qrd['pay_tag'] = $qrd['pay_tag_fee']==0 ? 0:1;
|
|
|
+ $qrd['wpay_fee'] = $item->wpay_fee + $data['pay_fee'];
|
|
|
+ $qrd['apay_fee'] = ($item->apay_fee>=$data['pay_fee'])?($item->apay_fee-$data['pay_fee']):0 ;
|
|
|
+ $qrd['pay_status'] = ($qrd['wpay_fee'] == 0 && $item->pay_fee == 0) ? 3 : ($qrd['apay_fee'] == 0 ? 1 : 2);
|
|
|
+ $data['pay_fee'] = 0;
|
|
|
+ } else {
|
|
|
+ $data['pay_fee'] = $data['pay_fee'] - $item->pay_tag_fee;
|
|
|
+ $qrd['pay_tag_fee'] = 0;
|
|
|
+ $qrd['pay_tag'] = 0;
|
|
|
+ $qrd['wpay_fee'] = $item->pay_tag_fee;
|
|
|
+ $qrd['apay_fee'] = ($item->apay_fee>=$item->pay_tag_fee)?($item->apay_fee-$item->pay_tag_fee):0 ;
|
|
|
+ $qrd['pay_status'] = ($qrd['wpay_fee'] == 0 && $item->pay_fee == 0) ? 3 : ($qrd['apay_fee'] == 0 ? 1 : 2);
|
|
|
+
|
|
|
+ }
|
|
|
+ $qrdSave[] = $qrd;
|
|
|
+ if( $qrd['pay_tag']==0)$del[]=$item->sequenceNo;
|
|
|
+ else{
|
|
|
+ $tag[]=[
|
|
|
+ 'id'=>TagLog::where('code',$item->sequenceNo)->value('id'),
|
|
|
+ 'tag_fee' => $qrd['pay_tag_fee'],
|
|
|
+ 'updatetime'=>date('Y-m-d H:i:s')
|
|
|
+ ];
|
|
|
+ }
|
|
|
+ if ($data['pay_fee'] == 0) break;
|
|
|
+ }
|
|
|
+ (new \app\admin\model\QrdInfo)->saveAll($qrdSave);
|
|
|
+ (new \app\admin\model\TagLog)->saveAll($tag);
|
|
|
+ (new \app\admin\model\TagLog)->where('code','in',$del)->delete();
|
|
|
+ }
|
|
|
+ public function returnInv($data){
|
|
|
+ $invinfo =InvoicePool::where(['invNo'=>$data['invNo'],"status"=>[5,6,7,8,9]])->findOrEmpty();
|
|
|
+ if($invinfo->isEmpty())return;
|
|
|
+ if($invinfo->is_comon!=1 )return;
|
|
|
+ $invpay =InvoicePay::where(['invNo'=>$data['invNo']])->findOrEmpty();
|
|
|
+ if($invpay->isEmpty())return;
|
|
|
+ if($invpay->status!=1 )return;
|
|
|
+ $payinfo = Pay::where('payNo',$invpay['payNo'])->findOrEmpty();
|
|
|
+ if($payinfo->isEmpty()) return;
|
|
|
+ if($payinfo->is_comon!=1)return;
|
|
|
+ $payinvoice = PayInvoice::where(["hpNo"=>$invpay->hpNo,"status"=>4])->findOrEmpty();
|
|
|
+ if($payinvoice->isEmpty())return;
|
|
|
+ $payinvoice->status=10;
|
|
|
+ $payinvoice->save();
|
|
|
+ $payinfo->winv_fee = $payinfo->winv_fee+$payinvoice->inv_fee;
|
|
|
+ $payinfo->ainv_fee = $payinfo->ainv_fee-$payinvoice->inv_fee;
|
|
|
+ $payinfo->inv_status = ($payinfo->winv_fee==0 &&$payinfo->inv_fee==0)?3:($payinfo->ainv_fee==0?2:1);
|
|
|
+ $this->CheckComonOrder($payinfo);
|
|
|
+ $payinfo->save();
|
|
|
+ $invpay->status =2;
|
|
|
+ $invpay->save();
|
|
|
+ }
|
|
|
+
|
|
|
+ protected function checkPay($data){
|
|
|
+ $payinfo = Pay::where('payNo',$data['payNo'])->findOrEmpty();
|
|
|
+ if($payinfo->isEmpty()) return;
|
|
|
+ if($payinfo->is_comon!=1)return;
|
|
|
+ $this->CheckComonOrder($payinfo);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public function CheckComonOrder($payinfo){
|
|
|
+ if($payinfo->status==3||$payinfo->status==4 ){
|
|
|
+ PayInfo::alias('a')
|
|
|
+ ->leftJoin('ComonOrder b','a.cgdNo=b.cgdNo')
|
|
|
+ ->where(['payNo'=>$payinfo->payNo,'is_del'=>0,'a.status'=>0])
|
|
|
+ ->update(['b.status'=>0]);
|
|
|
+ }else{
|
|
|
+ if($payinfo->inv_status==3 &&$payinfo->pay_status==3){
|
|
|
+ PayInfo::alias('a')
|
|
|
+ ->leftJoin('ComonOrder b','a.cgdNo=b.cgdNo')
|
|
|
+ ->where(['payNo'=>$payinfo->payNo,'is_del'=>0,'a.status'=>1])
|
|
|
+ ->update(["b.status"=>2]);
|
|
|
+ }elseif($payinfo->inv_status!=3|| $payinfo->pay_status!=3){
|
|
|
+ PayInfo::alias('a')
|
|
|
+ ->leftJoin('ComonOrder b','a.cgdNo=b.cgdNo')
|
|
|
+ ->where(['payNo'=>$payinfo->payNo,'is_del'=>0,'a.status'=>1])
|
|
|
+ ->update(['b.status'=>1]);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //新开票完成 创建对应的标签;
|
|
|
|
|
|
protected function invComon($data){
|
|
|
$invinfo =InvoicePool::where(['invNo'=>$data['invNo']])->findOrEmpty();
|
|
@@ -202,81 +346,4 @@ class ComonQrd
|
|
|
$invpay->status =1;
|
|
|
$invpay->save();
|
|
|
}
|
|
|
-
|
|
|
- public function payComon($data){
|
|
|
- $payinfo = Pay::where("payNo",$data['payNo'])->findOrEmpty();
|
|
|
- if($payinfo->isEmpty()) return;
|
|
|
- if($payinfo->is_comon!=1)return;
|
|
|
- if(!in_array($payinfo->status,[1,2]))return;
|
|
|
- $qrdNo = PayInfo::alias("a")->leftJoin("ComonOrder b","a.cgdNo=b.cgdNo")->where(["payNo"=>$data['payNo'],"is_del"=>0,"a.status"=>1])->column("orderCode");
|
|
|
- $qrdinfo = QrdInfo::where([["sequenceNo","in",$qrdNo],["wpay_fee",">",0]])->select();
|
|
|
- if($qrdinfo->isEmpty())return;
|
|
|
- $this->CheckComonOrder($payinfo);
|
|
|
- $tag=[];
|
|
|
- $qrdSave=[];
|
|
|
- foreach ($qrdinfo as $item){
|
|
|
- $tag_temp=[
|
|
|
- "code"=>$item->sequenceNo,
|
|
|
- "tag_id"=>10,
|
|
|
- "creater"=>"system",
|
|
|
- "createrid"=>0,
|
|
|
- "tag_fee"=>0,
|
|
|
- "tag_img"=>"",
|
|
|
- "status"=>1
|
|
|
- ];
|
|
|
- $qrd=[
|
|
|
- "id"=>$item->id,
|
|
|
- "wpay_fee"=>$item->wpay_fee,
|
|
|
- "apay_fee"=>$item->apay_fee,
|
|
|
- "pay_status"=>$item->pay_status,
|
|
|
- "pay_tag_fee"=>0,
|
|
|
- "pay_tag" => 1
|
|
|
- ];
|
|
|
- if($item->wpay_fee>$data['pay_fee']){
|
|
|
- $tag_temp['tag_fee'] = $data['pay_fee'];
|
|
|
- $qrd['pay_tag_fee'] = $data['pay_fee'];
|
|
|
- $qrd['wpay_fee'] = $item->wpay_fee-$data['pay_fee'];
|
|
|
- $qrd['apay_fee'] = $item->apay_fee+$data['pay_fee'];
|
|
|
- $qrd['pay_status'] = ($qrd['wpay_fee']==0 &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?1:2);
|
|
|
- $data['pay_fee']=0;
|
|
|
- }else{
|
|
|
- $data['pay_fee']=$data['pay_fee']-$item->wpay_fee;
|
|
|
- $tag_temp['tag_fee'] =$item->wpay_fee;
|
|
|
- $qrd['pay_tag_fee'] = $item->wpay_fee;
|
|
|
- $qrd['wpay_fee'] = 0;
|
|
|
- $qrd['apay_fee'] = $item->apay_fee+$item->wpay_fee;
|
|
|
- $qrd['pay_status'] = ($qrd['wpay_fee']==0 &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?1:2);
|
|
|
- }
|
|
|
- $qrdSave[]=$qrd;
|
|
|
- $tag[]=$tag_temp;
|
|
|
- if($data['pay_fee']==0) break;
|
|
|
- }
|
|
|
- (new \app\admin\model\QrdInfo)->saveAll($qrdSave);
|
|
|
- (new \app\admin\model\TagLog)->saveAll($tag);
|
|
|
- }
|
|
|
-
|
|
|
- //新开票完成 创建对应的标签;
|
|
|
-
|
|
|
- public function returnInv($data){
|
|
|
- $invinfo =InvoicePool::where(['invNo'=>$data['invNo'],"status"=>[5,6,7,8,9]])->findOrEmpty();
|
|
|
- if($invinfo->isEmpty())return;
|
|
|
- if($invinfo->is_comon!=1 )return;
|
|
|
- $invpay =InvoicePay::where(['invNo'=>$data['invNo']])->findOrEmpty();
|
|
|
- if($invpay->isEmpty())return;
|
|
|
- if($invpay->status!=1 )return;
|
|
|
- $payinfo = Pay::where('payNo',$invpay['payNo'])->findOrEmpty();
|
|
|
- if($payinfo->isEmpty()) return;
|
|
|
- if($payinfo->is_comon!=1)return;
|
|
|
- $payinvoice = PayInvoice::where(["hpNo"=>$invpay->hpNo,"status"=>4])->findOrEmpty();
|
|
|
- if($payinvoice->isEmpty())return;
|
|
|
- $payinvoice->status=10;
|
|
|
- $payinvoice->save();
|
|
|
- $payinfo->winv_fee = $payinfo->winv_fee+$payinvoice->inv_fee;
|
|
|
- $payinfo->ainv_fee = $payinfo->ainv_fee-$payinvoice->inv_fee;
|
|
|
- $payinfo->inv_status = ($payinfo->winv_fee==0 &&$payinfo->inv_fee==0)?3:($payinfo->ainv_fee==0?2:1);
|
|
|
- $this->CheckComonOrder($payinfo);
|
|
|
- $payinfo->save();
|
|
|
- $invpay->status =2;
|
|
|
- $invpay->save();
|
|
|
- }
|
|
|
}
|