Stat.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. <?php
  2. namespace User\Lib;
  3. use Dever;
  4. class Stat
  5. {
  6. # 获取用户每日新增数量
  7. public function cron_api(){}
  8. public function cron()
  9. {
  10. $num = Dever::input('num', 1);
  11. $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
  12. $end = Dever::input('end', date('Y-m-d'));
  13. $start = Dever::maketime($start . ' 00:00:00');
  14. $end = Dever::maketime($end . ' 23:59:59');
  15. $day = intval(($end - $start)/86400);
  16. for($i=0; $i<=$day; $i++) {
  17. $where['start'] = $start + 86400*$i;
  18. $where['end'] = $start + 86400*$i + 86399;
  19. $num = Dever::db('user/info')->getNum($where);
  20. if ($num <= 0) {
  21. continue;
  22. }
  23. $data = array();
  24. $data['day'] = $where['start'];
  25. $info = Dever::db('user/stat')->find($data);
  26. $data['user'] = $num;
  27. $order = Dever::config('base')->passport_stat_order;
  28. if ($order) {
  29. $order = Dever::load($order, $where);
  30. $data['order_user'] = $order;
  31. }
  32. $data['qoq'] = 0;
  33. if (!$info) {
  34. Dever::db('user/stat')->insert($data);
  35. } else {
  36. $data['where_id'] = $info['id'];
  37. Dever::db('user/stat')->update($data);
  38. }
  39. }
  40. }
  41. # 获取环比增长
  42. public function qoq($user, $day)
  43. {
  44. $where = array('day' => Dever::maketime($day));
  45. $search = Dever::search_button();
  46. if ($search) {
  47. $where['config']['group'] = $search[0];
  48. $where['config']['col'] = str_replace('|id', '', $search[1]);
  49. }
  50. $prev = Dever::db('user/stat')->prev($where);
  51. if ($prev) {
  52. $qoq = round(($user-$prev['user'])/$prev['user'], 2)*100;
  53. } else {
  54. $qoq = 0;
  55. }
  56. return $qoq . '%';
  57. }
  58. }