|
@@ -334,6 +334,14 @@ class CardMainController extends Curd
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @Desc 储值卡统计
|
|
|
+ * @Author Gorden
|
|
|
+ * @Date 2024/11/22 13:06
|
|
|
+ *
|
|
|
+ * @param Request $request
|
|
|
+ * @return Response
|
|
|
+ */
|
|
|
public function statistics(Request $request)
|
|
|
{
|
|
|
$classify = $request->get('card_main_classify');
|
|
@@ -350,10 +358,59 @@ class CardMainController extends Curd
|
|
|
})->when(!empty($addtimes), function ($query) use ($addtimes) {
|
|
|
$addtimes[0] = strtotime($addtimes[0]);
|
|
|
$addtimes[1] = strtotime($addtimes[1]);
|
|
|
- $query->whereBetween('card_main_addtimes',$addtimes);
|
|
|
+ $query->whereBetween('card_main_addtimes', $addtimes);
|
|
|
});
|
|
|
|
|
|
+ $statistics = [];
|
|
|
$totalModel = clone $cardMain;
|
|
|
-// $totalIds =
|
|
|
+ $totalList = $totalModel->select('card_main_id', 'card_main_amount')->get()->toArray();
|
|
|
+ $statistics = [
|
|
|
+ 'total' => ['total' => 0, 'amount' => 0],
|
|
|
+ 'is_issue' => ['total' => 0, 'amount' => 0],
|
|
|
+ 'init' => ['total' => 0, 'amount' => 0],
|
|
|
+ 'waiting' => ['total' => 0, 'amount' => 0],
|
|
|
+ 'pending' => ['total' => 0, 'amount' => 0],
|
|
|
+ 'used' => ['total' => 0, 'amount' => 0],
|
|
|
+ 'done' => ['total' => 0, 'amount' => 0],
|
|
|
+ 'paused' => ['total' => 0, 'amount' => 0]
|
|
|
+ ];
|
|
|
+ foreach ($totalList as $total) {
|
|
|
+ // 发行统计
|
|
|
+ $isIssueTotal = Card::where('is_issue', 'Y')->where('join_card_main_id', $total['card_main_id'])->count();
|
|
|
+ $statistics['is_issue']['total'] += $isIssueTotal;
|
|
|
+ $statistics['is_issue']['amount'] = sprintf('%.2f', $statistics['is_issue']['total'] * $total['card_main_amount'] + $statistics['is_issue']['amount']);
|
|
|
+ // 待分配统计
|
|
|
+ $initTotal = Card::where('card_status', 'INIT')->where('join_card_main_id', $total['card_main_id'])->count();
|
|
|
+ $statistics['init']['total'] += $initTotal;
|
|
|
+ $statistics['init']['amount'] = sprintf('%.2f', $statistics['init']['total'] * $total['card_main_amount'] + $statistics['init']['amount']);
|
|
|
+ // 已分配,待售统计
|
|
|
+ $waitingTotal = Card::where('card_status', 'WAITING')->where('join_card_main_id', $total['card_main_id'])->count();
|
|
|
+ $statistics['waiting']['total'] += $waitingTotal;
|
|
|
+ $statistics['waiting']['amount'] = sprintf('%.2f', $statistics['waiting']['total'] * $total['card_main_amount'] + $statistics['waiting']['amount']);
|
|
|
+ // 已售,待激活统计
|
|
|
+ $pendingTotal = Card::where('card_status', 'PENDING')->where('join_card_main_id', $total['card_main_id'])->count();
|
|
|
+ $statistics['pending']['total'] += $pendingTotal;
|
|
|
+ $statistics['pending']['amount'] = sprintf('%.2f', $statistics['pending']['total'] * $total['card_main_amount'] + $statistics['pending']['amount']);
|
|
|
+ // 已激活统计
|
|
|
+ $usedTotal = Card::where('card_status', 'USED')->where('join_card_main_id', $total['card_main_id'])->count();
|
|
|
+ $statistics['used']['total'] += $usedTotal;
|
|
|
+ $statistics['used']['amount'] = sprintf('%.2f', $statistics['used']['total'] * $total['card_main_amount']);
|
|
|
+ // 使用完成统计
|
|
|
+ $doneTotal = Card::where('card_status', 'DONE')->where('join_card_main_id', $total['card_main_id'])->count();
|
|
|
+ $statistics['done']['total'] += $doneTotal;
|
|
|
+ $statistics['done']['amount'] = sprintf('%.2f', $statistics['done']['total'] * $total['card_main_amount'] + $statistics['done']['amount']);
|
|
|
+ // 冻结统计
|
|
|
+ $pausedTotal = Card::where('card_status', 'PAUSED')->where('join_card_main_id', $total['card_main_id'])->count();
|
|
|
+ $statistics['paused']['total'] += $pausedTotal;
|
|
|
+ $statistics['paused']['amount'] = sprintf('%.2f', $statistics['paused']['total'] * $total['card_main_amount'] + $statistics['paused']['total']);
|
|
|
+ }
|
|
|
+ $statistics['total']['total'] = $statistics['init']['total'] + $statistics['waiting']['total']
|
|
|
+ + $statistics['pending']['total'] + $statistics['used']['total'] + $statistics['done']['total']
|
|
|
+ + $statistics['paused']['total'];
|
|
|
+ $statistics['total']['amount'] = sprintf('%.2f', $statistics['init']['amount']
|
|
|
+ + $statistics['waiting']['amount'] + $statistics['pending']['amount'] + $statistics['used']['amount']
|
|
|
+ + $statistics['done']['amount'] + $statistics['paused']['amount']);
|
|
|
+
|
|
|
+ return json_success('success', $statistics);
|
|
|
}
|
|
|
}
|