《仿盒马》app开发技术分享-- 插入积分信息(65)

鸿蒙小林
• 阅读 6

技术栈

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);

到这里我们就实现了用户积分信息的插入

点赞
收藏
评论区
推荐文章
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 我的积分页(63)
技术栈Appgalleryconnect开发准备上一节我们实现了个人中心页面的业务逻辑优化,成功的在用户登陆退出状态下展示对应的组件内容,这一节我们来实现app中另外一个比较重要的模块积分模块。功能分析因为我们的回收订单是跟回收金积分是绑定的,我们在完成回
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 积分页组件新增(64)
技术栈Appgalleryconnect开发准备上一节我们创建了积分页,给页面添加了标题栏和积分展示的组件。这一节我们继续丰富积分页的内容,添加引导栏,积分明细展示等区域功能分析因为页面的关联不强,我们采用组件引入的方式实现引导栏,同时,在下方继续添加对应
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 积分信息展示(66)
技术栈Appgalleryconnect开发准备上一节我们实现了数据的插入,现在我们需要在tabs中展示我们积分的详细情况了,现在我们只需要从云端进行数据的查询,在页面中拿到数据进行展示就能实现我们想要的效果功能分析数据的展示我们通过用自定义组件的方式实现
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 兑换商品数据插入(67)
技术栈Appgalleryconnect开发准备上一节我们实现了积分列表的展示,我们可以更直观的查看当前用户积分的收支情况,但是现在我们只有积分收入并没有消费的地方,所以现在我们开始着手积分兑换相关的内容。这一节我们来实现积分兑换商品的内容功能分析首先我们
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 兑换列表展示(68)
技术栈Appgalleryconnect开发准备上一节我们创建了积分相关的商品表,我们现在可以针对积分进行更多的操作了,我们首先添加了对应的数据到我们的云数据库中,这一节我们就要把我们存储的数据查询出来展示给用户功能分析首先我们需要在进入页面后进行数据查询
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 兑换提交准备(72)
技术栈Appgalleryconnect开发准备上一节我们实现了地址的选择,商品数据的展示,我们页面中需要的提交的内容还有所欠缺,我们还需要新增一些展示兑换细节的组件,同时在提交之前还需要实现备注功能,我们还要在页面中展示一些积分相关的内容,告知用户积分的
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 订单提交逻辑完善(74)
技术栈Appgalleryconnect开发准备上一节我们实现了兑换订单的提交功能,并且成功的把数据提交到云端,但是我们的业务逻辑并没有完全实现,我们只是把数据提交到了云端,但我们的积分还存在,我们回到积分数据查看的页面也没有消费积分的记录,这一节我们要实
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 兑换订单列表框架(75)
技术栈Appgalleryconnect开发准备上一节我们针对订单兑换的业务逻辑进行了完善,成功的在兑换物品之后修改了用户信息的修改,新增了积分消费的记录。这一节我们实现订单创建之后进入的列表展示页框架。功能分析兑换商品的订单列表框架我们选择使用tabs,
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 逻辑优化第二弹(82)
技术栈Appgalleryconnect开发准备这一节我们继续对我们已有的业务逻辑进行优化,在积分兑换完商品后我们回到积分展示页面发现积分的数量并没有减少,而是重新进入才会发生变化,上一节我们实现商城订单的确认揽收之后继续在待收货页面实现确认揽收按钮的业务
鸿蒙小林 鸿蒙小林
17小时前
《仿盒马》app开发技术分享-- 逻辑优化第三弹(83)
技术栈Appgalleryconnect开发准备现在我们的app功能已经趋近完善,bug和缺失的细节也越来越少了,我们继续对app进行优化,首先是我们的积分页面,我们只实现了全部的积分展示内容,对收入和支出的积分明细并没有进行展示,这里我们要实现一下,然后