1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- <?php
- namespace User\Lib;
- use Dever;
- class Stat
- {
- # 获取用户每日新增数量
- public function cron_api(){}
- public function cron()
- {
- $num = Dever::input('num', 1);
- $start = Dever::input('start', date('Y-m-d', strtotime('-'.$num.' day')));
- $end = Dever::input('end', date('Y-m-d'));
- $start = Dever::maketime($start . ' 00:00:00');
- $end = Dever::maketime($end . ' 23:59:59');
- $day = intval(($end - $start)/86400);
- for($i=0; $i<=$day; $i++) {
- $where['start'] = $start + 86400*$i;
- $where['end'] = $start + 86400*$i + 86399;
- $num = Dever::db('user/info')->getNum($where);
- if ($num <= 0) {
- continue;
- }
- $data = array();
- $data['day'] = $where['start'];
- $info = Dever::db('user/stat')->find($data);
- $data['user'] = $num;
- $order = Dever::config('base')->passport_stat_order;
- if ($order) {
- $order = Dever::load($order, $where);
- $data['order_user'] = $order;
- }
- $data['qoq'] = 0;
-
- if (!$info) {
- Dever::db('user/stat')->insert($data);
- } else {
- $data['where_id'] = $info['id'];
- Dever::db('user/stat')->update($data);
- }
- }
- }
- # 获取环比增长
- public function qoq($user, $day)
- {
- $where = array('day' => Dever::maketime($day));
- $search = Dever::search_button();
- if ($search) {
- $where['config']['group'] = $search[0];
- $where['config']['col'] = str_replace('|id', '', $search[1]);
- }
- $prev = Dever::db('user/stat')->prev($where);
- if ($prev) {
- $qoq = round(($user-$prev['user'])/$prev['user'], 2)*100;
- } else {
- $qoq = 0;
- }
- return $qoq . '%';
- }
- }
|