wugg 2 years ago
parent
commit
f1112b561e

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

@@ -112,7 +112,7 @@ class Menu extends BaseController{
                 return error_show(1003,"菜单不信息不存在");
             }
         }
-        $name = isset($post['name']) ?trim($post['name']) :"";
+        $name = isset($post['menu_name']) ?trim($post['menu_name']) :"";
         if($name==""){
             return error_show(1002,"菜单名称不能为空");
         }

+ 539 - 31
app/admin/controller/OrderInv.php

@@ -3,7 +3,7 @@
 
 namespace app\admin\controller;
 use app\admin\BaseController;
-use think\App;
+use Exception;use think\App;
 use think\facade\Db;
 
 class OrderInv extends BaseController{
@@ -50,37 +50,60 @@ class OrderInv extends BaseController{
         $temp =[];
         $invNo=makeNo("INV");
         $invfee=array_sum(array_column($orderArr,'inv_fee'));
+        Db::startTrans();
+        try{
+               foreach ($orderArr as $value){
+                    if(!isset($value['sequenceNo']) ||$value['sequenceNo']==''){
+                        Db::rollback();
+                           return error_show(1004,"参数 sequenceNo 不能为空");
+                    }
+                    $qrd = Db::name("qrd_info")->where(["sequenceNo"=>$value['sequenceNo']])->find();
+                    if($qrd['status']==2){
+                        Db::rollback();
+                     return error_show(1004,"确认单{$value['sequenceNo']}不参与对账");
+                    }
+                    if(!isset($value['inv_fee']) || $value['inv_fee']===''){
+                        Db::rollback();
+                           return error_show(1004,"参数 inv_fee 不能为空");
+                    }
+                    if($qrd['winv_fee']<$value['inv_fee']){
+                        Db::rollback();
+                     return error_show(1004,"确认单{$value['sequenceNo']}待开票金额不足");
+                    }
+                   $ascc=[
+                       "assocNo"=>makeNo("AS"),
+                       "apply_id"=>$this->uid,
+                       "apply_name"=>$this->uname,
+                       "type"=>1,
+                       "orderCode"=>$value['sequenceNo'],
+                       "viceCode"=>$invNo,
+                       "order_total"=>$qrd['totalPrice'],
+                       "vice_total"=>$invfee,
+                       "cancel_fee"=>$value['inv_fee'],
+                       "status"=>1,
+                        "addtime"=>date("Y-m-d H:i:s"),
+                        "updatetime"=>date("Y-m-d H:i:s")
+                    ];
+                    $update = [
+                        "inv_fee"=>$qrd['inv_fee']+$value['inv_fee'],
+                        "winv_fee"=>$qrd['winv_fee']-$value['inv_fee'],
+                        "inv_status"=>2,
+                        "status"=>1,
+                        "updatetime"=>date("Y-m-d H:i:s")
+                    ];
+                    $up = Db::name("qrd_info")->where($qrd)->update($update);
+                    if($up==false){
+                        Db::rollback();
+                        return error_show(1005,"确认单{$value['sequenceNo']} 更新失败");
+                    }
+                    $temp[]=$ascc;
+                }
+                $associn = Db::name("assoc")->insertAll($temp);
+                if($associn==0){
+                    Db::rollback();
+                     return error_show(1005,"确认单申请开票失败");
+                }
 
-        foreach ($orderArr as $value){
-            if(!isset($value['sequenceNo']) ||$value['sequenceNo']==''){
-                   return error_show(1004,"参数 sequenceNo 不能为空");
-            }
-            $qrd = Db::name("qrd_info")->where(["sequenceNo"=>$value['sequenceNo']])->find();
-            if($qrd['status']==2){
-             return error_show(1004,"确认单{$value['sequenceNo']}不参与对账");
-            }
-            if(!isset($value['inv_fee']) || $value['inv_fee']===''){
-                   return error_show(1004,"参数 inv_fee 不能为空");
-            }
-            if($qrd['winv_fee']<$value['inv_fee']){
-             return error_show(1004,"确认单{$value['sequenceNo']}待开票金额不足");
-            }
-           $ascc=[
-               "assocNo"=>makeNo("AS"),
-               "apply_id"=>$this->uid,
-               "apply_name"=>$this->uname,
-               "type"=>1,
-               "orderCode"=>$value['sequenceNo'],
-               "viceCode"=>$invNo,
-               "order_total"=>$qrd['totalPrice'],
-               "vice_total"=>$invfee,
-               "cancel_fee"=>$value['inv_fee'],
-               "status"=>1,
-                "addtime"=>date("Y-m-d H:i:s"),
-                "updatetime"=>date("Y-m-d H:i:s")
-            ];
-            $temp[]=$ascc;
-        }
           $inv=[
             "invNo"=>$invNo,
             "inv_value"=>$invfee,
@@ -101,6 +124,491 @@ class OrderInv extends BaseController{
             "addtime"=>date("Y-m-d H:i:s"),
             "updatetime"=>date("Y-m-d H:i:s")
         ];
+        $invin = Db::name("invoice_pool")->insert($inv);
+        if($invin){
+            $invinfo=[
+               "buyer_title"=>$buyinfo['invoice_title'],
+               "buyer_code"=>$buyinfo['invoice_code'],
+               "buyer_addr"=>$buyinfo['invoice_addr'],
+               "buyer_mobile"=>$buyinfo['invoice_mobile'],
+               "buyer_bank"=>$buyinfo['invoice_bank'],
+               "buyer_bankNo"=>$buyinfo['invoice_bankNo'],
+               "seller_title"=>$company['company_name'],
+               "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")
+            ];
+            $poolinfo =Db::name("invoice_pool_info")->insert($invinfo);
+            if($poolinfo){
+                 Db::commit();
+                return app_show(0,"确认单发票申请成功",["invNo"=>$invNo]);
+            }
+        }
+         Db::rollback();
+        return error_show(1004,"确认单发票申请失败");
+        }catch (Exception $e){
+            Db::rollback();
+            return error_show(1004,$e->getMessage());
+        }
+   }
+    // 0 待财务开票/待金税开票   1待财务审核 2待填写物流 3开票完成  4开票失败/开票驳回   5财务驳回 6退票
+   public  function  status(){
+        $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=''?trim($this->post['invNo']):"";
+        if($invNo==""){
+            return error_show(1004,"参数 invNo 不能为空");
+        }
+        $invinfo = Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
+        if($invinfo==false){
+            return error_show(1004,"发票申请数据未找到");
+        }
+        $status=  isset($this->post['status'])&&$this->post['status']!==''?intval($this->post['status']):"";
+        if($status===''){
+            return error_show(1004,"参数 status 不能为空");
+        }
+        //open_type 1 金税开票 2 金税线下开票 3 线下开票
+        $open_type = isset($this->post['open_type'])&&$this->post['open_type']!==''?intval($this->post['open_type']):"";
+
+        $remark = isset($this->post['remark'])&&$this->post['remark']!=''?trim($this->post['remark']):"";
+
+//        $invArr=isset($this->post['invArr'])&&!empty($this->post['invArr'])?$this->post['invArr']:[];
+        $invCode =isset($this->post['invCode'])&&$this->post['invCode']!=''?trim($this->post['invCode']):"";
+        $invNum =isset($this->post['invNum'])&&$this->post['invNum']!=''?trim($this->post['invNum']):"";
+        $open_date =isset($this->post['open_date'])&&$this->post['open_date']!=''?trim($this->post['open_date']):"";
+        $total_fee =isset($this->post['total_fee'])&&$this->post['total_fee']!=''?floor($this->post['total_fee']):"";
+        $subtotal_fee =isset($this->post['subtotal_fee'])&&$this->post['subtotal_fee']!=''?floor($this->post['subtotal_fee']):"";
+
+        if($status==1){
+           if($open_type==='')return error_show(1004,"参数 open_type 不能为空");
+           if($open_type!=1){
+               if($invCode==='') return error_show(1004,"参数 invCode 不能为空");
+               if($invNum==='') return error_show(1004,"参数 invNum 不能为空");
+               if($open_date==='') return error_show(1004,"参数 open_date 不能为空");
+               if($total_fee==='') return error_show(1004,"参数 tatal_fee 不能为空");
+               if($subtotal_fee==='') return error_show(1004,"参数 subtotal_fee 不能为空");
+               if($total_fee!=$invinfo['inv_value'])return error_show(1004,"发票金额不足");
+           }
+        }
+        $update=[
+            "status"=>$status,
+            "exam_remark"=>$remark,
+            "updatetime" => date("Y-m-d H:i:s")
+            ];
+        $status==1 ? $update['open_type']=$open_type :"";
+        Db::startTrans();
+        try{
+
+          $invup =Db::name("invoice_pool")->where($invinfo)->update($update);
+        if($invup){
+            if($status==1 && $open_type!=1){
+                $temp=[];
+                  $invpool=[
+                        "invNo"=>$invinfo['invNo'],
+                        "inv_type"=>$open_type,
+                        "inv_code"=>$invCode,
+                        "inv_number"=>$invNum,
+                        "inv_total"=>$total_fee,
+                        "inv_subtotal"=>$subtotal_fee,
+                        "open_date"=>$open_date,
+                        "status"=>1,
+                        "addtime"=>date("Y-m-d H:i:s"),
+                        "updatetime"=>date("Y-m-d H:i:s")
+                     ];
+//                foreach ($invArr as $value){
+//                     $invpool=[
+//                        "invNo"=>$invinfo['invNo'],
+//                        "in_type"=>$open_type,
+//                        "inv_code"=>$value['inv_code'],
+//                        "inv_number"=>$value['inv_number'],
+//                        "inv_total"=>$value['inv_total'],
+//                        "inv_subtotal"=>$value['inv_subtotal'],
+//                        "open_date"=>$value['open_date'],
+//                        "status"=>1,
+//                        "addtime"=>date("Y-m-d H:i:s"),
+//                        "updatetime"=>date("Y-m-d H:i:s")
+//                     ];
+//                     $temp[]=$invpool;
+//                }
+
+               // $in = Db::name("invoice_ticket")->insertAll($temp);
+                $in = Db::name("invoice_ticket")->insert($invpool);
+                if($in==false){
+                    Db::rollback();
+                   return error_show(1004,"发票信息添加失败");
+                }
+            }
+
+            if($status==4 ||$status==5 ){
+               $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"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 =[
+                              "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
+                              "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
+                              "inv_status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ? 1 : 2,
+                              "status"=>$qrdinfo['ainv_fee']==0 &&($qrdinfo['inv_fee']-$value['cancel_fee'])==0 ?0 : 1,
+                              "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"=>3,"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,"确认单关联信息更新失败");
+                          }
+                      }
+                 }
+            }
+            Db::commit();
+            return app_show(0,"审核成功");
+        }
+                Db::rollback();
+              return error_show(1004,"审核失败");
+        }catch (Exception $e){
+              Db::rollback();
+              return error_show(1004,$e->getMessage());
+        }
 
    }
+    /**
+     * 发票设置物流
+     */
+    public function SetPost(){
+     //  @param invNo postCompany postCode postFee;
+        $invNo =isset($this->post['invNo'])&&$this->post['invNo']!="" ? trim($this->post['invNo']):"";
+        if($invNo==''){
+            return error_show(1004,"参数invNo不能为空");
+        }
+        $invinfo =Db::name("invoice_pool")->where(["invNo"=>$invNo,"is_del"=>0])->find();
+        if($invinfo==false){
+            return error_show(1004,"发票申请信息未找到");
+        }
+        $post_company =isset($this->post['post_company'])&&$this->post['post_company']!="" ? trim($this->post['post_company']):"";
+        if($post_company==''){
+            return error_show(1004,"参数 post_company 不能为空");
+        }
+         $post_code =isset($this->post['post_code'])&&$this->post['post_code']!="" ? trim($this->post['post_code']):"";
+        if($post_code==''){
+            return error_show(1004,"参数 post_code 不能为空");
+        }
+        $post_fee =isset($this->post['post_fee'])&&$this->post['post_fee']!="" ? floor($this->post['post_fee']):"0";
+        Db::startTrans();
+        try{
+            $data=[
+                "post_company"=>$post_company,
+                "post_code"=>$post_code,
+                "post_fee"=>$post_fee,
+                "status"=>3,
+                "updatetime"=>date("Y-m-d H:i:s")
+            ];
+            $up =Db::name("invoice_pool")->where($invinfo)->update($data);
+            if($up){
+                 $qrdArr=Db::name("assoc")->where(["viceCode"=>$invNo,"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'],
+                              "inv_tme"=>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,"确认单关联信息更新失败");
+                          }
+                      }
+                 }
+                Db::commit();
+                return app_show(0,"更新成功");
+            }
+             Db::rollback();
+             return error_show(1003,"发票申请信息更新失败");
+        }catch (Exception $e){
+         Db::rollback();
+         return error_show(1004,$e->getMessage());
+        }
+    }
+    /**
+    * 发票废弃使用
+    */
+    public function  Discard(){
+
+    }
+    /**@param invNo return_reason remark  退票申请
+    * @return \think\response\Json|void
+     */
+    public function ReturnAdd(){
+     $invNo = isset($this->post['invNo']) &&  $this->post['invNo']!=''? trim($this->post['invNo']) :'';
+     if($invNo==""){
+         return error_show(1004,"参数 invNo 不能为空");
+     }
+     $return_reason = isset($this->post['return_reason']) &&  $this->post['return_reason']!=''? trim($this->post['return_reason']) :'';
+     $remark = isset($this->post['remark']) &&  $this->post['remark']!=''? trim($this->post['remark']) :'';
+     if($return_reason==""){
+          return error_show(1004,"参数 return_reason 不能为空");
+     }
+     if($remark==""){
+          return error_show(1004,"参数 remark 不能为空");
+     }
+     $returnCode = makeNo("RIN");
+     $data=[
+         "returnCode"=>$returnCode,
+         "invNo"=>$invNo,
+         "return_reason"=>$return_reason,
+         "remark"=>$remark,
+         "status"=>0,
+         "apply_id"=>$this->uid,
+         "apply_name"=>$this->uname,
+         "addtime"=>date("Y-m-d H:i:s"),
+         "updatetime"=>date("Y-m-d H:i:s")
+         ];
+        $inter = Db::name("invoice_return")->insert($data);
+         if($inter){
+             return app_show(0,"退票申请新建成功",["returnCode"=>$returnCode]);
+         }else{
+             return error_show(1005,"退票申请新建失败");
+         }
+    }
+    // 0 待审核 1 待退票 2 退票成功 3 驳回4 退票失败
+    public function ReturnStatus(){
+        $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
+        if($returnCode==""){
+            return error_show(1005,"参数 returnCode 不能为空");
+        }
+        $status = isset($this->post['status'])&&$this->post['status']!="" ? intval($this->post['status']):"";
+        if ($status==""){
+              return error_show(1005,"参数 status 不能为空");
+        }
+        $return_type = isset($this->post['return_type'])&&$this->post['return_type']!="" ? intval($this->post['return_type']):"";
+        if ($return_type==""){
+              return error_show(1005,"参数 return_type 不能为空");
+        }
+        $remark =isset($this->post['remark'])&&$this->post['remark']!="" ? trim($this->post['remark']):"";
+        if($remark==""){
+             return error_show(1005,"参数 remark 不能为空");
+        }
+        $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
+        if($return==false){
+            return error_show(1005,"退票申请信息未找到");
+        }
+        $update=["status"=>$status,"return_type"=>$return_type,"remark"=>$remark,"updatetime"=>date("Y-m-d H:i:s")];
+        $up =Db::name("invoice_return")->where($return)->update($update);
+        if($up){
+            return app_show(0,"退票申请信息更新成功");
+        }else{
+            return error_show(1005,"退票申请信息更新失败");
+        }
+    }
+    public function returnRed(){
+        $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!="" ? trim($this->post['returnCode']):"";
+        if($returnCode==""){
+            return error_show(1005,"参数 returnCode 不能为空");
+        }
+        $redinv =isset($this->post['redinv'])&&$this->post['redinv']!="" ? trim($this->post['redinv']):"";
+        if($redinv==""){
+            return error_show(1005,"参数 redinv 不能为空");
+        }
+         $return= Db::name("invoice_return")->where(["returnCode"=>$returnCode])->find();
+        if($return==false){
+            return error_show(1005,"退票申请信息未找到");
+        }
+         $invinfo = Db::name("invoice_pool")->where(["invNo"=>$return['invNo'],"is_del"=>0])->find();
+         if($invinfo==false){
+            return error_show(1005,"发票申请信息未找到");
+         }
+        Db::startTrans();
+        try{
+
+        $update=["status"=>2,"red_inv"=>$redinv,"updatetime"=>date("Y-m-d H:i:s")];
+        $up =Db::name("invoice_return")->where($return)->update($update);
+        if($up){
+            $invup = ["status"=>6,"updatetime"=>date("Y-m-d H:i:s")];
+            $inv=Db::name("invoice_pool")->where($invinfo)->update($invup);
+            if($inv){
+                 $qrdArr=Db::name("assoc")->where(["viceCode"=>$return['invNo'],"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 =[
+                              "winv_fee"=>$qrdinfo['winv_fee']+$value['cancel_fee'],
+                              "inv_fee"=>$qrdinfo['inv_fee']-$value['cancel_fee'],
+                              "inv_status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 ? 1 : 2,
+                              "status"=>$qrdinfo['ainv_fee']==0 &&$qrdinfo['inv_fee']==0 && $qrdinfo['pay_status'] ?0 : 1,
+                              "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"=>3,"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,"确认单关联信息更新失败");
+                          }
+                      }
+                 }
+              Db::commit();
+              return app_show(0,"退票申请信息更新成功");
+            }
+        }
+            Db::rollback();
+            return error_show(1005,"退票申请信息更新失败");
+        }catch (\Exception $e){
+            Db::rollback();
+            return error_show(1005,$e->getMessage());
+        }
+    }
+    /**
+     *
+     */
+    public function list(){
+        $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
+        $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
+        $condition=[["a.is_del","=",0]];
+        $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :"";
+        $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :"";
+        if($start!=""){
+            $condition[]=["a.addtime",">=",$start." 00:00:00"];
+        }
+
+        if($end!=""){
+            $condition[]=["a.addtime","<=",$end." 23:59:59"];
+        }
+        $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
+        if($status!==""){
+          $condition[]=["a.status","=",$status];
+        }
+        $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
+        if($inv_type!==""){
+           $condition[]=["a.inv_type","=",$inv_type];
+        }
+        $inv_out= isset($this->post['inv_out'])&&$this->post['inv_out']!=="" ? trim($this->post['inv_out']):"";
+        if($inv_out!==""){
+           $condition[]=["a.inv_out","=",$inv_out];
+        }
+          $inv_in = isset($this->post['inv_in'])&&$this->post['inv_in']!=="" ? trim($this->post['inv_in']):"";
+        if($inv_in!==""){
+           $condition[]=["a.inv_in","=",$inv_in];
+        }
+         $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):"";
+        if($invNo!==""){
+           $condition[]=["a.invNo","like","%$invNo%"];
+        }
+
+         $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):"";
+        if($apply_id!==""){
+           $condition[]=["a.apply_id","=",$apply_id];
+        }
+        $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :"";
+        if($apply_name!==""){
+           $condition[]=["a.apply_name","like","%$apply_name%"];
+        }
+        $count=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where
+        ($condition)->count();
+        $total =ceil($count/$size);
+        $page= $page>$total ? intval($total):$page;
+        $list=Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where($condition)
+        ->page($page,$size)->select();
+        return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+
+    public function returnList(){
+         $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
+        $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
+        $condition=[["b.is_del","=",0]];
+        $start = isset($this->post['start'])&&$this->post['start']!="" ? trim($this->post['start']) :"";
+        $end = isset($this->post['end'])&&$this->post['end']!="" ? trim($this->post['end']) :"";
+        if($start!=""){
+            $condition[]=["a.addtime",">=",$start." 00:00:00"];
+        }
+        if($end!=""){
+            $condition[]=["a.addtime","<=",$end." 23:59:59"];
+        }
+         $inv_type = isset($this->post['inv_type'])&&$this->post['inv_type']!=="" ? intval($this->post['inv_type']):"";
+        if($inv_type!==""){
+           $condition[]=["b.inv_type","=",$inv_type];
+        }
+         $apply_id = isset($this->post['apply_id'])&&$this->post['apply_id']!=="" ? intval($this->post['apply_id']):"";
+        if($apply_id!==""){
+           $condition[]=["a.apply_id","=",$apply_id];
+        }
+        $apply_name = isset($this->post['apply_name'])&&$this->post['apply_name']!==""?trim($this->post['apply_name']) :"";
+        if($apply_name!==""){
+           $condition[]=["a.apply_name","like","%$apply_name%"];
+        }
+          $status= isset($this->post['status'])&&$this->post['status']!=="" ? intval($this->post['status']):"";
+        if($status!==""){
+          $condition[]=["a.status","=",$status];
+        }
+         $invNo = isset($this->post['invNo'])&&$this->post['invNo']!=="" ? trim($this->post['invNo']):"";
+        if($invNo!==""){
+           $condition[]=["a.invNo","like","%$invNo%"];
+        }
+         $returnCode = isset($this->post['returnCode'])&&$this->post['returnCode']!=="" ? trim($this->post['returnCode']):"";
+        if($returnCode!==""){
+           $condition[]=["a.returnCode","like","%$returnCode%"];
+        }
+         $count=Db::name("invoice_return")->alias("a")
+         ->leftJoin("invoice_pool b","a.invNo=b.invNo")
+         ->leftJoin("invoice_pool_info c","a.invNo=c.invNo")
+         ->where($condition)->count();
+        $total =ceil($count/$size);
+        $page= $page>$total ? intval($total):$page;
+        $list=Db::name("invoice_return")->alias("a")
+         ->leftJoin("invoice_pool b","a.invNo=b.invNo")
+         ->leftJoin("invoice_pool_info c","a.invNo=c.invNo")
+        ->where($condition)->page($page,$size)->field("c.buyer_title,c.buyer_code,c.buyer_addr,c.buyer_mobile,c.buyer_bank,
+        c.buyer_bankNo,c.seller_title,c.seller_code,c.seller_addr,c.seller_mobile,c.seller_bank,c.seller_bankNo,c.voider,c.payee,
+        c.drawer,c.reviewer,c.ownerPlace,b.inv_value,b.inv_out,b.inv_in,b.inv_type,b.open_type,is_ticket,b.email,
+        b.winv_fee,b.ainv_fee,b.post_fee,b.post_company,b.post_code,a.*")->select();
+        return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
 }

+ 355 - 0
app/admin/controller/OrderPay.php

@@ -0,0 +1,355 @@
+<?php
+
+
+namespace app\admin\controller;
+use app\admin\BaseController;
+use think\App;
+use think\facade\Db;
+
+class OrderPay extends BaseController{
+    public function __construct(App $app) {parent::__construct($app);}
+        //新建资金认领数据
+    public function create(){
+        $tradNo = isset($this->post['tradNo'])&&$this->post['tradNo']!=""?trim($this->post['tradNo']):"";
+        if($tradNo==""){
+            return error_show(1004,"参数 tradNo 不能为空");
+        }
+        $orderArr =  isset($this->post['orderArr'])&&!empty($this->post['orderArr'])?$this->post['orderArr']:[];
+        if(empty($orderArr)){
+            return error_show(1004,"参数 orderArr 不能为空");
+        }
+       Db::startTrans();
+        try{
+            $logNo=makeNo("TRC");
+            $trade =Db::name("trade")->where(["tradNo"=>$tradNo,"is_del"=>0])->lock(true)->findOrEmpty();
+            if(empty($trade)){
+                Db::rollback();
+                return error_show(1004,"未找到资金信息");
+            }
+            $total_fee =array_sum(array_column($orderArr,"trad_fee"));
+            if ($trade['balance']<$total_fee){
+                 Db::rollback();
+                return error_show(1004,"资金余额不足核销");
+            }
+            $assoc=[];
+            foreach ($orderArr as $value){
+                if(!isset($value['sequenceNo'])||$value['sequenceNo']==""){
+                    Db::rollback();
+                   return error_show(1004,"销售单编号不能为空");
+                }
+                if(!isset($value['trad_fee'])||$value['trad_fee']==""){
+                    Db::rollback();
+                   return error_show(1004,"销售单核销金额不能为空");
+                }
+                $qrd =Db::name("qrd_info")->where("sequenceNo","=",$value['sequenceNo'])->field("id,status,pay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
+                if(empty($qrd)){
+                    Db::rollback();
+                   return error_show(1004,"销售单信息未找到");
+                }
+                if($qrd['wpay_fee']<$value['trad_fee']){
+                   Db::rollback();
+                   return error_show(1004,"销售单未付款金额不足核销金额");
+                }
+                $updt=[
+                    "pay_fee"=>$qrd['pay_fee']+$value['trad_fee'],
+                    "wpay_fee"=>$qrd['wpay_fee']-$value['trad_fee'],
+                    "pay_status"=>2,
+                    "status"=>1,
+                    "updatetime"=>date("Y-m-d H:i:s")
+                ];
+                $qrdup = Db::name("qrd_info")->where($qrd)->update($updt);
+                if($qrdup==false){
+                  Db::rollback();
+                   return error_show(1004,"销售单核销金额失败");
+                }
+                $temp=[
+                    "assocNo"=>makeNo("AS"),
+                    "apply_id"=>$this->uid,
+                    "apply_name"=>$this->uname,
+                    "type"=>2,
+                    "orderCode"=>$value['sequenceNo'],
+                    "viceCode"=>$logNo,
+                    "order_total"=>$qrd['totalPrice'],
+                    "vice_total"=>$total_fee,
+                    "cancel_fee"=>$value['trad_fee'],
+                    "status"=>1,
+                    "addtime"=>date("Y-m-d H:i:s"),
+                    "updatetime"=>date("Y-m-d H:i:s")
+                ];
+                $assoc[]=$temp;
+            }
+            $asscin= Db::name("assoc")->insertAll($assoc);
+            if($asscin!=count($assoc)){
+               Db::rollback();
+               return error_show(1004,"销售单核销金额关联失败");
+            }
+            $update=[
+                "balance"=>$trade['balance']-$total_fee,
+                "used_fee"=>$trade['used_fee']+$total_fee,
+                "status"=>($trade['balance']-$total_fee)==0 ? 2:1,
+                "updatetime"=>date("Y-m-d H:i:s"),
+            ];
+            $tradup=Db::name("trade")->where($trade)->update($update);
+            if($tradup){
+                $create = [
+                    "logNo"=>$logNo,
+                    "tradNo"=>$tradNo,
+                    "apply_id"=>$this->uid,
+                    "apply_name"=>$this->uname,
+                    "trade_time"=>$trade['trade_time'],
+                    "total_fee"=>$total_fee,
+                    "status"=>1,
+                    "addtime"=>date("Y-m-d H:i:s"),
+                    "updatetime"=>date("Y-m-d H:i:s")
+                ];
+                $tradchild =Db::name("trade_pool")->insert($create);
+                if($tradchild){
+                    Db::commit();
+                    return app_show(0,"资金认领成功",["logNo"=>$logNo]);
+                }
+            }
+             Db::rollback();
+             return error_show(1004,"资金认领失败");
+        }catch (\Exception $e){
+             Db::rollback();
+             return error_show(1004,$e->getMessage());
+        }
+    }
+    // 1待审批2审批通过3审批驳回
+    public function status(){
+        $logNo = isset($this->post['logNo'])&&$this->post['logNo']!=""?trim($this->post['logNo']):"";
+        if($logNo==""){
+            return error_show(1004,"参数logNo不能为空");
+        }
+        $status=isset($this->post['status'])&&$this->post['status']!=""?intval($this->post['status']):"";
+        if($status==""){
+            return error_show(1004,"参数 status 不能为空");
+        }
+         $remark=isset($this->post['remark'])&&$this->post['remark']!=""?trim($this->post['remark']):"";
+        if($remark==""){
+            return error_show(1004,"参数 remark 不能为空");
+        }
+        Db::startTrans();
+        try {
+            $logingo= Db::name("trade_pool")->where(["logNo"=>$logNo,"is_del"=>0])->find();
+            if($logingo==false){
+                Db::rollback();
+               return error_show(1004,"资金认领信息未找到");
+            }
+            $up=["status"=>$status,"updatetime"=>date("Y-m-d H:i:s"),"remark"=>$remark];
+            $logup = Db::name("trade_pool")->where($logingo)->update($up);
+            if($logup){
+                if($status==2){
+                    $qrdArr=Db::name("assoc")->where(["viceNo"=>$logNo,"status"=>1,"is_del"=>0])->select()->toArray();
+                    if(!empty($qrdArr)){
+                        foreach ($qrdArr as $value){
+                            $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
+                            if(empty($qrd)){
+                                Db::rollback();
+                                return error_show(1005,"未找到销售单数据");
+                            }
+                            if($qrd['pay_fee']<$value['cancel_fee']){
+                                Db::rollback();
+                                return error_show(1005,"销售单待付金额不足");
+                            }
+                            $update =[
+                                "apay_fee"=>$qrd['apay_fee']+$value['cancel_fee'],
+                                "pay_fee"=>$qrd['pay_fee']-$value['cancel_fee'],
+                                "pay_time"=>date("Y-m-d H:i:s"),
+                                "pay_status"=>$qrd['wpay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ? 3:2,
+                                "updatetime"=>date("Y-m-d H:i:s")
+                                ];
+                            $qrdup =Db::name("qrd_info")->where($qrd)->update($update);
+                            if($qrdup==false){
+                                Db::rollback();
+                                return error_show(1005,"销售单更新失败");
+                            }
+                            $asscup =[
+                                "status"=>2,
+                                "assoc_time"=>date("Y-m-d H:i:s"),
+                                "updatetime"=>date("Y-m-d H:i:s")
+                            ];
+                            $assc=Db::name("assoc")->where($value)->update($asscup);
+                            if($assc==false){
+                                Db::rollback();
+                                return error_show(1005,"销售单更新失败");
+                            }
+                        }
+                    }
+                }
+                if($status==3){
+                    $qrdArr=Db::name("assoc")->where(["viceNo"=>$logNo,"status"=>1,"is_del"=>0])->select()->toArray();
+                    if(!empty($qrdArr)){
+                        foreach ($qrdArr as $value){
+                            $qrd =Db::name("qrd_info")->where(["sequenceNo"=>$value['orderCode']])->field("id,status,pay_fee,apay_fee,wpay_fee,pay_status,totalPrice")->findOrEmpty();
+                            if(empty($qrd)){
+                                Db::rollback();
+                                return error_show(1005,"未找到销售单数据");
+                            }
+                            if($qrd['pay_fee']<$value['cancel_fee']){
+                                Db::rollback();
+                                return error_show(1005,"销售单待付金额不足");
+                            }
+                            $update =[
+                                "wpay_fee"=>$qrd['wpay_fee']+$value['cancel_fee'],
+                                "pay_fee"=>$qrd['pay_fee']-$value['cancel_fee'],
+                                "pay_status"=>$qrd['apay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ? 1:2,
+                                "status"=>$qrd['apay_fee']==0 && ($qrd['pay_fee']-$value['cancel_fee'])==0 ?0:1,
+                                "updatetime"=>date("Y-m-d H:i:s")
+                                ];
+                            $qrdup =Db::name("qrd_info")->where($qrd)->update($update);
+                            if($qrdup==false){
+                                Db::rollback();
+                                return error_show(1005,"销售单更新失败");
+                            }
+                            $asscup =[
+                                "status"=>3,
+                                "updatetime"=>date("Y-m-d H:i:s")
+                            ];
+                            $assc=Db::name("assoc")->where($value)->update($asscup);
+                            if($assc==false){
+                                Db::rollback();
+                                return error_show(1005,"销售单更新失败");
+                            }
+                        }
+                    }
+                    $trade =Db::name("trade")->where(["tradNo"=>$logingo['tradNo'],"is_del"=>0])->findOrEmpty();
+                    if($trade==false){
+                       Db::rollback();
+                       return error_show(1005,"资金信息未找到");
+                    }
+                    if($trade['used_fee']<$logingo['total_fee']){
+                        Db::rollback();
+                       return error_show(1005,"资金信息已认领金额不足");
+                    }
+                    $tradup =[
+                        "used_fee"=>$trade['used_fee']-$logingo['total_fee'],
+                        "balance"=>$trade['balance']+$logingo['total_fee'],
+                        "status"=>($trade['used_fee']-$logingo['total_fee'])==0 ? 0 :1,
+                        "updatetime"=>date("Y-m-d H:i:s")
+                    ];
+                    $updaT=Db::name("trade")->where($trade)->update($tradup);
+                    if($updaT==false){
+                        Db::rollback();
+                       return error_show(1005,"资金信息更新失败");
+                    }
+                }
+                Db::commit();
+                return app_show(0,"审核成功");
+            }
+            Db::rollback();
+            return error_show(1004,"审核失败");
+         }catch (\Exception $e){
+            Db::rollback();
+             return error_show(1004,$e->getMessage());
+         }
+    }
+    //资金信息列表
+    public function list(){
+        $condition=[];
+        $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
+        $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
+        $name =isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
+        $bank =isset($this->post['bank'])&&$this->post['bank']!=""? trim($this->post['bank']):"";
+        $start =isset($this->post['start'])&&$this->post['start']!=""? trim($this->post['start']):"";
+        $end =isset($this->post['end'])&&$this->post['end']!=""? trim($this->post['end']):"";
+        $status =isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):"";
+        $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):"";
+         if($tradNo!==""){
+            $condition[]=["a.tradNo","like","%$tradNo%"];
+        }
+        if($bank!=""){
+            $condition[]=["trade_bank","like","%$bank%"];
+        }
+         if($name!=""){
+            $condition[]=["trade_out","like","%$name%"];
+        }
+          if($start!=""){
+            $condition[]=["trade_time",">=",$start." 00:00:00"];
+        }
+           if($end!=""){
+            $condition[]=["trade_time","<=",$end." 23:59:59"];
+        }
+           if($status!==""){
+            $condition[]=["status","=",$status];
+        }
+         $count=Db::name("trade")->where($condition)->count();
+           $total=ceil($count/$size);
+           $page=$page>$total? intval($total):$page;
+           $list =Db::name("trade")->where($condition)->page($page,$size)->order("trade_time desc")->select();
+           return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+
+    public function  tradeList(){
+       $page=isset($this->post['page'])&&$this->post['page']!="" ? intval($this->post['page']) :1;
+        $size=isset($this->post['size'])&&$this->post['size']!="" ? intval($this->post['size']) :15;
+        $condition =[["a.is_del","=",0],["b.is_del","=",0]];
+
+        $name =isset($this->post['name'])&&$this->post['name']!=""? trim($this->post['name']):"";
+        $bank =isset($this->post['bank'])&&$this->post['bank']!=""? trim($this->post['bank']):"";
+        $start =isset($this->post['start'])&&$this->post['start']!=""? trim($this->post['start']):"";
+        $end =isset($this->post['end'])&&$this->post['end']!=""? trim($this->post['end']):"";
+        $status =isset($this->post['status'])&&$this->post['status']!==""? intval($this->post['status']):"";
+        $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=""? intval($this->post['apply_id']):"";
+        $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=""? trim($this->post['apply_name']):"";
+        $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):"";
+         if($tradNo!==""){
+            $condition[]=["a.tradNo","like","%$tradNo%"];
+        }
+         $logNo =isset($this->post['logNo'])&&$this->post['logNo']!=""? trim($this->post['logNo']):"";
+         if($logNo!==""){
+            $condition[]=["a.logNo","like","%$logNo%"];
+        }
+        if($bank!=""){
+            $condition[]=["b.trade_bank","like","%$bank%"];
+        }
+         if($name!=""){
+            $condition[]=["b.trade_out","like","%$name%"];
+        }
+          if($start!=""){
+            $condition[]=["a.add_time",">=",$start." 00:00:00"];
+        }
+           if($end!=""){
+            $condition[]=["a.add_time","<=",$end." 23:59:59"];
+        }
+        if($status!==""){
+            $condition[]=["a.status","=",$status];
+        }
+        if($apply_id!==""){
+            $condition[]=["a.apply_id","=",$apply_id];
+        }
+         if($apply_name!==""){
+            $condition[]=["a.apply_name","like","%$apply_name%"];
+        }
+         $count=Db::name("trade_pool")->alias("a")->leftJoin("trade b","a.tradNo=b.tradNo")->where($condition)->count();
+           $total=ceil($count/$size);
+           $page=$page>$total? intval($total):$page;
+           $list =Db::name("trade_pool")->alias("a")->leftJoin("trade b","a.tradNo=b.tradNo")->where($condition)
+           ->page($page,$size)->field("a.*,b.trade_bank,b.trade_account,b.trade_out,b.total_fee as btotal_fee,b.used_fee,b.balance")->order("a.addtime desc")->select();
+           return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
+    }
+    // 获取资金下面的认领信息
+    public function  tradeQuery(){
+        $tradNo =isset($this->post['tradNo'])&&$this->post['tradNo']!=""? trim($this->post['tradNo']):"";
+        $status =isset($this->post['status'])&&$this->post['status']!=""? intval($this->post['status']):"";
+        $apply_id =isset($this->post['apply_id'])&&$this->post['apply_id']!=""? intval($this->post['apply_id']):"";
+        $apply_name =isset($this->post['apply_name'])&&$this->post['apply_name']!=""? trim($this->post['apply_name']):"";
+        $condition=[["is_del","=",0]];
+          if($apply_id!==""){
+            $condition[]=["apply_id","=",$apply_id];
+        }
+         if($apply_name!==""){
+            $condition[]=["apply_name","like","%$apply_name%"];
+        }
+           if($status!==""){
+            $condition[]=["status","=",$status];
+        }
+         if($tradNo!==""){
+            $condition[]=["tradNo","like","%$tradNo%"];
+        }
+         $list =Db::name("trade_pool")->where($condition)->order("addtime desc")->select();
+          return app_show(0,"获取成功",$list);
+    }
+
+
+}

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

@@ -76,3 +76,19 @@ Route::rule("invstatus","admin/Payment/invStatus");
 Route::rule("invlist","admin/Payment/InvList");
 Route::rule("invdel","admin/Payment/invDel");
 
+Route::rule("orderinvadd","admin/OrderInv/create");
+Route::rule("orderinvstatus","admin/OrderInv/status");
+Route::rule("invsetpost","admin/OrderInv/SetPost");
+Route::rule("invreturnadd","admin/OrderInv/ReturnAdd");
+Route::rule("invreturnstatus","admin/OrderInv/ReturnStatus");
+Route::rule("invreturnred","admin/OrderInv/returnRed");
+Route::rule("orderinvlist","admin/OrderInv/list");
+Route::rule("invreturnlist","admin/OrderInv/returnList");
+
+Route::rule("orderpayadd","admin/OrderPay/create");
+Route::rule("orderpaystatus","admin/OrderPay/status");
+Route::rule("orderpaylist","admin/OrderPay/list");
+Route::rule("tradeList","admin/OrderPay/tradeList");
+Route::rule("tradeQuery","admin/OrderPay/tradeQuery");
+
+