Przeglądaj źródła

会员列表查询

theo 2 lat temu
rodzic
commit
ade2590a2f

+ 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);
     }
-}
+}

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

@@ -42,33 +42,24 @@ class IndexList extends \common\libs\dataList\DataList implements DataListInterf
                 UI.HIGHEST_EMP_LV, UI.CLOSE_LOGIN_AT, UI.PULLED_AT, 
                 UI.GROUP_LEADER_AT, UI.ALLOW_TRANSFER, UI.ALLOW_RECONSUME_SMS, UI.ALLOW_RECONSUME_SMS_TO, 
                 UI.HIGHEST_EMP_LV_PERIOD, UI.TRANSFER_PROP, UI.LOGIN_NUMS, UI.FAIL_NUMS, UI.LAST_LOGIN_IP, 
-                UI.LAST_LOGIN_AT, UI.SHOW_EMP_LV
+                UI.LAST_LOGIN_AT, UI.SHOW_EMP_LV,UN.RELATIVE_LOCATION,
+                CU.USER_NAME CON_USER_NAME,CU.REAL_NAME CON_REAL_NAME,
+                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 AND UN.PARENT_UID = UI.CON_UID'],
-//                ['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'],
+                ['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'],
             ],
             'page' => $this->page,
             'pageSize' => $this->pageSize,
         ]);
         foreach ($this->listData['list'] as $key => $value) {
-            $cu = User::find()->select('USER_NAME, REAL_NAME')->where(["ID"=>$value['CON_UID']])->asArray()->one();
-            $this->listData['list'][$key]['CON_USER_NAME'] = $cu?$cu['USER_NAME']:"";
-            $this->listData['list'][$key]['CON_REAL_NAME'] = $cu?$cu['REAL_NAME']:"";
-            $ru = User::find()->select('USER_NAME, REAL_NAME')->where(["ID"=>$value['REC_UID']])->asArray()->one();
-            $this->listData['list'][$key]['REC_USER_NAME'] = $ru?$ru['USER_NAME']:"";
-            $this->listData['list'][$key]['REC_REAL_NAME'] = $ru?$ru['REAL_NAME']:"";
-            $du = User::find()->select('USER_NAME, REAL_NAME')->where(["ID"=>$value['DEC_ID']])->asArray()->one();
-            $this->listData['list'][$key]['DEC_USER_NAME'] = $du?$du['USER_NAME']:"";
-
-            $un = UserNetwork::find()->select('RELATIVE_LOCATION')->where(["USER_ID"=>$value['USER_ID'],"PARENT_UID"=>$value['CON_UID']])->asArray()->one();
-            $this->listData['list'][$key]['RELATIVE_LOCATION'] = $un?$un['RELATIVE_LOCATION']:"";
-
             // 后台访问前台的请求参数
             if (!$this->isExport && Yii::$app->user->validateAdminAction('user', 'login-to-frontend')) {
                 $urlParams = BackendToFrontendApi::paramsFormat(['id' => $value['USER_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,
+        ];
+    }
 }