|
@@ -0,0 +1,148 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace refill;
|
|
|
+
|
|
|
+require_once(BASE_HELPER_PATH . '/mtopcard/mtopcard.php');
|
|
|
+
|
|
|
+use mtopcard;
|
|
|
+use Log;
|
|
|
+
|
|
|
+class util
|
|
|
+{
|
|
|
+ static function make_mobile()
|
|
|
+ {
|
|
|
+ static $prefix = ["139","138","137","136","135","134","159","158","157","150","151","152",
|
|
|
+ "188","187","182","183","184","178","130","131","132","156","155","186","185",
|
|
|
+ "176","133","153","189","180","181","177"];
|
|
|
+
|
|
|
+ $pos = mt_rand(0,count($prefix));
|
|
|
+ $no = "{$prefix[$pos]}" . mt_rand(10000000, 99999999);
|
|
|
+
|
|
|
+ return $no;
|
|
|
+ }
|
|
|
+
|
|
|
+ static function read_card($card_no,$card_type = 0)
|
|
|
+ {
|
|
|
+ if(empty($card_no)) return false;
|
|
|
+
|
|
|
+ $data = rcache($card_no, 'cardrefill-');
|
|
|
+ if(empty($data))
|
|
|
+ {
|
|
|
+ $mod_topcard = Model('topcard');
|
|
|
+ $ret = $mod_topcard->get_card($card_no);
|
|
|
+ if(empty($ret))
|
|
|
+ {
|
|
|
+ if($card_type === 0) {
|
|
|
+ $card_type = mtopcard\card_type($card_no);
|
|
|
+ }
|
|
|
+ $bind_phone = util::make_mobile();
|
|
|
+ $mod_topcard->add($card_no,$card_type,time(),$bind_phone);
|
|
|
+
|
|
|
+ $data['bind_phone'] = $bind_phone;
|
|
|
+ $data['refill_time'] = time();
|
|
|
+ $data['times'] = 0;
|
|
|
+ $data['black_card'] = 0;
|
|
|
+
|
|
|
+ wcache($card_no,$data,'cardrefill-');
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ $val = $ret[0];
|
|
|
+
|
|
|
+ $data['bind_phone'] = $val['bind_phone'];
|
|
|
+ $data['black_card'] = $val['black_card'];
|
|
|
+ $data['refill_time'] = time();
|
|
|
+ $data['times'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //之前没加black_card处理,这个字段不存在.
|
|
|
+ if(!array_key_exists('black_card',$data)) {
|
|
|
+ $data['black_card'] = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ static function inc_card($card_no, $card_info)
|
|
|
+ {
|
|
|
+ $card_info['times'] += 1;
|
|
|
+ $card_info['refill_time'] = time();
|
|
|
+ wcache($card_no,$card_info,'cardrefill-');
|
|
|
+ }
|
|
|
+
|
|
|
+ static function del_card($card_no)
|
|
|
+ {
|
|
|
+ dcache($card_no,'cardrefill-');
|
|
|
+ }
|
|
|
+
|
|
|
+ static function set_black($card_no)
|
|
|
+ {
|
|
|
+ if(empty($card_no)) return false;
|
|
|
+
|
|
|
+ $card_info = util::read_card($card_no);
|
|
|
+ if(!empty($card_info)) {
|
|
|
+ $card_info['black_card'] = 1;
|
|
|
+ $mod_topcard = Model('topcard');
|
|
|
+ $mod_topcard->where(['card_no' => $card_no])->update(['black_card' => 1]);
|
|
|
+ wcache($card_no,$card_info,'cardrefill-');
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ private static function black_order($order_sn,$msg)
|
|
|
+ {
|
|
|
+ static $errMsgs = ["只能给绑定正确手机号的油卡充值或只能给主卡充值","只能给主卡且卡状态正常的加油卡充值","加油卡卡号错误或不支持"];
|
|
|
+
|
|
|
+ if(empty($msg)) return false;
|
|
|
+
|
|
|
+ if(in_array($msg,$errMsgs))
|
|
|
+ {
|
|
|
+
|
|
|
+ $refill = Model('refill_order');
|
|
|
+ $order = $refill->getOrderInfo(['order_sn' => $order_sn]);
|
|
|
+
|
|
|
+ if(empty($order)) return false;
|
|
|
+
|
|
|
+ $card_no = $order['card_no'];
|
|
|
+ return util::set_black($card_no);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ static function black_from_log($file_name)
|
|
|
+ {
|
|
|
+ $fn = fopen($file_name,"r");
|
|
|
+ if(empty($fn)) {
|
|
|
+ Log::record("Open File {$file_name} error.",Log::ERR);
|
|
|
+ return false;
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ Log::record("{$file_name} start woring",Log::DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
+ $errs = [];
|
|
|
+ while(! feof($fn)) {
|
|
|
+ $line = trim(fgets($fn));
|
|
|
+ $ret = preg_match('/[\w\W]+"channelOrderNumber":"(?P<order_sn>[^"]+)"[\w\W]+"message":"(?P<message>[\x{4e00}-\x{9fa5}]+)"[\w\W]+"status":109/u',$line,$matches);
|
|
|
+ if($ret) {
|
|
|
+ $order_sn = $matches['order_sn'];
|
|
|
+ $message = $matches['message'];
|
|
|
+
|
|
|
+ self::black_order($order_sn,$message);
|
|
|
+
|
|
|
+ $errs[$message] = empty($errs[$message]) ? 1 : $errs[$message] + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($errs as $msg => $count) {
|
|
|
+ Log::record("msg:{$msg} count:{$count}",Log::DEBUG);
|
|
|
+ }
|
|
|
+
|
|
|
+ fclose($fn);
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+}
|