소스 검색

add cmbc-28 column format

stanley-king 3 년 전
부모
커밋
e07d5fd1f1

+ 9 - 0
core/framework/libraries/log.php

@@ -107,6 +107,15 @@ class Log
     }
 
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
+
+    public static function set_level($level) {
+        self::instance()->mCurLevel = $level;
+    }
+
+    public static function enable_sql(bool $enable) {
+        self::instance()->mOpenSql = $enable;
+    }
+
     public static function record($message, $lev = self::ERR)
     {
         self::instance()->doRecord($message, $lev);

+ 4 - 0
helper/bank/bcm.php

@@ -24,6 +24,10 @@ class bcm implements IBank
 
     public function match($line) : bool
     {
+        if(count(self::$format) != count($line)) {
+            return false;
+        }
+
         if($this->mKnown == false)
         {
             if($line[0] == '查询账号:' && $line[2] == '户  名:') {

+ 4 - 0
helper/bank/ccb.php

@@ -44,6 +44,10 @@ class ccb implements IBank
 
     public function match($line) : bool
     {
+        if(count(self::$format) != count($line)) {
+            return false;
+        }
+
         if($this->mKnown != 2)
         {
             if($line[0] == '账  号' && $line[2] == '账户名称') {

+ 4 - 0
helper/bank/ccbb.php

@@ -58,6 +58,10 @@ class ccbb implements IBank
 
     public function match($line) : bool
     {
+        if(count(self::$format) != count($line)) {
+            return false;
+        }
+
         $diff = array_diff(self::$format,$line);
         return empty($diff);
     }

+ 5 - 1
helper/bank/cmbc.php

@@ -26,6 +26,10 @@ class cmbc implements IBank
 
     public function match($line): bool
     {
+        if(count(self::$format) != count($line)) {
+            return false;
+        }
+
         if ($this->mKnown != 2)
         {
             if ($line[0] == '标题' && $line[3] == '账号名称') {
@@ -92,7 +96,7 @@ class cmbc implements IBank
     public function convert($line): array
     {
         $money_type = $line[2];
-        $trade_time = strtotime($line[3] . ' ' . $line[4]);
+        $trade_time = strtotime($line[3] . ' ' . sprintf("%06d",intval($line[4])));
         if($trade_time == false) {
             return [];
         }

+ 135 - 0
helper/bank/cmbc28.php

@@ -0,0 +1,135 @@
+<?php
+
+
+namespace bank;
+
+//招商银行
+class cmbc28 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 => '收(付)方开户行名',
+        16 => '收(付)方开户行地址',
+        17 => '母(子)公司账号分行名',
+        18 => '母(子)公司账号',
+        19 => '母(子)公司名称',
+        20 => '信息标志',
+        21 => '有否附件信息',
+        22 => '冲账标志',
+        23 => '扩展摘要',
+        24 => '交易分析码',
+        25 => '票据号',
+        26 => '商务支付订单号',
+        27 => '内部编号',
+        28 => '公司一卡通号'
+    ];
+
+    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[15];
+
+        $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;
+    }
+}

+ 5 - 1
helper/bank/cmbcex.php

@@ -26,6 +26,10 @@ class cmbcex implements IBank
 
     public function match($line): bool
     {
+        if(count(self::$format) != count($line)) {
+            return false;
+        }
+
         if ($this->mKnown != 2)
         {
             if ($line[0] == '标题' && $line[3] == '账号名称') {
@@ -91,7 +95,7 @@ class cmbcex implements IBank
     public function convert($line): array
     {
         $money_type = $line[2];
-        $trade_time = strtotime($line[3] . ' ' . $line[4]);
+        $trade_time = strtotime($line[3] . ' ' . sprintf("%06d",intval($line[4])));
         if($trade_time == false) {
             return [];
         }

+ 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__ . '/cmbc28.php');
 require_once(__DIR__ . '/hfb.php');
 
 function mb_str_replace($search, $replace, $subject)
@@ -44,7 +45,7 @@ class converter
     public function __construct()
     {
         $this->mState = 0;
-        $this->mConveters = [new ccb(), new ccbb(), new bcm(), new spdb(), new cmbc(), new cmbcex(), new hfb()];
+        $this->mConveters = [new ccb(), new ccbb(), new bcm(), new spdb(), new cmbc(), new cmbcex(), new cmbc28(), new hfb()];
         $this->clear();
     }
 

+ 2 - 2
helper/bank/execl_loader.php

@@ -126,11 +126,11 @@ class execl_loader
             elseif($key === 'line')
             {
                 $line = $convert->convert($val);
-                if(!empty($line)) {
+                if(!empty($line) && !empty($line['trade_no'])) {
                     $inserter($line);
                 }
                 else {
-                    Log::record(json_encode($val),Log::DEBUG);
+                    Log::record(json_encode($val,JSON_UNESCAPED_UNICODE),Log::DEBUG);
                 }
             }
             else {

+ 8 - 4
test/TestSpreadsheet.php

@@ -75,12 +75,16 @@ 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/国研银行'; //'国研交行21-22.xls','国研浦发银行明细账2109-2202.xls','椰子招行2021-04月.xlsx','国研招行21-2202.xlsx'
-        $files = ['国研浦发银行明细账2109-2202.xls'];
+//        $path = BASE_DATA_PATH . '/log/国研银行'; //'国研交行21-22.xls','国研浦发银行明细账2109-2202.xls','椰子招行2021-04月.xlsx','国研招行21-2202.xlsx'
+        Log::set_level(Log::WARING);
+        Log::enable_sql(false);
+
+
+        $path = BASE_DATA_PATH . '/log/椰子银行';
+        $files = ['椰子招行2021-06月.xlsx'];
 
         $loader = new bank\execl_loader();
-        foreach ($files as $file)
-        {
+        foreach ($files as $file) {
             $file = $path . '/' . $file;
             $loader->load_file($file);
         }