Commit efa0dbcd efa0dbcd559ff18e06341b8cd8d40fd32a1909a6 by lemon

*

1 parent df356054
...@@ -18,20 +18,33 @@ class MusicianIncomeService extends Service ...@@ -18,20 +18,33 @@ class MusicianIncomeService extends Service
18 */ 18 */
19 public function income() 19 public function income()
20 { 20 {
21 $start_month = $this->request->input('start', date('Ym', strtotime('-6 month'))); 21 $start_month = $this->request->input('start');
22 $end_month = $this->request->input('end', date('Ym', strtotime('-1 month'))); 22 $end_month = $this->request->input('end');
23 23
24 $res = StakeholderSongCollate::query()->custom($this->request->only(['song_id']))->identify() 24 $res = StakeholderSongCollate::query()->custom($this->request->only(['song_id']))->identify()
25 ->groupBy('month')->orderBy('month')->selectRaw('month, sum(share_amount) as income')->get()->toArray(); 25 ->groupBy('month')->orderBy('month')->selectRaw('month, sum(share_amount) as income')->get()->toArray();
26 26
27 $stat_income = []; 27 $stat_income = [];
28 $total_income = '0';
28 foreach ($res as $item) { 29 foreach ($res as $item) {
30
31 if (empty($start_month) || empty($end_month)) {
32
33 if (count($stat_income) < 7) {
34 $stat_income[] = $item;
35 continue;
36 }
37 break;
38 } else {
29 if ($item['month'] >= $start_month && $item['month'] <= $end_month) { 39 if ($item['month'] >= $start_month && $item['month'] <= $end_month) {
30 $stat_income[] = $item; 40 $stat_income[] = $item;
31 } 41 }
32 } 42 }
33 43
34 return Response::success($stat_income); 44 $total_income = bcadd($total_income, $item->income, self::DECIMAL);
45 }
46
47 return Response::success(['list'=>$stat_income, 'total_income'=>$total_income]);
35 } 48 }
36 49
37 /** 50 /**
......