public function __construct() { parent::__construct(); import('function.datehelper'); $model_stat = Model('stat'); $this->search_arr = $_POST; //$this->search_arr = $_GET; //处理搜索时间 if ($this->search_arr['stattype'] == 'yesterday') { $this->search_arr['search_type'] = 'day'; $this->search_arr['show_type'] = 'hour'; $this->search_arr['day']['search_time'] = date('Y-m-d', time() - 86400); $this->search_arr['day']['search_time'] = strtotime($this->search_arr['day']['search_time']); } elseif ($this->search_arr['stattype'] == 'day3') { $this->search_arr['search_type'] = 'day3'; $this->search_arr['show_type'] = 'day'; $this->search_arr['day']['search_time'] = date('Y-m-d', time() - 86400); $this->search_arr['day']['search_time'] = strtotime($this->search_arr['day']['search_time']); } elseif ($this->search_arr['stattype'] == 'day7') { $this->search_arr['search_type'] = 'day7'; $this->search_arr['show_type'] = 'day'; $this->search_arr['day']['search_time'] = date('Y-m-d', time() - 86400); $this->search_arr['day']['search_time'] = strtotime($this->search_arr['day']['search_time']); } elseif ($this->search_arr['stattype'] == 'week') { $this->search_arr['search_type'] = 'week'; $this->search_arr['show_type'] = 'week'; $searchweek_weekarr = getWeek_SdateAndEdate(time()); $this->search_arr['week']['current_week'] = implode('|', $searchweek_weekarr); } elseif ($this->search_arr['stattype'] == 'month') { $this->search_arr['search_type'] = 'month'; $this->search_arr['show_type'] = 'day'; $this->search_arr['month']['current_year'] = date('Y', time()); $this->search_arr['month']['current_month'] = date('m', time()); } elseif ($this->search_arr['stattype'] == 'year') { $this->search_arr['search_type'] = 'year'; $this->search_arr['show_type'] = 'month'; $this->search_arr['year']['current_year'] = date('Y', time()); } $searchtime_arr = $model_stat->getStarttimeAndEndtime($this->search_arr); $this->search_arr['stime'] = $searchtime_arr[0]; $this->search_arr['etime'] = $searchtime_arr[1]; }
/** * 处理搜索时间 */ public function dealwithSearchTime($search_arr) { //初始化时间 //天 if (!$search_arr['search_time']) { $search_arr['search_time'] = date('Y-m-d', time()); } $search_arr['day']['search_time'] = strtotime($search_arr['search_time']); //搜索的时间 //周 if (!$search_arr['searchweek_year']) { $search_arr['searchweek_year'] = date('Y', time()); } if (!$search_arr['searchweek_month']) { $search_arr['searchweek_month'] = date('m', time()); } if (!$search_arr['searchweek_week']) { $search_arr['searchweek_week'] = implode('|', getWeek_SdateAndEdate(time())); } $weekcurrent_year = $search_arr['searchweek_year']; $weekcurrent_month = $search_arr['searchweek_month']; $weekcurrent_week = $search_arr['searchweek_week']; $search_arr['week']['current_year'] = $weekcurrent_year; $search_arr['week']['current_month'] = $weekcurrent_month; $search_arr['week']['current_week'] = $weekcurrent_week; //月 if (!$search_arr['searchmonth_year']) { $search_arr['searchmonth_year'] = date('Y', time()); } if (!$search_arr['searchmonth_month']) { $search_arr['searchmonth_month'] = date('m', time()); } $monthcurrent_year = $search_arr['searchmonth_year']; $monthcurrent_month = $search_arr['searchmonth_month']; $search_arr['month']['current_year'] = $monthcurrent_year; $search_arr['month']['current_month'] = $monthcurrent_month; return $search_arr; }
/** * 订单统计 */ public function saleOp() { $where = array(); if (trim($_GET['order_type']) != '') { $where['order_state'] = trim($_GET['order_type']); } if (trim($_GET['stat_type']) == 'sale') { $field = ' sum(order_amount) as allnum '; } else { $field = ' count(*) as allnum '; } if (!$_REQUEST['search_type']) { $_REQUEST['search_type'] = 'day'; } if (trim($_GET['store_name']) != '') { $where['store_name'] = trim($_GET['store_name']); $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'); $statlist = array(); //统计数据列表 $sum_num = 0; //总数统计 if ($_REQUEST['search_type'] == 'day') { //构造横轴数据 for ($i = 0; $i < 24; $i++) { //统计图数据 $curr_arr[$i] = 0; //今天 $up_arr[$i] = 0; //昨天 //统计表数据 $uplist_arr[$i]['timetext'] = $i; $currlist_arr[$i]['timetext'] = $i; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = "{$i}"; } $stime = $search_time - 86400; //昨天0点 $etime = $search_time + 86400 - 1; //今天24点 $today_day = @date('d', $search_time); //今天日期 $yesterday_day = @date('d', $stime); //昨天日期 $where['add_time'] = array('between', array($stime, $etime)); $field .= ' ,DAY(FROM_UNIXTIME(add_time)) as dayval,HOUR(FROM_UNIXTIME(add_time)) as hourval '; $memberlist = $model->getStoreSaleStatList($where, $field, 0, '', 0, 'dayval,hourval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($today_day == $v['dayval']) { $curr_arr[$v['hourval']] = intval($v['allnum']); $currlist_arr[$v['hourval']]['val'] = intval($v['allnum']); } if ($yesterday_day == $v['dayval']) { $up_arr[$v['hourval']] = intval($v['allnum']); $uplist_arr[$v['hourval']]['val'] = intval($v['allnum']); } } } elseif (trim($_GET['store_name']) != '') { Tpl::output('data_null', 'yes'); } $stat_arr['series'][0]['name'] = '昨天'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '今天'; $stat_arr['series'][1]['data'] = array_values($curr_arr); Tpl::output('actionurl', 'index.php?act=stat_trade&op=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; $up_week = @date('W', $stime); //上周 $curr_week = @date('W', $etime); //本周 //构造横轴数据 for ($i = 1; $i <= 7; $i++) { //统计图数据 $up_arr[$i] = 0; $curr_arr[$i] = 0; $tmp_weekarr = getSystemWeekArr(); //统计表数据 $uplist_arr[$i]['timetext'] = $tmp_weekarr[$i]; $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i]; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i]; unset($tmp_weekarr); } $where['add_time'] = array('between', array($stime, $etime)); $field .= ',WEEKOFYEAR(FROM_UNIXTIME(add_time)) as weekval,DAYOFWEEK(FROM_UNIXTIME(add_time)) as dayofweekval '; $memberlist = $model->getStoreSaleStatList($where, $field, 0, '', 0, 'weekval,dayofweekval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($up_week == $v['weekval']) { $up_arr[$v['dayofweekval']] = intval($v['allnum']); $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']); } if ($curr_week == $v['weekval']) { $curr_arr[$v['dayofweekval']] = intval($v['allnum']); $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']); } } } elseif (trim($_GET['store_name']) != '') { Tpl::output('data_null', 'yes'); } $stat_arr['series'][0]['name'] = '上周'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '本周'; $stat_arr['series'][1]['data'] = array_values($curr_arr); Tpl::output('actionurl', 'index.php?act=stat_trade&op=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 -1 month"); $etime = getMonthLastDay($current_year, $current_month) + 86400 - 1; $up_month = date('m', $stime); $curr_month = date('m', $etime); //计算横轴的最大量(由于每个月的天数不同) $up_dayofmonth = date('t', $stime); $curr_dayofmonth = date('t', $etime); $x_max = $up_dayofmonth > $curr_dayofmonth ? $up_dayofmonth : $curr_dayofmonth; //构造横轴数据 for ($i = 1; $i <= $x_max; $i++) { //统计图数据 $up_arr[$i] = 0; $curr_arr[$i] = 0; //统计表数据 $uplist_arr[$i]['timetext'] = $i; $currlist_arr[$i]['timetext'] = $i; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = $i; } $where['add_time'] = array('between', array($stime, $etime)); $field .= ',MONTH(FROM_UNIXTIME(add_time)) as monthval,day(FROM_UNIXTIME(add_time)) as dayval '; $memberlist = $model->getStoreSaleStatList($where, $field, 0, '', 0, 'monthval,dayval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($up_month == $v['monthval']) { $up_arr[$v['dayval']] = intval($v['allnum']); $uplist_arr[$v['dayval']]['val'] = intval($v['allnum']); } if ($curr_month == $v['monthval']) { $curr_arr[$v['dayval']] = intval($v['allnum']); $currlist_arr[$v['dayval']]['val'] = intval($v['allnum']); } } } elseif (trim($_GET['store_name']) != '') { Tpl::output('data_null', 'yes'); } $stat_arr['series'][0]['name'] = '上月'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '本月'; $stat_arr['series'][1]['data'] = array_values($curr_arr); Tpl::output('actionurl', 'index.php?act=stat_trade&op=sale&search_type=month&search_time_year=' . $current_year . '&search_time_month=' . $current_month); } //统计数据标题 $statlist['headertitle'] = array('订单号', '买家', '店铺名称', '下单时间', '订单总额', '订单状态'); //导出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); } $order_all_list = $model->getStoreOrderList($where, false); //data foreach ($order_all_list as $k => $v) { $excel_data[$k + 1][] = array('data' => $v['order_sn']); $excel_data[$k + 1][] = array('data' => $v['buyer_name']); $excel_data[$k + 1][] = array('data' => $v['store_name']); $excel_data[$k + 1][] = array('data' => date('Y-m-d H:i:s', $v['add_time'])); $excel_data[$k + 1][] = array('data' => number_format($v['order_amount'], 2)); switch ($v['order_state']) { case ORDER_STATE_CANCEL: $excel_data[$k + 1][] = array('data' => '已取消'); break; case ORDER_STATE_NEW: $excel_data[$k + 1][] = array('data' => '待付款'); break; case ORDER_STATE_PAY: $excel_data[$k + 1][] = array('data' => '待发货'); break; case ORDER_STATE_SEND: $excel_data[$k + 1][] = array('data' => '待收货'); break; case ORDER_STATE_SUCCESS: $excel_data[$k + 1][] = array('data' => '交易完成'); break; } } $excel_data = $excel_obj->charset($excel_data, CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset('订单统计', CHARSET)); $excel_obj->generateXML($excel_obj->charset('订单统计', CHARSET) . date('Y-m-d-H', time())); exit; } else { $order_list = $model->getStoreOrderList($where); //得到统计图数据 if (trim($_GET['stat_type']) == 'sale') { $stat_arr['title'] = '订单销售额统计'; $stat_arr['yAxis'] = '订单销售额'; } else { $stat_arr['title'] = '订单量统计'; $stat_arr['yAxis'] = '订单量'; } $stat_json = getStatData_LineLabels($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('order_list', $order_list); Tpl::output('show_page', $model->showpage()); Tpl::output('top_link', $this->sublink($this->links, 'sale')); Tpl::showpage('stat.sale'); } }
/** * 新增店铺 */ public function newstoreOp() { //导出excel连接地址 $actionurl = 'index.php?act=stat_store&op=newstore'; $where = array(); //所属店铺分类 $search_sclass = intval($_REQUEST['search_sclass']); if ($search_sclass > 0) { $where['sc_id'] = $search_sclass; $actionurl .= "&search_sclass={$search_sclass}"; } $field = ' count(*) as allnum '; if (!$_REQUEST['search_type']) { $_REQUEST['search_type'] = 'day'; } //初始化时间 //天 if (!$_REQUEST['search_time']) { $_REQUEST['search_time'] = date('Y-m-d', time() - 86400); } $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'); $statlist = array(); //统计数据列表 if ($_REQUEST['search_type'] == 'day') { //构造横轴数据 for ($i = 0; $i < 24; $i++) { //统计图数据 $curr_arr[$i] = 0; //今天 $up_arr[$i] = 0; //昨天 //统计表数据 $uplist_arr[$i]['timetext'] = $i; $currlist_arr[$i]['timetext'] = $i; //方便搜索会员列表,计算开始时间和结束时间 $currlist_arr[$i]['stime'] = $search_time + $i * 3600; $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 3600; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = "{$i}"; } $stime = $search_time - 86400; //昨天0点 $etime = $search_time + 86400 - 1; //今天24点 $today_day = @date('d', $search_time); //今天日期 $yesterday_day = @date('d', $stime); //昨天日期 $where['store_time'] = array('between', array($stime, $etime)); $field .= ' ,DAY(FROM_UNIXTIME(store_time)) as dayval,HOUR(FROM_UNIXTIME(store_time)) as hourval '; $memberlist = $model->getNewStoreStatList($where, $field, 0, '', 0, 'dayval,hourval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($today_day == $v['dayval']) { $curr_arr[$v['hourval']] = intval($v['allnum']); $currlist_arr[$v['hourval']]['val'] = intval($v['allnum']); } if ($yesterday_day == $v['dayval']) { $up_arr[$v['hourval']] = intval($v['allnum']); $uplist_arr[$v['hourval']]['val'] = intval($v['allnum']); } } } $stat_arr['series'][0]['name'] = '昨天'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '今天'; $stat_arr['series'][1]['data'] = array_values($curr_arr); //统计数据标题 $statlist['headertitle'] = array('小时', '昨天', '今天', '同比'); Tpl::output('actionurl', $actionurl . '&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; $up_week = @date('W', $stime); //上周 $curr_week = @date('W', $etime); //本周 //构造横轴数据 for ($i = 1; $i <= 7; $i++) { //统计图数据 $up_arr[$i] = 0; $curr_arr[$i] = 0; $tmp_weekarr = getSystemWeekArr(); //统计表数据 $uplist_arr[$i]['timetext'] = $tmp_weekarr[$i]; $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i]; //方便搜索会员列表,计算开始时间和结束时间 $currlist_arr[$i]['stime'] = strtotime($current_weekarr[0]) + ($i - 1) * 86400; $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i]; unset($tmp_weekarr); } $where['store_time'] = array('between', array($stime, $etime)); $field .= ',WEEKOFYEAR(FROM_UNIXTIME(store_time)) as weekval,WEEKDAY(FROM_UNIXTIME(store_time))+1 as dayofweekval '; $memberlist = $model->getNewStoreStatList($where, $field, 0, '', 0, 'weekval,dayofweekval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($up_week == $v['weekval']) { $up_arr[$v['dayofweekval']] = intval($v['allnum']); $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']); } if ($curr_week == $v['weekval']) { $curr_arr[$v['dayofweekval']] = intval($v['allnum']); $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']); } } } $stat_arr['series'][0]['name'] = '上周'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '本周'; $stat_arr['series'][1]['data'] = array_values($curr_arr); //统计数据标题 $statlist['headertitle'] = array('星期', '上周', '本周', '同比'); Tpl::output('actionurl', $actionurl . '&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 -1 month"); $etime = getMonthLastDay($current_year, $current_month) + 86400 - 1; $up_month = date('m', $stime); $curr_month = date('m', $etime); //计算横轴的最大量(由于每个月的天数不同) $up_dayofmonth = date('t', $stime); $curr_dayofmonth = date('t', $etime); $x_max = $up_dayofmonth > $curr_dayofmonth ? $up_dayofmonth : $curr_dayofmonth; //构造横轴数据 for ($i = 1; $i <= $x_max; $i++) { //统计图数据 $up_arr[$i] = 0; $curr_arr[$i] = 0; //统计表数据 $uplist_arr[$i]['timetext'] = $i; $currlist_arr[$i]['timetext'] = $i; //方便搜索会员列表,计算开始时间和结束时间 $currlist_arr[$i]['stime'] = strtotime($current_year . '-' . $current_month . "-01") + ($i - 1) * 86400; $currlist_arr[$i]['etime'] = $currlist_arr[$i]['stime'] + 86400 - 1; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = $i; } $where['store_time'] = array('between', array($stime, $etime)); $field .= ',MONTH(FROM_UNIXTIME(store_time)) as monthval,day(FROM_UNIXTIME(store_time)) as dayval '; $memberlist = $model->getNewStoreStatList($where, $field, 0, '', 0, 'monthval,dayval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($up_month == $v['monthval']) { $up_arr[$v['dayval']] = intval($v['allnum']); $uplist_arr[$v['dayval']]['val'] = intval($v['allnum']); } if ($curr_month == $v['monthval']) { $curr_arr[$v['dayval']] = intval($v['allnum']); $currlist_arr[$v['dayval']]['val'] = intval($v['allnum']); } } } $stat_arr['series'][0]['name'] = '上月'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '本月'; $stat_arr['series'][1]['data'] = array_values($curr_arr); //统计数据标题 $statlist['headertitle'] = array('日期', '上月', '本月', '同比'); Tpl::output('actionurl', $actionurl . '&search_type=month&search_time_year=' . $current_year . '&search_time_month=' . $current_month); } //计算同比 foreach ((array) $currlist_arr as $k => $v) { $tmp = array(); $tmp['seartime'] = $v['stime'] . '|' . $v['etime']; $tmp['timetext'] = $v['timetext']; $tmp['currentdata'] = $v['val']; $tmp['updata'] = $uplist_arr[$k]['val']; $tmp['tbrate'] = getTb($tmp['updata'], $tmp['currentdata']); $statlist['data'][] = $tmp; } //导出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 ($statlist['data'] as $k => $v) { $excel_data[$k + 1][] = array('data' => $v['timetext']); $excel_data[$k + 1][] = array('format' => 'Number', 'data' => $v['updata']); $excel_data[$k + 1][] = array('format' => 'Number', 'data' => $v['currentdata']); $excel_data[$k + 1][] = array('data' => $v['tbrate']); } $excel_data = $excel_obj->charset($excel_data, CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset('新增店铺统计', CHARSET)); $excel_obj->generateXML($excel_obj->charset('新增店铺统计', CHARSET) . date('Y-m-d-H', time())); exit; } else { //得到统计图数据 $stat_arr['title'] = '新增店铺统计'; $stat_arr['yAxis'] = '新增店铺数'; $stat_json = getStatData_LineLabels($stat_arr); Tpl::output('stat_json', $stat_json); Tpl::output('statlist', $statlist); Tpl::output('top_link', $this->sublink($this->links, 'newstore')); Tpl::showpage('stat.newstore'); } }
/** * 预存款统计 */ public function predepositOp() { $where = array(); if (trim($_GET['pd_type']) == 'cash_pay') { $field = 'sum(lg_freeze_amount) as allnum'; } else { $field = 'sum(lg_av_amount) as allnum'; } if (!$_REQUEST['search_type']) { $_REQUEST['search_type'] = 'day'; } $where['lg_type'] = trim($_GET['pd_type']) == '' ? 'recharge' : trim($_GET['pd_type']); //初始化时间 //天 if (!$_REQUEST['search_time']) { $_REQUEST['search_time'] = date('Y-m-d', time() - 86400); } $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'); $statlist = array(); //统计数据列表 if ($_REQUEST['search_type'] == 'day') { //构造横轴数据 for ($i = 0; $i < 24; $i++) { //统计图数据 $curr_arr[$i] = 0; //今天 $up_arr[$i] = 0; //昨天 //统计表数据 $uplist_arr[$i]['timetext'] = $i; $currlist_arr[$i]['timetext'] = $i; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = "{$i}"; } $stime = $search_time - 86400; //昨天0点 $etime = $search_time + 86400 - 1; //今天24点 $today_day = @date('d', $search_time); //今天日期 $yesterday_day = @date('d', $stime); //昨天日期 $where['lg_add_time'] = array('between', array($stime, $etime)); $field .= ' ,DAY(FROM_UNIXTIME(lg_add_time)) as dayval,HOUR(FROM_UNIXTIME(lg_add_time)) as hourval '; $memberlist = $model->getPredepositInfo($where, $field, 0, '', 0, 'dayval,hourval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($today_day == $v['dayval']) { $curr_arr[$v['hourval']] = abs($v['allnum']); $currlist_arr[$v['hourval']]['val'] = abs($v['allnum']); } if ($yesterday_day == $v['dayval']) { $up_arr[$v['hourval']] = abs($v['allnum']); $uplist_arr[$v['hourval']]['val'] = abs($v['allnum']); } } } $stat_arr['series'][0]['name'] = '昨天'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '今天'; $stat_arr['series'][1]['data'] = array_values($curr_arr); //统计数据标题 $statlist['headertitle'] = array('小时', '昨天', '今天', '同比'); Tpl::output('actionurl', 'index.php?act=stat_trade&op=predeposit&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; $up_week = @date('W', $stime); //上周 $curr_week = @date('W', $etime); //本周 //构造横轴数据 for ($i = 1; $i <= 7; $i++) { //统计图数据 $up_arr[$i] = 0; $curr_arr[$i] = 0; $tmp_weekarr = getSystemWeekArr(); //统计表数据 $uplist_arr[$i]['timetext'] = $tmp_weekarr[$i]; $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i]; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i]; unset($tmp_weekarr); } $where['lg_add_time'] = array('between', array($stime, $etime)); $field .= ',WEEKOFYEAR(FROM_UNIXTIME(lg_add_time)) as weekval,WEEKDAY(FROM_UNIXTIME(lg_add_time))+1 as dayofweekval '; $memberlist = $model->getPredepositInfo($where, $field, 0, '', 0, 'weekval,dayofweekval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($up_week == $v['weekval']) { $up_arr[$v['dayofweekval']] = abs($v['allnum']); $uplist_arr[$v['dayofweekval']]['val'] = abs($v['allnum']); } if ($curr_week == $v['weekval']) { $curr_arr[$v['dayofweekval']] = abs($v['allnum']); $currlist_arr[$v['dayofweekval']]['val'] = abs($v['allnum']); } } } $stat_arr['series'][0]['name'] = '上周'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '本周'; $stat_arr['series'][1]['data'] = array_values($curr_arr); //统计数据标题 $statlist['headertitle'] = array('星期', '上周', '本周', '同比'); Tpl::output('actionurl', 'index.php?act=stat_trade&op=predeposit&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 -1 month"); $etime = getMonthLastDay($current_year, $current_month) + 86400 - 1; $up_month = date('m', $stime); $curr_month = date('m', $etime); //计算横轴的最大量(由于每个月的天数不同) $up_dayofmonth = date('t', $stime); $curr_dayofmonth = date('t', $etime); $x_max = $up_dayofmonth > $curr_dayofmonth ? $up_dayofmonth : $curr_dayofmonth; //构造横轴数据 for ($i = 1; $i <= $x_max; $i++) { //统计图数据 $up_arr[$i] = 0; $curr_arr[$i] = 0; //统计表数据 $uplist_arr[$i]['timetext'] = $i; $currlist_arr[$i]['timetext'] = $i; $uplist_arr[$i]['val'] = 0; $currlist_arr[$i]['val'] = 0; //横轴 $stat_arr['xAxis']['categories'][] = $i; } $where['lg_add_time'] = array('between', array($stime, $etime)); $field .= ',MONTH(FROM_UNIXTIME(lg_add_time)) as monthval,day(FROM_UNIXTIME(lg_add_time)) as dayval '; $memberlist = $model->getPredepositInfo($where, $field, 0, '', 0, 'monthval,dayval'); if ($memberlist) { foreach ($memberlist as $k => $v) { if ($up_month == $v['monthval']) { $up_arr[$v['dayval']] = abs($v['allnum']); $uplist_arr[$v['dayval']]['val'] = abs($v['allnum']); } if ($curr_month == $v['monthval']) { $curr_arr[$v['dayval']] = abs($v['allnum']); $currlist_arr[$v['dayval']]['val'] = abs($v['allnum']); } } } $stat_arr['series'][0]['name'] = '上月'; $stat_arr['series'][0]['data'] = array_values($up_arr); $stat_arr['series'][1]['name'] = '本月'; $stat_arr['series'][1]['data'] = array_values($curr_arr); //统计数据标题 $statlist['headertitle'] = array('日期', '上月', '本月', '同比'); Tpl::output('actionurl', 'index.php?act=stat_trade&op=predeposit&search_type=month&search_time_year=' . $current_year . '&search_time_month=' . $current_month); } //计算同比 foreach ((array) $currlist_arr as $k => $v) { $tmp = array(); $tmp['timetext'] = $v['timetext']; $tmp['currentdata'] = $v['val']; $tmp['updata'] = $uplist_arr[$k]['val']; $tmp['tbrate'] = getTb($tmp['updata'], $tmp['currentdata']); $statlist['data'][] = $tmp; } //导出Excel if ($_GET['exporttype'] == 'excel') { //获取数据 $log_list = $model->getPredepositInfo($where, '*', ''); //导出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 $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' => '类型'); $excel_data[0][] = array('styleid' => 's_title', 'data' => '描述'); //data foreach ($log_list as $k => $v) { $excel_data[$k + 1][] = array('data' => $v['lg_member_name']); $excel_data[$k + 1][] = array('data' => date('Y-m-d H:i:s', $v['lg_add_time'])); $excel_data[$k + 1][] = array('data' => $v['lg_av_amount']); $excel_data[$k + 1][] = array('data' => $v['lg_freeze_amount']); $excel_data[$k + 1][] = array('data' => $v['lg_admin_name']); switch ($v['lg_type']) { case 'recharge': $excel_data[$k + 1][] = array('data' => '充值'); break; case 'order_pay': $excel_data[$k + 1][] = array('data' => '消费'); break; case 'cash_pay': $excel_data[$k + 1][] = array('data' => '提现'); break; case 'refund': $excel_data[$k + 1][] = array('data' => '退款'); break; } $excel_data[$k + 1][] = array('data' => $v['lg_desc']); } $excel_data = $excel_obj->charset($excel_data, CHARSET); $excel_obj->addArray($excel_data); $excel_obj->addWorksheet($excel_obj->charset('预存款统计', CHARSET)); $excel_obj->generateXML($excel_obj->charset('预存款统计', CHARSET) . date('Y-m-d-H', time())); exit; } else { $log_list = $model->getPredepositInfo($where, '*', 15); Tpl::output('log_list', $log_list); Tpl::output('show_page', $model->showpage()); //总数统计部分 $recharge_amount = $model->getPredepositInfo(array('lg_type' => 'recharge', 'lg_add_time' => array('between', array($stime, $etime))), 'sum(lg_av_amount) as allnum'); $order_amount = $model->getPredepositInfo(array('lg_type' => 'order_pay', 'lg_add_time' => array('between', array($stime, $etime))), 'sum(lg_av_amount) as allnum'); $cash_amount = $model->getPredepositInfo(array('lg_type' => 'cash_pay', 'lg_add_time' => array('between', array($stime, $etime))), 'sum(lg_freeze_amount) as allnum'); Tpl::output('stat_array', array('recharge_amount' => $recharge_amount[0]['allnum'], 'order_amount' => abs($order_amount[0]['allnum']), 'cash_amount' => abs($cash_amount[0]['allnum']))); $user_amount = $model->getPredepositInfo(true, 'distinct lg_member_id'); Tpl::output('user_amount', count($user_amount)); $usable_amount = $model->getPredepositInfo(true, 'sum(lg_av_amount+lg_freeze_amount) as allnum'); Tpl::output('usable_amount', $usable_amount[0]['allnum']); //得到统计图数据 $stat_arr['title'] = '预存款统计'; $stat_arr['yAxis'] = '金额'; $stat_json = getStatData_LineLabels($stat_arr); Tpl::output('stat_json', $stat_json); Tpl::output('statlist', $statlist); Tpl::output('top_link', $this->sublink($this->links, 'predeposit')); Tpl::showpage('stat.predeposit'); } }
/** * 店铺排行 */ 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'); } }