Harmonyos5应用开发实战——订单系统响应模型设计(part2)

109 阅读2分钟
3. 系统信息响应模型

GetHmSystemResp 类继承自 BaseResponse,用于存储系统信息,包含 storeIdstoreType 两个属性。

export class GetHmSystemResp extends BaseResponse {
  storeId: string
  // 商户类型 1 桌号点餐  2 取餐码点餐
  storeType: number

  constructor(status: number, msg: string, storeId: string, storeType: number) {
    super(status, msg)
    this.storeId = storeId
    this.storeType = storeType
  }
}
4. 用户信息响应模型

GetUserInfoResp 类同样继承自 BaseResponse,用于存储用户信息,包含用户的基本信息、积分、钱包等。

export class GetUserInfoResp extends BaseResponse {
  id: string
  name: string
  img: string
  openId: string
  unionId: string
  storeId: string
  totalScore: string
  wallet: string
  userTel?: string

  constructor(status: number, msg: string, id: string, name: string, img: string, openId: string,
    storeId: string, totalScore: string, wallet: string, unionId: string) {
    super(status, msg)
    this.id = id
    this.name = name
    this.img = img
    this.openId = openId
    this.storeId = storeId
    this.totalScore = totalScore
    this.wallet = wallet
    this.unionId = unionId
  }
}
5. 店铺信息响应模型

GetStoreInfoResp 类用于存储店铺信息,包含店铺详情、优惠信息和店铺设置。

export class GetStoreInfoResp {
  store: StoreInfo
  reduction: Array<Reduction>
  storeSet: StoreSet

  constructor(store: StoreInfo, reduction: Array<Reduction>, storeSet: StoreSet) {
    this.store = store
    this.reduction = reduction
    this.storeSet = storeSet
  }
}
6. 订单相关响应模型

包括 OrderModelGoodsOfOrderOrderTableGetMyOrderResp 等类,用于存储订单信息、订单商品信息、订单桌号信息和订单列表信息。

export class OrderModel {
  id?: string
  orderNum?: string
  time?: string
  payTime?: string
  money?: string
  reductionMoney?: number
  boxMoney?: string
  mjMoney?: string
  xyhMoney?: string
  note?: string
  payType?: string
  orderType?: string
  tableware?: string
  yhqMoney?: string
  couponId?: string
  dnState?: string
  oid?: string
  tel?: string
  name?: string
  address?: string
  lat?: string
  lng?: string
}

@Observed
export class GoodsOfOrder {
  id: string = ''
  logo: string = ''
  money: string = ''
  money2: string = ''
  discount: string = ''
  name: string = ''
  num: string = ''
  isMust: string = ''
  specType: string = ''
  spec: string = ''
  combination?: PackageSpec[]
}

export class OrderTable {
  id: string = ''
  name: string = ''
  typeName: string = ''
}

// 订单列表
@Observed
export class GetMyOrderResp {
  order?: OrderModel
  num?: number
  good?: Array<GoodsOfOrder>
  table?: OrderTable
}
7. 优惠券相关响应模型

CouponRespMyCouponResp 类用于存储优惠券信息和用户的优惠券信息。

//优惠券
export class CouponResp {
  id: string = ''
  // 优惠券名称
  name: string = ''
  // 描述
  desc: Array<string> = []
  // 优惠开始时间
  startTime: string = ''
  // 优惠结束时间
  endTime: string = ''
  // 满减额
  full: string = ''
  // 优惠金额
  reduce: string = ''
  // 类型:1 优惠券 2 红包
  type: string = ''
  // 总数量
  num: string = ''
  // 剩余数量
  stock: string = ''
  // 优惠券适用范围:1 外卖 2 店内 3 店内和外卖
  couponsType: string = ''
  state: number = 0

  constructor(id: string, name: string, desc: Array<string>, startTime: string, endTime: string, full: string,
    reduce: string, type: string, num: string, stock: string, couponsType: string, state: number) {
    this.id = id
    this.name = name
    this.desc = desc
    this.startTime = startTime
    this.endTime = endTime
    this.full = full
    this.reduce = reduce
    this.type = type
    this.num = num
    this.stock = stock
    this.couponsType = couponsType
    this.state = state
  }
}

//我的优惠券
export class MyCouponResp {
  id: string = ''
  couponId: string = ''
  state: string = ''
  type: string = ''
  full: string = ''
  reduce: string = ''
  name: string = ''
  //店内、外卖和店内
  couponType: string = ''
  endTime: string = ''
  desc: Array<string> = []
}

通过以上核心功能的实现,在HarmonyOS 5应用开发中为订单系统的数据交互和处理提供了标准化的响应模型,提高了代码的可维护性和可扩展性。