Browse Source

客户列表好了

shish 6 years ago
parent
commit
3641064a20

+ 4 - 4
app/admin/controllers/UserController.php

@@ -40,16 +40,16 @@ use common\services\xhTMessageService;
 
 class UserController extends BaseController
 {
-
+	
 	public function actionGetList()
 	{
 		$get = Yii::$app->request->get();
-		
+
 		//组建where
 		$type = isset($get['type']) ? $get['type'] : 0;
 		$search = isset($get['search']) ? $get['search'] : '';
 		$where = ['merchantId' => $this->merchantId];
-		switch($type){
+		switch ($type) {
 			case 1:
 				//粉丝
 				$where['subscribe'] = 1;
@@ -64,7 +64,7 @@ class UserController extends BaseController
 			if (stringUtil::isMobieNumber($search)) {
 				$where['mobile'] = $search;
 			} else {
-				$where['userName'] = ['like' => $search];
+				$where['userName'] = ['like', $search];
 			}
 		}
 		$list = UserService::getUserList($where);

+ 5 - 4
biz/user/services/UserAssetService.php

@@ -15,12 +15,13 @@ class UserAssetService extends BaseService
 		$class = static::$baseFile;
 		return $class::getByUserId($userId);
 	}
-	
-	public static function getByUserIds($ids)
+
+	//批量获取用户资产 shish 2019.11.30
+	public static function getByUserIds($ids, $indexBy = null)
 	{
-		self::getAllByCondition([''])
+		return self::getAllByCondition(['userId' => ['in', $ids]], null, '*', $indexBy);
 	}
-	
+
 	public static function updateByUserId($userId, $data)
 	{
 		self::updateByCondition(['userId' => $userId], $data);

+ 8 - 3
biz/user/services/UserService.php

@@ -26,11 +26,12 @@ class UserService extends BaseService
 		}
 		$imgUrl = Yii::$app->params['imgUrl'];
 		if (isset($list) && !empty($list)) {
-
+			
 			//取客户资产
 			$ids = array_column($list, 'id');
-			UserAssetService::getByIds()
-
+			$ids = array_unique($ids);
+			$asset = UserAssetService::getByUserIds($ids, 'userId');
+			
 			foreach ($list as $key => $val) {
 				//访问时间
 				$visitTime = date("m-d H:i", $val['visitTime']);
@@ -39,6 +40,10 @@ class UserService extends BaseService
 				}
 				$list[$key]['visitTime'] = $visitTime;
 				$list[$key]['avatar'] = $imgUrl . $val['avatar'];
+				$userId = $val['id'];
+				$list[$key]['userAsset'] = isset($asset[$userId]) ? $asset[$userId] : [];
+				//客户发来新消息数
+				$list[$key]['messageNum'] = rand(0, 19);
 			}
 		}
 		$data['list'] = $list;