《仿盒马》app开发技术分享-- 订单结合优惠券结算(60)

鸿蒙小林
• 阅读 3

技术栈

Appgallery connect

开发准备

上一节我们已经实现了优惠券的选择,并且成功的把券后的价格也展示给用户,不能使用的优惠券我们也用友好的方式告知用户,这一节我们来实现优惠券内容的下一步,优惠券内容结合订单进行结算提交

功能分析

因为我们之前的订单列表是订单相关商品相关是分开的,所以在这里我们同样要把优惠券的内容分开,只存储id进去后续再查询出对应的券金额,我们首先就是要修改订单表,然后在券选择的同时拿到优惠券的相关内容,提交订单时把优惠券内容一起提交,方便我们后续的订单详情内查询券后价

代码实现

首先修改orderlist的表内容

{
  "CloudDBZoneName": "default",
  "objectTypeName": "order_list",
  "fields": [
    {"fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},
    {"fieldName": "user_id", "fieldType": "Integer", "notNull": true, "defaultValue": 0},
    {"fieldName": "order_code", "fieldType": "String"},
    {"fieldName": "order_status", "fieldType": "Integer"},
    {"fieldName": "order_product_id", "fieldType": "String"},
    {"fieldName": "coupon_id", "fieldType": "Integer"},
    {"fieldName": "address", "fieldType": "String"},
    {"fieldName": "nickname", "fieldType": "String"},
    {"fieldName": "phone", "fieldType": "String"},
    {"fieldName": "order_remark", "fieldType": "String"},
    {"fieldName": "pay_type", "fieldType": "String"},
    {"fieldName": "order_create_time", "fieldType": "String"},
    {"fieldName": "order_pay_time", "fieldType": "String"},
    {"fieldName": "order_delivery_time", "fieldType": "String"},
    {"fieldName": "order_over_time", "fieldType": "String"}



  ],
  "indexes": [
    {"indexName": "field1Index", "indexList": [{"fieldName":"id","sortType":"ASC"}]}
  ],
  "permissions": [
    {"role": "World", "rights": ["Read", "Upsert", "Delete"]},
    {"role": "Authenticated", "rights": ["Read", "Upsert", "Delete"]},
    {"role": "Creator", "rights": ["Read", "Upsert", "Delete"]},
    {"role": "Administrator", "rights": ["Read", "Upsert", "Delete"]}
  ]
}

然后我们在选择券的时候拿到券的id,这里我们用回调的方式实现

//自定义弹窗页面
 onItemSelected: (coupon_id:number) => void= () => {
  };


//结算页
  @State coupon_id:number=0

 couponController: CustomDialogController| null = new CustomDialogController({
    builder: CouponCheckDialog({
      couponPrice:this.couponPrice,
      price:this.price(),
      onItemSelected:(coupon_id:number)=>{
        this.coupon_id=coupon_id
      }
    }),
    alignment: DialogAlignment.Bottom,
    customStyle:true
  });

结算订单时合并信息提交

 Text("提交订单")
          .fontColor(Color.White)
          .padding(10)
          .borderRadius(10)
          .backgroundColor("#d81e06")
          .fontSize(14)
          .onClick(async ()=>{
            if (this.addressInfo!=null) {
              let databaseZone = cloudDatabase.zone('default');
              try {
                for (let i = 0; i < this.productList.length; i++) {
                  let productPush = new order_product_list();
                  productPush.id=this.codeId+i
                  productPush.order_product_id=this.codeId
                  productPush.img=this.productList[i].productImgAddress
                  productPush.price=this.productList[i].productPrice
                  productPush.name=this.productList[i].productName
                  productPush.originalPrice=this.productList[i].productOriginalPrice
                  productPush.spec=this.productList[i].productSpecName
                  productPush.buyAmount=this.productList[i].buyAmount
                  let num = await databaseZone.upsert(productPush);
                  hilog.info(0x0000, 'testTag', `Succeeded in upserting data, result: ${num}`);

                }
              }catch (e) {
                hilog.info(0x0000, 'testTag', `Succeeded in upserting data, result: ${e}`);
              }


              let orderPush = new order_list();
              orderPush.id=Math.floor(Math.random() * 1000000)
              orderPush.user_id=this.user!.user_id
              orderPush.order_product_id=String(this.codeId)
              orderPush.order_code=this.generateOrderNo(10)
              orderPush.order_status=0
              if (this.remark!='') {
                orderPush.order_remark=this.remark
              }
              orderPush.coupon_id=this.coupon_id
              orderPush.address=this.addressInfo.address
              orderPush.nickname=this.addressInfo.nikeName
              orderPush.phone=this.addressInfo.phone
              orderPush.order_create_time=this.formatCurrentDate()
              orderPush.order_pay_time=this.formatCurrentDate()
              let num = await databaseZone.upsert(orderPush);
              hilog.info(0x0000, 'testTag', `Succeeded in upserting data, result: ${num}`);
              if (num>0) {


                for (let i = 0; i < this.productList.length; i++) {
                  if (this.productList[i].isNeedPay) {
                    let item = new cart_product_list();
                    item.id=this.productList[i].id
                    let listData = await databaseZone.delete(item);
                    hilog.info(0x0000, 'testTag', `Succeeded in upserting data, result: ${listData}`);
                  }
                }
                let eventData: emitter.EventData = {
                  data: {}
                };
                let innerEvent: emitter.InnerEvent = {
                  eventId: 1012,
                  priority: emitter.EventPriority.HIGH
                };
                emitter.emit(innerEvent, eventData);

                  router.replaceUrl({url:'pages/view/OrderSuccessPage',params:orderPush})
              }
            } else {
              showToast("请先选择地址")
            }
          })

到这里我们就实现了结算订单跟优惠券的关联

点赞
收藏
评论区
推荐文章
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 确认订单页(业务逻辑)(30)
技术栈Appgalleryconnect开发准备上一节我们实现了确认订单页的页面绘制和价格计算优惠计算,订单列表展示等功能,这一节我们来实现确认订单页的整个业务逻辑。首先我们要实现的就是地址的选择,然后把我们计算的价格,商品列表等数据保存起来,然后我们开始
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 旧物回收订单列表(43)
技术栈Appgalleryconnect开发准备上一节我们实现了订单的创建,并且成功吧数据提交到云数据库中,这一节我们实现的内容是展示我们提交的订单列表功能分析要实现订单列表的展示,首先我们要查询对应用户下的订单列表,查询出对应的订单列表后,展示出对应的数
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 领取优惠券(56)
技术栈Appgalleryconnect开发准备在之前的功能开发中,我们有些功能只有展示的能力并没有与云端产生任何的交互,后续经过我们的迭代,更多的能力有了交互能力,这一节我们就要开始着手给那些静态展示的模块添加业务逻辑,我们现在要实现的是首页的新人优惠券
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 优惠券展示页(57)
技术栈Appgalleryconnect开发准备上一节我们实现了优惠券的领取功能,并且在云端已经成功查询出优惠券信息,那么我们需要来实现一个优惠券展示的页面来向用户展示当前账号下的优惠券信息,辅助用户更好的去购买需要的商品,因为优惠券会有多种状态,在展示时
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 优惠券逻辑优化(58)
技术栈Appgalleryconnect开发准备我们已经实现了优惠券的领取和展示,现在已经趋近于一个完整的电商应用了,但是这时候问题又来了,我们领取完优惠券之后,我们的新用户优惠券模块依然存在,他并没有消失,既然我们是从云数据库中查询的数据,那么我们需要找
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享--确认订单选择优惠券(59)
技术栈Appgalleryconnect开发准备在上一节我们实现了在确认订单页查询优惠券,但是我们并没有其他优惠券相关的逻辑,我们的目的还是在订单结算的时候去使用我们对应的优惠券,现在我们要在确认订单页去进行优惠券的选择,为了方便用户操作,我们以弹窗的形式
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享--未完成订单列表展示逻辑优化(61)
技术栈Appgalleryconnect前言:上一节我们实现订单与优惠券的联合提交时,我去到订单列表页面查看生成的订单信息,发现现在的订单从信息展示到价格计算全都是有问题的。所以紧急的把对应的问题修改一下。问题来源:cssasyncaboutToAppea
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 兑换订单提交(73)
技术栈Appgalleryconnect开发准备上一节我们实现了兑换提交前的准备页面,向用户展示了兑换相关的所有信息,这一节我们就可以实现兑换订单的提交了功能分析订单提交我们需要创建对应的兑换商品订单提交信息表,我们需要把地址,商品信息,积分,备注,订单状
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 兑换订单列表框架(75)
技术栈Appgalleryconnect开发准备上一节我们针对订单兑换的业务逻辑进行了完善,成功的在兑换物品之后修改了用户信息的修改,新增了积分消费的记录。这一节我们实现订单创建之后进入的列表展示页框架。功能分析兑换商品的订单列表框架我们选择使用tabs,
鸿蒙小林 鸿蒙小林
6小时前
《仿盒马》app开发技术分享-- 待发货兑换订单列表(76)
技术栈Appgalleryconnect开发准备上一节我们实现了兑换订单展示页面的框架,这一节我们要进行兑换订单的展示,在兑换订单提交后,默认的状态是待发货状态,我们用列表的方式展示出来功能分析进入页面时我们就要通过用户的userid去查询对应的订单,获取