ryan 2 недель назад
Родитель
Сommit
93dc0c1ce2

+ 36 - 1
common/services/GuestDeclarationOrderService.php

@@ -97,6 +97,41 @@ class GuestDeclarationOrderService
         ];
     }
 
+    public function debugCompletePaidDraft(string $draftId, string $accessToken): array
+    {
+        if (!defined('YII_ENV') || YII_ENV === 'prod') {
+            throw new NotFoundHttpException();
+        }
+
+        $draft = $this->loadAuthorizedDraft($draftId, $accessToken);
+        if ($draft->STATUS !== GuestDeclarationDraftStatus::PENDING_PAYMENT || $draft->isExpired()) {
+            throw new BadRequestHttpException('Only an active pending-payment draft can be debug-completed.');
+        }
+        if (!$draft->PAYMENT_REFERENCE || (float) $draft->PAY_AMOUNT <= 0 || !$draft->CURRENCY) {
+            throw new BadRequestHttpException('The guest draft has no valid initialized payment.');
+        }
+
+        $now = gmdate('Y-m-d\\TH:i:s\\Z');
+        $transaction = [
+            'id' => 'DEBUG-' . $draft->ID,
+            'domain' => 'debug',
+            'status' => 'success',
+            'reference' => $draft->PAYMENT_REFERENCE,
+            'amount' => (int) round((float) $draft->PAY_AMOUNT * 100),
+            'currency' => strtoupper((string) $draft->CURRENCY),
+            'metadata' => ['custom_fields' => [
+                ['display_name' => 'Order SN', 'variable_name' => 'orderSn', 'value' => $draft->ORDER_SN],
+                ['display_name' => 'Order Type', 'variable_name' => 'orderType', 'value' => 'guestUserDec'],
+            ]],
+            'created_at' => $now,
+            'paid_at' => $now,
+            'channel' => 'debug',
+            'email' => (string) ($draft->getPayload()['email'] ?? ''),
+        ];
+
+        return $this->completePaidDraft($draft->ORDER_SN, $transaction);
+    }
+
     public function submitDraft(string $draftId, string $accessToken, array $input): array
     {
         $draft = $this->loadAuthorizedDraft($draftId, $accessToken);
@@ -189,7 +224,7 @@ class GuestDeclarationOrderService
         $levels = Cache::getDecLevelConfig();
         $minimumPv = $levels ? min(array_map(static function ($level) { return (float) $level['PERF']; }, $levels)) : 0;
         if ($pv < $minimumPv) {
-            throw new BadRequestHttpException(Yii::t('app', 'totalBVCanNotLessThanSelectedBV').‘1’);
+            throw new BadRequestHttpException(Yii::t('app', 'totalBVCanNotLessThanSelectedBV').'1');
         }
         if ((string) ($input['decWay'] ?? '') !== '1') {
             $selectedLevel = $levels[$input['decLv'] ?? ''] ?? null;

+ 1 - 0
frontendApi/config/params.php

@@ -18,6 +18,7 @@ return [
         'v1/site/config',
         'v1/shop/verify-approach-order',
         'v1/user/guest-dec',
+        'v1/user/guest-dec-debug-paid',
         'v1/user/guest-dec-status',
         'v1/user/guest-full-info',
         'v1/user/guest-inspect-network',

+ 1 - 0
frontendApi/config/urlManagerRules.php

@@ -116,6 +116,7 @@ return [
             'GET,POST bind-edit/<id>' => 'bind-edit',
             'GET,POST dec' => 'dec',
             'GET,POST guest-dec' => 'guest-dec',
+            'POST guest-dec-debug-paid' => 'guest-dec-debug-paid',
             'GET guest-dec-status' => 'guest-dec-status',
             'GET,POST upgrade' => 'upgrade',
             'POST upgrade-info' => 'upgrade-info',

+ 53 - 3
frontendApi/modules/v1/controllers/UserController.php

@@ -540,12 +540,32 @@ class UserController extends BaseController {
             foreach ($packages as $index => $package) {
                 $packages[$index]['LEVEL_NAME'] = $decLevels[$package['LEVEL_ID']]['LEVEL_NAME'] ?? '';
             }
+
+//            $query_condition = " AND (1<>1";
+//            if(!$isDecReg || ($isDecReg && $isDec==1)){
+//                $query_condition = " AND (FIND_IN_SET(1, S.GIFT_TYPE)>0";
+//            }
+//            if($isStudio==1){
+//                $query_condition .= " OR FIND_IN_SET(3, S.GIFT_TYPE)>0";
+//            }
+//            $query_condition .= ") AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID";
+
+            // 只查询普通商品
+//            $allGoods = ShopGoods::find()
+//                ->alias('S')
+//                ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
+//                ->join('INNER JOIN', ShopGoodsNature::tableName() . ' AS N', 'N.GOODS_ID=S.ID')
+//                ->join('INNER JOIN', Currency::tableName() . ' AS C', 'C.ID=N.LOCAL_CURRENCY_ID')
+//                ->where("STATUS=1 AND CATEGORY_TYPE=1 " . $query_condition, [':COUNTRY_ID' => $countryId])
+//                ->orderBy('SORT ASC')
+//                ->asArray()
+//                ->all();
             $goods = ShopGoods::find()
                 ->alias('S')
                 ->select('S.*,N.MARKET_PRICE,N.SELL_PRICE,N.TAX_RATE,N.LOCAL_CURRENCY_ID,N.COUNTRY_ID,C.CODE')
                 ->innerJoin(ShopGoodsNature::tableName() . ' N', 'N.GOODS_ID=S.ID')
                 ->innerJoin(Currency::tableName() . ' C', 'C.ID=N.LOCAL_CURRENCY_ID')
-                ->where('S.STATUS=1 AND S.CATEGORY_TYPE=1 AND FIND_IN_SET(1,S.GIFT_TYPE)>0 AND N.COUNTRY_ID=:COUNTRY_ID', [':COUNTRY_ID' => $countryId])
+                ->where('S.STATUS=1 AND S.CATEGORY_TYPE=1 AND FIND_IN_SET(1,S.GIFT_TYPE)>0 AND (S.INSTALMENT=0 OR S.INSTALMENT=1) AND N.COUNTRY_ID=:COUNTRY_ID', [':COUNTRY_ID' => $countryId])
                 ->orderBy('S.SORT ASC')
                 ->asArray()->all();
 
@@ -572,11 +592,41 @@ class UserController extends BaseController {
                 'decLevel' => DeclarationLevel::getData(),
             ]);
         } catch (\Throwable $e) {
-            LoggerTool::error('guestDec failed: ' . get_class($e));
+            LoggerTool::error([
+                'event' => 'guestDec_failed',
+                'exception' => get_class($e),
+                'message' => $e->getMessage(),
+                'file' => basename($e->getFile()),
+                'line' => $e->getLine(),
+            ]);
+            if ($e instanceof \yii\web\HttpException) {
+                return static::notice($e->getMessage(), $e->statusCode);
+            }
+            return static::notice('Unable to process guest order.', 500);
+        }
+    }
+
+    public function actionGuestDecDebugPaid()
+    {
+        try {
+            $input = Yii::$app->request->post();
+            $result = (new GuestDeclarationOrderService())->debugCompletePaidDraft(
+                (string) ($input['draftId'] ?? ''),
+                (string) ($input['accessToken'] ?? '')
+            );
+            return static::notice($result);
+        } catch (\Throwable $e) {
+            LoggerTool::error([
+                'event' => 'guestDec_debug_paid_failed',
+                'exception' => get_class($e),
+                'message' => $e->getMessage(),
+                'file' => basename($e->getFile()),
+                'line' => $e->getLine(),
+            ]);
             if ($e instanceof \yii\web\HttpException) {
                 return static::notice($e->getMessage(), $e->statusCode);
             }
-            return static::notice('Unable to process guest order.message:'.$e->getMessage().'trace:'.$e->getTrace(), 500);
+            return static::notice('Unable to debug-complete guest order.', 500);
         }
     }