/** * 地区分布 */ public function storeareaOp() { $model = Model('stat'); //获得搜索的开始时间和结束时间 $searchtime_arr = $model->getStarttimeAndEndtime($this->search_arr); $where = array(); if (trim($_GET['search_time'])) { $where['store_time'] = array('elt', strtotime($_GET['search_time'])); } $search_sclass = intval($_REQUEST['search_sclass']); if ($search_sclass > 0) { $where['sc_id'] = $search_sclass; } $field = ' province_id, COUNT(*) as storenum '; $statlist_tmp = $model->statByStore($where, $field, 0, 0, 'storenum desc,province_id', 'province_id'); // 地区 $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(); foreach ((array) $statlist_tmp 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['province_id']); $v['sort'] = $k + 1; $v['provincename'] = ($t = $province_array[$province_id]) ? $t : '其他'; $statlist[$province_id] = $v; } $stat_arr = array(); foreach ((array) $province_array as $k => $v) { if ($statlist[$k]) { $stat_arr[] = array('cha' => $k, 'name' => $v, 'des' => ",店铺量:{$statlist[$k]['storenum']}", 'level' => $statlist[$k]['level']); } else { $stat_arr[] = array('cha' => $k, 'name' => $v, 'des' => ',无订单数据', 'level' => 4); } } $stat_json = uk86_getStatData_Map($stat_arr); Tpl::output('stat_json', $stat_json); Tpl::output('statlist', $statlist); $actionurl = 'index.php?act=stat_store&op=showstore&type=storearea'; if (trim($_GET['search_time'])) { $actionurl = $actionurl . '&t=0|' . strtotime($_GET['search_time']); } if ($search_sclass > 0) { $actionurl .= "&scid={$search_sclass}"; } Tpl::output('actionurl', $actionurl); Tpl::output('top_link', $this->sublink($this->links, 'storearea')); Tpl::showpage('stat.storearea'); }
/** * 地区分布 */ 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] = uk86_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] = uk86_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'); }
/** * 区域分析之地图数据 */ public function area_mapOp() { $model = Model('stat'); $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); $memberlist = array(); //查询统计数据 $field = ' reciver_province_id '; switch ($_GET['type']) { case 'orderamount': $field .= ' ,SUM(order_amount) as orderamount '; $orderby = 'orderamount desc'; break; case 'ordernum': $field .= ' ,COUNT(*) as ordernum '; $orderby = 'ordernum desc'; break; default: $_GET['type'] = 'membernum'; $field .= ' ,COUNT(DISTINCT buyer_id) as membernum '; $orderby = 'membernum desc'; break; } $orderby .= ',reciver_province_id'; $statlist_tmp = $model->statByStatorder($where, $field, 10, 0, $orderby, 'reciver_province_id'); // 地区 $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(); foreach ((array) $statlist_tmp 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[$province_id] = $v; } $stat_arr = array(); foreach ((array) $province_array as $k => $v) { if ($statlist[$k]) { switch ($_GET['type']) { case 'orderamount': $des = ",下单金额:{$statlist[$k]['orderamount']}"; break; case 'ordernum': $des = ",下单量:{$statlist[$k]['ordernum']}"; break; default: $des = ",下单会员数:{$statlist[$k]['membernum']}"; break; } $stat_arr[] = array('cha' => $k, 'name' => $v, 'des' => $des, 'level' => $statlist[$k]['level']); } else { $des = ",无订单数据"; $stat_arr[] = array('cha' => $k, 'name' => $v, 'des' => $des, 'level' => 4); } } $stat_json = uk86_getStatData_Map($stat_arr); Tpl::output('stat_field', $_GET['type']); Tpl::output('stat_json', $stat_json); Tpl::showpage('stat.map', 'null_layout'); }