Skip to content

loyalty ​

会员积分

概述 ​

k.commerce.loyalty 提供会员积分相关操作,包括积分获取、兑换、会员等级管理等。

会员创建

会员需要手动到 Kooboo 后台创建:电商 → 会员(默认在隐藏目录中)→ 创建会员

info() ​

获取顾客的会员积分信息。

ts
k.api.get(() => {
    const customer = k.commerce.customer.getByEmail('test@example.com')
    return k.commerce.loyalty.info(customer.id)
})

参数:

参数类型必填说明
customerIdstring是顾客ID

返回: LoyaltyInfo

changeMembership() ​

变更会员等级。

ts
k.api.post(() => {
    const customer = k.commerce.customer.getByEmail('test@example.com')
    const memberships = k.commerce.membership.list()
    if (memberships && memberships.length > 0) {
        k.commerce.loyalty.changeMembership(customer.id, memberships[0].id)
    }
    return 'change success'
})

参数:

参数类型必填说明
customerIdstring是顾客ID
membershipIdstring是会员ID

返回: void

earnPoints() ​

赚取积分。

ts
k.api.post(() => {
    const customer = k.commerce.customer.getByEmail('test@example.com')
    k.commerce.loyalty.earnPoints(customer.id, 100, '购物奖励')
    return 'earn success'
})

参数:

参数类型必填说明
customerIdstring是顾客ID
pointsnumber是赚取的积分数量
descriptionstring否积分描述

返回: void

redeemPoints() ​

消费积分。

ts
k.api.post(() => {
    const customer = k.commerce.customer.getByEmail('test@example.com')
    k.commerce.loyalty.redeemPoints(customer.id, 50, '积分兑换')
    return 'redeem success'
})

参数:

参数类型必填说明
customerIdstring是顾客ID
pointsnumber是消费的积分数量
descriptionstring否积分描述

返回: void

points() ​

获取顾客的积分记录。

ts
k.api.get(() => {
    const customer = k.commerce.customer.getByEmail('test@example.com')
    return k.commerce.loyalty.points(customer.id, {
        pageIndex: 1,
        pageSize: 20
    })
})

参数:

参数类型必填说明
customerIdstring是顾客ID
queryobject否查询参数
query.pageIndexnumber否页码,默认 1
query.pageSizenumber否每页条数,默认 10

返回:

ts
{
    list: CustomerPointModel[];
    count: number;
    pageIndex: number;
    pageSize: number;
}

memberships() ​

获取会员信息列表。

参数:无。

ts
k.api.get(() => {
    const memberships = k.commerce.loyalty.memberships()
    return { count: memberships.length, items: memberships }
})

返回: Membership[]

renewMembership() ​

续费会员。

ts
k.api.post(() => {
    const customer = k.commerce.customer.getByEmail('test@example.com')
    k.commerce.loyalty.renewMembership(customer.id)
    return 'renew success'
})

参数:

参数类型必填说明
customerIdstring是顾客ID

返回: void

结构 ​

LoyaltyInfo 属性 ​

属性说明类型
Points会员积分number
MembershipStatus会员状态MembershipStatus

MembershipStatus 属性 ​

属性说明类型
Membership会员信息Membership
StartedAt会员开始时间string
EndAt会员结束时间string
Active会员是否有效boolean

Membership 属性 ​

属性说明类型
id会员IDstring
name会员名称string
description会员描述string
price会员价格number
duration会员时长number
durationUnit会员时长单位"Year" | "Month" | "Day" | "Week"
priority会员优先级number
condition升级条件Condition[]
allowAutoUpgrade是否允许自动升级boolean
allowPurchase是否允许购买boolean
customData自定义数据{key: value}[] | null
createdAt创建时间string
updatedAt更新时间string

Condition 属性 ​

属性说明类型
isAny任一条件满足即可boolean
items条件项列表ConditionItem[]

ConditionItem 属性 ​

属性说明类型
option条件选项string
method条件方法string
value条件值string

CustomerPointModel 属性 ​

属性说明类型
customerId客户IDstring
points积分number
createdAt创建时间string
type类型string
description描述string
key键string
disabled是否禁用boolean

相关文档 ​