public function indexAction()
{
$session = $_SESSION;
$userName = $session['userInfo']['username'];
/*
* 订单统计表
* @author ftt
* @time 2015年11月5日15:53:14
*/
$md = new Comm_Curl(); //实例化 Curl类
$day = intval($_GET['day']); //接收日期id
$where['day'] = isset($day) ? $day : NULL;
if($where['day'] == 0){
$where['day']=1;
$day=1;
}
$data = $md->post('http://www.baidu.com/api/getAdminOrderTongji',$where);
$data = json_decode($data,TRUE);
$d1=$data['d1']; //当前(数组)
$d2=$data['d2']; //对比(数组)
$count =$d1['count']; //当前值(订单数)
$order_money=$d1['yizhifu'];
$yes_order_money=$order_money;
$money = $d1['money'];
/*获取订单百分比*/
$new_order_per = round(($count/$d2['count'])*100);
if($new_order_per =='0'){
$new_order_per=100; //如果对比值为0那么将其设置为百分之百
}
if($new_order_per > 1000){
$new_order_per=1000;
}
/*付款订单百分比*/
$order_money_per = round(($order_money/$d2['yizhifu'])*100);
if($order_money_per =='0'){
$order_money_per=100; //如果对比值为0那么将其设置为百分之百
}
if($order_money_per > 1000){
$new_order_per=1000;
}
/*确认订单百分比*/
//目前与确认订单一致
/*成交额百分比*/
$money_per = round(($money/$d2['money'])*100);
if($money_per =='0'){
$money_per=100; //如果对比值为0那么将其设置为百分之百
}
if($money_per > 1000){
$money_per=1000;
}
/**
* 设置确认订单百分比等于付款订单百分比
*/
$yes_order_money_per = $order_money_per;
/*比较两次的大小用于对页面显示的百分比箭头做判定*/
if($count <= $d2['count']){
$new_order_per_or=2;
}else{
$new_order_per_or=1;
}
if($order_money <= $d2['yizhifu']){
$order_money_per_or = 2;
$yes_order_money_per_or = 2;
}else{
$order_money_per_or = 1;
$yes_order_money_per_or = 1;
}
if($money <= $d2['money']){
$money_per_or = 2;
}else{
$money_per_or = 1;
}
/*
* 判断day的值进行字符串拼接
*/
$dayType = '';
switch ($day) {
case 1:
$dayType='今日';
break;
case 2:
$dayType='昨天';
break;
case 3:
$dayType='本周';
break;
case 4:
$dayType='本月';
break;
case 5:
$dayType='本季度';
break;
case 6:
$dayType='本年';
break;
case 7:
$dayType='全部';
break;
default:
$dayType='今日';
break;
}
$lists = array(
'new_order'=>$count, //新订单
'new_order_per'=>$new_order_per,
'new_order_per_or'=>$new_order_per_or,
'order_money'=>$order_money, //付款订单
'order_money_per'=>$order_money_per,
'order_money_per_or'=>$order_money_per_or,
'yes_order_money'=>$order_money, //确认订单
'yes_order_money_per'=>$yes_order_money_per,
'yes_order_money_per_or'=>$yes_order_money_per_or,
'money'=>$money, //成交额
'money_per'=>$money_per,
'money_per_or'=>$money_per_or,
'dayType'=>$dayType,
'day1'=>$day,
);
// print_r($lists);
$view = $this->getView();
$view->assign("day",$day);
$view->assign("val",$lists); //订单统计数
$view->assign("userName", $userName);
$this->getView()->display("admin/index.html");
}
public function getAdminOrderTongjiAction() {
$day = isset ( $this->request ['day'] ) ? Comm_Tools::removeXSS ( trim ( $this->request ['day'] ) ) : 1;
$sql = '';
switch ($day) {
case 1 : // 当天
// 昨天开始和结束
$nowup = date ( "Y/m/d H:i:s", mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 1, date ( "Y" ) ) ); // 昨天开始
$nowdown = date ( "Y/m/d H:i:s", mktime ( 23, 59, 59, date ( "m" ), date ( "d" ) - 1, date ( "Y" ) ) ); // 昨天结束
$d1 = $this->getAdminOrders ( date ( 'Y-m-d' ), date ( 'Y-m-d 23:59:59' ) );
$d2 = $this->getAdminOrders ( $nowup, $nowdown );
echo json_encode ( array (
'd1' => $d1,
'd2' => $d2
) );
break;
case 2 : // 昨天
// 昨天开始和结束
$now = date ( "Y/m/d H:i:s", mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 1, date ( "Y" ) ) ); // 昨天开始
$end = date ( "Y/m/d H:i:s", mktime ( 23, 59, 59, date ( "m" ), date ( "d" ) - 1, date ( "Y" ) ) ); // 昨天结束
// 前天开始和结束
$nowup = date ( "Y/m/d H:i:s", mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - 2, date ( "Y" ) ) );
$nowdown = date ( "Y/m/d H:i:s", mktime ( 23, 59, 59, date ( "m" ), date ( "d" ) - 2, date ( "Y" ) ) );
$d1 = $this->getAdminOrders ( $now, $end );
$d2 = $this->getAdminOrders ( $nowup, $nowdown );
echo json_encode ( array (
'd1' => $d1,
'd2' => $d2
) );
break;
case 3 : // 本周
// 上周起始时间:
$nowup = date ( "Y-m-d H:i:s", mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - date ( "w" ) + 1 - 7, date ( "Y" ) ) );
$nowdown = date ( "Y-m-d H:i:s", mktime ( 23, 59, 59, date ( "m" ), date ( "d" ) - date ( "w" ) + 7 - 7, date ( "Y" ) ) );
// 本周起始时间:
$now = date ( "Y-m-d H:i:s", mktime ( 0, 0, 0, date ( "m" ), date ( "d" ) - date ( "w" ) + 1, date ( "Y" ) ) );
$end = date ( "Y-m-d H:i:s", mktime ( 23, 59, 59, date ( "m" ), date ( "d" ) - date ( "w" ) + 7, date ( "Y" ) ) );
$d1 = $this->getAdminOrders ( $now, $end );
$d2 = $this->getAdminOrders ( $nowup, $nowdown );
echo json_encode ( array (
'd1' => $d1,
'd2' => $d2
) );
break;
case 4 : // 本月
// 上月起始时间:
$nowup = date ( "Y-m-d H:i:s", mktime ( 0, 0, 0, date ( "m" ) - 1, 1, date ( "Y" ) ) );
$nowdown = date ( "Y-m-d H:i:s", mktime ( 23, 59, 59, date ( "m" ), 0, date ( "Y" ) ) );
// 本月起始时间:
$now = date ( "Y-m-d H:i:s", mktime ( 0, 0, 0, date ( "m" ), 1, date ( "Y" ) ) );
$end = date ( "Y-m-d H:i:s", mktime ( 23, 59, 59, date ( "m" ), date ( "t" ), date ( "Y" ) ) );
$d1 = $this->getAdminOrders ( $now, $end );
$d2 = $this->getAdminOrders ( $nowup, $nowdown );
echo json_encode ( array (
'd1' => $d1,
'd2' => $d2
) );
break;
case 5 : // 季度
$season = ceil ( (date ( 'n' )) / 3 ) - 1; // 上季度是第几季度
// 上季度起始时间:
$nowup = date ( 'Y-m-d H:i:s', mktime ( 0, 0, 0, $season * 3 - 3 + 1, 1, date ( 'Y' ) ) );
$nowdown = date ( 'Y-m-d H:i:s', mktime ( 23, 59, 59, $season * 3, date ( 't', mktime ( 0, 0, 0, $season * 3, 1, date ( "Y" ) ) ), date ( 'Y' ) ) );
$season = ceil ( (date ( 'n' )) / 3 );
// 本季度起始时间:
$now = date ( 'Y-m-d H:i:s', mktime ( 0, 0, 0, $season * 3 - 3 + 1, 1, date ( 'Y' ) ) );
$end = date ( 'Y-m-d H:i:s', mktime ( 23, 59, 59, $season * 3, date ( 't', mktime ( 0, 0, 0, $season * 3, 1, date ( "Y" ) ) ), date ( 'Y' ) ) );
$d1 = $this->getAdminOrders ( $now, $end );
$d2 = $this->getAdminOrders ( $nowup, $nowdown );
echo json_encode ( array (
'd1' => $d1,
'd2' => $d2
) );
break;
case 6 : // 本年
// 上年起始时间:
$nowup = date ( "Y-m-d", mktime ( 0, 0, 0, 01, 01, date ( "Y" ) - 1 ) );
$nowdown = date ( "Y-m-d ", mktime ( 23, 59, 59, 12, 31, date ( "Y" ) - 1 ) );
// 本年起始时间:
$now = date ( "Y-m-d", mktime ( 0, 0, 0, 01, 01, date ( "Y" ) ) );
$end = date ( "Y-m-d", mktime ( 23, 59, 59, 12, 31, date ( "Y" ) ) );
$d1 = $this->getAdminOrders ( $now, $end );
$d2 = $this->getAdminOrders ( $nowup, $nowdown );
echo json_encode ( array (
'd1' => $d1,
'd2' => $d2
) );
break;
case 7 : // 全部
// 全部起始时间:
$d1 = $this->getAdminOrders ( '2015-01-01', '2020-12-31' );
echo json_encode ( array (
'd1' => $d1
) );
break;
default :
echo json_encode ( array (
'd1' => array (),
'd2' => array ()
) );
;
break;
}
exit ();
}