Przeglądaj źródła

添加个人中心礼品卡接口

llp 1 tydzień temu
rodzic
commit
84a3705323

+ 19 - 0
packages/Longyi/Gift/src/Http/Controllers/Shop/GiftController.php

@@ -24,6 +24,25 @@ class GiftController extends Controller
         echo 111;exit;
         echo 111;exit;
         return view('giftcard::shop.index');
         return view('giftcard::shop.index');
     }
     }
+
+    public function lists(): JsonResponse
+    {
+        $gifts = $this->giftCardRepository->giftcards();
+        return response()->json([
+            'success' => true,
+            'data' => $gifts,
+        ]);
+    }
+
+    public function add($request): JsonResponse
+    {
+        $id = $request->input('id');
+        $success = $this->giftCardRepository->add($id);
+        return response()->json([
+            'success' => $success,
+            'message' => $success ? 'Gift card added successfully' : 'Failed to add gift card',
+        ]);
+    }
     /**
     /**
      * Get customer's gift cards list
      * Get customer's gift cards list
      */
      */

+ 60 - 0
packages/Longyi/Gift/src/Models/GiftCards.php

@@ -132,4 +132,64 @@ class GiftCards extends Model implements GiftCardsContract
 
 
         return $code;
         return $code;
     }
     }
+
+    public function giftcards()
+    {
+        return [
+            1 => [
+                'name' => 'Gift Card 1',
+                'amount' => 50.00,
+                'points' => 0,
+                'num' => 0,
+                'expirationdate' => 30,
+                'channel' => 'activity_26_04_21',
+                'notes' => '拉新活动添加'
+            ],
+            2 => [
+                'name' => 'Gift Card 1',
+                'amount' => 50.00,
+                'points' => 0,
+                'num' => 0,
+                'expirationdate' => 30,
+                'channel' => 'activity_26_04_21',
+                'notes' => '拉新活动添加'
+            ],
+            3 => [
+                'name' => 'Gift Card 1',
+                'amount' => 50.00,
+                'points' => 0,
+                'num' => 0,
+                'expirationdate' => 30,
+                'channel' => 'activity_26_04_21',
+                'notes' => '拉新活动添加'
+            ],
+            4 => [
+                'name' => 'Gift Card 1',
+                'amount' => 50.00,
+                'points' => 0,
+                'num' => 0,
+                'expirationdate' => 30,
+                'channel' => 'activity_26_04_21',
+                'notes' => '拉新活动添加'
+            ],
+        ];
+    }
+
+    public function add($id)
+    {
+        $gifts = $this->giftcards();
+        $giftInfo = $gifts[$id] ?? null;
+        if ($giftInfo) {
+            return false;
+        }
+        try {
+            DB::beginTransaction();
+            self::addGiftCard($id, $giftInfo['amount'], $giftInfo['num'], $giftInfo['expirationdate'], $giftInfo['channel'], $giftInfo['notes']);
+            DB::commit();
+        } catch (\Exception $e) {
+            DB::rollBack();
+            throw $e;
+        }
+        return true;
+    }
 }
 }