ZhouBenXu il y a 4 mois
Parent
commit
c070a173bc

+ 6 - 0
app/admin/controller/sys_manage/CategoryController.php

@@ -218,4 +218,10 @@ class CategoryController extends Curd
     {
         return CategoryService::delCategory($request);
     }
+
+    public function getCategoryTree(Request $request)
+    {
+        $category_id = $request->get('category_id');
+        return CategoryService::getCategoryTree($category_id);
+    }
 }

+ 12 - 0
app/admin/service/card/CardBatchService.php

@@ -15,6 +15,7 @@ use support\Response;
 use app\model\CardBatch;
 use app\model\Card;
 use app\admin\service\card\CardService;
+use app\admin\service\sys_manage\CategoryService;
 
 class CardBatchService
 {
@@ -31,6 +32,10 @@ class CardBatchService
         try {
             // 添加卡批次
             $model = new CardBatch();
+            if (is_array($params['join_card_batch_category_id'])) {
+                $params['join_card_batch_category_id'] = end($params['join_card_batch_category_id']);
+            }
+
             $model->join_card_batch_user_id = $params['join_card_batch_user_id']; // 批次创建用户 user_id
             $model->join_card_batch_category_id = $params['join_card_batch_category_id']; // 批次卡分类ID
             $model->card_batch_status = $params['card_batch_status']; // 批次状态
@@ -243,6 +248,12 @@ class CardBatchService
 
 
         if (!empty($rows)) {
+
+            // 查询所有分类信息
+            $category = array_column($rows, 'join_card_batch_category_id');
+            $categoryInfos = CategoryService::getCategoryInfos($category) ?? [];
+            $categoryInfos && $categoryInfos = array_column($categoryInfos, null, 'category_id');
+
             // 查询求和数据信息
             $card_batch_id_string = implode(',', array_column($rows, 'card_batch_id'));
             $sql = "select join_card_batch_id,
@@ -280,6 +291,7 @@ class CardBatchService
             $card_status_total = array_column($card_status_total, null, 'join_card_batch_id');
             foreach ($rows as $key => &$value) {
                 $value['card_batch_status_value'] = $cardBatchModel::CARD_BATCH_STATUS[$value['card_batch_status']];
+                $value['category_name'] = $categoryInfos[$value['join_card_batch_category_id']]['category_name'] ?? "";
                 if ($value['card_batch_validtimes'] == 0) {
                     $value['card_batch_validtimes_value'] = "永久";
                 } else {

+ 81 - 0
app/admin/service/sys_manage/CategoryService.php

@@ -213,4 +213,85 @@ class CategoryService
         }
         return $category->category_super_path;
     }
+
+    /**
+     * Notes: 获取树状分类信息
+     * User: ZhouBenXu
+     * DateTime: 2024/7/2 下午2:52
+     * @param $parentId
+     * @return \support\Response
+     */
+    public static function getCategoryTree($parentId)
+    {
+        // 查询当前父级ID下的所有分类
+        $list = self::getAllCategories($parentId);
+        $allCategories = self::getTree($list,152);
+        return json_success('',$allCategories);
+    }
+
+    /**
+     * Notes: 获取指定分类下的所有分类
+     * User: ZhouBenXu
+     * DateTime: 2024/7/2 下午2:41
+     * @param $parentId
+     * @param $categories
+     * @return array|mixed
+     */
+    public static function getAllCategories($parentId = 0, $categories = [])
+    {
+        // 查询当前父级ID下的所有分类
+        $row = SysCategory::where('category_super_id', $parentId)->where('category_status', 'ACTIVED')->get()->toArray();
+        if(!empty($row)) {
+            foreach ($row as $key => $value) {
+                // 当前分类加入数组
+                $value['label'] = $value['category_name'];
+                $value['value'] = $value['category_id'];
+                $categories[] = $value;
+                // 递归查询子分类
+                $categories = self::getAllCategories($value['category_id'], $categories);
+            }
+        }
+        return $categories;
+    }
+
+    /**
+     * Notes: 树状结构
+     * User: ZhouBenXu
+     * DateTime: 2024/7/2 下午2:51
+     * @param $list
+     * @param $id
+     * @return array
+     */
+    public static function getTree($list = [], $id = 0)
+    {
+        $tree = array();
+        foreach ($list as $k => $v) {
+            if ($v['category_super_id'] == $id) {
+                if (!empty(self::getTree($list, $v['category_id']))) {
+                    $v['children'] = self::getTree($list, $v['category_id']);
+                }
+                $tree[] = $v;
+            }
+        }
+        return $tree;
+    }
+
+
+    /**
+     * @Desc 分类详情
+     * @Author Gorden
+     * @Date 2024/2/22 11:37
+     *
+     * @param $id
+     * @return \support\Response
+     */
+    public static function getCategoryInfos($ids)
+    {
+        $category = SysCategory::whereIn('category_id', $ids)->select(['category_id','category_name','category_super_id'])->get()->toArray();
+        if (!$category) {
+            return json_fail('分类不存在');
+        }
+        return $category;
+    }
+
 }

+ 1 - 1
app/admin/validate/card/CardBatchValidate.php

@@ -52,7 +52,7 @@ class CardBatchValidate extends Validate
      */
     public function checkCardSort($params)
     {
-        if ($params['card_batch_serial_begin'] < $params['card_batch_serial_end']) {
+        if ($params['card_batch_serial_begin'] > $params['card_batch_serial_end']) {
             return false;
         }
         // 查询是否存在相同前缀后缀信息

+ 1 - 0
route/admin.php

@@ -179,6 +179,7 @@ Route::group('/admin', function () {
             Route::post('/update/{id:\d+}', [\app\admin\controller\sys_manage\CategoryController::class, 'updateCategory']);
             Route::post('/updateStatus/{id:\d+}', [\app\admin\controller\sys_manage\CategoryController::class, 'updateStatus']);
             Route::delete('/delete', [\app\admin\controller\sys_manage\CategoryController::class, 'delCategory']);
+            Route::get('/categoryTree', [\app\admin\controller\sys_manage\CategoryController::class, 'getCategoryTree']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);