Esempio n. 1
0
 /**
  * 退款统计
  */
 public function refundOp()
 {
     $where = array();
     if (!$this->search_arr['search_type']) {
         $this->search_arr['search_type'] = 'day';
     }
     $model = Model('stat');
     //获得搜索的开始时间和结束时间
     $searchtime_arr = $model->getStarttimeAndEndtime($this->search_arr);
     $field = ' SUM(refund_amount) as amount ';
     if ($this->search_arr['search_type'] == 'day') {
         //构造横轴数据
         for ($i = 0; $i < 24; $i++) {
             $stat_arr['xAxis']['categories'][] = "{$i}";
             $statlist[$i] = 0;
         }
         $field .= ' ,HOUR(FROM_UNIXTIME(add_time)) as timeval ';
     }
     if ($this->search_arr['search_type'] == 'week') {
         //构造横轴数据
         for ($i = 1; $i <= 7; $i++) {
             $tmp_weekarr = uk86_getSystemWeekArr();
             //横轴
             $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
             unset($tmp_weekarr);
             $statlist[$i] = 0;
         }
         $field .= ' ,WEEKDAY(FROM_UNIXTIME(add_time))+1 as timeval ';
     }
     if ($this->search_arr['search_type'] == 'month') {
         //计算横轴的最大量(由于每个月的天数不同)
         $dayofmonth = date('t', $searchtime_arr[0]);
         //构造横轴数据
         for ($i = 1; $i <= $dayofmonth; $i++) {
             //横轴
             $stat_arr['xAxis']['categories'][] = $i;
             $statlist[$i] = 0;
         }
         $field .= ' ,day(FROM_UNIXTIME(add_time)) as timeval ';
     }
     $where = array();
     $where['add_time'] = array('between', $searchtime_arr);
     $statlist_tmp = $model->statByRefundreturn($where, $field, 0, 0, 'timeval asc', 'timeval');
     if ($statlist_tmp) {
         foreach ((array) $statlist_tmp as $k => $v) {
             $statlist[$v['timeval']] = floatval($v['amount']);
         }
     }
     //得到统计图数据
     $stat_arr['legend']['enabled'] = false;
     $stat_arr['series'][0]['name'] = '退款金额';
     $stat_arr['series'][0]['data'] = array_values($statlist);
     $stat_arr['title'] = '退款金额统计';
     $stat_arr['yAxis'] = '金额';
     $stat_json = uk86_getStatData_LineLabels($stat_arr);
     Tpl::output('stat_json', $stat_json);
     Tpl::output('searchtime', implode('|', $searchtime_arr));
     Tpl::output('top_link', $this->sublink($this->links, 'refund'));
     Tpl::showpage('stat.aftersale.refund');
 }
Esempio n. 2
0
 /**
  * 店铺流量统计
  */
 public function storeflowOp()
 {
     $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'] = 'sum';
     $field = ' SUM(clicknum) as amount';
     if ($this->search_arr['search_type'] == 'week') {
         //构造横轴数据
         for ($i = 1; $i <= 7; $i++) {
             $tmp_weekarr = uk86_getSystemWeekArr();
             //横轴
             $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
             unset($tmp_weekarr);
             $statlist[$i] = 0;
         }
         $field .= ' ,WEEKDAY(FROM_UNIXTIME(stattime))+1 as timeval ';
     }
     if ($this->search_arr['search_type'] == 'month') {
         //计算横轴的最大量(由于每个月的天数不同)
         $dayofmonth = date('t', $searchtime_arr[0]);
         //构造横轴数据
         for ($i = 1; $i <= $dayofmonth; $i++) {
             //横轴
             $stat_arr['xAxis']['categories'][] = $i;
             $statlist[$i] = 0;
         }
         $field .= ' ,day(FROM_UNIXTIME(stattime)) as timeval ';
     }
     $statlist_tmp = $model->statByFlowstat($flow_tablename, $where, $field, 0, 0, 'timeval asc', 'timeval');
     if ($statlist_tmp) {
         foreach ((array) $statlist_tmp as $k => $v) {
             $statlist[$v['timeval']] = floatval($v['amount']);
         }
     }
     //得到统计图数据
     $stat_arr['legend']['enabled'] = false;
     $stat_arr['series'][0]['name'] = '访问量';
     $stat_arr['series'][0]['data'] = array_values($statlist);
     $stat_arr['title'] = '店铺访问量统计';
     $stat_arr['yAxis'] = '访问次数';
     $stat_json = uk86_getStatData_LineLabels($stat_arr);
     Tpl::output('stat_json', $stat_json);
     self::profile_menu('storeflow');
     Tpl::showpage('stat.flow.store');
 }
Esempio n. 3
0
 /**
  * 销售统计
  */
 public function saleOp()
 {
     $model = Model('stat');
     //默认统计当前数据
     if (!$this->search_arr['search_type']) {
         $this->search_arr['search_type'] = 'day';
     }
     //计算昨天和今天时间
     if ($this->search_arr['search_type'] == 'day') {
         $stime = $this->search_arr['day']['search_time'] - 86400;
         //昨天0点
         $etime = $this->search_arr['day']['search_time'] + 86400 - 1;
         //今天24点
         $curr_stime = $this->search_arr['day']['search_time'];
         //今天0点
     } elseif ($this->search_arr['search_type'] == 'week') {
         $current_weekarr = explode('|', $this->search_arr['week']['current_week']);
         $stime = strtotime($current_weekarr[0]) - 86400 * 7;
         $etime = strtotime($current_weekarr[1]) + 86400 - 1;
         $curr_stime = strtotime($current_weekarr[0]);
         //本周0点
     } elseif ($this->search_arr['search_type'] == 'month') {
         $stime = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01 -1 month");
         $etime = uk86_getMonthLastDay($this->search_arr['month']['current_year'], $this->search_arr['month']['current_month']) + 86400 - 1;
         $curr_stime = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01");
         //本月0点
     }
     $where = array();
     $where['store_id'] = $_SESSION['store_id'];
     $where['order_add_time'] = array('between', array($stime, $etime));
     if (trim($_GET['order_type']) != '') {
         $where['order_state'] = trim($_GET['order_type']);
     }
     //走势图
     $field = ' COUNT(*) as ordernum,SUM(order_amount) as orderamount ';
     $stat_arr = array();
     //$searchtime_arr = array($stime,$etime);
     if ($this->search_arr['search_type'] == 'day') {
         //构造横轴数据
         for ($i = 0; $i < 24; $i++) {
             //统计图数据
             $curr_arr['orderamount'][$i] = 0;
             //今天
             $up_arr['orderamount'][$i] = 0;
             //昨天
             $curr_arr['ordernum'][$i] = 0;
             //今天
             $up_arr['ordernum'][$i] = 0;
             //昨天
             //统计表数据
             $currlist_arr[$i]['timetext'] = $i;
             $uplist_arr[$i]['val'] = 0;
             $currlist_arr[$i]['val'] = 0;
             //横轴
             $stat_arr['orderamount']['xAxis']['categories'][] = "{$i}";
             $stat_arr['ordernum']['xAxis']['categories'][] = "{$i}";
         }
         $today_day = @date('d', $etime);
         //今天日期
         $yesterday_day = @date('d', $stime);
         //昨天日期
         $field .= ' ,DAY(FROM_UNIXTIME(order_add_time)) as dayval,HOUR(FROM_UNIXTIME(order_add_time)) as hourval ';
         $orderlist = $model->statByStatorder($where, $field, 0, 0, '', 'dayval,hourval');
         foreach ((array) $orderlist as $k => $v) {
             if ($today_day == $v['dayval']) {
                 $curr_arr['ordernum'][$v['hourval']] = intval($v['ordernum']);
                 $curr_arr['orderamount'][$v['hourval']] = floatval($v['orderamount']);
                 $currlist_arr[$v['hourval']]['val'] = $v[$search_type];
             }
             if ($yesterday_day == $v['dayval']) {
                 $up_arr['ordernum'][$v['hourval']] = intval($v['ordernum']);
                 $up_arr['orderamount'][$v['hourval']] = floatval($v['orderamount']);
                 $uplist_arr[$v['hourval']]['val'] = $v[$search_type];
             }
         }
         $stat_arr['ordernum']['series'][0]['name'] = '昨天';
         $stat_arr['ordernum']['series'][0]['data'] = array_values($up_arr['ordernum']);
         $stat_arr['ordernum']['series'][1]['name'] = '今天';
         $stat_arr['ordernum']['series'][1]['data'] = array_values($curr_arr['ordernum']);
         $stat_arr['orderamount']['series'][0]['name'] = '昨天';
         $stat_arr['orderamount']['series'][0]['data'] = array_values($up_arr['orderamount']);
         $stat_arr['orderamount']['series'][1]['name'] = '今天';
         $stat_arr['orderamount']['series'][1]['data'] = array_values($curr_arr['orderamount']);
     }
     if ($this->search_arr['search_type'] == 'week') {
         $up_week = @date('W', $stime);
         //上周
         $curr_week = @date('W', $etime);
         //本周
         //构造横轴数据
         for ($i = 1; $i <= 7; $i++) {
             $tmp_weekarr = uk86_getSystemWeekArr();
             //统计图数据
             $up_arr['ordernum'][$i] = 0;
             $curr_arr['ordernum'][$i] = 0;
             $up_arr['orderamount'][$i] = 0;
             $curr_arr['orderamount'][$i] = 0;
             //横轴
             $stat_arr['ordernum']['xAxis']['categories'][] = $tmp_weekarr[$i];
             $stat_arr['orderamount']['xAxis']['categories'][] = $tmp_weekarr[$i];
             //统计表数据
             $uplist_arr[$i]['timetext'] = $tmp_weekarr[$i];
             $currlist_arr[$i]['timetext'] = $tmp_weekarr[$i];
             $uplist_arr[$i]['val'] = 0;
             $currlist_arr[$i]['val'] = 0;
             unset($tmp_weekarr);
         }
         $field .= ',WEEKOFYEAR(FROM_UNIXTIME(order_add_time)) as weekval,WEEKDAY(FROM_UNIXTIME(order_add_time))+1 as dayofweekval ';
         $orderlist = $model->statByStatorder($where, $field, 0, 0, '', 'weekval,dayofweekval');
         foreach ((array) $orderlist as $k => $v) {
             if ($up_week == $v['weekval']) {
                 $up_arr['ordernum'][$v['dayofweekval']] = intval($v['ordernum']);
                 $up_arr['orderamount'][$v['dayofweekval']] = intval($v['orderamount']);
                 $uplist_arr[$v['dayofweekval']]['val'] = intval($v[$search_type]);
             }
             if ($curr_week == $v['weekval']) {
                 $curr_arr['ordernum'][$v['dayofweekval']] = intval($v['ordernum']);
                 $curr_arr['orderamount'][$v['dayofweekval']] = intval($v['orderamount']);
                 $currlist_arr[$v['dayofweekval']]['val'] = intval($v[$search_type]);
             }
         }
         $stat_arr['ordernum']['series'][0]['name'] = '上周';
         $stat_arr['ordernum']['series'][0]['data'] = array_values($up_arr['ordernum']);
         $stat_arr['ordernum']['series'][1]['name'] = '本周';
         $stat_arr['ordernum']['series'][1]['data'] = array_values($curr_arr['ordernum']);
         $stat_arr['orderamount']['series'][0]['name'] = '上周';
         $stat_arr['orderamount']['series'][0]['data'] = array_values($up_arr['orderamount']);
         $stat_arr['orderamount']['series'][1]['name'] = '本周';
         $stat_arr['orderamount']['series'][1]['data'] = array_values($curr_arr['orderamount']);
     }
     if ($this->search_arr['search_type'] == 'month') {
         $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['ordernum'][$i] = 0;
             $curr_arr['ordernum'][$i] = 0;
             $up_arr['orderamount'][$i] = 0;
             $curr_arr['orderamount'][$i] = 0;
             //横轴
             $stat_arr['ordernum']['xAxis']['categories'][] = $i;
             $stat_arr['orderamount']['xAxis']['categories'][] = $i;
             //统计表数据
             $currlist_arr[$i]['timetext'] = $i;
             $uplist_arr[$i]['val'] = 0;
             $currlist_arr[$i]['val'] = 0;
         }
         $field .= ',MONTH(FROM_UNIXTIME(order_add_time)) as monthval,day(FROM_UNIXTIME(order_add_time)) as dayval ';
         $orderlist = $model->statByStatorder($where, $field, 0, 0, '', 'monthval,dayval');
         foreach ($orderlist as $k => $v) {
             if ($up_month == $v['monthval']) {
                 $up_arr['ordernum'][$v['dayval']] = intval($v['ordernum']);
                 $up_arr['orderamount'][$v['dayval']] = floatval($v['orderamount']);
                 $uplist_arr[$v['dayval']]['val'] = intval($v[$search_type]);
             }
             if ($curr_month == $v['monthval']) {
                 $curr_arr['ordernum'][$v['dayval']] = intval($v['ordernum']);
                 $curr_arr['orderamount'][$v['dayval']] = intval($v['orderamount']);
                 $currlist_arr[$v['dayval']]['val'] = intval($v[$search_type]);
             }
         }
         $stat_arr['ordernum']['series'][0]['name'] = '上月';
         $stat_arr['ordernum']['series'][0]['data'] = array_values($up_arr['ordernum']);
         $stat_arr['ordernum']['series'][1]['name'] = '本月';
         $stat_arr['ordernum']['series'][1]['data'] = array_values($curr_arr['ordernum']);
         $stat_arr['orderamount']['series'][0]['name'] = '上月';
         $stat_arr['orderamount']['series'][0]['data'] = array_values($up_arr['orderamount']);
         $stat_arr['orderamount']['series'][1]['name'] = '本月';
         $stat_arr['orderamount']['series'][1]['data'] = array_values($curr_arr['orderamount']);
     }
     $stat_arr['ordernum']['title'] = '订单量统计';
     $stat_arr['ordernum']['yAxis'] = '订单量';
     $stat_arr['orderamount']['title'] = '下单金额统计';
     $stat_arr['orderamount']['yAxis'] = '下单金额';
     $stat_json['ordernum'] = uk86_getStatData_LineLabels($stat_arr['ordernum']);
     $stat_json['orderamount'] = uk86_getStatData_LineLabels($stat_arr['orderamount']);
     Tpl::output('stat_json', $stat_json);
     Tpl::output('stattype', $search_type);
     //总数统计
     $where['order_add_time'] = array('between', array($curr_stime, $etime));
     $statcount_arr = $model->getoneByStatorder($where, ' COUNT(*) as ordernum, SUM(order_amount) as orderamount');
     $statcount_arr['ordernum'] = ($t = intval($statcount_arr['ordernum'])) > 0 ? $t : 0;
     $statcount_arr['orderamount'] = uk86_ncPriceFormat(($t = floatval($statcount_arr['orderamount'])) > 0 ? $t : 0);
     Tpl::output('statcount_arr', $statcount_arr);
     Tpl::output('searchtime', implode('|', array($curr_stime, $etime)));
     Tpl::output('show_page', $model->showpage(2));
     self::profile_menu('sale');
     Tpl::showpage('stat.sale.index');
 }
Esempio n. 4
0
 /**
  * 销售走势
  */
 public function storesales_trendsOp()
 {
     $storeid = intval($_GET['storeid']);
     if ($storeid <= 0) {
         Tpl::output('stat_error', '走势图加载错误');
         Tpl::showpage('stat.store.salestrends');
         exit;
     }
     if (!$_GET['search_type']) {
         $_GET['search_type'] = 'day';
     }
     $model = Model('stat');
     $where = array();
     $where['store_id'] = $storeid;
     $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
     foreach ((array) $searchtime_arr_tmp as $k => $v) {
         $searchtime_arr[] = intval($v);
     }
     $where['order_isvalid'] = 1;
     //计入统计的有效订单
     $where['order_add_time'] = array('between', $searchtime_arr);
     $field = " store_id,store_name,SUM(order_amount) as orderamount, COUNT(*) as ordernum, COUNT(DISTINCT buyer_id) as membernum";
     $stat_arr = array('orderamount' => array(), 'ordernum' => array(), 'membernum' => array());
     $statlist = array();
     if ($_GET['search_type'] == 'day') {
         //构造横轴数据
         for ($i = 0; $i < 24; $i++) {
             //横轴
             foreach ($stat_arr as $k => $v) {
                 $stat_arr[$k]['xAxis']['categories'][] = "{$i}";
                 $statlist[$k][$i] = 0;
             }
         }
         $field .= ' ,HOUR(FROM_UNIXTIME(order_add_time)) as timeval ';
     }
     if ($_GET['search_type'] == 'week') {
         //构造横轴数据
         for ($i = 1; $i <= 7; $i++) {
             $tmp_weekarr = uk86_getSystemWeekArr();
             //横轴
             foreach ($stat_arr as $k => $v) {
                 $stat_arr[$k]['xAxis']['categories'][] = $tmp_weekarr[$i];
                 $statlist[$k][$i] = 0;
             }
             unset($tmp_weekarr);
         }
         $field .= ' ,WEEKDAY(FROM_UNIXTIME(order_add_time))+1 as timeval ';
     }
     if ($_GET['search_type'] == 'month') {
         //计算横轴的最大量(由于每个月的天数不同)
         $dayofmonth = date('t', $searchtime_arr[0]);
         //构造横轴数据
         for ($i = 1; $i <= $dayofmonth; $i++) {
             //横轴
             foreach ($stat_arr as $k => $v) {
                 $stat_arr[$k]['xAxis']['categories'][] = $i;
                 $statlist[$k][$i] = 0;
             }
         }
         $field .= ' ,day(FROM_UNIXTIME(order_add_time)) as timeval ';
     }
     //查询数据
     $statlist_tmp = $model->statByStatorder($where, $field, 0, '', 'timeval', 'timeval');
     //整理统计数组
     $storename = '';
     if ($statlist_tmp) {
         foreach ($statlist_tmp as $k => $v) {
             $storename = $v['store_name'];
             foreach ($stat_arr as $t_k => $t_v) {
                 if ($k == 'orderamount') {
                     $statlist[$t_k][$v['timeval']] = round($v[$t_k], 2);
                 } else {
                     $statlist[$t_k][$v['timeval']] = intval($v[$t_k]);
                 }
             }
         }
     }
     foreach ($stat_arr as $k => $v) {
         $stat_arr[$k]['legend']['enabled'] = false;
         switch ($k) {
             case 'orderamount':
                 $caption = '下单金额';
                 break;
             case 'ordernum':
                 $caption = '下单量';
                 break;
             default:
                 $caption = '下单会员数';
                 break;
         }
         $stat_arr[$k]['series'][0]['name'] = $caption;
         $stat_arr[$k]['series'][0]['data'] = array_values($statlist[$k]);
         $stat_arr[$k]['title'] = $caption . '走势';
         $stat_arr[$k]['yAxis'] = $caption;
         //得到统计图数据
         $stat_json[$k] = uk86_getStatData_LineLabels($stat_arr[$k]);
     }
     Tpl::output('storename', $storename);
     Tpl::output('stat_json', $stat_json);
     Tpl::showpage('stat.store.salestrends', 'null_layout');
 }
Esempio n. 5
0
 /**
  * 订单走势
  */
 public function sale_trendOp()
 {
     $model = Model('stat');
     //存储参数
     $this->search_arr = $_REQUEST;
     //默认统计当前数据
     if (!$this->search_arr['search_type']) {
         $this->search_arr['search_type'] = 'day';
     }
     $where = array();
     if (trim($_GET['order_state']) != '') {
         $where['order_state'] = trim($_GET['order_state']);
     }
     if (trim($_GET['store_name']) != '') {
         $where['store_name'] = array('like', '%' . trim($_GET['store_name']) . '%');
     }
     $stattype = trim($_GET['type']);
     if ($stattype == 'ordernum') {
         $field = ' COUNT(*) as ordernum ';
         $stat_arr['title'] = '订单量统计';
         $stat_arr['yAxis'] = '订单量';
     } else {
         $stattype = 'orderamount';
         $field = ' SUM(order_amount) as orderamount ';
         $stat_arr['title'] = '订单销售额统计';
         $stat_arr['yAxis'] = '订单销售额';
     }
     $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
     foreach ((array) $searchtime_arr_tmp as $k => $v) {
         $searchtime_arr[] = intval($v);
     }
     if ($this->search_arr['search_type'] == 'day') {
         //构造横轴数据
         for ($i = 0; $i < 24; $i++) {
             //统计图数据
             $curr_arr[$i] = 0;
             //今天
             $up_arr[$i] = 0;
             //昨天
             //统计表数据
             $currlist_arr[$i]['timetext'] = $i;
             $uplist_arr[$i]['val'] = 0;
             $currlist_arr[$i]['val'] = 0;
             //横轴
             $stat_arr['xAxis']['categories'][] = "{$i}";
         }
         $today_day = @date('d', $searchtime_arr[1]);
         //今天日期
         $yesterday_day = @date('d', $searchtime_arr[0]);
         //昨天日期
         $where['order_add_time'] = array('between', $searchtime_arr);
         $field .= ' ,DAY(FROM_UNIXTIME(order_add_time)) as dayval,HOUR(FROM_UNIXTIME(order_add_time)) as hourval ';
         $orderlist = $model->statByStatorder($where, $field, 0, 0, '', 'dayval,hourval');
         foreach ((array) $orderlist as $k => $v) {
             if ($today_day == $v['dayval']) {
                 $curr_arr[$v['hourval']] = intval($v[$stattype]);
                 $currlist_arr[$v['hourval']]['val'] = $v[$stattype];
             }
             if ($yesterday_day == $v['dayval']) {
                 $up_arr[$v['hourval']] = intval($v[$stattype]);
                 $uplist_arr[$v['hourval']]['val'] = $v[$stattype];
             }
         }
         $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);
     }
     if ($this->search_arr['search_type'] == 'week') {
         $up_week = @date('W', $searchtime_arr[0]);
         //上周
         $curr_week = @date('W', $searchtime_arr[1]);
         //本周
         //构造横轴数据
         for ($i = 1; $i <= 7; $i++) {
             //统计图数据
             $up_arr[$i] = 0;
             $curr_arr[$i] = 0;
             $tmp_weekarr = uk86_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['order_add_time'] = array('between', $searchtime_arr);
         $field .= ',WEEKOFYEAR(FROM_UNIXTIME(order_add_time)) as weekval,WEEKDAY(FROM_UNIXTIME(order_add_time))+1 as dayofweekval ';
         $orderlist = $model->statByStatorder($where, $field, 0, 0, '', 'weekval,dayofweekval');
         foreach ((array) $orderlist as $k => $v) {
             if ($up_week == $v['weekval']) {
                 $up_arr[$v['dayofweekval']] = intval($v[$stattype]);
                 $uplist_arr[$v['dayofweekval']]['val'] = intval($v[$stattype]);
             }
             if ($curr_week == $v['weekval']) {
                 $curr_arr[$v['dayofweekval']] = intval($v[$stattype]);
                 $currlist_arr[$v['dayofweekval']]['val'] = intval($v[$stattype]);
             }
         }
         $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);
     }
     if ($this->search_arr['search_type'] == 'month') {
         $up_month = date('m', $searchtime_arr[0]);
         $curr_month = date('m', $searchtime_arr[1]);
         //计算横轴的最大量(由于每个月的天数不同)
         $up_dayofmonth = date('t', $searchtime_arr[0]);
         $curr_dayofmonth = date('t', $searchtime_arr[1]);
         $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;
             //统计表数据
             $currlist_arr[$i]['timetext'] = $i;
             $uplist_arr[$i]['val'] = 0;
             $currlist_arr[$i]['val'] = 0;
             //横轴
             $stat_arr['xAxis']['categories'][] = $i;
         }
         $where['order_add_time'] = array('between', array($searchtime_arr[0], $searchtime_arr[1]));
         $field .= ',MONTH(FROM_UNIXTIME(order_add_time)) as monthval,day(FROM_UNIXTIME(order_add_time)) as dayval ';
         $orderlist = $model->statByStatorder($where, $field, 0, 0, '', 'monthval,dayval');
         foreach ($orderlist as $k => $v) {
             if ($up_month == $v['monthval']) {
                 $up_arr[$v['dayval']] = intval($v[$stattype]);
                 $uplist_arr[$v['dayval']]['val'] = intval($v[$stattype]);
             }
             if ($curr_month == $v['monthval']) {
                 $curr_arr[$v['dayval']] = intval($v[$stattype]);
                 $currlist_arr[$v['dayval']]['val'] = intval($v[$stattype]);
             }
         }
         $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);
     }
     $stat_json = uk86_getStatData_LineLabels($stat_arr);
     Tpl::output('stat_json', $stat_json);
     Tpl::output('stattype', $stattype);
     Tpl::showpage('stat.linelabels', 'null_layout');
 }
Esempio n. 6
0
 /**
  * 新增会员
  */
 public function newmemberOp()
 {
     if (!$this->search_arr['search_type']) {
         $this->search_arr['search_type'] = 'day';
     }
     $model = Model('stat');
     $statlist = array();
     //统计数据列表
     //新增总数数组
     $count_arr = array('up' => 0, 'curr' => 0);
     $where = array();
     $field = ' COUNT(*) as allnum ';
     if ($this->search_arr['search_type'] == 'day') {
         //构造横轴数据
         for ($i = 0; $i < 24; $i++) {
             //统计图数据
             $curr_arr[$i] = 0;
             //今天
             $up_arr[$i] = 0;
             //昨天
             //统计表数据
             $currlist_arr[$i]['timetext'] = $i;
             //方便搜索会员列表,计算开始时间和结束时间
             $currlist_arr[$i]['stime'] = $this->search_arr['day']['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 = $this->search_arr['day']['search_time'] - 86400;
         //昨天0点
         $etime = $this->search_arr['day']['search_time'] + 86400 - 1;
         //今天24点
         //总计的查询时间
         $count_arr['seartime'] = $stime + 86400 . '|' . $etime;
         $today_day = @date('d', $this->search_arr['day']['search_time']);
         //今天日期
         $yesterday_day = @date('d', $stime);
         //昨天日期
         $where['member_time'] = array('between', array($stime, $etime));
         $field .= ' ,DAY(FROM_UNIXTIME(member_time)) as dayval,HOUR(FROM_UNIXTIME(member_time)) as hourval ';
         $memberlist = $model->statByMember($where, $field, 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']);
                     $count_arr['curr'] += intval($v['allnum']);
                 }
                 if ($yesterday_day == $v['dayval']) {
                     $up_arr[$v['hourval']] = intval($v['allnum']);
                     $uplist_arr[$v['hourval']]['val'] = intval($v['allnum']);
                     $count_arr['up'] += 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', 'index.php?act=stat_member&op=newmember&search_type=day&search_time=' . date('Y-m-d', $this->search_arr['day']['search_time']));
     }
     if ($this->search_arr['search_type'] == 'week') {
         $current_weekarr = explode('|', $this->search_arr['week']['current_week']);
         $stime = strtotime($current_weekarr[0]) - 86400 * 7;
         $etime = strtotime($current_weekarr[1]) + 86400 - 1;
         //总计的查询时间
         $count_arr['seartime'] = $stime + 86400 * 7 . '|' . $etime;
         $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 = uk86_getSystemWeekArr();
             //统计表数据
             $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['member_time'] = array('between', array($stime, $etime));
         $field .= ',WEEKOFYEAR(FROM_UNIXTIME(member_time)) as weekval,WEEKDAY(FROM_UNIXTIME(member_time))+1 as dayofweekval ';
         $memberlist = $model->statByMember($where, $field, 0, '', 'weekval,dayofweekval');
         if ($memberlist) {
             foreach ($memberlist as $k => $v) {
                 if ($up_week == intval($v['weekval'])) {
                     $up_arr[$v['dayofweekval']] = intval($v['allnum']);
                     $uplist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
                     $count_arr['up'] += intval($v['allnum']);
                 }
                 if ($curr_week == $v['weekval']) {
                     $curr_arr[$v['dayofweekval']] = intval($v['allnum']);
                     $currlist_arr[$v['dayofweekval']]['val'] = intval($v['allnum']);
                     $count_arr['curr'] += 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', 'index.php?act=stat_member&op=newmember&search_type=week&searchweek_year=' . $this->search_arr['week']['current_year'] . '&searchweek_month=' . $this->search_arr['week']['current_month'] . '&searchweek_week=' . $this->search_arr['week']['current_week']);
     }
     if ($this->search_arr['search_type'] == 'month') {
         $stime = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01 -1 month");
         $etime = uk86_getMonthLastDay($this->search_arr['month']['current_year'], $this->search_arr['month']['current_month']) + 86400 - 1;
         //总计的查询时间
         $count_arr['seartime'] = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['current_month'] . "-01") . '|' . $etime;
         $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;
             //统计表数据
             $currlist_arr[$i]['timetext'] = $i;
             //方便搜索会员列表,计算开始时间和结束时间
             $currlist_arr[$i]['stime'] = strtotime($this->search_arr['month']['current_year'] . '-' . $this->search_arr['month']['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;
             unset($tmp_montharr);
         }
         $where['member_time'] = array('between', array($stime, $etime));
         $field .= ',MONTH(FROM_UNIXTIME(member_time)) as monthval,day(FROM_UNIXTIME(member_time)) as dayval ';
         $memberlist = $model->statByMember($where, $field, 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']);
                     $count_arr['up'] += intval($v['allnum']);
                 }
                 if ($curr_month == $v['monthval']) {
                     $curr_arr[$v['dayval']] = intval($v['allnum']);
                     $currlist_arr[$v['dayval']]['val'] = intval($v['allnum']);
                     $count_arr['curr'] += 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', 'index.php?act=stat_member&op=newmember&search_type=month&searchmonth_year=' . $this->search_arr['month']['current_year'] . '&searchmonth_month=' . $this->search_arr['month']['current_month']);
     }
     //计算同比
     foreach ((array) $currlist_arr as $k => $v) {
         $tmp = array();
         $tmp['timetext'] = $v['timetext'];
         $tmp['seartime'] = $v['stime'] . '|' . $v['etime'];
         $tmp['currentdata'] = $v['val'];
         $tmp['updata'] = $uplist_arr[$k]['val'];
         $tmp['tbrate'] = uk86_getTb($tmp['updata'], $tmp['currentdata']);
         $statlist['data'][] = $tmp;
     }
     //计算总结同比
     $count_arr['tbrate'] = uk86_getTb($count_arr['up'], $count_arr['curr']);
     //导出Excel
     if ($_GET['exporttype'] == 'excel') {
         //导出Excel
         uk86_import('libraries.uk86excel');
         $excel_obj = new Uk86Excel();
         $excel_data = array();
         //设置样式
         $excel_obj->uk86_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[count($statlist['data']) + 1][] = array('data' => '总计');
         $excel_data[count($statlist['data']) + 1][] = array('format' => 'Number', 'data' => $count_arr['up']);
         $excel_data[count($statlist['data']) + 1][] = array('format' => 'Number', 'data' => $count_arr['curr']);
         $excel_data[count($statlist['data']) + 1][] = array('data' => $count_arr['tbrate']);
         $excel_data = $excel_obj->uk86_charset($excel_data, CHARSET);
         $excel_obj->uk86_addArray($excel_data);
         $excel_obj->uk86_addWorksheet($excel_obj->uk86_charset('新增会员统计', CHARSET));
         $excel_obj->uk86_generateXML($excel_obj->uk86_charset('新增会员统计', CHARSET) . date('Y-m-d-H', time()));
         exit;
     } else {
         //得到统计图数据
         $stat_arr['title'] = '新增会员统计';
         $stat_arr['yAxis'] = '新增会员数';
         $stat_json = uk86_getStatData_LineLabels($stat_arr);
         Tpl::output('stat_json', $stat_json);
         Tpl::output('statlist', $statlist);
         Tpl::output('count_arr', $count_arr);
         Tpl::output('top_link', $this->sublink($this->links, 'newmember'));
         Tpl::showpage('stat.newmember');
     }
 }
Esempio n. 7
0
 /**
  * 促销销售趋势分析
  */
 public function promotiontrendOp()
 {
     //优惠类型数组
     $goodstype_arr = array(2 => '抢购', 3 => '限时折扣', 4 => '优惠套装');
     $model = Model('stat');
     $where = array();
     $searchtime_arr_tmp = explode('|', $this->search_arr['t']);
     foreach ((array) $searchtime_arr_tmp as $k => $v) {
         $searchtime_arr[] = intval($v);
     }
     $where['order_isvalid'] = 1;
     //计入统计的有效订单
     $where['order_add_time'] = array('between', $searchtime_arr);
     $where['goods_type'] = array('in', array(2, 3, 4));
     $field = ' goods_type';
     switch ($this->search_arr['stattype']) {
         case 'orderamount':
             $field .= " ,SUM(goods_pay_price) as orderamount";
             $caption = '下单金额';
             break;
         case 'goodsnum':
             $field .= " ,SUM(goods_num) as goodsnum";
             $caption = '下单商品数';
             break;
         default:
             $field .= " ,count(DISTINCT order_id) as ordernum";
             $caption = '下单量';
             break;
     }
     if ($this->search_arr['search_type'] == 'day') {
         //构造横轴数据
         for ($i = 0; $i < 24; $i++) {
             //横轴
             $stat_arr['xAxis']['categories'][] = "{$i}";
             foreach ($goodstype_arr as $k => $v) {
                 $statlist[$k][$i] = 0;
             }
         }
         $field .= ' ,HOUR(FROM_UNIXTIME(order_add_time)) as timeval ';
     }
     if ($this->search_arr['search_type'] == 'week') {
         //构造横轴数据
         for ($i = 1; $i <= 7; $i++) {
             $tmp_weekarr = uk86_getSystemWeekArr();
             //横轴
             $stat_arr['xAxis']['categories'][] = $tmp_weekarr[$i];
             unset($tmp_weekarr);
             foreach ($goodstype_arr as $k => $v) {
                 $statlist[$k][$i] = 0;
             }
         }
         $field .= ' ,WEEKDAY(FROM_UNIXTIME(order_add_time))+1 as timeval ';
     }
     if ($this->search_arr['search_type'] == 'month') {
         //计算横轴的最大量(由于每个月的天数不同)
         $dayofmonth = date('t', $searchtime_arr[0]);
         //构造横轴数据
         for ($i = 1; $i <= $dayofmonth; $i++) {
             //横轴
             $stat_arr['xAxis']['categories'][] = $i;
             foreach ($goodstype_arr as $k => $v) {
                 $statlist[$k][$i] = 0;
             }
         }
         $field .= ' ,day(FROM_UNIXTIME(order_add_time)) as timeval ';
     }
     //查询数据
     $statlist_tmp = $model->statByStatordergoods($where, $field, 0, 0, 'timeval', 'goods_type,timeval');
     //整理统计数组
     if ($statlist_tmp) {
         foreach ($statlist_tmp as $k => $v) {
             //将数据按照不同的促销方式分组
             foreach ($goodstype_arr as $t_k => $t_v) {
                 if ($t_k == $v['goods_type']) {
                     switch ($this->search_arr['stattype']) {
                         case 'orderamount':
                             $statlist[$t_k][$v['timeval']] = round($v[$this->search_arr['stattype']], 2);
                             break;
                         case 'goodsnum':
                             $statlist[$t_k][$v['timeval']] = intval($v[$this->search_arr['stattype']]);
                             break;
                         default:
                             $statlist[$t_k][$v['timeval']] = intval($v[$this->search_arr['stattype']]);
                             break;
                     }
                 }
             }
         }
     }
     foreach ($goodstype_arr as $k => $v) {
         $tmp = array();
         $tmp['name'] = $v;
         $tmp['data'] = array_values($statlist[$k]);
         $stat_arr['series'][] = $tmp;
     }
     //得到统计图数据
     $stat_arr['title'] = $caption . '统计';
     $stat_arr['yAxis'] = $caption;
     $stat_json = uk86_getStatData_LineLabels($stat_arr);
     Tpl::output('stat_json', $stat_json);
     Tpl::output('stattype', $_GET['stattype']);
     Tpl::showpage('stat.linelabels', 'null_layout');
 }