Browse Source

储值卡绑定

ZhouBenXu 4 months ago
parent
commit
a8c5021a57

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

@@ -113,4 +113,23 @@ class CardController
         return CardService::getStatusList();
     }
 
+
+    /**
+     * Notes: 储值卡绑定
+     * User: ZhouBenXu
+     * DateTime: 2024/7/2 下午6:08
+     * @param Request $request
+     * @return \support\Response
+     */
+    public function binding(Request $request)
+    {
+        $params = $request->post();
+        var_dump($params);
+        $validate = new CardValidate();
+        if (!$validate->scene('binding')->check($params)) {
+            return json_fail($validate->getError());
+        }
+        return CardService::binding($params);
+    }
+
 }

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

@@ -185,6 +185,9 @@ class CardService
             $category = array_column($rows, 'join_card_category_id');
             $categoryInfos = CategoryService::getCategoryInfos($category) ?? [];
             $categoryInfos && $categoryInfos = array_column($categoryInfos, null, 'category_id');
+            // 查询会员信息
+
+
             foreach ($rows as $key => &$value) {
                 $value['category_name'] = $categoryInfos[$value['join_card_category_id']]['category_name'] ?? "";
                 $value['card_status_value'] = Card::CARD_STATUS[$value['card_status']];
@@ -433,4 +436,39 @@ class CardService
     }
 
 
+    /**
+     * Notes: 储值卡绑定
+     * User: ZhouBenXu
+     * DateTime: 2024/7/2 下午6:08
+     * @param $params
+     * @return Response
+     */
+    public static function binding($params)
+    {
+        Db::beginTransaction();
+        try {
+            $card_ids = $params['card_id'];
+            if (!is_array($card_ids)) {
+                $card_ids = [$card_ids];
+            }
+            Card::whereIn('card_id', $card_ids)->update(['join_card_member_id'=>$params['join_card_member_id']]);
+            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【" . implode(',', $card_ids) . '】');
+        return json_success('success');
+    }
+
+
 }

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

@@ -18,6 +18,7 @@ class CardValidate extends Validate
         'page' => 'require', // 页码
         'pageSize' => 'require', // 分页条数
         'card_ids' => 'require', // 储值卡id
+        'join_card_member_id' => 'require', // 会员id
     ];
 
     protected $message = [];
@@ -27,6 +28,7 @@ class CardValidate extends Validate
         'delete' => ['card_ids'],
         'list' => ['page','pageSize'],
         'info' => ['card_id'],
+        'binding' => ['card_id','join_card_member_id'],
     ];
 
 

+ 1 - 0
route/admin.php

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