How to obtain user information through uid after the user is divided into tables

Some time ago, Hunan Red Network had a requirement, which was to call the top 10 ranked posts by users. The basic effect of the test is to first query the uid set of the top 10 (because the original data structure of the functional module only queries the uid information in the pinned table). The final effect is as follows (since the test website only has a small part of the data, only 5 are displayed below):


After getting the uid, you need to get several data related to the user, including the avatar, the URL of the personal homepage, and the user name; the avatar can be obtained using the avatar method in discuz, and the URL of the personal homepage can be assembled directly through the uid. The user name needs to be obtained separately. Some people may say that you can directly use the fetch_first method of the DB class to query the common_member table to find the user's corresponding user name.

But there is a premise from the beginning, that is, the users of the website are divided into tables. For example, after the tables are divided, two user tables will be generated, namely common_member and common_member_archive, so just querying the former will definitely not work. In fact, if you read discuz's own source code, you can find that in many places, his approach is to determine whether the user is in common_member. If it exists, call the value directly. Otherwise, you need to query common_member_archive. The following is the source code of a module of discuz itself:


This is obviously feasible, but through Class C, it is found that username is not checked through uid, but uid is only checked through username. This is the above. If you want to use this idea, you need to write it like this:


However, there is actually an easier way

That is to do the processing through uc, because what is needed is the user name and other information also saved in uc, and for ordinary website users, the user information saved in uc is consistent with the user information saved in dz. For example, you can see the following method in the discuz source code:


Anyone who is familiar with discuz development knows that as the name suggests, this method is used to retrieve user information in uc. We can find this method in uc_client/client.php:


The method called by this method can then be found in uc_client/control/user.php:


That is to say, we only need to pass in 1 as the second parameter at the beginning, that is, get_user_by_uid() will be called in this method, and the parameter is actually uid. Then we can find the method in uc_client/model/user.php:


In this way, the user information in uc has been retrieved. It should be noted that when returning in the onget_user method in the previous step, it did not return all the user's information, nor did it return an array with key values such as uid, username, email, etc. So if $user is returned, if the value of username needs to be obtained, it cannot be written as $user['username'].

At this point, the user's user name is obtained through the user uid of discuz by calling the uc user.