Browse Source

卡详情 储值卡详情

PV-12\Admin 4 months ago
parent
commit
9f9ed3bfe4

+ 30 - 8
app/admin/controller/card/CardController.php

@@ -9,30 +9,52 @@
 
 namespace app\admin\controller\card;
 
+use app\admin\service\card\CardService;
+use app\admin\validate\card\CardValidate;
+use support\Request;
+use Tinywan\Jwt\JwtToken;
+
 class CardController
 {
 
     /**
-     * Notes: 卡列表
+     * Notes: 储值卡列表
      * User: ZhouBenXu
      * DateTime: 2024/6/28 上午10:42
      */
-    public function list(){
-
+    public function list(Request $request)
+    {
+        $params = $request->get();
+        $params['page'] = $params['page'] ?? 1;
+        $params['pageSize'] = $params['pageSize'] ?? 20;
+        $params['join_card_batch_user_id'] = JwtToken::getCurrentId();
+        // 验证器
+        $validate = new CardValidate();
+        if (!$validate->scene('list')->check($params)) {
+            return json_fail($validate->getError());
+        }
+        return CardService::getList($params);
     }
 
     /**
-     * Notes: 卡详情
+     * Notes: 储值卡详情
      * User: ZhouBenXu
      * DateTime: 2024/6/28 上午10:43
      */
-    public function info(){
-
+    public function info(Request $request)
+    {
+        $params = $request->get();
+        // 验证器
+        $validate = new CardValidate();
+        if (!$validate->scene('info')->check($params)) {
+            return json_fail($validate->getError());
+        }
+        return CardService::getInfo($params['card_id']);
     }
 
 
     /**
-     * Notes: 修改卡信息
+     * Notes: 修改储值卡信息
      * User: ZhouBenXu
      * DateTime: 2024/6/28 上午10:43
      */
@@ -44,7 +66,7 @@ class CardController
 
 
     /**
-     * Notes: 删除卡信息
+     * Notes: 删除储值卡信息
      * User: ZhouBenXu
      * DateTime: 2024/6/28 上午10:43
      */

+ 4 - 3
app/admin/service/card/CardBatchService.php

@@ -151,7 +151,6 @@ class CardBatchService
     }
 
 
-
     /**
      * Notes: 卡批次列表
      * User: ZhouBenXu
@@ -236,6 +235,7 @@ class CardBatchService
             $card_status_total = Db::select($sql);
             $card_status_total = array_column($card_status_total, null, 'join_card_batch_id');
             foreach ($rows as $key => &$value) {
+                $value['card_batch_status_value'] = $value['card_batch_status'];
                 $value['card_batch_status'] = array_flip($cardBatchModel::CARD_BATCH_STATUS)[$value['card_batch_status']];
                 !empty($value['card_batch_json']) && $value['card_batch_json'] = json_decode($value['card_batch_json'], true);
                 !empty($value['card_batch_extend_json']) && $value['card_batch_extend_json'] = json_decode($value['card_batch_extend_json'], true);
@@ -262,13 +262,14 @@ class CardBatchService
      */
     public static function getInfo($card_batch_id)
     {
-        $cardBatch = CardBatch::where('card_batch_id', $card_batch_id)->first()->toArray();
+        $cardBatch = CardBatch::where('card_batch_id', $card_batch_id)->first() ?? [];
         if (!empty($cardBatch)) {
+            $cardBatch['card_batch_status_value'] = $cardBatch['card_batch_status'];
             $cardBatch['card_batch_status'] = array_flip(CardBatch::CARD_BATCH_STATUS)[$cardBatch['card_batch_status']];
             !empty($cardBatch['card_batch_json']) && $cardBatch['card_batch_json'] = json_decode($cardBatch['card_batch_json'], true);
             !empty($cardBatch['card_batch_extend_json']) && $cardBatch['card_batch_extend_json'] = json_decode($cardBatch['card_batch_extend_json'], true);
         }
-        return json_success('',$cardBatch);
+        return json_success('', $cardBatch);
     }
 
 }

+ 91 - 0
app/admin/service/card/CardService.php

@@ -121,4 +121,95 @@ class CardService
         return json_success('success');
     }
 
+
+    /**
+     * Notes: 储值卡列表
+     * User: ZhouBenXu
+     * DateTime: 2024/6/28 上午11:36
+     * @param $params
+     * @return \support\Response
+     */
+    public static function getList($params)
+    {
+
+        $cardModel = new Card();
+        $page = $params['page'];
+        $page_size = $params['pageSize'];
+        $join_card_batch_id = $params['join_card_batch_id'] ?? "";
+        $join_card_category_id = $params['join_card_category_id'] ?? "";
+        $join_card_member_id = $params['join_card_member_id'] ?? "";
+        $card_status = !empty($params['card_status']) ? Card::CARD_STATUS[$params['card_status']] : "";
+        $card_category = $params['card_category'] ?? "";
+        $card_name = $params['card_name'] ?? "";
+
+        $rows = $cardModel::select('*')
+            ->when(!empty($card_name) && $card_name != '', function ($query) use ($card_name) {
+                $query->where('card_name', 'like', '%' . $card_name . '%');
+            })->when(!empty($card_status), function ($query) use ($card_status) {
+                $query->where('card_status', $card_status);
+            })->when(!empty($join_card_batch_id), function ($query) use ($join_card_batch_id) {
+                $query->where('join_card_batch_id', $join_card_batch_id);
+            })->when(!empty($join_card_category_id), function ($query) use ($join_card_category_id) {
+                $query->where('join_card_category_id', $join_card_category_id);
+            })->when(!empty($join_card_member_id), function ($query) use ($join_card_member_id) {
+                $query->where('join_card_member_id', $join_card_member_id);
+            })->when(!empty($card_category), function ($query) use ($card_category) {
+                $query->where('card_category', $card_category);
+            })
+            ->orderBy('card_id', 'DESC')
+            ->forPage($page, $page_size)
+            ->get()
+            ->toArray();
+
+        $total = $cardModel::select('card_id')
+            ->when(!empty($card_name) && $card_name != '', function ($query) use ($card_name) {
+                $query->where('card_name', 'like', '%' . $card_name . '%');
+            })->when(!empty($card_status), function ($query) use ($card_status) {
+                $query->where('card_status', $card_status);
+            })->when(!empty($join_card_batch_id), function ($query) use ($join_card_batch_id) {
+                $query->where('join_card_batch_id', $join_card_batch_id);
+            })->when(!empty($join_card_category_id), function ($query) use ($join_card_category_id) {
+                $query->where('join_card_category_id', $join_card_category_id);
+            })->when(!empty($join_card_member_id), function ($query) use ($join_card_member_id) {
+                $query->where('join_card_member_id', $join_card_member_id);
+            })->when(!empty($card_category), function ($query) use ($card_category) {
+                $query->where('card_category', $card_category);
+            })
+            ->count();
+        if (!empty($rows)) {
+            foreach ($rows as $key => &$value) {
+                $value['card_status_value'] = $value['card_status'];
+                $value['card_status'] = array_flip(Card::CARD_STATUS)[$value['card_status']];
+                !empty($value['card_json']) && $value['card_json'] = json_decode($value['card_json'], true);
+                !empty($value['card_assign_json']) && $value['card_assign_json'] = json_decode($value['card_assign_json'], true);
+                !empty($value['card_process_json']) && $value['card_process_json'] = json_decode($value['card_process_json'], true);
+                !empty($value['card_extend_json']) && $value['card_extend_json'] = json_decode($value['card_extend_json'], true);
+            }
+
+        }
+        return json_success('', compact('rows', 'page', 'page_size', 'total'));
+    }
+
+
+    /**
+     * Notes: 储值卡详情
+     * User: ZhouBenXu
+     * DateTime: 2024/6/28 上午11:41
+     * @param $card_id
+     * @return \support\Response
+     */
+    public static function getInfo($card_id)
+    {
+        $cardInfo = Card::where('card_id', $card_id)->first() ?? [];
+        if (!empty($cardInfo)) {
+            $cardInfo['card_status_value'] = $cardInfo['card_status'];
+            $cardInfo['card_status'] = array_flip(Card::CARD_STATUS)[$cardInfo['card_status']];
+            !empty($cardInfo['card_json']) && $cardInfo['card_json'] = json_decode($cardInfo['card_json'], true);
+            !empty($cardInfo['card_assign_json']) && $cardInfo['card_assign_json'] = json_decode($cardInfo['card_assign_json'], true);
+            !empty($cardInfo['card_process_json']) && $cardInfo['card_process_json'] = json_decode($cardInfo['card_process_json'], true);
+            !empty($cardInfo['card_extend_json']) && $cardInfo['card_extend_json'] = json_decode($cardInfo['card_extend_json'], true);
+        }
+        return json_success('', $cardInfo);
+    }
+
 }

+ 32 - 0
app/admin/validate/card/CardValidate.php

@@ -0,0 +1,32 @@
+<?php
+/**
+ * CardBatchValidate.php
+ * User: ZhouBenXu
+ * Date: 2024/6/27
+ * Time: 上午9:54
+ * Notes:
+ */
+
+namespace app\admin\validate\card;
+
+use support\Validate;
+
+class CardValidate extends Validate
+{
+    protected $rule = [
+        'card_id' => 'require', // 储值卡id
+        'page' => 'require', // 页码
+        'pageSize' => 'require', // 分页条数
+    ];
+
+    protected $message = [];
+
+    protected $scene = [
+        'save' => ['join_card_batch_user_id','card_batch_id','validtimes_status','card_batch_name'],
+        'delete' => ['card_ids'],
+        'list' => ['page','pageSize'],
+        'info' => ['card_id']
+    ];
+
+
+}

+ 1 - 0
route/admin.php

@@ -898,6 +898,7 @@ Route::group('/admin', function () {
         /* 卡管理 */
         Route::group('/card', function () {
             Route::get('/list', [\app\admin\controller\card\CardController::class, 'list']);
+            Route::get('/info', [\app\admin\controller\card\CardController::class, 'info']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);