Browse Source

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

wugg 8 months ago
parent
commit
bf57a16cfb

+ 0 - 3
app/admin/command/downredinvres.php

@@ -135,9 +135,6 @@ class downredinvres extends Command
 							"QDBZ"=>"0",
 							"YFPDM"=>$red['YFPDM'],
 							"YFPHM"=>$red['YFPHM'],
-//							"YFPLX"=>$red['FPLXDM'],
-//							"YFPKPRQ"=>date("Y-m-d",strtotime($red['YFPKPRQ'])),
-//							"CHYY"=>$red['red_reason'],
 							"YFPLX"=>$red['FPLXDM'] == '004' ||$red['FPLXDM'] =='028'||$red['red_reason']=='' ?'':$red['FPLXDM'],
 							"YFPKPRQ"=>$red['FPLXDM'] == '004' ||$red['FPLXDM'] =='028'||$red['red_reason']=='' ? '':date("Y-m-d",strtotime($red['YFPKPRQ'])),
 							"CHYY"=>$red['FPLXDM'] == '004' ||$red['FPLXDM'] =='028' ? '':$red['red_reason'],

+ 2 - 0
app/admin/controller/Action.php

@@ -37,6 +37,8 @@ class Action extends Base{
             $list[] = $value;
         }
         menuAction($list, $menu);
+          $weight= array_column($menu,'weight');
+         array_multisort($weight, SORT_DESC, $menu);
         return app_show(0, "获取成功", array_values($menu));
     }
 

+ 4 - 4
app/admin/controller/Base.php

@@ -31,10 +31,10 @@ class Base extends BaseController
 	        'hpinvreturn', #回票申请退票
 	        'stagereturn',#付款申请退款
     	];
-	protected  $uid=0;
-	protected  $uname='';
-	protected  $roleid=0;
-	protected  $level=0;
+	public  $uid=0;
+	public  $uname='';
+	public  $roleid=0;
+	public  $level=0;
 	public $post='';
   public function __construct(App $app) {
   	parent::__construct($app);

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

@@ -483,4 +483,189 @@ class ComonOrder extends Base
         $this->success("开票申请创建成功");
     }
     
+        /**
+	 * 对账单开票申请
+	 */
+    public function invAddT(){
+        $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|float|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 (in_array($param['invtype'] ,
+        		   [
+        			   'fully_digitalized_special_electronic' ,
+        			   'fully_digitalized_normal_electronic'
+        		   ]
+        	   )) {
+        		   //全电发票限制金额
+        		   if ($invfee > 10000000) {
+        		   	$this->error('开票面额不能超过一千万元');
+        		   }
+        	   }
+        	   else {//全电发票
+        		   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'=>$goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_good_name']??$qrdinfo[$item['sequenceNo']]['goodName'] ,
+                        'catName'=>$goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_cat_name']??$qrdinfo[$item['sequenceNo']]['thirdCat'],
+                        'catNo'=>$goodInfo[$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'=>$goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_tax']??$qrdinfo[$item['sequenceNo']]['tax'],
+                        'is_discount'=>$goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]['is_discount'],
+                        'addTax'=>$goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]['addTax'],
+                        'inv_tag'=>$goodInfo[$qrdinfo[$item['sequenceNo']]['goodNo']]['inv_tag'],
+                        'taxPrice'=>round($item['inv_fee']*($goodInfo[$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('开票申请创建成功');
+    }
+    
 }

+ 20 - 1
app/admin/controller/Company.php

@@ -3,7 +3,7 @@ declare (strict_types = 1);
 
 namespace app\admin\controller;
 
-use think\App;
+use app\admin\model\OcrTotal;use think\App;
 use think\facade\Config;use think\facade\Db;
 
 
@@ -339,4 +339,23 @@ class Company extends Base
         $list=Db::name("order_rate")->where("status","=",1)->select();
         return app_show(0,"获取成功",$list);
     }
+    /** 获取OCR统计
+    * @return \think\response\Json|void
+    * @throws \think\db\exception\DataNotFoundException
+    * @throws \think\db\exception\ModelNotFoundException
+    * @throws \think\exception\DbException
+     */
+    public function OcrTotalList(){
+        $param=$this->request->param(["page"=>1,"size"=>10,"start"=>"","end"=>"","companyNo"=>""],"post","trim");
+        $where=[];
+        if($param["companyNo"]!=""){
+            $where[]=["companyNo","like","%".$param["companyNo"]."%"];
+        }
+        if($param["start"]!=""&&$param["end"]!=""){
+            $where[]=["daydate","between",[startTime($param['start']),endTime($param["end"])]];
+        }
+        $list = OcrTotal::where($where)->order('daydate desc')
+            ->paginate(['page'=>$param['page'],'list_rows'=>$param['size']]);
+        return app_show(0, '获取成功', ['list'=>$list->items(),'count'=>$list->total()]);
+    }
 }

+ 5 - 3
app/admin/controller/Exec.php

@@ -8,7 +8,9 @@ use think\App;
 use think\facade\Validate;
 class Exec extends Base{
 
-	public function __construct(App $app) {parent::__construct($app);}
+	public function __construct(App $app) {
+	    parent::__construct($app);
+	}
 
 	public function list(){
 		$param=$this->request->param(["name"=>"","type"=>"","status"=>"","companyNo"=>"",'relaComNo'=>'',"page"=>1,"size"=>15],"post","trim");
@@ -53,7 +55,7 @@ class Exec extends Base{
 			"apply_name"=>$this->uname,
 			"apply_id"=>$this->uid,
 			"companyNo"=>$companyNo,
-			"companyName"=>Db::name("supplier_info")->where(["code"=>$companyNo])->value("name",""),
+			"companyName"=>Db::connect('mysql_sys')->name('headquarters')->where(["code"=>$companyNo])->value("name",""),
 			"action"=>$param["action"]??"",
 			"type"=>0,
 			"status"=>0,
@@ -94,7 +96,7 @@ class Exec extends Base{
 		$data=[
 			"name"=>$exec['name'],
 			"companyNo"=>$companyNo,
-			"companyName"=>Db::name("supplier_info")->where(["code"=>$companyNo])->value("name",""),
+			"companyName"=>Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$companyNo])->value("name",""),
 			"start"=>date("Y-m-d 00:00:00",strtotime($param['start'])),
 			"end"=>date("Y-m-d 23:59:59",strtotime($param['end'])),
 			"apply_id"=>$this->uid,

+ 3 - 2
app/admin/controller/Export.php

@@ -223,7 +223,8 @@ class Export extends Base
     public function orderPayExport()
     {
         $param = $this->request->only(['start' => '', 'end' => '', 'name' => '', 'bank' => '', 'status' => '', 'tradNo' => '', 'company' => '', 'userd_lower' => '', 'used_upper' => ''], 'post', 'trim');
-        $where = [['a.is_del', '=', 0]];
+        $where = [['a.is_del', '=', 0],['b.is_del', '=', 0],['d.is_del', '=', 0],['d.is_del', '=', 0],["c.type","=",
+        2],["c.status","in",[1,2]]];
         if (($param['start'] != '') && ($param['end'] != '')) $where[] = ['a.trade_time', 'between', [$param['start'] . ' 00:00:00', $param['end'] . ' 23:59:59']];
         if ($param['name'] != '') $where[] = ['a.trade_out', 'like', '%' . $param['name'] . '%'];
         if ($param['bank'] != '') $where[] = ['a.trade_bank', 'like', '%' . $param['bank'] . '%'];
@@ -260,7 +261,7 @@ class Export extends Base
             b.status 认领审批状态,
             b.remark 驳回原因')
             ->leftJoin('trade_pool b', 'b.tradNo=a.tradNo')
-            ->leftJoin('assoc c', 'c.viceCode=b.logNo and c.type=2 and c.status<>3')
+            ->leftJoin('assoc c', 'c.viceCode=b.logNo')
             ->leftJoin('qrd_info d', 'd.sequenceNo=c.orderCode')
             ->where($where)
             ->order('a.trade_time desc')

+ 9 - 4
app/admin/controller/InvCat.php

@@ -143,14 +143,15 @@ class InvCat extends Base{
         if($cat_code!=''){
             $condition[]=["cat_code|merge_code","like","%$cat_code%"];
         }
-        $status =isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
-        if($status!==''){
-          $condition[]=["status","=",$status];
+        $status =isset($this->post['status'])&&$this->post['status']!==''?$this->post['status']:[];
+        if(!empty($status)){
+            $condition[]=["status","in",$status];
         }
         $count =Db::name("inv_cat")->where($condition)->count();
         $total=ceil($count/$size);
         $page = $page>=$total? intval($total):$page;
-        $list =Db::name("inv_cat")->where($condition)->order("id desc")->page($page,$size)->select()->toArray();
+        $list =Db::name("inv_cat")->where($condition)->order("status asc,id desc")->page($page,$size)->select()
+        ->toArray();
         foreach ($list as &$value){
             $value['tax'] = $value['tax']==''?[]:explode("、",$value['tax']);
         }
@@ -167,6 +168,10 @@ class InvCat extends Base{
         if($cat_code!=''){
             $condition[]=["cat_code|merge_code","like","%$cat_code%"];
         }
+        $status =isset($this->post['status'])&&$this->post['status']!==''?$this->post['status']:[];
+        if(!empty($status)){
+            $condition[]=['status','in',$status];
+        }
        $list =Db::name("inv_cat")->where($condition)
        ->field("cat_name,cat_code,status,tax,addtax,sumitem,`desc`,short_name,merge_code,LENGTH(cat_name) as weight")
        ->order("weight asc,addtime desc")

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

@@ -23,12 +23,12 @@ class Menu extends Base{
         $level = $this->request->post('level/d',$this->level,'trim');
         if ($level == '') return app_show(10000, "账户角色账户已禁用", []);
         if ($level != 1) {
-            $role = Db::name("role_action")->where("role_id", "=", $this->roleid)->find();
+            $role = Db::name("role_action")->where("role_id", "=", $this->roleid)->json(['action_conllect'])->find();
 
             if ($role == false) {
                 return app_show(0, "获取成功", []);
             }
-            $action = Db::name("action")->where(['id' => explode(",", $role['action_conllect']), "status" => 1, "is_del" => 0])->column("id,menuid,action_code");
+            $action = Db::name("action")->where(['id' => $role['action_conllect'], "status" => 1, "is_del" => 0])->column("id,menuid,action_code");
             if (empty($action)) return app_show(0, "获取成功", []);
 
             $MenuAction = [];

+ 246 - 43
app/admin/controller/OrderInv.php

@@ -28,18 +28,30 @@ class OrderInv extends Base{
      * 新建销售单开票申请
      */
    public function create(){
-	        $companyType = isset($this->post['companyType'])&&$this->post['companyType']!=='' ? trim($this->post['companyType']):"";
-	        if ($companyType==''){
-	              return error_show(1004,"参数 companyType 不能为空");
-	        }
-        	$buy_id = isset($this->post['buy_id'])&&$this->post['buy_id']!=='' ? intval($this->post['buy_id']):"";
+   	    $is_comon = isset($this->post['is_comon'])&&$this->post['is_comon']!=='' ? trim($this->post['is_comon']):'0';
+   	    if($is_comon==0){
+   	    	$buy_id = isset($this->post['buy_id'])&&$this->post['buy_id']!=='' ? intval($this->post['buy_id']):'';
 	       if($buy_id==''){
-	           return error_show(1004,"参数 buy_id 不能为空");
+	           return error_show(1004,'参数 buy_id 不能为空');
 	       }
-           $buyinfo =Db::name("customer_invoice")->where(['id'=>$buy_id,"is_del"=>0])->find();
+           $buyinfo =Db::name('customer_invoice')->where(['id'=>$buy_id,'is_del'=>0])->find();
            if($buyinfo==false){
-                 return error_show(1004,"购买方发票信息未找到");
+                 return error_show(1004,'购买方发票信息未找到');
            }
+   	    }else{
+   	    	        $buy_id = isset($this->post['buyNo'])&&$this->post['buyNo']!=='' ? trim($this->post['buyNo']):'';
+   	    		       if($buy_id==''){
+   	    		           return error_show(1004,'参数 buyNo不能为空');
+   	    		       }
+   	    	           $buyinfo =Db::name('company_info')
+   	    	           ->field("invoice_title,company_license invoice_code,company_address invoice_addr,
+   	    	          mobile invoice_mobile,bank_name invoice_bank,bankNo invoice_bankNo")
+   	    	           ->where(['companyNo'=>$buy_id,'is_del'=>0])->find();
+   	    	           if($buyinfo==false){
+   	    	                 return error_show(1004,'购买方发票信息未找到');
+   	    	           }
+   	    }
+        
 
 		if($this->level==1){
 			$companyNo = isset($this->post['companyNo'])&&$this->post['companyNo']!=='' ? trim($this->post['companyNo']):"";
@@ -108,6 +120,7 @@ class OrderInv extends Base{
                     	Db::rollback();
                         return error_show(1004,"确认单{$value['sequenceNo']}待开票金额不足");
                     }
+                    if($qrd['is_comon']!=$is_comon) throw new \Exception("确认单{$value['sequenceNo']}类型有误");
                    $ainv = Db::name("invoice_pool")
                        ->alias("a")
                        ->leftJoin("invoice_good b", "a.invNo=b.invNo and b.is_del=0")
@@ -212,6 +225,7 @@ class OrderInv extends Base{
             "exam_remark"=>$exam_remark, //审核备注
             "ainv_fee"=>0,//已核销金额
             "winv_fee"=>$invfee,//未核销金额
+            'is_comon'=> $is_comon ,
             "status"=>1,// 带财务审核
             "is_del"=>0,
             "email"=>$email,
@@ -2472,7 +2486,7 @@ class OrderInv extends Base{
             if($value["inv_total"]==""&& in_array($value['inv_type'],["fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"])){
                 return error_show(1005,"第".($key+1)."行缺少发票金额数据");
             }
-             if($value["inv_subtotal"]==""){
+             if($value["inv_subtotal"]=="" && !in_array($value['inv_type'],['fully_digitalized_special_electronic', 'fully_digitalized_normal_electronic'])){
                 return error_show(1005,"第".($key+1)."行缺少发票税后金额数据");
             }
             if($value["open_date"]==""){
@@ -2497,7 +2511,7 @@ class OrderInv extends Base{
 //            	if($value['buyer_bankNo']=="") return error_show(1005,"第".($key+1)."行缺少购买方银行账户数据");
 //            	if($value['tax_fee']=="") return error_show(1005,"第".($key+1)."行缺少发票税额数据");
 //            }
-			!isset($total[$value['invNo']]) ? $total[$value['invNo']]['total']=0:"";
+			!isset($total[$value['invNo']]) ? $total[$value['invNo']]['inv_total']=0:"";
 
             $temp=[];
             $temp['invNo'] = $value["invNo"];
@@ -2538,12 +2552,12 @@ class OrderInv extends Base{
 
 		 	foreach ($total as $key=>$val){
 				if(!isset($inpool[$key])) throw new Exception("{$key}发票数据不存在或状态有误");
-				if(in_array($val['inv_type'],["fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"]) && $inpool[$key]['winv_fee']!=$val['total']){
+				if(in_array($val['inv_type'],["fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"]) && $inpool[$key]['winv_fee']>$val['inv_total']){
 					throw new Exception("{$key}全电发票面金额小于未开票金额");
 				}
 				if($inpool[$key]['inv_type']!= $val['inv_type']) throw new Exception("{$key}发票类型有误");
 				$update=[
-					"status"=>in_array($val['inv_type'],["fully_digitalized_special_electronic", "fully_digitalized_normal_electronic"])?4:3,
+					"status"=>3,
 					"open_type"=>$inpool[$key]['open_type']??3,
 					"updatetime"=>date("Y-m-d H:i:s")
 				];
@@ -2554,38 +2568,38 @@ class OrderInv extends Base{
                 }
 
                if($update['status']==4){
-            	$qrdArr=Db::name("assoc")->where(["viceCode"=>$key,"is_del"=>0])->column("id,orderCode,cancel_fee");
-                 if(!empty($qrdArr)){
-                      foreach ($qrdArr as $value){
-                          $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
-                          if($qrdinfo==false){
-                              Db::rollback();
-                              return error_show(1003,"确认单信息未找到");
-                          }
-                          if($qrdinfo['inv_fee']<$value['cancel_fee']){
-                               Db::rollback();
-                              return error_show(1003,"确认单信息开票金额不足");
-                          }
-                          $update =[
-                              "ainv_fee"=>$qrdinfo['ainv_fee']+$value['cancel_fee'],
-                              "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
-                              "invtime"=>date("Y-m-d H:i:s"),
-                              "inv_status"=>$qrdinfo['winv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 3 : 2,
-                              "updatetime"=>date("Y-m-d H:i:s"),
-                          ];
-                          $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
-                          if($qrdup==false){
-                              Db::rollback();
-                              return error_show(1003,"确认单信息更新失败");
-                          }
-                          $assoc=["status"=>2,"assoc_time"=>date("Y-m-d H:i:s"),"updatetime"=>date("Y-m-d H:i:s")];
-                          $assocup =Db::name("assoc")->where($value)->update($assoc);
-                          if($assocup==false){
-                              Db::rollback();
-                              return error_show(1003,"确认单关联信息更新失败");
+                    $qrdArr=Db::name("assoc")->where(["viceCode"=>$key,"is_del"=>0])->column("id,orderCode,cancel_fee");
+                     if(!empty($qrdArr)){
+                          foreach ($qrdArr as $value){
+                              $qrdinfo =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->find();
+                              if($qrdinfo==false){
+                                  Db::rollback();
+                                  return error_show(1003,"确认单信息未找到");
+                              }
+                              if($qrdinfo['inv_fee']<$value['cancel_fee']){
+                                   Db::rollback();
+                                  return error_show(1003,"确认单信息开票金额不足");
+                              }
+                              $update =[
+                                  "ainv_fee"=>$qrdinfo['ainv_fee']+$value['cancel_fee'],
+                                  "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
+                                  "invtime"=>date("Y-m-d H:i:s"),
+                                  "inv_status"=>$qrdinfo['winv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 3 : 2,
+                                  "updatetime"=>date("Y-m-d H:i:s"),
+                              ];
+                              $qrdup = Db::name("qrd_info")->where($qrdinfo)->update($update);
+                              if($qrdup==false){
+                                  Db::rollback();
+                                  return error_show(1003,"确认单信息更新失败");
+                              }
+                              $assoc=["status"=>2,"assoc_time"=>date("Y-m-d H:i:s"),"updatetime"=>date("Y-m-d H:i:s")];
+                              $assocup =Db::name("assoc")->where($value)->update($assoc);
+                              if($assocup==false){
+                                  Db::rollback();
+                                  return error_show(1003,"确认单关联信息更新失败");
+                              }
                           }
-                      }
-                 }
+                     }
                 }
                 $val['inv_type'] = $this->kingInvoice[$val['inv_type']];
                $list[]=$val;
@@ -2650,4 +2664,193 @@ class OrderInv extends Base{
     	$up= $info->save();
     	return $up? app_show(0,"修改成功"):error_show(1004,"修改失败");
     }
+    //万宇数据传递
+    public function  importInvByWanyu(){
+		$param =$this->request->only(['data'=>[]],'post');
+		if(empty($param['data']))return error_show(1004,'参数 data 不能为空');
+		$total=[];
+		$list=[];
+		 foreach ($param['data'] as $key=>$value){
+
+            if($value['invNo']==''){
+                return error_show(1005,'第'.($key+1).'行缺少发票申请编号数据');
+            }
+            if($value['inv_type']===''){
+                return error_show(1005,'第'.($key+1).'行缺少发票类型数据');
+            }
+            if(!in_array($value['inv_type'],$this->invName))  return error_show(1005,'第'.($key+1).'行发票类型数据有误');
+            if($value['inv_code']=='' && !in_array($value['inv_type'],[ 'fully_digitalized_special_electronic', 'fully_digitalized_normal_electronic'])){
+                return error_show(1005,'第'.($key+1).'行缺少发票代码数据');
+            }
+            if($value['inv_number']==''){
+                return error_show(1005,'第'.($key+1).'行缺少发票号码数据');
+            }
+            if($value['open_date']==''){
+                return error_show(1005,'第'.($key+1).'行缺少发票开票日期数据');
+            }
+            //电子票校验码必传
+            if($value['check_code']=='' && in_array($value['inv_type'],['normal','roll','toll','electronic'])){
+                return error_show(1005,'第'.($key+1).'行缺少发票校验码数据');
+            }
+            if($value['seller_id']=="") return error_show(1005,"第".($key+1)."行缺少销售方纳税识别号数据");
+            if($value['seller_title']=="") return error_show(1005,"第".($key+1)."行缺少销售方名称数据");
+            if($value['seller_addr']=="") return error_show(1005,"第".($key+1)."行缺少销售方地址数据");
+            if($value['seller_mobile']=="") return error_show(1005,"第".($key+1)."行缺少销售方联系方式数据");
+            if($value['seller_bank']=="") return error_show(1005,"第".($key+1)."行缺少销售方银行数据");
+            if($value['seller_bankNo']=="") return error_show(1005,"第".($key+1)."行缺少销售方银行账户数据");
+            if($value['buyer_id']=="") return error_show(1005,"第".($key+1)."行缺少购买方纳税识别号数据");
+            if($value['buyer_title']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['buyer_addr']=="") return error_show(1005,"第".($key+1)."行缺少购买方地址数据");
+            if($value['buyer_mobile']=="") return error_show(1005,"第".($key+1)."行缺少购买方联系方式数据");
+            if($value['buyer_bank']=="") return error_show(1005,"第".($key+1)."行缺少购买方银行数据");
+            if($value['buyer_bankNo']=="") return error_show(1005,"第".($key+1)."行缺少购买方银行账户数据");
+            if($value['buyer_title']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['XMMC']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['GGXH']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['DW']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['SPSL']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['DJ']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['JE']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['SL']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['SE']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if($value['JSHJ']=="") return error_show(1005,"第".($key+1)."行缺少购买方名称数据");
+            if(isset($total[$value['invNo']])){
+                $total[$value['invNo']]['inv_subtotal']+= $value['JE'];
+                $total[$value['invNo']]['inv_total']+= $value['JSHJ'];
+                $total[$value['invNo']]['tax_fee']+= $value['SE'];
+                $item_t= json_decode($total[$value['invNo']]['item'],true);
+                $item_t[]=[
+                                    'XMMC'=>$value['XMMC'],
+                                    'GGXH'=>$value['GGXH'],
+                                    'DW'=>$value['DW'],
+                                    'SPSL'=>$value['SPSL'],
+                                    'DJ'=>$value['DJ'],
+                                    'JE'=>$value['JE'],
+                                    'SL'=>$value['SL'],
+                                    'SE'=>$value['SE'],
+                                    'SPBM'=>$value['SPBM'],
+                                    'JSHJ'=>$value['JSHJ'],
+                                 ];
+                $total[$value['invNo']]['item']=json_encode($item_t,JSON_UNESCAPED_UNICODE);
+                continue;
+            }
+            $item=[[ 'XMMC'=>$value['XMMC'],
+                     'GGXH'=>$value['GGXH'],
+                     'DW'=>$value['DW'],
+                     'SPSL'=>$value['SPSL'],
+                     'DJ'=>$value['DJ'],
+                     'JE'=>$value['JE'],
+                     'SL'=>$value['SL'],
+                     'SE'=>$value['SE'],
+                     'SPBM'=>$value['SPBM'],
+                     'JSHJ'=>$value['JSHJ'],
+                     ]];
+            $temp=[];
+            $temp['invNo'] = $value['invNo'];
+            $temp['type'] = $value['type'];
+            $temp['inv_type'] =$value['inv_type'];
+            $temp['inv_code'] = $value['inv_code'];
+            $temp['inv_number'] = $value['inv_number'];
+            $temp['inv_subtotal'] = $value['JE'];
+            $temp['inv_total'] = $value['JSHJ'];
+            $temp['check_code'] = $value['check_code']??'';
+            $temp['seller_id'] = $value['seller_id']??'';
+            $temp['seller_title'] = $value['seller_title']??'';
+            $temp['seller_addr'] = $value['seller_addr']??'';
+            $temp['seller_mobile'] = $value['seller_mobile']??'';
+            $temp['seller_bank'] = $value['seller_bank']??'';
+            $temp['seller_bankNo'] = $value['seller_bankNo']??'';
+            $temp['buyer_id'] = $value['buyer_id']??'';
+            $temp['buyer_title'] = $value['buyer_title']??'';
+            $temp['buyer_addr'] = $value['buyer_addr']??'';
+            $temp['buyer_mobile'] = $value['buyer_mobile']??'';
+            $temp['buyer_bank'] = $value['buyer_bank']??'';
+            $temp['buyer_bankNo'] = $value['buyer_bankNo']??'';
+            $temp['tax_fee'] = $value['SE']??'';
+            $temp['remark'] = $value['remark']??'';
+            $temp['item'] =json_encode($item,JSON_UNESCAPED_UNICODE);
+            $temp['pdfstream'] = '';
+            $temp['open_date'] =  date('Y-m-d H:i:s',strtotime($value['open_date']));
+            $temp['status'] =1;
+            $temp['is_del'] = 0;
+            $temp['addtime'] = date('Y-m-d H:i:s');
+            $temp['updatetime'] = date('Y-m-d H:i:s');
+            $total[$value['invNo']]=$temp;
+        }
+
+		 Db::startTrans();
+		 try{
+		 	$keyarr =array_keys($total);
+		 	$inpool = Db::name('invoice_pool')->where([['invNo','in',$keyarr],['open_type','in',[0,2,3]],['is_del','=',0],['status','=',2]])->column('winv_fee,invNo,inv_value,inv_type','invNo');
+
+		 	foreach ($total as $key=>$val){
+				if(!isset($inpool[$key])) throw new Exception("{$key}发票数据不存在或状态有误");
+				if(in_array($val['inv_type'],['fully_digitalized_special_electronic', 'fully_digitalized_normal_electronic']) && $inpool[$key]['winv_fee']!=$val['inv_total']){
+					throw new Exception("{$key}全电发票面金额小于未开票金额");
+				}
+				if($inpool[$key]['inv_type']!= $val['inv_type']) throw new Exception("{$key}发票类型有误");
+				$update=[
+					'status'=>4,
+					'open_type'=>$inpool[$key]['open_type']??3,
+					'updatetime'=>date('Y-m-d H:i:s')
+				];
+				 $up =Db::name('invoice_pool')->where([['invNo','=',$key],['is_del','=',0]])->save($update);
+                if(!$up){
+                    Db::rollback();
+                    return error_show(1005,'发票状态更新失败');
+                }
+
+               if($update['status']==4){
+                    $qrdArr=Db::name('assoc')->where(['viceCode'=>$key,'is_del'=>0])->column('id,orderCode,cancel_fee');
+                     if(!empty($qrdArr)){
+                          foreach ($qrdArr as $value){
+                              $qrdinfo =Db::name('qrd_info')->where(['sequenceNo'=>$value['orderCode']])->find();
+                              if($qrdinfo==false){
+                                  Db::rollback();
+                                  return error_show(1003,'确认单信息未找到');
+                              }
+                              if($qrdinfo['inv_fee']<$value['cancel_fee']){
+                                   Db::rollback();
+                                  return error_show(1003,'确认单信息开票金额不足');
+                              }
+                              $update =[
+                                  'ainv_fee'=>$qrdinfo['ainv_fee']+$value['cancel_fee'],
+                                  'inv_fee'=>$qrdinfo['inv_fee']-$value['cancel_fee'],
+                                  'invtime'=>date('Y-m-d H:i:s'),
+                                  'inv_status'=>$qrdinfo['winv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 3 : 2,
+                                  'updatetime'=>date('Y-m-d H:i:s'),
+                              ];
+                              $qrdup = Db::name('qrd_info')->where($qrdinfo)->update($update);
+                              if($qrdup==false){
+                                  Db::rollback();
+                                  return error_show(1003,'确认单信息更新失败');
+                              }
+                              $assoc=['status'=>2,'assoc_time'=>date('Y-m-d H:i:s'),'updatetime'=>date('Y-m-d H:i:s')];
+                              $assocup =Db::name('assoc')->where($value)->update($assoc);
+                              if($assocup==false){
+                                  Db::rollback();
+                                  return error_show(1003,'确认单关联信息更新失败');
+                              }
+                          }
+                     }
+                }
+                $val['inv_type'] = $this->kingInvoice[$val['inv_type']];
+               $list[]=$val;
+		 	}
+
+		 	     $inticket =Db::name('invoice_ticket')->insertAll($list);
+			     if(!$inticket){
+	                Db::rollback();
+	                return error_show(1005,'发票数据录入失败');
+	            }
+                Db::commit();
+                return app_show(0,'发票数据录入成功');
+
+		 }catch (\Exception $e){
+		 	Db::rollback();
+		 	return error_show(1008,$e->getMessage());
+		 }
+
+    }
+
 }

+ 4 - 1
app/admin/controller/OrderPay.php

@@ -43,11 +43,14 @@ class OrderPay extends Base{
                     Db::rollback();
                    return error_show(1004,"销售单核销金额不能为空");
                 }
-                $qrd =Db::name("qrd_info")->where("sequenceNo","=",$value['sequenceNo'])->field("id,customerNo,status,pay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
+                $qrd =Db::name("qrd_info")->where("sequenceNo","=",$value['sequenceNo'])
+                ->field("id,customerNo,status,pay_fee,wpay_fee,pay_status,totalPrice,is_comon")
+                ->findOrEmpty();
                 if(empty($qrd)){
                     Db::rollback();
                    return error_show(1004,"销售单信息未找到");
                 }
+                if($qrd['is_comon']==1) throw new \Exception("{$value['sequenceNo']} 通用订单不可认领资金");
                 if($qrd['wpay_fee']<$value['trad_fee']){
                    Db::rollback();
                    return error_show(1004,"销售单未付款金额不足核销金额");

+ 68 - 24
app/admin/controller/Payment.php

@@ -21,6 +21,7 @@ class Payment extends Base
 //    已作废:invalidated
 //    已红冲:reversed
     protected $invStatus=[0=>"待验证","1"=>'正常',"2"=>'已作废',"3"=>'已红冲'];
+    
     public function __construct(App $app) {
     	parent::__construct($app);
     	$invoice =Config::get("invoiceType");
@@ -221,16 +222,32 @@ class Payment extends Base
        $data=[];
         foreach ($list as $key=>$value){
             $value['ordeNum'] = Db::name("pay_info")->where([["payNo","=",$value["payNo"]],["is_del","=",0]])->count();
-            $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
-            (["code"=>$value['payNo'],"a.status"=>1])->column("a.id,b.tag_name,a.tag_img,a.tag_remark","b.type");
-            $value['inv_tag_name']=$tag[2]['tag_name']??'';
-            $value['inv_tag_id']=$tag[2]['id']??'0';
-            $value['pay_tag_name']=$tag[1]['tag_name']??'';
-            $value['pay_tag_id']=$tag[1]['id']??'0';
-            $value['pay_tag_img']=$tag[1]['tag_img']??'';
-            $value['inv_tag_img']=$tag[2]['tag_img']??'';
-            $value['inv_tag_remark']=$tag[2]['tag_remark']??'';
-            $value['pay_tag_remark']=$tag[1]['tag_remark']??'';
+               $value['inv_tag_name']='';
+                            $value['pay_tag_name']='';
+                            $value['pay_tag_img']='';
+                            $value['inv_tag_id']='0';
+                            $value['pay_tag_id']='0';
+                            $value['pay_tag_remark']='';
+                            $value['inv_tag_img']='';
+                            $value['inv_tag_remark']='';
+             if($value['pay_tag']==1 || $value['inv_tag']==1){
+	            $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
+	            (['code'=>$value['payNo'],"a.status"=>[1,2]])->order('a.id desc')->column('a.id,b.tag_name,a.tag_img,a
+	            .tag_remark','b.type');
+	           if($value['inv_tag']==1){
+	            $value['inv_tag_name']=$tag[2]['tag_name']??'';
+	            $value['inv_tag_id']=$tag[2]['id']??'0';
+	            $value['inv_tag_img']=$tag[2]['tag_img']??'';
+	            $value['inv_tag_remark']=$tag[2]['tag_remark']??'';
+	           }
+
+	            if($value['pay_tag']==1){
+		            $value['pay_tag_id']=$tag[1]['id']??'0';
+		            $value['pay_tag_name']=$tag[1]['tag_name']??'';
+		            $value['pay_tag_img']=$tag[1]['tag_img']??'';
+		            $value['pay_tag_remark']=$tag[1]['tag_remark']??'';
+	            }
+            }
             $value['has_account'] = (int)isset($supp_account['data'][$value['supplierNo']]);
             $data[]=$value;
         }
@@ -1114,16 +1131,32 @@ class Payment extends Base
 		        ->select()->toArray();
 	        }
         $payinfo['pay_type']=Db::name('supplier_info')->where('code',$payinfo['supplierNo'])->value('pay_method','');
-        $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
-            (["code"=>$payNo,"a.status"=>1])->column("a.id,b.tag_name,a.tag_img,a.tag_remark","b.type");
-            $payinfo['inv_tag_id']=$tag[2]['id']??'0';
-            $payinfo['pay_tag_id']=$tag[1]['id']??'0';
-            $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']??'';
+        $payinfo['inv_tag_name']='';
+                            $payinfo['pay_tag_name']='';
+                            $payinfo['pay_tag_img']='';
+                            $payinfo['inv_tag_id']='0';
+                            $payinfo['pay_tag_id']='0';
+                            $payinfo['pay_tag_remark']='';
+                            $payinfo['inv_tag_img']='';
+                            $payinfo['inv_tag_remark']='';
+             if($payinfo['pay_tag']==1 || $payinfo['inv_tag']==1){
+	            $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
+	            (['code'=>$payNo,"a.status"=>[1,2]])->order('id desc')->column('a.id,b.tag_name,a.tag_img,a
+	            .tag_remark','b.type');
+	              if($payinfo['inv_tag']==1){
+	            $payinfo['inv_tag_name']=$tag[2]['tag_name']??'';
+	            $payinfo['inv_tag_id']=$tag[2]['id']??'0';
+	            $payinfo['inv_tag_img']=$tag[2]['tag_img']??'';
+	            $payinfo['inv_tag_remark']=$tag[2]['tag_remark']??'';
+	           }
+
+	            if($payinfo['pay_tag']==1){
+		            $payinfo['pay_tag_id']=$tag[1]['id']??'0';
+		            $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['cgdlist'] = $pay;
         return app_show(0,"获取成功",$payinfo);
     }
@@ -1298,7 +1331,7 @@ class Payment extends Base
             $val = Validate::rule([
                 'payNo|对账编号' => 'require|max:255',
                 'invoiceType|发票类型' => 'require|in:' . implode(',', array_values($this->invName)),
-                'invoiceCode|发票代码' => 'require|max:255',
+                'invoiceCode|发票代码' => 'max:255|checkInvoiceCode:',
                 'invoiceNumber|发票号码' => 'require|max:255',
                 'inv_subtotal_amount|发票税前金额' => 'require|float|max:9999999.99',
                 'open_time|开票日期' => 'require|date',
@@ -1312,6 +1345,14 @@ class Payment extends Base
                 }
                 return true;
             });
+            $val->extend('checkInvoiceCode', function ($val, $rule, $da) {
+
+                if (in_array($da['invoiceType'], ['special', 'normal', 'roll', 'special_electronic', 'electronic', 'toll'])) {
+                    if (empty($val)) return '发票代码必填';
+                }
+                return true;
+            });
+
 
             //所有的payNo(对账编码)
             $payNo = array_column($param['list'], 'payNo');
@@ -1987,7 +2028,7 @@ class Payment extends Base
 	    if($payinfo==false){
 		    return error_show(1004,"对账单数据未找到");
 	    }
-	    if ($this->level == 2) {
+	    if ($this->level == 2 && $payinfo['is_comon']==0) {
 		    //判断是否开通供应商账号
 		    $temp = check_has_account_by_supplierNos([$payinfo['supplierNo']]);
 		    if (isset($temp['data'][$payinfo['supplierNo']])) return error_show(1004, '该供应商已经开通账号,不允许当前账号操作');
@@ -2082,12 +2123,12 @@ class Payment extends Base
 			if(empty($pay))throw new Exception("对账详情未找到");
 			$invup =Db::name("pay_payment")->where($invinfo)->update(["status"=>5,"updatetime"=>date("Y-m-d H:i:s")]);
 			if($invup==false)throw new Exception("付款更新失败");
-
+            if($pay['apay_fee']<$invinfo['pay_fee'])throw new Exception('已付款金额不足');
 			$paydata=[
 				 "apay_fee"=>$pay['apay_fee']-$invinfo['pay_fee'],
                   "wpay_fee"=>$pay['wpay_fee']+$invinfo['pay_fee'],
                   "pay_status" => $pay['pay_fee']==0 &&($pay['apay_fee']-$invinfo['pay_fee'])==0?1:2,
-                   "updatetime" => date("Y-m-d H:i:s")
+                  "updatetime" => date("Y-m-d H:i:s")
 			];
 			$oayup =Db::name("pay")->where($pay)->update($paydata);
 			if($oayup==false)throw new Exception("对账更新失败");
@@ -2102,6 +2143,9 @@ class Payment extends Base
 		$up =Db::name("pay_return")->where($returninfo)->update($update);
 		if($up==false)throw new Exception("退款申请审核失败");
 		Db::commit();
+		if($param['status']==2 && $pay['is_comon']==1){
+            event('comonOrder', ['payNo' => $pay['payNo'], 'pay_fee' => $invinfo['pay_fee'], 'type' => 'repay']);
+        }
 		return app_show(0,"退款申请审核成功");
 		}catch (\Exception $e){
 			Db::rollback();

+ 8 - 9
app/admin/controller/Role.php

@@ -88,10 +88,10 @@ class Role extends Base{
         if($isT){
             return error_show(1002,"角色名称已存在");
         }
-        $action = isset($post['action'])&&is_array($post['action']) ? implode(",",$post['action']) : "";
+        $action = isset($post['action'])&&is_array($post['action']) ? json_encode($post['action']) : "";
 
-        $data = isset($post['action_data']) &&is_array($post['action_data'])?implode(",",$post['action_data']): "";
-        $private_data = isset($post['private_data']) &&is_array($post['private_data'])?implode(",",$post['private_data']): "";
+        $data = isset($post['action_data']) &&is_array($post['action_data'])?json_encode($post['action_data']): "";
+        $private_data = isset($post['private_data']) &&is_array($post['private_data'])?json_encode($post['private_data']): "";
         Db::startTrans();
         try {
             $list = [
@@ -148,14 +148,13 @@ class Role extends Base{
         $info =Db::name("role")->alias("a")
         ->leftJoin("cfp_role_action t","a.id=t.role_id")
         ->field("a.*,t.action_conllect,t.action_data,t.private_data")
+        ->json(['action_conllect',"action_data","private_data"])
         ->where("a.id","=",$roleid)->find();
         if(!$info){
             return error_show(1002,"未找到对应的数据");
         }
 
-        $info['action'] = $info['action_conllect'] ? explode(",", $info['action_conllect']) : [];
-        $info['action_data'] =$info['action_data']!=""?explode(",",$info['action_data']):"";
-        $info['private_data'] =$info['private_data']!=""?explode(",",$info['private_data']) :"";
+        $info['action'] = $info['action_conllect'] ;
         return app_show(0,"获取成功",$info);
     }
     /** 角色信息编辑
@@ -199,12 +198,12 @@ class Role extends Base{
         if($vers){
             return error_show(1002,"角色名已存在");
         }
-        $action = isset($post['action'])&&is_array($post['action']) ? implode(",",$post['action']) : "";
+        $action = isset($post['action'])&&is_array($post['action']) ?json_encode($post['action']) : "";
         if($action==""){
             return error_show(1004,"功能权限不能为空");
         }
-        $data = isset($post['action_data']) &&is_array($post['action_data'])?implode(",",$post['action_data']): "";
-        $private_data = isset($post['private_data']) &&is_array($post['private_data'])?implode(",",$post['private_data']): "";
+        $data = isset($post['action_data']) &&is_array($post['action_data'])?json_encode($post['action_data']): "";
+        $private_data = isset($post['private_data']) &&is_array($post['private_data'])?json_encode($post['private_data']): "";
         Db::startTrans();
         try {
             $list = [

+ 97 - 31
app/admin/controller/Sale.php

@@ -3,7 +3,7 @@
 
 namespace app\admin\controller;
 
-use app\admin\model\CgdInfo;use app\admin\model\InvoicePool;use app\admin\model\Pay;use app\admin\model\TradePool;use think\App;
+use app\admin\model\CgdInfo;use app\admin\model\InvoicePool;use app\admin\model\Pay;use app\admin\model\QrdInfo;use app\admin\model\TradePool;use think\App;
 use think\facade\Db;use think\facade\Validate;
 class Sale extends Base{
 	#public $novalidate=["*"];
@@ -153,18 +153,41 @@ class Sale extends Base{
         $data=[];
         foreach ( $list as $ky=>$value){
             $value['catInfo'] = json_decode($value['catInfo'],true);
-            $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
-            (["code"=>$value['sequenceNo'],"a.status"=>1])->column("a.id,b.tag_name,a.tag_img,a.tag_remark","b.type");
-            $value['goodNum'] = $value['goodNum'] -$value['thNum'];
-            $value['sendNum'] = $value['sendNum'] -$value['thNum'];
-            $value['inv_tag_name']=$tag[4]['tag_name']??'';
-            $value['inv_tag_id']=$tag[4]['id']??'0';
-            $value['pay_tag_id']=$tag[3]['id']??'0';
-            $value['pay_tag_name']=$tag[3]['tag_name']??'';
-            $value['pay_tag_img']=$tag[3]['tag_img']??'';
-            $value['inv_tag_img']=$tag[4]['tag_img']??'';
-            $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
-            $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
+                            $value['inv_tag_name']='';
+                            $value['pay_tag_name']='';
+                            $value['pay_tag_img']='';
+                            $value['inv_tag_id']='0';
+                            $value['pay_tag_id']='0';
+                            $value['pay_tag_remark']='';
+                            $value['inv_tag_img']='';
+                            $value['inv_tag_remark']='';
+             if($value['pay_tag']==1 || $value['inv_tag']==1){
+	            $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
+	            (["code"=>$value['sequenceNo'],"a.status"=>[1,2]])->order("id desc")->column("a.id,b.tag_name,a.tag_img,a.tag_remark","b.type");
+	            if($value['pay_tag']==1){
+		            $value['inv_tag_name']=$tag[4]['tag_name']??'';
+		            $value['inv_tag_id']=$tag[4]['id']??'0';
+		            $value['inv_tag_img']=$tag[4]['tag_img']??'';
+		            $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
+	            }
+	           
+	             if($value['inv_tag']==1){
+		            $value['pay_tag_id']=$tag[3]['id']??'0';
+		            $value['pay_tag_name']=$tag[3]['tag_name']??'';
+		            $value['pay_tag_img']=$tag[3]['tag_img']??'';
+		            $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
+	            }
+            }
+             $value['plat_pay_fee']=0;
+            if($value['is_comon']==1){
+                $tax = QrdInfo::where(['cxCode'=>$value['cxCode'],'is_comon'=>0])->findOrEmpty();
+                if($tax->isEmpty()==false){
+                	    $rate =$tax->totalPrice==0?0: ($tax->apay_fee/$tax->totalPrice);
+                	  $value['plat_pay_fee']= round($value['totalPrice']* $rate,2);
+                }
+            }
+              $value['goodNum'] = $value['goodNum'] -$value['thNum'];
+	          $value['sendNum'] = $value['sendNum'] -$value['thNum'];
             $invArr = Db::name("assoc")
                 ->alias("a")
                 ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
@@ -308,16 +331,43 @@ class Sale extends Base{
         $data=[];
         foreach ( $list as $ky=>$value){
             $value['catInfo'] = json_decode($value['catInfo'],true);
-            $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")->where
-            (["code"=>$value['sequenceNo'],"a.status"=>1])->column("b.tag_name,a.tag_img,a.tag_remark","b.type");
             $value['goodNum'] = $value['goodNum'] -$value['thNum'];
             $value['sendNum'] = $value['sendNum'] -$value['thNum'];
-            $value['inv_tag_name']=$tag[4]['tag_name']??'';
-            $value['pay_tag_name']=$tag[3]['tag_name']??'';
-            $value['pay_tag_img']=$tag[3]['tag_img']??'';
-            $value['inv_tag_img']=$tag[4]['tag_img']??'';
-            $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
-            $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
+            $value['inv_tag_name']='';
+                            $value['pay_tag_name']='';
+                            $value['pay_tag_img']='';
+                            $value['inv_tag_id']='0';
+                            $value['pay_tag_id']='0';
+                            $value['pay_tag_remark']='';
+                            $value['inv_tag_img']='';
+                            $value['inv_tag_remark']='';
+             if($value['pay_tag']==1 || $value['inv_tag']==1){
+	            $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')->where
+	            (['code'=>$value['sequenceNo'],'a.status'=>[1,2]])->order('id desc')->column('a.id,b.tag_name,a.tag_img,a.tag_remark','b.type');
+	            if($value['pay_tag']==1){
+		            $value['inv_tag_name']=$tag[4]['tag_name']??'';
+		            $value['inv_tag_id']=$tag[4]['id']??'0';
+		            $value['inv_tag_img']=$tag[4]['tag_img']??'';
+		            $value['inv_tag_remark']=$tag[4]['tag_remark']??'';
+	            }
+	           
+	             if($value['inv_tag']==1){
+		            $value['pay_tag_id']=$tag[3]['id']??'0';
+		            $value['pay_tag_name']=$tag[3]['tag_name']??'';
+		            $value['pay_tag_img']=$tag[3]['tag_img']??'';
+		            $value['pay_tag_remark']=$tag[3]['tag_remark']??'';
+	            }
+            }
+              $value['goodNum'] = $value['goodNum'] -$value['thNum'];
+	          $value['sendNum'] = $value['sendNum'] -$value['thNum'];
+            $value['plat_pay_fee']=0;
+            if($value['is_comon']==1){
+                $tax = QrdInfo::where(["cxCode"=>$value['cxCode'],"is_comon"=>0])->findOrEmpty();
+                if($tax->isEmpty()==false){
+                	$rate = $tax->totalPrice==0?0: ($tax->apay_fee/$tax->totalPrice);
+                	  $value['plat_pay_fee']= round($value['totalPrice']* $rate,2);
+                }
+            }
             $invArr = Db::name("assoc")
                 ->alias("a")
                 ->leftJoin("invoice_good b", "a.viceCode=b.invNo AND b.orderCode =a.orderCode")
@@ -373,16 +423,32 @@ class Sale extends Base{
         $goodinfo = Db::name("good")->where(["spuCode"=>$qrdinfo["goodNo"]])->findOrEmpty();
         $qrdinfo['goodinfo'] =$goodinfo;
         $qrdinfo['catInfo'] = json_decode($qrdinfo['catInfo'],true);
-        $tag =Db::name("tag_log")->alias("a")->leftJoin("order_tag b","a.tag_id=b.id")
-        ->where(["code"=>$qrdinfo['sequenceNo'],"a.status"=>1])->column("a.id,b.tag_name,a.tag_img,a.tag_remark","b.type");
-        $qrdinfo['inv_tag_name']=$tag[4]['tag_name']??'';
-        $qrdinfo['pay_tag_name']=$tag[3]['tag_name']??'';
-        $qrdinfo['pay_tag_img']=$tag[3]['tag_img']??'';
-         $qrdinfo['inv_tag_id']=$tag[4]['id']??'0';
-          $qrdinfo['pay_tag_id']=$tag[3]['id']??'0';
-        $qrdinfo['pay_tag_remark']=$tag[3]['tag_remark']??'';
-        $qrdinfo['inv_tag_img']=$tag[4]['tag_img']??'';
-        $qrdinfo['inv_tag_remark']=$tag[4]['tag_remark']??'';
+                $qrdinfo['inv_tag_name']='';
+                $qrdinfo['pay_tag_name']='';
+                $qrdinfo['pay_tag_img']='';
+                $qrdinfo['inv_tag_id']='0';
+                $qrdinfo['pay_tag_id']='0';
+                $qrdinfo['pay_tag_remark']='';
+                $qrdinfo['inv_tag_img']='';
+                $qrdinfo['inv_tag_remark']='';
+        if($qrdinfo['pay_tag']==1 || $qrdinfo['inv_tag']==1){
+	        $tag =Db::name('tag_log')->alias('a')->leftJoin('order_tag b','a.tag_id=b.id')
+	        ->where(['code'=>$qrdinfo['sequenceNo'],'a.status'=>[1,2]])->order('id desc')->column('a.id,b.tag_name,a.tag_img,a.tag_remark','b.type');
+	         if($qrdinfo['pay_tag']==1){
+		            $qrdinfo['inv_tag_name']=$tag[4]['tag_name']??'';
+		            $qrdinfo['inv_tag_id']=$tag[4]['id']??'0';
+		            $qrdinfo['inv_tag_img']=$tag[4]['tag_img']??'';
+		            $qrdinfo['inv_tag_remark']=$tag[4]['tag_remark']??'';
+	            }
+	           
+	             if($qrdinfo['inv_tag']==1){
+		            $qrdinfo['pay_tag_id']=$tag[3]['id']??'0';
+		            $qrdinfo['pay_tag_name']=$tag[3]['tag_name']??'';
+		            $qrdinfo['pay_tag_img']=$tag[3]['tag_img']??'';
+		            $qrdinfo['pay_tag_remark']=$tag[3]['tag_remark']??'';
+	            }
+        }
+        
         $qrdinfo['goodNum'] = $qrdinfo['goodNum'] -$qrdinfo['thNum'];
         $qrdinfo['sendNum'] = $qrdinfo['sendNum'] -$qrdinfo['thNum'];
         $qrdinfo['customerAttr'] = Db::name("customer_info")->where(["companyNo"=>$qrdinfo['customerNo']])->value("parent",'');

+ 107 - 52
app/admin/controller/TagGood.php

@@ -3,11 +3,15 @@
 
 namespace app\admin\controller;
 
-use app\admin\model\OrderTag;use app\admin\model\Pay;use app\admin\model\QrdInfo;use app\admin\model\TagLog;use think\App;
-use think\facade\Db;
+use app\admin\model\OrderTag;
+use app\admin\model\Pay;
+use app\admin\model\QrdInfo;
+use app\admin\model\TagLog;
+use think\App;
+use think\facade\Db;use think\facade\Validate;
 
 class TagGood extends Base{
-	#public $novalidate=['*'];
+//	public $novalidate=['*'];
     public function __construct(App $app) {parent::__construct($app);}
     //新建标签
     public function create(){
@@ -52,7 +56,7 @@ class TagGood extends Base{
         $size = isset($this->post['size'])&&$this->post['size']!=''?intval($this->post['size']):15;
         $type = isset($this->post['type'])&&$this->post['type']!=''?intval($this->post['type']):'';
         $status = isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):'';
-        if($this->post['relaComNo']!=""){
+        if(isset($this->post['relaComNo']) && $this->post['relaComNo']!=""){
         	$companyNo = isset($this->post['relaComNo'])&& $this->post['relaComNo']!="" ? trim($this->post['relaComNo']) :"";
         }else{
         	 $companyNo = isset($this->post['companyNo'])&& $this->post['companyNo']!="" ? trim($this->post['companyNo']) :"";
@@ -82,7 +86,7 @@ class TagGood extends Base{
         $page = $page>=$total ? intval($total):$page;
         $list =Db::name("order_tag")->where($condition)->page($page,$size)->order("addtime desc")->select()->toArray();
         $comNo=array_column($list,"companyNo");
-        $ComArr=Db::name("supplier_info")->where(["code"=>$comNo])->column("name","code");
+        $ComArr=Db::connect("mysql_sys")->name("headquarters")->where(["code"=>$comNo])->column("name","code");
         foreach ($list as &$item){
         	$item['companyName']=$ComArr[$item['companyNo']]??"";
         }
@@ -191,7 +195,7 @@ class TagGood extends Base{
         if($code==''){
             return error_show(1004,"参数 code 不能为空");
         }
-        $taglog =Db::name("tag_log")->where(["tag_id"=>$tagid,"code"=>$code,"status"=>1])->findOrEmpty();
+//        $taglog =TagLog::where(["tag_id"=>$tagid,"code"=>$code,"status"=>1])->findOrEmpty();
         $total_fee =isset($this->post['total_fee']) &&$this->post["total_fee"]!=="" ? floatval($this->post["total_fee"]):"";
         if($total_fee==''){
             return error_show(1004,"参数 total_fee 不能为空");
@@ -200,18 +204,11 @@ class TagGood extends Base{
         $tag_remark=isset($this->post["tag_remark"]) && $this->post["tag_remark"]!=""?$this->post["tag_remark"]:"";
         Db::startTrans();
         try{
-        	if(!empty($taglog)){
-				$up = Db::name("tag_log")->where($taglog)->update(["status"=>0,"updatetime"=>date("Y-m-d H:i:s")]);
-				if($up==false){
-					Db::rollback();
-	                return error_show(1004,"标签日志新建失败");
-				}
-        	}
 	        if($taginfo['type']==1 || $taginfo['type']==2){
-		           $result= $this->payTag($taginfo['type'],$code,$total_fee);
+		           $this->payTag($taginfo['type'],$code,$total_fee);
 	        }
 	        if($taginfo['type']==3|| $taginfo['type']==4){
-		           $result= $this->qrdTag($taginfo['type'],$code,$total_fee);
+		           $this->qrdTag($taginfo['type'],$code,$total_fee);
 	        }
 	        $tagdata=[
 	            "code"=>$code,
@@ -226,23 +223,16 @@ class TagGood extends Base{
 	            "updatetime"=>date("Y-m-d H:i:s")
 			];
 	        $in =Db::name("tag_log")->insert($tagdata);
-	        if($in==false){
-	            Db::rollback();
-	            return error_show(1004,"标签日志新建失败");
-	        }
-			$data =$result->getData();
-	        if($data['code']==0){
+	        if($in==false) throw  new \Exception("标签日志新建失败");
+	           
 	            Db::commit();
 	            return app_show(0,"标签添加成功");
-	        }
-	         Db::rollback();
-	        return error_show($data['code'],$data['message']);
         }catch (\Exception $e){
 			Db::rollback();
 	        return error_show(1004,$e->getMessage());
         }
     }
-    
+    //标签废弃
     public function checkTag(){
         $param= $this->request->post(["logid"=>''],"post","trim");
         $loginfo = TagLog::where("id",$param['logid'])->findOrEmpty();
@@ -261,7 +251,42 @@ class TagGood extends Base{
 		          $this->qrdReTag($tag['type'],$loginfo->code,$loginfo->tag_fee);
 	        }
 	        $loginfo->status=0;
-	        $loginfo->save();
+	        $loginfo->id=null;
+	       TagLog::create($loginfo->toArray());
+        }catch (\Exception $exception){
+        	TagLog::rollback();
+        	$this->error($exception->getMessage());
+        }
+        TagLog::commit();
+        $this->success("{$message}数据标签解除");
+    }
+    
+    //解除标签
+    public function returnTag(){
+        $param= $this->request->post(['orderCode'=>'',"type"=>""],'post','trim');
+        $valid =Validate::rule(["orderCode|订单编号"=>"require","type|标签类型"=>"require|number|in:1,2,3,4"]);
+        if($valid->check($param)==false)$this->error($valid->getError());
+        $loginfo = TagLog::withJoin(["tagInfo"])->where(['code'=>$param['orderCode'],"tag_log.status"=>[1,2],
+        'tagInfo.type'=>$param['type']])->order("tag_log.id","desc")->findOrEmpty();
+        if($loginfo->isEmpty())$this->error('未找到标签关联数据');
+        TagLog::startTrans();
+        $message='';
+        try{
+        	 if($loginfo['type']==1 || $loginfo['type']==2){
+        	 	$message="对账单{$loginfo->code}{$loginfo->tag_name}";
+		         $fee= $this->payReTag($loginfo['type'],$loginfo->code);
+	        }
+	        if($loginfo['type']==3|| $loginfo['type']==4){
+	        	$message="销售单{$loginfo->code}{$loginfo->tag_name}";
+		         $fee= $this->qrdReTag($loginfo['type'],$loginfo->code);
+	        }
+	        $loginfo['status']=0;
+	        $loginfo['tag_fee']=$fee;
+	       unset($loginfo['addtime'],$loginfo['updatetime']);
+	        $loginfo->id=null;
+	        $loginfo->apply_id=$this->uid;
+	        $loginfo->apply_name=$this->uname;
+	       TagLog::create($loginfo->toArray());
         }catch (\Exception $exception){
         	TagLog::rollback();
         	$this->error($exception->getMessage());
@@ -279,31 +304,31 @@ class TagGood extends Base{
     private  function payTag($tagId,$code,$total_fee){
 		 $pay=Db::name("pay")->where(["payNo"=>$code,"is_del"=>0])->findOrEmpty();
 		 if(empty($pay)){
-		    return	error_show(1004,"未找到对账单数据");
+		 	throw  new \Exception('未找到对账单数据');
 		 }
 		  $update=["updatetime"=>date("Y-m-d H:i:s")];
 		 if($tagId==1){
 		 	if($pay['wpay_fee']+$pay['pay_tag_fee']<$total_fee){
-		 		return	error_show(1004,"对账单未付金额不足");
+		 		throw  new \Exception('对账单未付金额不足');
 		 	}
 		 	$update['wpay_fee']=$pay['wpay_fee']+$pay['pay_tag_fee']-$total_fee;
 		 	$status = $update['wpay_fee']==0 &&$pay['pay_fee']==0 ? 3:($pay['apay_fee']==0?1:2);
-		 	$update['pay_tag_fee'] = $total_fee;
+		 	$update['pay_tag_fee'] =$pay['pay_tag_fee']+ $total_fee;
 		 	$update['pay_status'] = $status;
 		 	$update['pay_tag'] = 1;
 		 }
 		 if($tagId==2){
 		 	if($pay['winv_fee']+$pay['inv_tag_fee']<$total_fee){
-		 		return	error_show(1004,"对账单未付金额不足");
+		 		throw  new \Exception('对账单未开票金额不足');
 		 	}
 		 	$update['winv_fee']=$pay['winv_fee']+$pay['inv_tag_fee']-$total_fee;
 		 	$status = $update['winv_fee']==0 &&$pay['inv_fee']==0 ? 3:($pay['ainv_fee']==0?1:2);
-		 	$update['inv_tag_fee'] = $total_fee;
+		 	$update['inv_tag_fee'] =$pay['inv_tag_fee']+  $total_fee;
 		 	$update['inv_status'] = $status;
 		 	$update['inv_tag'] = 1;
 		 }
 		 $resulr= Db::name("pay")->where($pay)->update($update);
-		 return $resulr? app_show(0,"标签添加成功"):error_show(1004,"标签添加失败");
+		 if($resulr==false) throw  new \Exception('对账单更新失败');
     }
     
     	/**解除标签
@@ -313,25 +338,29 @@ class TagGood extends Base{
 	* @return \think\response\Json|void
 	* @throws \think\db\exception\DbException
 	*/
-    private  function payReTag($tagId,$code,$total_fee){
+    private  function payReTag($tagId,$code){
 		 $pay=Pay::where(['payNo'=>$code,'is_del'=>0])->findOrEmpty();
 		 if($pay->isEmpty())throw  new \Exception("未找到对账单数据");
+		 $fee=0;
 		 if($tagId==1){
-		 	if($pay['pay_tag_fee']<$total_fee)throw  new \Exception('对账单付款标签金额不足');
-		 	$pay->pay_tag_fee=$pay->pay_tag_fee-$total_fee;
-		 	$pay->wpay_fee=$pay->wpay_fee+$total_fee;
+		 	if($pay['pay_tag_fee']<0)throw  new \Exception('对账单付款标签金额不足');
+		 	$fee=$pay->pay_tag_fee;
+		 	$pay->wpay_fee=$pay->wpay_fee+$pay->pay_tag_fee;
+		 	$pay->pay_tag_fee=0;
 		 	$pay->pay_status = $pay->wpay_fee==0 && $pay->pay_fee==0?3:($pay->apay_fee==0?1:2);
 		 	$pay->pay_tag=0;
 		 }
 		 if($tagId==2){
-		 	if($pay['inv_tag_fee']<$total_fee)throw  new \Exception('对账单回票标签金额不足');
-		 	$pay->inv_tag_fee=$pay->inv_tag_fee-$total_fee;
-		 	$pay->winv_fee=$pay->winv_fee+$total_fee;
+		 	if($pay['inv_tag_fee']<0)throw  new \Exception('对账单回票标签金额不足');
+		 	$fee=$pay->inv_tag_fee;
+		 	$pay->winv_fee=$pay->winv_fee+$pay->inv_tag_fee;
+		 	$pay->inv_tag_fee=0;
 		 	$pay->inv_status = $pay->winv_fee==0 && $pay->inv_fee==0?3:($pay->ainv_fee==0?1:2);
 		 	$pay->inv_tag=0;
 		 }
 		 $resulr= $pay->save();
 		if($resulr==false)throw  new \Exception("对账单更新失败");
+		return $fee;
     }
 	/**
 	* @param $tagId 标签类型 3 回款4开票
@@ -343,31 +372,31 @@ class TagGood extends Base{
     private function qrdTag($tagId,$code,$total_fee){
     	$qrd=Db::name("qrd_info")->where(["sequenceNo"=>$code,"is_del"=>0])->findOrEmpty();
 		 if(empty($qrd)){
-		    return	error_show(1004,"未找到销售单数据");
+		 	throw  new \Exception('未找到销售单数据');
 		 }
 		  $update=["updatetime"=>date("Y-m-d H:i:s")];
 		 if($tagId==3){
 		 	if($qrd['wpay_fee']+$qrd['pay_tag_fee']<$total_fee){
-		 		return	error_show(1004,"对账单未付金额不足");
+		 		throw  new \Exception('销售单未付金额不足');
 		 	}
 		 	$update['wpay_fee']=$qrd['wpay_fee']+$qrd['pay_tag_fee']-$total_fee;
 		 	$status = $update['wpay_fee']==0 &&$qrd['pay_fee']==0 ? 3:($qrd['apay_fee']==0?1:2);
-		 	$update['pay_tag_fee'] = $total_fee;
+		 	$update['pay_tag_fee'] =$qrd['pay_tag_fee']+ $total_fee;
 		 	$update['pay_status'] = $status;
 		 	$update['pay_tag'] = 1;
 		 }
 		 if($tagId==4){
 		 	if($qrd['winv_fee']+$qrd['inv_tag_fee']<$total_fee){
-		 		return	error_show(1004,"对账单未开票金额不足");
+		 		throw  new \Exception('销售单未开票金额不足');
 		 	}
 		 	$update['winv_fee']=$qrd['winv_fee']+$qrd['inv_tag_fee']-$total_fee;
 		 	$status = $update['winv_fee']==0 &&$qrd['inv_fee']==0 ? 3:($qrd['ainv_fee']==0?1:2);
-		 	$update['inv_tag_fee'] = $total_fee;
+		 	$update['inv_tag_fee'] = $qrd['inv_tag_fee']+$total_fee;
 		 	$update['inv_status'] = $status;
 		 	$update['inv_tag'] = 1;
 		 }
 		 $resulr= Db::name("qrd_info")->where($qrd)->update($update);
-		 return $resulr? app_show(0,"标签添加成功"):error_show(1004,"标签添加失败");
+		  if($resulr==false) throw  new \Exception('标签添加失败');
     }
     
     /** 解除标签销售单
@@ -377,24 +406,50 @@ class TagGood extends Base{
 	 * @return \think\response\Json|void
 	* @throws \think\db\exception\DbException
 	 */
-    private function qrdReTag($tagId,$code,$total_fee){
+    private function qrdReTag($tagId,$code){
     	$qrd=QrdInfo::where(['sequenceNo'=>$code,'is_del'=>0])->findOrEmpty();
 		 if($qrd->isEmpty())throw  new \Exception('未找到销售单数据');
+		 $fee =0 ;
 		  if($tagId==3){
-		 	if($qrd->pay_tag_fee<$total_fee)throw  new \Exception('销售单回款标签金额不足');
-		 	$qrd->pay_tag_fee=$qrd->pay_tag_fee-$total_fee;
-		 	$qrd->wpay_fee=$qrd->wpay_fee+$total_fee;
+		 	if($qrd->pay_tag_fee<0)throw  new \Exception('销售单回款标签金额不足');
+		 	 $fee =$qrd->pay_tag_fee ;
+		 	$qrd->wpay_fee=$qrd->wpay_fee+$qrd->pay_tag_fee;
+		 	$qrd->pay_tag_fee=0;
 		 	$qrd->pay_status = $qrd->wpay_fee==0 && $qrd->pay_fee==0?3:($qrd->apay_fee==0?1:2);
 		 	$qrd->pay_tag=0;
 		 }
 		 if($tagId==4){
-		 	if($qrd->pay_tag_fee<$total_fee)throw  new \Exception('销售单开票标签金额不足');
-		 	$qrd->inv_tag_fee=$qrd->inv_tag_fee-$total_fee;
-		 	$qrd->winv_fee=$qrd->winv_fee+$total_fee;
+		 	if($qrd->inv_tag_fee<0)throw  new \Exception('销售单开票标签金额不足');
+		 	$fee =$qrd->inv_tag_fee ;
+		 	$qrd->winv_fee=$qrd->winv_fee+$qrd->inv_tag_fee;
+		 	$qrd->inv_tag_fee=0;
 		 	$qrd->inv_status = $qrd->winv_fee==0 && $qrd->inv_fee==0?3:($qrd->ainv_fee==0?1:2);
 		 	$qrd->inv_tag=0;
 		 }
 		 $resulr= $qrd->save();
 		if($resulr==false)throw  new \Exception('销售单更新失败');
+		return $fee;
+    }
+    
+    
+    public function logList(){
+    	$param = $this->request->param(["betweenTime"=>[],"customerNo"=>"","supplierNo"=>"",'companyNo'=>'',
+    	"type"=>'',"status"=>"","orderCode"=>"","creater"=>"","order_type"=>0,"size"=>10,"page"=>1],"post","trim");
+    	$where=[["tagInfo.type","in",$param['order_type']==2?[1,2]:[3,4]]];
+    	$sbtable = $param['order_type']==2?'payInfo':'orderInfo';
+    	empty($param['betweenTime'])?:$where[]=["tag_log.addtime","between",$param['betweenTime']];
+    	
+    if($param['order_type']==1)$param['customerNo']==""?:$where[]=["{$sbtable}.customerNo","like","%{$param['customerNo']}%"];
+    if($param['order_type']==2)$param['supplierNo']==""?:$where[]=["{$sbtable}.supplierNo","like","%{$param['supplierNo']}%"];
+    	$param['companyNo']==""?:$where[]=["{$sbtable}.companyNo","like","%{$param['companyNo']}%"];
+    	$param['type']==''?:$where[]=["tagInfo.type","=",$param['type']];
+    	$param['status']===""?:$where[]=["tag_log.status","=",$param['status']];
+    	$param['orderCode']==""?:$where[]=["code","like","%{$param['orderCode']}%"];
+    	$param['creater']==""?:$where[]=["creater","like","%{$param['creater']}%"];
+    	$model =new TagLog();
+    	$list = $model->withJoin(["tagInfo",$sbtable],"left")->where($where)
+    	->order("id","desc")
+    	->paginate(["list_rows"=>$param['size'],"page"=>$param['page']]);
+    	$this->success("获取成功",["list"=>$list->items(),"count"=>$list->total()]);
     }
 }

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

@@ -41,11 +41,11 @@ class Track extends Base
     	  $saleName =array_column($sale,'ownerName',"cxCode");
     	  $saleId =array_column($sale,'ownerid',"cxCode");
     	 $data=[];
-    	 foreach ($param as $item){
+    	 foreach ($param as $key=>$item){
     	    if($rule->check($item)==false)$this->error($rule->getError());
     	    if(!isset($outChild[$item['outChildCode']]))$this->error("发货工单{$item['outChildCode']}未找到或未发货");
     	    $temp=[
-    	    	"TrackCode"=>makeNo("TK"),
+    	    	"TrackCode"=>substr(makeNo('TK'), 0, -2) . str_pad(strval($key), 2, '0', STR_PAD_LEFT),
     	    	"orderCode"=>$outChild[$item['outChildCode']],
     	    	"cgdNo"=>$cgdArr[$outChild[$item['outChildCode']]]??"",
     	    	"saler"=>$saleName[$outChild[$item['outChildCode']]]??"",

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

@@ -3,7 +3,8 @@
 
 namespace app\admin\controller;
 
-use app\admin\model\WechatUser;use think\App;
+use app\admin\model\WechatUser;
+use think\App;
 use think\facade\Validate;
 use think\facade\Db;
 class WeChat extends Base {

+ 215 - 74
app/admin/listener/ComonQrd.php

@@ -3,20 +3,100 @@ declare (strict_types = 1);
 
 namespace app\admin\listener;
 
-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;use think\facade\Config;
+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
 {
     /**
      * 事件监听处理
-     *
      * @return mixed
      */
     public function handle($event)
     {
-		if($event['type']=="pay")$this->payComon($event);
-		if($event['type']=="inv")$this->invComon($event);
-		if($event['type']=="rinv")$this->returnInv($event);
-		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 !=='GS2404151642335170')return;
+            	if($bool){
+            		if($invinfo->status!=4 ||$invinfo->is_comon!=1 )return;
+            		$assoc_status=2;
+            	}else{
+            		$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();
+            	if($orderArr->isEmpty())return;
+            	$payArr=array_column($assoc->toArray(),"cancel_fee","orderCode");
+            	$tag=[];
+    	        $qrdSave=[];
+            	foreach ($orderArr as $item){
+            		if(!isset($payArr[$item->sequenceNo]))continue;
+		           $tag_temp=[
+		                'code'=>$item->sequenceNo,
+		                'tag_id'=>11,
+		                'creater'=>'system',
+		                'createrid'=>0,
+		                'tag_fee'=>0,
+		                'tag_img'=>'',
+		                "tag_code"=>$data['invNo'],
+		                'status'=>$bool?1:0
+		                ];
+		            $qrd=[
+		                'id'=>$item->id,
+			            'wpay_fee'=>$item->wpay_fee,
+			            'pay_status'=>$item->pay_status,
+			            'pay_tag_fee'=>$item->pay_tag_fee,
+			            'pay_tag' => 1
+			            ];
+		            if($bool){
+		            	if($item->wpay_fee>$payArr[$item->sequenceNo]){
+		            		$tag_temp['tag_fee']= $payArr[$item->sequenceNo];
+		            		$qrd['pay_tag_fee'] =$item->pay_tag_fee+$payArr[$item->sequenceNo];
+		            		$qrd['wpay_fee'] = $item->wpay_fee-$payArr[$item->sequenceNo];
+		            		$qrd['pay_status'] = ($qrd['wpay_fee']==0 &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?1:2);
+		            	}else{
+		            		$tag_temp['tag_fee'] =$item->wpay_fee;
+		            		$qrd['pay_tag_fee'] =$item->pay_tag_fee+ $item->wpay_fee;
+		            		$qrd['wpay_fee'] = 0;
+		            		$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;
+				            $qrd['wpay_fee'] = $item->wpay_fee+$tag_fee;
+				            $qrd['pay_status'] = ($qrd['wpay_fee']==0  &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?2:1);
+		            }
+		            $qrdSave[]=$qrd;
+		            $tag[]=$tag_temp;
+            	};
+            	(new \app\admin\model\QrdInfo)->saveAll($qrdSave);
+            	(new \app\admin\model\TagLog)->saveAll($tag);
     }
     
     public function payComon($data){
@@ -28,18 +108,25 @@ class ComonQrd
     	$qrdinfo = QrdInfo::where([["sequenceNo","in",$qrdNo],["wpay_fee",">",0]])->select();
     	if($qrdinfo->isEmpty())return;
     	$this->CheckComonOrder($payinfo);
+    	$tagInfo = TagLog::where(["code"=>$qrdNo,"tag_id"=>10,"status"=>1])->column("id,code,tag_id,creater,createrid,tag_fee,tag_img,status","code");
     	$tag=[];
     	$qrdSave=[];
+        $payfee=$data['pay_fee'];
     	foreach ($qrdinfo as $item){
-    		$tag_temp=[
-    			"code"=>$item->sequenceNo,
-    			"tag_id"=>10,
-    			"creater"=>"system",
-    			"createrid"=>0,
-    			"tag_fee"=>0,
-    			"tag_img"=>"",
-    			"status"=>1
+    	    if(isset($tagInfo[$item->sequenceNo])){
+    	        $tag_temp = $tagInfo[$item->sequenceNo];
+    	    }else{
+    	        $tag_temp=[
+    	            "id"=>null,
+                    '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,
@@ -48,29 +135,133 @@ class ComonQrd
 	            "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'];
+    		if($item->wpay_fee>=$payfee){
+    			$tag_temp['tag_fee'] += $payfee;
+    			$qrd['pay_tag_fee'] = $item->pay_tag_fee+$payfee;
+    			$qrd['wpay_fee'] = ($item->wpay_fee>=$payfee)? $item->wpay_fee-$payfee:0;
+    			$qrd['apay_fee'] = $item->apay_fee+$payfee;
     			$qrd['pay_status'] = ($qrd['wpay_fee']==0 &&$item->pay_fee==0) ? 3:($qrd['apay_fee']==0?1:2);
-    			$data['pay_fee']=0;
+    			$payfee=0;
     		}else{
-    			$data['pay_fee']=$data['pay_fee']-$item->wpay_fee;
-    			$qrd['pay_tag_fee'] = $item->wpay_fee;
+    			$payfee=$payfee-$item->wpay_fee;
+    			$tag_temp['tag_fee'] +=$item->wpay_fee;
+    			$qrd['pay_tag_fee'] = $item->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;
+    		if($payfee==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);
+        $tagInfo = TagLog::where(['code'=>$qrdNo,'tag_id'=>10,'status'=>1])->column('id,code,tag_id,creater,createrid,tag_fee,tag_img,status','code');
+
+        $qrdSave =$tagsave =$del= [];
+         $payfee=$data['pay_fee'];
+        foreach ($qrdinfo as $item) {
+            if(!isset($tagInfo[$item->sequenceNo]))continue;
+            $tag_temp = $tagInfo[$item->sequenceNo];
+             $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 >=$payfee) {
+                $tag_temp['tag_fee']-= $payfee;
+                $qrd['pay_tag_fee']  = $item->pay_tag_fee-$payfee;
+                $qrd['pay_tag']  =$qrd['pay_tag_fee']>0?1:0;
+                $qrd['wpay_fee']     = $item->wpay_fee + $payfee;
+                $qrd['apay_fee']     = ($item->apay_fee>=$payfee)? $item->apay_fee-$payfee:0;
+                $qrd['pay_status']   = ($qrd['wpay_fee'] == 0 && $item->pay_fee == 0) ? 3 : ($qrd['apay_fee'] == 0 ? 1 : 2);
+            } else {
+                $tag_temp['tag_fee']-= $item->pay_tag_fee;
+                $qrd['pay_tag_fee']  = 0;
+                $qrd['pay_tag']  = 0;
+                $qrd['wpay_fee']     = $item->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($tag_temp['tag_fee']<=0)$del[]=$tag_temp['id'];
+            else $tagsave[]=$tag_temp;
+        }
+        (new \app\admin\model\QrdInfo)->saveAll($qrdSave);
+        if(!empty($del))(new \app\admin\model\TagLog)->whereIn("id",$del)->delete();
+        if(!empty($tagsave))(new \app\admin\model\TagLog)->saveAll($tagsave);
+
+    }
+    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();
     	if($invinfo->isEmpty())return;
@@ -161,54 +352,4 @@ class ComonQrd
     		    $invpay->status =1;
     		    $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]);
-		        }
-    		}
-    }
-    
-    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();
-    }
 }

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

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

+ 16 - 1
app/admin/model/TagLog.php

@@ -10,6 +10,21 @@ use think\Model;
  */
 class TagLog extends Model
 {
-     protected $createTime='addtime';
+	protected $createTime='addtime';
     protected $updateTime='updatetime';
+    public $status = ["解除","添加","修改"];
+    
+    public function TagInfo(){
+    	return $this->belongsTo(OrderTag::class,"tag_id","id")->bind(["type","tag_name"]);
+    }
+    
+    public function OrderInfo(){
+        return $this->belongsTo(QrdInfo::class,'code','sequenceNo')
+        ->bind(['companyNo','companyName','customerNo','customerName',]);
+    }
+    
+    public function PayInfo(){
+        return $this->belongsTo(Pay::class,'code','payNo')
+        ->bind(['companyNo','companyName','supplierNo','supplierName']);
+    }
 }

+ 7 - 6
app/command/good.php

@@ -25,7 +25,7 @@ class good extends Command
         // 指令输出
 	    $this->date=date("Y-m-d H:i:s",time()-3600);
 	    $goodset =Cache::store("redis")->get("goodSet");
-//	    if($goodset ==1) return;
+	    if($goodset ==1) return;
 	    Cache::store("redis")->set("goodSet",1,1800);
 	    try{
 		    $this->goodBasic();
@@ -43,8 +43,9 @@ class good extends Command
     	
     	foreach ($data as $v){
 			$is=\app\admin\model\Good::where("spuCode",$v['spuCode'])->findOrEmpty();
-			if($is->isEmpty()){
+			if($is->isEmpty() || ($is->isZx==1 && $is->updatetime!=$v['updatetime'])){
 				$array=[
+					"id"=>$is->isEmpty()?null:$is->id,
 					"spuCode"=>$v['spuCode'],
 					"good_name"=>$v['good_name'],
 					"companyNo"=>$v['companyNo'],
@@ -68,8 +69,8 @@ class good extends Command
 					"cgd_supplierName"=>$v['cgd_supplier_name'],
 					"exam_info"=>"",
 					"status"=>0,
-					"addtime"=>date("Y-m-d H:i:s"),
-					"updatetime"=>date("Y-m-d H:i:s")
+					"addtime"=>$v['addtime'],
+					"updatetime"=>$v['updatetime'],
 				];
 				$saleAll[]=$array;
 				echo "【".date("Y-m-d H:i:s")."】 添加商品{$v['spuCode']}进入类目表\r\n";
@@ -91,7 +92,7 @@ class good extends Command
             ->withAttr("good_unit",function ($m){
             	return Db::connect('mysql_wsm')->name('unit')->where("id",$m)->value("unit","");
             })->field("spuCode,good_name,cat_id,good_unit,craft_desc,after_sales,supplierNo,companyNo,supplierName,companyName,good_img,
-            good_info_img,good_thumb_img,creater,createrid,is_stock,0 isZx,is_combind,cgd_supplier_code,cgd_supplier_name,isChild")
+            good_info_img,good_thumb_img,creater,createrid,is_stock,0 isZx,is_combind,cgd_supplier_code,cgd_supplier_name,isChild,addtime,updatetime")
             ->where("updatetime",">=", $this->date)
             ->where("status","=", 1)
             ->select()->toArray();
@@ -108,7 +109,7 @@ class good extends Command
             	return Db::connect('mysql_wsm')->name('unit')->where("id",$v)->value("unit","");
             })
             ->field("spuCode,good_name,craft_desc,'' after_sales,cat_id,good_unit,supplierNo,companyNo,supplierName,companyName,good_img,
-            good_info_img,good_thumb_img,creater,createrid,0 is_stock,1 isZx,is_combind,cgd_supplier_code,cgd_supplier_name,isChild")
+            good_info_img,good_thumb_img,creater,createrid,0 is_stock,1 isZx,is_combind,cgd_supplier_code,cgd_supplier_name,isChild,addtime,updatetime")
             ->where("addtime",">=", $this->date)
             ->select()->toArray();
     	     return $this->addGood($list);

+ 1 - 1
app/common.php

@@ -560,7 +560,7 @@ if(!function_exists('menuAction')){
 			if($value['pid']==0){
 				$list[]=$value;
 			}else{
-				$menu=Db::name("admin_menu")->where(["id"=>$value['pid'],"is_del"=>0,"status"=>1])->field("id,menu_name,menu_img,menu_route,menu_url,pid,level,is_show,is_private,menu_type,status")->findOrEmpty();
+				$menu=Db::name("admin_menu")->where(["id"=>$value['pid'],"is_del"=>0,"status"=>1])->field("id,menu_name,menu_img,menu_route,menu_url,pid,level,is_show,weight,is_private,menu_type,status")->findOrEmpty();
 				if(empty($menu)) continue;
 				if(!isset($temp[$value['pid']]))$temp[$value['pid']]=$menu;
 				$temp[$value['pid']]['child'][]=$value;