예제 #1
0
파일: o2o.php 프로젝트: jin123456bat/home
 /**
  * o2o统计
  */
 function statistics()
 {
     if (login::o2o()) {
         $timetype = empty($this->get->timetype) ? 'day' : $this->get->timetype;
         if (!in_array($timetype, array('day', 'week', 'month'))) {
             return new json(json::PARAMETER_ERROR, '日期范围错误');
         }
         switch ($timetype) {
             case 'day':
                 $time = $_SERVER['REQUEST_TIME'] - 24 * 3600;
                 break;
             case 'week':
                 $time = $_SERVER['REQUEST_TIME'] - 7 * 24 * 3600;
                 break;
             case 'month':
                 $time = $_SERVER['REQUEST_TIME'] - 30 * 24 * 3600;
                 break;
             default:
                 $time = $_SERVER['REQUEST_TIME'];
                 break;
         }
         $userModel = $this->model('user');
         $o2oModel = $this->model('o2ouser');
         $rate = $o2oModel->get($this->session->id, 'rate');
         //$status = array(orderlistModel::STATUS_CLOSE,orderlistModel::STATUS_REFUND,orderlistModel::STATUS_QUITE,orderlistModel::STATUS_PAYING);
         $status = array(0, 2, 3, 7);
         if ($this->get->form == 1) {
             $userModel->where('user.oid=?', array($this->session->id));
             $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id');
             $userModel->table('orderdetail', 'left join', 'orderdetail.oid=orderlist.id');
             $userModel->where('orderlist.status not in (?)', $status);
             $userModel->where('orderlist.tradetime>?', array($time));
             $sale = $userModel->select('sum(orderdetail.num)');
             $result['sale'] = number_format($sale[0]['sum(orderdetail.num)']);
             $userModel->where('user.oid=?', array($this->session->id));
             $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id');
             $userModel->where('orderlist.status not in (?)', $status);
             $userModel->where('orderlist.tradetime>?', array($time));
             $revenue = $userModel->select('sum(orderlist.ordertotalamount)');
             $result['revenue'] = number_format($revenue[0]['sum(orderlist.ordertotalamount)'] * $rate, 2);
             $userModel->where('user.oid=?', array($this->session->id));
             $usernum = $userModel->select('count(id)');
             $userModel->where('user.regtime>?', array($time));
             $result['usernum'] = number_format($usernum[0]['count(id)']);
             $userModel->where('user.oid=?', array($this->session->id));
             $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id');
             $userModel->where('orderlist.status not in (?)', $status);
             $userModel->where('orderlist.createtime>?', array($time));
             $ordernum = $userModel->select('count(orderlist.id)');
             $result['ordernum'] = number_format($ordernum[0]['count(orderlist.id)']);
             $temp = array();
             if ($this->get->timetype == 'month') {
                 for ($i = 0; $i < 6; $i++) {
                     $obj = array();
                     $year = date("Y");
                     //echo $year;
                     $month = date("m");
                     $day = date("d");
                     if ($month - $i < 1) {
                         $month += 12;
                         $year--;
                     }
                     $starttime = strtotime($year . '-' . ($month - $i) . '-1 0:0:0');
                     $obj['period'] = $month - $i . '月';
                     //$endtime = strtotime($year.'-'.$month.'-1 0:0:0');
                     $endtime = strtotime('+1 month', $starttime);
                     //echo date("Y-m-d H:i:s",$starttime).'=>';
                     //echo date("Y-m-d H:i:s",$endtime).'<br>';
                     $userModel->where('user.oid=?', array($this->session->id));
                     $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id');
                     $userModel->table('orderdetail', 'left join', 'orderdetail.oid=orderlist.id');
                     $userModel->where('orderlist.status not in (?)', $status);
                     $userModel->where('orderlist.tradetime>? and orderlist.tradetime<?', array($starttime, $endtime));
                     $sale = $userModel->select('sum(orderdetail.num)');
                     $obj['sales'] = number_format($sale[0]['sum(orderdetail.num)']);
                     $userModel->where('user.oid=?', array($this->session->id));
                     $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id');
                     $userModel->where('orderlist.status not in (?)', $status);
                     $userModel->where('orderlist.tradetime>? and orderlist.tradetime<?', array($starttime, $endtime));
                     $revenue = $userModel->select('sum(orderlist.ordertotalamount)');
                     $obj['profit'] = number_format($revenue[0]['sum(orderlist.ordertotalamount)'] * $rate, 2);
                     $temp[] = $obj;
                 }
             }
             $result['detail'] = $temp;
         } else {
             if ($this->get->form == 2) {
                 $userModel->where('user.oid=?', array($this->session->id));
                 $userModel->table('user_login_log', 'left join', 'user.id=user_login_log.uid');
                 $userModel->where('user_login_log.time>?', array($time));
                 $logintimes = $userModel->select('count(user_login_log.id)');
                 $result['logintimes'] = number_format($logintimes[0]['count(user_login_log.id)']);
                 $userModel->where('user.oid=?', array($this->session->id));
                 $userModel->where('user.regtime>?', array($time));
                 $newuser = $userModel->select('count(id)');
                 $result['newuser'] = number_format($newuser[0]['count(id)']);
                 $userModel->where('user.oid=?', array($this->session->id));
                 $userModel->table('orderlist', 'left join', 'orderlist.uid=user.id');
                 $userModel->where('orderlist.status not in (?)', $status);
                 $userModel->groupby('user.id');
                 $parameter = 'user.id,user.username,user.gravatar,user.telephone,sum(orderlist.ordertotalamount) as sum,count(orderlist.id) as count,avg(orderlist.ordertotalamount) as avg';
                 $result['detail'] = $userModel->select($parameter);
                 foreach ($result['detail'] as &$value) {
                     $value['gravatar'] = file::realpathToUrl($value['gravatar']);
                 }
             }
         }
         return new json(json::OK, NULL, $result);
     }
     return new json(json::NOT_LOGIN);
 }
예제 #2
0
 /**
  * 映射
  * @param unknown $name
  * @param unknown $args
  */
 function __call($name, $args)
 {
     if (!empty($args)) {
         return $this->call('index', '__404');
     }
     if ($name != 'login') {
         if (!login::o2o()) {
             $this->response->setCode(302);
             $this->response->addHeader('Location', $this->http->url('o2ocenter', 'login'));
             return false;
         }
     }
     $action = array('index', 'search', 'profile');
     $template = $this->_template_dir . $name . '.html';
     $http = http::getInstance();
     $base_template = ROOT . '/application/template/' . $template;
     if (file_exists($base_template)) {
         $this->view = new view($this->_config, $template);
         if (in_array($name, $action)) {
             //加载系统配置
             $systemModel = $this->model('system');
             $system = $systemModel->fetch(array('system'));
             $temp = array();
             foreach ($system as $key => $value) {
                 $temp[$value['name'] . '_' . $value['type']] = $value['value'];
             }
             $this->view->assign('system', $temp);
             //载入用户的o2o配置
             $o2oModel = $this->model('o2ouser');
             $o2o = $o2oModel->get($this->session->id);
             if (empty($o2o)) {
                 return $this->call('index', '__404');
             }
             //载入用户的基本信息
             $userModel = $this->model('user');
             $user = $userModel->get($this->session->id);
             $this->view->assign('user', $user);
             switch ($name) {
                 case 'search':
                     $start = empty(filter::int($this->get->start)) ? 0 : filter::int($this->get->start);
                     $length = empty(filter::int($this->get->length)) ? 10 : filter::int($this->get->length);
                     $this->view->assign('start', $start);
                     $this->view->assign('length', $length);
                     $query = str_replace(' ', '%', str_replace('  ', ' ', $this->get->query));
                     $userModel = $this->model('user');
                     $userModel->where('user.oid=?', array($this->session->id));
                     if (!empty($query)) {
                         $userModel->where('(username like ? or telephone like ? or email like ?)', array('%' . $query . '%', '%' . $query . '%', '%' . $query . '%'));
                     }
                     $userModel->limit($start, $length);
                     $search = $userModel->select();
                     $this->view->assign('search', $search);
                     break;
                 default:
             }
             $this->view->assign('o2o', $o2o);
         }
         return $this->view->display();
     } else {
         return $this->call('index', '__404');
     }
 }