Beispiel #1
0
 public function parse($content)
 {
     $info = array();
     $s = str_replace(' ', ' ', $content);
     $s = str_replace('</td>', ' # ', $s);
     $s = strip_tags($s);
     $s = preg_replace('/\\s+/', ' ', $s);
     $s = preg_replace('/(#\\s)+/', '# ', $s);
     //        file_put_contents('/home/rong/tmp/guangda.' .time() . '.' . rand(0,100) . '.txt', $s);
     #用户信息 没有区分先生和女士
     $zh = '[\\x{4e00}-\\x{9fa5}]+';
     $p = "/尊敬的\\s*({$zh}?)\\s*(女士|先生)/u";
     $r = $this->pregMatchAll($p, $s, $out);
     $info['name'] = $out[1][0];
     $info['sex'] = $out[2][0];
     $fullCardNo = '\\d+\\*{2,8}\\d+';
     preg_match_all("/{$fullCardNo}/", $s, $match);
     //2015/06/25 added by wanghuafeng 多卡解析,合并多卡卡号
     $card_num_arr = array();
     $unique_cards_arr = array_unique($match[0]);
     foreach ($unique_cards_arr as $val) {
         $card_num_arr[] = substr($val, -4);
     }
     $all_card_no_str = implode(',', $card_num_arr);
     //        print_r($all_card_no_str);
     //        print_r($match);
     //        exit;
     $cards_count = count($card_num_arr);
     #账户基本信息
     #额度基本信息(人民币)
     $p = '/Rewards Points Balance # (\\S+) # (\\S+) # (\\S+) # (\\S+) # (\\S+) # (\\S+)/';
     $r = $this->pregMatchAll($p, $s, $out);
     $info['payment_cur_date'] = ParseUtil::formatDate($out[1][0]);
     $info['payment_due_date'] = ParseUtil::formatDate($out[2][0]);
     $info['credit_limit'] = ParseUtil::formatMoney($out[3][0]);
     #$info['cash_advance_limit'] = $out[2][0];
     $info['new_balance'] = ParseUtil::formatMoney($out[4][0]);
     $info['min_payment'] = ParseUtil::formatMoney($out[5][0]);
     //没有账单周期,自己算,当前账单日设为周期末尾一天
     $info['statement_end_date'] = $info['payment_cur_date'];
     $info['statement_start_date'] = strtotime('last month', $info['payment_cur_date']);
     #获取各张卡的账单汇总
     $p = '/Minimum Payment Due # (.*?)总计 #/';
     $r = $this->pregMatchAll($p, $s, $out);
     $d = $out[1][0];
     //        print_r($out);
     //        exit;
     $cards = array();
     if ($r) {
         $p = '/([\\d\\*]+) # (\\S+) # (\\S+) # (\\S+) # (\\S+)/';
         $r = $this->pregMatchAll($p, $d, $out);
         //            print_r($out);
         //            exit;
         for ($i = 0; $i < count($out[0]); $i++) {
             $card_key = $out[1][$i];
             //                $card['available_balance'] = ParseUtil::formatMoney($out[3][0]);//修改前AvailableCredit字段对应
             $card['new_charges'] = ParseUtil::formatMoney($out[3][0]);
             //竹君文档中对应new_charges
             $card['new_balance'] = ParseUtil::formatMoney($out[4][$i]);
             $card['min_payment'] = ParseUtil::formatMoney($out[5][$i]);
             $cards[$card_key]['balance'] = $card;
         }
         //            print_r($cards);
         //            exit;
     }
     #获取各张卡的交易信息
     $p = '/RMB Account Details(.*)精彩活动/';
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        print_r($cards);
     //        exit;
     if ($r) {
         $trade_txt = $out[1][0];
         //            var_dump($trade_txt);
         //            exit;
         $trades_txt = explode('账号 Account Number:', $trade_txt);
         //            var_dump(count($trade_txt));
         //            exit;
         for ($i = 1; $i < count($trades_txt); $i++) {
             $this->pregMatchAll('/([\\d\\*]+)[^\\d]*上期(欠|存)款/', $trades_txt[$i], $out);
             //                var_dump($out);
             //                exit;
             $card_key = $out[1][0];
             //信用卡卡号00035683****1690593
             $date = '\\d{4}\\/\\d{2}\\/\\d{2}';
             $money = '([0-9,]+\\.\\d{2})';
             $p = "/({$date}) # ({$date}) # (\\d+) # ([^#]*?) # (\\(存入\\))?{$money}/";
             //完整版的账单详情(交易日期,记账日期,卡号末四位,交易明细,金额)
             $r = $this->pregMatchAll($p, $trades_txt[$i], $out_tmp);
             //                $previousBalancePattern = '/Previous Balance:([0-9,]+\.\d{2})/';
             //                $pbMatched = preg_match($previousBalancePattern, $trade_txt, $pbMatch);
             //                if ($pbMatched) {   //last_balance解析
             //                    $pb = $pbMatch[1];
             //                    $cards[$card_key]['balance']['last_balance'] = ParseUtil::formatMoney($pb);
             //                }
             //                var_dump($trades_txt[$i]);
             //                var_dump($out_tmp);
             //                exit;
             for ($j = 0; $j < count($out_tmp[1]); $j++) {
                 $trade['trans_date'] = ParseUtil::formatDate($out_tmp[1][$j], $info['statement_end_date']);
                 $trade['post_date'] = ParseUtil::formatDate($out_tmp[2][$j], $info['statement_end_date']);
                 $trade['card_no'] = $out_tmp[3][$j];
                 $trade['description'] = $out_tmp[4][$j];
                 $trade['currency'] = ParseUtil::getCurrencyType($out_tmp[6][$j]);
                 $trade['rmb_amount'] = ParseUtil::formatMoney($out_tmp[6][$j]);
                 if (!empty($out_tmp[5][$j])) {
                     $trade['rmb_amount'] *= -1;
                 }
                 $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                 //消费分类
                 $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                 //可疑消费分析
                 $trades[] = $trade;
             }
             //                var_dump($trades);
             //                exit;
             $cards[$card_key]['trade'] = $trades;
             $p = "/({$date}) # ({$date}) # ([^#]*?) # (\\(存入\\))?{$money}/";
             //缺少卡号末四位的明细(交易日期,记账日期,交易明细,金额)
             $r = $this->pregMatchAll($p, $trades_txt[$i], $out_tmp);
             //                var_dump($trades_txt[$i]);
             //                var_dump($out_tmp);
             //                exit;
             if ($r) {
                 for ($j = 0; $j < count($out_tmp[1]); $j++) {
                     $trade['trans_date'] = ParseUtil::formatDate($out_tmp[1][$j], $info['statement_end_date']);
                     $trade['post_date'] = ParseUtil::formatDate($out_tmp[2][$j], $info['statement_end_date']);
                     $trade['description'] = $out_tmp[3][$j];
                     if (!empty($out_tmp[4][$j])) {
                         $trade['rmb_amount'] *= -1;
                     }
                     $trade['currency'] = ParseUtil::getCurrencyType($out_tmp[5][$j]);
                     $trade['rmb_amount'] = ParseUtil::formatMoney($out_tmp[5][$j]);
                     $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                     //消费分类
                     $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                     //可疑消费分析
                     $trades[] = $trade;
                 }
                 $cards[$card_key]['trade'] = $trades;
             }
             $p = "/({$date}) # ({$date}) # (\\d+) # ([^#]*?) # /";
             //(只缺少金额)
             $r = $this->pregMatchAll($p, $trades_txt[$i], $out_tmp);
             //                var_dump($trades_txt[$i]);
             //                var_dump($out_tmp);
             //                exit;
             if ($r) {
                 for ($j = 0; $j < count($out_tmp[1]); $j++) {
                     $trade['trans_date'] = ParseUtil::formatDate($out_tmp[1][$j], $info['statement_end_date']);
                     $trade['post_date'] = ParseUtil::formatDate($out_tmp[2][$j], $info['statement_end_date']);
                     $trade['card_no'] = $out_tmp[3][$j];
                     $trade['description'] = $out_tmp[4][$j];
                     $fenqi = preg_match("/本期应还款{$money}/", $trade['description'], $rmbMatch);
                     if ($fenqi) {
                         //                            var_dump($trade['description']);
                         //                            var_dump($rmbMatch);
                         //                            exit;
                         $trade['currency'] = ParseUtil::getCurrencyType($rmbMatch[1]);
                         $trade['rmb_amount'] = ParseUtil::formatMoney($rmbMatch[1]);
                         $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                         //消费分类
                         $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                         //可疑消费分析
                         $trades[] = $trade;
                     } elseif (preg_match("/{$money}/", $trade['description'], $rmbMatch)) {
                         //                            var_dump($trade['description']);
                         //                            var_dump($rmbMatch);
                         //                            exit;
                         $trade['currency'] = ParseUtil::getCurrencyType($rmbMatch[1]);
                         $trade['rmb_amount'] = ParseUtil::formatMoney($rmbMatch[1]);
                         $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                         //消费分类
                         $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                         //可疑消费分析
                         $trades[] = $trade;
                     }
                 }
                 $cards[$card_key]['trade'] = $trades;
             }
             $p = "/({$date}) # ({$date}) # ([^#]*?) # /";
             //(缺少卡号和金额,解析交易说明中的)
             $r = $this->pregMatchAll($p, $trades_txt[$i], $out_tmp);
             //                var_dump($trades_txt[$i]);
             //                var_dump($out_tmp);
             //                exit;
             if ($r) {
                 for ($j = 0; $j < count($out_tmp[1]); $j++) {
                     $trade['trans_date'] = ParseUtil::formatDate($out_tmp[1][$j], $info['statement_end_date']);
                     $trade['post_date'] = ParseUtil::formatDate($out_tmp[2][$j], $info['statement_end_date']);
                     $trade['description'] = $out_tmp[3][$j];
                     $fenqi = preg_match("/本期应还款{$money}/", $trade['description'], $rmbMatch);
                     if ($fenqi) {
                         $trade['currency'] = ParseUtil::getCurrencyType($rmbMatch[1]);
                         $trade['rmb_amount'] = ParseUtil::formatMoney($rmbMatch[1]);
                         $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                         //消费分类
                         $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                         //可疑消费分析
                         $trades[] = $trade;
                     }
                 }
                 $cards[$card_key]['trade'] = $trades;
             }
         }
     }
     #积分明细
     $p = '/调整积分 ?Adjusted.*?# (\\d+) #[^#]*# (\\d+) #[^#]*# (\\d+) #[^#]*# (\\d+) #[^#]*# (\\d+)/';
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['total_points'] = ParseUtil::formatNum($out[1][0]);
         $info['last_points'] = ParseUtil::formatNum($out[2][0]);
         $info['earned_points'] = ParseUtil::formatNum($out[3][0]);
         $info['redeemed_points'] = ParseUtil::formatNum($out[4][0]);
         $info['adjusted_points'] = ParseUtil::formatNum($out[5][0]);
     }
     if (empty($cards)) {
         return $this->insert($info);
     }
     //        print_r($cards);
     //        exit;
     //区分不同的卡
     foreach ($cards as $key => $detail) {
         $oneCardInfo = $info;
         //            $oneCardInfo['card_no'] = substr($key, -4);
         $oneCardInfo['card_no'] = $all_card_no_str;
         $oneCardInfo['trans_detail'] = json_encode($detail['trade']);
         if (is_array($detail['balance'])) {
             $oneCardInfo = array_merge($oneCardInfo, $detail['balance']);
         }
         //            $this->insert($oneCardInfo);
     }
     return true;
 }
Beispiel #2
0
 public function parse($content)
 {
     //        echo $content;
     //        exit;
     $info = array();
     $s = str_replace('&nbsp;', ' ', $content);
     $s = str_replace('#', '', $s);
     $s = str_replace(array('</td>', '</TD>'), ' # ', $s);
     $s = strip_tags($s);
     $s = preg_replace('/\\s+/', ' ', $s);
     // 		$s = preg_replace('/(#\s)+/', '# ', $s);
     // 		file_put_contents('/home/rong/tmp/huaxia.one.' . date('Ymd.His') . '.' . rand(0,100) . '.txt', $s);
     #用户信息
     $zh = '[\\x{4e00}-\\x{9fa5}]+';
     $p = "/尊敬的\\s*({$zh})\\s*(先生|女士)/u";
     $r = $this->pregMatchAll($p, $s, $out);
     if (!$r) {
         $p = "/尊敬的*({$zh})\\s*(先生|女士)/u";
         $r = $this->pregMatchAll($p, $s, $out);
     }
     $info['name'] = $out[1][0];
     $info['sex'] = $out[2][0];
     $date = '\\d{4}\\/\\d{2}\\/\\d{2}';
     $money = '[\\-\\d\\.,]+';
     $this->pregMatchAll('/信用卡对账单[^\\d]*?(\\d.*)份/', $s, $out);
     $month = $out[1][0];
     #账户基本信息
     $p = "/Statement Date: # 每月(\\d{2}日).*Payment Due Date: # ({$date}).*Credit Limit: # ({$money}).*Cash Advance Limit: # ({$money})/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['payment_cur_date'] = ParseUtil::formatDate($month . $out[1][0]);
         $info['payment_due_date'] = ParseUtil::formatDate($out[2][0]);
         $info['credit_limit'] = ParseUtil::formatMoney($out[3][0]);
         $info['cash_advance_limit'] = ParseUtil::formatMoney($out[4][0]);
         $info['statement_end_date'] = $info['payment_cur_date'];
         $info['payment_cur_date'] > 0 && ($info['statement_start_date'] = strtotime('last month', $info['payment_cur_date']));
     }
     $rmbStr = substr($s, 0, strpos($s, "美元账户"));
     #账户还款计算明细(tip:中间有中文空白符)
     $p = "/Amount Payable: ({$money}).*?Minimum Payment: ({$money}).*?Interest # ({$money})[\\s #]+({$money})[\\s #]+({$money})[\\s #]+({$money})[\\s #]+({$money})[\\s #]+({$money})/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         //            print_r($out);
         //            exit;
         $info['new_balance'] = ParseUtil::formatMoney($out[3][0]);
         // Closing Balance
         $info['min_payment'] = ParseUtil::formatMoney($out[2][0]);
         //Minimum Payment:
         $info['last_balance'] = ParseUtil::formatMoney($out[4][0]);
         //Opening Balance
         $info['last_payment'] = ParseUtil::formatMoney($out[5][0]);
         // New Credits
         $info['new_charges'] = ParseUtil::formatMoney($out[6][0]);
         //New Debits
         $info['adjustment'] = ParseUtil::formatMoney($out[7][0]);
         //Adjustment
         $info['interest'] = ParseUtil::formatMoney($out[8][0]);
         //Interest
     }
     print_r($info);
     #积分明细
     $number = '[\\d,]+';
     $p = "/Points Redeemed this month # ({$number})[\\s #]+({$number})[\\s #]+({$number})[\\s #]+({$number})[\\s #]+({$number})[\\s #]+({$number})/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['total_points'] = ParseUtil::formatNum($out[1][0]);
         $info['last_points'] = ParseUtil::formatNum($out[2][0]);
         $info['earned_points'] = ParseUtil::formatNum($out[3][0]);
         $info['rewarded_points'] = ParseUtil::formatNum($out[4][0]);
         $info['adjusted_points'] = ParseUtil::formatNum($out[5][0]);
         $info['redeemed_points'] = ParseUtil::formatNum($out[6][0]);
         $info = ParseUtil::trimArr($info);
     }
     var_export($info);
     //详细交易信息
     $details = array();
     $p = "/({$date})[^#]* # ({$date}) # ([^#]*) # ({$money}) # (\\d{4})/";
     $this->pregMatchAll($p, $s, $out);
     for ($j = 0; $j < count($out[0]); $j++) {
         $one['trans_date'] = ParseUtil::formatDate($out[1][$j], $info['statement_end_date']);
         $one['post_date'] = ParseUtil::formatDate($out[2][$j], $info['statement_end_date']);
         $one['description'] = $out[3][$j];
         $one['rmb_amount'] = ParseUtil::formatMoney($out[4][$j]);
         $one['currency'] = ParseUtil::getCurrencyType($out[4][$j]);
         $one['card_no'] = $out[5][$j];
         $cardNo = $one['card_no'];
         $one['orign_amount'] = $one['rmb_amount'];
         $one['type'] = ParseUtil::getConsumeType($one['description']);
         // 消费分类
         $one['is_doubt'] = ParseUtil::isDoubtComsume($one['description']);
         // 可疑消费分析
         $details[$cardNo][] = ParseUtil::trimArr($one);
     }
     if (empty($details)) {
         return $this->insert($info);
     }
     //区分不同的卡
     foreach ($details as $cardNo => $detail) {
         $oneCardInfo = $info;
         $oneCardInfo['card_no'] = $cardNo;
         $oneCardInfo['trans_detail'] = json_encode($detail);
         $this->insert($oneCardInfo);
     }
     return true;
 }
 public function parse($content)
 {
     $info = array();
     $s = str_replace('&nbsp;', ' ', $content);
     $s = preg_replace('/<\\/td>/', ' # ', $s);
     $s = strip_tags($s);
     $s = preg_replace('/\\s+/', ' ', $s);
     $s = preg_replace('/(#\\s)+/', '# ', $s);
     //        file_put_contents('/home/rong/tmp/gongshang.' .time() . '.' . rand(0,100) . '.txt', $s);
     //用户信息
     $zh = '[\\x{4e00}-\\x{9fa5}]+';
     $p = "/尊敬的\\s*?({$zh})\\s*?(女士|先生)/u";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['name'] = $out[1][0];
         $info['sex'] = $out[2][0];
     }
     $cardPattern = '# (\\d{4}) #';
     preg_match_all("/{$cardPattern}/", $s, $cardMatch);
     $card_num_arr = array();
     $unique_cards_arr = array_unique($cardMatch[1]);
     foreach ($unique_cards_arr as $val) {
         $card_num_arr[] = substr($val, -4);
     }
     $cards_count = count($card_num_arr);
     $all_card_no_str = implode(',', array_unique($card_num_arr));
     var_dump($all_card_no_str);
     var_dump($cards_count);
     exit;
     //用户基本信息
     $p = '/贷记卡到期还款日 # ([^#]+) #.*?账单周期 ([^#]+) # 对账单生成日 ([^#]+) #/';
     $r = $this->pregMatchAll($p, $s, $out);
     $t = explode('—', trim($out[2][0]));
     if ($t) {
         $info['statement_start_date'] = ParseUtil::formatDate($t[0]);
         $info['statement_end_date'] = strtotime('+ 30 days', $info['statement_start_date']);
         $info['payment_cur_date'] = ParseUtil::formatDate($out[3][0]);
         $info['payment_due_date'] = ParseUtil::formatDate($out[1][0]);
     }
     $cards = array();
     $p = '/信用额度 #(.*)?合计 # 人民币/';
     $r = $this->pregMatchAll($p, $s, $out);
     $d = $out[1][0];
     $money = '([\\d\\-\\.\\/,RMB]+)';
     $p = "/(\\d+)[^#]*? # (\\S+) # {$money} # {$money} # {$money}/";
     $r = $this->pregMatchAll($p, $d, $out);
     //        print_r($out);
     //        exit;
     if ($out[1][0]) {
         $info['card_no'] = $all_card_no_str;
     }
     for ($i = 0; $i < count($out[0]); $i++) {
         $cardNo = $out[1][$i];
         $card['new_balance'] = ParseUtil::formatMoney($out[3][$i]);
         $card['min_payment'] = ParseUtil::formatMoney($out[4][$i]);
         $card['credit_limit'] = ParseUtil::formatMoney($out[5][$i]);
         $cards[$cardNo]['balance']['人民币'] = $card;
     }
     //本期交易汇总(人民币)
     $p = '/本期余额 # .*?人民币(.*)?合计/';
     $r = $this->pregMatchAll($p, $s, $out);
     $d = $out[1][0];
     $p = "/(\\d+) # {$money} # {$money} # {$money} # {$money}/";
     $r = $this->pregMatchAll($p, $d, $out);
     /*
     		for ($i = 0; $i < count($out[0]); $i++) {
     			$cardNo = $out[1][$i];
     			$one ['last_balance'] = ParseUtil::formatMoney($out[2][$i]);
     			$one ['last_payment'] = ParseUtil::formatMoney($out[3][$i]);
     			$one ['new_charges'] = ParseUtil::formatMoney($out[4][$i]);
     			if (is_array($cards[$cardNo]['balance']['人民币'])) {
     				$cards[$cardNo]['balance']['人民币'] = array_merge($cards[$cardNo]['balance']['人民币'], $one);
     			} else {
     				$cards[$cardNo]['balance']['人民币'] = $one;
     			}
     		}
     */
     //        print_r($out);
     //        exit;
     if ($r) {
         if ($cards_count > 1) {
             $cardNo = $out[1][$i];
             $last_balance = 0;
             foreach ($out[2] as $val) {
                 $last_balance += ParseUtil::formatMoney($val);
             }
             $one['last_balance'] = $last_balance * -1;
             //last_balance 正负号对调
             $last_payment = 0;
             foreach ($out[3] as $val) {
                 $last_payment += ParseUtil::formatMoney($val);
             }
             $one['last_payment'] = $last_payment;
             $new_charges = 0;
             foreach ($out[4] as $val) {
                 $new_charges += ParseUtil::formatMoney($val);
             }
             $one['new_charges'] = $new_charges;
             if (is_array($cards[$cardNo]['balance']['人民币'])) {
                 $cards[$cardNo]['balance']['人民币'] = array_merge($cards[$cardNo]['balance']['人民币'], $one);
             } else {
                 $cards[$cardNo]['balance']['人民币'] = $one;
             }
             //                print_r($one);
             //                exit;
         } else {
             for ($i = 0; $i < count($out[0]); $i++) {
                 $cardNo = $out[1][$i];
                 $one['last_balance'] = ParseUtil::formatMoney($out[2][$i]) * -1;
                 //last_balance 正负号对调
                 $one['last_payment'] = ParseUtil::formatMoney($out[3][$i]);
                 $one['new_charges'] = ParseUtil::formatMoney($out[4][$i]);
                 if (is_array($cards[$cardNo]['balance']['人民币'])) {
                     $cards[$cardNo]['balance']['人民币'] = array_merge($cards[$cardNo]['balance']['人民币'], $one);
                 } else {
                     $cards[$cardNo]['balance']['人民币'] = $one;
                 }
             }
         }
         //            var_dump($one);
         //            exit;
         #	Yii::log(print_r($out,1).print_r($s,1)."=======gongshang0==");
     }
     //详细交易信息
     $date = '\\d{4}\\-\\d{2}\\-\\d{2}';
     $p = '/交 易 明 细 #(.*)?积 分 信 息 /';
     $r = $this->pregMatchAll($p, $s, $out);
     $d = $out[1][0];
     //        print_r($out);
     //        exit;
     $p = "/(\\d{4}) # ({$date}) # ({$date}) # ([^#]*) # ([^#]*) # {$money} # {$money}\\((存入|支出)\\)/";
     #	$p = "/(\d{4}) # ($date) # ($date) # (\S+) # (\S+) # $money # $money\((存入|支出)\)/";
     $r = $this->pregMatchAll($p, $d, $out);
     for ($i = 0; $i < count($out[0]); $i++) {
         unset($one);
         $cardNo = $out[1][$i];
         $one['card_no'] = $cardNo;
         $one['trans_date'] = intval(strtotime($out[2][$i]));
         $one['post_date'] = intval(strtotime($out[3][$i]));
         $one['description'] = $out[4][$i];
         $one['rmb_amount'] = ParseUtil::formatMoney($out[6][$i]);
         if ($out[8][$i] == '存入') {
             $one['rmb_amount'] *= -1;
         }
         $one['currency'] = ParseUtil::getCurrencyType($out[6][$i]);
         $one['type'] = ParseUtil::getConsumeType($one['description']);
         //消费分类
         $one['is_doubt'] = ParseUtil::isDoubtComsume($one['description']);
         //可疑消费分析
         $cards[$cardNo]['trades'][] = $one;
     }
     //        print_r($cards[$cardNo]['trades']);
     //        exit;
     //细分明细(信用卡积分,分行特色信用卡积分,联名积分1,联名积分2)
     //		$p = '/分行特色信用卡积分 # 新增 ([\d,]+) # 余额 ([\d,]+)/';
     $p = '/积分 # (新增 ([\\d,]+) # )?余额 ([\\d,]+)/';
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['total_points'] = ParseUtil::formatNum($out[3][0]);
         $info['earned_points'] = ParseUtil::formatNum($out[2][0]);
     }
     $info = ParseUtil::trimArr($info);
     if (empty($cards)) {
         return $this->insert($info);
     }
     //区分不同的卡
     $oneCardInfo = $info;
     if ($cards_count > 1) {
         $detailArr = array();
         foreach ($cards as $key => $detail) {
             //$oneCardInfo['card_no'] = $key;
             if (isset($detail['trades'])) {
                 $detailArr = array_merge($detailArr, $detail['trades']);
             }
             if (is_array($detail['balance'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['balance']);
                 unset($oneCardInfo['人民币']);
             }
             if (is_array($detail['balance']['人民币'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['balance']['人民币']);
             }
             if (isset($detail['balance']['美元'])) {
                 $oneCardInfo['credit_limit_usd'] = $detail['balance']['美元']['credit_limit'];
                 $oneCardInfo['new_balance_usd'] = $detail['balance']['美元']['new_balance'];
                 $oneCardInfo['min_payment_usd'] = $detail['balance']['美元']['min_payment'];
             }
             if (is_array(@$detail['points'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['points']);
             }
         }
         $oneCardInfo['trans_detail'] = json_encode($detailArr);
         print_r($oneCardInfo);
         exit;
         //            $this->insert($oneCardInfo);
     } else {
         foreach ($cards as $key => $detail) {
             //$oneCardInfo['card_no'] = $key;
             if (isset($detail['trades'])) {
                 $oneCardInfo['trans_detail'] = json_encode($detail['trades']);
             }
             if (is_array($detail['balance'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['balance']);
                 unset($oneCardInfo['人民币']);
             }
             if (is_array($detail['balance']['人民币'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['balance']['人民币']);
             }
             if (isset($detail['balance']['美元'])) {
                 $oneCardInfo['credit_limit_usd'] = $detail['balance']['美元']['credit_limit'];
                 $oneCardInfo['new_balance_usd'] = $detail['balance']['美元']['new_balance'];
                 $oneCardInfo['min_payment_usd'] = $detail['balance']['美元']['min_payment'];
             }
             if (is_array(@$detail['points'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['points']);
             }
             //            $this->insert($oneCardInfo);
             //            print_r($oneCardInfo);
         }
     }
     //        print_r($oneCardInfo);
     exit;
     return true;
 }
Beispiel #4
0
 public function newBillParse($s, array &$info, array &$details)
 {
     #账户基本信息
     #额度基本信息(人民币)
     //账单日 Statement Date # 20141127 # 信用额度 Credit Limit # 3900.00 CNY #
     $money = '([\\-\\d\\.,]+)';
     $date = '\\d{8}';
     $p = "/账单日.*? ({$date})/";
     //.*?Credit Limit # ($money) #/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['payment_cur_date'] = ParseUtil::formatDate($out[1][0]);
         //没有账单周期,自己算,当前账单日设为周期末尾一天
         $info['statement_end_date'] = $info['payment_cur_date'];
         $info['statement_start_date'] = strtotime('last month', $info['payment_cur_date']);
     }
     $p = "/到期还款日.*? ({$date}) # 还款明细 #/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['payment_due_date'] = ParseUtil::formatDate($out[1][0]);
     }
     $p = "/信用额度 Credit Limit # ({$money}) CNY/";
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($s);
     //        print_r($out);
     //        exit;
     $info['credit_limit'] = ParseUtil::formatMoney($out[1][0]);
     $p = "/人民币\\(CNY\\) # ({$money}) # ({$money}) # ({$date}) # 还款明细 #/";
     $r = $this->pregMatchAll($p, $s, $out);
     #$info['cash_advance_limit'] = $out[5][0];
     $info['new_balance'] = ParseUtil::formatMoney($out[1][0]) * -1;
     $info['min_payment'] = ParseUtil::formatMoney($out[3][0]);
     //		$info['credit_limit_usd'] = ParseUtil::formatMoney($out[4][0]);
     #账户还款计算明细(人民币)
     $p = "/人民币(CNY) # {$money} # {$money} # {$money} # {$money} # {$money} #/";
     $r = $this->pregMatchAll($p, $s, $out);
     $info['last_balance'] = ParseUtil::formatMoney($out[1][0]) * -1;
     $info['last_payment'] = ParseUtil::formatMoney($out[3][0]);
     $info['new_charges'] = ParseUtil::formatMoney($out[2][0]);
     $p = '/\\d{4,8} # \\d{4,8} # \\d{4} # [^#]* # [^#]* # [^#]+ # [^#]+ /';
     $r = $this->pregMatchAll($p, $s, $out);
     for ($i = 0; $i < count($out[0]); $i++) {
         $out[$i + 1] = explode("#", $out[0][$i]);
     }
     for ($i = 1; $i < count($out[0]) + 1; $i++) {
         $one['trans_date'] = intval(strtotime($out[$i][0]));
         $one['post_date'] = intval(strtotime($out[$i][1]));
         $one['card_no'] = trim($out[$i][2]);
         $one['description'] = $out[$i][3];
         $one['rmb_amount'] = ParseUtil::formatMoney($out[$i][6]) * -1;
         $one['currency'] = ParseUtil::getCurrencyType($out[$i][5]);
         #$one['trans_area'] = $out[5][0];
         #$one['orign_amount'] = $out[7][0];
         $one['type'] = ParseUtil::getConsumeType($one['description']);
         //消费分类
         $one['is_doubt'] = ParseUtil::isDoubtComsume($one['description']);
         // 可疑消费分析
         $details[$one['card_no']][] = ParseUtil::trimArr($one);
     }
 }
 public function parse($content)
 {
     $info = array();
     $cards = array();
     $s = str_replace('&nbsp;', ' ', $content);
     $s = preg_replace('/<\\/td>/', ' # ', $s);
     $s = strip_tags($s);
     $s = preg_replace('/\\s+/', ' ', $s);
     $s = preg_replace('/(#\\s)+/', '# ', $s);
     //		file_put_contents('/home/rong/tmp/zhongxin.' .time() . '.txt' , $s);
     #用户信息
     $zh = '[\\x{4e00}-\\x{9fa5}]+';
     $p = "/尊敬的\\s*?({$zh})\\s*?(女士|先生)/u";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['name'] = $out[1][0];
         $info['sex'] = $out[2][0];
     }
     $cardPattern = '卡号后四位.*? (\\d{4}) ';
     preg_match_all("/{$cardPattern}/", $s, $cardMatch);
     $card_num_arr = array();
     $unique_cards_arr = array_unique($cardMatch[1]);
     foreach ($unique_cards_arr as $val) {
         $card_num_arr[] = substr($val, -4);
     }
     $all_card_no_str = implode(',', array_unique($card_num_arr));
     $this->cards_count = count($card_num_arr);
     //        print_r($cards_count);
     //        exit;
     #获取各张卡的交易信息
     #bug-fix by shupan at 2013-12-06 17:36,不影响
     $p = '/本期账务明细】 # (.*?) 【温馨提示/';
     if (false === $this->parseOldBill($s, $cards, $info)) {
         $this->parseNewBill($s, $cards, $info);
         $p = '/本期账务明细[】]? # (.*?) (【分期业务明细|【温馨提示)/';
     }
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        exit;
     if ($r) {
         $trade_txt = $out[1][0];
         $trades_txt = explode('◆卡号:', $trade_txt);
         for ($i = 1; $i < count($trades_txt); $i++) {
             $r = $this->pregMatchAll('/([\\d\\-\\*]+) # 交易日/', $trades_txt[$i], $out);
             if (!$r) {
                 continue;
             }
             $card_key = $out[1][0];
             $money = '([-\\d\\.,]+)';
             $p = "/(\\d+) # (\\d+) # (\\d+) # ([^#]*?) # (\\w+) # {$money} # (\\w+) # {$money}/";
             $r = $this->pregMatchAll($p, $trades_txt[$i], $out_tmp);
             //                print_r($out_tmp);
             //                exit;
             $trade = array();
             for ($j = 0; $j < count($out_tmp[1]); $j++) {
                 $trade['trans_date'] = ParseUtil::formatDate($out_tmp[1][$j], $info['statement_end_date']);
                 $trade['post_date'] = ParseUtil::formatDate($out_tmp[2][$j], $info['statement_end_date']);
                 $trade['card_no'] = $out_tmp[3][$j];
                 $trade['description'] = $out_tmp[4][$j];
                 $trade['currency'] = ParseUtil::getCurrencyType($out_tmp[5][$j]);
                 $trade['rmb_amount'] = ParseUtil::formatMoney($out_tmp[6][$j]);
                 #$trade['type'] = ParseUtil::getConsumeType($trade['description']); //TODO 消费分类
                 $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                 // 可疑消费分析
                 $trades[] = $trade;
             }
             #每次交易的交易明细trades
             $cards[$card_num_arr[0]]['trade'] = $trades;
         }
         //            print_r($cards);
         //            exit;
     }
     #积分明细(信用卡积分,分行特色信用卡积分,联名积分1,联名积分2)
     //		$p = '/积分明细.*?有效期提醒 # (.*)/';
     $p = '/有效期提醒 # (.*)/';
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        exit;
     if ($r) {
         $p = '/(\\d{4,}[\\d\\-\\*]+) # ([\\d,]+) # ([\\d,]+) # ([\\d,]+) # ([\\d,]+) # ([\\d,]+)/';
         $r = $this->pregMatchAll($p, $out[0][0], $jifens_txt);
         //            print_r($jifens_txt);
         //            exit;
         if ($this->cards_count > 1) {
             //多卡
             $card_key = $card_num_arr[0];
             $last_points = 0;
             foreach ($jifens_txt[2] as $val) {
                 $last_points += ParseUtil::formatNum($val);
             }
             $jifen['last_points'] = $last_points;
             $earned_points = 0;
             foreach ($jifens_txt[3] as $val) {
                 $earned_points += ParseUtil::formatNum($val);
             }
             $jifen['earned_points'] = $earned_points;
             $rewarded_points = 0;
             foreach ($jifens_txt[4] as $val) {
                 $rewarded_points += ParseUtil::formatNum($val);
             }
             $jifen['rewarded_points'] = $rewarded_points;
             $redeemed_points = 0;
             foreach ($jifens_txt[5] as $val) {
                 $redeemed_points += ParseUtil::formatNum($val);
             }
             $jifen['redeemed_points'] = $redeemed_points;
             $total_points = 0;
             foreach ($jifens_txt[6] as $val) {
                 $total_points += ParseUtil::formatNum($val);
             }
             $jifen['total_points'] = $total_points;
             $cards[$card_key]['points'] = $jifen;
         } else {
             for ($i = 0; $i < count($jifens_txt[0]); $i++) {
                 $card_key = $jifens_txt[1][$i];
                 $jifen['last_points'] = ParseUtil::formatNum($jifens_txt[2][$i]);
                 $jifen['earned_points'] = ParseUtil::formatNum($jifens_txt[3][$i]);
                 $jifen['rewarded_points'] = ParseUtil::formatNum($jifens_txt[4][$i]);
                 $jifen['redeemed_points'] = ParseUtil::formatNum($jifens_txt[5][$i]);
                 $jifen['total_points'] = ParseUtil::formatNum($jifens_txt[6][$i]);
                 $cards[$card_key]['points'] = $jifen;
             }
         }
     }
     if (empty($cards)) {
         return $this->insert($info);
     }
     //        print_r($cards);
     //区分不同的卡
     if ($this->cards_count > 0) {
         $oneCardInfo = $info;
         $oneCardInfo['trans_detail'] = null;
         //初始化时,设置trans_detail字段为空
         foreach ($cards as $key => $detail) {
             $oneCardInfo['card_no'] = $all_card_no_str;
             if (!empty($detail['trade'])) {
                 $oneCardInfo['trans_detail'] = json_encode($detail['trade']);
             }
             is_array($detail['balance']) && ($oneCardInfo = array_merge($oneCardInfo, $detail['balance']));
             is_array($detail['points']) && ($oneCardInfo = array_merge($oneCardInfo, $detail['points']));
         }
     } else {
         foreach ($cards as $key => $detail) {
             $oneCardInfo = $info;
             $oneCardInfo['card_no'] = $all_card_no_str;
             $oneCardInfo['trans_detail'] = json_encode($detail['trade']);
             is_array($detail['balance']) && ($oneCardInfo = array_merge($oneCardInfo, $detail['balance']));
             is_array($detail['points']) && ($oneCardInfo = array_merge($oneCardInfo, $detail['points']));
             //                print_r($oneCardInfo);
         }
     }
     print_r($oneCardInfo);
     //        exit;
     //        $this->insert($oneCardInfo);
     return true;
 }
 public function oldBillParse($s, array &$info, array &$details)
 {
     #2013年11月账单改版了,邮件中没有详细明细了,放到客户端查询了
     $money = '[¥$\\$\\d\\-\\., ]+';
     $p = "/您 # (\\d{4}) # 年 # \\d{1,2} # 月信用卡个人卡账单已出,.*?最后还款日 # (\\d{1,2}) # 月 # (\\d{1,2}) # 日.*本期应还金额 # ({$money}) # ({$money}) # 最低还款额 # ({$money}) # ({$money})/";
     //这里不用打印日志
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['payment_due_date'] = ParseUtil::formatDate($out[1][0] . $out[2][0] . $out[3][0]);
         $info['payment_cur_date'] = strtotime('20 days ago', $info['payment_due_date']);
         $info['statement_end_date'] = $info['payment_cur_date'];
         $info['statement_start_date'] = strtotime('last month', $info['payment_cur_date']);
         $info['new_balance'] = ParseUtil::formatMoney($out[4][0]);
         $info['new_balance_usd'] = ParseUtil::formatMoney($out[5][0]);
         $info['min_payment'] = ParseUtil::formatMoney($out[6][0]);
         $info['min_payment_usd'] = ParseUtil::formatMoney($out[7][0]);
     }
     #2013年11月之前,2012年7月之后的账单
     //用户基本信息
     $date = '\\d{4}\\/\\d{2}\\/\\d{2}';
     $p = "/Statement Cycle # ({$date})-({$date}).*?Date # ({$date}).*?Limit # ({$money}).*?Balance # ({$money}).*?Limit # ({$money}).*?Payment # ({$money})/";
     // Statement Cycle # 2012/    09/16-2012/10/15 # 到期还款日 # Payment Due Date # 2012/11/03 # # # # # # 信用额度 # Credit Limit # ¥14,000 # 本期还款总额 #
     //New Balance # ¥13,480.55 # # # # # #     预借现金额度 # Cash Advance Limit # ¥7,000 # 本期最低还款额 # Min.Payment # ¥1,348.06
     $r = $this->pregMatchAll($p, $s, $out);
     $statementDate = date('Ymd');
     #默认时间设置
     if ($r) {
         print_r($out);
         exit;
         $info['statement_start_date'] = ParseUtil::formatDate($out[1][0]);
         $info['statement_end_date'] = ParseUtil::formatDate($out[2][0]);
         $statementDate = $info['statement_end_date'];
         $info['payment_cur_date'] = $info['statement_end_date'];
         $info['payment_due_date'] = strtotime(trim($out[3][0]));
         $info['credit_limit'] = ParseUtil::formatMoney($out[4][0]);
         $info['new_balance'] = ParseUtil::formatMoney($out[5][0]);
         $info['cash_advance_limit'] = ParseUtil::formatMoney($out[6][0]);
         $info['min_payment'] = ParseUtil::formatMoney($out[7][0]);
     } else {
         //          招商银行商务卡(个人承债)账单
         $dateHead = '\\d{4}年\\d{2}月\\d{2}日';
         $p = "/Statement Date # ({$dateHead}) # 信用额度 Credit Limit # ({$money}) .*? Payment Due Date # ({$dateHead}) .*? 人民币本期应还金额 Current Balance # ({$money})/";
         $r = $this->pregMatchAll($p, $s, $out);
         if ($r) {
             $info['payment_cur_date'] = ParseUtil::formatDate($out[1][0]);
             $info['payment_due_date'] = ParseUtil::formatDate($out[3][0]);
             $info['statement_end_date'] = $info['payment_cur_date'];
             $statementDate = $info['statement_end_date'];
             $info['credit_limit'] = ParseUtil::formatMoney($out[2][0]);
             $info['new_balance'] = ParseUtil::formatMoney($out[4][0]);
         }
     }
     //用户还款计算明细
     $p = "/循环利息 ?Interest[ #]*({$money}) # ({$money}) # ({$money}) # ({$money}) # ({$money}) # ({$money})/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['last_balance'] = ParseUtil::formatMoney($out[2][0]);
         $info['last_payment'] = ParseUtil::formatMoney($out[3][0]);
         $info['new_charges'] = ParseUtil::formatMoney($out[4][0]);
         $info['adjustment'] = ParseUtil::formatMoney($out[5][0]);
         $info['interest'] = ParseUtil::formatMoney($out[6][0]);
     } else {
         return false;
     }
     //详细交易明细
     $p = '/Trans Amount # (.*) ★ # 上述交易/';
     $r = $this->pregMatchAll($p, $s, $out);
     $d = $out[1][0];
     $date = '\\d{4}\\-\\d{2}\\-\\d{2}';
     $money = '[¥\\$\\d\\-, ]+\\.\\d{2}';
     $p = "/(\\d{4})? # (\\d{4}) # ([^#]*?) # ({$money}) # (\\d{4}) # ([A-Z]*) ?# ({$money})?/";
     $r = $this->pregMatchAll($p, $d, $out);
     $cards = array_unique($out[5]);
     sort($cards);
     $defaultNo = array_pop($cards);
     //        print_r($out);
     //        exit;
     for ($i = 0; $i < count($out[0]); $i++) {
         //转年时会出现问题,但是客户端也不展现年份,暂时这样处理
         $cardNo = trim($out[5][$i]);
         if (empty($cardNo) || $cardNo == '0000') {
             $cardNo = $defaultNo;
         }
         if (empty($out[1][$i])) {
             $out[1][$i] = $out[2][$i];
         }
         //$one ['trans_date'] = ParseUtil::formatDate($out[1][$i], $info['statement_end_date']);
         // $one ['post_date'] = ParseUtil::formatDate($out[2][$i], $info['statement_end_date']);
         if (strlen($out[1][$i]) == 4) {
             $one['trans_date'] = ParseUtil::formatDate($out[1][$i], $statementDate);
         } else {
             $one['trans_date'] = ParseUtil::formatDate($out[1][$i]);
         }
         //            var_dump('trand_date: ' . date('Ymd', $one ['trans_date']) . '------------');
         if (strlen($out[2][$i]) == 4) {
             $one['post_date'] = ParseUtil::formatDate($out[2][$i], $statementDate);
         } else {
             $one['post_date'] = ParseUtil::formatDate($out[2][$i]);
         }
         //            var_dump('post_datte: ' . date('Ymd', $one ['post_date']) . '------------');
         //            exit;
         $one['description'] = $out[3][$i];
         $one['rmb_amount'] = ParseUtil::formatMoney($out[4][$i]);
         $one['currency'] = ParseUtil::getCurrencyType($out[4][$i]);
         $one['card_no'] = $out[5][$i];
         $one['trans_area'] = $out[6][$i];
         $one['orign_amount'] = ParseUtil::formatMoney($out[7][$i]);
         $one['type'] = ParseUtil::getConsumeType($one['description']);
         // 消费分类
         $one['is_doubt'] = ParseUtil::isDoubtComsume($one['description']);
         // 可疑消费分析
         $details[$cardNo][] = ParseUtil::trimArr($one);
     }
     //积分明细
     $p = '/积分总数 [# ]+(\\d+) # (\\d+) # (\\d+) # (\\d+) # (\\d+) # (\\d+) #/';
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['total_points'] = ParseUtil::formatNum($out[1][0]);
         $info['last_points'] = ParseUtil::formatNum($out[2][0]);
         $info['earned_points'] = ParseUtil::formatNum($out[3][0]);
         $info['rewarded_points'] = ParseUtil::formatNum($out[4][0]);
         $info['adjusted_points'] = ParseUtil::formatNum($out[5][0]);
         $info['redeemed_points'] = ParseUtil::formatNum($out[6][0]);
     }
     $info = ParseUtil::trimArr($info);
     return true;
 }
Beispiel #7
0
 public function parse($content)
 {
     $info = array();
     $s = str_replace('&nbsp;', ' ', $content);
     $s = str_replace('</td>', ' # ', $s);
     $s = strip_tags($s);
     $s = preg_replace('/\\s+/', ' ', $s);
     $s = preg_replace('/(#\\s)+/', '# ', $s);
     //        file_put_contents('/home/rong/tmp/jianshe.' .time() . '.' . rand(0,100) . '.txt', $s);
     //        var_dump($s);
     //        exit;
     #用户信息
     $zh = '[\\x{4e00}-\\x{9fa5}]+';
     $p = "/尊敬的({$zh})?,/u";
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        exit;
     $fullCardNo = '\\d{4,}\\*{2,8}\\d{4,}';
     preg_match_all("/{$fullCardNo}/", $s, $match);
     //2015/06/25 added by wanghuafeng 多卡解析,合并多卡卡号
     $card_num_arr = array();
     $unique_cards_arr = array_unique($match[0]);
     foreach ($unique_cards_arr as $val) {
         $card_num_arr[] = substr($val, -4);
     }
     $all_card_no_str = implode(',', array_unique($card_num_arr));
     $cards_count = count($card_num_arr);
     //        print_r($all_card_no_str);
     if ($r) {
         $info['name'] = $out[1][0];
         $info['sex'] = @$out[2][0];
     }
     $lastPaymentPattern = '/金额人民币: ([0-9,]+\\.\\d{2})/';
     $lpMatched = preg_match($lastPaymentPattern, $s, $lastPaymentMatch);
     if ($lpMatched) {
         $info['last_payment'] = ParseUtil::formatMoney($lastPaymentMatch[1]);
     } else {
         $info['last_payment'] = 0;
     }
     //        print_r($info);
     //        exit;
     #账户基本信息
     #$p = '/账单周期.*?(\d\S+).*?Date # ([\d\-\/]+).*?Date # ([\d\-\/]+).*?Limit # [A-Z]*\s*([\d,]+).*?Limit # [A-Z]*\s*([\d,]+).*?Points # ([\d,]+).*?(CNY) # ([\d\.,]+) # ([\d\.,]+)/';
     $circleDate = '\\d{4}年\\d{2}月\\d{2}日';
     $date = '\\d{4}\\-\\d{2}\\-\\d{2}';
     $money = '[CNY\\-\\d\\., ]+';
     $num = '[\\d,]+';
     #$p = "/Statement Date # (\d+) #[^#]*# ($date) #[^#]*# ($money) #[^#]*# ($money) #[^#]*# RMB:($money)[^#]*#[^#]*# RMB:($money)/";
     $p = "/({$circleDate})\\-({$circleDate}) #[^#]*#[^#]*# ({$date}) #[^#]*# ({$date}|已逾期) #[^#]*# ({$money}) #[^#]*# ({$money}) #[^#]*# ({$num})/";
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        exit;
     if ($r) {
         $info['statement_start_date'] = ParseUtil::formatDate(trim($out[1][0]));
         $info['statement_end_date'] = ParseUtil::formatDate(trim($out[2][0]));
         $info['payment_cur_date'] = strtotime(trim($out[3][0]));
         $info['payment_due_date'] = strtotime(trim($out[4][0]));
         $info['credit_limit'] = ParseUtil::formatMoney($out[5][0]);
         $info['cash_advance_limit'] = ParseUtil::formatMoney($out[6][0]);
         #积分余额
         $info['total_points'] = ParseUtil::formatNum($out[7][0]);
     }
     $p = "/Dispute Amt\\/Nbr #[^#]*# ({$money}) # ({$money})/";
     //        print_r($s);
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        exit;
     if ($r) {
         $info['new_balance'] = ParseUtil::formatMoney($out[1][0]);
         $info['min_payment'] = ParseUtil::formatMoney($out[2][0]);
         if (preg_match_all("/美元(USD) # ({$money}) # ({$money}) #/", $s, $match)) {
             $info['new_balance_usd'] = ParseUtil::formatMoney($match[1][0]);
             $info['min_payment_usd'] = ParseUtil::formatMoney($match[2][0]);
         }
     }
     #账户还款计算明细
     $p = "/上期账单余额\\(Previous Balance\\) # ({$money}) # (.*?)\\*\\*\\* 结束/";
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        exit;
     $info['last_balance'] = ParseUtil::formatMoney($out[1][0]);
     $d = $out[2][0];
     #详细交易信息
     $date = '\\d{4}\\-\\d{2}\\-\\d{2}';
     $p = "/({$date}) # ({$date}) # (\\d{4}) # ([^#].*?) # ([A-Z]*) # ([-\\d\\.,]+) #/";
     $details = array();
     $r = $this->pregMatchAll($p, $d, $out);
     if ($r) {
         for ($i = 0; $i < count($out[0]); $i++) {
             $one['trans_date'] = intval(strtotime($out[1][$i]));
             $one['post_date'] = intval(strtotime($out[2][$i]));
             $one['card_no'] = $out[3][0];
             $one['description'] = $out[4][$i];
             # $one['currency'] = ParseUtil::getCurrencyType($out [5] [$i]);
             $one['rmb_amount'] = ParseUtil::formatMoney($out[6][$i]);
             #$one['trans_area'] = $out[6][0];
             #$one['orign_amount'] = format_money($out[7][0]);
             $one['type'] = ParseUtil::getConsumeType($one['description']);
             //TODO 消费分类
             $one['is_doubt'] = ParseUtil::isDoubtComsume($one['description']);
             // 可疑消费分析
             $details[$one['card_no']][] = ParseUtil::trimArr($one);
         }
     }
     #积分明细
     $p = '/Total Points #[^#]*(\\d{4}) # ([\\d\\.,]+) # ([\\d\\.,]+) # ([\\d\\.,]+) # ([\\d\\.,]+) # ([\\d\\.,]+) # ([\\d\\.,]+) #/';
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['total_points'] = ParseUtil::formatNum($out[7][0]);
         $info['last_points'] = ParseUtil::formatNum($out[2][0]);
         $info['earned_points'] = ParseUtil::formatNum($out[3][0]);
         $info['rewarded_points'] = ParseUtil::formatNum($out[4][0]);
         $info['adjusted_points'] = ParseUtil::formatNum($out[5][0]);
         $info['redeemed_points'] = ParseUtil::formatNum($out[6][0]);
         $info = ParseUtil::trimArr($info);
     }
     if (empty($details)) {
         return $this->insert($info);
     }
     //区分不同的卡
     foreach ($details as $cardNo => $detail) {
         $oneCardInfo = $info;
         $oneCardInfo['card_no'] = $all_card_no_str;
         $oneCardInfo['trans_detail'] = json_encode($detail);
         //            $this->insert($oneCardInfo);
     }
     print_r($oneCardInfo);
     return true;
 }
 /**
  * 解析2013年5月份之后的账单
  * @param array $card
  * @param array $info
  */
 public function parseNewBill($s, array &$cards, array &$info)
 {
     $money = '[\\-\\d\\.,]+';
     $date = '\\d{2}\\/\\d{2}';
     //		$p = "/RMB\/USD Account[ #]+RMB ($money) # RMB ($money) # (\d+).* New Balance[ #]+$money [^\d]+ ($money) [^\d]+ ($money) [^\d]+ ($money) [^\d]+ ($money) [^\d]+ ($money) [^\d]+/";
     $p = "/本期最低还款额 Min\\.Payment.*?({$money}).*?本期应还款金额.*?({$money}).*?上期账单金额.*?({$money}).*?本期已还金额.*?({$money}).*?本期账单金额.*?({$money}).*?本期调整金额.*?({$money}).*?循环利息.*?({$money})/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         //TODO $out[3][0] 为Balance B/F 对应数据库字段last_balance
         //            print_r($out);
         //            exit;
         $card['balance']['人民币']['new_balance'] = ParseUtil::formatMoney($out[2][0]);
         //New Balance
         $card['balance']['人民币']['min_payment'] = ParseUtil::formatMoney($out[1][0]);
         //Min.Payment
         $card['balance']['人民币']['last_balance'] = ParseUtil::formatMoney($out[3][0]);
         //Balance B/F
         $card['balance']['人民币']['last_payment'] = ParseUtil::formatMoney($out[4][0]);
         //Payment
         $card['balance']['人民币']['new_charges'] = ParseUtil::formatMoney($out[5][0]);
         //New Carges
         $card['balance']['人民币']['adjustment'] = ParseUtil::formatMoney($out[6][0]);
         //Adjustment
         $card['balance']['人民币']['interest'] = ParseUtil::formatMoney($out[7][0]);
         //循环利息
         //            print_r($card['balance']['人民币']);
         //            exit;
     }
     // 细交易信息(人民币)
     //		$p = '/CARD No\.\(last 4 digits\)(.*?)本账户积分明细/';
     $p = '/交易日(.*?)本账户积分明细/';
     $r = $this->pregMatchAll($p, $s, $out);
     $d = $out[1][0];
     $p = "/({$date}) # ({$date}) # (.*?) # ({$money}) # (\\d{4}) #/";
     $r = $this->pregMatchAll($p, $d, $out);
     for ($j = 0; $j < count($out[1]); $j++) {
         $one['trans_date'] = ParseUtil::formatDate($out[1][$j], $info['statement_end_date']);
         $one['post_date'] = ParseUtil::formatDate($out[2][$j], $info['statement_end_date']);
         $one['description'] = $out[3][$j];
         $one['rmb_amount'] = ParseUtil::formatMoney($out[4][$j]);
         $one['card_no'] = $out[5][$j];
         $one['currency'] = ParseUtil::getCurrencyType($out[4][$j]);
         $one['type'] = ParseUtil::getConsumeType($one['description']);
         // 消费分类
         $one['is_doubt'] = ParseUtil::isDoubtComsume($one['description']);
         // 可疑消费分析
         $trades[] = $one;
         $info['card_no'] = $one['card_no'];
     }
     #积分明细(信用卡积分,分行特色信用卡积分,联名积分1,联名积分2)
     #bug-fix by shupan at 20131212 17:04
     //		$p = '/EndingBalance # (\d+)[^\d]*(\d+)[^\d]*(\d+)[^\d]*(\d+)[^\d]*(\d+)[^\d]*(\d+)[^\d]*(\d+)/';
     $num = '\\d+';
     $p = "/累计积分余额 [^\\d]* ({$num}) [^\\d]* ({$num}) [^\\d]* ({$num}) [^\\d]* ({$num}) [^\\d]* ({$num}) [^\\d]* ({$num})/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $point['total_points'] = ParseUtil::formatNum($out[1][0]);
         $point['earned_points'] = ParseUtil::formatNum($out[4][0]);
         $point['adjusted_points'] = ParseUtil::formatNum($out[5][0]);
         $point['rewarded_points'] = ParseUtil::formatNum($out[6][0]);
         $point['last_points'] = ParseUtil::formatNum($out[2][0]);
         $point['redeemed_points'] = ParseUtil::formatNum($out[3][0]);
     }
     $card['trades'] = $trades;
     $card['points'] = $point;
     $cards[$info['card_no']] = $card;
 }
Beispiel #9
0
 public function parse($content)
 {
     $info = array();
     $s = str_replace('&nbsp;', ' ', $content);
     $s = str_replace('#', '', $s);
     $s = str_replace('</td>', ' # ', $s);
     $s = strip_tags($s);
     $s = preg_replace('/\\s+/', ' ', $s);
     //        var_dump($s);
     //        exit;
     // 		file_put_contents('/home/rong/tmp/guangfa.' . date('Ymd.His') . '.' . rand(0,100) . '.txt', $s);
     #用户信息
     $zh = '[\\x{4e00}-\\x{9fa5}]+';
     $p = "/尊敬的\\s*?({$zh})\\s*?(女士|先生)/u";
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        exit;
     if ($r) {
         $info['name'] = $out[1][0];
         $info['sex'] = $out[2][0];
     } elseif ($this->pregMatchAll("/尊敬的\\s*?({$zh}).*?(女士|先生)/u", $s, $out)) {
         $info['name'] = $out[1][0];
         $info['sex'] = $out[2][0];
     }
     //        print_r($info);
     //        exit;
     $money = '[¥$\\$\\d\\-\\., ]+';
     $date = '\\d{4}\\/\\d{2}\\/\\d{2}';
     $fullCardNo = '\\d{4}\\*{8}\\d{4}';
     preg_match_all("/{$fullCardNo}/", $s, $match);
     //TODO 多卡解析,合并多卡卡号
     //        print_r(array_unique($match[0]));
     //筛选出所有的卡号
     $card_num_arr = array();
     $unique_cards_arr = array_unique($match[0]);
     foreach ($unique_cards_arr as $val) {
         $card_num_arr[] = substr($val, -4);
     }
     $all_card_no_str = implode(',', array_unique($card_num_arr));
     $cards_count = count($card_num_arr);
     // 该详情页含有的信用卡的数量
     //        var_dump($all_card_no_str);
     //        exit;
     /**
      * (2011年11月账单)账单周期Statement cycle # 2011/11/02-2011/12/01 # 综合信用额度Total Credit Limit # 10,000.00 #
      * (2013年10月账单)账单周期 Statement Cycle # 2013/10/04-2013/11/03 # # # # # 综合信用额度 Total Credit Limit # 13,000
      * bug-fix by shupan at 2013-11-09 14:36
      */
     $p = "/Statement ?[Cc]ycle # ({$date})[\\- ]+({$date}) .*?Total Credit Limit # ({$money})/";
     $r = preg_match_all($p, $s, $out);
     if (!$r) {
         //2013年部分账单(5月),账单周期和综合信用额度用的是图片,太坑爹啦
         $p = "/({$date})[\\- ]+({$date}) [ #]+ ({$money})/";
         $r = $this->pregMatchAll($p, $s, $out);
     }
     if ($r) {
         $info['statement_start_date'] = ParseUtil::formatDate($out[1][0]);
         $info['statement_end_date'] = ParseUtil::formatDate($out[2][0]);
         //            var_dump($info ['statement_end_date']);
         //            exit;
         $info['payment_cur_date'] = $info['statement_end_date'];
         $info["credit_limit"] = ParseUtil::formatMoney($out[3][0]);
     }
     $cards = array();
     $p = '/卡号 Card Number # (\\S+) [ #]+ 本期应还总额 New Balance # (\\S+) [ #]+ 本期最低还款额 Min Payment # (\\S+) [ #]+ 还款到期日 Payment Due Date # (\\S+) [ #]+ 清算货币 Currency # (\\S+) [ #]+ 信用额(元) Credit Limit # (\\S+)/';
     // 		$p = '/卡号 Card Number # (\S+) [ #]+ 本期应还总额 New Balance # (\S+) [ #]+ 本期最低还款额 Min Payment # (\S+) [ #]+ 还款到期日 Payment Due Date # (\S+)/';
     //		$r = $this->pregMatchAll($p, $s, $out);
     $r = preg_match_all($p, $s, $out);
     //        print_r($out);
     //        exit;
     if (!$r) {
         //bug-fix by shupan at 2013-11-09 14:36, 支持2011年旧账单
         //          $p = "/信用额[(\(]元[)\)] ?Credit Limit [ #]* ($fullCardNo) # ($money) # ($money) # ($date) # ([^#]*) # ($money)/";
         $p = "/信用额.*?元.*?Credit Limit [ #]* ({$fullCardNo}) # ({$money}) # ({$money}) # ({$date}) # ([^#]*) # ({$money})/";
         $r = preg_match_all($p, $s, $out);
         //            print_r($out);
         //            exit;
     }
     if (!$r) {
         //2013年部分账单(5月),信用卡基本信息都是用的是图片
         $p = "/({$fullCardNo}) [ #]+ ({$money}) [ #]+ ({$money}) [ #]+ ({$date}) [ #]+ ([^#]*) [ #]+ ({$money})/";
         $r = $this->pregMatchAll($p, $s, $out);
         //            print_r($out);
         //            exit;
     }
     if ($r) {
         if (count($out[1]) > 1) {
             //TODO 多卡问题,new_balance等信息解析
             $new_balance = 0;
             foreach ($out[2] as $val) {
                 $new_balance += ParseUtil::formatMoney($val);
             }
             $card['new_balance'] = $new_balance;
             //                var_dump($new_balance);
             $min_payment = 0;
             foreach ($out[3] as $val) {
                 $min_payment += ParseUtil::formatMoney($val);
             }
             $card['min_payment'] = $min_payment;
             //                var_dump($min_payment);
             $payment_due_date = 0;
             foreach ($out[4] as $val) {
                 $payment_due_date = ParseUtil::formatDate($val);
             }
             $card['payment_due_date'] = $payment_due_date;
             //                var_dump($payment_due_date);
             $credit_limit_arr = array();
             foreach ($out[6] as $val) {
                 $credit_limit_arr[] = ParseUtil::formatMoney($val);
             }
             $card['credit_limit'] = max($credit_limit_arr);
             //取最大额作为其信用额度
             //                var_dump($card['credit_limit']);
             $currency = $out[5][0];
             //暂时按统一币种处理
             $card_key = $unique_cards_arr[0];
             $cards[$card_key]['balance'][$currency] = $card;
             //                print_r($cards);
         } else {
             //单卡问题
             for ($i = 0; $i < count($out[1]); $i++) {
                 $card['new_balance'] = ParseUtil::formatMoney($out[2][$i]);
                 $card['min_payment'] = ParseUtil::formatMoney($out[3][$i]);
                 $card['payment_due_date'] = ParseUtil::formatDate($out[4][$i]);
                 $card["credit_limit"] = ParseUtil::formatMoney($out[6][$i]);
                 $currency = $out[5][$i];
                 $card_key = $out[1][$i];
                 $cards[$card_key]['balance'][$currency] = $card;
             }
         }
     }
     //        print_r($out);
     //        exit;
     #获取各张卡的交易信息
     $transDate = '\\d{8}';
     $p = "/卡号.*?({$fullCardNo}) [ #]+ {$transDate} # {$transDate} (.*?) # 合计/";
     $r = preg_match_all($p, $s, $out);
     //        print_r($out);
     //        exit;
     //        $money = '([0-9,-]+\.\d{2})';   // TODO 金额包含正负号
     if (!$r) {
         //            $transDate = '\d{2}\/\d{2}';
         $p = "/交易明细 [ #]+ (.*?) # 合计/";
         $r = $this->pregMatchAll($p, $s, $out);
         //            print_r($out);
         //            exit;
         if ($r) {
             $transDate = '\\d{4}-?\\d{2}-?\\d{2}';
             $transContent = $out[1][0];
             print_r($transContent);
             $p = "/({$transDate}|\\s?) # ({$transDate}|\\s?)\\s?# (.*?) # {$money} # (人民币) # {$money}/";
             $transDetailMatched = $this->pregMatchAll($p, $transContent, $transDetailMatch);
             //                print_r($transDetailMatch);
             //                exit;
             if ($transDetailMatched) {
                 for ($rnum = 0; $rnum < count($transDetailMatch[0]); $rnum++) {
                     if (!trim($transDetailMatch[1][$rnum])) {
                         $trade['trans_date'] = $info['statement_end_date'];
                         $trade['post_date'] = $info['statement_end_date'];
                     } else {
                         $trade['trans_date'] = ParseUtil::formatDate($transDetailMatch[1][$rnum], $info['statement_end_date']);
                         $trade['post_date'] = ParseUtil::formatDate($transDetailMatch[2][$rnum], $info['statement_end_date']);
                     }
                     $trade['description'] = str_replace('#', '', $transDetailMatch[3][$rnum]);
                     $trade['rmb_amount'] = ParseUtil::formatMoney($transDetailMatch[4][$rnum]);
                     if ($trade['rmb_amount'] == '0.0') {
                         $trade['rmb_amount'] = ParseUtil::formatMoney('-' . $transDetailMatch[5][$rnum]);
                     }
                     $trade['currency'] = ParseUtil::getCurrencyType($transDetailMatch[6][$rnum]);
                     $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                     //消费分类
                     $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                     //可疑消费分析
                     $trades[] = $trade;
                 }
             }
             //                print_r($trades);
             //                print_r($cards);
             //                exit;
             foreach ($cards as $key => $val) {
                 //                    $card_key = substr($key, -4);
                 $card_key = $key;
                 $cards[$card_key]['trades'] = $trades;
             }
             //                print_r($cards[$card_key]['trades']);
             //                exit;
         }
     }
     if ($r) {
         $card_num = count($out[0]);
         for ($cnum = 0; $cnum < $card_num; $cnum++) {
             $card_key = $out[1][$cnum];
             //                print_r($card_key);
             //                print_r($cards);
             if ($cards_count < 2) {
                 if (array_key_exists($card_key, $cards)) {
                     $p = "/({$transDate}|\\s)[\\s]?#[\\s]?({$transDate}|\\s+)[\\s]?# ([^#]*?) # (\\S+) # (人民币) # (\\S+) #/";
                     $r = $this->pregMatchAll($p, $out[0][$cnum], $out_tmp);
                     //                    print_r($out_tmp);
                     //                    exit;
                     if ($r) {
                         for ($rnum = 0; $rnum < count($out_tmp[0]); $rnum++) {
                             if (!trim($out_tmp[1][$rnum])) {
                                 $trade['trans_date'] = $info['statement_end_date'];
                                 $trade['post_date'] = $info['statement_end_date'];
                             } else {
                                 $trade['trans_date'] = ParseUtil::formatDate($out_tmp[1][$rnum], $info['statement_end_date']);
                                 $trade['post_date'] = ParseUtil::formatDate($out_tmp[2][$rnum], $info['statement_end_date']);
                             }
                             $trade['description'] = $out_tmp[3][$rnum];
                             $trade['rmb_amount'] = ParseUtil::formatMoney($out_tmp[4][$rnum]);
                             if ($trade['rmb_amount'] == '0.0') {
                                 $trade['rmb_amount'] = ParseUtil::formatMoney('-' . $out_tmp[5][$rnum]);
                             }
                             $trade['currency'] = ParseUtil::getCurrencyType($out_tmp[6][$rnum]);
                             $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                             //消费分类
                             $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                             //可疑消费分析
                             $trades[] = $trade;
                         }
                     }
                     $cards[$card_key]['trades'] = $trades;
                     //                    var_dump($cards[$card_key]['trades']);
                     //                    exit;
                 }
             } else {
                 $p = "/({$transDate}|\\s)[\\s]?#[\\s]?({$transDate}|\\s+)[\\s]?# ([^#]*?) # (\\S+) # (人民币) # (\\S+) #/";
                 $r = $this->pregMatchAll($p, $out[0][$cnum], $out_tmp);
                 //                    print_r($out_tmp);
                 //                    exit;
                 if ($r) {
                     for ($rnum = 0; $rnum < count($out_tmp[0]); $rnum++) {
                         if (!trim($out_tmp[1][$rnum])) {
                             $trade['trans_date'] = $info['statement_end_date'];
                             $trade['post_date'] = $info['statement_end_date'];
                         } else {
                             $trade['trans_date'] = ParseUtil::formatDate($out_tmp[1][$rnum], $info['statement_end_date']);
                             $trade['post_date'] = ParseUtil::formatDate($out_tmp[2][$rnum], $info['statement_end_date']);
                         }
                         $trade['description'] = $out_tmp[3][$rnum];
                         $trade['rmb_amount'] = ParseUtil::formatMoney($out_tmp[4][$rnum]);
                         if ($trade['rmb_amount'] == '0.0') {
                             $trade['rmb_amount'] = ParseUtil::formatMoney('-' . $out_tmp[5][$rnum]);
                         }
                         $trade['currency'] = ParseUtil::getCurrencyType($out_tmp[6][$rnum]);
                         $trade['type'] = ParseUtil::getConsumeType($trade['description']);
                         //消费分类
                         $trade['is_doubt'] = ParseUtil::isDoubtComsume($trade['description']);
                         //可疑消费分析
                         $trades[] = $trade;
                     }
                 }
                 $cards[$card_key]['trades'] = $trades;
                 //                    var_dump($cards[$card_key]['trades']);
                 //                    exit;
             }
         }
     }
     //        print_r($cards);
     //        exit;
     #解析本期应还总额情况
     #added by xudongbo 20150505
     $p = "/# 人民币 # ({$money}) # # ({$money}) # # ({$money}) # # ({$money})[ #]* 积分按卡号汇总情/";
     $r = $this->pregMatchAll($p, $s, $out);
     //        print_r($out);
     //        print_r($s);
     //        exit;
     if (!$r) {
         # 人民币 # 7,136.96 # # 4,878.48 # # 7,139.00 # # 4,876.44 # # # # # # # # # # # # # # # # 分期付款明细
         $p = "/# 人民币 # ({$money}) # # ({$money}) # # ({$money}) # # ({$money})[ #]* 分期付款明细/";
         $r = $this->pregMatchAll($p, $s, $out);
         //            print_r($out);
         //            exit;
         if ($r) {
             for ($i = 0; $i < count($out[1]); $i++) {
                 $info['last_balance'] = ParseUtil::formatMoney($out[1][$i]);
                 $info['new_charges'] = ParseUtil::formatMoney($out[2][$i]);
                 $info['last_payment'] = ParseUtil::formatMoney($out[3][$i]);
             }
         }
     } else {
         //字段修改字段对应数据
         for ($i = 0; $i < count($out[1]); $i++) {
             $info['last_balance'] = ParseUtil::formatMoney($out[1][$i]);
             $info['new_charges'] = ParseUtil::formatMoney($out[2][$i]);
             $info['last_payment'] = ParseUtil::formatMoney($out[3][$i]);
         }
     }
     if ($cards_count > 1) {
         // TODO 多卡问题
         //            print_r($s);
         $p = "/\\d{4} # 人民币 # ({$money}) # # ({$money}) # # ({$money}) # # ({$money})/";
         $r = $this->pregMatchAll($p, $s, $match);
         print_r($match);
         $last_balance = 0;
         foreach ($match[1] as $val) {
             $last_balance += ParseUtil::formatMoney($val);
         }
         $info['last_balance'] = $last_balance;
         //Opening Balance
         $new_charges = 0;
         foreach ($match[2] as $val) {
             $new_charges += ParseUtil::formatMoney($val);
         }
         $info['new_charges'] = $new_charges;
         //Total Debits
         $last_payment = 0;
         foreach ($match[3] as $val) {
             $last_payment += ParseUtil::formatMoney($val);
             //Total Credits
         }
         $info['last_payment'] = $last_payment;
         //            print_r($info);
         //            exit;
     }
     #获取积分信息
     $p = '/本期扣减.*?本期余额 ?Current Balance [ #]+ (.*?) [◆|【]/';
     $r = $this->pregMatchAll($p, $s, $out);
     $num = '[\\d,\\-]*';
     if ($r) {
         $p = "/(\\S+) # (\\S+) # ({$num}) [ #]* ({$num}) [ #]* ({$num}) [ #]* ({$num})/";
         $r = $this->pregMatchAll($p, $out[1][0], $out_tmp);
         for ($jfnum = 0; $jfnum < count($out_tmp[0]); $jfnum++) {
             $card_key = $out_tmp[1][$jfnum];
             if (array_key_exists($card_key, $cards)) {
                 // 					$jf['type'] = $out_tmp[2][$jfnum];
                 $jf['last_points'] = ParseUtil::formatNum($out_tmp[3][$jfnum]);
                 $jf['earned_points'] = ParseUtil::formatNum($out_tmp[4][$jfnum]);
                 $jf['redeemed_points'] = ParseUtil::formatNum($out_tmp[5][$jfnum]);
                 $jf['total_points'] = ParseUtil::formatNum($out_tmp[6][$jfnum]);
             }
             //                print_r($jf);
             //                exit;
             $cards[$card_key]['points'] = $jf;
         }
     }
     if (empty($cards)) {
         return $this->insert($info);
     }
     //多卡问题
     //        print_r($cards);
     //        exit;
     if ($cards_count > 1) {
         $combine_cards_info = array();
         foreach ($cards as $key => $detail) {
             $oneCardInfo = $info;
             //            print_r($info);
             //            print_r($cards);
             //            var_dump($detail);
             //            exit;
             //            $oneCardInfo['card_no'] = substr($key, -4);     //TODO 多卡问题
             $oneCardInfo['card_no'] = $all_card_no_str;
             //            print_r($oneCardInfo['card_no']);
             //            exit;
             if (isset($detail['trades'])) {
                 $oneCardInfo['trans_detail'] = json_encode($detail['trades']);
             }
             if (is_array($detail['balance']['人民币'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['balance']['人民币']);
             }
             if (isset($detail['balance']['美元'])) {
                 $oneCardInfo['credit_limit_usd'] = $detail['balance']['美元']['credit_limit'];
                 $oneCardInfo['new_balance_usd'] = $detail['balance']['美元']['new_balance'];
                 $oneCardInfo['min_payment_usd'] = $detail['balance']['美元']['min_payment'];
             }
             if (is_array($detail['points'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['points']);
             }
             $combine_cards_info = array_merge($combine_cards_info, $oneCardInfo);
             //            print_r($oneCardInfo);
             //            exit;
             //            $this->insert($oneCardInfo);
         }
         print_r($combine_cards_info);
         exit;
         return true;
     } else {
         foreach ($cards as $key => $detail) {
             $oneCardInfo = $info;
             //            $oneCardInfo['card_no'] = substr($key, -4);     //TODO 多卡问题
             $oneCardInfo['card_no'] = $all_card_no_str;
             //            print_r($oneCardInfo['card_no']);
             //            exit;
             if (isset($detail['trades'])) {
                 $oneCardInfo['trans_detail'] = json_encode($detail['trades']);
             }
             if (is_array($detail['balance']['人民币'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['balance']['人民币']);
             }
             if (isset($detail['balance']['美元'])) {
                 $oneCardInfo['credit_limit_usd'] = $detail['balance']['美元']['credit_limit'];
                 $oneCardInfo['new_balance_usd'] = $detail['balance']['美元']['new_balance'];
                 $oneCardInfo['min_payment_usd'] = $detail['balance']['美元']['min_payment'];
             }
             if (is_array($detail['points'])) {
                 $oneCardInfo = array_merge($oneCardInfo, $detail['points']);
             }
             print_r($oneCardInfo);
             //            $this->insert($oneCardInfo);
         }
         return true;
     }
 }
Beispiel #10
0
 public function OldBillParse($s, array &$info, array &$details)
 {
     #账户基本信息
     #额度基本信息(人民币)
     $money = '[\\-\\d\\.,]+';
     $date = '\\d{4}\\-\\d{2}\\-\\d{2}';
     $p = "/信用额度 # RMB ({$money}) # 取现额度 # RMB ({$money}) # 本期账单日 # ({$date}) # 本期应还金额 # RMB ({$money}) # 本期还款日 # ({$date}) # 本期最低还款额 # RMB ({$money})/";
     $r = preg_match_all($p, $s, $out);
     //        print_r($out);
     //        exit;
     if ($r) {
         $info['credit_limit'] = ParseUtil::formatMoney($out[1][0]);
         $info['cash_advance_limit'] = ParseUtil::formatMoney($out[2][0]);
         $info['payment_cur_date'] = ParseUtil::formatDate($out[3][0]);
         $info['payment_due_date'] = ParseUtil::formatDate($out[5][0]);
         $info['statement_end_date'] = $info['payment_cur_date'];
         $info['statement_start_date'] = strtotime('last month', $info['payment_cur_date']);
         $info['new_balance'] = ParseUtil::formatMoney($out[4][0]);
         $info['min_payment'] = ParseUtil::formatMoney($out[6][0]);
     } else {
         //bug-fix by shupan at 2013-11-09 19:09
         $p = "/信用额度 [^#]*# RMB ({$money}) # 取现额度 [^#]*# RMB ({$money}) # 账单日 [^#]*# ({$date}) # 到期还款日 [^#]*# ({$date}) # 本期应还款金额 [^#]*# RMB ({$money}) # 最低还款金额 [^#]*# RMB ({$money})/";
         $r = $this->pregMatchAll($p, $s, $out);
         //            print_r($s);
         //            print_r($out);
         //            exit;
         if ($r) {
             $info['credit_limit'] = ParseUtil::formatMoney($out[1][0]);
             $info['cash_advance_limit'] = ParseUtil::formatMoney($out[2][0]);
             $info['payment_cur_date'] = ParseUtil::formatDate($out[3][0]);
             $info['payment_due_date'] = ParseUtil::formatDate($out[4][0]);
             $info['new_balance'] = ParseUtil::formatMoney($out[5][0]);
             $info['min_payment'] = ParseUtil::formatMoney($out[6][0]);
         }
     }
     if ($r) {
         //没有账单周期,自己算,当前账单日设为周期末尾一天
         $info['statement_end_date'] = $info['payment_cur_date'];
         $info['statement_start_date'] = strtotime('last month', $info['payment_cur_date']);
     }
     #账户还款计算明细(人民币)
     $p = "/上期账单金额 ?RMB ({$money}) # 上期还款金额 ?RMB ({$money}) # 本期账单金额 ?RMB ({$money}) # 本期调整金额 ?RMB ({$money}) # 循环利息 ?RMB ({$money})/";
     //		$r = $this->pregMatchAll($p, $s, $out);
     $r = preg_match_all($p, $s, $out);
     //        print_r($out);
     //        exit;
     if (!$r) {
         //bug-fix by shupan at 2013-11-09 19:09
         $p = "/上期账单金额 [^#]* # RMB ({$money}) [^#]* # [^#]* # RMB ({$money}) [^#]* # [^#]* # RMB ({$money}) [^#]* # [^#]* # RMB ({$money}) [^#]* # [^#]* # RMB ({$money})/";
         $r = $this->pregMatchAll($p, $s, $out);
         //            print_r($s);
         //            print_r($out);
         //            exit;
     }
     //        print_r($out);
     //        exit;
     if ($r) {
         $info['last_balance'] = ParseUtil::formatMoney($out[1][0]);
         $info['last_payment'] = ParseUtil::formatMoney($out[2][0]);
         $info['new_charges'] = ParseUtil::formatMoney($out[3][0]);
         $info['adjustment'] = ParseUtil::formatMoney($out[4][0]);
         $info['interest'] = ParseUtil::formatMoney($out[5][0]);
     }
     //TODO美元
     #详细交易信息
     //		$p = '/人民币金额 # (.*)用卡小贴士/';
     $p = '/交易日期 # (.*)/';
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $d = $out[1][0];
         $p = "/({$date}) # ({$date})( # (\\d{4}))? # ([^#]*) # [RMB ]*({$money})/";
         $r = $this->pregMatchAll($p, $d, $out);
         //            print_r($out);
         //            exit;
         if ($r) {
             //账单详细明细中可能没有卡号,那么随机分配一个,这种账单应该是一起还的(已和PM确认),
             $cards = array_unique($out[4], SORT_REGULAR);
             sort($cards);
             $defaultNo = array_pop($cards);
             for ($i = 0; $i < count($out[0]); $i++) {
                 $one['trans_date'] = ParseUtil::formatDate($out[1][$i], $info['statement_end_date']);
                 $one['post_date'] = ParseUtil::formatDate($out[2][$i], $info['statement_end_date']);
                 $one['card_no'] = empty($out[4][$i]) ? $defaultNo : $out[4][$i];
                 //                    $one['card_no'] = $defaultNo;
                 $one['description'] = $out[5][$i];
                 $one['rmb_amount'] = ParseUtil::formatMoney($out[6][$i]);
                 $one['currency'] = ParseUtil::getCurrencyType($out[6][$i]);
                 $one['type'] = ParseUtil::getConsumeType($one['description']);
                 //消费分类
                 $one['is_doubt'] = ParseUtil::isDoubtComsume($one['description']);
                 //可疑消费分析
                 $details[$one['card_no']][] = ParseUtil::trimArr($one);
                 unset($one);
             }
         }
         //            print_r($details);
         //            exit;
     }
     $info['card_no'] = $this->all_card_no_str;
     //        print_r($info);
     //        exit;
     #积分明细
     $num = '([\\d,]+)';
     $p = "/万里通积分.*?本期余额 # ({$num}) # 本期新增 # ({$num}) # 本期调整 # ({$num})/";
     $r = $this->pregMatchAll($p, $s, $out);
     if ($r) {
         $info['total_points'] = ParseUtil::formatNum($out[1][0]);
         $info['earned_points'] = ParseUtil::formatNum($out[2][0]);
         $info['adjusted_points'] = ParseUtil::formatNum($out[3][0]);
     }
 }