Exemplo n.º 1
0
	/**
	 * 行业排行
	 */
	public function hotOp(){
	    $datanum = 30;
	    if(!$this->search_arr['search_type']){
			$this->search_arr['search_type'] = 'day';
		}
		$model = Model('stat');
		//获得搜索的开始时间和结束时间
		$searchtime_arr = $model->getStarttimeAndEndtime($this->search_arr);
		$where = array();
		$where['order_isvalid'] = 1;//计入统计的有效订单
		$where['order_add_time'] = array('between',$searchtime_arr);
		$where['store_id'] = array('neq',$_SESSION['store_id']);
		$gc_id_depth = $this->gc_arr[$this->choose_gcid]['depth'];
		if ($this->choose_gcid > 0){
		    $where['gc_parentid_'.$gc_id_depth] = $this->choose_gcid;
		}
		/**
		 * 商品排行
		 */
		$goods_stat_arr = array();
	    //构造横轴数据
		for($i=1; $i<=$datanum; $i++){
		    //数据
		    $goods_stat_arr['series'][0]['data'][] = array('name'=>'','y'=>0);
			//横轴
			$goods_stat_arr['xAxis']['categories'][] = "$i";
		}
        $field = 'goods_id,goods_name,SUM(goods_num) as goodsnum';
		$goods_list = $model->statByStatordergoods($where, $field, 0, $datanum, 'goodsnum desc,goods_id asc', 'goods_id');
		foreach ((array)$goods_list as $k=>$v){
		    $goods_stat_arr['series'][0]['data'][$k] = array('name'=>strval($v['goods_name']),'y'=>floatval($v['goodsnum']));
		}
		//得到统计图数据
		$goods_stat_arr['series'][0]['name'] = '下单商品数';
		$goods_stat_arr['title'] = "行业商品{$datanum}强";
		$goods_stat_arr['legend']['enabled'] = false;
        $goods_stat_arr['yAxis'] = '下单商品数';
		$goods_statjson = getStatData_Column2D($goods_stat_arr);

		Tpl::output('goods_statjson',$goods_statjson);
		Tpl::output('goods_list',$goods_list);
        self::profile_menu('hot');
        Tpl::showpage('stat.industry.hot');
	}
Exemplo n.º 2
0
	/**
	 * 商品流量统计
	 */
    public function goodsflowOp() {
        $store_id = intval($_SESSION['store_id']);
        //确定统计分表名称
		$last_num = $store_id % 10; //获取店铺ID的末位数字
		$tablenum = ($t = intval(C('flowstat_tablenum'))) > 1 ? $t : 1; //处理流量统计记录表数量
		$flow_tablename = ($t = ($last_num % $tablenum)) > 0 ? "flowstat_$t" : 'flowstat';
		if(!$this->search_arr['search_type']){
			$this->search_arr['search_type'] = 'week';
		}
        $model = Model('stat');
        //获得搜索的开始时间和结束时间
		$searchtime_arr = $model->getStarttimeAndEndtime($this->search_arr);
		$where = array();
		$where['store_id'] = $store_id;
		$where['stattime'] = array('between',$searchtime_arr);
		$where['type'] = 'goods';

		$field = ' goods_id,SUM(clicknum) as amount';
		$stat_arr = array();
        //构造横轴数据
        for($i=1; $i<=30; $i++){
			//横轴
			$stat_arr['xAxis']['categories'][] = $i;
			$stat_arr['series'][0]['data'][] = array('name'=>'','y'=>0);
		}
		$statlist_tmp = $model->statByFlowstat($flow_tablename, $where, $field, 0, 30, 'amount desc,goods_id asc', 'goods_id');
		if ($statlist_tmp){
		    $goodsid_arr = array();
    	    foreach((array)$statlist_tmp as $k=>$v){
    	        $goodsid_arr[] = $v['goods_id'];
    		}
    		//查询相应商品
		    $goods_list_tmp = $model->statByGoods(array('goods_id'=>array('in',$goodsid_arr)), $field = 'goods_name,goods_id');
		    foreach ((array)$goods_list_tmp as $k=>$v){
		        $goods_list[$v['goods_id']] = $v;
		    }
		    foreach((array)$statlist_tmp as $k=>$v){
		        $v['goods_name'] = $goods_list[$v['goods_id']];
		        $v['amount'] = floatval($v['amount']);
		        $statlist[] = $v;
		        $stat_arr['series'][0]['data'][$k] = array('name'=>strval($goods_list[$v['goods_id']]['goods_name']),'y'=>floatval($v['amount']));
		    }
		}
        //得到统计图数据
		$stat_arr['legend']['enabled'] = false;
		$stat_arr['series'][0]['name'] = '访问量';
		$stat_arr['title'] = '商品访问量TOP30';
        $stat_arr['yAxis'] = '访问次数';
		$stat_json = getStatData_Column2D($stat_arr);
        Tpl::output('stat_json',$stat_json);
		self::profile_menu('goodsflow');
		Tpl::showpage('stat.flow.goods');
	}
Exemplo n.º 3
0
	/**
	 * 热卖商品
	 */
	public function hotgoodsOp(){
	    $topnum = 30;

	    if(!$this->search_arr['search_type']){
			$this->search_arr['search_type'] = 'day';
		}
		$model = Model('stat');
		//获得搜索的开始时间和结束时间
		$searchtime_arr = $model->getStarttimeAndEndtime($this->search_arr);
		$model = Model('stat');
		$where = array();
		$where['store_id'] = $_SESSION['store_id'];
		$where['order_isvalid'] = 1;//计入统计的有效订单
		$where['order_add_time'] = array('between',$searchtime_arr);

		//查询销量top
	    //构造横轴数据
		for($i=1; $i<=$topnum; $i++){
		    //数据
		    $stat_arr['series'][0]['data'][] = array('name'=>'','y'=>0);
			//横轴
			$stat_arr['xAxis']['categories'][] = "$i";
		}
		$field = ' goods_id,goods_name,SUM(goods_num) as goodsnum ';
		$orderby = 'goodsnum desc,goods_id';
		$statlist = array();
		$statlist['goodsnum'] = $model->statByStatordergoods($where, $field, 0, $topnum, $orderby, 'goods_id');
		foreach ((array)$statlist['goodsnum'] as $k=>$v){
		    $stat_arr['series'][0]['data'][$k] = array('name'=>strval($v['goods_name']),'y'=>intval($v['goodsnum']));
		}
		$stat_arr['series'][0]['name'] = '下单商品数';
		$stat_arr['legend']['enabled'] = false;
		//得到统计图数据
		$stat_arr['title'] = '热卖商品TOP'.$topnum;
        $stat_arr['yAxis'] = '下单商品数';
		$stat_json['goodsnum'] = getStatData_Column2D($stat_arr);
		unset($stat_arr);


		//查询下单金额top
		//构造横轴数据
		for($i=1; $i<=$topnum; $i++){
		    //数据
		    $stat_arr['series'][0]['data'][] = array('name'=>'','y'=>0);
			//横轴
			$stat_arr['xAxis']['categories'][] = "$i";
		}
		$field = ' goods_id,goods_name,SUM(goods_pay_price) as orderamount ';
		$orderby = 'orderamount desc,goods_id';
		$statlist['orderamount'] = $model->statByStatordergoods($where, $field, 0, $topnum, $orderby, 'goods_id');
		foreach ((array)$statlist['orderamount'] as $k=>$v){
		    $stat_arr['series'][0]['data'][$k] = array('name'=>strval($v['goods_name']),'y'=>floatval($v['orderamount']));
		}
		$stat_arr['series'][0]['name'] = '下单金额';
		$stat_arr['legend']['enabled'] = false;
		//得到统计图数据
		$stat_arr['title'] = '热卖商品TOP'.$topnum;
        $stat_arr['yAxis'] = '下单金额';
		$stat_json['orderamount'] = getStatData_Column2D($stat_arr);
		Tpl::output('stat_json',$stat_json);
		Tpl::output('statlist',$statlist);
	    self::profile_menu('hotgoods');
	    Tpl::showpage('stat.goods.hotgoods');
	}
Exemplo n.º 4
0
 /**
  * 行业排行
  */
 public function rankOp()
 {
     if (!$this->search_arr['search_type']) {
         $this->search_arr['search_type'] = 'day';
     }
     $model = Model('stat');
     //获得搜索的开始时间和结束时间
     $searchtime_arr = $model->getStarttimeAndEndtime($this->search_arr);
     $where = array();
     $where['order_isvalid'] = 1;
     //计入统计的有效订单
     $where['order_add_time'] = array('between', $searchtime_arr);
     $gc_id_depth = $this->gc_arr[$this->choose_gcid]['depth'];
     if ($this->choose_gcid > 0) {
         $where['gc_parentid_' . $gc_id_depth] = $this->choose_gcid;
     }
     /**
      * 商品排行
      */
     $goods_stat_arr = array();
     //构造横轴数据
     for ($i = 1; $i <= 50; $i++) {
         //数据
         $goods_stat_arr['series'][0]['data'][] = array('name' => '', 'y' => 0);
         //横轴
         $goods_stat_arr['xAxis']['categories'][] = "{$i}";
     }
     $field = 'goods_id,goods_name,SUM(goods_num) as goodsnum';
     $goods_list = $model->statByStatordergoods($where, $field, 0, 50, 'goodsnum desc,goods_id asc', 'goods_id');
     foreach ((array) $goods_list as $k => $v) {
         $goods_stat_arr['series'][0]['data'][$k] = array('name' => strval($v['goods_name']), 'y' => floatval($v['goodsnum']));
     }
     //得到统计图数据
     $goods_stat_arr['series'][0]['name'] = '下单商品数';
     $goods_stat_arr['title'] = "行业商品50强";
     $goods_stat_arr['legend']['enabled'] = false;
     $goods_stat_arr['yAxis'] = '下单商品数';
     $goods_statjson = getStatData_Column2D($goods_stat_arr);
     /**
      * 店铺排行
      */
     $store_stat_arr = array();
     //构造横轴数据
     for ($i = 1; $i <= 30; $i++) {
         //数据
         $store_stat_arr['series'][0]['data'][] = array('name' => '', 'y' => 0);
         //横轴
         $store_stat_arr['xAxis']['categories'][] = "{$i}";
     }
     $field = 'store_id,store_name,COUNT(DISTINCT order_id) as ordernum';
     $store_list = $model->statByStatordergoods($where, $field, 0, 30, 'ordernum desc,store_id asc', 'store_id');
     foreach ((array) $store_list as $k => $v) {
         $store_stat_arr['series'][0]['data'][$k] = array('name' => strval($v['store_name']), 'y' => floatval($v['ordernum']));
     }
     //得到统计图数据
     $store_stat_arr['series'][0]['name'] = '下单量';
     $store_stat_arr['title'] = "行业店铺30强";
     $store_stat_arr['legend']['enabled'] = false;
     $store_stat_arr['yAxis'] = '下单量';
     $store_statjson = getStatData_Column2D($store_stat_arr);
     Tpl::output('goods_statjson', $goods_statjson);
     Tpl::output('goods_list', $goods_list);
     Tpl::output('store_statjson', $store_statjson);
     Tpl::output('store_list', $store_list);
     Tpl::output('top_link', $this->sublink($this->links, 'rank'));
     Tpl::showpage('stat.industry.rank');
 }
Exemplo n.º 5
0
 /**
  * 热卖商品列表
  */
 public function hotgoods_listOp()
 {
     $model = Model('stat');
     switch ($_GET['type']) {
         case 'goodsnum':
             $sort_text = '下单量';
             break;
         default:
             $_GET['type'] = 'orderamount';
             $sort_text = '下单金额';
             break;
     }
     //构造横轴数据
     for ($i = 1; $i <= 50; $i++) {
         //数据
         $stat_arr['series'][0]['data'][] = array('name' => '', 'y' => 0);
         //横轴
         $stat_arr['xAxis']['categories'][] = "{$i}";
     }
     $where = array();
     $where['order_isvalid'] = 1;
     //计入统计的有效订单
     $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
     foreach ((array) $searchtime_arr_tmp as $k => $v) {
         $searchtime_arr[] = intval($v);
     }
     $where['order_add_time'] = array('between', $searchtime_arr);
     //商品分类
     if ($this->choose_gcid > 0) {
         //获得分类深度
         $depth = $this->gc_arr[$this->choose_gcid]['depth'];
         $where['gc_parentid_' . $depth] = $this->choose_gcid;
     }
     //查询统计数据
     $field = ' goods_id,goods_name ';
     switch ($_GET['type']) {
         case 'goodsnum':
             $field .= ' ,SUM(goods_num) as goodsnum ';
             $orderby = 'goodsnum desc';
             break;
         default:
             $_GET['type'] = 'orderamount';
             $field .= ' ,SUM(goods_pay_price) as orderamount ';
             $orderby = 'orderamount desc';
             break;
     }
     $orderby .= ',goods_id';
     $statlist = $model->statByStatordergoods($where, $field, 0, 50, $orderby, 'goods_id');
     foreach ((array) $statlist as $k => $v) {
         switch ($_GET['type']) {
             case 'goodsnum':
                 $stat_arr['series'][0]['data'][$k] = array('name' => strval($v['goods_name']), 'y' => intval($v[$_GET['type']]));
                 break;
             case 'orderamount':
                 $stat_arr['series'][0]['data'][$k] = array('name' => strval($v['goods_name']), 'y' => floatval($v[$_GET['type']]));
                 break;
         }
         $statlist[$k]['sort'] = $k + 1;
     }
     $stat_arr['series'][0]['name'] = $sort_text;
     $stat_arr['legend']['enabled'] = false;
     //得到统计图数据
     $stat_arr['title'] = '热卖商品TOP50';
     $stat_arr['yAxis'] = $sort_text;
     $stat_json = getStatData_Column2D($stat_arr);
     Tpl::output('stat_json', $stat_json);
     Tpl::output('statlist', $statlist);
     Tpl::output('sort_text', $sort_text);
     Tpl::output('stat_field', $_GET['type']);
     Tpl::showpage('stat.goods.hotgoods.list', 'null_layout');
 }
Exemplo n.º 6
0
 /**
  * 会员分析
  */
 public function analyzeOp()
 {
     if (!$this->search_arr['search_type']) {
         $this->search_arr['search_type'] = 'day';
     }
     $model = Model('stat');
     //构造横轴数据
     for ($i = 1; $i <= 15; $i++) {
         //横轴
         $stat_arr['xAxis']['categories'][] = $i;
     }
     $stat_arr['title'] = '买家排行Top15';
     $stat_arr['legend']['enabled'] = false;
     //获得搜索的开始时间和结束时间
     $searchtime_arr = $model->getStarttimeAndEndtime($this->search_arr);
     $where = array();
     $where['statm_time'] = array('between', $searchtime_arr);
     //下单量
     $where['statm_ordernum'] = array('gt', 0);
     $field = ' statm_memberid, statm_membername, sum(statm_ordernum) as ordernum ';
     $ordernum_listtop15 = $model->statByStatmember($where, $field, 0, 15, 'ordernum desc,statm_memberid desc', 'statm_memberid');
     $stat_ordernum_arr = $stat_arr;
     $stat_ordernum_arr['series'][0]['name'] = '下单量';
     $stat_ordernum_arr['series'][0]['data'] = array();
     for ($i = 0; $i < 15; $i++) {
         $stat_ordernum_arr['series'][0]['data'][] = array('name' => strval($ordernum_listtop15[$i]['statm_membername']), 'y' => intval($ordernum_listtop15[$i]['ordernum']));
     }
     $stat_ordernum_arr['yAxis'] = '下单量';
     $statordernum_json = getStatData_Column2D($stat_ordernum_arr);
     unset($stat_ordernum_arr);
     Tpl::output('statordernum_json', $statordernum_json);
     Tpl::output('ordernum_listtop15', $ordernum_listtop15);
     //下单商品件数
     $where['statm_goodsnum'] = array('gt', 0);
     $field = ' statm_memberid, statm_membername, sum(statm_goodsnum) as goodsnum ';
     $goodsnum_listtop15 = $model->statByStatmember($where, $field, 0, 15, 'goodsnum desc,statm_memberid desc', 'statm_memberid');
     $stat_goodsnum_arr = $stat_arr;
     $stat_goodsnum_arr['series'][0]['name'] = '下单商品件数';
     $stat_goodsnum_arr['series'][0]['data'] = array();
     for ($i = 0; $i < 15; $i++) {
         $stat_goodsnum_arr['series'][0]['data'][] = array('name' => strval($goodsnum_listtop15[$i]['statm_membername']), 'y' => intval($goodsnum_listtop15[$i]['goodsnum']));
     }
     $stat_goodsnum_arr['yAxis'] = '下单商品件数';
     $statgoodsnum_json = getStatData_Column2D($stat_goodsnum_arr);
     unset($stat_goodsnum_arr);
     Tpl::output('statgoodsnum_json', $statgoodsnum_json);
     Tpl::output('goodsnum_listtop15', $goodsnum_listtop15);
     //下单金额
     $where['statm_orderamount'] = array('gt', 0);
     $field = ' statm_memberid, statm_membername, sum(statm_orderamount) as orderamount ';
     $orderamount_listtop15 = $model->statByStatmember($where, $field, 0, 15, 'orderamount desc,statm_memberid desc', 'statm_memberid');
     $stat_orderamount_arr = $stat_arr;
     $stat_orderamount_arr['series'][0]['name'] = '下单金额';
     $stat_orderamount_arr['series'][0]['data'] = array();
     for ($i = 0; $i < 15; $i++) {
         $stat_orderamount_arr['series'][0]['data'][] = array('name' => strval($orderamount_listtop15[$i]['statm_membername']), 'y' => floatval($orderamount_listtop15[$i]['orderamount']));
     }
     $stat_orderamount_arr['yAxis'] = '下单金额';
     $statorderamount_json = getStatData_Column2D($stat_orderamount_arr);
     unset($stat_orderamount_arr);
     Tpl::output('statorderamount_json', $statorderamount_json);
     Tpl::output('orderamount_listtop15', $orderamount_listtop15);
     Tpl::output('searchtime', implode('|', $searchtime_arr));
     Tpl::output('top_link', $this->sublink($this->links, 'analyze'));
     Tpl::showpage('stat.memberanalyze');
 }
Exemplo n.º 7
0
 /**
  * 类目销售统计
  */
 public function class_saleOp()
 {
     if (!$_REQUEST['search_type']) {
         $_REQUEST['search_type'] = 'day';
     }
     //初始化时间
     //天
     if (!$_REQUEST['search_time']) {
         $_REQUEST['search_time'] = date('Y-m-d', time());
     }
     $search_time = strtotime($_REQUEST['search_time']);
     //搜索的时间
     Tpl::output('search_time', $_REQUEST['search_time']);
     //周
     if (!$_REQUEST['search_time_year']) {
         $_REQUEST['search_time_year'] = date('Y', time());
     }
     if (!$_REQUEST['search_time_month']) {
         $_REQUEST['search_time_month'] = date('m', time());
     }
     if (!$_REQUEST['search_time_week']) {
         $_REQUEST['search_time_week'] = implode('|', getWeek_SdateAndEdate(time()));
     }
     $current_year = $_REQUEST['search_time_year'];
     $current_month = $_REQUEST['search_time_month'];
     $current_week = $_REQUEST['search_time_week'];
     $year_arr = getSystemYearArr();
     $month_arr = getSystemMonthArr();
     $week_arr = getMonthWeekArr($current_year, $current_month);
     Tpl::output('current_year', $current_year);
     Tpl::output('current_month', $current_month);
     Tpl::output('current_week', $current_week);
     Tpl::output('year_arr', $year_arr);
     Tpl::output('month_arr', $month_arr);
     Tpl::output('week_arr', $week_arr);
     if ($_REQUEST['search_type'] == 'day') {
         $stime = $search_time;
         //昨天0点
         $etime = $search_time + 86400 - 1;
         //今天24点
         Tpl::output('actionurl', 'index.php?act=stat_trade&op=class_sale&search_type=day&search_time=' . date('Y-m-d', $search_time));
     }
     if ($_REQUEST['search_type'] == 'week') {
         $current_weekarr = explode('|', $current_week);
         $stime = strtotime($current_weekarr[0]) - 86400 * 7;
         $etime = strtotime($current_weekarr[1]) + 86400 - 1;
         Tpl::output('actionurl', 'index.php?act=stat_trade&op=class_sale&search_type=week&search_time_year=' . $current_year . '&search_time_month=' . $current_month . '&search_time_week=' . $current_week);
     }
     if ($_REQUEST['search_type'] == 'month') {
         $stime = strtotime($current_year . '-' . $current_month . "-01 0 month");
         $etime = getMonthLastDay($current_year, $current_month) + 86400 - 1;
         Tpl::output('actionurl', 'index.php?act=stat_trade&op=class_sale&search_type=month&search_time_year=' . $current_year . '&search_time_month=' . $current_month);
     }
     //获取销售排名数据Top10
     $condition = array();
     $condition['order.add_time'] = array('between', array($stime, $etime));
     $condition['order.order_state'] = array('neq', ORDER_STATE_NEW);
     //去除未支付订单
     $condition['order.refund_state'] = array('exp', "!(order_state = '" . ORDER_STATE_CANCEL . "' and refund_state = 0)");
     //没有参与退款的取消订单,不记录到统计中
     $condition['order.payment_code'] = array('exp', "!(order.payment_code='offline' and order.order_state <> '" . ORDER_STATE_SUCCESS . "')");
     //货到付款订单,订单成功之后才计入统计
     if (trim($_GET['class_type']) == '' || trim($_GET['class_type']) == 'goods_class') {
         $type = 'goods';
         if (intval($_GET['cate_id']) > 0) {
             $condition['goods.gc_id'] = intval($_GET['cate_id']);
         }
         Tpl::output('chart_tip', '商品类目销售排名Top10');
     } else {
         $type = 'store';
         if (intval($_GET['store_class']) > 0) {
             $condition['store.sc_id'] = intval($_GET['store_class']);
         }
         Tpl::output('chart_tip', '店铺类目销售排名Top10');
     }
     $model = Model('stat');
     //导出Excel
     if ($_GET['exporttype'] == 'excel') {
         //获取数据
         $data_list = $model->getStoreTradeList($condition, $type);
         //导出Excel
         import('libraries.excel');
         $excel_obj = new Excel();
         $excel_data = array();
         //设置样式
         $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
         //header
         if (trim($_GET['class_type']) == '' || trim($_GET['class_type']) == 'goods_class') {
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '商品名称');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '所属分类');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '店铺名称');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单单量');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单商品件数');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单金额');
         } else {
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '店铺名称');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '所属分类');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '店主账号');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单单量');
             $excel_data[0][] = array('styleid' => 's_title', 'data' => '下单金额');
         }
         //data
         foreach ($data_list as $k => $v) {
             if (trim($_GET['class_type']) == '' || trim($_GET['class_type']) == 'goods_class') {
                 $excel_data[$k + 1][] = array('data' => $v['goods_name']);
                 $excel_data[$k + 1][] = array('data' => $v['gc_name']);
                 $excel_data[$k + 1][] = array('data' => $v['store_name']);
                 $excel_data[$k + 1][] = array('data' => $v['onum']);
                 $excel_data[$k + 1][] = array('data' => $v['gnum']);
                 $excel_data[$k + 1][] = array('data' => $v['pnum']);
             } else {
                 $excel_data[$k + 1][] = array('data' => $v['store_name']);
                 $excel_data[$k + 1][] = array('data' => $v['sc_name']);
                 $excel_data[$k + 1][] = array('data' => $v['member_name']);
                 $excel_data[$k + 1][] = array('data' => $v['onum']);
                 $excel_data[$k + 1][] = array('data' => $v['pnum']);
             }
         }
         $excel_data = $excel_obj->charset($excel_data, CHARSET);
         $excel_obj->addArray($excel_data);
         $excel_obj->addWorksheet($excel_obj->charset(trim($_GET['class_type']) == 'store_class' ? '店铺类目销售排名' : '商品类目销售排名', CHARSET));
         $excel_obj->generateXML($excel_obj->charset(trim($_GET['class_type']) == 'store_class' ? '店铺类目销售排名' : '商品类目销售排名', CHARSET) . date('Y-m-d-H', time()));
         exit;
     } else {
         $data_list = $model->getStoreTradeList($condition, $type, 10);
         Tpl::output('data_list', $data_list);
         $stat_arr['title'] = trim($_GET['class_type']) == 'store_class' ? '店铺类目销售排名' : '商品类目销售排名';
         $stat_arr['yAxis'] = '下单金额';
         $stat_arr['series'][0]['name'] = '下单金额';
         $stat_arr['series'][0]['data'] = array();
         for ($i = 0; $i < 15; $i++) {
             $stat_arr['series'][0]['data'][] = array('name' => strval($data_list[$i][trim($_GET['class_type']) == 'store_class' ? 'store_name' : 'goods_name']), 'y' => floatval($data_list[$i]['pnum']));
         }
         //构造横轴数据
         for ($i = 1; $i <= 15; $i++) {
             //横轴
             $stat_arr['xAxis']['categories'][] = $i;
         }
         $stat_arr['legend']['enabled'] = false;
         $stat_json = getStatData_Column2D($stat_arr);
         Tpl::output('stat_json', $stat_json);
         //店铺分类
         $model_store_class = Model('store_class');
         $parent_list = $model_store_class->getTreeClassList(2);
         if (is_array($parent_list)) {
             foreach ($parent_list as $k => $v) {
                 $parent_list[$k]['sc_name'] = str_repeat("&nbsp;", $v['deep'] * 2) . $v['sc_name'];
             }
         }
         Tpl::output('class_list', $parent_list);
         Tpl::output('goods_class', Model('goods_class')->getTreeClassList(1));
         Tpl::output('top_link', $this->sublink($this->links, 'class_sale'));
         Tpl::showpage('stat.classsale');
     }
 }
Exemplo n.º 8
0
 /**
  * 店铺排行
  */
 public function rankOp()
 {
     $where = array();
     if (trim($_GET['order_type']) != '') {
         $where['order_state'] = trim($_GET['order_type']);
     }
     if (!$_REQUEST['search_type']) {
         $_REQUEST['search_type'] = 'day';
     }
     if (trim($_GET['store_name']) != '') {
         $where['store_name'] = trim($_GET['store_name']);
     }
     //初始化时间
     //天
     if (!$_REQUEST['search_time']) {
         $_REQUEST['search_time'] = date('Y-m-d', time());
     }
     $search_time = strtotime($_REQUEST['search_time']);
     //搜索的时间
     Tpl::output('search_time', $_REQUEST['search_time']);
     //周
     if (!$_REQUEST['search_time_year']) {
         $_REQUEST['search_time_year'] = date('Y', time());
     }
     if (!$_REQUEST['search_time_month']) {
         $_REQUEST['search_time_month'] = date('m', time());
     }
     if (!$_REQUEST['search_time_week']) {
         $_REQUEST['search_time_week'] = implode('|', getWeek_SdateAndEdate(time()));
     }
     $current_year = $_REQUEST['search_time_year'];
     $current_month = $_REQUEST['search_time_month'];
     $current_week = $_REQUEST['search_time_week'];
     $year_arr = getSystemYearArr();
     $month_arr = getSystemMonthArr();
     $week_arr = getMonthWeekArr($current_year, $current_month);
     Tpl::output('current_year', $current_year);
     Tpl::output('current_month', $current_month);
     Tpl::output('current_week', $current_week);
     Tpl::output('year_arr', $year_arr);
     Tpl::output('month_arr', $month_arr);
     Tpl::output('week_arr', $week_arr);
     $model = Model('stat');
     if ($_REQUEST['search_type'] == 'day') {
         $stime = $search_time;
         //昨天0点
         $etime = $search_time + 86400 - 1;
         //今天24点
         Tpl::output('actionurl', 'index.php?act=stat_store&op=rank&search_type=day&search_time=' . date('Y-m-d', $search_time));
     }
     if ($_REQUEST['search_type'] == 'week') {
         $current_weekarr = explode('|', $current_week);
         $stime = strtotime($current_weekarr[0]) - 86400 * 7;
         $etime = strtotime($current_weekarr[1]) + 86400 - 1;
         Tpl::output('actionurl', 'index.php?act=stat_store&op=rank&search_type=week&search_time_year=' . $current_year . '&search_time_month=' . $current_month . '&search_time_week=' . $current_week);
     }
     if ($_REQUEST['search_type'] == 'month') {
         $stime = strtotime($current_year . '-' . $current_month . "-01 0 month");
         $etime = getMonthLastDay($current_year, $current_month) + 86400 - 1;
         Tpl::output('actionurl', 'index.php?act=stat_store&op=rank&search_type=month&search_time_year=' . $current_year . '&search_time_month=' . $current_month);
     }
     $where['add_time'] = array('between', array($stime, $etime));
     $where['order_state'] = array('neq', ORDER_STATE_NEW);
     //去除未支付订单
     $where['refund_state'] = array('exp', "!(order_state = '" . ORDER_STATE_CANCEL . "' and refund_state = 0)");
     //没有参与退款的取消订单,不记录到统计中
     $where['payment_code'] = array('exp', "!(payment_code='offline' and order_state <> '" . ORDER_STATE_SUCCESS . "')");
     //货到付款订单,订单成功之后才计入统计
     //得到统计图数据
     if (trim($_GET['stat_type']) == 'sale') {
         $store_list = $model->getStoreSaleRank($where, 'sale_amount');
         $statlist['headertitle'] = array('排名', '店铺名称', '销售额');
         $stat_arr['title'] = '店铺销售额排行Top15';
         $stat_arr['yAxis'] = '销售额';
         $stat_arr['series'][0]['name'] = '销售额';
     } else {
         $store_list = $model->getStoreSaleRank($where, 'sale_num');
         $statlist['headertitle'] = array('排名', '店铺名称', '订单量');
         $stat_arr['title'] = '店铺订单量排行Top15';
         $stat_arr['yAxis'] = '订单量';
         $stat_arr['series'][0]['name'] = '订单量';
     }
     //导出Excel
     if ($_GET['exporttype'] == 'excel') {
         //导出Excel
         import('libraries.excel');
         $excel_obj = new Excel();
         $excel_data = array();
         //设置样式
         $excel_obj->setStyle(array('id' => 's_title', 'Font' => array('FontName' => '宋体', 'Size' => '12', 'Bold' => '1')));
         //header
         foreach ($statlist['headertitle'] as $v) {
             $excel_data[0][] = array('styleid' => 's_title', 'data' => $v);
         }
         //data
         foreach ($store_list as $k => $v) {
             $excel_data[$k + 1][] = array('data' => $k + 1);
             $excel_data[$k + 1][] = array('data' => $v['store_name']);
             $excel_data[$k + 1][] = array('data' => $v['allnum']);
         }
         $excel_data = $excel_obj->charset($excel_data, CHARSET);
         $excel_obj->addArray($excel_data);
         if (trim($_GET['stat_type']) == 'sale') {
             $excel_obj->addWorksheet($excel_obj->charset('店铺销售额排行Top15', CHARSET));
             $excel_obj->generateXML($excel_obj->charset('店铺销售额排行Top15', CHARSET) . date('Y-m-d-H', time()));
         } else {
             $excel_obj->addWorksheet($excel_obj->charset('店铺订单量排行Top15', CHARSET));
             $excel_obj->generateXML($excel_obj->charset('店铺订单量排行Top15', CHARSET) . date('Y-m-d-H', time()));
         }
         exit;
     } else {
         $stat_arr['series'][0]['data'] = array();
         for ($i = 0; $i < 15; $i++) {
             $stat_arr['series'][0]['data'][] = array('name' => strval($store_list[$i]['store_name']), 'y' => floatval($store_list[$i]['allnum']));
         }
         //构造横轴数据
         for ($i = 1; $i <= 15; $i++) {
             //横轴
             $stat_arr['xAxis']['categories'][] = $i;
         }
         $stat_arr['legend']['enabled'] = false;
         $stat_json = getStatData_Column2D($stat_arr);
         //总数统计
         $amount = $model->getStoreSaleStatList($where, ' count(*) as allnum ');
         $sale = $model->getStoreSaleStatList($where, ' sum(order_amount) as allnum ');
         Tpl::output('sum_data', array($amount[0]['allnum'], $sale[0]['allnum']));
         Tpl::output('stat_json', $stat_json);
         Tpl::output('statlist', $statlist);
         Tpl::output('store_list', $store_list);
         Tpl::output('top_link', $this->sublink($this->links, 'rank'));
         Tpl::showpage('stat.storerank');
     }
 }