Member Management System H5-02 Member Recharge

In the previous article, we explained the card opening business on the mobile terminal. After the membership card is opened, the next business is to recharge. We have already implemented the logic of recharge on the PC side. In this article, we will follow the logic on the PC side and add a new business point when recharging.

1 Data source added

When recharging to members, we will give members corresponding points according to the same amount. You need to create a data source for points records first. Open the console, find the data source, click Add, enter
Insert image description here
the name of the data source Points Record,
Insert image description here
click Edit to add a field
Insert image description here
, first add a points field, select Number as the type,
Insert image description here
then create a points type field, select Enumeration as the type, and click Create Now to add the enumeration value
Insert image description here
We set the points type to recharge and consumption.
Insert image description here
After we have the points record table, we also have a points field. Here we first consider adding a field to the membership table.
Insert image description here

2 Add navigation function

After the data source is set up, we first add a navigation function, open our application, add a new navigation menu to the grid navigation on the homepage, create a member recharge page, then
Insert image description here
set
Insert image description here
the navigation page and jump to the member recharge page.
Insert image description here

3 Develop member recharge page

If the member recharges, use the form container to generate it, add the form container, and select the recharge record data source.
Insert image description here
When recharging, first select the member, and then fill in the membership card according to the member. We now add an ordinary container at the top, and add single-line input components and buttons inside.
Insert image description here
Set the layout style of the ordinary container and change it to horizontal arrangement. Switch
Insert image description here
the single-line input template to search template
Insert image description here
. Modify the button style to link style.
Insert image description here

4 Fill in the membership card information

After the interface is built, we need to implement some logic. The effect we want is to enter the mobile phone number, click Query, and fill the membership card information under the member into the drop-down box. First create a variable in the code area to save the phone number we entered.
Insert image description here
Insert image description here
Then select the single-line input component, set the value change event, and assign the value we entered to the variable.
Insert image description here
Insert image description here
Insert image description here
When we click to query, we need to call the custom code we created. In the code Create a new javascript method
Insert image description here
and enter the following code

export default async function({
     
     event, data}) {
    
    
try {
    
    
    const data = await $w.cloud.callDataSource({
    
    
      dataSourceName: "hyxx_u9t5lg8",
      methodName: "wedaGetItemV2",
      params: {
    
    
        // 筛选内容,筛选内容推荐使用编辑器数据筛选器生成
        filter: {
    
    
          where: {
    
    
            $and: [
              {
    
    
                sj: {
    
    
                  $eq: $page.dataset.state.telphone, // 获取单条时,推荐传入_id数据标识进行操作
                },
              },
            ],
          },
        },
        select: {
    
    
          $master: true, // 常见的配置,返回主表
        },
      },
    });
    console.log("请求结果", data); 
  $w.page.dataset.state.memberid = data._id
  } catch (e) {
    
    
    console.log("错误代码", e.code, "错误信息", e.message);
  }

}

The logic of the code is to match the member information based on the entered phone number, and assign the returned data identifier to the memberid. We create a variable to receive the return value. Select the membership card
Insert image description here
field and set the filtering
Insert image description here
conditions. The filtering conditions are set to the member equal to our memberid.
Insert image description here
Finally, we set the click event for the button and call our custom code
Insert image description here

5 Implement membership recharge logic

Create a javascript method in the code area.
Insert image description here
The code is as follows

export default async function({
     
     event, data}) {
    
    
   const chongzhi = $w.form1.submitParams.data
   try {
    
    
    const card = await $w.cloud.callDataSource({
    
    
      dataSourceName: "hykxx_gmcze7h",
      methodName: "wedaGetItemV2",
      params: {
    
    
        // 筛选内容,筛选内容推荐使用编辑器数据筛选器生成
        filter: {
    
    
          where: {
    
    
            $and: [
              {
    
    
                _id: {
    
    
                  $eq:chongzhi.sshyk , // 获取单条时,推荐传入_id数据标识进行操作
                },
              },
            ],
          },
        },
        select: {
    
    
          $master: true, // 常见的配置,返回主表
        },
      },
    });

    const chongzhirecord = await $w.cloud.callDataSource({
    
    
      dataSourceName: "czjl_bzq96i1",
      methodName: "wedaCreateV2",
      params: {
    
    
        data: chongzhi,
      },
    });
const gengxin = await $w.cloud.callDataSource({
    
    
      dataSourceName: "hykxx_gmcze7h",
      methodName: "wedaUpdateV2",
      params: {
    
    
        // 更新数据
        data: {
    
    
          ye: card.ye+Number(chongzhi.czje),
        },
        // 筛选内容,筛选内容推荐使用编辑器数据筛选器生成
        filter: {
    
    
          where: {
    
    
            $and: [
              {
    
    
                _id: {
    
    
                  $eq: chongzhi.sshyk, // 更新单条时,推荐传入_id数据标识进行操作
                },
              },
            ],
          },
        },
      },
    });

   const data = await $w.cloud.callDataSource({
    
    
      dataSourceName: "jfjl_pn9c908",
      methodName: "wedaCreateV2",
      params: {
    
    
        data: {
    
    
          jflx: "1",
          jf: chongzhi.czje,
        },
      },
    });
    
    const member = await $w.cloud.callDataSource({
    
    
      dataSourceName: "hyxx_u9t5lg8",
      methodName: "wedaGetItemV2",
      params: {
    
    
        // 筛选内容,筛选内容推荐使用编辑器数据筛选器生成
        filter: {
    
    
          where: {
    
    
            $and: [
              {
    
    
                _id: {
    
    
                  $eq:$w.page.dataset.state.memberid , // 获取单条时,推荐传入_id数据标识进行操作
                },
              },
            ],
          },
        },
        select: {
    
    
          $master: true, // 常见的配置,返回主表
        },
      },
    });
    console.log("jf",member.jf)

    const jfgengxin = await $w.cloud.callDataSource({
    
    
      dataSourceName: "hyxx_u9t5lg8",
      methodName: "wedaUpdateV2",
      params: {
    
    
        // 更新数据
        data: {
    
    
          jf: Number(member.jf?member.jf:0)+Number(chongzhi.czje),
        },
        // 筛选内容,筛选内容推荐使用编辑器数据筛选器生成
        filter: {
    
    
          where: {
    
    
            $and: [
              {
    
    
                _id: {
    
    
                  $eq: $w.page.dataset.state.memberid, // 更新单条时,推荐传入_id数据标识进行操作
                },
              },
            ],
          },
        },
      },
    });
    console.log("请求结果", data); // {"id": "f8f6930864c11bde006ff6c4662f9bf6"}
  } catch (e) {
    
    
    console.log("错误代码", e.code, "错误信息", e.message);
  }

   console.log("form1",$w.form1.submitParams)
}

Then replace the submit method of the form container with your own method
Insert image description here

Summarize

In this article, we have implemented the business logic of recharge, explained the method of filling the drop-down list based on query conditions, and used custom methods to customize the business logic, so that you can design business rules according to your own needs.

Guess you like

Origin blog.csdn.net/u012877217/article/details/133077857