Browse Source

Merge branch 'feature/2243-userlist-speed' into new-version

theo 2 years ago
parent
commit
ba7e663451

+ 2 - 2
backendApi/modules/v1/controllers/UserController.php

@@ -149,7 +149,7 @@ class UserController extends BaseController
         ]);
         $condition = $filter['condition'];
         $params = $filter['params'];
-        $condition .= ' AND UI.DELETED=0 ';
+        $condition .= ' AND U.DELETED=0 ';
         $listObj = new IndexList();
         $data = $listObj->getList(['condition' => $condition, 'params' => $params]);
         return static::notice($data);
@@ -2229,4 +2229,4 @@ class UserController extends BaseController
         }
         return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
     }
-}
+}

+ 5 - 5
backendApi/modules/v1/models/lists/user/IndexList.php

@@ -32,7 +32,7 @@ class IndexList extends \common\libs\dataList\DataList implements DataListInterf
      */
     public function dataHandle()
     {
-        $this->condition .= ' AND UN.USER_ID=UI.USER_ID AND UN.PARENT_UID=UI.CON_UID';
+//        $this->condition .= ' AND UN.PARENT_UID=UI.CON_UID';
         $this->listData = User::lists($this->condition, $this->params, [
             'select' => 'U.*,
                 UI.USER_ID, UI.ZC_PV, UI.CON_UID, UI.REC_UID, UI.CON_NUM, UI.REC_NUM, UI.NETWORK_DEEP, 
@@ -47,11 +47,11 @@ class IndexList extends \common\libs\dataList\DataList implements DataListInterf
                 RU.USER_NAME REC_USER_NAME,RU.REAL_NAME REC_REAL_NAME,
                 DU.USER_NAME DEC_USER_NAME
                 ',
-            'orderBy' => 'UI.CREATED_AT DESC',
-            'from' => UserInfo::tableName() . ' AS UI',
+            'orderBy' => 'U.CREATED_AT DESC',
+            'from' => User::tableName() . ' AS U',
             'join' => [
-                ['LEFT JOIN', User::tableName() . ' AS U', 'U.ID=UI.USER_ID'],
-                ['LEFT JOIN', UserNetwork::tableName() . ' AS UN', 'UI.USER_ID=UN.USER_ID'],
+                ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'U.ID=UI.USER_ID'],
+                ['LEFT JOIN', UserNetwork::tableName() . ' AS UN', 'U.ID=UN.USER_ID'],
                 ['LEFT JOIN', User::tableName() . ' AS CU', 'UI.CON_UID=CU.ID'],
                 ['LEFT JOIN', User::tableName() . ' AS RU', 'UI.REC_UID=RU.ID'],
                 ['LEFT JOIN', User::tableName() . ' AS DU', 'U.DEC_ID=DU.ID'],

+ 58 - 10
common/models/User.php

@@ -6,6 +6,7 @@ use common\helpers\Cache;
 use common\helpers\Tool;
 use common\helpers\user\Info;
 use Yii;
+use yii\data\Pagination;
 use yii\helpers\Json;
 use common\libs\logging\operate\valueType\Config as ValueTypeConfig;
 
@@ -403,7 +404,7 @@ class User extends \common\components\ActiveRecord
         }
     }
 
-    
+
     /**
      *  判断用户是否是观察期
      *  观望期:自加入算起2个月
@@ -428,10 +429,10 @@ class User extends \common\components\ActiveRecord
     public static function sumDevPvByUserId($userId) {
         $decOrderPv = DecOrder::find()
         ->select('SUM(DEC_PV) AS PV_SUM')
-        ->where('TO_USER_ID=:TO_USER_ID AND IS_DEL=0', 
+        ->where('TO_USER_ID=:TO_USER_ID AND IS_DEL=0',
             [
-                'TO_USER_ID'=>$userId, 
-                
+                'TO_USER_ID'=>$userId,
+
             ]
         )
         ->asArray()
@@ -439,10 +440,10 @@ class User extends \common\components\ActiveRecord
         $decOrderPv = isset($decOrderPv['PV_SUM']) ? $decOrderPv['PV_SUM'] : 0;
         $orderDecPv = OrderDec::find()
         ->select('SUM(PAY_PV) AS PV_SUM')
-        ->where('USER_ID=:USER_ID AND IS_DELETE=0', 
+        ->where('USER_ID=:USER_ID AND IS_DELETE=0',
             [
-                'USER_ID'=>$userId, 
-                
+                'USER_ID'=>$userId,
+
             ]
         )
         ->asArray()
@@ -451,10 +452,10 @@ class User extends \common\components\ActiveRecord
         // 还得加上用户在老系统中的所有报单PV之和
         $originPv = OriginDecPv::find()
         ->select('SUM(DEC_PV) AS PV_SUM')
-        ->where('USER_ID=:USER_ID', 
+        ->where('USER_ID=:USER_ID',
             [
-                'USER_ID'=>$userId, 
-                
+                'USER_ID'=>$userId,
+
             ]
         )
         ->asArray()
@@ -572,4 +573,51 @@ class User extends \common\components\ActiveRecord
             'SEX' => '性别',
         ];
     }
+
+    /**
+     * 获取列表
+     * @param string $condition
+     * @param array $params
+     * @param array $argv
+     * @return array
+     */
+    public static function lists($condition = '', $params = [], $argv = []) {
+        self::prepare($condition, $params, $argv, true);
+        unset($condition, $params, $argv);
+
+        $countQuery = clone self::$query;
+        $simpleQuery = clone self::$query;
+
+        if(!$simpleQuery->params){
+            $simpleQuery->join = [];
+            $count = $simpleQuery->count(self::$argv['count']);
+        } else {
+            $count = $countQuery->count(self::$argv['count']); // 得到总数
+        }
+//        $count = $countQuery->count(self::$argv['count']); // 得到总数
+        $pagination = new Pagination(['totalCount' => $count]);
+        $pagination->setPageSize(self::$argv['pageSize']);
+        if(self::$argv['page'] !== null){
+            $pagination->setPage(self::$argv['page']);
+        }
+        self::$query->offset($pagination->offset)->limit($pagination->limit);
+        if(self::$argv['asArray']){
+            self::$query->asArray();
+        }
+        $lists = self::$query->all();
+
+        self::$query = null;
+        unset($countQuery);
+        $startNum = $pagination->page * $pagination->pageSize + 1;
+        return [
+            'list' => $lists ? $lists : [],
+            'pagination' => $pagination,
+            // 'sql'=self::$rawSql,
+            'currentPage'=>$pagination->page,
+            'totalPages'=>$pagination->pageCount,
+            'startNum' => $startNum,
+            'totalCount' => $pagination->totalCount,
+            'pageSize' => $pagination->pageSize,
+        ];
+    }
 }