wugg 1 年間 前
コミット
7b046a23c3

+ 449 - 0
app/admin/controller/ComonOrder.php

@@ -0,0 +1,449 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\controller;
+
+use app\admin\model\CgdInfo;use app\admin\model\CompanyInfo;
+use app\admin\model\InvoiceGood;
+use app\admin\model\InvoicePay;
+use app\admin\model\InvoicePool;
+use app\admin\model\InvoicePoolInfo;
+use app\admin\model\Pay;
+use app\admin\model\PayInfo;
+use app\admin\model\QrdInfo;
+use app\admin\model\ReportCode;
+use app\admin\model\SupplierInfo;
+use app\admin\model\TagLog;
+use think\App;
+use think\Exception;
+use think\facade\Config;
+use think\facade\Db;
+use think\facade\Validate;
+//通用订单处理
+class ComonOrder extends Base
+{
+	public $model=null;
+	protected $typename;
+	protected $invoiceType;
+    protected $invName;
+    protected $kingInvoice;
+    protected $novalidate=["*"];
+    public function __construct(App $app) {
+    	parent::__construct($app);
+    	$this->model = new \app\admin\model\ComonOrder();
+    	 $invoice =Config::get('invoiceType');
+        $this->invoiceType = $invoice['invoiceName'];
+        $this->invName = $invoice['invoiceType'];
+        $this->typename = $invoice['KingName'];
+        $this->kingInvoice = $invoice['KingInvoice'];
+    }
+    
+    public function list(){
+        $post = $this->request->only(["start"=>"","end"=>"","cxCode"=>"","customerNo"=>"","companyNo"=>"",
+        'relaComNo'=>'','page'=>1,'size'=>15],"post","trim");
+        $where=[];
+        $post['start']==''?:$where[]=["addtime",">=",date("Y-m-d 00:00:00",strtotime($post['start']))];
+        $post['end']==''?:$where[]=["addtime","<=",date("Y-m-d 23:59:59",strtotime($post['end']))];
+        $post['cxCode']==''?:$where[]=["cxCode","like","%{$post['cxCode']}%"];
+        $post['customerNo']==''?:$where[]=["customerNo","=",$post['customerNo']];
+        $post['companyNo']==''?:$where[]=["companyNo|supplierNo","=",$post['companyNo']];
+        $post['relaComNo']==''?:$where[]=["companyNo|supplierNo|customerNo","=",$post['relaComNo']];
+        $list=$this->model->with(["qrd","cgd"])->where($where)->order("id desc")->paginate(["page"=>$post['page'],"list_rows"=>$post['size']]);
+        $this->success("0",["list"=>$list->items(),"count"=>$list->total()]);
+    }
+    //通用订单创建对账单
+    public function PayCreate(){
+        $param=$this->request->only(["common_ids"=>[]],"post","trim");
+        $valid=Validate::rule(["common_ids|通用订单id集合"=>"require|array"]);
+        if($valid->check($param)==false)$this->error($valid->getError());
+        $obj = $this->model->with(['cgd'])->where(["id"=>$param['common_ids']])->select();
+        if($obj->isEmpty())$this->error("未找到相关数据");
+        $list = $obj->toArray();
+        $status = array_unique(array_column($list,"status"));
+        $supplierNo = array_unique(array_column($list,"supplierNo"));
+        $customerNo = array_unique(array_column($list,"customerNo"));
+        $goodNo = array_unique(array_column($list,"goodNo"));
+        if(in_array(1,$status)|| in_array(2,$status))$this->error('提交数据存在已对账或对账中的数据');
+        $supplierName = \app\admin\model\SupplierInfo::whereIn("code",$supplierNo)->value("name",'');
+        $customerName = \app\admin\model\CompanyInfo::whereIn("companyNo",$customerNo)->value("company_name",'');
+        if(count($supplierNo)>1)$this->error('提交数据采购供应商存在不一致');
+        if(count($customerNo)>1)$this->error('提交数据销售客户存在不一致');
+        $good_info = \app\admin\model\Good::where(['spuCode'=>$goodNo])->column('status','spuCode');
+        if(empty($good_info))$this->error('商品开票类目信息不存在');
+        if(in_array(0,$good_info)){
+        	$key = array_search(0,$good_info);
+        	$this->error("商品 $key 采购未确认开票类目");
+        }
+        if(in_array(1,$good_info)){
+            $key = array_search(1,$good_info);
+            $this->error("商品 $key 财务未确认开票类目");
+        }
+        $payNo= makeNo("PAY");
+        $this->model->startTrans();
+        try {
+         $paydata=[
+                'payNo'=>$payNo,
+                'apply_id'=>$this->uid,
+                'apply_name'=>$this->uname,
+                'total_fee'=>"0",
+                'supplierNo'=>$supplierNo[0],
+                'supplierName'=>$supplierName,
+                'companyNo'=>$customerNo[0],
+                'companyName'=>$customerName,
+                'wpay_fee'=>"0",
+                'apay_fee'=>'0',
+                'ainv_fee'=>'0',
+                'winv_fee'=>'0',
+                'remark'=>'',
+                'is_comon'=>1,
+                'status'=>1,
+                'addtime'=>date('Y-m-d H:i:s'),
+                'updatetime'=>date('Y-m-d H:i:s'),
+            ];
+         foreach ($list as $item){
+         	if(!isset($item['cgd']) || empty($item['cgd'])) throw new Exception("采购单信息未找到");
+         	    $value= $item['cgd'];
+         	   $temp=[];
+               $temp['cgdNo']=$value['sequenceNo'];
+               $temp['total_fee']=$value['totalPrice'];
+               $temp['apay_fee']=$value['apay_fee'];
+               $temp['wpay_fee']=$value['wpay_fee'];
+               $temp['winv_fee']=$value['winv_fee'];
+               $temp['ainv_fee']=$value['ainv_fee'];
+               $temp['payNo']=$payNo;
+               $temp['addtime']=date('Y-m-d H:i:s');
+               $temp['updatetime']=date('Y-m-d H:i:s');
+               $data[]=$temp;
+                $paydata['total_fee']= bcadd($paydata['total_fee'],$temp['total_fee'],2);
+                $paydata['apay_fee']= bcadd($paydata['apay_fee'],$temp['apay_fee'],2);
+                $paydata['wpay_fee']= bcadd($paydata['wpay_fee'],$temp['wpay_fee'],2);
+                $paydata['ainv_fee']=bcadd($paydata['ainv_fee'],$temp['ainv_fee'],2);
+                $paydata['winv_fee']= bcadd($paydata['winv_fee'],$temp['winv_fee'],2);
+         }
+         if(empty($data))throw new Exception('采购单对账信息不能为空');
+         $save= (new \app\admin\model\PayInfo)->saveAll($data);
+         if($save->count()==0)throw new Exception('采购单对账信息录入失败');
+         $payIn =Pay::create($paydata);
+         if($payIn->id>0){
+         	$this->model->where(['id'=>$param['common_ids']])->save(["status"=>1]);
+         	CgdInfo::where(["sequenceNo"=>array_column($list,"cgdNo")])->save(['status'=>1]);
+         	
+         	$report =ReportCode::where(['cgdNo'=>array_column($list,'cgdNo')])->select();
+         	if($report->isEmpty()==false)$report->update(['payNo'=>Db::raw("CONCAT(payNo,{$payNo})")]);
+         	$this->model->commit();
+         }else throw new Exception('采购单对账单创建失败');
+        }catch (\Exception $exception){
+        	$this->model->rollback();
+        	$this->error($exception->getMessage());
+        }
+        $this->success("对账单创建成功");
+    }
+    
+    //通用订单修改对账单
+    public function PaySave(){
+        $param=$this->request->only(['common_ids'=>[],"payNo"=>""],'post','trim');
+        $valid=Validate::rule([
+        	'common_ids|通用订单id集合'=>'require|array',
+        	'payNo|通用订单对账单编号'=>'require',
+        	]);
+        if($valid->check($param)==false)$this->error($valid->getError());
+        $obj = $this->model->with(['cgd'])->where(['id'=>$param['common_ids']])->select();
+        if($obj->isEmpty())$this->error('未找到相关数据');
+        $payinfo = Pay::where(['payNo'=>$param['payNo'],'is_del'=>0])->findOrEmpty();
+        if($payinfo->isEmpty())$this->error('未找到对账单数据');
+        if($payinfo->status!=1)$this->error('对账单数据已提交审核');
+        $cgdNo =payInfo::where([['payNo','=',$param['payNo']],['is_del','=',0]])->column('cgdNo');
+       
+        $list = $obj->toArray();
+         $cgdArr=array_column($list,'cgdNo');
+        $status = array_unique(array_column($list,'status'));
+        $supplierNo = array_unique(array_column($list,'supplierNo'));
+        $customerNo = array_unique(array_column($list,'customerNo'));
+        $goodNo = array_unique(array_column($list,'goodNo'));
+//        if(in_array(1,$status)|| in_array(2,$status)){
+//        	$this->error('提交数据存在已对账或对账中的数据');
+//        }
+        $supplierName = \app\admin\model\SupplierInfo::whereIn('code',$supplierNo)->value('name','');
+        $customerName = \app\admin\model\CompanyInfo::whereIn('companyNo',$customerNo)->value('company_name','');
+        if(count($supplierNo)>1)$this->error('提交数据采购供应商存在不一致');
+        if(count($customerNo)>1)$this->error('提交数据销售客户存在不一致');
+        $good_info = \app\admin\model\Good::where(['spuCode'=>$goodNo])->column('status','spuCode');
+        if(empty($good_info))$this->error("商品开票类目信息不存在");
+        if(in_array(0,$good_info)){
+        	$key = array_search(0,$good_info);
+        	$this->error("商品 $key 采购未确认开票类目");
+        }
+        if(in_array(1,$good_info)){
+            $key = array_search(1,$good_info);
+            $this->error("商品 $key 财务未确认开票类目");
+        }
+        $add=[];
+        $remove=[];
+        if(!empty($cgdNo)){
+          $remove = array_diff($cgdNo,$cgdArr);
+          $add = array_diff($cgdArr,$cgdNo);
+        }
+        $data=[];
+        $this->model->startTrans();
+        try {
+         $paydata=[
+                'total_fee'=>'0',
+                'supplierNo'=>$supplierNo,
+                'supplierName'=>$supplierName,
+                'companyNo'=>$customerNo,
+                'companyName'=>$customerName,
+                'wpay_fee'=>'0',
+                'apay_fee'=>'0',
+                'ainv_fee'=>'0',
+                'winv_fee'=>'0',
+                'remark'=>'',
+                'is_comon'=>1,
+                'status'=>1,
+                'updatetime'=>date('Y-m-d H:i:s'),
+            ];
+         foreach ($list as $item){
+         	if(!isset($item['cgd']) || empty($item['cgd'])) throw new Exception('采购单信息未找到');
+         	   $value= $item['cgd'];
+         	  if(!empty($add)&& in_array($value['sequenceNo'],$add)){
+	               $temp=[];
+	               $temp['cgdNo']=$value['sequenceNo'];
+	               $temp['total_fee']=$value['totalPrice'];
+	               $temp['apay_fee']=$value['apay_fee'];
+	               $temp['wpay_fee']=$value['wpay_fee'];
+	               $temp['winv_fee']=$value['winv_fee'];
+	               $temp['ainv_fee']=$value['ainv_fee'];
+	               $temp['payNo']=$param['payNo'];
+	               $temp['addtime']=date('Y-m-d H:i:s');
+	               $temp['updatetime']=date('Y-m-d H:i:s');
+	               $data[]=$temp;
+               }
+                $paydata['total_fee']= bcadd($paydata['total_fee'],$temp['total_fee'],2);
+                $paydata['apay_fee']= bcadd($paydata['apay_fee'],$temp['apay_fee'],2);
+                $paydata['wpay_fee']= bcadd($paydata['wpay_fee'],$temp['wpay_fee'],2);
+                $paydata['ainv_fee']=bcadd($paydata['ainv_fee'],$temp['ainv_fee'],2);
+                $paydata['winv_fee']= bcadd($paydata['winv_fee'],$temp['winv_fee'],2);
+         }
+         if(!empty($data)){
+         	$save= (new \app\admin\model\PayInfo)->saveAll($data);
+         	 if($save->count()==0)throw new Exception('采购单对账信息录入失败');
+         }
+         $payIn =Pay::where($payinfo)->save($paydata);
+         if($payIn){
+         	$this->model->where(['id'=>$param['common_ids']])->save(['status'=>1]);
+         	$this->model->where(['cgdNo'=>$remove])->save(['status'=>0]);
+         	CgdInfo::where(['sequenceNo'=>$add])->save(['status'=>1]);
+         	CgdInfo::where(['sequenceNo'=>$remove])->save(['status'=>0]);
+         	$report =ReportCode::where(['cgdNo'=>$add])->select();
+         	if($report->isEmpty()==false)$report->update(['payNo'=>Db::raw("CONCAT(payNo,{$param['payNo']})")]);
+         	$reports =ReportCode::where(['cgdNo'=>$remove])->select();
+         	if($reports->isEmpty()==false)$reports->update(['payNo'=>Db::raw("REPLACE(payNo,',{$param['payNo']}','')")]);
+         	$this->model->commit();
+         }else throw new Exception('采购单对账单创建失败');
+        }catch (\Exception $exception){
+        	$this->model->rollback();
+        	$this->error($exception->getMessage());
+        }
+        $this->success('对账单创建成功');
+    }
+    //通用对账单信息
+    public function PayInfo()
+    {
+        $param=$this->request->only(['payNo'=>''],"post","trim");
+        $valid=Validate::rule(['payNo|通用订单对账单编号'=>'require']);
+        if($valid->check($param)==false)$this->error($valid->getError());
+        $payinfo =Pay::where(['payNo'=>$param['payNo'],'is_del'=>0])->append(["cgdlist","qrdlist"])->findOrEmpty();
+        if($payinfo->isEmpty())$this->error("对账单数据未找到");
+        if($payinfo->is_comon==0)$this->error('非通用对账单数据无法访问数据');
+        $pay = PayInfo::where(['payNo'=>$param['payNo'],'is_del'=>0])->select();
+        if($pay->isEmpty())$this->error('对账单订单数据未找到');
+        $cgdlist = [];
+        $qrdlist = [];
+        foreach ($pay as $item){
+        	$list=$this->model->with(['qrd',"cgd"])->where(["cgdNo"=>$item->cgdNo])->findOrEmpty();
+        	if($list->isEmpty())continue;
+        	
+        	$list->cgd->catInfo = json_decode($list->cgd->catInfo,true);
+        	$list->qrd->catInfo = json_decode($list->qrd->catInfo,true);
+        	 $cgdlist[] =$list->cgd->toArray();
+        	 $qrdlist[] =$list->qrd->toArray();
+        }
+         $payinfo->cgdlist =$cgdlist;
+         $payinfo->qrdlist =$qrdlist;
+        $payinfo['pay_type']=SupplierInfo::where('code',$payinfo['supplierNo'])->value('pay_method','');
+        $tag =TagLog::alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
+            (['code'=>$param['payNo'],'a.status'=>1])->column('b.tag_name,a.tag_img,a.tag_remark','b.type');
+            $payinfo['inv_tag_name']=$tag[2]['tag_name']??'';
+            $payinfo['pay_tag_name']=$tag[1]['tag_name']??'';
+            $payinfo['pay_tag_img']=$tag[1]['tag_img']??'';
+            $payinfo['pay_tag_remark']=$tag[1]['tag_remark']??'';
+            $payinfo['inv_tag_img']=$tag[2]['tag_img']??'';
+            $payinfo['inv_tag_remark']=$tag[2]['tag_remark']??'';
+        $this->success('获取成功',$payinfo);
+    }
+    /**
+	 * 对账单开票申请
+	 */
+    public function invAdd(){
+        $param=$this->request->only(["payNo"=>"","orderArr"=>[],"invtype"=>"","email"=>"","remark"=>"",
+        'exam_remark'=>''],"post","trim");
+        $valid =Validate::rule([
+        	"payNo|对账单编号"=>"require",
+        	"orderArr|订单数据"=>"require|array",
+        	"invtype|开票类型"=>["require","in"=>$this->invName],
+        	"email|邮箱"=>"email",
+        	]);
+        if($valid->check($param)==false) $this->error($valid->getError());
+        $valide = Validate::rule([
+        	"sequenceNo|销售订单号"=>"require",
+        	"num|商品开票数量"=>"require|number|gt:0",
+        	"inv_fee|商品开票金额"=>"require|float|gt:0",
+        	]);
+        
+        $qrdinfo = QrdInfo::whereIn('sequenceNo',array_column($param['orderArr'],"sequenceNo"))
+        ->column("id,sequenceNo,customerNo,customerName,companyNo,companyName,goodNo,goodNum,thNum,inv_fee,winv_fee,
+        status,goodUnit,goodName,thirdCat,totalPrice,tax","sequenceNo");
+        if(empty($qrdinfo))$this->error("订单信息不存在");
+        $goodInfo= \app\admin\model\Good::whereIn("spuCode",array_unique(array_column($qrdinfo,"goodNo")))
+        ->column("inv_good_name,inv_cat_name,inv_cat_code,inv_tax,is_discount,addTax,inv_tag,status","spuCode");
+        if(empty($goodInfo))$this->error('商品类目信息不存在');
+        $assoc=[];
+        $invoiceGood=[];
+        $invNo=makeNo('INV');
+        $invfee=array_sum(array_column($param['orderArr'],'inv_fee'));
+        $companyArr = array_unique(array_column($qrdinfo,'companyName','companyNo'));
+        $customerArr = array_unique(array_column($qrdinfo,'customerName','customerNo'));
+        if(count($companyArr)>1)$this->error("订单业务公司不一致");
+        if(count($customerArr)>1)$this->error("订单客户公司不一致");
+        $company = CompanyInfo::whereIn("companyNo",array_keys($companyArr))->findOrEmpty();
+        if($company->isEmpty())$this->error('订单业务公司开票信息未找到');
+         $customer = CompanyInfo::whereIn('companyNo',array_keys($customerArr))->findOrEmpty();
+        if($customer->isEmpty())$this->error('订单客户公司开票信息未找到');
+        if($company['denomination']!=''&& $invfee>intval($company['denomination'])*10000){
+           $this->error("开票面额不能超过{$company['denomination']}万元");
+        }
+        foreach ($param['orderArr'] as $i=>$item){
+        	if($valide->check($item)==false) $this->error($valide->getError());
+        	if(!isset($qrdinfo[$item['sequenceNo']]))$this->error("订单 {$item['sequenceNo']} 信息不存在");
+        	if($qrdinfo[$item['sequenceNo']]['status']==2)$this->error("订单 {$item['sequenceNo']} 不参与对账");
+        	if($qrdinfo[$item['sequenceNo']]['winv_fee']<$item['inv_fee'])$this->error("订单 {$item['sequenceNo']} 待开票金额不足");
+        	$total = InvoicePool::alias("a")->leftJoin('invoice_good b', 'a.invNo=b.invNo and b.is_del=0')
+                     ->where(['a.status' => [0, 1, 2, 3, 4], 'b.orderCode' => $item['sequenceNo']])
+                     ->sum('b.goodNum');
+        	if($total+$item['num']>($qrdinfo[$item['sequenceNo']]['goodNum']-$qrdinfo[$item['sequenceNo']]['thNum']))$this->error("订单 {$item['sequenceNo']} 待开票数量不足");
+        	if(!isset($goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]))$this->error("订单 {$item['sequenceNo']} 商品类目信息不存在");
+        	if($goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]['status']!=2)$this->error("订单 {$item['sequenceNo']} 未确认开票类目信息");
+        	$num = \app\admin\model\Assoc::alias('a')
+            ->leftJoin('invoice_good b', 'a.viceCode=b.invNo AND b.orderCode=a.orderCode')
+            ->where(['a.status' => [1, 2], 'a.is_del' => 0, 'a.type' => 1, 'a.orderCode' => $item['sequenceNo']])
+            ->sum('b.goodNum');
+        	if($num+$item['num']>($qrdinfo[$item['sequenceNo']]['goodNum']-$qrdinfo[$item['sequenceNo']]['thNum']))$this->error("订单 {$item['sequenceNo']} 待开票数量不足");
+        	$assoc[]=[
+        		       'assocNo'=>substr(makeNo('AS'),0,-4).str_pad(strval($i+1),4,'0',STR_PAD_LEFT),
+                       'apply_id'=>$this->uid,
+                       'apply_name'=>$this->uname,
+                       'type'=>1,
+                       'orderCode'=>$item['sequenceNo'],
+                       'customerNo'=>$qrdinfo[$item['sequenceNo']]['customerNo'],
+                       'viceCode'=>$invNo,
+                       'order_total'=>$qrdinfo[$item['sequenceNo']]['totalPrice'],
+                       'vice_total'=>$invfee,
+                       'cancel_fee'=>$item['inv_fee'],
+                       'status'=>1,
+                       'addtime'=>date('Y-m-d H:i:s'),
+                       'updatetime'=>date('Y-m-d H:i:s')
+                       ];
+        	$invoiceGood[]=[
+                       'invNo'=>$invNo,
+                        'orderCode'=>$item['sequenceNo'],
+                        'goodNo'=>$qrdinfo[$item['sequenceNo']]['goodNo'],
+                        'goodName'=>$good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_good_name']??$qrdinfo[$item['sequenceNo']]['goodName'] ,
+                        'catName'=>$good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_cat_name']??$qrdinfo[$item['sequenceNo']]['thirdCat'],
+                        'catNo'=>$good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_cat_code']??'',
+                        'goodPrice'=>round($item['inv_fee']/$item['num'],8),
+                        'unitName'=>$qrdinfo[$item['sequenceNo']]['goodUnit'],
+                        'goodNum'=>$item['num'],
+                        'specInfo'=>$item['sequenceNo'],
+                        'totalPrice'=>$item['inv_fee'],
+                        'totalTax'=>$item['inv_fee'],
+                        'tax'=>$good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_tax']??$qrdinfo[$item['sequenceNo']]['tax'],
+                        'is_discount'=>$good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['is_discount']??0,
+                        'addTax'=>$good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['addTax']??'',
+                        'inv_tag'=>$good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_tag']??'',
+                        'taxPrice'=>round($item['inv_fee']*($good_info[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_tax']??$qrdinfo[$item['sequenceNo']]['tax']),2),
+                        'addtime'=>date('Y-m-d H:i:s'),
+                        'updatetime'=>date('Y-m-d H:i:s')
+                    ];
+        	$qrdinfo[$item['sequenceNo']]["inv_fee"] = $qrdinfo[$item['sequenceNo']]['inv_fee']+$item['inv_fee'];
+        	$qrdinfo[$item['sequenceNo']]["winv_fee"] = $qrdinfo[$item['sequenceNo']]['winv_fee']-$item['inv_fee'];
+        	$qrdinfo[$item['sequenceNo']]["inv_status"] = 2;
+        	$qrdinfo[$item['sequenceNo']]["status"] = 1;
+        }
+         $inv=[
+            'invNo'=>$invNo,
+            'inv_value'=>$invfee,
+            'inv_out'=> array_keys($companyArr)[0],
+            'inv_company'=> $company['invoice_title']??'',
+            'apply_id'=>$this->uid,
+            'apply_name'=>$this->uname,
+            'inv_type'=>$param['invtype'],//发票类型  专用 普通 电子专用 电子普通 全电子票
+            'open_type'=>0, //开票类型 金税开票 金税线下 纯线下
+            'platform_type'=>$platform[0]??0, //开票类型 金税开票 金税线下 纯线下
+            'is_ticket'=>$company['out_ticket'], //是否支持金税开票
+            'company_type'=> $customer['company_type']??'01', //类型01 企业,02 机关事业单位,03 个人, 04 其他
+            'remark'=>$param['remark'], //申请备注
+            'exam_remark'=>$param['exam_remark'], //审核备注
+            'ainv_fee'=>0,//已核销金额
+            'winv_fee'=>$invfee,//未核销金额
+            'status'=>1,// 带财务审核
+            'is_del'=>0,
+            'email'=>$param['email'],
+            'addtime'=>date('Y-m-d H:i:s'),
+            'updatetime'=>date('Y-m-d H:i:s')
+        ];
+        $invinfo=[
+               'buyer_title'=>$customer['invoice_title'],
+               'buyer_code'=>$customer['company_license'],
+               'buyer_addr'=>$customer['company_address'],
+               'buyer_mobile'=>$customer['mobile'],
+               'buyer_bank'=>$customer['bank_name'],
+               'buyer_bankNo'=>$customer['bankNo'],
+               'seller_title'=>$company['invoice_title'],
+               'seller_code'=>$company['company_license'],
+               'seller_addr'=>$company['company_address'],
+               'seller_mobile'=>$company['mobile'],
+               'seller_bank'=>$company['bank_name'],
+               'seller_bankNo'=>$company['bankNo'],
+               'invNo'=>$invNo,
+               'voider'=>$company['voider'],
+               'payee'=>$company['payee'],
+               'drawer'=>$company['drawer'],
+               'reviewer'=>$company['reviewer'],
+               'ownerPlace'=>$company['ownerPlace'],
+               'addtime'=>date('Y-m-d H:i:s')
+            ];
+        $this->model->startTrans();
+        try{
+            $assocSa=(new \app\admin\model\Assoc)->saveAll($assoc);
+            if($assocSa->isEmpty()) throw new Exception("开票关联数据生成失败");
+            $goodInv = (new \app\admin\model\InvoiceGood)->saveAll($invoiceGood);
+        	if($goodInv->isEmpty()) throw new Exception('开票商品明细数据生成失败');
+        	$qrdSave = (new \app\admin\model\QrdInfo)->saveAll($qrdinfo);
+        	if($qrdSave->isEmpty()) throw new Exception('销售单信息更新失败');
+        	$invoice = InvoicePool::create($inv);
+        	if($invoice->isEmpty()) throw new Exception('开票信息创建失败');
+        	$invoiceinf = InvoicePoolInfo::create($invinfo);
+        	if($invoiceinf->isEmpty()) throw new Exception('开票信息创建失败');
+        	$payIn = InvoicePay::create(["invNo"=>$invNo,"payNo"=>$param["payNo"]]);
+        	if($payIn->isEmpty()) throw new Exception('开票信息创建失败');
+        	$report =ReportCode::where(['qrdNo'=>array_column($param['orderArr'],'sequenceNo')])->select();
+        	if($report->isEmpty()==false)$report->update(["invNo"=>Db::raw("CONCAT(invNo,',',{$invNo})")]);
+        	$this->model->commit();
+        	
+        }catch (\Exception $exception){
+        	$this->model->rollback();
+        	$this->error($exception->getMessage());
+        }
+        $this->success("开票申请创建成功");
+    }
+    
+}

+ 2 - 2
app/admin/controller/Payment.php

@@ -968,7 +968,7 @@ class Payment extends Base
 
 
     public function cgdQuery(){
-		$post = $this->request->only(["cgdNoArr"=>[],"qrdNoArr"=>[],"status"=>"","is_comon"=>"0","relaComNo"=>'',"companyNo"=>"","supplierNo"=>""],"post");
+		$post = $this->request->only(["cgdNoArr"=>[],"qrdNoArr"=>[],"status"=>"","is_comon"=>"","relaComNo"=>'',"companyNo"=>"","supplierNo"=>""],"post");
 		$valid=Validate::rule([
 			"cgdNoArr|采购单编号集合"=>"requireWithout:qrdNoArr|array",
 		    "qrdNoArr|销售单编号集合"=>"requireWithout:cgdNoArr|array",
@@ -985,7 +985,7 @@ class Payment extends Base
         if($companyNo!=""){
           $condition []=["companyNo","=",$companyNo];
         }
-        if($post['is_comon']!='') $condition []=['is_comon','=',$post['is_comon']];
+        if(isset($post['is_comon'])&& $post['is_comon']!=='') $condition []=['is_comon','=',$post['is_comon']];
          $relaComNo= isset($post['relaComNo'])&&$post['relaComNo']!="" ? trim($post['relaComNo']) :"";
          if($relaComNo!=""){
             $condition[]=["companyNo|supplierNo","=",$relaComNo];

+ 17 - 0
app/admin/listener/ComonQrd.php

@@ -0,0 +1,17 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\listener;
+
+class ComonQrd
+{
+    /**
+     * 事件监听处理
+     *
+     * @return mixed
+     */
+    public function handle($event)
+    {
+
+    }
+}

+ 14 - 0
app/admin/model/Assoc.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Assoc extends Model
+{
+    //
+}

+ 28 - 0
app/admin/model/ComonOrder.php

@@ -0,0 +1,28 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class ComonOrder extends Model
+{
+	protected $createTime='addtime';
+    protected $updateTime='updatetime';
+    
+   public static function is_common($code){
+    $isT= self::where("orderCode|cgdNo",$code)->findOrEmpty();
+    return $isT->isEmpty()? 0:1;
+   }
+   
+   public function Qrd(){
+   	 return $this->belongsTo(QrdInfo::class,"orderCode","sequenceNo");
+   }
+   
+   public function Cgd(){
+   	 return $this->belongsTo(CgdInfo::class,'cgdNo','sequenceNo');
+   }
+}

+ 15 - 0
app/admin/model/InvoicePay.php

@@ -0,0 +1,15 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class InvoicePay extends Model
+{
+	protected $createTime='addtime';
+    protected $updateTime='updatetime';
+}

+ 14 - 0
app/admin/model/InvoicePool.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class InvoicePool extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/InvoicePoolInfo.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class InvoicePoolInfo extends Model
+{
+    //
+}

+ 14 - 0
app/admin/model/Pay.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class Pay extends Model
+{
+    //
+}

+ 16 - 0
app/admin/model/PayInfo.php

@@ -0,0 +1,16 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class PayInfo extends Model
+{
+    public function Comon(){
+    	return $this->belongsTo(ComonOrder::class,"cgdNo","cgdNo");
+    }
+}

+ 2 - 1
app/admin/model/QrdInfo.php

@@ -10,5 +10,6 @@ use think\Model;
  */
 class QrdInfo extends Model
 {
-    //
+    protected $createTime="addtime";
+    protected $updateTime="updatetime";
 }

+ 3 - 0
app/admin/model/ReportCode.php

@@ -26,4 +26,7 @@ class ReportCode extends Model
     public function __destruct(){
       $this->save();
     }
+    public function beat(){
+    
+    }
 }

+ 14 - 0
app/admin/model/TagLog.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class TagLog extends Model
+{
+    //
+}