《仿盒马》app开发技术分享-- 兑换订单提交(73)

简介: 上一节我们实现了兑换提交前的准备页面,向用户展示了兑换相关的所有信息,这一节我们就可以实现兑换订单的提交了

## 技术栈

Appgallery connect

开发准备

上一节我们实现了兑换提交前的准备页面,向用户展示了兑换相关的所有信息,这一节我们就可以实现兑换订单的提交了

功能分析

订单提交我们需要创建对应的兑换商品订单提交信息表,我们需要把地址,商品信息,积分,备注,订单状态,订单创建时间,订单取消时间,订完完成时间等信息都进行存储

代码实现

首先我们创建兑换订单表

{
   
  "objectTypeName": "points_order_info",
  "fields": [
    {
   "fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},
    {
   "fieldName": "user_id", "fieldType": "String"},
    {
   "fieldName": "order_code", "fieldType": "String"},
    {
   "fieldName": "name", "fieldType": "String"},
    {
   "fieldName": "points", "fieldType": "Double"},
    {
   "fieldName": "msg", "fieldType": "String"},
    {
   "fieldName": "amount", "fieldType": "Integer"},
    {
   "fieldName": "nike_name", "fieldType": "String"},
    {
   "fieldName": "address", "fieldType": "String"},
    {
   "fieldName": "phone", "fieldType": "String"},
    {
   "fieldName": "crete_time", "fieldType": "String"},
    {
   "fieldName": "cancel_time", "fieldType": "String"},
    {
   "fieldName": "over_time", "fieldType": "String"},
    {
   "fieldName": "success_time", "fieldType": "String"},
    {
   "fieldName": "order_type", "fieldType": "Integer"}


  ],
  "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"]}
  ]
}

实体


class PointsOrderInfo {
   
    id: number;
    user_id: string;
    order_code: string;
    name: string;
    points: number;
    msg: string;
    amount: number;
    nike_name: string;
    address: string;
    phone: string;
    crete_time: string;
    cancel_time: string;
    over_time: string;
    success_time: string;
    order_type: number;

    constructor() {
   
    }

    setId(id: number): void {
   
        this.id = id;
    }

    getId(): number  {
   
        return this.id;
    }

    setUser_id(user_id: string): void {
   
        this.user_id = user_id;
    }

    getUser_id(): string  {
   
        return this.user_id;
    }

    setOrder_code(order_code: string): void {
   
        this.order_code = order_code;
    }

    getOrder_code(): string  {
   
        return this.order_code;
    }

    setName(name: string): void {
   
        this.name = name;
    }

    getName(): string  {
   
        return this.name;
    }

    setPoints(points: number): void {
   
        this.points = points;
    }

    getPoints(): number  {
   
        return this.points;
    }

    setMsg(msg: string): void {
   
        this.msg = msg;
    }

    getMsg(): string  {
   
        return this.msg;
    }

    setAmount(amount: number): void {
   
        this.amount = amount;
    }

    getAmount(): number  {
   
        return this.amount;
    }

    setNike_name(nike_name: string): void {
   
        this.nike_name = nike_name;
    }

    getNike_name(): string  {
   
        return this.nike_name;
    }

    setAddress(address: string): void {
   
        this.address = address;
    }

    getAddress(): string  {
   
        return this.address;
    }

    setPhone(phone: string): void {
   
        this.phone = phone;
    }

    getPhone(): string  {
   
        return this.phone;
    }

    setCrete_time(crete_time: string): void {
   
        this.crete_time = crete_time;
    }

    getCrete_time(): string  {
   
        return this.crete_time;
    }

    setCancel_time(cancel_time: string): void {
   
        this.cancel_time = cancel_time;
    }

    getCancel_time(): string  {
   
        return this.cancel_time;
    }

    setOver_time(over_time: string): void {
   
        this.over_time = over_time;
    }

    getOver_time(): string  {
   
        return this.over_time;
    }

    setSuccess_time(success_time: string): void {
   
        this.success_time = success_time;
    }

    getSuccess_time(): string  {
   
        return this.success_time;
    }

    setOrder_type(order_type: number): void {
   
        this.order_type = order_type;
    }

    getOrder_type(): number  {
   
        return this.order_type;
    }

}

export {
    PointsOrderInfo };

db类

import {
    cloudDatabase } from '@kit.CloudFoundationKit';

class points_order_info extends cloudDatabase.DatabaseObject {
   
  public id: number;
  public user_id: string;
  public order_code: string;
  public name: string;
  public points: number;
  public msg: string;
  public amount: number;
  public nike_name: string;
  public address: string;
  public phone: string;
  public crete_time: string;
  public cancel_time: string;
  public over_time: string;
  public success_time: string;
  public order_type: number;

  public naturalbase_ClassName(): string {
   
    return 'points_order_info';
  }
}

export {
    points_order_info };

然后我们开始提交数据

   Text("确认兑换")
            .fontColor(Color.White)
            .padding(10)
            .borderRadius(10)
            .backgroundColor("#d81e06")
            .fontSize(14)
            .onClick(async ()=>{
   
              if (this.addressInfo!=null) {
   
                let order=new points_order_info()
                order.id=Math.floor(Math.random() * 1000000)
                order.user_id=String(this.user!.user_id)
                order.order_code=Math.floor(Math.random() * 1000000)+"1013"
                order.url=this.pointsProduct!.url
                order.name=this.pointsProduct!.name
                order.points=this.pointsProduct!.points
                if (this.remark!='') {
   
                  order.msg=this.remark
                }else {
   
                  order.msg="无"
                }
                order.amount=1
                order.nike_name=this.addressInfo.nikeName
                order.address=this.addressInfo.address
                order.phone=this.addressInfo.phone
                order.crete_time=this.thisTime()
                let num = await databaseZone.upsert(order);
                if (num>0) {
   
                  showToast("兑换成功")
                }
              }else {
   
                showToast("请选择地址")
              }
            })

到这里我们的兑换订单提交就完成了

相关文章
|
2天前
|
监控 网络协议 算法
2026年起SSL证书有效期逐年缩短:企业如何避免“续期风暴”!
SSL证书有效期将从2026年起分三阶段逐步缩短至47天,人工续期难以为继。阿里云“WoSign SSL证书+自动化服务”,支持域名监控、自动托管、云产品/服务器一键部署及智能提醒,助力企业高效应对高频续期挑战。
8071 2
|
11天前
|
域名解析 人工智能 Linux
|
21天前
|
Linux Go 开发工具
手机上跑 DeepSeek 智能体:开源安卓客户端 DSH Go 安装与使用指南
DSH Go 是一款开源安卓客户端,将 DeepSeek Harness 智能体引擎装进手机:免 Root、免 Termux,一键安装即用;支持本机运行(内置 Ubuntu+Node.js)或远程接管电脑会话;具备插话打断、过程折叠、屏幕操控、端到端加密分享等特色功能,真正实现智能体“口袋化”。
18566 64
|
19天前
|
人工智能
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
进不去 Antigravity 或 Gemini,提示所在地区不可用?三步查清 Google 账号关联地区、官方更正表单理由选法与改区注意事项。
Google 提示「所在地区不可用」?进不去 Antigravity 或 Gemini,先查账号这个设置
|
5天前
|
人工智能 安全 网络安全
|
10天前
|
Linux API iOS开发
【DSH】DeepSeek Harness新手保姆教程(下载+安装+配置+使用,2026最新实测)
DeepSeek Harness(dsh)是 DeepSeek AI 开源的智能体框架,秉持“一切皆插件”理念,支持读文件、改代码、执行命令、处理表格等自动化任务;免费开源,兼容 Win/macOS,需配 API 密钥使用。(239字)
1507 5
|
8天前
|
云安全 数据采集 人工智能
|
16天前
|
人工智能 开发工具 开发者
2026最新codex下载安装保姆级使用教程(下载+安装+登录+使用,含所有历史版本)
Codex 是 OpenAI 推出的开源 AI 编程智能体,跑在本地终端和桌面客户端里,能读懂整个代码仓库,一句自然语言就能让它改代码、执行命令、跑测试、修 Bug,支持 Windows、macOS、Linux 三大平台。本文把 Codex下载、安装、登录、汉化、基础使用一次讲全,并整理了国内用户最常踩的坑,跟着做 10 分钟就能跑起来。
2652 8
|
9天前
|
Web App开发 缓存 安全
巨魔商店 TrollStore 安装教程(2026):免电脑在线安装与全机型安装器矩阵_iOS巨魔安装
巨魔商店(TrollStore)是iOS 14–17.0(特定版本)的永久签名工具,无需越狱,利用CoreTrust漏洞实现IPA签名长期有效,彻底告别7天重签。支持免电脑在线安装(TrollHelperOTA),适配多机型/系统组合,开源免费,安全可控。(239字)
2152 0