$this->mall_id]]; if ($operatorUserType) { $where[] = ['operator_user_type' => $operatorUserType]; } if ($operatorUserKeyword) { if ($operatorUserType == AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_ADMIN) { $adminFind = Admin::find(); Admin::paramPack([ 'where' => [ ['mall_id' => [0, $this->mall_id]], [ 'or', ['like', 'username', $operatorUserKeyword], ['like', 'account', $operatorUserKeyword] ] ], 'select' => 'id' ], $adminFind); $adminIdsBy = $adminFind->column(); $where[] = ['operator_user_id' => $adminIdsBy]; } elseif ($operatorUserType == AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_USER) { $userIdsByMobile = User::find() ->where(['like', 'mobile', $operatorUserKeyword]) ->andWhere(['mall_id' => $this->mall_id]) ->select('id') ->column(); $where[] = ['operator_user_id' => array_merge([$operatorUserKeyword], $userIdsByMobile)]; } } if ($operatorTargetUserKeyword) { $userIdsByOperatorTargetUserKeyword = User::find() ->where(['like', 'mobile', $operatorTargetUserKeyword]) ->andWhere(['mall_id' => $this->mall_id]) ->select('id') ->column(); $where[] = [ 'or', ['=', 'operator_target_user_id', $operatorTargetUserKeyword], ['in', 'operator_target_user_id', $userIdsByOperatorTargetUserKeyword] ]; } if ($behavior) { $where[] = ['=', 'behavior', $behavior]; } $userSelect = 'id, mobile, nickname, avatar_url'; $with = [ 'user' => function ($query) use ($userSelect) { $query->select($userSelect); } ]; $order = 'id desc'; $list = AgentBehaviorLogs::listPage(compact('where', 'with', 'order')); $operatorUserIds = []; array_walk($list['list'], function ($item) use (&$operatorUserIds) { $operatorUserIds[$item['operator_user_type']][] = $item['operator_user_id']; }); // 查询用户 $userList = []; if (!empty($operatorUserIds[AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_USER])) { $userList = User::getUserList( [ ['in', 'id', $operatorUserIds[AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_USER]] ], $userSelect, [], true ); } // 查询后台管理员 $adminList = []; if (!empty($operatorUserIds[AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_ADMIN])) { $adminList = Admin::lists([ 'where' => [ [ 'id' => $operatorUserIds[AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_ADMIN], 'status' => [StatusEnum::DISABLED, StatusEnum::ENABLED] ] ], 'select' => "id, account mobile, username nickname" ]); } $userList = array_column($userList, null, 'id'); $adminList = array_column($adminList, null, 'id'); array_walk($list['list'], function (&$item) use ($adminList, $userList) { $item['extra_info'] = json_decode($item['extra_info'], true); $item['behavior_text'] = AgentBehaviorLogsEnum::getMapValueByKey(0, $item['behavior']); $item['operator_user_type_text'] = AgentBehaviorLogsEnum::getMapValueByKey(1, $item['operator_user_type']); $item['created_at_text'] = date('Y-m-d H:i:s', $item['created_at']); $item['ip_text'] = $item['ip'] ? long2ip($item['ip']) : '-'; $item['operator_user'] = AgentBehaviorLogsEnum::OPERATOR_USER_TYPE_USER == $item['operator_user_type'] ? ($userList[$item['operator_user_id']] ?? []) : ($adminList[$item['operator_user_id']] ?? []); }); return $list; } }