wugg 2 years ago
parent
commit
bfc09bf86c
6 changed files with 273 additions and 5 deletions
  1. 25 2
      app/admin/controller/OrderInv.php
  2. 113 0
      app/admin/controller/OrderPay.php
  3. 2 0
      app/admin/route/app.php
  4. 57 1
      app/common.php
  5. 2 1
      composer.json
  6. 74 1
      composer.lock

+ 25 - 2
app/admin/controller/OrderInv.php

@@ -638,10 +638,33 @@ class OrderInv extends BaseController{
         $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();
+        ->page($page,$size)->select()->toArray();
+        foreach ($list as &$item) {
+            $company =Db::name("company_info")->where(["companyNo"=>$item['inv_out']])->find();
+          $kehu =Db::name("customer_info")->where(["companyNo"=>$item['inv_in']])->find();
+          $item['companyName'] = $company['company_name']??"";
+          $item['customerName'] = $kehu['companyName']??"";
+        }
         return app_show(0,"获取成功",["list"=>$list,"count"=>$count]);
     }
-
+    //获取发票详情
+    public function info(){
+      $invNo = isset($this->post['invNo'])&& $this->post['invNo']!='' ? trim($this->post['invNo']):"";
+      if($invNo==''){
+          return error_show(1004,"参数 invNo 不能为空");
+      }
+      $poolinfo =Db::name("invoice_pool")->alias("a")->leftJoin("invoice_pool_info b","a.invNo=b.invNo")->where
+      ([["a.invNo","=",$invNo],["a.is_del","=",0]])->findOrEmpty();
+      if(empty($poolinfo)){
+             return error_show(1004,"为找到开票信息");
+      }
+      $company =Db::name("company_info")->where(["companyNo"=>$poolinfo['inv_out']])->find();
+      $kehu =Db::name("customer_info")->where(["companyNo"=>$poolinfo['inv_in']])->find();
+      $poolinfo['companyName'] = $company['company_name']??"";
+      $poolinfo['customerName'] = $kehu['companyName']??"";
+       return app_show(0,"获取成功",$poolinfo);
+    }
+    //退票列表
     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;

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

@@ -547,4 +547,117 @@ class OrderPay extends BaseController{
           return error_show(1004,$e->getMessage());
         }
     }
+
+     /**
+     * 显示创建资源表单页.
+     *
+     * @return \think\Response
+     */
+    public function importTrade()
+    {
+        $files =  $this->request->file("excel");
+        $data = upload($files,$files->getOriginalExtension());
+        if($data['code']!=0){
+            return error_show(1004,$data['msg']);
+        }
+        $trade = $data['data'];
+        $list = [];
+        foreach ( $trade  as $key => $value) {
+
+            if (!isset($value[0]) || $value[0] == '') {
+                //return ['code' => 1003, "msg" => '交易时间不能为空'];
+                return error_show( 1003, '交易时间不能为空!');
+            }
+            if ((!isset($value[1]) || $value[1] == '') && (!isset($value[2]) || $value[2] == '')) {
+                //return ['code' => 1003, "msg" => '收入/支出金额不能为空'];
+                return error_show( 1003, '收入/支出金额不能为空!');
+            }
+            if (!isset($value[4]) || $value[4] == '') {
+               // return ['code' => 1003, "msg" => '交易行名不能为空'];
+                return error_show( 1003, '交易行名不能为空!');
+            }
+            if (!isset($value[6]) || $value[6] == '') {
+              //  return ['code' => 1003, "msg" => '对方账户不能为空'];
+                return error_show( 1003, '对方账户不能为空!');
+            }
+            if (!isset($value[7]) || $value[7] == '') {
+              //  return ['code' => 1003, "msg" => '对方户名不能为空'];
+                return error_show( 1003, '对方户名不能为空!');
+            }
+            if ($key == 0) {
+                if ($value[0] != '交易时间') {
+                  //  return ['code' => 1003, "msg" => '模板第一列为必须为交易时间!'];
+                    return error_show( 1003, '模板第一列为必须为交易时间!');
+                }
+                if ($value[1] != '收入金额') {
+                   // return ['code' => 1003, "msg" => '模板第二列为必须为收入金额!'];
+                    return error_show( 1003, '模板第二列为必须为收入金额!');
+                }
+                if ($value[2] != '支出金额') {
+                 //   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[7] != '对方户名') {
+                  //  return ['code' => 1003, "msg" => '模板第八列为必须为对方户名!'];
+                    return error_show( 1003, '模板第八列为必须为对方户名!');
+                }
+                continue;
+            }
+            $total_fee = $value[1]==0&&$value[2]!=0 ? $value[2]: $value[1];
+            $type = $value[1]==0&&$value[2]!=0 ? 1: 0;
+            $time = explode(" ", $value[0]);
+            $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[4];
+            $list[$key]["trade_account"] = $value[6];
+            $list[$key]["trade_out"] = $value[7];
+            $list[$key]["trade_in"] = '';
+            $list[$key]["trade_type"] = $type;
+            $list[$key]["trade_used"] = isset($value[8]) ? $value[8] : "";
+            $list[$key]["trade_remark"] = '';
+        }
+        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_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());
+        }
+    }
 }

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

@@ -86,6 +86,7 @@ Route::rule("invdel","admin/Payment/invDel");
 
 Route::rule("orderinvadd","admin/OrderInv/create");
 Route::rule("orderinvstatus","admin/OrderInv/status");
+Route::rule("orderinvinfo","admin/OrderInv/info");
 Route::rule("invsetpost","admin/OrderInv/SetPost");
 Route::rule("invreturnadd","admin/OrderInv/ReturnAdd");
 Route::rule("invreturnstatus","admin/OrderInv/ReturnStatus");
@@ -101,6 +102,7 @@ Route::rule("tradeQuery","admin/OrderPay/tradeQuery");
 Route::rule("orderpayreturn","admin/OrderPay/ReturnPay");
 Route::rule("orderreturnlist","admin/OrderPay/returnList");
 Route::rule("orderreturnstatus","admin/OrderPay/returnStatus");
+Route::rule("importTrade","admin/OrderPay/importTrade");
 
 Route::rule("index","admin/index/index");
 Route::rule("report","admin/Report/index");

+ 57 - 1
app/common.php

@@ -150,6 +150,23 @@ function makeNo($str){
     return $str.$year.$date.$msec;
 }
 
+
+function makeStr($str){
+
+    $date=date("mdHis");
+    $year = date("Y")-2000;
+    $msec=randomkeys(4);
+    return $str.$msec.$year.$date;
+}
+function randomkeys($length) {
+    $returnStr='';
+    $pattern = '1234567890abcdefghijklmnopqrstuvwxyz';//ABCDEFGHIJKLOMNOPQRSTUVWXYZ
+
+    for($i = 0; $i < $length; $i ++) {
+        $returnStr .= $pattern[mt_rand ( 0, strlen($pattern)-1 )]; //生成php随机数
+    }
+    return $returnStr;
+}
 /**
  * @param $token
  * @param $condition
@@ -259,4 +276,43 @@ function MenuTree(&$menuArr,$pid=0){
         }
     }
     return $meun;
-};
+};
+
+
+function upload($files,$extend="xls")
+{
+    // 获取表单上传文件
+    try {
+        validate([
+            'file' => [
+                // 限制文件大小(单位b),这里限制为4M
+                //fileSize' => 4 * 1024 * 1024,
+                'fileExt' => 'xlsx,xls'
+            ]
+        ],
+            [
+                //'file.fileSize' => '文件太大',
+                'file.fileExt' => '不支持的文件',
+            ]
+        )->check(['file' => $files]);
+        if ($extend == 'xlsx') {
+            $objReader = PHPExcel_IOFactory::createReader('Excel2007');
+        } else {
+            $objReader = PHPExcel_IOFactory::createReader('Excel5');
+        }
+
+        $savename = Filesystem::disk('public')->putFile('topic/excel', $files);
+        $import_path = root_path() . 'public/storage/' . $savename;
+
+        $spreadsheet = $objReader->load($import_path);
+        $sheet = $spreadsheet->getActiveSheet();
+        $sheetData = $sheet->toArray();
+        if (empty($sheetData) || !is_array($sheetData)) {
+            return ['code' => 1003, "msg" => '数据不能为空'];
+        }
+        return ['code' => 0, "msg" => '数据解析成功', 'data' => $sheetData];
+    } catch (think\exception\ValidateException $e) {
+        // echo $e->getMessage();
+        return ['code' => 1003, "msg" => $e->getMessage()];
+    }
+}

+ 2 - 1
composer.json

@@ -23,7 +23,8 @@
         "php": ">=7.2.5",
         "topthink/framework": "^6.0.0",
         "topthink/think-orm": "^2.0",
-        "topthink/think-multi-app": "^1.0"
+        "topthink/think-multi-app": "^1.0",
+        "phpoffice/phpexcel": "^1.8"
     },
     "require-dev": {
         "symfony/var-dumper": "^4.2",

+ 74 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "604f2c27afda19f9faea016a74813af0",
+    "content-hash": "3aa191934404180c982ae2eea0633938",
     "packages": [
         {
             "name": "league/flysystem",
@@ -225,6 +225,79 @@
             ],
             "time": "2022-04-17T13:12:02+00:00"
         },
+        {
+            "name": "phpoffice/phpexcel",
+            "version": "1.8.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/PHPOffice/PHPExcel.git",
+                "reference": "1441011fb7ecdd8cc689878f54f8b58a6805f870"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/PHPOffice/PHPExcel/zipball/1441011fb7ecdd8cc689878f54f8b58a6805f870",
+                "reference": "1441011fb7ecdd8cc689878f54f8b58a6805f870",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-mbstring": "*",
+                "ext-xml": "*",
+                "ext-xmlwriter": "*",
+                "php": "^5.2|^7.0"
+            },
+            "require-dev": {
+                "squizlabs/php_codesniffer": "2.*"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-0": {
+                    "PHPExcel": "Classes/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "LGPL-2.1"
+            ],
+            "authors": [
+                {
+                    "name": "Maarten Balliauw",
+                    "homepage": "http://blog.maartenballiauw.be"
+                },
+                {
+                    "name": "Erik Tilt"
+                },
+                {
+                    "name": "Franck Lefevre",
+                    "homepage": "http://rootslabs.net"
+                },
+                {
+                    "name": "Mark Baker",
+                    "homepage": "http://markbakeruk.net"
+                }
+            ],
+            "description": "PHPExcel - OpenXML - Read, Create and Write Spreadsheet documents in PHP - Spreadsheet engine",
+            "homepage": "https://github.com/PHPOffice/PHPExcel",
+            "keywords": [
+                "OpenXML",
+                "excel",
+                "php",
+                "spreadsheet",
+                "xls",
+                "xlsx"
+            ],
+            "support": {
+                "issues": "https://github.com/PHPOffice/PHPExcel/issues",
+                "source": "https://github.com/PHPOffice/PHPExcel/tree/master"
+            },
+            "abandoned": "phpoffice/phpspreadsheet",
+            "time": "2018-11-22T23:07:24+00:00"
+        },
         {
             "name": "psr/cache",
             "version": "1.0.1",