《仿盒马》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("请先选择地址")
            }
          })

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

相关文章
|
Rust Shell Linux
CentOS下安装Rust
CentOS下安装Rust
4063 1
|
Web App开发 编解码 监控
【开源视频联动物联网平台】推流,拉流,转发,转码?
【开源视频联动物联网平台】推流,拉流,转发,转码?
1985 2
|
3月前
|
人工智能 自然语言处理 数据可视化
行业观察|Vibe‑Modeling浪潮之下:国产建筑AI的现实路径与取舍思考
海外AEC赛道提出Vibe‑Modeling,把AI建筑的目标锚定在“读懂设计意图、输出可编辑参数化三维几何体”。但国内建筑AI并没有简单复刻这条技术路线。本文结合行业观察与实测,以ADAI作为国内代表样本,对比海外产品技术范式,剖析国内建筑AI选择“图像层意图约束”这条路线背后的业务现实、工程约束,同时讨论从图像渲染走向几何生成,国内赛道需要跨越哪些硬核障碍。
行业观察|Vibe‑Modeling浪潮之下:国产建筑AI的现实路径与取舍思考
|
2月前
|
人工智能 自然语言处理 语音技术
阿里云百炼Token Plan个人版Essential和Standard套餐选哪个?区别有哪些?
阿里云百炼Token Plan个人版:Essential(79元/月,2.55万Credits)适合轻中度使用;Standard(139元/月,4.5万Credits)多1.8倍额度、支持3–4并发Agent,并**额外赠送Harness权益(AgentStudio工具免费额度+后付费88折,不占Credits)**,推荐高频或需智能体协作的用户选择。
|
10月前
|
存储 前端开发 JavaScript
如何避免密钥在前端硬编码?
如何避免密钥在前端硬编码?
1147 154
|
5月前
|
弹性计算 监控 安全
阿里云云防火墙网站服务器安全策略配置完全指南
本文提供了一份完整的阿里云云防火墙网站服务器安全策略配置指南。云防火墙作为云原生SaaS化边界安全产品,可实现互联网边界、VPC边界、NAT边界及主机边界的全方位流量管控。文章从开通服务与授权配置开始,详细拆解了互联网边界防火墙的资产自动接入与防护开启、入侵防御系统的威胁引擎运行模式配置、访问控制策略的匹配原理与配置示例、VPC边界防火墙的自动引流与手动引流模式、NAT边界防火墙的出方向管控、主机边界防火墙的安全组策略同步,以及日志分析的投递开启与查询语法。在网站服务器安全层面,深入阐述了针对Web服务的入方向访问控制策略配置方法、常见Web攻击的IPS拦截规则调优、虚拟补丁的自动更新机制、基
|
6月前
|
JSON BI 调度
Python + 大模型行业资讯自动化摘要流水线完整工程实现方案
Python + 大模型行业资讯自动化摘要流水线完整工程实现方案
|
7月前
|
人工智能 API Python
办公Agent如何真正提效?用数据对比说明:介入前后团队时间消耗变化
这是一份真实办公提效实验报告:20人团队引入办公Agent后,事务与沟通时间骤降56%,人均每周多出9小时有效工作时间。数据揭示——AI不替代人,而是接管填表、催办、写纪要等低价值衔接工作,让人回归核心创造。(239字)
630 7
|
7月前
|
人工智能 搜索推荐 开发者
GEO 技术赋能传统媒体数字化转型:广电场景下的 AI 获客与内容创新实践
生成式引擎优化(GEO)作为 AI 时代全域增长的关键技术,正推动传统媒体与前沿技术的深度融合。本文以湖南广电金鹰卡通与 GEO 技术专家周有贵团队的合作为案例,从技术原理、场景落地、价值共创三个维度,解析 GEO 技术在广电客户精准运营、品牌全域建设、内容生态创新中的应用路径,为传媒行业数字化转型提供可复用的技术实践参考。