How to get the user's account balance `Balance` and cumulative earnings `TotalReward` through the `userDetail` tag?

Calendar 👁️ 70

How to retrieve and display a user's account balance and cumulative income in the Anqi CMS template?

For operators, flexibly displaying user-specific information on the website, such as their account balance or cumulative earnings, is a key element in improving user experience and managing the membership system.AnQi CMS as a powerful and practical content management system, provides a very convenient way to obtain these user data.Today, let's talk about how to use your template touserDetailTags can easily retrieve and display a user'sBalance(account balance) andTotalReward(cumulative income).

Get to know in-depthuserDetailTag

userDetailIt is a very practical tag in the Anqi CMS template engine, specifically used to obtain detailed information about a specified user.It's like a data interface that allows you to directly retrieve various properties of the user in the front-end template based on the user ID.Whether it is the basic information of the user, or the financial data we are concerned about today,userDetailCan easily help you achieve that.

While usinguserDetailThe most core parameter when labeling isid. ThisidRepresents the user identity you want to retrieve. Typically, this will be the ID of the currently logged-in user, or the ID of a specific user you want to display in a particular scenario.

Its basic usage form is as follows:

{% userDetail 变量名称 with name="字段名称" id="用户ID" %}

Here, "variable name" is the temporary name you specify for the data you obtain, for easy reference in templates; "field name" is the specific user attribute you want to obtain, such asBalanceorTotalReward;“User ID” literally means the unique identifier of the user to be queried.

Get the user's account balance (Balance)

The account balance usually refers to the available funds of the user on the platform, which can be used for consumption, purchasing services, or cash withdrawal, etc.It is an essential function to display the user's account balance on membership, points system, or e-commerce websites.

ByuserDetailLabel, we can get the user's account balance like this:

{# 假设我们已经通过某种方式获取到了当前登录用户的ID,并存储在名为 `currentUser.Id` 的变量中 #}

<p>
    <strong>当前账户余额:</strong>
    {% userDetail userBalance with name="Balance" id=currentUser.Id %}
    {{ userBalance }} 元
</p>

In this code, we useuserDetailLabel, specifyname="Balance"to retrieve the user's balance and assign the result touserBalancethis temporary variable. Subsequently, through{{ userBalance }}The balance amount can be displayed on the page. If the user has no balance or the amount is zero, it usually displays '0' or '0.00'.

Get the cumulative income of the user (TotalReward)

The cumulative income is more focused on the total income accumulated by users on the platform through certain behaviors (such as content creation rewards, promotion commissions, invitation rebates, etc.).This is very helpful in motivating users and showcasing the value of the platform.

The method to get the cumulative income of the user is similar to getting the balance:

{# 假设我们已经通过某种方式获取到了当前登录用户的ID,并存储在名为 `currentUser.Id` 的变量中 #}

<p>
    <strong>累计收益:</strong>
    {% userDetail totalReward with name="TotalReward" id=currentUser.Id %}
    {{ totalReward }} 元
</p>

Similarly, we specifyname="TotalReward"to get the cumulative income and store it intotalRewardThe variable is then displayed. This value is usually a continuously increasing cumulative value that can bring users a sense of achievement.

Combine with the actual application scenario

In practice, you may wish to display these financial information simultaneously on a user center page or personal dashboard.Combine them, and users can easily understand their financial situation.

For example, you might write template code like this in a user's personal center page overview module:

<div class="user-financial-overview">
    <h2>我的财务概览</h2>

    {# 假设 currentUser.Id 已经由后端传递到模板上下文中,代表当前登录用户的ID #}

    {% userDetail userBalance with name="Balance" id=currentUser.Id %}
    {% userDetail totalReward with name="TotalReward" id=currentUser.Id %}

    <p>
        <strong>当前可用余额:</strong>
        {# 如果希望余额为0时显示特定文本,可以结合if标签判断 #}
        {% if userBalance > 0 %}
            <span class="highlight-balance">{{ userBalance }}</span> 元
        {% else %}
            <span>0.00</span> 元
        {% endif %}
    </p>

    <p>
        <strong>历史累计收益:</strong>
        {# 同样,如果累计收益为0时显示特定文本 #}
        {% if totalReward > 0 %}
            <span class="highlight-reward">{{ totalReward }}</span> 元
        {% else %}
            <span>0.00</span> 元
        {% endif %}
    </p>

    <div class="actions">
        <a href="/user/recharge">充值</a>
        <a href="/user/withdraw">提现</a>
        <a href="/user/rewards">收益明细</a>
    </div>
</div>

In this way, not only do you display the data, but you can also present it in different styles based on specific data values (such as whether it is greater than 0), even guide the user to the next step, making the entire financial module more vivid and practical.

Summary

userDetailThe label provides great flexibility for Anqi CMS users, allowing them to easily display dynamic user-related data on the front-end template. By proficiently usingBalanceandTotalRewardThese fields will enable your website to better serve various business scenarios such as member management, content monetization, e-commerce operations, and provide users with more personalized and transparent experiences.


Frequently Asked Questions (FAQ)

1.userDetailin the labelidHow should the parameter be obtained? idThe parameter usually represents the ID of the currently logged-in user. In the regular development process of Anqi CMS, the backend controller will pass the current logged-in user's ID through the template context (Context) to the front-end template, and you can directly refer to this variable in the template (as shown in the above example)currentUser.Id). If in a specific scenario it is necessary to display other users' IDs, then the user's ID should be obtained through URL parameters, database queries, and passed to the template.

2. If the user does not haveBalanceorTotalRewarddata, what will the template display?ForBalanceandTotalRewardfor this type of numeric field, if the user does not have relevant records or the data is zero,userDetailthe label will usually return directly0In the template, you can combine as shown in the sample code.{% if ... %}The tag is used for judgment. When the value is 0, it displays "0.00" or other more friendly prompts, such as "No balance" or "No earnings yet."}

3. In addition to account balance and cumulative earnings,userDetailWhat information can tags obtain about users? userDetailTags have very rich functions, in addition toBalanceandTotalRewardIt can also obtain many other important information about the user, such as:

  • UserNameUsername
  • RealNameReal Name
  • EmailEmail
  • PhonePhone Number
  • AvatarURL: User avatar link
  • GroupId: User group ID
  • IsRetailer: Is a distributor
  • InviteCode: Invitation code
  • LastLogin: Last login time (timestamp, needs to be paired with...stampToDateformatted)
  • ExpireTime: VIP expiration time (timestamp, needs to be coordinated with)stampToDateformatting) You can flexibly call these fields according to your actual needs to build a more perfect user page.

Related articles

How to dynamically display exclusive content for distributors based on the user's `IsRetailer` status in AnQiCMS templates?

Today, providing customized experiences for users of different types has become the key to improving user satisfaction and business efficiency.For businesses with a distribution system, how to ensure that distributors can easily access their exclusive content without causing interference to ordinary users is a common need.AnQiCMS with its flexible template engine and powerful user management features, can help you easily achieve this goal.

2025-11-07

How to format `LastLogin` (last login time) into a readable date using the `stampToDate` tag?

In website operation and management, user behavior data is an important basis for improving user experience and formulating strategies.Among them, the "LastLogin" is a direct indicator of user activity.However, this data is usually stored in the form of raw timestamps, and for ordinary users, a string of numbers is far less friendly and understandable than a direct date and time.AnQi CMS provides powerful template tag functions, among which the `stampToDate` tag is a powerful tool to solve this problem, it can help us easily convert abstract timestamps into clear and readable date formats

2025-11-07

The `userDetail` tag supports which parameters to accurately find specific user information?

In AnqiCMS template development, to display specific user information on the page, we often use a very practical tag - `userDetail`.This tag allows us to accurately retrieve and present detailed user data based on specific conditions.Understanding the parameters it supports is crucial for flexibly building user-related page functions.The core function of the `userDetail` tag is to obtain data based on a clear user identifier.When in use, it requires us to specify the user ID to be queried through the `id` parameter

2025-11-07

How to use the `userDetail` tag to retrieve the user's real name `RealName` on the frontend page?

In website operations, personalization and user experience are the key to enhancing brand image.Sometimes, we are not satisfied with just displaying the user's nickname or avatar. In certain scenarios, such as the member center, profile page, or some activity leaderboard, we may also need to display the user's real name.AnQi CMS is a highly flexible and feature-rich Go language content management system that provides intuitive template tags, allowing front-end developers to easily retrieve and display this information.Today, let's delve into how to use the `userDetail` tag of Anqi CMS

2025-11-07

Can the `userDetail` tag retrieve the user's email `Email` and phone number `Phone` and display it on the front end?

In website operation and user experience design, sometimes we need to display specific user information on the front-end page, such as contact email or phone number, in order to provide personalized services or facilitate users to view/update their personal information.It is crucial for users of AnQiCMS to understand how to implement this safely and efficiently.This article will delve into the `userDetail` tag of AnQiCMS, discussing whether it can retrieve and display the user's email (`Email`) and phone number (`Phone`), as well as the matters that need to be paid attention to during use

2025-11-07

How to use `AvatarURL` or `FullAvatarURL` to display a user avatar in the template?

In website operation, the user avatar is not just a decoration, it carries the user's identity and is an important part of community interaction and personalized experience.Whether it is in the comment area, author introduction, or member center, a clear user avatar can significantly enhance the website's affinity and professionalism.AnQiCMS as an efficient content management system naturally also provides us with the powerful function of flexibly displaying user avatars in templates.Today, let's talk about how to use the `AvatarURL` and `FullAvatarURL` fields in AnQiCMS templates

2025-11-07

How to get the `GroupId` of the user through the `userDetail` tag and further get the detailed information of the user group?

In AnQiCMS, providing personalized content and experience to users is a key link to enhance website stickiness.It is particularly important to understand the details of the user's group to display exclusive content based on user level or provide differentiated service information.Today, let's delve into how to make use of the powerful template tag features of AnQiCMS, through the `userDetail` tag to obtain the `GroupId` of the user, and further use the `userGroupDetail` tag to display the detailed information of these user groups on the website front end

2025-11-07

How to display the personal introduction filled in the `Introduce` field on the user's profile page?

In website operation, providing users with personalized profile display, especially the personal introduction filled in by users themselves, can greatly enhance the vitality and sense of belonging of the community.For users of AnQiCMS, it is actually a very intuitive and flexible operation to display the personal introduction filled in by the user in the `Introduce` field on the profile page, mainly relying on the powerful template tag system of AnQiCMS.### Understand the template mechanism of AnQiCMS In AnQiCMS

2025-11-07