report.php 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <?php
  2. defined('IN_WEB') or die( 'Include Error!');
  3. /**
  4. * 日记事件上报
  5. */
  6. class ModelReport {
  7. /**
  8. * 客户端日记
  9. * @return string
  10. * Created by: hss
  11. * Created on: 2020/3/27 20:05
  12. */
  13. public function clientlog($data = "",$uid = 0){
  14. $month = date('Ym');
  15. $tb = otable::clientlog($month);
  16. if(empty($data)){
  17. $isTB = oo::commonOprRedis('Statistics')->get(okeys::clientlog());
  18. if(empty($isTB)){
  19. //判断表是否存在
  20. $database = oo::$config['dbindex'] . "api_statistics";
  21. $sql = "select count(*) as count from information_schema.TABLES t where t.TABLE_SCHEMA ='{$database}' and t.TABLE_NAME ='t_clientlog_{$month}'";
  22. $ret = oo::commonOprDb('statistics')->getOne($sql,1);
  23. if(empty($ret['count'])){
  24. $sql = "CREATE TABLE {$tb} (
  25. `id` int(11) NOT NULL AUTO_INCREMENT,
  26. `uid` int(11) NULL DEFAULT 0,
  27. `time` int(11) NULL DEFAULT 0,
  28. `filename` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT '',
  29. PRIMARY KEY (`id`) USING BTREE
  30. ) ENGINE = InnoDB AUTO_INCREMENT = 1 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci ROW_FORMAT = Dynamic;";
  31. $rs = oo::commonOprDb('statistics')->query($sql);
  32. if($rs){
  33. oo::commonOprRedis('Statistics')->setex(okeys::clientlog(),1,oo::redisRandomExpire(86400));
  34. }
  35. }else{
  36. oo::commonOprRedis('Statistics')->setex(okeys::clientlog(),1,oo::redisRandomExpire(86400));
  37. }
  38. }
  39. }else{
  40. $time = time();
  41. $filename = $uid."_".date("Ymd")."_".substr(time(),-5,5).'.log';
  42. $filepath = 'clientLog/'.date("Ymd").'/'.$uid.'/';
  43. $ret = oo::logs()->debug4($data,$filename,$filepath);
  44. if($ret){
  45. //插入数据库
  46. $sql = "INSERT INTO {$tb} (uid,time,filename) VALUES (";
  47. $sql .= "'{$uid}','{$time}','{$filename}')";
  48. $rs = oo::commonOprDb('statistics')->query($sql);
  49. }
  50. return $ret;
  51. }
  52. }
  53. /**
  54. * 支付上报
  55. * @return string
  56. * Created by: hss
  57. * Created on: 2020/6/11 10:11
  58. */
  59. public function payReport($sid = 1,$gid = "",$event_id = 10008){
  60. oo::commonOprRedis('Statistics')->hIncrBy(okeys::payReport($sid,$event_id),$gid,1);
  61. }
  62. }