public function listsAction() { $title = new OFC_Elements_Title('测试统计'); $title->setStyle('{font-size: 16px;}'); $start = strtotime(date('Y-m-d', strtotime('-30 days'))); $l = array(); for ($i = 0; $i <= 30; $i++) { $l[] = date('m/d', $start + $i * 86400); } $labels = new OFC_Elements_Axis_Label($l); $labels->setRotate(30); $x = new OFC_Elements_Axis_X(); $x->setLabels($labels)->setGridColour('#EAF4FB'); $data1 = array(); $data2 = array(); for ($i = 0; $i <= 30; $i++) { // $s = $this->db->select() // ->from('order_info', 'sum(order_amount)') // ->where('order_status = 1') // ->where('add_time >= ?', $start) // ->where('add_time < ?', $start + 86400); // ->fetchOne(); $data1[] = $i; // $s = $this->db->select() // ->from('order_info', 'sum(order_amount)') // ->where('order_status = 1') // ->where('pay_status = 2 OR shipping_status = 1 OR shipping_status = 2') // ->where('add_time >= ?', $start) // ->where('add_time < ?', $start + 86400) // ->fetchOne(); // $data2[] = $s ? floatval($s) : 0; $data2[] = $i + rand(200, 1000); $start += 86400; } $y = new OFC_Elements_Axis_Y(); $max = max(20000, max($data1) + 1000); $y->setRange(0, $max, floor($max / 20000) * 1000)->setGridColour('#EAF4FB'); $line1 = new OFC_Charts_Line_Dot(); $line1->setKey('总数', 12)->setValues($data1)->setTip('#x_label# 总数 ¥#val#'); $line2 = new OFC_Charts_Line_Dot(); $line2->setColour('#FF0000')->setKey('变化的数据', 12)->setValues($data2)->setTip('#x_label# 变化 ¥#val#'); $chart = new OFC_Chart(); $chart->setTitle($title)->setXaxis($x)->setYaxis($y)->setBgColour('#FEFFFF')->addElement($line1)->addElement($line2)->output(); $this->isload = false; }
/** * 最近30天浏览统计 */ public function action_month() { $uname = $this->getQuery('save_dir'); //$stat_date = urldecode($this->getRequest('stat_date', 'stat_date')); //$end_date = urldecode($this->getRequest('end_date', 'end_date')); $title = new OFC_Elements_Title($uname . '最近30日流量统计'); $title->setStyle('{font-size: 16px;}'); $start = strtotime(date('Y-m-d', strtotime('-30 days'))); $l = array(); for ($i = 0; $i <= 30; $i++) { $l[] = date('m/d', $start + $i * 86400); $listDay[] = date('y-m-d', $start + $i * 86400); } $labels = new OFC_Elements_Axis_Label($l); $labels->setRotate(30); $x = new OFC_Elements_Axis_X(); $x->setLabels($labels)->setGridColour('#EAF4FB'); $data1 = array(); $data2 = array(); foreach ($listDay as $i) { $time = date('Y-m-d', strtotime($i)); $tot_flow = DB::select('tot_flow')->from('imgup_flow')->where('uname', '=', $uname)->where('date', '=', $time)->fetch_one(); $s1 = $tot_flow / 1048576; $data1[] = $s1 ? round($s1) : 0; $s2 = DB::select('tot_times')->from('imgup_flow')->where('uname', '=', $uname)->where('date', '=', $time)->fetch_one(); $s2 = $s2; $data2[] = $s2 ? floatval($s2) : 0; $start += 86400; } $y = new OFC_Elements_Axis_Y(); $max = max(2000, max($data2) + 100); $y->setRange(0, $max, floor($max / 2000) * 100)->setGridColour('#EAF4FB'); $line1 = new OFC_Charts_Line_Dot(); $line1->setKey('流量', 12)->setValues($data1)->setTip('#x_label# 访问 #val# m'); $line2 = new OFC_Charts_Line_Dot(); $line2->setColour('#FF0000')->setKey('访问次数', 12)->setValues($data2)->setTip('#x_label# 访问 #val# 次'); $chart = new OFC_Chart(); $chart->setTitle($title)->setXaxis($x)->setYaxis($y)->setBgColour('#FEFFFF')->addElement($line1)->addElement($line2)->output(); $this->auto_render = false; }