《仿盒马》app开发技术分享-- 订单提交逻辑完善(74)

2025-06-28 13:35:55
105次阅读
0个评论

## 技术栈

Appgallery connect

开发准备

上一节我们实现了兑换订单的提交功能,并且成功的把数据提交到云端,但是我们的业务逻辑并没有完全实现,我们只是把数据提交到了云端,但我们的积分还存在,我们回到积分数据查看的页面也没有消费积分的记录,这一节我们要实现的就是完善订单提交的业务逻辑

功能分析

首先我们要在兑换完成后把用户信息的积分给扣除掉,点击按钮后进行云端交互修改用户信息表,然后我们在兑换成功时新增一条积分消费记录。

代码实现

我们先在订单提交的时候修改用户信息表的内容

 if (num>0) {
                  showToast("兑换成功")

                  let userData=new user_info()
                  userData.id=this.userInfo!.id
                  userData.user_id=this.userInfo!.user_id
                  userData.sex=this.userInfo!.sex
                  userData.bind_phone=this.userInfo!.bind_phone
                  userData.create_time=this.userInfo!.create_time
                  userData.nickname=this.userInfo!.nickname
                  userData.head_img=this.userInfo!.head_img
                  userData.money=this.userInfo!.money
                  userData.points=this.userInfo!.points-this.pointsProduct!.points
                  let s= await databaseZone.upsert(userData);
                }

修改完用户信息之后,我们同时还需要新增一条积分收支记录,在收支记录添加前,还需要实现一个时间获取的方法


@State year:string=''
  @State month:string=''
  @State day:string=''
  @State time:string=''
  formatCurrent() {
    const now = new Date();

    const years = now.getFullYear();
    const months = String(now.getMonth() + 1).padStart(2, '0');
    const days = String(now.getDate()).padStart(2, '0');
    const m_hours = String(now.getHours()).padStart(2, '0');
    const m_minutes = String(now.getMinutes()).padStart(2, '0');
    const m_seconds = String(now.getSeconds()).padStart(2, '0');
    this.year=String(years)
    this.month=months
    this.day=days
    this.time=m_hours+":"+m_minutes+":"+m_seconds
  }

记录生成

 let points=new points_info()
                  points.id=Math.floor(Math.random() * 1000000)
                  points.user_id=this.user!.user_id
                  points.points=String(this.pointsProduct?.points)
                  points.points_type='0'
                  points.address='客户端下单奖励'
                  points.year=this.year
                  points.month=this.month
                  points.day=this.day
                  points.time=this.time
                  points.create_time=this.year+"-"+this.month+"-"+this.day+" "+this.time
                  let points_nums =  await databaseZone.upsert(points);

到这里我们的订单提交逻辑就彻底完善了

收藏00

登录 后评论。没有帐号? 注册 一个。