Core.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. $log += Dever::input();
  33. $url = Dever::url();
  34. $log['uid'] = $uid;
  35. $log['source_id'] = $source_id;
  36. $log['url'] = $url;
  37. $log['ip'] = Dever::ip();
  38. Dever::log($log, $this->key . '/' . $source_id . '/' . $type);
  39. return true;
  40. }
  41. public function get($day, $type, $source_id, $start = 0, $end = 0)
  42. {
  43. $log = Dever::getLog($day, $this->key . '/' . $source_id . '/' . $type);
  44. $source = array();
  45. $source['pv'] = 0;
  46. $source['uv'] = 0;
  47. $source['user_num'] = 0;
  48. $source['user_yes_num'] = 0;
  49. if ($log) {
  50. $result = array();
  51. $pv = $uv = 0;
  52. $user = array();
  53. foreach ($log as $k => $v) {
  54. if ($v) {
  55. $temp = explode('dever&', $v);
  56. $info = explode(' ', $temp[0]);
  57. $result[$k]['time'] = $info[0];
  58. $result[$k]['project'] = $info[1];
  59. $result[$k]['app'] = $info[2];
  60. parse_str($temp[1], $result[$k]['param']);
  61. $pv++;
  62. if (isset($result[$k]['param']['uid']) && $result[$k]['param']['uid'] > 0) {
  63. $user[$result[$k]['param']['uid']] = 1;
  64. } else {
  65. $user[$result[$k]['param']['ip']] = 1;
  66. }
  67. }
  68. }
  69. $source['pv'] = $pv;
  70. $source['uv'] = count($user);
  71. if ($start && $end) {
  72. $where['source_id'] = $source_id;
  73. $where['start'] = $start;
  74. $where['end'] = $end;
  75. $source['user_num'] = Dever::db('source/user')->getTotal($where);
  76. $source['user_yes_num'] = $source['user_num'];
  77. }
  78. }
  79. return $source;
  80. }
  81. }