فهرست منبع

1feature/EK-5822

ryan 2 هفته پیش
والد
کامیت
8c8a071b26
1فایلهای تغییر یافته به همراه12 افزوده شده و 11 حذف شده
  1. 12 11
      frontendApi/modules/v1/controllers/UserController.php

+ 12 - 11
frontendApi/modules/v1/controllers/UserController.php

@@ -49,6 +49,7 @@ use common\models\User;
 use common\models\UserBind;
 use common\models\UserBonus;
 use common\models\UserInfo;
+use common\models\UserRelation;
 use common\models\BaUserInfo;
 use common\models\UserNetwork;
 use common\models\forms\DeclarationUpgradeForm;
@@ -154,20 +155,20 @@ class UserController extends BaseController {
      */
     public function actionNetworkStats() {
         $userId = Yii::$app->user->id;
-        $networkInfo = UserNetwork::find()
-            ->select(['LOCATION_TAG', 'TOP_DEEP'])
+        $relationInfo = UserRelation::find()
+            ->select(['TOP_DEEP'])
             ->where(['USER_ID' => $userId])
             ->asArray()
             ->one();
 
         $descendants = [];
-        if ($networkInfo) {
-            $descendants = UserNetwork::find()
-                ->alias('N')
-                ->select(['N.USER_ID', 'N.PARENT_UID', 'N.TOP_DEEP'])
-                ->innerJoin(User::tableName() . ' U', 'U.ID = N.USER_ID')
-                ->where('N.LOCATION_TAG LIKE :LOCATION_TAG', [':LOCATION_TAG' => $networkInfo['LOCATION_TAG'] . '%'])
-                ->andWhere(['>', 'N.TOP_DEEP', $networkInfo['TOP_DEEP']])
+        if ($relationInfo) {
+            $descendants = UserRelation::find()
+                ->alias('R')
+                ->select(['R.USER_ID', 'R.PARENT_UID', 'R.TOP_DEEP'])
+                ->innerJoin(User::tableName() . ' U', 'U.ID = R.USER_ID')
+                ->where('FIND_IN_SET(:USER_ID, R.PARENT_UIDS)', [':USER_ID' => $userId])
+                ->andWhere(['>', 'R.TOP_DEEP', $relationInfo['TOP_DEEP']])
                 ->andWhere(['U.DELETED' => 0])
                 ->asArray()
                 ->all();
@@ -181,13 +182,13 @@ class UserController extends BaseController {
             $pcv += (float) OriginDecPv::find()->where(['USER_ID' => $userIds])->sum('DEC_PV');
         }
 
-        $maxDeep = $descendants ? max(array_column($descendants, 'TOP_DEEP')) : $networkInfo['TOP_DEEP'] ?? 0;
+        $maxDeep = $descendants ? max(array_column($descendants, 'TOP_DEEP')) : $relationInfo['TOP_DEEP'] ?? 0;
         return static::notice([
             'DOWNLINE_COUNT' => count($descendants),
             'DIRECT_DOWNLINE_COUNT' => count(array_filter($descendants, function ($downline) use ($userId) {
                 return $downline['PARENT_UID'] === $userId;
             })),
-            'MAX_DOWNLINE_DEEP' => max(0, (int) $maxDeep - (int) ($networkInfo['TOP_DEEP'] ?? 0)),
+            'MAX_DOWNLINE_DEEP' => max(0, (int) $maxDeep - (int) ($relationInfo['TOP_DEEP'] ?? 0)),
             'DOWNLINE_PCV' => $pcv,
         ]);
     }