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

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

技术栈

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("请先选择地址")
            }
          })

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

相关文章
|
22天前
|
人工智能 监控 前端开发
支付宝 AI 出行助手高效研发指南:4 人团队的架构迁移与提效实战
支付宝「AI 出行助手」是一款集成公交、地铁、火车票、机票、打车等多项功能的智能出行产品。
262 21
支付宝 AI 出行助手高效研发指南:4 人团队的架构迁移与提效实战
|
26天前
|
存储 消息中间件 人工智能
Fluss:重新定义实时数据分析与 AI 时代的流式存储
Apache Fluss(孵化中)是新一代流式存储系统,旨在解决传统架构中数据重复复制、高成本与复杂性等问题。它基于 Apache Arrow 构建,支持列式存储、实时更新与高效查询,融合流处理与湖仓架构优势,适用于实时分析、AI 与多模态数据场景。Fluss 提供统一读写、冷热分层与开放生态,已在阿里巴巴大规模落地,助力企业实现低成本、高效率的实时数据处理。
216 25
|
3月前
|
存储 运维 JavaScript
《HarmonyOSNext应用崩溃自救指南:零数据丢失的故障恢复黑科技》
本文详解HarmonyOS Next应用崩溃时如何实现零数据丢失的故障恢复机制,涵盖API差异、核心接口与实战代码,助开发者提升App稳定性和用户体验。
198 65
|
3月前
|
物联网 开发工具
【HarmonyOS】鸿蒙应用蓝牙功能实现 (二)
【HarmonyOS】鸿蒙应用蓝牙功能实现 (二)
115 9
【HarmonyOS】鸿蒙应用蓝牙功能实现 (二)
|
3月前
|
定位技术 开发工具
【HarmonyOS】鸿蒙应用实现调用系统地图导航或路径规划
【HarmonyOS】鸿蒙应用实现调用系统地图导航或路径规划
122 5
【HarmonyOS】鸿蒙应用实现调用系统地图导航或路径规划
|
1月前
|
人工智能 运维 Prometheus
运维再不“聪明点”,迟早被业务拖垮!
运维再不“聪明点”,迟早被业务拖垮!
129 0
|
1月前
|
人工智能 IDE 开发工具
通义灵码 AI IDE使用体验(3)项目优化及bug修复
本文介绍了使用通义灵码 AI IDE进行项目重构与优化的全过程,涵盖页面调整、UI更新、功能修复等内容,并展示了多次优化后的成果与仍存在的问题。
184 0
|
3月前
|
机器人 API 数据安全/隐私保护
微博评论脚本, 新浪微博自动评论机器人,autojs工具开发
该机器人包含登录验证、内容识别、智能回复和频率控制功能,使用AutoJS的控件操作API实现自动化。
|
3月前
|
Java 数据库连接 数据库
Java 组件详细使用方法与封装实战指南
本指南详解Java核心组件使用与封装技巧,涵盖跨平台开发、面向对象编程、多线程、数据库操作等关键内容,并提供工具类、连接池、异常及响应结果的封装方法。结合Spring框架、MyBatis、Spring Boot等主流技术,助你掌握高质量Java组件设计与开发实践。
149 2