Просмотр исходного кода

共富体系-用户查询方法

sunxbiao месяцев назад: 6
Родитель
Сommit
d3b7aaf07c

+ 26 - 0
app/common/dao/shared/SharedProsperityUserDao.php

@@ -4,6 +4,7 @@ namespace app\common\dao\shared;
4 4
 
5 5
 use app\common\dao\BaseDao;
6 6
 use app\common\model\shared\SharedProsperityUser;
7
+use app\entity\data\shared\SharedProsperityUserEntity;
7 8
 
8 9
 class SharedProsperityUserDao extends BaseDao
9 10
 {
@@ -12,4 +13,29 @@ class SharedProsperityUserDao extends BaseDao
12 13
     {
13 14
         return SharedProsperityUser::class;
14 15
     }
16
+
17
+    /**
18
+     * @param array $userIdList
19
+     * @return SharedProsperityUserEntity[]
20
+     */
21
+    public function getSharedProsperityUserEntityListByUserIdList(array $userIdList): array
22
+    {
23
+        $entityList = [];
24
+        try {
25
+            /** @var SharedProsperityUser $model */
26
+            $model = $this->getModel();
27
+            $dataRes = $model::getDB()
28
+                ->whereIn('user_id', $userIdList)
29
+                ->select()
30
+                ->toArray();
31
+            if (!empty($dataRes)) {
32
+                $entityList = array_map(function ($data) {
33
+                    return SharedProsperityUserEntity::newInstance($data);
34
+                }, $dataRes);
35
+            }
36
+        } catch (\Exception $e) {
37
+
38
+        }
39
+        return $entityList;
40
+    }
15 41
 }

+ 25 - 0
app/common/repositories/shared/SharedProsperityUserRepository.php

@@ -20,6 +20,31 @@ class SharedProsperityUserRepository extends BaseRepository
20 20
         $this->dao = $dao;
21 21
     }
22 22
 
23
+    /**
24
+     * @param int $userId
25
+     * @return SharedProsperityUserEntity
26
+     */
27
+    public function getSharedProsperityUserEntityByUserId(int $userId): SharedProsperityUserEntity
28
+    {
29
+        $entityList = $this->getSharedProsperityUserEntityListByUserIdList([$userId]);
30
+        $entity = array_shift($entityList);
31
+        if ($entity instanceof SharedProsperityUserEntity) {
32
+            return $entity;
33
+        } else {
34
+            /** @var SharedProsperityUserEntity */
35
+            return SharedProsperityUserEntity::newInstance();
36
+        }
37
+    }
38
+
39
+    /**
40
+     * @param array $userIdList
41
+     * @return SharedProsperityUserEntity[]
42
+     */
43
+    public function getSharedProsperityUserEntityListByUserIdList(array $userIdList): array
44
+    {
45
+        return $this->dao->getSharedProsperityUserEntityListByUserIdList($userIdList);
46
+    }
47
+
23 48
     public function create($data)
24 49
     {
25 50
         return $this->dao->create($data);