wugg 2 lat temu
rodzic
commit
48e8c116f1
2 zmienionych plików z 115 dodań i 9 usunięć
  1. 105 0
      app/admin/controller/OrderPay.php
  2. 10 9
      app/admin/controller/Payment.php

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

@@ -768,4 +768,109 @@ class OrderPay extends BaseController{
             return app_show(1004, $e->getMessage());
         }
     }
+
+    public function importTradeByArr()
+    {
+        $trade =isset($this->post['data']) &&!empty($this->post['data'])?  $this->post['data']:[];
+        if(!is_array($trade) || empty($trade) ) return error_show( 1003,"参数 data 不能为空");
+        $list = [];
+        foreach ( $trade  as $key => $value) {
+
+            if (!isset($value[0]) || $value[0] == '') {
+                //return ['code' => 1003, "msg" => '交易时间不能为空'];
+                return error_show( 1003, '第'.($key+1).'行收款方公司编号不能为空!');
+            }
+            if (!isset($value[4]) || $value[4] == '') {
+               // return ['code' => 1003, "msg" => '交易行名不能为空'];
+                return error_show( 1003, '第'.($key+1).'行收入金额不能为空!');
+            }
+            if (!isset($value[8]) || $value[8] == '') {
+              //  return ['code' => 1003, "msg" => '对方账户不能为空'];
+                return error_show( 1003, '第'.($key+1).'行对方账户不能为空!');
+            }
+            if (!isset($value[9]) || $value[9] == '') {
+              //  return ['code' => 1003, "msg" => '对方户名不能为空'];
+                return error_show( 1003, '第'.($key+1).'行对方户名不能为空!');
+            }
+            if ($key == 0) {
+                if ($value[0] != '收款方公司编号') {
+                  //  return ['code' => 1003, "msg" => '模板第一列为必须为交易时间!'];
+                    return error_show( 1003, '模板第一列为必须为收款方公司编号!');
+                }
+                if ($value[4] != '收入金额') {
+                   // return ['code' => 1003, "msg" => '模板第二列为必须为收入金额!'];
+                    return error_show( 1003, '模板第五列为必须为收入金额!');
+                }
+
+                if ($value[6] != '交易行名') {
+                    //return ['code' => 1003, "msg" => '模板第五列为必须为交易行名!'];
+                    return error_show( 1003, '模板第七列为必须为交易行名!');
+                }
+                if ($value[8] != '对方账号') {
+                   // return ['code' => 1003, "msg" => '模板第七列为必须为对方账号!'];
+                    return error_show( 1003, '模板第九列为必须为对方账号!');
+                }
+                if ($value[9] != '对方户名') {
+                  //  return ['code' => 1003, "msg" => '模板第八列为必须为对方户名!'];
+                    return error_show( 1003, '模板第十列为必须为对方户名!');
+                }
+                continue;
+            }
+            $company =Db::name("company_info")->where(["companyNo"=>$value[0]])->findOrEmpty();
+            if(empty($company)){
+                return error_show( 1003, "业务公司编号不存在{$value[0]}");
+            }
+            $total_fee =  $value[4];
+            $type =  0;
+            $time = explode(" ", $value[3]);
+            $list[$key]["tradeTime"] = date("Y-m-d", strtotime($time[0])) . " " . (isset($time[1]) ? $time[1] : "00:00:00");
+            $list[$key]["trade_fee"] = str_replace(",","",$total_fee);
+            $list[$key]["trade_bank"] = $value[6];
+            $list[$key]["trade_account"] = $value[8];
+            $list[$key]["trade_out"] = $value[9];
+            $list[$key]["trade_in"] = $value[1]??$company['company_name'];
+            $list[$key]["trade_type"] = $type;
+            $list[$key]["trade_used"] = isset($value[10]) ? $value[10] : "";
+            $list[$key]["trade_remark"] = '';
+            $list[$key]["companyNo"] = $value[0];
+            $list[$key]["trade_in_account"] = $value[2]??"";
+        }
+        if(empty($list)){
+            return error_show( 1003, '导入数据不能为空!');
+        }
+       Db::startTrans();
+        try{
+            $tra=[];
+            foreach ($list as $value) {
+                $temp = [];
+                $temp["tradNo"] = makeStr('S');
+                $temp['trade_time'] = $value['tradeTime'];
+                $temp['total_fee'] = $value['trade_fee'];
+                $temp['trade_bank'] = $value['trade_bank'];
+                $temp['trade_account'] = $value['trade_account'];
+                $temp['trade_type'] =$value['trade_type'];
+                $temp['trade_out'] = $value['trade_out'];
+                $temp['trade_in'] = $value['trade_in'];
+                $temp['trade_in_account'] = $value['trade_in_account'];
+                $temp['companyNo'] = $value['companyNo'];
+                $temp['trade_used'] = $value['trade_used'];
+                $temp['trade_remark'] = $value['trade_remark'];
+                $temp['balance'] =$value['trade_fee'];
+                $temp['addtime'] = date("Y-m-d H:i:s");
+                $temp['updatetime'] = date("Y-m-d H:i:s");
+                $tra[]=$temp;
+            }
+            $list = Db::name('trade')->insertAll($tra);
+            if($list==count($tra)){
+                Db::commit();
+                return app_show(0, "资金导入成功");
+            }else{
+                Db::rollback();
+                return app_show(1004, "资金导入失败");
+            }
+        }catch (\Exception $e){
+            Db::rollback();
+            return app_show(1004, $e->getMessage());
+        }
+    }
 }

+ 10 - 9
app/admin/controller/Payment.php

@@ -936,10 +936,10 @@ class Payment extends BaseController
         if($payinfo['status']!=3){
             return error_show(1004,"对账单数据未完成审核");
         }
-        $type = isset($post['invType']) && $post['invType']!="" ? intval($post['invType']):"";
-        if($type==''){
-           return error_show(1004,"参数 invType 不能为空");
-        }
+//        $type = isset($post['invType']) && $post['invType']!="" ? intval($post['invType']):"";
+//        if($type==''){
+//           return error_show(1004,"参数 invType 不能为空");
+//        }
 
         $invArr=isset($post['invArr']) && !empty($post['invArr']) ? $post['invArr'] :'';
         if($invArr==''|| empty($invArr)){
@@ -970,17 +970,18 @@ class Payment extends BaseController
 //        }
 		$daList=[];
 		foreach ($invArr as $item){
-			if($type==1){
+			if(!isset($item['invType'])||$item['invType']=='') return error_show(1004,"参数 invType 不能为空");
+			if($item['invType']==1){
 				if(!isset($item['invNumber'])||$item['invNumber']=='')  return error_show(1004,"参数 invNumber 不能为空");
 				if(!isset($item['invCode'])||$item['invCode']=='')  return error_show(1004,"参数 invCode 不能为空");
 				if(!isset($item['openTime'])||$item['openTime']=='')  return error_show(1004,"参数 invNumber 不能为空");
 				if(!isset($item['subtotal_amount'])||$item['subtotal_amount']=='')  return error_show(1004,"参数 subtotal_amount 不能为空");
 			}
-			if($type==2){
+			if($item['invType']==2){
 				if(!isset($item['inv_img'])||$item['inv_img']=='')  return error_show(1004,"参数 inv_img 不能为空");
 				if(!isset($item['invName'])||$item['invName']=='')  return error_show(1004,"参数 invName 不能为空");
 			}
-			if($type==3){
+			if($item['invType']==3){
 				if(!isset($item['inv_img'])||$item['inv_img']=='')  return error_show(1004,"参数 inv_img 不能为空");
 				if(!isset($item['invName'])||$item['invName']=='')  return error_show(1004,"参数 invName 不能为空");
 			}
@@ -992,13 +993,13 @@ class Payment extends BaseController
                 "apply_name"=>$this->uname,
                 "inv_fee"=> 0,//核算金额
                 "inv_subtotal_amount"=> $item['subtotal_amount']??0, //票面金额
-                "invType"=> $type,
+                "invType"=> $item['invType'],
                 "invoiceType"=>'',
                 "inv_img"=>$item['inv_img']??'',
                 "invName"=>$item['invName']??'',
                 "invoiceNumber"=>$item['invNumber']??'',
                 "invoiceCode"=>$item['invCode']??'',
-                "status"=>$type==2?1:2,
+                "status"=>$item['invType']==2?1:2,
                 "checkNumber"=>$item['checkNumber']??'',
                 "open_time"=>$item['openTime']!=''? date("Y-m-d",strtotime($item['openTime'])):"",
                 "addtime"=>date("Y-m-d H:i:s"),