dao = $dao; } /** * 插入或更新零号线用户数据 * * @param int|null $id 用户ID,为null时表示新增 * @param array $data 用户数据 * @return \app\common\dao\BaseDao|bool|\think\Model * @throws DbException */ public function insertOrUpdate(?int $id, array $data) { // 团队昵称为空时,取用户昵称 $userDao = new UserDao(); if (empty($data['team_name'])) { $userData = $userDao->get($data['team_uid']); $data['team_name'] = $userData->nickname; } // 判断是更新现有记录还是创建新记录 if ($data['id'] > 0) { return $this->dao->update($id, $data); } try { Db::startTrans(); // 0号线用户修改节点 $userDao->update($data['team_uid'], ['level_id' => $this->systemUserId]); // 如果不带走团队,所有直推用户节点id修改成上级id if ($data['is_remove'] != 1) { $directUserIds = $userDao->getDirectUserIds($data['team_uid']); $upLevelId = $userData->level_id; $userDao->updates($directUserIds, ['level_id' => $upLevelId]); } $this->dao->create($data); Db::commit(); return true; } catch (\Exception $e) { Db::rollback(); return false; } } /** * @param $param * @return array * 获取列表 */ public function getList($param) { $where = $this->getWhere($param); $list = $this->dao->getList($where,$param->page,$param->limit); return $list->toArray(); } /** * @param $param * @return array * 拼接搜索条件 */ private function getWhere($param): array { $where = []; // 状态条件 - 精确搜索 if (!empty($param->status)) { $where[] = ['status', '=', $param->status]; } // 团队昵称条件 - 模糊搜索 if (!empty($param->teamName)) { $where[] = ['team_name', 'like', '%' . $param->teamName . '%']; } // 团队长uid条件 - 精确搜索 if (!empty($param->account)) { $userDao = new UserDao(); $userWhere[] = ['account','like','%' . $param->account . '%']; $userData = $userDao->getWhere($userWhere,'uid'); $where[] = ['team_uid', '=', $userData->uid ?? 0]; } return $where; } }