本文实例讲述了yii框架结合charjs实现统计30天数据的方法。分享给大家供大家参考,具体如下:
理论上30天数据应该都有,但实际上却不一定是,所以需要补全
public static function getdayorderchardata($days = 30) { $nowday = date('y-m-d', strtotime('-1day')); // 当前前一天 $lastday = date("y-m-d", strtotime('-'.$days.'day')); // days天前 $daysformat = []; // 获取到days段的日期 for($i = $days; $i > 0; $i--) { $daysformat[] = date("y-m-d", strtotime('-'.$i.'day')); } // 所有用户 $allorderdata = lf::find() ->lect(['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_bear是什么意思day' => $lastday, 'now_day' => $nowday]); $dayamounttitle = yii::t('backend', 'day_order_amount_title', ['last_day' => $lastday, 'now_day' => $nowday]); $labels = $daysformat; // 所有用户 $ordercounts = []; // 订单数量 $orderamounts = []; // 订单金额 $orderpayamounts = []; // 支付金额 $allorderdataarr = []; foreach($allorderdata as $allkey => $allval) { $allorderdataarr[$allval->char_time]['char_time'] = $allval->char_time; $allorderdataarr[$allval->char_time]['total_order'] = $allval->total_order; $allorderdataarr[$allval->char_time]['total_order_amount'] = $allval->total_order_amount; $allorderdataarr[$allval->char_time]['total_order_pay_amount'] = $allval->total_order_pay_amount; } foreach($daysformat as $key => $val) { if(array_key_exists($val, $allorderdataarr)) { $ordercounts[] = $allorderdataarr[$val]['total_order']; $orderamounts[] = $allorderdataarr[$val]['total_order_amount']; $orderpayamounts[] = $allorderdataarr[$val]['total_order_pay_amount']; }三下乡心得 el { $ordercounts[] = '0'; $orderamounts[] = '0'; $orderpayamounts[] = '0'; } } $data = [ 'daycounttitle' => $daycounttitle, 'dayamounttitle' => $dayamounttitle, 'ordercountlabel' => yii::t('backend', 'day_order_count_label', ['days' => $days]), 'orderam白雪公主魔镜魔镜ountlabel' => 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; }
j英语分类s
// 按天获取订单数量 var dayordercountchartcanvas = $('#dayordercountchart').get(0).getcontext('2d') var dayordercountchartdata = { labels : <?= json_encode($dayorderchar['labels'], true) ?>, datats: [ { label : '<?= $dayorderchar['ordercountlabel'] ?>', backgroundcolor : 'rgba(0, 192, 293, 0.5)', data : <?= json_encode($dayorderchar['ordercounts'], true) ?> } ] } var dayordercountchartoptions = { scales: { xaxes: [{ gridlines: { display: fal } }], yaxes: [{ gridlines: { display: fal } }] } } var dayordercountchart = new chart(dayordercountchartcanvas, { type: 'line', data: dayordercountchartdata, options: dayordercountchartoptions }); // 按天获取订单及金额 var dayorderamouncanvas = $('#dayorderamountchart').get(0).getcontext('2d') var dayorderamoundata = { labels : <?= json_encode($dayorderchar['labels'], true) ?>, datats: [ { label : '<?= $dayorderchar['orderamountlabel'] ?>', backgroundcolor : 'rgba(0, 192, 293, 0.5)', data : <?= json_encode($dayorderchar['orderamounts'], true) ?> }, { label : '<?= $dayorderchar['orderpayamountlabel'] ?>', backgroundcolor : 'rgba(0, 166, 90, 0.5)', data : <?= json_encode($dayorderchar['orderpayamounts'], true) ?> } ] } var dayorderamounoptions = { sca河南大学自考les: { xaxes: [{ gridlines: { display: fal } }], yaxes: [{ gridlines: { display: fal } }] } } var dayorderamountchart = new chart(dayorderamouncanvas, { type: 'line', data: dayorderamoundata, options: dayorderamounoptions });
记住,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; // 支付总额
本文发布于:2023-04-08 16:43:02,感谢您对本站的认可!
本文链接:https://www.wtabcd.cn/fanwen/zuowen/1143fb8d8f451aa3729382cf6d086f30.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文word下载地址:yii框架结合charjs实现统计30天数据的方法.doc
本文 PDF 下载地址:yii框架结合charjs实现统计30天数据的方法.pdf
留言与评论(共有 0 条评论) |