第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Laravel - 每日、每周、每月和每年的收入報告

Laravel - 每日、每周、每月和每年的收入報告

PHP
慕田峪9158850 2021-09-18 13:51:54
如何運行 Laravel Eloquent 查詢來檢索每日、每周、每月和每年的收入報告。表:收入身份證 | 頻道 | 金額 | created_at1 | 大理石| 3400 | 12 年 9 月 10 日2 | 黃金 | 3400 | 8/10/123 | 大理石| 4500 | 07/10/124 | 銀 | 3200 | 22/09/125 | 銀 | 3400 | 12 年 9 月 10 日6 | 銀 | 790 | 22/09/127 | 黃金 | 1000 | 9/08/128 | 大理石| 9000 | 22/09/12預(yù)期結(jié)果:以下是不準確的示例結(jié)果日期 | 頻道 | 每周收入| 月收入| 年收入| 總收入2/2/2017 | 黃金 | 200 | 5400 | 3244 | 90222日期 | 銀 | 600 | 4300 | 983 | 10000我想對上面解釋的金額(收入)求和,也許按頻道和 created_at(日期)分組。我如何編寫雄辯的查詢并在使用 created_at 之間按日期過濾。它應(yīng)該在控制器中完成。
查看完整描述

1 回答

?
catspeake

TA貢獻1111條經(jīng)驗 獲得超0個贊

如果您的頻道有限(如 5-20),則使用以下代碼:


<?php

$items = Revenue::groupBy('channel')->get(['channel']);

$re = [];

foreach ($items as $key => $value) {

    $re['daily'][$value] = Revenue::where('channel',$value)->whereDate('created_at',date('Y-m-d'))->sum('amount');

    $re['weekly'][$value] = Revenue::where('channel',$value)->whereBetween('date', [

        Carbon::parse('last monday')->startOfDay(),

        Carbon::parse('next friday')->endOfDay(),

    ])->sum('amount');

    $re['monthly'][$value] = Revenue::where('channel',$value)->whereMonth('created_at',date('m'))->sum('amount');

    $re['yearly'][$value] = Revenue::where('channel',$value)->whereYear('created_at',date('Y'))->sum('amount');

}


var_dump($re);

在這段代碼中,我們首先分離通道,然后使用它們來計算所需的結(jié)果。順便說一句,代碼是要測試的。


查看完整回答
反對 回復(fù) 2021-09-18
  • 1 回答
  • 0 關(guān)注
  • 253 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學習伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號