《仿盒马》app开发技术分享-- 逻辑优化第一弹(81)
2025-06-28 13:39:29
139次阅读
0个评论
最后修改时间:2025-07-23 22:28:37
技术栈
Appgallery connect
开发准备
随着上一节我们兑换商品订单相关逻辑的实现,我们的app功能已经更加的完善了,接下来我们开始对整个app缺失的小功能以及对已有的功能bug进行优化和逻辑的新增,这一节我们新增的功能是,商城订单的揽收 功能,兑换订单的取消后积分退回功能,如果不实现积分退回,就会出现用户兑换后取消订单,但是积分已经消耗的情况,这时我们的业务逻辑就产生了一个bug,造成了一个比较抽象的情况。
功能分析
要实现商城订单的揽收功能,首先需要在待发货列表里新增确认揽收按钮,并新增修改订单状态的功能,在实现确认揽收时,我们要注意的是id的问题,在这里我们实现了upsert方法去修改数据源,在修改之前我们就拿到了数据,所以在修改的时候我们需要的id是我们查询出来的id,不是我们新增的id,如果我们新增id,就会在后端创建一跳出了id以外一摸一样的数据,造成数据错乱,然后我们在兑换订单点击取消按钮后把扣除掉用户的积分返还给用户,在积分返还的时候我们也要注意id的问题,只要是修改数据,我们的id都要是查询出来的id,不需要去实现一个随机数id
代码实现
首先我们在列表中新增确认揽收按钮,实现相关的逻辑,在确认揽收中我们提交了若干参数,在创建当前时间戳的时候我们还需要生成对应的时间戳方法。
formatCurrentDate(): string {
const now = new Date();
const year = now.getFullYear();
const month = String(now.getMonth() + 1).padStart(2, '0');
const day = String(now.getDate()).padStart(2, '0');
return `${year}-${month}-${day}`;
}
接下来我们实现确认揽收相关的方法
Row({space:10}){
Text()
Blank()
Text("确认揽收")
.fontColor(Color.Black)
.fontSize(12)
.padding(5)
.borderRadius(10)
.backgroundColor(Color.Pink)
.onClick(async ()=>{
let orderPush=new order_list()
orderPush.id=item.id
orderPush.user_id=this.user!.user_id
orderPush.order_product_id=item.order_product_id
orderPush.order_code=item.order_code
orderPush.order_status=1
orderPush.order_remark=item.order_remark
orderPush.address=item.address
orderPush.nickname=item.nickname
orderPush.phone=item.phone
orderPush.order_create_time=item.order_create_time
orderPush.order_pay_time=this.formatCurrentDate()
orderPush.order_delivery_time=this.formatCurrentDate()
let num = await databaseZone.upsert(orderPush);
if (num>0) {
this.onRefresh()
showToast("揽收成功")
}
})
}
.width('100%')
接下来我们在积分订单按钮点击逻辑事件中,实现积分兑换订单取消,在取消订单后我们给当前操作用户实现一条数据的新增,实现把积分返还给用户
if (num>0) {
showToast("兑换取消成功")
let points=new points_info()
points.id=Math.floor(Math.random() * 1000000)
points.user_id=this.user!.user_id
points.points=String(item.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 nums1 = await databaseZone.upsert(points);
this.onRefresh()
}
现在我们就不会出现用户退单后积分已经消费的问题了
00
- 0回答
- 0粉丝
- 0关注
相关话题
- 《仿盒马》app开发技术分享-- 逻辑优化第三弹(83)
- 《仿盒马》app开发技术分享-- 逻辑优化第二弹(82)
- 《仿盒马》app开发技术分享-- 购物车逻辑优化(39)
- 《仿盒马》app开发技术分享-- 优惠券逻辑优化(58)
- 《仿盒马》app开发技术分享-- 订单提交逻辑完善(74)
- 《仿盒马》app开发技术分享-- 用户登录页(业务逻辑)(21)
- 《仿盒马》app开发技术分享-- 确认订单页(业务逻辑)(30)
- 《仿盒马》app开发技术分享-- 旧物回收页(业务逻辑)(41)
- 《仿盒马》app开发技术分享--未完成订单列表展示逻辑优化(61)
- 《仿盒马》app开发技术分享-- 购物车业务逻辑完善(34)
- 《仿盒马》app开发技术分享-- 个人中心&关于逻辑完善(36)
- 《仿盒马》app开发技术分享-- 个人中心页优化(62)
- 《仿盒马》app开发技术分享-- 扫一扫功能(35)
- 《仿盒马》app开发技术分享-- 金刚区(3)
- 《仿盒马》app开发技术分享-- 定位获取(25)