Bläddra i källkod

Merge branch 'dev-wgg' of wugg/cxinv into dev

wugg 1 år sedan
förälder
incheckning
085713d3f4

+ 8 - 3
app/admin/command/GetOrderInfoAndInvoiceInfo.php

@@ -48,13 +48,18 @@ class GetOrderInfoAndInvoiceInfo extends Command
 								Db::name("invoice_red")->where($red)->update(["status"=>4,"remark"=>"开票成功","updatetime"=>date("Y-m-d H:i:s")]);
 								Db::name("invoice_pool")->where(["invNo"=>$red['invNo'],"is_del"=>0])->update(["status"=>6,"updatetime"=>date("Y-m-d H:i:s")]);
 							}
-
+							$this->insertTicket($value['result'],$invNo);
 					}else{
 							$invNo = $value['invNo'];
+							$invoicePoo= Db::name('invoice_pool')->where(['invNo'=>$value['invNo'],'is_del'=>0])
+							->findOrEmpty();
 							Db::name("invoice_pool")->where(["invNo"=>$value['invNo'],"is_del"=>0])->update(["status"=>4,"seller_check"=>1,"buyer_check"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+							$this->insertTicket($value['result'],$invNo);
+							if($invoicePoo['is_comon']==1)event("comonOrder",["invNo"=>$invNo,"type"=>"inv"]);
+							
 					}
-					$da=Db::name("invoice_interface")->where($value)->update(["is_check"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
-					if($da) $this->insertTicket($value['result'],$invNo);
+					Db::name("invoice_interface")->where($value)->update(["is_check"=>1,"updatetime"=>date("Y-m-d H:i:s")]);
+					
 				}
 				if($value['status']==3 || $value['status']==4){
 					if($value['KPLX']==1){

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

@@ -0,0 +1,466 @@
+<?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"=>"",'status'=>'',
+        'relaComNo'=>'','platform_type'=>'','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['status']==''?:$where[]=["status","=",$post['status']];
+        $post['platform_type']==''?:$where[]=["platform_type","=",$post['platform_type']];
+        $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();
+        	 $invArr = Db::name('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' => $list->qrd->sequenceNo])->group
+                ('a.status')->column('sum(b.goodNum) as goodNum', 'a.status');
+             $list->qrd->goodNum =$list->qrd->goodNum - $list->qrd->thNum;
+             $list->qrd->inv_num = $invArr[1]??0;
+             $list->qrd->ainv_num = $invArr[2]??0;
+             $list->qrd->winv_num  =$list->qrd->goodNum-  $list->qrd->inv_num-$list->qrd->ainv_num;
+        	 $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,platform_type","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']}万元");
+        }
+        $platform = array_column($qrdinfo,'platform_type');
+        if(count(array_unique($platform))!=1){
+        	$this->error("订单平台类型不一致");
+//            return error_show(1004,'订单平台类型不一致');
+        }
+        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,
+            'is_comon'=>1,
+            '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 - 1
app/admin/controller/OrderInv.php

@@ -1526,7 +1526,7 @@ class OrderInv extends Base{
         if($buyer_name!==""){
            $condition[]=["b.buyer_title","like","%$buyer_name%"];
         }
-
+		if(isset($this->post['is_comon'])&&$this->post['is_comon']!=='') $condition []=['is_comon','=',$this->post['is_comon']];
          $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):"";
         if($apply_id!==""){
            $condition[]=["a.apply_id","=",$apply_id];
@@ -1555,6 +1555,7 @@ class OrderInv extends Base{
 						a.status,
 						a.inv_value,
 						a.inv_type,
+						a.is_comon,
 						a.buyer_check,
 						a.seller_check,
 						a.exam_remark,

+ 15 - 7
app/admin/controller/Payment.php

@@ -117,6 +117,7 @@ class Payment extends Base
                     `a`.`total_fee` AS `total_fee`,
                     `b`.`apply_name`,
                     `b`.`apply_id`,
+                    `a`.`is_comon`,
                     `a`.`winv_fee` ,
                     `a`.`ainv_fee` ,
                     `a`.`wpay_fee` ,
@@ -564,6 +565,9 @@ class Payment extends Base
                      }
                 }
                Db::commit();
+                if(($status==3 || $status==4)&&$data['is_common']==1){
+                	event("comonOrder",["payNo"=>$payNo,"type"=>"check"]);
+                }
                return app_show(0,"状态更新成功");
             }
             Db::rollback();
@@ -783,6 +787,9 @@ class Payment extends Base
                 }
 
                 Db::commit();
+                if($payinfo['is_comon']==1 && $status==4){
+                	event("comonOrder",["payNo"=>$payinfo['payNo'],"pay_fee"=>$payment['pay_fee'],"type"=>"pay"]);
+                }
                 return app_show(0,"状态修改成功");
             }else{
                 Db::rollback();
@@ -968,7 +975,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 +992,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];
@@ -1523,7 +1530,7 @@ class Payment extends Base
         $list = Db::name("pay_invoice")
             ->alias("a")
             ->leftJoin("pay b", "a.payNo=b.payNo")
-            ->field("a.*,b.supplierNo,b.supplierName,b.companyName,b.companyNo")
+            ->field("a.*,b.supplierNo,b.supplierName,b.companyName,b.is_comon,b.companyNo")
             ->where($condition)
             ->page($page,$size)
             ->order("addtime desc")
@@ -1797,7 +1804,7 @@ class Payment extends Base
     }
 	public function hpinvReturnList(){
 		$param =$this->request->only(["relaComNo"=>"","companyNo"=>"","supplierNo"=>"","start"=>"","end"=>"","returnCode"=>"",
-		"status"=>"","hpNo"=>"","payNo"=>"","page"=>1,"size"=>15],"post","trim");
+		"status"=>"","hpNo"=>"","is_comon"=>"","payNo"=>"","page"=>1,"size"=>15],"post","trim");
 		$condition=[["a.is_del","=",0],['a.returnType',"=",1]];
 		 $check = checkRole($this->roleid,[132,130]);
         if($check){
@@ -1809,6 +1816,7 @@ class Payment extends Base
 		if($param['start']!="") $condition[]=["a.addtime",">=",date("Y-m-d H:i:s",strtotime($param['start']))];
 		if($param['end']!="") $condition[]=["a.addtime","<=",date("Y-m-d 23:59:59",strtotime($param['end']))];
 		if($param['status']!="") $condition[]=["a.status","=",$param['status']];
+		if($param['is_comon']!="") $condition[]=["b.is_comon","=",$param['is_comon']];
 		if($param['hpNo']!="") $condition[]=["a.orderCode","like","%{$param['hpNo']}%"];
 		if($param['returnCode']!="") $condition[]=["a.returnCode","like","%{$param['returnCode']}%"];
 		if($param['payNo']!="") $condition[]=["a.payNo","like","%{$param['payNo']}%"];
@@ -1828,7 +1836,7 @@ class Payment extends Base
             ->where($condition)
             ->page($page, intval($param['size']))
             ->order('id desc')
-            ->field("a.*,b.supplierNo,b.supplierName,b.companyNo,b.companyName,b.total_fee,b.ainv_fee,b.winv_fee,b.inv_fee,c.inv_fee pay_inv_fee")
+            ->field("a.*,b.is_comon,b.supplierNo,b.supplierName,b.companyNo,b.companyName,b.total_fee,b.ainv_fee,b.winv_fee,b.inv_fee,c.inv_fee pay_inv_fee")
             ->select()
             ->toArray();
         //校验是否开通了供应商账号
@@ -1947,7 +1955,7 @@ class Payment extends Base
     }
     public function stageReturnList(){
 		$param =$this->request->only(["relaComNo"=>"","companyNo"=>"","supplierNo"=>"","start"=>"","end"=>"","returnCode"=>"","payNo"=>"",
-		"status"=>"","dzNo"=>"","page"=>1,"size"=>15],"post","trim");
+		"status"=>"","dzNo"=>"","is_comon"=>"","page"=>1,"size"=>15],"post","trim");
 		$condition=[["a.is_del","=",0],['a.returnType',"=",2]];
 		  $check = checkRole($this->roleid,[131,129]);
         if($check){
@@ -1978,7 +1986,7 @@ class Payment extends Base
             ->where($condition)
             ->page($page, intval($param['size']))
             ->order('id desc')
-            ->field("a.*,b.supplierNo,b.supplierName,b.companyNo,b.companyName,b.total_fee,b.apay_fee,b.wpay_fee,b.pay_fee,c.pay_fee pay_pay_fee")
+            ->field("a.*,b.supplierNo,b.is_comon,b.supplierName,b.companyNo,b.companyName,b.total_fee,b.apay_fee,b.wpay_fee,b.pay_fee,c.pay_fee pay_pay_fee")
             ->select()
             ->toArray();
 

+ 38 - 1
app/admin/controller/WeChat.php

@@ -3,7 +3,7 @@
 
 namespace app\admin\controller;
 
-use think\App;
+use app\admin\model\WechatUser;use think\App;
 use think\facade\Validate;
 use think\facade\Db;
 class WeChat extends Base {
@@ -75,4 +75,41 @@ class WeChat extends Base {
 		}
 		return app_show(0,"获取成功",$baseconfig);
 	}
+	
+	public function list(){
+		$post =$this->request->only(['mobile'=>'',"nickname"=>"","page"=>1,"size"=>10],'post','trim');
+		$where=[];
+		if($post['mobile']!='')$where[]=["mobile","like","%{$post['mobile']}%"];
+		if($post['nickname']!='')$where[]=["nickname","like","%{$post['nickname']}%"];
+		$list =(new WechatUser())->where($where)->json(['companyArr'])->paginate(["page"=>$post['page'],"list_rows"=>$post['size']]);
+		$this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
+	}
+	
+	public function save(){
+		$post =$this->request->only([
+			"id"=>"",
+			'mobile'=>'',
+			'nickname'=>'',
+			'is_show'=>'',
+			'companyArr'=>[],
+			],'post','trim');
+		$valid =Validate::rule([
+			"id|主键id"=>"require|number",
+			"mobile|手机号"=>"require|mobile",
+			"nickname|名称"=>"require",
+			"is_show|可查看报表"=>"require",
+			"companyArr|可查看企业"=>"require|array"
+			]);
+		if($valid->check($post)==false)$this->error($valid->getError());
+		$model = new WechatUser();
+		$info =$model->findOrEmpty($post['id']);
+		if($info->isEmpty())$this->error("未找到用户数据");
+		$info->mobile = $post['mobile'];
+		$info->nickname = $post['nickname'];
+		$info->is_show = $post['is_show'];
+		$info->companyArr = json_encode($post['companyArr'],JSON_UNESCAPED_UNICODE);
+		$info->save();
+		$this->success('更新成功');
+	}
+	
 }

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

@@ -0,0 +1,138 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\listener;
+
+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;use think\facade\Config;
+class ComonQrd
+{
+    /**
+     * 事件监听处理
+     *
+     * @return mixed
+     */
+    public function handle($event)
+    {
+		if($event['type']=="pay")$this->payComon($event);
+		if($event['type']=="inv")$this->invComon($event);
+		if($event['type']=="check")$this->checkPay($event);
+    }
+    
+    public function payComon($data){
+    	$payinfo = Pay::where("payNo",$data['payNo'])->findOrEmpty();
+    	if($payinfo->isEmpty()) return;
+    	if($payinfo->is_comon!=1)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;
+    			$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);
+    }
+    
+    protected function invComon($data){
+    	$invinfo =InvoicePool::where(['invNo'=>$data['invNo']])->findOrEmpty();
+    	
+    	if($invinfo->isEmpty())return;
+    	if($invinfo->status!=4 ||$invinfo->is_comon!=1 )return;
+    	$invpay =InvoicePay::where(['invNo'=>$data['invNo']])->findOrEmpty();
+    	if($invpay->isEmpty())return;
+    	if($invpay->status!=0 )return;
+    	$payinfo = Pay::where('payNo',$invpay['payNo'])->findOrEmpty();
+    	if($payinfo->isEmpty()) return;
+    	if($payinfo->is_comon!=1)return;
+    	$ticket =InvoiceTicket::where(["invNo"=>$data['invNo'],"type"=>0])->findOrEmpty();
+    	if($ticket->isEmpty())return;
+    	$pay_fee=0;
+    	    	if($payinfo->winv_fee >=$invinfo->inv_value){
+    	    		$pay_fee = $invinfo->inv_value;
+    	    	}else{
+    	    		$pay_fee = $payinfo->winv_fee;
+    	    	}
+    	$payinvoice = [
+    		"payNo"=>$invpay['payNo'],
+    		"hpNo"=>makeNo("hp"),
+    		"apply_id"=>0,
+    		"apply_name"=>"system",
+    		"invType"=>$invinfo->open_type==3?1:3,
+    		"invoiceType"=>$invinfo->inv_type,
+    		"inv_fee"=>$pay_fee,
+    		"inv_subtotal_amount"=>$ticket->inv_subtotal,
+    		"inv_amount"=>$ticket->inv_total,
+    		"invStatus"=>1,
+    		"status"=>4,
+    		"check_time"=>date("Y-m-d H:i:s"),
+    		"open_time"=>$ticket->open_date,
+    		"invoiceNumber"=>$ticket->inv_number,
+    		"seller_check"=>1,
+    		"buyer_check"=>1,
+    		"invoiceCode"=>$ticket->inv_code,
+    		"checkNumber"=>$ticket->check_code,
+    		"checkApi"=>$data['checkApi']??0
+    		];
+    	$payinfo->winv_fee = $payinfo->winv_fee-$pay_fee;
+    	$payinfo->ainv_fee = $payinfo->ainv_fee+$pay_fee;
+    	$payinfo->inv_status = ($payinfo->winv_fee==0 &&$payinfo->inv_fee==0)?3:($payinfo->ainv_fee==0?1:2);
+    	$this->CheckComonOrder($payinfo);
+    	$payinfo->save();
+    	PayInvoice::create($payinvoice);
+    }
+     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->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]);
+        }
+        if($payinfo->inv_status==1 &&$payinfo->pay_status==1){
+            PayInfo::alias('a')->leftJoin('ComonOrder b','a.cgdNo=b.cgdNo')
+            ->where(['payNo'=>$payinfo->payNo,'is_del'=>0,'a.status'=>1])
+            ->update(['b.status'=>0]);
+        }
+    }
+}

+ 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/InvoiceTicket.php

@@ -0,0 +1,14 @@
+<?php
+declare (strict_types = 1);
+
+namespace app\admin\model;
+
+use think\Model;
+
+/**
+ * @mixin \think\Model
+ */
+class InvoiceTicket 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");
+    }
+}

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

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

+ 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
+{
+    //
+}

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

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

+ 2 - 0
app/admin/route/app.php

@@ -268,6 +268,8 @@ route::rule("departtipsadd","admin/DepartTips/departcreate");//网络部录单
 
 route::rule("wechat_getinfo","admin/WeChat/getinfo");//微信授权获取用户信息
 route::rule("wechat_getconfig","admin/WeChat/getConfig");//微信获取页面jssdk配置
+route::rule("wechat_list","admin/WeChat/list");//微信获取页面jssdk配置
+route::rule("wechat_save","admin/WeChat/save");//微信获取页面jssdk配置
 
 route::rule("goodChangeList","admin/GoodChange/list");
 route::rule("goodChangeInfo","admin/GoodChange/info");

+ 1 - 1
app/command/CopySupplier.php

@@ -55,7 +55,7 @@ class CopySupplier extends Command
 	           "bank_name"=>$supplier['inv_bank'],
 	           "bankNo"=>$supplier['inv_bankNo'],
 	           "contector"=>$supplier['contactor'],
-	           "mobile"=>$supplier['invoice_mobile'],
+	           "mobile"=>$supplier['mobile']??$supplier['invoice_mobile'],
 	           "company_img"=>$supplier['license_img'],
 	           "input_ticket"=>0,
 	           "out_ticket"=>0,

+ 3 - 1
app/command/Report.php

@@ -997,7 +997,9 @@ class Report extends Command
 			d.total_fee-d.th_fee 采购金额,
 			d.good_creater`商品创建人`,
 			d.addtime`采购单时间`,
-			d.cgd_apply_name`竞单人`
+			d.cgd_apply_name`源头竞单人`,
+			d.cgd_supplier_name`源头供应商`,
+			d.supplier_origin_price `源头采购成本`
 		")
 		->where($where)
 		->cursor();

+ 7 - 1
app/command/handleCxData.php

@@ -2,7 +2,7 @@
 
 namespace app\command;
 
-use think\console\Command;
+use app\admin\model\ComonOrder;use think\console\Command;
 use think\console\Input;
 use think\console\Output;
 use think\Exception;
@@ -103,6 +103,7 @@ class handleCxData extends command
 									          'customerNo'=>$data['customer_code'] ,//客户编号,
 									          'customerName'=>$data['customer_name'] ,//客户名称,
 									          'poCode'=>$data['poNo'] ,//po编号,
+									          "is_comon"=>ComonOrder::is_common($data['orderCode']),
 									          'platName'=>$data['platform_id'] ,//平台名称,
 									          'platform_type' => $data['platform_type']??'0',//平台名称,
 									          'workCode'=>$data['workNo'] ,//业务编号,
@@ -183,6 +184,7 @@ class handleCxData extends command
 									          'workCode'=>$data['workNo'] ,//业务编号,
 									          'zxCode'=>$data['zxNo'] ,//咨询单编号,
 									          'goodMaterial'=>'' ,//商品材质,
+									           'is_comon'=>ComonOrder::is_common($data['orderCode']),
 									          'goodUnit'=>$data['unit'] ,//商品单位,
 									          'goodDesc'=>$data['cost_desc'] ,//工艺说明,
 									          'goodType'=>$data['good_type'] ,//商品类型,
@@ -221,6 +223,7 @@ class handleCxData extends command
 							    'sequenceNo'=>$data['orderCode'] ,//确认单编号,
 							    'ownerName'=>$data['apply_name'] ,//销售员,
 							    'ownerid'=>$data['apply_id'] ,//销售员id,
+							    'is_comon'=>ComonOrder::is_common($data['orderCode']),
 							    'department'=>$data['depart'] ,//部门,
 							    'createdTime'=>$data['addtime'] ,//销售单创建时间,
 							    'manager'=>$data['manager']??'',
@@ -340,6 +343,7 @@ class handleCxData extends command
 									      'cgdSource'=>$data['order_source'] ,//采购单来源',
 									      'companyNo'=>$data['companyNo'] ,//业务公司编号',
 									      'companyName'=>$data['companyName'] ,//业务公司',
+									       'is_comon'=>ComonOrder::is_common($data['cgdNo']),
 									      'cgdTime'=>$data['addtime'] ,//采购下单时间',
 									      'bkCode'=>$data['bkcode'] ,//备库单编号',
 									      'qrdCode'=>$data['qrdNo'] ,//确认单编号',
@@ -428,6 +432,7 @@ class handleCxData extends command
 									       'supplierNo'=>$data['supplierNo'] ,//供应商编号',
 									      'supplierName'=>$data['supplier_name'] ,//供应商名称',
 									      'goodModel'=>'' ,//商品型号',
+									       'is_comon'=>ComonOrder::is_common($data['cgdNo']),
 									      'goodMaterial'=>'' ,//商品材质',
 									      'goodUnit'=>$data['unit'] ,//商品单位',
 									      'goodDesc'=>$data['cost_desc'] ,//工艺说明',
@@ -486,6 +491,7 @@ class handleCxData extends command
 							    'goodType'=>$data['good_type'] ,//商品类型',
 							    'goodBrand'=>$data['brand'] ,//商品品牌',
 							    'goodModel'=>'' ,//商品型号',
+							     'is_comon'=>ComonOrder::is_common($data['cgdNo']),
 							    'firstCat'=>$data['cat_name'][0]['cat_name'] ?? "" ,//商品一级分类',
 							    'secCat'=>!isset($data['cat_name'][1]) ? '' : $data['cat_name'][1]['cat_name'] ,//二级分类,
 							    'thirdCat'=>!isset($data['cat_name'][2]) ? '' : $data['cat_name'][2]['cat_name'] ,

+ 2 - 1
app/event.php

@@ -11,7 +11,8 @@ return [
         'HttpEnd'  => [],
         'LogLevel' => [],
         'LogWrite' => [],
-        "rolesave"=>[\app\listener\roleListen::class]
+        "rolesave"=>[\app\listener\roleListen::class],
+        "comonOrder"=>[\app\admin\listener\ComonQrd::class]
     ],
 
     'subscribe' => [