Authored by yangyang

解决冲突

... ... @@ -18,6 +18,7 @@ use Plugin\Cache;
use Plugin\Helpers;
use Hood\Session;
use LibModels\Wap\Passport\LoginData;
use Plugin\UdpLog;
class AbstractAction extends Controller_Abstract
{
... ... @@ -328,6 +329,7 @@ class AbstractAction extends Controller_Abstract
if (isset($userInfo['data']) && $userInfo['data']) {
$uidCookie = $userInfo['data']['profile_name'] . '::' . $userInfo['data']['uid'] . '::' . $userInfo['data']['vip_info']['title'] . '::' . $token;
$this->setCookie('_UID', $uidCookie);
UdpLog::info('【登录】同步登陆cookie生成',$uidCookie);
}
$this->setSession('_TOKEN', $token);
$this->setSession('_LOGIN_UID', $uid);
... ...
... ... @@ -255,7 +255,7 @@ class Yohobuy
}
$result = curl_exec($ch);
//log打印
UdpLog::info('get调用接口入参url/出参:', 'in:'.$url.'?'.$str.' out:'.$result);
UdpLog::info('post调用接口入参url/出参:', 'in:'.$url.'?'.$str.' out:'.$result);
if (!$returnJson && !empty($result)) {
$result = json_decode($result, true);
}
... ...
... ... @@ -23,6 +23,13 @@ class UdpLog
public static $port = '4444';
//influxdb measurement
public static $measurement = 'php_log';
public static $filePath = '/Data/logs/';
const RECORD_MODE_FILE = 'FILE';
const RECORD_MODE_UDP = 'UDP';
const RECORD_MODE = 'FILE';//mode: FILE | UDP
/**
* proc line and send log to influxdb
... ... @@ -30,27 +37,82 @@ class UdpLog
* @param $message
* @param $meta
*/
private static function procLog($level,$message,$debugInfo,$meta='') {
private static function procLog($level, $message, $debugInfo, $meta = '') {
date_default_timezone_set('PRC');
$level = str_replace(__CLASS__.'::','',$level);
$file = $debugInfo[0]["file"];
$line = $debugInfo[0]["line"];
$string = '';
//make tags
$tags = array(
'host='.gethostname(),
'level='.$level,
'file='.$file,
'line='.$line
'time' => date('Y-m-d H:i:s',time()),
'level' => $level,
'host'=> gethostname(),
'file'=> $file,
'line'=> $line,
'message' => $message,
'meta' => serialize($meta)
);
//make a line
$tags = implode(',',$tags);
$string = self::$measurement .','.$tags.' message="'.$message.'",meta="'.var_export($meta,true).'"';
self::send($string);
$string = implode('|', $tags);//format: time|level|host|file|line|message|meta
if(self::RECORD_MODE == self::RECORD_MODE_UDP) {
self::send($string);
}
else if(self::RECORD_MODE == self::RECORD_MODE_FILE) {
self::fileLog($level, $string);
}
}
/**
* 文件日志记录
*
* @param string $level
* @param string $message
*/
private static function fileLog($level, $message)
{
$filename = $level . '.log'; //日志文件
$logFile = self::createPath(self::$filePath, $filename);
if (!file_exists(self::$filePath))//判断文件路径是否存在
{
if (!empty(self::$filePath))//判断路径是否为空
{
if (!(self::createDir(self::$filePath))) {
return false;
}
if (!is_writable($logFile)) {
return false;
}
}
}
@error_log($message."\r\n", 3, $logFile);
}
/**
* 作用:创建目录
* 输入:要创建的目录
* 输出:true | false
*/
private static function createDir($dir)
{
return is_dir($dir) or (self::createDir(dirname($dir)) and mkdir($dir, 0777));
}
/**
* 作用:构建路径
* 输入:文件的路径,要写入的文件名
* 输出:构建好的路径字串
*/
private static function createPath($dir, $filename)
{
if (empty($dir)) {
return $filename;
} else {
return $dir . "/" . $filename;
}
}
/**
* send by udp
* @param $string
*/
... ... @@ -96,5 +158,4 @@ class UdpLog
public static function debug($message,$meta='') {
self::procLog(__METHOD__,$message,debug_backtrace(),$meta);
}
}
}
\ No newline at end of file
... ...
... ... @@ -10,6 +10,7 @@ use Plugin\Pay\weixin\JsApiPay;
use Plugin\Pay\weixin\lib\WxPayUnifiedOrder;
use Plugin\Pay\weixin\lib\WxPayApi;
use Plugin\Pay\weixin\lib\WxPayConfig;
use Plugin\UdpLog;
/**
* 个人中心相关的控制器
... ... @@ -968,6 +969,7 @@ class HomeController extends AbstractAction
/* 判断订单信息不存在 */
$orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
if (empty($orderDetail['data'])) {
UdpLog::info('【下单】订单信息校验','orderCode:'.$orderCode.'uid:'.$uid.'返回:'.json_encode($orderDetail));
break;
}
... ...
... ... @@ -8,6 +8,7 @@ use Plugin\Helpers;
use Plugin\Images;
use Plugin\UdpLog;
/**
*
* @name CartModel
... ... @@ -731,12 +732,15 @@ class CartModel
$result = array('code' => 400, 'message' => '出错啦');
if (empty($addressId)) {
UdpLog::info('【结算信息】配送地址参数校验','addressId为空');
$result['code'] = 401;
$result['message'] = '配送地址不能为空';
} elseif (empty($deliveryTime)) {
UdpLog::info('【结算信息】配送时间参数校验','deliveryTime为空');
$result['code'] = 402;
$result['message'] = '请选择配送时间';
} elseif (empty($deliveryWay)) {
UdpLog::info('【结算信息】配送方式参数参数校验','deliveryTime为空');
$result['code'] = 403;
$result['message'] = '请选择配送方式';
} else {
... ...
... ... @@ -8,6 +8,7 @@ use LibModels\Wap\Home\UserData;
use Plugin\Cache;
use Plugin\Helpers;
use Plugin\Images;
use Plugin\UdpLog;
/**
*
... ... @@ -590,6 +591,7 @@ class UserModel
// 处理地址数据
if (isset($address['data']) && !empty($address['data'])) {
UdpLog::info('地址数据校验','uid'.$uid.'返回:'.json_encode($address));
$result = $address['data'];
}
... ...
... ... @@ -6,6 +6,7 @@ use Index\CartModel;
use Index\UserModel;
use Plugin\Helpers;
use Plugin\UnionTrans;
use Plugin\UdpLog;
/**
* 购物车相关的控制器
... ... @@ -465,6 +466,7 @@ class IndexController extends AbstractAction
. ',deliveryWay:' . $deliveryWay . 'invoiceTitle:' . $invoiceTitle . ',invoiceId:' . $invoiceId . ',yohoCoin:' . $yohoCoin
. ',paymentId:' . $paymentId . ',paymentType:' . $paymentType . ',remark:' . $remark . ',couponCode:' . $couponCode . "\n";
error_log($message, 3, '/Data/logs/php/h5_error/order.' . date('Ym') . '.log');
UdpLog::info('【下单】下单异常数据','message:'.$message,'返回:'.json_encode($result));
}
// 返回数据
else {
... ...
... ... @@ -10,6 +10,7 @@ use Plugin\Pay\weixin\lib\WxPayApi;
use Plugin\Pay\weixin\lib\WxPayConfig;
use Plugin\Pay\aliwap\AliwapReqparams;
use Plugin\Pay\aliwap\AliwapService;
use Plugin\UdpLog;
/**
* 支付相关的控制器
... ... @@ -33,12 +34,14 @@ class PayController extends AbstractAction
/* 判断是否有订单号参数 */
$orderCode = $this->get('order_code');
if (empty($orderCode)) {
UdpLog::info('【支付宝支付】参数校验', 'orderCode为空');
break;
}
/* 判断用户是否登录 */
$uid = $this->getUid(true);
if (!$uid) {
UdpLog::info('【支付宝支付】参数校验', 'uid为空');
$this->go( Helpers::url('/signin.html', array('refer' => $this->_request->server('HTTP_REFERER'))) );
break;
}
... ... @@ -46,6 +49,7 @@ class PayController extends AbstractAction
/* 判断订单信息是否存在 */
$orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
if (empty($orderDetail['data'])) {
UdpLog::info('【支付宝支付】校验订单信息', 'orderCode:'.$orderCode.'uid:'.$uid.'返回:'.json_encode($orderDetail));
$this->helpJsRedirect('没有找到该订单');
break;
}
... ... @@ -61,6 +65,7 @@ class PayController extends AbstractAction
$aliwapService = new AliwapService();
$payRequestPars = $aliwapService->getPayRequestPars($reqParams);
if (empty($payRequestPars)) {
UdpLog::info('【支付宝支付】提交支付宝端口无响应', 'orderCode:'.$orderCode.'totalFee:'.$totalFee.'createTime:'.$orderDetail['data']['create_time']);
$this->helpJsRedirect('支付系统繁忙,请稍后再试');
break;
}
... ... @@ -93,23 +98,27 @@ class PayController extends AbstractAction
$uid = $this->getUid(true);
if (!$uid) {
UdpLog::info('【wechat支付】参数校验', 'uid为空');
break;
}
$orderCode = $this->get('order_code');
if (empty($orderCode)) {
UdpLog::info('【wechat支付】参数校验', 'orderCode为空');
break;
}
/* 判断订单信息不存在 */
$orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
if (empty($orderDetail['data'])) {
UdpLog::info('【wechat支付】校验订单信息', 'orderCode:'.$orderCode.'uid:'.$uid.'返回:'.json_encode($orderDetail));
break;
}
$totalFee = strval($orderDetail['data']['payment_amount'] * 100);
$openId = $this->getSession('weixinOpenId');
if (empty($openId)) {
UdpLog::info('【wechat支付】获取wechat标识为空', 'orderCode:'.$orderCode.'uid:'.$uid.'返回openId:'.$openId);
break;
}
... ... @@ -149,6 +158,7 @@ class PayController extends AbstractAction
$payment = $this->get('payment',0);
if (!$uid || !$orderCode || !$payment) {
UdpLog::info('【支付时间校验】参数校验', 'orderCode:'.$orderCode.'uid:'.$uid.'payment:'.$payment);
break;
}
... ...