浏览代码

商品销售统计

gorden 4 月之前
父节点
当前提交
0a63eae32c
共有 2 个文件被更改,包括 44 次插入27 次删除
  1. 32 22
      app/admin/controller/finance/GoodsSalesController.php
  2. 12 5
      app/admin/service/sys_manage/CategoryService.php

+ 32 - 22
app/admin/controller/finance/GoodsSalesController.php

@@ -20,7 +20,6 @@ class GoodsSalesController
         $classify = $request->get('classify', '');
         $categoryId = $request->get('category_id', '');
         $goodsName = $request->get('goods_name', '');
-        $premisesId = $request->get('premises_id', '');
         $payType = $request->get('pay_type', '');
         if (!empty($days)) {
             $days[0] = strtotime($days[0]);
@@ -28,16 +27,27 @@ class GoodsSalesController
         }
         $searchGoodsIds = [];
         if (!empty($classify)) {
-            $searchGoodsIds = Goods::where('goods_classify', $classify)->pluck('goods_id')->toArray();
-        } elseif (!empty($categoryId)) {
+            if ($classify == 'SERVICE') {
+                $classify = ['SERVICE', 'CHNMED', 'CHNNCD'];
+            } else {
+                $classify = [$classify];
+            }
+            $searchGoodsIds = Goods::whereIn('goods_classify', $classify)->pluck('goods_id')->toArray();
+        }
+        if (!empty($categoryId)) {
             $categorySuperPath = SysCategory::where('category_id', $categoryId)->value('category_super_path');
-            $searchCategoryIds = [];
-            if (!empty($category)) {
-                $searchCategoryIds = SysCategory::where('category_super_path', 'like', $categorySuperPath . '%')->pluck('category_id')->toArray();
+            if (empty($categorySuperPath)) {
+                $categorySuperPath = '#' . $categoryId . '#';
             }
+            $searchCategoryIds = SysCategory::where('category_super_path', 'like', $categorySuperPath . '%')->pluck('category_id')->toArray();
             $searchCategoryIds[] = $categoryId;
+            // 按产品分类筛出来的ID
+            $oldSearchGoodsIds = $searchGoodsIds;
 
             $searchGoodsIds = Goods::whereIn('join_goods_category_id', $searchCategoryIds)->pluck('goods_id')->toArray();
+            if (!empty($oldSearchGoodsIds)){
+                $searchGoodsIds = array_intersect($searchGoodsIds,$oldSearchGoodsIds);
+            }
         }
 
         $dataInOuts = DataInout::where('data_inout_status', 'VALID')
@@ -56,18 +66,18 @@ class GoodsSalesController
         $statistics = [
             'total' => 0,
             'amount' => 0,
-            'goods'=>['total' => 0,'amount' => 0],
-            'service'=>['total' => 0,'amount' => 0],
-            'chnmed'=>['total' => 0,'amount' => 0],
-            'chnncd'=>['total' => 0,'amount' => 0],
-            'package'=>['total' => 0,'amount' => 0],
-            'meals'=>['total' => 0,'amount' => 0],
-            'dishes'=>['total' => 0,'amount' => 0],
-            'vip'=>['total' => 0,'amount' => 0],
-            'recharge'=>['total' => 0,'amount' => 0],
-            'combine'=>['total' => 0,'amount' => 0],
-            'partner'=>['total' => 0,'amount' => 0],
-            'referrer'=>['total' => 0,'amount' => 0],
+            'goods' => ['total' => 0, 'amount' => 0],
+            'service' => ['total' => 0, 'amount' => 0],
+            'chnmed' => ['total' => 0, 'amount' => 0],
+            'chnncd' => ['total' => 0, 'amount' => 0],
+            'package' => ['total' => 0, 'amount' => 0],
+            'meals' => ['total' => 0, 'amount' => 0],
+            'dishes' => ['total' => 0, 'amount' => 0],
+            'vip' => ['total' => 0, 'amount' => 0],
+            'recharge' => ['total' => 0, 'amount' => 0],
+            'combine' => ['total' => 0, 'amount' => 0],
+            'partner' => ['total' => 0, 'amount' => 0],
+            'referrer' => ['total' => 0, 'amount' => 0],
         ];
         foreach ($dataInOuts as $dataInOut) {
             if (empty($dataInOut['join_data_inout_object_json'])) {
@@ -100,12 +110,12 @@ class GoodsSalesController
                         $goods[$goodKey]['order_sheet_pay'] += $good['order_sheet_pay'];
                     }
 
-                    $statistics['total'] = round($good['order_sheet_num'] + $statistics['total'],2);
-                    $statistics['amount'] =  round($good['order_sheet_pay'] + $statistics['amount'],2);
+                    $statistics['total'] = round($good['order_sheet_num'] + $statistics['total'], 2);
+                    $statistics['amount'] = round($good['order_sheet_pay'] + $statistics['amount'], 2);
 
                     $orderClassify = strtolower($order['classify']);
-                    $statistics[$orderClassify]['total'] = $good['order_sheet_num'] + $statistics[$orderClassify]['total'];
-                    $statistics[$orderClassify]['amount'] = $good['order_sheet_pay'] + $statistics[$orderClassify]['amount'];
+                    $statistics[$orderClassify]['total'] = round($good['order_sheet_num'] + $statistics[$orderClassify]['total'], 2);
+                    $statistics[$orderClassify]['amount'] = round($good['order_sheet_pay'] + $statistics[$orderClassify]['amount'], 2);
                 }
             }
         }

+ 12 - 5
app/admin/service/sys_manage/CategoryService.php

@@ -135,7 +135,14 @@ class CategoryService
             ];
             if ($category->category_super_id != $params['category_super_id'] && $params['category_super_id'] != 0) {
                 $data['category_super_id'] = $params['category_super_id'];
-                $data['category_super_path'] = self::getCategoryPath($params['category_super_id']) . '#' . $params['category_super_id'] . '#';
+                $parentSuperPath = self::getCategoryPath($params['category_super_id']);
+                $superPath = '#' . $params['category_super_id'] . '#';
+                if ($parentSuperPath == $superPath) {
+                    $data['category_super_path'] = $superPath;
+                } else {
+                    $data['category_super_path'] = $parentSuperPath . $superPath;
+                }
+
             }
             if (!SysCategory::where('category_id', $id)->update($data)) {
                 throw new \Exception('分类修改失败');
@@ -225,8 +232,8 @@ class CategoryService
     {
         // 查询当前父级ID下的所有分类
         $list = self::getAllCategories($parentId);
-        $allCategories = self::getTree($list,152);
-        return json_success('',$allCategories);
+        $allCategories = self::getTree($list, 152);
+        return json_success('', $allCategories);
     }
 
     /**
@@ -241,7 +248,7 @@ class CategoryService
     {
         // 查询当前父级ID下的所有分类
         $row = SysCategory::where('category_super_id', $parentId)->where('category_status', 'ACTIVED')->get()->toArray();
-        if(!empty($row)) {
+        if (!empty($row)) {
             foreach ($row as $key => $value) {
                 // 当前分类加入数组
                 $value['label'] = $value['category_name'];
@@ -287,7 +294,7 @@ class CategoryService
      */
     public static function getCategoryInfos($ids)
     {
-        $category = SysCategory::whereIn('category_id', $ids)->select(['category_id','category_name','category_super_id'])->get()->toArray();
+        $category = SysCategory::whereIn('category_id', $ids)->select(['category_id', 'category_name', 'category_super_id'])->get()->toArray();
         if (!$category) {
             return json_fail('分类不存在');
         }