瀏覽代碼

储值卡管理修改

ZhouBenXu 4 月之前
父節點
當前提交
39094e0c78

+ 15 - 0
app/admin/controller/card/CardBatchController.php

@@ -33,6 +33,9 @@ class CardBatchController
         if (!$validate->scene('add')->check($params)) {
             return json_fail($validate->getError());
         }
+        if (!$validate->checkCardSort($params)) {
+            return json_fail("卡号重请修改后添加");
+        }
         return CardBatchService::insert($params);
     }
 
@@ -115,4 +118,16 @@ class CardBatchController
         return CardBatchService::getInfo($params['card_batch_id']);
     }
 
+    /**
+     * Notes: 卡状态下拉列表
+     * User: ZhouBenXu
+     * DateTime: 2024/7/1 上午9:27
+     * @return Response
+     */
+    public function getStatusList()
+    {
+        return CardBatchService::getStatusList();
+    }
+
+
 }

+ 10 - 0
app/admin/controller/card/CardController.php

@@ -101,5 +101,15 @@ class CardController
         return CardService::exportCard($request);
     }
 
+    /**
+     * Notes: 卡状态下拉列表
+     * User: ZhouBenXu
+     * DateTime: 2024/7/1 上午9:27
+     * @return Response
+     */
+    public function getStatusList()
+    {
+        return CardService::getStatusList();
+    }
 
 }

+ 51 - 6
app/admin/service/card/CardBatchService.php

@@ -41,7 +41,6 @@ class CardBatchService
             $model->card_batch_serial_begin = $params['card_batch_serial_begin']; // 卡批次序号起始
             $model->card_batch_serial_end = $params['card_batch_serial_end']; // 卡批次序号结束
             $model->card_batch_amount = $params['card_batch_amount']; // 卡批次面额
-            $model->card_batch_added = $params['card_batch_added']; // 卡批次增值赠送
             $model->card_batch_validtimes = $params['card_batch_validtimes']; // 卡批次有效期 0=永久 天
             $model->card_batch_json = $params['card_batch_json'] ?? "{}"; // 卡JSON {}
             $model->card_batch_remark = $params['card_batch_remark'] ?? ""; // 备注
@@ -50,7 +49,36 @@ class CardBatchService
             if ($model->save()) {
                 $join_card_batch_id = $model->card_batch_id;
                 // 添加卡信息
-                CardService::insert($join_card_batch_id, $params);
+//                CardService::insert($join_card_batch_id, $params);
+
+                $cardModel = new Card();
+                // 生成包含序号数组
+                $card_sort = range($params['card_batch_serial_begin'], $params['card_batch_serial_end']);
+                $insertData = [];
+                if ($params['card_batch_validtimes'] != 0) { // 卡批次有效期 0=永久 天
+                    $params['card_batch_validtimes'] = (strtotime(date('Y-m-d 00:00:00')) + $params['card_batch_validtimes'] * 86400) - 1;
+                }
+                foreach ($card_sort as $value) {
+                    $info['join_card_batch_id'] = $join_card_batch_id;
+                    $info['join_card_category_id'] = $params['join_card_batch_category_id'];
+                    $info['card_status'] = "INIT";
+                    $info['card_category'] = $params['card_batch_category'] ?? "NORMAL"; // 批次类型 NORMAL
+                    $info['card_name'] = $params['card_batch_name'];
+                    $info['card_prefix'] = $params['card_batch_prefix'];
+                    $info['card_suffix'] = $params['card_batch_suffix'];
+                    $info['card_pass'] = mt_rand(100000, 999999);// 卡密
+                    $info['card_amount'] = $params['card_batch_amount'];
+                    $info['card_validtimes'] = $params['card_batch_validtimes']; // 卡批次有效期 0=永久 天
+                    $info['card_json'] = "{}";
+                    $info['card_assign_json'] = "{}";
+                    $info['card_process_json'] = "{}";
+                    $info['card_sort'] = $value;
+                    $info['card_remark'] = $params['card_batch_remark'] ?? ""; // 备注
+                    $info['card_extend_json'] = "{}";
+                    $info['card_addtimes'] = time();
+                    $insertData[] = $info;
+                }
+                $cardModel->insert($insertData);
             }
 
             Db::commit();
@@ -255,8 +283,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'] = $cardBatchModel::CARD_BATCH_STATUS[$value['card_batch_status']];
+                $value['card_batch_status_value'] = $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);
                 // 合并储值卡面值以及状态数量
@@ -284,12 +311,30 @@ class CardBatchService
     {
         $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']];
+            $cardBatch['card_batch_status_value'] = 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);
     }
 
+    /**
+     * Notes: 卡状态下拉列表
+     * User: ZhouBenXu
+     * DateTime: 2024/7/1 上午9:27
+     * @return Response
+     */
+    public static function getStatusList()
+    {
+        $data = [];
+        $statusList = CardBatch::CARD_BATCH_STATUS;
+        foreach ($statusList as $key => $value) {
+            $info = [];
+            $info['status'] = $key;
+            $info['status_value'] = $value;
+            $data[] = $info;
+        }
+        return json_success('', $data);
+    }
+
 }

+ 62 - 7
app/admin/service/card/CardService.php

@@ -9,10 +9,12 @@
 
 namespace app\admin\service\card;
 
+use app\model\CardBatch;
 use support\Db;
 use support\exception\BusinessException;
 use app\model\Card;
 use support\Request;
+use support\Response;
 
 class CardService
 {
@@ -46,7 +48,6 @@ class CardService
                 $info['card_suffix'] = $card_info['card_batch_suffix'];
                 $info['card_pass'] = mt_rand(10000000, 99999999);// 卡密
                 $info['card_amount'] = $card_info['card_batch_amount'];
-                $info['card_added'] = $card_info['card_batch_added'];
                 $info['card_validtimes'] = $card_info['card_batch_validtimes']; // 卡批次有效期 0=永久 天
                 $info['card_json'] = "{}";
                 $info['card_assign_json'] = "{}";
@@ -180,12 +181,18 @@ class CardService
             ->count();
         if (!empty($rows)) {
             foreach ($rows as $key => &$value) {
-                $value['card_status_value'] = $value['card_status'];
-                $value['card_status'] = Card::CARD_STATUS[$value['card_status']];
+                $value['card_status_value'] = 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);
+                $value['card_no'] = $value['card_prefix'] . $value['card_sort'] . $value['card_suffix'];
+                if ($value['card_validtimes'] == 0) {
+                    $value['card_validtimes'] = "永久";
+                } else {
+                    $value['card_validtimes'] = date("Y-m-d H:i:s", $value['card_validtimes']);
+                }
+
             }
 
         }
@@ -223,9 +230,34 @@ class CardService
      */
     public static function exportCard(Request $request)
     {
-        $card_ids = $request->get('card_id', '');
+        $params = $request->get();
+
+        $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']) ? $params['card_status'] : "";
+        $card_category = $params['card_category'] ?? "";
+        $card_name = $params['card_name'] ?? "";
+        $card_ids = $params['card_id'] ?? "";
+
         $cardModel = new Card();
-        $list = $cardModel::select('*')->whereIn('card_id', $card_ids)->get()->toArray();
+        $list = $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);
+            })
+            ->whereIn('card_id', $card_ids)
+            ->get()
+            ->toArray();
         $exportData = [];
         // 增加签名
         if (!empty($list)) {
@@ -235,14 +267,18 @@ class CardService
                 $info['card_prefix'] = $value['card_prefix'];
                 $info['card_suffix'] = $value['card_suffix'];
                 $info['card_sort'] = $value['card_sort'];
-                $info['card_validtimes'] = $value['card_validtimes'];
+                if ($value['card_validtimes'] == 0) {
+                    $info['card_validtimes'] = "永久";
+                } else {
+                    $info['card_validtimes'] = date("Y-m-d H:i:s", $value['card_validtimes']);
+                }
                 // 生成签名
                 $card_no = $value['card_prefix'] . $value['card_sort'] . $value['card_suffix'];
                 $card_sign = self::generateSignature($info, $info['card_pass']);
                 $card_extend_json['action'] = "bind-card";
                 $card_extend_json['data'] = ["card_id" => $card_no, "card_sign" => $card_sign];
                 $info['card_no'] = $card_no;
-                $info['card_extend_json'] = $card_extend_json;
+                $info['card_extend_json'] = json_encode($card_extend_json);
                 $exportData[] = $info;
             }
         }
@@ -365,5 +401,24 @@ class CardService
         return json_success('success');
     }
 
+    /**
+     * Notes: 卡状态下拉列表
+     * User: ZhouBenXu
+     * DateTime: 2024/7/1 上午9:27
+     * @return Response
+     */
+    public static function getStatusList()
+    {
+        $data = [];
+        $statusList = Card::CARD_STATUS;
+        foreach ($statusList as $key => $value) {
+            $info = [];
+            $info['status'] = $key;
+            $info['status_value'] = $value;
+            $data[] = $info;
+        }
+        return json_success('', $data);
+    }
+
 
 }

+ 31 - 4
app/admin/validate/card/CardBatchValidate.php

@@ -10,6 +10,7 @@
 namespace app\admin\validate\card;
 
 use support\Validate;
+use app\model\CardBatch;
 
 class CardBatchValidate extends Validate
 {
@@ -24,7 +25,6 @@ class CardBatchValidate extends Validate
         'card_batch_serial_begin' => 'require', // 卡批次序号起始
         'card_batch_serial_end' => 'require', // 卡批次序号结束
         'card_batch_amount' => 'require', // 卡批次面额
-        'card_batch_added' => 'require', // 卡批次增值赠送
         'card_batch_validtimes' => 'require', // 卡批次有效期时间戳 0=永久 天
         'validtimes_status' => 'require', // 修改时有效期状态  0 永久 1增加 2减少
         'page' => 'require', // 页码
@@ -35,12 +35,39 @@ class CardBatchValidate extends Validate
     protected $message = [];
 
     protected $scene = [
-        'add' => ['join_card_batch_user_id', 'join_card_batch_category_id', 'card_batch_status', 'card_batch_name', 'card_batch_prefix', 'card_batch_suffix', 'card_batch_serial_begin', 'card_batch_serial_end', 'card_batch_amount', 'card_batch_added', 'card_batch_validtimes'],
-        'save' => ['join_card_batch_user_id','card_batch_id','validtimes_status','card_batch_name'],
+        'add' => ['join_card_batch_user_id', 'join_card_batch_category_id', 'card_batch_status', 'card_batch_name', 'card_batch_prefix', 'card_batch_suffix', 'card_batch_serial_begin', 'card_batch_serial_end', 'card_batch_amount', 'card_batch_validtimes'],
+        'save' => ['join_card_batch_user_id', 'card_batch_id', 'validtimes_status', 'card_batch_name'],
         'delete' => ['card_batch_ids'],
-        'list' => ['page','pageSize'],
+        'list' => ['page', 'pageSize'],
         'info' => ['card_batch_id']
     ];
 
 
+    /**
+     * Notes: 卡号区间校验不能存在交集
+     * User: ZhouBenXu
+     * DateTime: 2024/7/1 上午11:30
+     * @param $params
+     * @return bool
+     */
+    public function checkCardSort($params)
+    {
+        // 查询是否存在相同前缀后缀信息
+        $cardBatchInfo = CardBatch::where('card_batch_prefix', $params['card_batch_prefix'])
+            ->where('card_batch_suffix', $params['card_batch_prefix'])
+            ->select()
+            ->get()
+            ->toArray();
+        if (!empty($cardBatchInfo)) {
+            foreach ($cardBatchInfo as $key => $value) {
+                // 校验序号是否存在交集信息
+                if ($value['card_batch_serial_begin'] <= $params['card_batch_serial_end'] && $value['card_batch_serial_end'] >= $params['card_batch_serial_begin']) {
+                    return false;
+                }
+            }
+        }
+        return true;
+    }
+
+
 }

+ 2 - 0
route/admin.php

@@ -902,6 +902,7 @@ Route::group('/admin', function () {
             Route::get('/exportCard', [\app\admin\controller\card\CardController::class, 'exportCard']);
             Route::delete('/delete', [\app\admin\controller\card\CardController::class, 'delete']);
             Route::post('/save', [\app\admin\controller\card\CardController::class, 'save']);
+            Route::get('/status', [\app\admin\controller\card\CardController::class, 'getStatusList']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);
@@ -913,6 +914,7 @@ Route::group('/admin', function () {
             Route::delete('/delete', [\app\admin\controller\card\CardBatchController::class, 'delete']);
             Route::get('/list', [\app\admin\controller\card\CardBatchController::class, 'list']);
             Route::get('/info', [\app\admin\controller\card\CardBatchController::class, 'info']);
+            Route::get('/status', [\app\admin\controller\card\CardBatchController::class, 'getStatusList']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);