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[^"]+)"[\w\W]+"message":"(?P[\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; } }