/** * 促销分析 */ public function promotionOp() { 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['goods_type'] = array('in', array(2, 3, 4)); //下单量 $field = ' goods_type,count(DISTINCT order_id) as ordernum,SUM(goods_num) as goodsnum,SUM(goods_pay_price) as orderamount'; $statlist_tmp = $model->statByStatordergoods($where, $field, 0, 0, 'goods_type', 'goods_type'); //优惠类型数组 $goodstype_arr = array(2 => '抢购', 3 => '限时折扣', 4 => '优惠套装'); $statlist = array(); $statcount = array('ordernum' => 0, 'goodsnum' => 0, 'orderamount' => 0.0); $stat_arr = array(); $stat_json = array('ordernum' => '', 'goodsnum' => '', 'orderamount' => ''); if ($statlist_tmp) { foreach ((array) $statlist_tmp as $k => $v) { $statcount['ordernum'] += intval($v['ordernum']); $statcount['goodsnum'] += intval($v['goodsnum']); $statcount['orderamount'] += floatval($v['orderamount']); } foreach ((array) $statlist_tmp as $k => $v) { $v['ordernumratio'] = round($v['ordernum'] / $statcount['ordernum'], 4) * 100; $v['goodsnumratio'] = round($v['goodsnum'] / $statcount['goodsnum'], 4) * 100; $v['orderamountratio'] = round($v['orderamount'] / $statcount['orderamount'], 4) * 100; $statlist_tmp2[$v['goods_type']] = $v; $stat_arr['ordernum'][] = array('p_name' => $goodstype_arr[$v['goods_type']], 'allnum' => $v['ordernumratio']); $stat_arr['goodsnum'][] = array('p_name' => $goodstype_arr[$v['goods_type']], 'allnum' => $v['goodsnumratio']); $stat_arr['orderamount'][] = array('p_name' => $goodstype_arr[$v['goods_type']], 'allnum' => $v['orderamountratio']); } foreach ($goodstype_arr as $k => $v) { if ($statlist_tmp2[$k]) { $statlist_tmp2[$k]['goodstype_text'] = $v; $statlist[] = $statlist_tmp2[$k]; } else { $statlist[] = array('goodstype_text' => $k, 'goodstype_text' => $v, 'ordernum' => 0, 'goodsnum' => 0, 'orderamount' => 0.0); } } $stat_json['ordernum'] = getStatData_Pie(array('title' => '下单量', 'name' => '下单量(%)', 'label_show' => false, 'series' => $stat_arr['ordernum'])); $stat_json['goodsnum'] = getStatData_Pie(array('title' => '下单商品数', 'name' => '下商品数(%)', 'label_show' => false, 'series' => $stat_arr['goodsnum'])); $stat_json['orderamount'] = getStatData_Pie(array('title' => '下单金额', 'name' => '下单金额(%)', 'label_show' => false, 'series' => $stat_arr['orderamount'])); } Tpl::output('statcount', $statcount); Tpl::output('statlist', $statlist); Tpl::output('stat_json', $stat_json); Tpl::output('searchtime', implode('|', $searchtime_arr)); Tpl::output('top_link', $this->sublink($this->links, 'promotion')); Tpl::showpage('stat.marketing.promotion'); }
/** * 促销分析 */ public function promotionOp() { 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['add_time'] = array('between', $searchtime_arr); //$where['order_state'] = array(array('neq',ORDER_STATE_CANCEL),array('neq',ORDER_STATE_NEW),'and'); $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', "!(order.payment_code='offline' and order_state <> '" . ORDER_STATE_SUCCESS . "')"); //货到付款订单,订单成功之后才计入统计 $where['goods_type'] = array('in', array(2, 3, 4)); //下单量 $field = ' goods_type,count(DISTINCT order.order_id) as ordernum,SUM(goods_num) as goodsnum,SUM(goods_pay_price) as orderamount'; $statlist_tmp = $model->statByOrderGoods($where, $field, 0, 0, 'goods_type', 'goods_type'); //优惠类型数组 $goodstype_arr = array(2 => '团购', 3 => '限时折扣', 4 => '优惠套装'); $statlist = array(); $statcount = array('ordernum' => 0, 'goodsnum' => 0, 'orderamount' => 0.0); $stat_arr = array(); $stat_json = array('ordernum' => '', 'goodsnum' => '', 'orderamount' => ''); if ($statlist_tmp) { foreach ((array) $statlist_tmp as $k => $v) { $statcount['ordernum'] += intval($v['ordernum']); $statcount['goodsnum'] += intval($v['goodsnum']); $statcount['orderamount'] += floatval($v['orderamount']); } foreach ((array) $statlist_tmp as $k => $v) { $v['ordernumratio'] = round($v['ordernum'] / $statcount['ordernum'], 4) * 100; $v['goodsnumratio'] = round($v['goodsnum'] / $statcount['goodsnum'], 4) * 100; $v['orderamountratio'] = round($v['orderamount'] / $statcount['orderamount'], 4) * 100; $statlist_tmp2[$v['goods_type']] = $v; $stat_arr['ordernum'][] = array('p_name' => $goodstype_arr[$v['goods_type']], 'allnum' => $v['ordernumratio']); $stat_arr['goodsnum'][] = array('p_name' => $goodstype_arr[$v['goods_type']], 'allnum' => $v['goodsnumratio']); $stat_arr['orderamount'][] = array('p_name' => $goodstype_arr[$v['goods_type']], 'allnum' => $v['orderamountratio']); } foreach ($goodstype_arr as $k => $v) { if ($statlist_tmp2[$k]) { $statlist_tmp2[$k]['goodstype_text'] = $v; $statlist[] = $statlist_tmp2[$k]; } else { $statlist[] = array('goodstype_text' => $k, 'goodstype_text' => $v, 'ordernum' => 0, 'goodsnum' => 0, 'orderamount' => 0.0); } } $stat_json['ordernum'] = getStatData_Pie(array('title' => '下单量', 'name' => '下单量(%)', 'label_show' => false, 'series' => $stat_arr['ordernum'])); $stat_json['goodsnum'] = getStatData_Pie(array('title' => '下单商品数', 'name' => '下商品数(%)', 'label_show' => false, 'series' => $stat_arr['goodsnum'])); $stat_json['orderamount'] = getStatData_Pie(array('title' => '下单金额', 'name' => '下单金额(%)', 'label_show' => false, 'series' => $stat_arr['orderamount'])); } Tpl::output('statcount', $statcount); Tpl::output('statlist', $statlist); Tpl::output('stat_json', $stat_json); Tpl::output('searchtime', implode('|', $searchtime_arr)); Tpl::output('top_link', $this->sublink($this->links, 'promotion')); Tpl::showpage('stat.marketing.promotion'); }
/** * 店铺等级 */ public function degreeOp() { $where = array(); $field = ' count(*) as allnum,grade_id '; $model = Model('stat'); //查询店铺分类下的店铺 $search_sclass = intval($_REQUEST['search_sclass']); if ($search_sclass > 0) { $where['sc_id'] = $search_sclass; } $storelist = $model->getNewStoreStatList($where, $field, 0, '', 0, 'grade_id'); $sd_list = $model->getStoreDegree(); $statlist['headertitle'] = array(); $statlist['data'] = array(); //处理数组数据 if (!empty($storelist)) { foreach ($storelist as $k => $v) { $storelist[$k]['p_name'] = $v['grade_id'] > 0 ? $sd_list[$v['grade_id']] : '平台店铺'; $storelist[$k]['allnum'] = intval($v['allnum']); $statlist['headertitle'][] = $v['grade_id'] > 0 ? $sd_list[$v['grade_id']] : '平台店铺'; $statlist['data'][] = $v['allnum']; } $data = array('title' => '店铺等级统计', 'name' => '店铺个数', 'label_show' => true, 'series' => $storelist); Tpl::output('stat_json', getStatData_Pie($data)); } Tpl::output('top_link', $this->sublink($this->links, 'degree')); Tpl::showpage('stat.storedegree'); }
/** * 店铺等级 */ public function degreeOp() { $where = array(); $field = ' count(*) as allnum,grade_id '; $model = Model('stat'); $memberlist = $model->getNewStoreStatList($where, $field, 0, '', 0, 'grade_id'); $sd_list = $model->getStoreDegree(); $statlist['headertitle'] = array(); $statlist['data'] = array(); //处理数组数据 if (!empty($memberlist)) { foreach ($memberlist as $k => $v) { $memberlist[$k]['p_name'] = $sd_list[$v['grade_id']]; $memberlist[$k]['allnum'] = intval($v['allnum']); $statlist['headertitle'][] = $sd_list[$v['grade_id']]; $statlist['data'][] = $v['allnum']; } } //导出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[1][] = $v; } $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 { Tpl::output('actionurl', 'index.php?act=stat_store&op=degree'); $data = array('title' => '店铺等级统计', 'name' => '店铺个数', 'label_show' => true, 'series' => $memberlist); Tpl::output('stat_json', getStatData_Pie($data)); Tpl::output('top_link', $this->sublink($this->links, 'degree')); Tpl::showpage('stat.storedegree'); } }