コード例 #1
0
ファイル: stat_industry.php プロジェクト: ff00x0/shopnc
 /**
  * 行业规模列表
  */
 public function scale_listOp()
 {
     //获得子分类ID
     $gc_childid = $gc_childarr = array();
     if ($this->choose_gcid > 0) {
         //如果进行了分类搜索,则统计该分类下的子分类
         $gc_childdepth = $this->gc_arr[$this->choose_gcid]['depth'] + 1;
         $gc_childid = explode(',', $this->gc_arr[$this->choose_gcid]['child']);
         if ($gc_childid) {
             foreach ((array) $this->gc_arr as $k => $v) {
                 if (in_array($v['gc_id'], $gc_childid)) {
                     $gc_childarr[$v['gc_id']] = $v;
                 }
             }
         }
     } else {
         //如果没有搜索分类,则默认统计一级分类
         $gc_childdepth = 1;
         foreach ((array) $this->gc_arr as $k => $v) {
             if ($v['depth'] == 1) {
                 $gc_childarr[$v['gc_id']] = $v;
             }
         }
     }
     if ($gc_childarr) {
         $model = Model('stat');
         $stat_list = array();
         //构造横轴数据
         foreach ($gc_childarr as $k => $v) {
             $stat_list[$k]['gc_name'] = $v['gc_name'];
             $stat_list[$k]['y'] = 0;
         }
         $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) {
             $where['gc_parentid_' . ($gc_childdepth - 1)] = $this->choose_gcid;
         }
         $field = 'gc_parentid_' . $gc_childdepth . ' as statgc_id';
         switch ($_GET['stattype']) {
             case 'ordernum':
                 $caption = '下单量';
                 $field .= ',COUNT(DISTINCT order_id) as ordernum';
                 $orderby = 'ordernum desc';
                 break;
             case 'goodsnum':
                 $caption = '下单商品数';
                 $field .= ',SUM(goods_num) as goodsnum';
                 $orderby = 'goodsnum desc';
                 break;
             default:
                 $_GET['stattype'] = 'orderamount';
                 $caption = '下单金额';
                 $field .= ',SUM(goods_pay_price) as orderamount';
                 $orderby = 'orderamount desc';
                 break;
         }
         $orderby .= ',statgc_id asc';
         $goods_list = $model->statByStatordergoods($where, $field, 0, 0, $orderby, 'statgc_id');
         foreach ((array) $goods_list as $k => $v) {
             $statgc_id = intval($v['statgc_id']);
             if (in_array($statgc_id, array_keys($gc_childarr))) {
                 $stat_list[$statgc_id]['gc_name'] = strval($gc_childarr[$v['statgc_id']]['gc_name']);
             } else {
                 $stat_list[$statgc_id]['gc_name'] = '其他';
             }
             switch ($_GET['stattype']) {
                 case 'orderamount':
                     $stat_list[$statgc_id]['y'] = floatval($v[$_GET['stattype']]);
                     break;
                 default:
                     $stat_list[$statgc_id]['y'] = intval($v[$_GET['stattype']]);
                     break;
             }
         }
         //构造横轴数据
         foreach ($stat_list as $k => $v) {
             //数据
             $stat_arr['series'][0]['data'][] = array('name' => strval($v['gc_name']), 'y' => $v['y']);
             //横轴
             $stat_arr['xAxis']['categories'][] = strval($v['gc_name']);
         }
         //得到统计图数据
         $stat_arr['series'][0]['name'] = $caption;
         $stat_arr['title'] = "行业{$caption}统计";
         $stat_arr['legend']['enabled'] = false;
         $stat_arr['yAxis']['title']['text'] = $caption;
         $stat_arr['yAxis']['title']['align'] = 'high';
         $statjson = getStatData_Basicbar($stat_arr);
         Tpl::output('stat_json', $statjson);
         Tpl::output('stattype', $_GET['stattype']);
         Tpl::showpage('stat.linelabels', 'null_layout');
     }
 }
コード例 #2
0
ファイル: statistics_sale.php プロジェクト: noikiy/ejia
	/**
	 * 地区分布
	 */
	public function areaOp(){
	    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['store_id'] = $_SESSION['store_id'];
		$where['order_isvalid'] = 1;//计入统计的有效订单
		$where['order_add_time'] = array('between',$searchtime_arr);
		$memberlist = array();
		//查询统计数据
		$field = ' reciver_province_id,SUM(order_amount) as orderamount,COUNT(*) as ordernum,COUNT(DISTINCT buyer_id) as membernum ';
		$orderby = 'reciver_province_id';
		$statlist = $model->statByStatorder($where, $field, 10, 0, $orderby, 'reciver_province_id');
		$datatype = array('orderamount'=>'下单金额','ordernum'=>'下单量','membernum'=>'下单会员数');
		//处理数组,将数组按照$datatype分组排序
		$statlist_tmp = array();
		foreach ((array)$statlist as $k=>$v){
		    foreach ((array)$datatype as $t_k=>$t_v){
		        $statlist_tmp[$t_k][$k] = $v[$t_k];
		    }
		}
		foreach ((array)$statlist_tmp as $t_k=>$t_v){
		    arsort($statlist_tmp[$t_k]);
		}
		$statlist_tmp2 = $statlist_tmp;
		$statlist_tmp = array();
		foreach ((array)$statlist_tmp2 as $t_k=>$t_v){
		    foreach ($t_v as $k=>$v){
		        $statlist[$k]['orderamount'] = floatval($statlist[$k]['orderamount']);
		        $statlist[$k]['ordernum'] = intval($statlist[$k]['ordernum']);
		        $statlist[$k]['membernum'] = intval($statlist[$k]['membernum']);
		        $statlist_tmp[$t_k][] = $statlist[$k];
		    }
		}
		// 地区
        $province_array = Model('area')->getTopLevelAreas();
        //地图显示等级数组
        $level_arr = array(array(1,2,3),array(4,5,6),array(7,8,9),array(10,11,12));
        $statlist = array();
        $stat_arr_bar = array();
		foreach ((array)$statlist_tmp as $t_k=>$t_v){
		    foreach ((array)$t_v as $k=>$v){
    		    $v['level'] = 4;//排名
    		    foreach ($level_arr as $lk=>$lv){
    		        if (in_array($k+1,$lv)){
    		            $v['level'] = $lk;//排名
    		        }
    		    }
    		    $province_id = intval($v['reciver_province_id']);
    		    $statlist[$t_k][$province_id] = $v;
		        if ($province_id){
		            //数据
        		    $stat_arr_bar[$t_k]['series'][0]['data'][] = array('name'=>strval($province_array[$province_id]),'y'=>$v[$t_k]);
            		//横轴
            		$stat_arr_bar[$t_k]['xAxis']['categories'][] = strval($province_array[$province_id]);
		        } else {
		            //数据
        		    $stat_arr_bar[$t_k]['series'][0]['data'][] = array('name'=>'未知','y'=>$v[$t_k]);
            		//横轴
            		$stat_arr_bar[$t_k]['xAxis']['categories'][] = '未知';
		        }
		    }
		}
		$stat_arr_map = array();
	    foreach ((array)$province_array as $k=>$v){
		    foreach ($datatype as $t_k=>$t_v){
		        if ($statlist[$t_k][$k][$t_k]){
		            $des = ",{$t_v}:{$statlist[$t_k][$k][$t_k]}";
		            $stat_arr_map[$t_k][] = array('cha'=>$k,'name'=>$v,'des'=>$des,'level'=>$statlist[$t_k][$k]['level']);
		        } else {
		            $des = ",无订单数据";
	                $stat_arr_map[$t_k][] = array('cha'=>$k,'name'=>$v,'des'=>$des,'level'=>4);
		        }
		    }
		}
		$stat_json_map = array();
		$stat_json_bar = array();
		if ($statlist){
    		foreach ($datatype as $t_k=>$t_v){
    		    //得到地图数据
    		    $stat_json_map[$t_k] = getStatData_Map($stat_arr_map[$t_k]);
    		    //得到统计图数据
    		    $stat_arr_bar[$t_k]['series'][0]['name'] = $t_v;
        		$stat_arr_bar[$t_k]['title'] = "地区排行";
        		$stat_arr_bar[$t_k]['legend']['enabled'] = false;
                $stat_arr_bar[$t_k]['yAxis']['title']['text'] = $t_v;
                $stat_arr_bar[$t_k]['yAxis']['title']['align'] = 'high';
        		$stat_json_bar[$t_k] = getStatData_Basicbar($stat_arr_bar[$t_k]);
    		}
		}
		Tpl::output('stat_json_map',$stat_json_map);
		Tpl::output('stat_json_bar',$stat_json_bar);
		self::profile_menu('area');
		Tpl::showpage('stat.sale.area');
	}