Kaynağa Gözat

储值卡修改

ZhouBenXu 4 ay önce
ebeveyn
işleme
c88ab63364

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

@@ -58,10 +58,17 @@ class CardController
      * User: ZhouBenXu
      * DateTime: 2024/6/28 上午10:43
      */
-    public function save()
+    public function save(Request $request)
     {
-
-
+        $params = $request->post();
+        $params['join_card_batch_user_id'] = JwtToken::getCurrentId();
+        // 验证器
+        $validate = new CardValidate();
+        if (!$validate->scene('save')->check($params)) {
+            return json_fail($validate->getError());
+        }
+        // 校验有效期 0 永久 1增加 2 减少
+        return CardService::save($params);
     }
 
 

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

@@ -317,4 +317,47 @@ class CardService
     }
 
 
+    /**
+     * Notes: 储值卡修改
+     * User: ZhouBenXu
+     * DateTime: 2024/6/28 下午3:17
+     * @param $params
+     * @return \support\Response
+     */
+    public static function save($params)
+    {
+        Db::beginTransaction();
+        try {
+            $cardBatchModel = new Card();
+            $model = $cardBatchModel::find($params['card_id']);
+            $model->card_name = $params['card_name'];
+            $model->join_card_member_id = $params['join_card_member_id'];
+            $params['card_status'] && $params['card_status'] = $model->card_status = Card::CARD_STATUS[$params['card_status']]; // 储值卡状态
+            if ($params['validtimes_status'] == 0) { // 卡批次有效期 0 永久天  1 增加 2减少
+                $model->card_validtimes = 0;
+            } elseif ($params['validtimes_status'] == 1) {
+                $model->card_validtimes = Db::raw('card_validtimes+' . $params['card_batch_validtimes'] * 86400);
+            } elseif ($params['validtimes_status'] == 2) {
+                $model->card_validtimes = Db::raw('card_validtimes-' . $params['card_batch_validtimes'] * 86400);
+            }
+            $model->save();
+            Db::commit();
+        } catch (\PDOException $e) {
+            Db::rollBack();
+            dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
+            return json_fail('数据写入失败~');
+        } catch (BusinessException $e) {
+            Db::rollBack();
+            dump($e->getFile() . '(' . $e->getLine() . '):' . $e->getMessage());
+            return json_fail($e->getMessage());
+        } catch (\Exception $e) {
+            Db::rollBack();
+            dump($e->getTrace());
+            return json_fail('数据写入失败~');
+        }
+//        _syslog("修改储值卡", "储值卡id【" . $params['card_id'] . "】");
+        return json_success('success');
+    }
+
+
 }

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

@@ -26,7 +26,7 @@ class CardValidate extends Validate
         'save' => ['join_card_batch_user_id','card_batch_id','validtimes_status','card_batch_name'],
         'delete' => ['card_ids'],
         'list' => ['page','pageSize'],
-        'info' => ['card_id']
+        'info' => ['card_id'],
     ];
 
 

+ 1 - 0
route/admin.php

@@ -901,6 +901,7 @@ Route::group('/admin', function () {
             Route::get('/info', [\app\admin\controller\card\CardController::class, 'info']);
             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']);
         })->middleware([
             \app\middleware\AdminAuthCheck::class
         ]);