理論上30天資料應該都有,但實際上卻不一定是,所以需要補全
public static function getdayorderchardata($days = 30)
// 所有使用者
$allorderdata = self::find()
->select(['from_unixtime(create_at,"%y-%m-%d") as char_time', 'count(id) as total_order', 'sum(order_amount) as total_order_amount', 'sum(pay_amount) as total_order_pay_amount'])
->where(['>=', 'from_unixtime(create_at,"%y-%m-%d")', $lastday])
->andwhere(['<=', 'from_unixtime(create_at,"%y-%m-%d")', $nowday])
->groupby('char_time')
->all();
$daycounttitle = yii::t('backend', 'day_order_count_title', ['last_day' => $lastday, 'now_day' => $nowday]);
$dayamounttitle = yii::t('backend', 'day_order_amount_title', ['last_day' => $lastday, 'now_day' => $nowday]);
$labels = $daysformat;
// 所有使用者
$ordercounts = ; // 訂單數量
$orderamounts = ; // 訂單金額
$orderpayamounts = ; // 支付金額
$allorder = ;
foreach($allorderdata as $allkey => $allval)
foreach($daysformat as $key => $val) else
}$data = [
'daycounttitle' => $daycounttitle,
'dayamounttitle' => $dayamounttitle,
'ordercountlabel' => yii::t('backend', 'day_order_count_label', ['days' => $days]),
'orderamountlabel' => yii::t('backend', 'day_order_amount_label', ['days' => $days]),
'orderpayamountlabel' => yii::t('backend', 'day_order_pay_amount_label', ['days' => $days]),
'nowday' => $nowday,
'lastday' => $lastday,
'labels' => $labels,
'ordercounts' => $ordercounts,
'orderamounts' => $orderamounts,
'orderpayamounts' => $orderpayamounts
];return $data;
}js// 按天獲取訂單數量
var dayordercountchartcanvas = $('#dayordercountchart').get(0).getcontext('2d')
var dayordercountchartdata = ]}
var dayordercountchartoptions =
}],yaxes: [}]}
} var dayordercountchart = new chart(dayornirgerbqdercountchartcanvas, );
// 按天獲取訂單及金額
var dayorderamouncanvas = $('#dayorderamountchart').get(0).getcontext('2d')
var dayorderamoundata = ,]}
var dayorderamounoptions =
}],yaxes: [}]}
} var dayorderamountchart = new chart(dayorderamouncanvas, );
記住,yii的as一定要在模型利定義公用變數
public $char_time; // 按時間統計
public $total_order; // 所有訂單
public $total_order_amount; // 所有訂單總額
public $total_pay_order; // 支付訂單
public $total_pay_amount; // 支付訂單總額
public $total_order_pay_amount; // 支付總額
yii結合charjs統計上一年與當前年資料
理論上是1年有12個月,但實際上卻是去年12個月已經過了,是完整的12個月,今年的12個月還沒過,不完整,所以需要補齊 public static function getyearorderchardata 已支付訂單 lastyearpaycounts 前一年月支付訂單總量 lastyearpay...
yii框架學習(一)yii框架介紹
yii幾乎擁有了當今web2.0應用發展的全部特性。下面是這些特性的乙個簡短的清單。yii是乙個基於元件 用於開發大型web應用的高效能php框架。在web開發中yii可以最大限度的實現 重用,極大的提高開發的速度。名字yii 讀音是yee or ji 應該就是 易 的讀音 代表的是容易 easy ...
YII 框架 php框架系列之新秀YII
這裡也強烈推薦yii框架,這個年輕的框架由美國華人開發,名叫薛強。yii framwork是2009最佳php框架。yii 是乙個基於元件 用於開發大型 web 應用的高效能 php 框架。它將 web 程式設計中的可重用性發揮到極致,能夠顯著加速開發程序。yii 讀作 易 代表簡單 easy 高效...