gorden 17 saat önce
ebeveyn
işleme
84fe68250c

+ 59 - 2
app/admin/controller/coupon/CardMainController.php

@@ -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);
     }
 }

+ 14 - 0
app/admin/controller/order/WholeController.php

@@ -109,6 +109,20 @@ class WholeController extends Curd
             $where['order_classify'] = ['in', ['RECHARGE', 'COMBINE', 'PARTNER', 'REFERRER', 'VIP']];
             $todayTimeUnix = strtotime(date('Y-m-d') . ' 00:00:00');
             $where['order_addtimes'] = ['>', $todayTimeUnix];
+        } else if ($type == 'todayCash') {
+            $todayTimeUnix = strtotime(date('Y-m-d') . ' 00:00:00');
+            $groupIds = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) > ? ', [$todayTimeUnix])
+                ->where(function ($query) {
+                    $query->where('pay_prepayid','like', '%CASH%')
+                        ->OrWhere('pay_prepayid','like', '%VIP%')
+                        ->orWhere('pay_prepayid','like', '%WELFARE%');
+                })
+                ->where('join_pay_order_id', '<>', '')
+                ->whereIn('pay_category', ['GOODS', 'SERVICE', 'CHNMED', 'CHNNCD', 'PACKAGE', 'MEALS'])
+                ->where('pay_status', 'SUCCESS')
+                ->pluck('join_pay_order_id')
+                ->toArray();
+            $where['order_groupby'] = ['in', $groupIds];
         }
         $orderIds = [];
         if (!empty($where['order_id'])) {

+ 13 - 1
app/admin/service/statistics/OrderService.php

@@ -29,7 +29,7 @@ class OrderService
         // 今日充值额
         $data['todayRecharge'] = Order::where('order_status_payment', 'SUCCESS')
             ->where('order_addtimes', '>', $todayTimeUnix)
-            ->whereIn('order_category', ['RECHARGE','COMBINE','PARTNER','REFERRER','VIP'])
+            ->whereIn('order_category', ['RECHARGE', 'COMBINE', 'PARTNER', 'REFERRER', 'VIP'])
             ->where('order_status_payment', 'SUCCESS')
             ->sum('order_amount_pay');
         // 今日退单
@@ -43,6 +43,18 @@ class OrderService
             ->sum('pay_amount');
 
         $data['todaySales'] = round($data['todaySales'], 2);
+        // 今日余额收入
+        $data['todayCashSales'] = PayDetail::whereRaw('CAST(UNIX_TIMESTAMP(pay_paytimes) as SIGNED) > ? ', [$todayTimeUnix])
+            ->where(function ($query) {
+                $query->where('pay_prepayid','like', '%CASH%')
+                    ->OrWhere('pay_prepayid','like', '%VIP%')
+                    ->orWhere('pay_prepayid','like', '%WELFARE%');
+            })
+            ->where('join_pay_order_id', '<>', '')
+            ->where('pay_status', 'SUCCESS')
+            ->sum('pay_amount');
+
+        $data['todayCashSales'] = round($data['todayCashSales'], 2);
 
         // 柱状图
         // 产品订单

+ 1 - 1
route/admin.php

@@ -1074,7 +1074,7 @@ Route::group('/admin', function () {
     Route::group('/card', function () {
         Route::group('/main', function () {
             Route::get('/list', [\app\admin\controller\coupon\CardMainController::class, 'select']);
-//            Route::get('/statistics', [\app\admin\controller\coupon\CouponController::class, 'statistics']);
+            Route::get('/statistics', [\app\admin\controller\coupon\CardMainController::class, 'statistics']);
             Route::get('/selectList', [\app\admin\controller\coupon\CardMainController::class, 'selectList']);
             Route::get('/info', [\app\admin\controller\coupon\CardMainController::class, 'info']);
             Route::post('/add', [\app\admin\controller\coupon\CardMainController::class, 'insert']);