ITPub博客

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

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

原创 HTML5 作者:鸿蒙小林 时间:2025-06-27 21:21:09 0 删除 编辑


## 技术栈


Appgallery connect


## 开发准备

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



## 功能分析

首先我们要在兑换完成后把用户信息的积分给扣除掉,点击按钮之后我们先要拿到修改前的id,修改当前id下的数据,不要重新创建id,不然我们的修改就会新增一条数据,点击按钮后进行云端交互修改用户信息表,然后我们在兑换成功时新增一条积分消费记录。



## 代码实现


我们先在订单提交的时候修改用户信息表的内容,在这里我们注意当前表单的id,一定不要修改这个id,否则我们的修改就会变成新增数据,其他的内容我们都拿查询出来的数据,把要修改的数据重新赋值。


```css

 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);

                }

```

修改完用户信息之后,我们同时还需要新增一条积分收支记录,在收支记录添加前,还需要实现一个时间获取的方法,时间获取我们要注意当前的月份只到11月,如果要实现12月份的时间选择,我们还要在月份处加一,然后我们定义时间变量,在方法中进行赋值即可

```css


@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

  }

```

记录生成,这里我们是提交后进行积分的新增,所以需要新生成一个订单,把积分给用户添加进去,这里我们需要注意订单当前的状态和说明,状态会影响我们后续的展示


```css

 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);

```

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


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70046889/viewspace-3089321/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2025-06-26

  • 博文量
    90
  • 访问量
    67426