富贵资源网 Design By www.hznty.com

本文实例讲述了yii框架结合charjs统计上一年与当前年数据的方法。分享给大家供大家参考,具体如下:

理论上是1年有12个月,但实际上却是去年12个月已经过了,是完整的12个月,今年的12个月还没过,不完整,所以需要补齐

public static function getYearOrderCharData() {
    // 获取当前年
    $months = range(1, 12);
    $currentYear = date('Y');
    $lastYear = date('Y', strtotime("-1 year"));
    // 所有订单
    $allOrderData = self::find()
            ->select(['FROM_UNIXTIME(create_at,"%Y-%m") as char_time', 'COUNT(id) as total_order', 'SUM(order_amount) as total_order_amount'])
            ->where(['>=', 'FROM_UNIXTIME(create_at,"%Y")', $lastYear])
            ->groupBy('char_time')
            ->all();
    // 已支付订单
    $allPayOrderData = self::find()
            ->select(['FROM_UNIXTIME(create_at,"%Y-%m") as char_time', 'COUNT(id) as total_order', 'SUM(pay_amount) as total_order_amount'])
            ->where(['>=', 'FROM_UNIXTIME(create_at,"%Y")', $lastYear])
            ->andWhere(['pay_status' => 2])
            ->groupBy('char_time')
            ->all();
    $yearCountTitle   = Yii::t('backend', 'year_order_count_title', ['last_year' => $lastYear, 'current_year' => $currentYear]);
    $yearAmountTitle  = Yii::t('backend', 'year_order_amount_title', ['last_year' => $lastYear, 'current_year' => $currentYear]);
    $yearPayCountTitle = Yii::t('backend', 'year_order_pay_count_title', ['last_year' => $lastYear, 'current_year' => $currentYear]);
    $yearPayAmountTitle = Yii::t('backend', 'year_order_pay_amount_title', ['last_year' => $lastYear, 'current_year' => $currentYear]);
 
    $labels = [];
    // 所有订单
    $lastYearCounts = []; // 前一年月订单总量
    $lastYearAmounts = []; // 前一年月订单总额
    $currentYearCounts = []; // 当前年月订单总量
    $currentYearAmounts = []; // 当前年月订单额
    $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'] = number_format($allVal->total_order_amount / 100, 2, '.', '');
    }
 
    // 已支付订单
    $lastYearPayCounts = []; // 前一年月支付订单总量
    $lastYearPayAmounts = []; // 前一年月支付订单总额
    $currentYearPayCounts = []; // 当前年月支付订单总量
    $currentYearPayAmounts = []; // 当前年月支付订单额
    $allPayOrderDataArr = [];
    foreach($allPayOrderData as $payKey => $payVal) {
      $allPayOrderDataArr[$payVal->char_time]['char_time'] = $payVal->char_time;
      $allPayOrderDataArr[$payVal->char_time]['total_order'] = $payVal->total_order;
      $allPayOrderDataArr[$payVal->char_time]['total_order_amount'] = number_format($payVal->total_order_amount / 100, 2, '.', '');
    }
 
    foreach($months as $key => $val) {
      $label = $val . Yii::t('backend', 'month');
      $labels[] = $label;
      $theMonth = strlen($val) == 2 "htmlcode">
// 订单总量对比
  var yearOrderCountChartCanvas = $('#yearOrderCountChart').get(0).getContext('2d')
  var yearOrderCountChartData = {
   labels : <"htmlcode">
public $char_time; // 按时间统计
  public $total_order; // 所有订单
  public $total_order_amount; // 所有订单总额
  public $total_pay_order; // 支付订单
  public $total_pay_amount; // 支付订单总额
  public $total_order_pay_amount; // 支付总额

更多关于Yii相关内容感兴趣的读者可查看本站专题:《Yii框架入门及常用技巧总结》、《php优秀开发框架总结》、《smarty模板入门基础教程》、《php面向对象程序设计入门教程》、《php字符串(string)用法总结》、《php+mysql数据库操作入门教程》及《php常见数据库操作技巧汇总》

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

富贵资源网 Design By www.hznty.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站资源来自互联网收集,仅供用于学习和交流,请遵循相关法律法规,本站一切资源不代表本站立场,如有侵权、后门、不妥请联系本站删除!
富贵资源网 Design By www.hznty.com

稳了!魔兽国服回归的3条重磅消息!官宣时间再确认!

昨天有一位朋友在大神群里分享,自己亚服账号被封号之后居然弹出了国服的封号信息对话框。

这里面让他访问的是一个国服的战网网址,com.cn和后面的zh都非常明白地表明这就是国服战网。

而他在复制这个网址并且进行登录之后,确实是网易的网址,也就是我们熟悉的停服之后国服发布的暴雪游戏产品运营到期开放退款的说明。这是一件比较奇怪的事情,因为以前都没有出现这样的情况,现在突然提示跳转到国服战网的网址,是不是说明了简体中文客户端已经开始进行更新了呢?