|
@@ -12,7 +12,7 @@ class IncomeAndExpendController
|
|
|
{
|
|
|
|
|
|
public function list(Request $request)
|
|
|
- {
|
|
|
+ {
|
|
|
$days = $request->get('days');
|
|
|
if (!empty($days)) {
|
|
|
$days[0] = strtotime($days[0]);
|
|
@@ -25,7 +25,7 @@ class IncomeAndExpendController
|
|
|
$days[1] = strtotime(date('Y-m-d', $days[1]) . " 23:59:59");
|
|
|
} else {
|
|
|
$month = date('Ym');
|
|
|
- $days[0] = strtotime(date('Y-m').'-01');
|
|
|
+ $days[0] = strtotime(date('Y-m') . '-01');
|
|
|
$days[1] = time();
|
|
|
}
|
|
|
$premises = $request->get('premises', DeptService::getPremisesList());
|
|
@@ -34,69 +34,77 @@ class IncomeAndExpendController
|
|
|
// $premisesKeyValue[$item['key']] = $item['label'];
|
|
|
// }
|
|
|
$premisesKey = [];
|
|
|
- foreach($premises as $item){
|
|
|
+ foreach ($premises as $item) {
|
|
|
$premisesKey[] = $item['key'];
|
|
|
}
|
|
|
|
|
|
- $dayNum = ($days[1] - $days[0])/(60*60*24);
|
|
|
- $currentDay = date('Y-m-d',$days[0]);
|
|
|
- $data =[];
|
|
|
- $statistics = ['income_amount'=>0,'income_wxpay'=>0,'income_alipay'=>0,'income_qrcode'=>0,'expend_amount'=>0,'expend_wxpay'=>0,'expend_alipay'=>0];
|
|
|
- for($i=0;$i<=$dayNum;$i++){
|
|
|
+ $dayNum = ($days[1] - $days[0]) / (60 * 60 * 24);
|
|
|
+ $currentDay = date('Y-m-d', $days[0]);
|
|
|
+ $data = [];
|
|
|
+ $statistics = ['income_amount' => 0, 'income_wxpay' => 0, 'income_alipay' => 0, 'income_money' => 0, 'expend_amount' => 0, 'expend_wxpay' => 0, 'expend_alipay' => 0, 'expend_money' => 0];
|
|
|
+ for ($i = 0; $i <= $dayNum; $i++) {
|
|
|
$dayData = [];
|
|
|
$dayData['day'] = $currentDay;
|
|
|
// 收入
|
|
|
- if(Util::schema()->hasTable("data_income_{$month}")){
|
|
|
+ if (Util::schema()->hasTable("data_income_{$month}")) {
|
|
|
$wxpay = Db::table("data_income_{$month}")
|
|
|
- ->where('data_income_days',$currentDay)
|
|
|
- ->where('data_income_pay_type','WXPAY')
|
|
|
- ->whereIn('join_data_income_dept_id',$premisesKey)
|
|
|
- ->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
|
|
|
- ->groupBy('data_income_pay_type')
|
|
|
- ->first();
|
|
|
-
|
|
|
+ ->where('data_income_days', $currentDay)
|
|
|
+ ->where('data_income_pay_type', 'WXPAY')
|
|
|
+ ->whereIn('join_data_income_dept_id', $premisesKey)
|
|
|
+ ->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
|
|
|
+ ->groupBy('data_income_pay_type')
|
|
|
+ ->first();
|
|
|
+
|
|
|
$alipay = Db::table("data_income_{$month}")
|
|
|
- ->where('data_income_days',$currentDay)
|
|
|
- ->where('data_income_pay_type','ALIPAY')
|
|
|
- ->whereIn('join_data_income_dept_id',$premisesKey)
|
|
|
+ ->where('data_income_days', $currentDay)
|
|
|
+ ->where('data_income_pay_type', 'ALIPAY')
|
|
|
+ ->whereIn('join_data_income_dept_id', $premisesKey)
|
|
|
->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
|
|
|
->groupBy('data_income_pay_type')
|
|
|
->first();
|
|
|
-
|
|
|
+
|
|
|
$qrcode = Db::table("data_income_{$month}")
|
|
|
- ->where('data_income_days',$currentDay)
|
|
|
- ->where('data_income_pay_type','QRCODE')
|
|
|
- ->whereIn('join_data_income_dept_id',$premisesKey)
|
|
|
+ ->where('data_income_days', $currentDay)
|
|
|
+ ->where('data_income_pay_type', 'MONEY')
|
|
|
+ ->whereIn('join_data_income_dept_id', $premisesKey)
|
|
|
->selectRaw("data_income_pay_type,SUM(data_income_amount) as data_income_amount")
|
|
|
->groupBy('data_income_pay_type')
|
|
|
->first();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
$dayData['income']['wxpay'] = $wxpay->data_income_amount ?? 0.00;
|
|
|
$statistics['income_wxpay'] += $dayData['income']['wxpay'];
|
|
|
$dayData['income']['alipay'] = $alipay->data_income_amount ?? 0.00;
|
|
|
$statistics['income_alipay'] += $dayData['income']['alipay'];
|
|
|
- $dayData['income']['qrcode'] = $qrcode->data_income_amount ?? 0.00;
|
|
|
- $statistics['income_qrcode'] += $dayData['income']['qrcode'];
|
|
|
+ $dayData['income']['money'] = $qrcode->data_income_amount ?? 0.00;
|
|
|
+ $statistics['income_money'] += $dayData['income']['money'];
|
|
|
|
|
|
- $dayData['income']['amount'] = $dayData['income']['wxpay']+$dayData['income']['alipay']+$dayData['income']['qrcode'];
|
|
|
+ $dayData['income']['amount'] = $dayData['income']['wxpay'] + $dayData['income']['alipay'] + $dayData['income']['money'];
|
|
|
|
|
|
$statistics['income_amount'] += $dayData['income']['amount'];
|
|
|
|
|
|
// 支出
|
|
|
- if(Util::schema()->hasTable("data_income_{$month}")){
|
|
|
+ if (Util::schema()->hasTable("data_income_{$month}")) {
|
|
|
$extendWxpay = Db::table("data_expend_{$month}")
|
|
|
- ->where('data_expend_days',$currentDay)
|
|
|
- ->where('data_expend_pay_type','WXPAY')
|
|
|
- ->whereIn('join_data_expend_dept_id',$premisesKey)
|
|
|
+ ->where('data_expend_days', $currentDay)
|
|
|
+ ->where('data_expend_pay_type', 'WXPAY')
|
|
|
+ ->whereIn('join_data_expend_dept_id', $premisesKey)
|
|
|
->selectRaw("data_expend_pay_type,SUM(data_expend_amount) as data_expend_amount")
|
|
|
->groupBy('data_expend_pay_type')
|
|
|
->first();
|
|
|
|
|
|
$extendAlipay = Db::table("data_expend_{$month}")
|
|
|
- ->where('data_expend_days',$currentDay)
|
|
|
- ->where('data_expend_pay_type','ALIPAY')
|
|
|
- ->whereIn('join_data_expend_dept_id',$premisesKey)
|
|
|
+ ->where('data_expend_days', $currentDay)
|
|
|
+ ->where('data_expend_pay_type', 'ALIPAY')
|
|
|
+ ->whereIn('join_data_expend_dept_id', $premisesKey)
|
|
|
+ ->selectRaw("data_expend_pay_type,SUM(data_expend_amount) as data_expend_amount")
|
|
|
+ ->groupBy('data_expend_pay_type')
|
|
|
+ ->first();
|
|
|
+
|
|
|
+ $extendMoney = Db::table("data_expend_{$month}")
|
|
|
+ ->where('data_expend_days', $currentDay)
|
|
|
+ ->where('data_expend_pay_type', 'MONEY')
|
|
|
+ ->whereIn('join_data_expend_dept_id', $premisesKey)
|
|
|
->selectRaw("data_expend_pay_type,SUM(data_expend_amount) as data_expend_amount")
|
|
|
->groupBy('data_expend_pay_type')
|
|
|
->first();
|
|
@@ -105,21 +113,23 @@ class IncomeAndExpendController
|
|
|
$statistics['expend_wxpay'] += $dayData['expend']['wxpay'];
|
|
|
$dayData['expend']['alipay'] = $extendAlipay->data_expend_amount ?? 0.00;
|
|
|
$statistics['expend_alipay'] += $dayData['expend']['alipay'];
|
|
|
- $dayData['expend']['amount'] = $dayData['expend']['wxpay']+$dayData['expend']['alipay'];
|
|
|
+ $dayData['expend']['money'] = $extendMoney->data_expend_amount ?? 0.00;
|
|
|
+ $statistics['expend_money'] += $dayData['expend']['money'];
|
|
|
+ $dayData['expend']['amount'] = $dayData['expend']['wxpay'] + $dayData['expend']['alipay'] + $dayData['expend']['money'];
|
|
|
|
|
|
$statistics['expend_amount'] += $dayData['expend']['amount'];
|
|
|
|
|
|
// 当前日期+1
|
|
|
- $currentDay = date('Y-m-d',strtotime("+1 days",strtotime($currentDay)));
|
|
|
+ $currentDay = date('Y-m-d', strtotime("+1 days", strtotime($currentDay)));
|
|
|
|
|
|
// 没有数据,跳过
|
|
|
- if($dayData['expend']['amount'] == 0 && $dayData['income']['amount'] == 0){
|
|
|
+ if ($dayData['expend']['amount'] == 0 && $dayData['income']['amount'] == 0) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
$data[] = $dayData;
|
|
|
}
|
|
|
|
|
|
- return json_success('',['rows'=>$data,'statistics'=>$statistics]);
|
|
|
+ return json_success('', ['rows' => $data, 'statistics' => $statistics]);
|
|
|
}
|
|
|
}
|