getoneByStatorder($where, $field); $statnew_arr['ordernum'] = ($t = $stat_order['ordernum']) ? $t : 0; $statnew_arr['orderamount'] = ds_price_format(($t = $stat_order['orderamount']) ? $t : (0)); $statnew_arr['ordermembernum'] = ($t = $stat_order['ordermembernum']) ? $t : 0; $statnew_arr['orderavg'] = ds_price_format(($t = $stat_order['orderavg']) ? $t : 0); unset($stat_order); //查询订单商品表下单商品数 $where = array(); $where[] = array('order_isvalid','=',1);//计入统计的有效订单 $where[] = array('order_add_time','between', array($stime, $etime)); $field = ' SUM(goods_num) as ordergoodsnum,AVG(goods_pay_price/goods_num) as priceavg '; $stat_ordergoods = $stat_model->getoneByStatordergoods($where, $field); $statnew_arr['ordergoodsnum'] = ($t = $stat_ordergoods['ordergoodsnum']) ? $t : 0; $statnew_arr['priceavg'] = ds_price_format(($t = $stat_ordergoods['priceavg']) ? $t : 0); unset($stat_ordergoods); //新增会员数 $where = array(); $where[] = array('member_addtime','between', array($stime, $etime)); $field = ' COUNT(*) as newmember '; $stat_member = $stat_model->getOneByMember($where, $field); $statnew_arr['newmember'] = ($t = $stat_member['newmember']) ? $t : 0; unset($stat_member); //会员总数 $where = array(); $field = ' COUNT(*) as membernum '; $stat_member = $stat_model->getOneByMember($where, $field); $statnew_arr['membernum'] = ($t = $stat_member['membernum']) ? $t : 0; unset($stat_member); //新增商品,商品总数 $goods_list = $stat_model->statByGoods(array('is_virtual' => 0), "COUNT(*) as goodsnum, SUM(IF(goods_addtime>=$stime and goods_addtime<=$etime,'1',0)) as newgoods"); $statnew_arr['goodsnum'] = ($t = $goods_list[0]['goodsnum']) > 0 ? $t : 0; $statnew_arr['newgoods'] = ($t = $goods_list[0]['newgoods']) > 0 ? $t : 0; /* * 昨日销售走势 */ //构造横轴数据 for ($i = 0; $i < 24; $i++) { //统计图数据 $curr_arr[$i] = 0;//今天 $up_arr[$i] = 0;//昨天 //横轴 $stat_arr['xAxis']['categories'][] = "$i"; } $stime = $stat_time - 86400;//昨天0点 $etime = $stat_time + 86400 - 1;//今天24点 $yesterday_day = @date('d', $stime);//昨天日期 $today_day = @date('d', $etime);//今天日期 $where = array(); $where[] = array('order_isvalid','=',1);//计入统计的有效订单 $where[] = array('order_add_time','between', array($stime, $etime)); $field = ' SUM(order_amount) as orderamount,DAY(FROM_UNIXTIME(order_add_time)) as dayval,HOUR(FROM_UNIXTIME(order_add_time)) as hourval '; $stat_order = $stat_model->statByStatorder($where, $field, 0, 0, '', 'dayval,hourval'); if ($stat_order) { foreach ($stat_order as $k => $v) { if ($today_day == $v['dayval']) { $curr_arr[$v['hourval']] = intval($v['orderamount']); } if ($yesterday_day == $v['dayval']) { $up_arr[$v['hourval']] = intval($v['orderamount']); } } } $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_arr['title'] = date('Y-m-d', $stat_time) . '销售走势'; $stat_arr['yAxis'] = '销售额'; $stattoday_json = getStatData_LineLabels($stat_arr); unset($stat_arr); /* * 7日内商品销售TOP30 */ $stime = $stat_time - 86400 * 6;//7天前0点 $etime = $stat_time + 86400 - 1;//今天24点 $where = array(); $where[] = array('order_isvalid','=',1);//计入统计的有效订单 $where[] = array('order_add_time','between', array($stime, $etime)); $field = ' sum(goods_num) as ordergoodsnum, goods_id, goods_name '; $goodstop30_arr = $stat_model->statByStatordergoods($where, $field, 0, 30, 'ordergoodsnum desc', 'goods_id'); View::assign('goodstop30_arr', $goodstop30_arr); View::assign('stattoday_json', $stattoday_json); View::assign('statnew_arr', $statnew_arr); View::assign('stat_time', $stat_time); $this->setAdminCurItem('general'); return View::fetch(); } /** * 统计设置 */ public function setting() { $config_model = model('config'); if (request()->isPost()) { $update_array = array(); $pricerange_temp_array = input('post.pricerange/a'); if (is_array($pricerange_temp_array)) { foreach ($pricerange_temp_array as $k => $v) { if(!is_numeric($v['s']) || !is_numeric($v['e'])){ $this->error(lang('is_numeric_error')); } if($v['s']<0 || $v['e']<0){ $this->error(lang('is_zero_error')); } if($v['s']>$v['e']){ $this->error(lang('amount_set_error')); } $pricerange_arr[] = $v; } $update_array['stat_pricerange'] = serialize($pricerange_arr); } else { $update_array['stat_pricerange'] = ''; } $result = $config_model->editConfig($update_array); if ($result === true) { $this->log(lang('ds_edit').lang('stat_setting'), 1); $this->success(lang('ds_common_save_succ')); } else { $this->log(lang('ds_edit').lang('stat_setting'), 0); $this->error(lang('ds_common_save_fail')); } } $list_setting = rkcache('config', true); $list_setting['stat_pricerange'] = unserialize($list_setting['stat_pricerange']); View::assign('list_setting', $list_setting); $this->setAdminCurItem('setting'); return View::fetch(); } /** * 统计设置 */ public function orderprange() { $config_model = model('config'); if (request()->isPost()) { $update_array = array(); $pricerange_temp_array = input('post.pricerange/a'); if (is_array($pricerange_temp_array)) { foreach ($pricerange_temp_array as $k => $v) { if(!is_numeric($v['s']) || !is_numeric($v['e'])){ $this->error(lang('is_numeric_error')); } if($v['s']<0 || $v['e']<0){ $this->error(lang('is_zero_error')); } if($v['s']>$v['e']){ $this->error(lang('amount_set_error')); } $pricerange_arr[] = $v; } $update_array['stat_orderpricerange'] = serialize($pricerange_arr); } else { $update_array['stat_orderpricerange'] = ''; } $result = $config_model->editConfig($update_array); if ($result === true) { $this->log(lang('ds_edit').lang('stat_setting'), 1); $this->success(lang('ds_common_save_succ')); } else { $this->log(lang('ds_edit').lang('stat_setting'), 0); $this->error(lang('ds_common_save_fail')); } } else { $list_setting = rkcache('config', true); $list_setting['stat_orderpricerange'] = unserialize($list_setting['stat_orderpricerange']); View::assign('list_setting', $list_setting); $this->setAdminCurItem('orderprange'); return View::fetch(); } } protected function getAdminItemList() { $menu_array = array( array( 'name' => 'general', 'text' => lang('stat_generalindex'), 'url' => url('Statgeneral/general') ), array( 'name' => 'setting', 'text' => lang('stat_goodspricerange'), 'url' => url('Statgeneral/setting') ), array( 'name' => 'orderprange', 'text' => lang('stat_orderpricerange'), 'url' => url('Statgeneral/orderprange') ) ); return $menu_array; } }