Эх сурвалжийг харах

Merge branch 'master' of http://39.98.194.76:3000/txct/wanyue_app

gorden 4 сар өмнө
parent
commit
dd1d2d2518

+ 17 - 2
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);
     }
 
@@ -45,13 +48,13 @@ class CardBatchController
     {
         $params = $request->post();
         $params['join_card_batch_user_id'] = JwtToken::getCurrentId();
+        $params['validtimes_status'] = $params['validtimes_status'] ?? 3;
         // 验证器
         $validate = new CardBatchValidate();
         if (!$validate->scene('save')->check($params)) {
             return json_fail($validate->getError());
         }
-
-        // 校验有效期 0 永久 1增加 2 减少
+        // 校验有效期 0 永久 1增加 2 减少 3不变
         return CardBatchService::save($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();
+    }
 
 }

+ 59 - 7
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();
@@ -86,6 +114,7 @@ class CardBatchService
             $cardBatchModel = new CardBatch();
             $model = $cardBatchModel::find($params['card_batch_id']);
             $model->card_batch_name = $params['card_batch_name'];
+            $model->card_batch_remark = $params['card_batch_remark'] ?? "";
             $params['card_batch_status'] = $model->card_batch_status = $params['card_batch_status']; // 批次状态
             if ($params['validtimes_status'] == 0) {
                 $model->card_batch_validtimes = 0; // 卡批次有效期 0=永久 天
@@ -99,7 +128,7 @@ class CardBatchService
                 $model->card_batch_validtimes = bcsub($model->card_batch_validtimes, $params['card_batch_validtimes']); // 卡批次有效期 0=永久 天
             }
             if ($model->save()) {
-                 // 修改卡批次下面的卡信息
+                // 修改卡批次下面的卡信息
                 // CardService::saveCardByCardBatchId($params['card_batch_id'], $params);
                 // 修改卡批次下面的卡信息
                 $model = new Card();
@@ -255,8 +284,13 @@ 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']];
+                if ($value['card_batch_validtimes'] == 0) {
+                    $value['card_batch_validtimes_value'] = "永久";
+                } else {
+                    $value['card_batch_validtimes_value'] = $value['card_batch_validtimes'];
+                }
+
                 !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 +318,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);
+    }
+
 
 }

+ 34 - 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,42 @@ 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)
+    {
+        if ($params['card_batch_serial_begin'] < $params['card_batch_serial_end']) {
+            return false;
+        }
+        // 查询是否存在相同前缀后缀信息
+        $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

@@ -906,6 +906,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
         ]);
@@ -917,6 +918,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
         ]);