Authored by yangyang

解决冲突

@@ -18,6 +18,7 @@ use Plugin\Cache; @@ -18,6 +18,7 @@ use Plugin\Cache;
18 use Plugin\Helpers; 18 use Plugin\Helpers;
19 use Hood\Session; 19 use Hood\Session;
20 use LibModels\Wap\Passport\LoginData; 20 use LibModels\Wap\Passport\LoginData;
  21 +use Plugin\UdpLog;
21 22
22 class AbstractAction extends Controller_Abstract 23 class AbstractAction extends Controller_Abstract
23 { 24 {
@@ -328,6 +329,7 @@ class AbstractAction extends Controller_Abstract @@ -328,6 +329,7 @@ class AbstractAction extends Controller_Abstract
328 if (isset($userInfo['data']) && $userInfo['data']) { 329 if (isset($userInfo['data']) && $userInfo['data']) {
329 $uidCookie = $userInfo['data']['profile_name'] . '::' . $userInfo['data']['uid'] . '::' . $userInfo['data']['vip_info']['title'] . '::' . $token; 330 $uidCookie = $userInfo['data']['profile_name'] . '::' . $userInfo['data']['uid'] . '::' . $userInfo['data']['vip_info']['title'] . '::' . $token;
330 $this->setCookie('_UID', $uidCookie); 331 $this->setCookie('_UID', $uidCookie);
  332 + UdpLog::info('【登录】同步登陆cookie生成',$uidCookie);
331 } 333 }
332 $this->setSession('_TOKEN', $token); 334 $this->setSession('_TOKEN', $token);
333 $this->setSession('_LOGIN_UID', $uid); 335 $this->setSession('_LOGIN_UID', $uid);
@@ -255,7 +255,7 @@ class Yohobuy @@ -255,7 +255,7 @@ class Yohobuy
255 } 255 }
256 $result = curl_exec($ch); 256 $result = curl_exec($ch);
257 //log打印 257 //log打印
258 - UdpLog::info('get调用接口入参url/出参:', 'in:'.$url.'?'.$str.' out:'.$result); 258 + UdpLog::info('post调用接口入参url/出参:', 'in:'.$url.'?'.$str.' out:'.$result);
259 if (!$returnJson && !empty($result)) { 259 if (!$returnJson && !empty($result)) {
260 $result = json_decode($result, true); 260 $result = json_decode($result, true);
261 } 261 }
@@ -23,6 +23,13 @@ class UdpLog @@ -23,6 +23,13 @@ class UdpLog
23 public static $port = '4444'; 23 public static $port = '4444';
24 //influxdb measurement 24 //influxdb measurement
25 public static $measurement = 'php_log'; 25 public static $measurement = 'php_log';
  26 +
  27 + public static $filePath = '/Data/logs/';
  28 +
  29 + const RECORD_MODE_FILE = 'FILE';
  30 + const RECORD_MODE_UDP = 'UDP';
  31 +
  32 + const RECORD_MODE = 'FILE';//mode: FILE | UDP
26 33
27 /** 34 /**
28 * proc line and send log to influxdb 35 * proc line and send log to influxdb
@@ -30,27 +37,82 @@ class UdpLog @@ -30,27 +37,82 @@ class UdpLog
30 * @param $message 37 * @param $message
31 * @param $meta 38 * @param $meta
32 */ 39 */
33 - private static function procLog($level,$message,$debugInfo,$meta='') { 40 + private static function procLog($level, $message, $debugInfo, $meta = '') {
  41 + date_default_timezone_set('PRC');
34 $level = str_replace(__CLASS__.'::','',$level); 42 $level = str_replace(__CLASS__.'::','',$level);
35 $file = $debugInfo[0]["file"]; 43 $file = $debugInfo[0]["file"];
36 $line = $debugInfo[0]["line"]; 44 $line = $debugInfo[0]["line"];
37 - 45 + $string = '';
38 //make tags 46 //make tags
39 $tags = array( 47 $tags = array(
40 - 'host='.gethostname(),  
41 - 'level='.$level,  
42 - 'file='.$file,  
43 - 'line='.$line 48 + 'time' => date('Y-m-d H:i:s',time()),
  49 + 'level' => $level,
  50 + 'host'=> gethostname(),
  51 + 'file'=> $file,
  52 + 'line'=> $line,
  53 + 'message' => $message,
  54 + 'meta' => serialize($meta)
44 ); 55 );
45 -  
46 //make a line 56 //make a line
47 - $tags = implode(',',$tags);  
48 -  
49 - $string = self::$measurement .','.$tags.' message="'.$message.'",meta="'.var_export($meta,true).'"';  
50 - self::send($string); 57 + $string = implode('|', $tags);//format: time|level|host|file|line|message|meta
  58 + if(self::RECORD_MODE == self::RECORD_MODE_UDP) {
  59 + self::send($string);
  60 + }
  61 + else if(self::RECORD_MODE == self::RECORD_MODE_FILE) {
  62 + self::fileLog($level, $string);
  63 + }
51 } 64 }
52 65
53 /** 66 /**
  67 + * 文件日志记录
  68 + *
  69 + * @param string $level
  70 + * @param string $message
  71 + */
  72 + private static function fileLog($level, $message)
  73 + {
  74 + $filename = $level . '.log'; //日志文件
  75 + $logFile = self::createPath(self::$filePath, $filename);
  76 + if (!file_exists(self::$filePath))//判断文件路径是否存在
  77 + {
  78 + if (!empty(self::$filePath))//判断路径是否为空
  79 + {
  80 + if (!(self::createDir(self::$filePath))) {
  81 + return false;
  82 + }
  83 + if (!is_writable($logFile)) {
  84 + return false;
  85 + }
  86 + }
  87 + }
  88 + @error_log($message."\r\n", 3, $logFile);
  89 + }
  90 +
  91 + /**
  92 + * 作用:创建目录
  93 + * 输入:要创建的目录
  94 + * 输出:true | false
  95 + */
  96 + private static function createDir($dir)
  97 + {
  98 + return is_dir($dir) or (self::createDir(dirname($dir)) and mkdir($dir, 0777));
  99 + }
  100 +
  101 + /**
  102 + * 作用:构建路径
  103 + * 输入:文件的路径,要写入的文件名
  104 + * 输出:构建好的路径字串
  105 + */
  106 + private static function createPath($dir, $filename)
  107 + {
  108 + if (empty($dir)) {
  109 + return $filename;
  110 + } else {
  111 + return $dir . "/" . $filename;
  112 + }
  113 + }
  114 +
  115 + /**
54 * send by udp 116 * send by udp
55 * @param $string 117 * @param $string
56 */ 118 */
@@ -96,5 +158,4 @@ class UdpLog @@ -96,5 +158,4 @@ class UdpLog
96 public static function debug($message,$meta='') { 158 public static function debug($message,$meta='') {
97 self::procLog(__METHOD__,$message,debug_backtrace(),$meta); 159 self::procLog(__METHOD__,$message,debug_backtrace(),$meta);
98 } 160 }
99 -}  
100 - 161 +}
@@ -10,6 +10,7 @@ use Plugin\Pay\weixin\JsApiPay; @@ -10,6 +10,7 @@ use Plugin\Pay\weixin\JsApiPay;
10 use Plugin\Pay\weixin\lib\WxPayUnifiedOrder; 10 use Plugin\Pay\weixin\lib\WxPayUnifiedOrder;
11 use Plugin\Pay\weixin\lib\WxPayApi; 11 use Plugin\Pay\weixin\lib\WxPayApi;
12 use Plugin\Pay\weixin\lib\WxPayConfig; 12 use Plugin\Pay\weixin\lib\WxPayConfig;
  13 +use Plugin\UdpLog;
13 14
14 /** 15 /**
15 * 个人中心相关的控制器 16 * 个人中心相关的控制器
@@ -968,6 +969,7 @@ class HomeController extends AbstractAction @@ -968,6 +969,7 @@ class HomeController extends AbstractAction
968 /* 判断订单信息不存在 */ 969 /* 判断订单信息不存在 */
969 $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession); 970 $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
970 if (empty($orderDetail['data'])) { 971 if (empty($orderDetail['data'])) {
  972 + UdpLog::info('【下单】订单信息校验','orderCode:'.$orderCode.'uid:'.$uid.'返回:'.json_encode($orderDetail));
971 break; 973 break;
972 } 974 }
973 975
@@ -8,6 +8,7 @@ use Plugin\Helpers; @@ -8,6 +8,7 @@ use Plugin\Helpers;
8 use Plugin\Images; 8 use Plugin\Images;
9 use Plugin\UdpLog; 9 use Plugin\UdpLog;
10 10
  11 +
11 /** 12 /**
12 * 13 *
13 * @name CartModel 14 * @name CartModel
@@ -731,12 +732,15 @@ class CartModel @@ -731,12 +732,15 @@ class CartModel
731 $result = array('code' => 400, 'message' => '出错啦'); 732 $result = array('code' => 400, 'message' => '出错啦');
732 733
733 if (empty($addressId)) { 734 if (empty($addressId)) {
  735 + UdpLog::info('【结算信息】配送地址参数校验','addressId为空');
734 $result['code'] = 401; 736 $result['code'] = 401;
735 $result['message'] = '配送地址不能为空'; 737 $result['message'] = '配送地址不能为空';
736 } elseif (empty($deliveryTime)) { 738 } elseif (empty($deliveryTime)) {
  739 + UdpLog::info('【结算信息】配送时间参数校验','deliveryTime为空');
737 $result['code'] = 402; 740 $result['code'] = 402;
738 $result['message'] = '请选择配送时间'; 741 $result['message'] = '请选择配送时间';
739 } elseif (empty($deliveryWay)) { 742 } elseif (empty($deliveryWay)) {
  743 + UdpLog::info('【结算信息】配送方式参数参数校验','deliveryTime为空');
740 $result['code'] = 403; 744 $result['code'] = 403;
741 $result['message'] = '请选择配送方式'; 745 $result['message'] = '请选择配送方式';
742 } else { 746 } else {
@@ -8,6 +8,7 @@ use LibModels\Wap\Home\UserData; @@ -8,6 +8,7 @@ use LibModels\Wap\Home\UserData;
8 use Plugin\Cache; 8 use Plugin\Cache;
9 use Plugin\Helpers; 9 use Plugin\Helpers;
10 use Plugin\Images; 10 use Plugin\Images;
  11 +use Plugin\UdpLog;
11 12
12 /** 13 /**
13 * 14 *
@@ -590,6 +591,7 @@ class UserModel @@ -590,6 +591,7 @@ class UserModel
590 591
591 // 处理地址数据 592 // 处理地址数据
592 if (isset($address['data']) && !empty($address['data'])) { 593 if (isset($address['data']) && !empty($address['data'])) {
  594 + UdpLog::info('地址数据校验','uid'.$uid.'返回:'.json_encode($address));
593 $result = $address['data']; 595 $result = $address['data'];
594 } 596 }
595 597
@@ -6,6 +6,7 @@ use Index\CartModel; @@ -6,6 +6,7 @@ use Index\CartModel;
6 use Index\UserModel; 6 use Index\UserModel;
7 use Plugin\Helpers; 7 use Plugin\Helpers;
8 use Plugin\UnionTrans; 8 use Plugin\UnionTrans;
  9 +use Plugin\UdpLog;
9 10
10 /** 11 /**
11 * 购物车相关的控制器 12 * 购物车相关的控制器
@@ -465,6 +466,7 @@ class IndexController extends AbstractAction @@ -465,6 +466,7 @@ class IndexController extends AbstractAction
465 . ',deliveryWay:' . $deliveryWay . 'invoiceTitle:' . $invoiceTitle . ',invoiceId:' . $invoiceId . ',yohoCoin:' . $yohoCoin 466 . ',deliveryWay:' . $deliveryWay . 'invoiceTitle:' . $invoiceTitle . ',invoiceId:' . $invoiceId . ',yohoCoin:' . $yohoCoin
466 . ',paymentId:' . $paymentId . ',paymentType:' . $paymentType . ',remark:' . $remark . ',couponCode:' . $couponCode . "\n"; 467 . ',paymentId:' . $paymentId . ',paymentType:' . $paymentType . ',remark:' . $remark . ',couponCode:' . $couponCode . "\n";
467 error_log($message, 3, '/Data/logs/php/h5_error/order.' . date('Ym') . '.log'); 468 error_log($message, 3, '/Data/logs/php/h5_error/order.' . date('Ym') . '.log');
  469 + UdpLog::info('【下单】下单异常数据','message:'.$message,'返回:'.json_encode($result));
468 } 470 }
469 // 返回数据 471 // 返回数据
470 else { 472 else {
@@ -10,6 +10,7 @@ use Plugin\Pay\weixin\lib\WxPayApi; @@ -10,6 +10,7 @@ use Plugin\Pay\weixin\lib\WxPayApi;
10 use Plugin\Pay\weixin\lib\WxPayConfig; 10 use Plugin\Pay\weixin\lib\WxPayConfig;
11 use Plugin\Pay\aliwap\AliwapReqparams; 11 use Plugin\Pay\aliwap\AliwapReqparams;
12 use Plugin\Pay\aliwap\AliwapService; 12 use Plugin\Pay\aliwap\AliwapService;
  13 +use Plugin\UdpLog;
13 14
14 /** 15 /**
15 * 支付相关的控制器 16 * 支付相关的控制器
@@ -33,12 +34,14 @@ class PayController extends AbstractAction @@ -33,12 +34,14 @@ class PayController extends AbstractAction
33 /* 判断是否有订单号参数 */ 34 /* 判断是否有订单号参数 */
34 $orderCode = $this->get('order_code'); 35 $orderCode = $this->get('order_code');
35 if (empty($orderCode)) { 36 if (empty($orderCode)) {
  37 + UdpLog::info('【支付宝支付】参数校验', 'orderCode为空');
36 break; 38 break;
37 } 39 }
38 40
39 /* 判断用户是否登录 */ 41 /* 判断用户是否登录 */
40 $uid = $this->getUid(true); 42 $uid = $this->getUid(true);
41 if (!$uid) { 43 if (!$uid) {
  44 + UdpLog::info('【支付宝支付】参数校验', 'uid为空');
42 $this->go( Helpers::url('/signin.html', array('refer' => $this->_request->server('HTTP_REFERER'))) ); 45 $this->go( Helpers::url('/signin.html', array('refer' => $this->_request->server('HTTP_REFERER'))) );
43 break; 46 break;
44 } 47 }
@@ -46,6 +49,7 @@ class PayController extends AbstractAction @@ -46,6 +49,7 @@ class PayController extends AbstractAction
46 /* 判断订单信息是否存在 */ 49 /* 判断订单信息是否存在 */
47 $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession); 50 $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
48 if (empty($orderDetail['data'])) { 51 if (empty($orderDetail['data'])) {
  52 + UdpLog::info('【支付宝支付】校验订单信息', 'orderCode:'.$orderCode.'uid:'.$uid.'返回:'.json_encode($orderDetail));
49 $this->helpJsRedirect('没有找到该订单'); 53 $this->helpJsRedirect('没有找到该订单');
50 break; 54 break;
51 } 55 }
@@ -61,6 +65,7 @@ class PayController extends AbstractAction @@ -61,6 +65,7 @@ class PayController extends AbstractAction
61 $aliwapService = new AliwapService(); 65 $aliwapService = new AliwapService();
62 $payRequestPars = $aliwapService->getPayRequestPars($reqParams); 66 $payRequestPars = $aliwapService->getPayRequestPars($reqParams);
63 if (empty($payRequestPars)) { 67 if (empty($payRequestPars)) {
  68 + UdpLog::info('【支付宝支付】提交支付宝端口无响应', 'orderCode:'.$orderCode.'totalFee:'.$totalFee.'createTime:'.$orderDetail['data']['create_time']);
64 $this->helpJsRedirect('支付系统繁忙,请稍后再试'); 69 $this->helpJsRedirect('支付系统繁忙,请稍后再试');
65 break; 70 break;
66 } 71 }
@@ -93,23 +98,27 @@ class PayController extends AbstractAction @@ -93,23 +98,27 @@ class PayController extends AbstractAction
93 98
94 $uid = $this->getUid(true); 99 $uid = $this->getUid(true);
95 if (!$uid) { 100 if (!$uid) {
  101 + UdpLog::info('【wechat支付】参数校验', 'uid为空');
96 break; 102 break;
97 } 103 }
98 104
99 $orderCode = $this->get('order_code'); 105 $orderCode = $this->get('order_code');
100 if (empty($orderCode)) { 106 if (empty($orderCode)) {
  107 + UdpLog::info('【wechat支付】参数校验', 'orderCode为空');
101 break; 108 break;
102 } 109 }
103 110
104 /* 判断订单信息不存在 */ 111 /* 判断订单信息不存在 */
105 $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession); 112 $orderDetail = OrderData::viewOrderData($orderCode, $uid, $this->_usession);
106 if (empty($orderDetail['data'])) { 113 if (empty($orderDetail['data'])) {
  114 + UdpLog::info('【wechat支付】校验订单信息', 'orderCode:'.$orderCode.'uid:'.$uid.'返回:'.json_encode($orderDetail));
107 break; 115 break;
108 } 116 }
109 117
110 $totalFee = strval($orderDetail['data']['payment_amount'] * 100); 118 $totalFee = strval($orderDetail['data']['payment_amount'] * 100);
111 $openId = $this->getSession('weixinOpenId'); 119 $openId = $this->getSession('weixinOpenId');
112 if (empty($openId)) { 120 if (empty($openId)) {
  121 + UdpLog::info('【wechat支付】获取wechat标识为空', 'orderCode:'.$orderCode.'uid:'.$uid.'返回openId:'.$openId);
113 break; 122 break;
114 } 123 }
115 124
@@ -149,6 +158,7 @@ class PayController extends AbstractAction @@ -149,6 +158,7 @@ class PayController extends AbstractAction
149 $payment = $this->get('payment',0); 158 $payment = $this->get('payment',0);
150 159
151 if (!$uid || !$orderCode || !$payment) { 160 if (!$uid || !$orderCode || !$payment) {
  161 + UdpLog::info('【支付时间校验】参数校验', 'orderCode:'.$orderCode.'uid:'.$uid.'payment:'.$payment);
152 break; 162 break;
153 } 163 }
154 164