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) {
29 if ($item['month'] >= $start_month && $item['month'] <= $end_month) { 30
30 $stat_income[] = $item; 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 {
39 if ($item['month'] >= $start_month && $item['month'] <= $end_month) {
40 $stat_income[] = $item;
41 }
31 } 42 }
43
44 $total_income = bcadd($total_income, $item->income, self::DECIMAL);
32 } 45 }
33 46
34 return Response::success($stat_income); 47 return Response::success(['list'=>$stat_income, 'total_income'=>$total_income]);
35 } 48 }
36 49
37 /** 50 /**
......