stanley-king 3 anni fa
parent
commit
6bb30ddc89
4 ha cambiato i file con 157 aggiunte e 6 eliminazioni
  1. 122 0
      helper/bank/cmbc16.php
  2. 2 1
      helper/bank/converter.php
  3. 23 1
      helper/bank/execl_loader.php
  4. 10 4
      test/TestSpreadsheet.php

+ 122 - 0
helper/bank/cmbc16.php

@@ -0,0 +1,122 @@
+<?php
+
+
+namespace bank;
+
+//招商银行
+class cmbc16 implements IBank
+{
+    private $mKnown;
+    private $mName;
+    private $mNo;
+    private $mBank;
+
+    public function __construct()
+    {
+        $this->clear();
+    }
+
+    public function clear()
+    {
+        $this->mKnown = 0;
+        $this->mName = '';
+        $this->mNo = '';
+        $this->mBank = '';
+    }
+
+    public function match($line): bool
+    {
+        if(count(self::$format) != count($line)) {
+            return false;
+        }
+
+        if ($this->mKnown != 2)
+        {
+            if ($line[0] == '标题' && $line[3] == '账号名称') {
+                $this->mName = $line[4];
+                $this->mKnown += 1;
+            }
+            elseif ($line[6] == '银行账号')
+            {
+                $this->mNo = $line[7];
+                if($this->mNo == '110946610810701') {
+                    $this->mBank = '招商银行北苑路支行';
+                }
+                elseif ($this->mNo == '110945155010101') {
+                    $this->mBank = '招商银行北苑路支行';
+                }
+
+                $this->mKnown += 1;
+            }
+        }
+
+        $diff = array_diff(self::$format, $line);
+        return empty($diff);
+    }
+
+    static $format = [
+        0 => '账号',
+        1 => '账号名称',
+        2 => '币种',
+        3 => '交易日',
+        4 => '交易时间',
+        5 => '起息日',
+        6 => '交易类型',
+        7 => '借方金额',
+        8 => '贷方金额',
+        9 => '余额',
+        10 => '摘要',
+        11 => '流水号',
+        12 => '收(付)方名称',
+        13 => '收(付)方账号',
+        14 => '收(付)方开户行名',
+        15 => ''
+    ];
+
+    public function convert($line): array
+    {
+        $money_type = $line[2];
+        $trade_time = strtotime($line[3] . ' ' . sprintf("%06d",intval($line[4])));
+        if($trade_time == false) {
+            return [];
+        }
+
+        $out = mb_str_replace(',', '', $line[7]);
+        $in = mb_str_replace(',', '', $line[8]);
+        $left = mb_str_replace(',', '', $line[9]);
+        $subject = $line[10];
+        $trade_no = $line[11];
+
+        $other_name = $line[12];
+        $other_no = $line[13];
+        $other_bank = $line[14];
+
+        $remark = '';
+        $proof_no = '';
+        $post_date = '';
+        $proof_type = '';
+
+        $result = [
+            'trade_time' => $trade_time,
+            'out_amount' => $out,
+            'in_amount' => $in,
+            'left_amount' => $left,
+            'money_type' => $money_type,
+            'other_name' => $other_name,
+            'other_no' => $other_no,
+            'other_bank' => $other_bank,
+            'post_date' => $post_date,
+            'rsubject' => $subject,
+            'remark' => $remark,
+            'trade_no' => $trade_no,
+            'proof_type' => $proof_type,
+            'proof_no' => $proof_no,
+            'self_name' => $this->mName,
+            'self_no' => $this->mNo,
+            'self_bank' => $this->mBank,
+            'service_charge' => 0.0
+        ];
+
+        return $result;
+    }
+}

+ 2 - 1
helper/bank/converter.php

@@ -9,6 +9,7 @@ require_once(__DIR__ . '/ccbb.php');
 require_once(__DIR__ . '/spdb.php');
 require_once(__DIR__ . '/cmbc.php');
 require_once(__DIR__ . '/cmbcex.php');
+require_once(__DIR__ . '/cmbc16.php');
 require_once(__DIR__ . '/cmbc28.php');
 require_once(__DIR__ . '/hfb.php');
 
@@ -45,7 +46,7 @@ class converter
     public function __construct()
     {
         $this->mState = 0;
-        $this->mConveters = [new ccb(), new ccbb(), new bcm(), new spdb(), new cmbc(), new cmbcex(), new cmbc28(), new hfb()];
+        $this->mConveters = [new ccb(), new ccbb(), new bcm(), new spdb(), new cmbc(), new cmbcex(), new cmbc16(), new cmbc28(), new hfb()];
         $this->clear();
     }
 

+ 23 - 1
helper/bank/execl_loader.php

@@ -5,6 +5,8 @@ namespace bank;
 require_once(BASE_ROOT_PATH . '/vendor/autoload.php');
 
 use PhpOffice;
+use PhpOffice\PhpSpreadsheet\Cell\DataType;
+use PhpOffice\PhpSpreadsheet\Cell\AdvancedValueBinder;
 use Log;
 
 function file_generator($path)
@@ -35,6 +37,26 @@ function file_generator($path)
 }
 
 
+class CustomValueBinder extends AdvancedValueBinder
+{
+    public static function dataTypeForValue($value): string
+    { //只重写dataTypeForValue方法,去掉一些不必要的判断
+        if (is_null($value)) {
+            return DataType::TYPE_NULL;
+        } elseif ($value instanceof PhpOffice\PhpSpreadsheet\RichText\RichText) {
+            return DataType::TYPE_INLINE;
+        } elseif (is_string($value) && $value[0] === '=' && strlen($value) > 1) {
+            return DataType::TYPE_FORMULA;
+        } elseif (is_bool($value)) {
+            return DataType::TYPE_BOOL;
+        } elseif (is_float($value) || is_int($value)) {
+            return DataType::TYPE_NUMERIC;
+        }
+        return DataType::TYPE_STRING;
+    }
+}
+
+
 class execl_loader
 {
     public function load_dirs($dirs)
@@ -79,7 +101,7 @@ class execl_loader
                     foreach ($cellIterator as $cell)
                     {
                         if ($cell !== null) {
-                            $item[] = trim($cell->getFormattedValue());
+                            $item[] = trim($cell->getValue());
                         }
                     }
 

+ 10 - 4
test/TestSpreadsheet.php

@@ -68,13 +68,15 @@ class TestSpreadsheet extends TestCase
 //        $file = BASE_DATA_PATH . '/log/椰子银行/2021.11汇付宝付款明细单据数据导出.xls';
 //        $file = BASE_DATA_PATH . '/log/椰子银行/椰子建行2021-05月.xls';
 
-        $path = BASE_DATA_PATH . '/log/国研银行';
+        $path = BASE_DATA_PATH . '/log/椰子招行2104-2111';
         Log::set_level(Log::WARING);
         Log::enable_sql(false);
+        Log::record("start",Log::WARING);
 
 
 //        $path = BASE_DATA_PATH . '/log/椰子银行';
-        $files = ['2021-1-3.xls'];
+//        $files = ['椰子招行2021-09月.xlsx'];'椰子招行2021-09月.xlsx',
+        $files = ['椰子招行2021-11月.xlsx'];
 
         $loader = new bank\execl_loader();
         foreach ($files as $file) {
@@ -88,10 +90,14 @@ class TestSpreadsheet extends TestCase
     {
         Log::set_level(Log::WARING);
         Log::enable_sql(false);
+        Log::record("start",Log::WARING);
 
-        $dir = BASE_DATA_PATH . '/log';
+        $dirs = [BASE_DATA_PATH . '/log/国研银行', BASE_DATA_PATH . '/log/椰子银行'];
         $loader = new bank\execl_loader();
-        $loader->load_dir($dir);
+        foreach ($dirs as $dir) {
+            $loader->load_dir($dir);
+        }
+
     }
 
     public function testFloat()