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

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

相关文章
|
3天前
|
存储
《仿盒马》app开发技术分享--未完成订单列表展示逻辑优化(61)
上一节我们实现订单与优惠券的联合提交时,我去到订单列表页面查看生成的订单信息,发现现在的订单从信息展示到价格计算全都是有问题的。所以紧急的把对应的问题修改一下。
94 70
|
28天前
|
存储 人工智能 Kubernetes
AI 场景深度优化!K8s 集群 OSSFS 2.0 存储卷全面升级,高效访问 OSS 数据
阿里云对象存储OSS是一款海量、安全、低成本、高可靠的云存储服务,是用户在云上存储的高性价比选择…
|
24天前
|
人工智能 Cloud Native 数据管理
邀您参加 KubeCon China 2025 分论坛 | 阿里云 AI 基础设施技术沙龙
KubeCon + CloudNativeCon China 2025 将于6月10-11日在香港合和酒店举办,由CNCF与Linux基金会联合主办。阿里云开发者将在大会上分享多个技术议题,涵盖AI模型分发、Argo工作流、Fluid数据管理等领域。大会前还有阿里云AI基础设施技术沙龙,聚焦AI基础设施及云原生技术实战经验。欢迎扫码报名参与!
246 64
|
25天前
|
tengine 应用服务中间件 网络安全
Debina操作系统如何安装Tengine并开启HTTP2
本指南介绍了Tengine的安装与配置方法。首先下载并解压Tengine源码包,确保依赖项已安装(如pcre、zlib和openssl)。接着运行`./configure`命令进行配置,建议添加`--with-http_v2_module`以启用HTTP/2支持。完成配置后执行`make`编译,再通过`sudo make install`完成安装。为方便使用,可创建符号链接指向Tengine二进制文件。
|
20天前
|
JavaScript Linux 内存技术
Debian 11系统下Node.js版本更新方法
Debian 11更新Node.js主要就是这三种方式,无论你是初涉其中的新手还是找寻挑战的专家,总有一种方式能满足你的需求。现在,你已经是这个
159 80
|
25天前
|
容器
50.[HarmonyOS NEXT RelativeContainer案例七] 均匀分布的底部导航栏:水平链布局技术详解
底部导航栏是移动应用中最常见的导航元素之一,它通常包含多个均匀分布的图标或按钮,用于在应用的主要功能之间切换。在HarmonyOS NEXT中,RelativeContainer组件提供了强大的链式布局(Chain)功能,能够轻松实现元素的均匀分布,非常适合底部导航栏的实现。本教程将详细讲解如何利用RelativeContainer的水平链布局功能实现一个美观、均匀分布的底部导航栏。
125 72
|
25天前
|
容器
49.[HarmonyOS NEXT RelativeContainer案例六] 智能屏障布局:打造自适应聊天气泡界面
在现代移动应用开发中,聊天界面是最常见的交互场景之一。一个优秀的聊天界面需要能够适应不同长度的消息内容,保持布局的一致性和美观性。HarmonyOS NEXT的RelativeContainer组件提供了强大的屏障(Barrier)功能,能够根据内容动态调整布局,非常适合实现聊天气泡这类需要自适应内容边界的UI元素。本教程将详细讲解如何利用RelativeContainer的屏障功能实现一个自适应的聊天气泡界面。
120 70
|
15天前
|
安全 网络虚拟化 数据安全/隐私保护
配置小型网络WLAN基本业务示例
本文介绍了通过AC与AP直连组网实现企业分支机构移动办公的WLAN基本业务配置方案。需求包括提供名为“WiFi”的无线网络,分配192.168.1.0/24网段IP地址给工作人员,采用直连二层组网方式,AC作为DHCP服务器,并使用隧道转发业务数据。配置步骤涵盖AP与AC间CAPWAP报文传输、DHCP服务设置、AP上线及WLAN业务参数配置等,最终确保STA成功接入无线网络“WiFi”。
配置小型网络WLAN基本业务示例
|
25天前
|
应用服务中间件 nginx
Debina操作系统如何安装OpenResty并开启HTTP2
本文介绍了在Debian服务器上安装OpenResty 1.25.3.2并启用HTTP/2模块的详细步骤。包括下载解压源码、安装依赖项、配置编译参数(指定安装路径与启用HTTP/2模块)、编译安装,以及创建符号链接方便使用。最后提供启动、停止和重新加载配置的命令,并提醒注意安全组设置以确保服务正常访问。

热门文章

最新文章

OSZAR »