| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- <?php
- namespace app\common\dao\shared;
- use app\common\dao\BaseDao;
- use app\common\model\BaseModel;
- use app\common\model\shared\SharedProsperityGroupUser;
- use app\entity\data\shared\SharedProsperityGroupUserEntity;
- use think\db\exception\DbException;
- class SharedProsperityGroupUserDao extends BaseDao
- {
- /**
- * @return BaseModel
- */
- protected function getModel(): string
- {
- return SharedProsperityGroupUser::class;
- }
- /**
- * 获取按团队分组的有效用户ID列表
- * @return array [group_id => [user_id1, user_id2, ...]]
- */
- public function getValidUsersGroupByGroup(): array
- {
- try {
- $rows = $this->getModel()::where('status', 1)
- ->field('group_id, user_id')
- ->select()
- ->toArray();
- $grouped = [];
- foreach ($rows as $row) {
- $grouped[$row['group_id']][] = $row['user_id'];
- }
- return $grouped;
- } catch (\Exception $e) {
- return [];
- }
- }
- /**
- * @param $groupId
- * @return array
- * @author 史晨
- * @date 2026/2/27 11:31
- * 获取团队用户(分页)
- */
- public function getUserByLevel($groupId)
- {
- try {
- return $this->getModel()::where('status', 1)
- ->where(['group_id' => $groupId])
- ->paginate(20)
- ->toArray();
- } catch (DbException $e) {
- return [];
- }
- }
- /**
- * @param array $idList
- * @return SharedProsperityGroupUserEntity[]
- */
- public function getSharedProsperityGroupUserEntityListByIdList(array $idList): array
- {
- $entityList = [];
- try {
- /** @var SharedProsperityGroupUser $model */
- $model = $this->getModel();
- $dataRes = $model::getDB()
- ->whereIn('id', $idList)
- ->select()
- ->toArray();
- if (!empty($dataRes)) {
- $entityList = array_map(function ($data) {
- return SharedProsperityGroupUserEntity::newInstance($data);
- }, $dataRes);
- }
- } catch (\Exception $e) {
- }
- return $entityList;
- }
- /**
- * @param array $userIdList
- * @return SharedProsperityGroupUserEntity[]
- */
- public function getSharedProsperityGroupUserEntityListByUserIdList(array $userIdList): array
- {
- $entityList = [];
- try {
- /** @var SharedProsperityGroupUser $model */
- $model = $this->getModel();
- $dataRes = $model::getDB()
- ->whereIn('user_id', $userIdList)
- ->select()
- ->toArray();
- if (!empty($dataRes)) {
- $entityList = array_map(function ($data) {
- return SharedProsperityGroupUserEntity::newInstance($data);
- }, $dataRes);
- }
- } catch (\Exception $e) {
- }
- return $entityList;
- }
- }
|