《仿盒马》app开发技术分享-- 插入积分信息(65)
2025-06-28 13:31:07
106次阅读
0个评论
技术栈
Appgallery connect
开发准备
上一节我们实现了积分页面的大概框架,那么现在我们开始进行数据的填充和查询,积分相关的内容现在之后当回收订单结算之后才会进行积分数据的添加,那我们想查询出对应的积分数据,还需要新增一张积分信息表
功能分析
现在积分相关的有订单结算以及后续的积分兑换功能,我们先实现订单结算的积分新增以及用户信息表的积分总额计算。 首先在回收单待完成页面点击确认按钮时进行数据的添加,我们这里要用type去区分积分数据的状态,状态分为收入和支出。然后我们修改userinfo的积分信息,在积分列表全部选项里查询出积分的数据在list列表中进行展示
代码实现
首先我们创建对应的表、实体、db类
{
"objectTypeName": "points_info",
"fields": [
{"fieldName": "id", "fieldType": "Integer", "notNull": true, "belongPrimaryKey": true},
{"fieldName": "user_id", "fieldType": "Integer", "notNull": true, "defaultValue": 0},
{"fieldName": "points", "fieldType": "String"},
{"fieldName": "create_time", "fieldType": "String"},
{"fieldName": "points_type", "fieldType": "String"},
{"fieldName": "address", "fieldType": "String"},
{"fieldName": "year", "fieldType": "String"},
{"fieldName": "month", "fieldType": "String"},
{"fieldName": "day", "fieldType": "String"},
{"fieldName": "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"]}
]
}
class PointsInfo {
id: number;
user_id: number = 0;
points: string;
create_time: string;
points_type: string;
address: string;
year: string;
month: string;
day: string;
time: string;
constructor() {
}
setId(id: number): void {
this.id = id;
}
getId(): number {
return this.id;
}
setUser_id(user_id: number): void {
this.user_id = user_id;
}
getUser_id(): number {
return this.user_id;
}
setPoints(points: string): void {
this.points = points;
}
getPoints(): string {
return this.points;
}
setCreate_time(create_time: string): void {
this.create_time = create_time;
}
getCreate_time(): string {
return this.create_time;
}
setPoints_type(points_type: string): void {
this.points_type = points_type;
}
getPoints_type(): string {
return this.points_type;
}
setAddress(address: string): void {
this.address = address;
}
getAddress(): string {
return this.address;
}
setYear(year: string): void {
this.year = year;
}
getYear(): string {
return this.year;
}
setMonth(month: string): void {
this.month = month;
}
getMonth(): string {
return this.month;
}
setDay(day: string): void {
this.day = day;
}
getDay(): string {
return this.day;
}
setTime(time: string): void {
this.time = time;
}
getTime(): string {
return this.time;
}
}
export { PointsInfo };
import { cloudDatabase } from '@kit.CloudFoundationKit';
class points_info extends cloudDatabase.DatabaseObject {
public id: number;
public user_id = 0;
public points: string;
public create_time: string;
public points_type: string;
public address: string;
public year: string;
public month: string;
public day: string;
public time: string;
public naturalbase_ClassName(): string {
return 'points_info';
}
}
export { points_info };
在订单确认完成按钮处我们实现云数据库数据新增
let points=new points_info()
points.id=Math.floor(Math.random() * 1000000)
points.user_id=this.user!.user_id
points.points=String(item.money)
points.points_type='0'
points.address='客户端下单奖励'
points.year=this.year
points.month=this.month
points.day=this.day
points.time=this.time
points.create_time=this.year+"-"+this.month+"-"+this.day+" "+this.time
let points_nums = await databaseZone.upsert(money);
用户账号内的总积分数修改
let userData=new user_info()
userData.id=this.userInfo!.id
userData.user_id=this.userInfo!.user_id
userData.sex=this.userInfo!.sex
userData.bind_phone=this.userInfo!.bind_phone
userData.create_time=this.userInfo!.create_time
userData.nickname=this.userInfo!.nickname
userData.head_img=this.userInfo!.head_img
if (this.userInfo?.money!=null) {
userData.money=this.userInfo!.money+item.money
}else {
userData.money=item.money
}
if (this.userInfo?.points!=null) {
userData.points=this.userInfo!.points+item.integral
}else {
userData.points=item.integral
}
let s= await databaseZone.upsert(userData);
到这里我们就实现了用户积分信息的插入
00
- 0回答
- 0粉丝
- 0关注
相关话题
- 《仿盒马》app开发技术分享-- 积分信息展示(66)
- 《仿盒马》app开发技术分享-- 我的积分页(63)
- 《仿盒马》app开发技术分享-- 积分页组件新增(64)
- 《仿盒马》app开发技术分享-- 兑换商品数据插入(67)
- 《仿盒马》app开发技术分享-- 个人信息页(23)
- 《仿盒马》app开发技术分享-- 金刚区(3)
- 《仿盒马》app开发技术分享-- 首页banner(6)
- 《仿盒马》app开发技术分享-- 定位获取(25)
- 《仿盒马》app开发技术分享-- 地图选点(27)
- 《仿盒马》app开发技术分享-- 新增地址(28)
- 《仿盒马》app开发技术分享-- 账号注销(86)
- 《仿盒马》app开发技术分享-- 首页模块配置(4)
- 《仿盒马》app开发技术分享-- 首页活动配置(5)
- 《仿盒马》app开发技术分享-- 分类左侧列表(17)
- 《仿盒马》app开发技术分享-- 商品规格弹窗(11)