ccb.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace bank;
  3. //建设银行
  4. class ccb implements IBank
  5. {
  6. private $mKnown;
  7. private $mName;
  8. private $mNo;
  9. private $mBank;
  10. static $format = [
  11. 0 => '交易时间',
  12. 1 => '借方发生额/元(支取)',
  13. 2 => '贷方发生额/元(收入)',
  14. 3 => '余额',
  15. 4 => '币种',
  16. 5 => '对方户名',
  17. 6 => '对方账号',
  18. 7 => '对方开户机构',
  19. 8 => '记账日期',
  20. 9 => '摘要',
  21. 10 => '备注',
  22. 11 => '账户明细编号-交易流水号',
  23. 12 => '企业流水号',
  24. 13 => '凭证种类',
  25. 14 => '凭证号',
  26. 15 => '交易介质编号'
  27. ];
  28. public function __construct()
  29. {
  30. $this->clear();
  31. }
  32. public function clear() {
  33. $this->mKnown = 0;
  34. $this->mName = '';
  35. $this->mNo = '';
  36. $this->mBank = '';
  37. }
  38. public function match($line) : bool
  39. {
  40. if(count(self::$format) != count($line)) {
  41. return false;
  42. }
  43. if($this->mKnown != 2)
  44. {
  45. if($line[0] == '账  号' && $line[2] == '账户名称') {
  46. $this->mNo = number_format($line[1],0,'.','');
  47. $this->mName = $line[3];
  48. $this->mKnown += 1;
  49. }
  50. elseif ($line[0] == '开户行名称')
  51. {
  52. $this->mBank = $line[1];
  53. if($line[1] == '中国建设银行股份有限公司北京傲城支行') {
  54. $this->mNo = '11050160990000000237';
  55. }
  56. $this->mKnown += 1;
  57. }
  58. }
  59. $diff = array_diff(self::$format,$line);
  60. return empty($diff);
  61. }
  62. public function convert($line) : array
  63. {
  64. $trade_time = strtotime($line[0]);
  65. if($trade_time == false) {
  66. return [];
  67. }
  68. $out = mb_str_replace(',','',$line[1]);
  69. $in = mb_str_replace(',','',$line[2]);
  70. $left = mb_str_replace(',','',$line[3]);
  71. $money_type = $line[4];
  72. $other_name = $line[5];
  73. $other_no = $line[6];
  74. $other_bank = $line[7];
  75. $post_date = $line[8];
  76. $subject = $line[9];
  77. $remark = $line[10];
  78. $trade_no = $line[11];
  79. $proof_type = $line[13];
  80. $proof_no = $line[14];
  81. $result = [
  82. 'trade_time' => $trade_time,
  83. 'out_amount' => $out,
  84. 'in_amount' => $in,
  85. 'left_amount' => $left,
  86. 'money_type' => $money_type,
  87. 'other_name' => $other_name,
  88. 'other_no' => $other_no,
  89. 'other_bank' => $other_bank,
  90. 'post_date' => $post_date,
  91. 'rsubject' => $subject,
  92. 'remark' => $remark,
  93. 'trade_no' => $trade_no,
  94. 'proof_type' => $proof_type,
  95. 'proof_no' => $proof_no,
  96. 'self_name' => $this->mName,
  97. 'self_no' => $this->mNo,
  98. 'self_bank' => $this->mBank,
  99. 'service_charge' => 0.0
  100. ];
  101. return $result;
  102. }
  103. }