每天为维度展示当月的数据情况

    /**
     * 获取每日数据统计
     */
    public function getOneDayCountLog()
    {
        // 本月所有天数
        for ($i = 1; $i < date('t')+1; $i++) {
            $monthDay['revenue_money_day'] = '';
            $monthDay['dayorder'] = $i;
            $monthDay['net_receipts_money_day'] = '';
            $countMonthDay[] = $monthDay;
        }
        // 每天为维度展示当月的数据情况
        $monthSalesDay = Sms::build()
            ->group('dayorder')
            ->field("sum(state) revenue_money_day, FROM_UNIXTIME(time, '%d') AS dayorder")
            ->field("sum(code) net_receipts_money_day, FROM_UNIXTIME(time, '%d') AS dayorder")
            ->order('dayorder asc')
            ->whereMonth('time')
            ->select();
        // 天数数据添加
        foreach ($countMonthDay as $key => $value) {
            foreach ($monthSalesDay as $key1 => $value1) {
                if ($value['dayorder'] == ltrim($value1['dayorder'], '0')) {
                    $countMonthDay[$key]['revenue_money_day'] = $value1['revenue_money_day'];
                    $countMonthDay[$key]['dayorder'] = ltrim($value1['dayorder'], '0');
                    $countMonthDay[$key]['net_receipts_money_day'] = $value1['net_receipts_money_day'];
                }
            }
        }


        $data['countMonthDay'] = $countMonthDay;
        return json_success('每日数据统计', $data);
    }

 

posted @ 2023-04-21 14:51  潘潘潘的博客  阅读(14)  评论(0编辑  收藏  举报