gorden 8 miesięcy temu
rodzic
commit
8692ce2a82

+ 0 - 1
app/admin/controller/finance/GoodsSalesController.php

@@ -34,7 +34,6 @@ class GoodsSalesController
         if (!empty($days)) {
             $where .= " where di.data_income_addtimes between {$days[0]} and {$days[1]}";
         }
-        dump($where);
 
         $totalSql = "
             select count(*) as total from (

+ 42 - 31
app/admin/controller/finance/MemberAccountController.php

@@ -13,14 +13,14 @@ class MemberAccountController
     {
         $page = $request->get('page', 1);
         $pageSize = $request->get('pageSize', 20);
-        $classify = $request->get('classify', 'CASH');
-        $days = ['2024-06-01', '2024-06-30'];
+        // $classify = $request->get('classify', 'CASH');
+        $days = $request->get('member_addtimes', []);
+        $level = $request->get('level', '');
+        $accountType = $request->get('account_type', 'CASH');
+        $premisesId = intval($request->get('premises_id', ''));
         if (!empty($days)) {
             $days[0] = strtotime($days[0]);
             $days[1] = strtotime($days[1]);
-            if (date('m', $days[0]) != date('m', $days[1])) {
-                return json_fail('暂不支持跨月查询');
-            }
 
             $month = date('Ym', $days[0]);
             $days[1] = strtotime(date('Y-m-d', $days[1]) . " 23:59:59");
@@ -58,34 +58,45 @@ class MemberAccountController
         // return json_success('', compact('rows', 'page', 'pageSize', 'total','statistics'));
 
 
-       $rows = Member::with([
-           'cert' => function ($query) {
-               $query->select('join_cert_member_id', 'member_cert_name');
-           },
-           'info' => function ($query) {
-               $query->select('join_info_member_id', 'member_info_nickname');
-           },
-           'role' => function ($query) {
-               $query->select('member_role_id', 'member_role_name');
-           }
-       ])->join('member_account as ma',function($join) use ($classify){
-           $join->on('member.member_id','=','ma.join_account_member_id')->where('ma.member_account_classify','=',$classify);
-       });
+        $rows = Member::with([
+            'cert' => function ($query) {
+                $query->select('join_cert_member_id', 'member_cert_name');
+            },
+            'info' => function ($query) {
+                $query->select('join_info_member_id', 'member_info_nickname');
+            },
+            'role' => function ($query) {
+                $query->select('member_role_id', 'member_role_name');
+            }
+        ])->join('member_account as ma', function ($join) use ($accountType) {
+            $join->on('member.member_id', '=', 'ma.join_account_member_id')->where('ma.member_account_classify', '=', $accountType);
+        })->when(!empty($level), function ($query) use ($level) {
+            if ($level == '00'){
+                $query->where('join_member_role_id','')->orWhere('join_member_role_id',NULL);
+            }else{
+                $query->where('join_member_role_id', $level);
+            }
+            
+        })->when(!empty($days), function ($query) use ($days) {
+            $query->whereBetween('member.member_addtimes', $days);
+        })->when(!empty($premisesId), function ($query) use ($premisesId) {
+            $query->whereJsonContains('member.member_extend_json->belong->premises', $premisesId);
+        });
 
-       $total = $rows->count('member_id');
-       $statistics['surplus'] = $rows->sum('ma.member_account_surplus');
-       $statistics['income'] = $rows->sum('ma.member_account_income');
-       $statistics['expend'] = $rows->sum('member_account_expend');
-       $statistics['added'] = $rows->sum('member_account_added');
+        $total = $rows->count('member_id');
+        $statistics['surplus'] = $rows->sum('ma.member_account_surplus');
+        $statistics['income'] = $rows->sum('ma.member_account_income');
+        $statistics['expend'] = $rows->sum('member_account_expend');
+        $statistics['added'] = $rows->sum('member_account_added');
 
-       $rows = $rows->select('member.member_id','member.member_mobile','member.member_addtimes',
-           'ma.member_account_income as member_account_income','ma.member_account_expend as member_account_expend'
-       )
-       ->orderBy('member.member_addtimes', 'DESC')
-           ->forPage($page, $pageSize)
-           ->get()
-           ->toArray();
+        $rows = $rows->select('member.member_id', 'member.member_mobile', 'member.member_addtimes', 'member.join_member_role_id',
+            'ma.member_account_income as member_account_income', 'ma.member_account_expend as member_account_expend', 'ma.member_account_surplus as member_account_surplus', 'ma.member_account_added as member_account_added'
+        )
+            ->orderBy('member.member_addtimes', 'DESC')
+            ->forPage($page, $pageSize)
+            ->get()
+            ->toArray();
 
-       return json_success('', compact('rows', 'page', 'pageSize', 'total','statistics'));
+        return json_success('', compact('rows', 'page', 'pageSize', 'total', 'statistics'));
     }
 }

+ 93 - 0
app/admin/controller/finance/PremisesMemberController.php

@@ -0,0 +1,93 @@
+<?php
+
+namespace app\admin\controller\finance;
+
+use app\admin\service\sys_manage\DeptService;
+use app\common\Util;
+use support\Db;
+use support\Request;
+use function _PHPStan_cc8d35ffb\RingCentral\Psr7\str;
+
+class PremisesMemberController
+{
+
+    private $accountType = ['CASH', 'POINTS', 'CARD'];
+
+    public function list(Request $request)
+    {
+        $page = $request->get('page', 1);
+        $pageSize = $request->get('pageSize', 20);
+        $accountType = $request->get('account_type', $this->accountType);
+        $premises = $request->get('premises', DeptService::getPremisesList());
+        $premisesKeyValue = [];
+        foreach($premises as $item){
+            $premisesKeyValue[$item['key']] = $item['label'];
+        }
+        $months = $request->get('month', []);
+        if (empty($months)) {
+            $months = [date('Y-m')];
+//            $months = ['2024-06'];
+        }else{
+            foreach($months as $key => $month){
+                $months[$key] = date('Y-m',strtotime($month));
+            }
+        }
+        $data = [];
+        $statistics = ['surplus'=>0,'income'=>0,'added'=>0,'expend'=>0];
+        foreach ($months as $month) {
+            $day = $month . '-01';
+            $monthStr = date('m', strtotime($day));
+            $firstDay = date('Y-m-t', strtotime('last month', strtotime($day)));
+            $firstMonth = date('Ym', strtotime($firstDay));
+            $lastDay = date('Y-m-t', strtotime($month));
+            if (strtotime("-1 days") < strtotime($lastDay)) {
+                $lastDay = date('Y-m-d', strtotime("-1 days"));
+            }
+            $lastMonth = date('Ym', strtotime($lastDay));
+            foreach ($premises as $premise) {
+                $premiseKey = intval($premise['key']);
+                foreach ($accountType as $item) {
+                    $firstData = [];
+                    $firstTable = "data_account_{$firstMonth}";
+                    if (Util::schema()->hasTable($firstTable)) {
+                        $firstData = Db::table("{$firstTable} as da")
+                            ->leftJoin('member', 'member.member_id', '=', 'da.join_data_account_member_id')
+                            ->whereJsonContains('member.member_extend_json->belong->premises', $premiseKey)
+                            ->where('data_account_days', $firstDay)
+                            ->where('data_account_classify', $item)
+                            ->selectRaw("SUM(data_account_income) as data_account_income,SUM(data_account_expend) as data_account_expend,SUM(data_account_surplus) as data_account_surplus,SUM(data_account_added) as data_account_added")
+                            ->groupBy('data_account_days')
+                            ->first();
+                    }
+
+                    $lastData = Db::table("data_account_{$lastMonth} as da")
+                        ->leftJoin('member', 'member.member_id', '=', 'da.join_data_account_member_id')
+                        ->whereJsonContains('member.member_extend_json->belong->premises', $premiseKey)
+                        ->where('data_account_days', $lastDay)
+                        ->where('data_account_classify', $item)
+                        ->selectRaw('SUM(data_account_income) as data_account_income,SUM(data_account_expend) as data_account_expend,SUM(data_account_surplus) as data_account_surplus,SUM(data_account_added) as data_account_added')
+                        ->groupBy('data_account_days')
+                        ->first();
+
+                    $record = [
+                        'month' => $monthStr,
+                        'premise' => isset($premisesKeyValue[$premiseKey]) ? $premisesKeyValue[$premiseKey] : $premiseKey,
+                        'account_type' => $item,
+                        'data_account_surplus' => $lastData->data_account_surplus ?? '0.00',
+                        'data_account_income' => !empty($firstData) ? number_format($lastData->data_account_income - $firstData->data_account_income,2,'.','') : ($lastData->data_account_income ?? '0.00'),
+                        'data_account_expend' => !empty($firstData) ? number_format($lastData->data_account_expend - $firstData->data_account_expend,2,'.','') : ($lastData->data_account_expend ?? '0.00'),
+                        'data_account_added' => !empty($firstData) ? number_format($lastData->data_account_added - $firstData->data_account_added,2,'.','') : ($lastData->data_account_added ?? '0.00'),
+                    ];
+                    $statistics['surplus'] = number_format($statistics['surplus']+$record['data_account_surplus'],2,'.','');
+                    $statistics['income'] = number_format($statistics['income']+$record['data_account_income'],2,'.','');
+                    $statistics['expend'] = number_format($statistics['expend']+$record['data_account_expend'],2,'.','');
+                    $statistics['added'] = number_format($statistics['added']+$record['data_account_added'],2,'.','');
+
+                    $data[] = $record;
+                }
+            }
+        }
+
+        return json_success('', ['rows'=>$data,'statistics'=>$statistics]);
+    }
+}

+ 39 - 0
app/admin/controller/finance/PremisesRevenueController.php

@@ -0,0 +1,39 @@
+<?php
+
+namespace app\admin\controller\finance;
+
+use app\admin\service\sys_manage\DeptService;
+use support\Db;
+use support\Request;
+
+class PremisesRevenueController
+{
+
+    private $accountType = ['CASH', 'POINTS', 'CARD'];
+
+    public function list(Request $request)
+    {
+        $page = $request->get('page', 1);
+        $pageSize = $request->get('pageSize', 20);
+        $premises = $request->get('premises', DeptService::getPremisesList());
+        $premisesKeyValue = [];
+        foreach($premises as $item){
+            $premisesKeyValue[$item['key']] = $item['label'];
+        }
+
+        $month = date('Ym');
+        
+        foreach ($premises as $premise) {
+            $premiseKey = intval($premise['key']);
+            $income = Db::table("data_income_{$month}")
+                ->where('join_data_income_dept_id',$premiseKey)
+                ->groupBy('data_income_pay_type')
+            ;
+        }
+        
+        $data = Db::table("data_income_{$month}");
+        $statistics = [];
+
+        return json_success('', ['rows'=>$data,'statistics'=>$statistics]);
+    }
+}

+ 1 - 1
app/admin/service/order/AppointmentService.php

@@ -56,7 +56,7 @@ class AppointmentService
             'member_cert.member_cert_name',
             'member_info.member_info_nickname',
             'goods.goods_name', 'goods.goods_cover', 'goods.goods_sales_price',
-            'order.order_name', 'goods_sku.goods_sku_specs_json', 'order.order_amount_total', 'order.order_amount_pay',
+            'order.order_id','order.order_name', 'goods_sku.goods_sku_specs_json', 'order.order_amount_total', 'order.order_amount_pay',
             'order.order_category', 'order.order_status_system', 'order.order_status_payment', 'order.order_status_storage',
             'order.order_addtimes',
             'member_benefit.member_benefit_name','member_benefit.member_benefit_id as benefit_id'

+ 18 - 3
app/admin/service/sys_manage/DeptService.php

@@ -40,12 +40,12 @@ class DeptService
 
         $category = $request->get('dept_category', '医护科室');
 
-        $depts = SysDept::where('dept_category',$category)
-            ->select('dept_id','dept_name')
+        $depts = SysDept::where('dept_category', $category)
+            ->select('dept_id', 'dept_name')
             ->get()
             ->toArray();
 
-        return json_success('',$depts);
+        return json_success('', $depts);
     }
 
     /**
@@ -233,4 +233,19 @@ class DeptService
     {
         return SysDept::where('dept_id', $deptId)->exists();
     }
+
+    public static function getPremisesList()
+    {
+        $premises = SysDept::where('dept_category','营业场所')->pluck('dept_name','dept_id')->toArray();
+        $arr = [];
+
+        foreach($premises as $key => $value){
+            $arr[] = [
+                'key'=>$key,
+                'label' =>$value
+            ];
+        }
+
+        return $arr;
+    }
 }

+ 3 - 0
route/admin.php

@@ -104,6 +104,9 @@ Route::group('/admin', function () {
         Route::group('/memberAccount',function (){
             Route::get('/list',[\app\admin\controller\finance\MemberAccountController::class,'list']);
         });
+        Route::group('/premisesMember',function (){
+            Route::get('/list',[\app\admin\controller\finance\PremisesMemberController::class,'list']);
+        });
     });
     /* 系统管理中心 */
     Route::group('/sys', function () {