Core.php 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace Source\Lib;
  3. use Dever;
  4. class Core
  5. {
  6. private $key = 'source';
  7. /**
  8. * 记录用户信息
  9. *
  10. * @return mixed
  11. */
  12. public function saveUser($vid, $uid, $source_id, $account_type, $account_id)
  13. {
  14. $data['vid'] = $vid;
  15. $data['uid'] = $uid;
  16. $data['source_id'] = $source_id;
  17. $data['account_type'] = $account_type;
  18. $data['account_id'] = $account_id;
  19. $info = Dever::db('source/user')->one($data);
  20. if (!$info) {
  21. Dever::db('source/user')->insert($data);
  22. }
  23. return true;
  24. }
  25. /**
  26. * 日志记录
  27. *
  28. * @return mixed
  29. */
  30. public function save($uid, $type, $source_id, $log = array())
  31. {
  32. return;
  33. $log += Dever::input();
  34. $url = Dever::url();
  35. $log['uid'] = $uid;
  36. $log['source_id'] = $source_id;
  37. $log['url'] = $url;
  38. $log['ip'] = Dever::ip();
  39. Dever::log($log, $this->key . '/' . $source_id . '/' . $type);
  40. return true;
  41. }
  42. public function get($day, $type, $source_id, $start = 0, $end = 0)
  43. {
  44. $log = Dever::getLog($day, $this->key . '/' . $source_id . '/' . $type);
  45. $source = array();
  46. $source['pv'] = 0;
  47. $source['uv'] = 0;
  48. $source['user_num'] = 0;
  49. $source['user_yes_num'] = 0;
  50. if ($log) {
  51. $result = array();
  52. $pv = $uv = 0;
  53. $user = array();
  54. foreach ($log as $k => $v) {
  55. if ($v) {
  56. $temp = explode('dever&', $v);
  57. $info = explode(' ', $temp[0]);
  58. $result[$k]['time'] = $info[0];
  59. $result[$k]['project'] = $info[1];
  60. $result[$k]['app'] = $info[2];
  61. parse_str($temp[1], $result[$k]['param']);
  62. $pv++;
  63. if (isset($result[$k]['param']['uid']) && $result[$k]['param']['uid'] > 0) {
  64. $user[$result[$k]['param']['uid']] = 1;
  65. } else {
  66. $user[$result[$k]['param']['ip']] = 1;
  67. }
  68. }
  69. }
  70. $source['pv'] = $pv;
  71. $source['uv'] = count($user);
  72. if ($start && $end) {
  73. $where['source_id'] = $source_id;
  74. $where['start'] = $start;
  75. $where['end'] = $end;
  76. $source['user_num'] = Dever::db('source/user')->getTotal($where);
  77. $source['user_yes_num'] = $source['user_num'];
  78. }
  79. }
  80. return $source;
  81. }
  82. }