积分商城功能表设计结构以及积分功能模块

本文详细介绍了积分商城的数据库表结构设计,包括会员积分记录、积分兑换商品及兑换记录等表的设计,并提供了会员签到与积分换购的具体实现流程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

积分商城功能表结构设计

1、会员积分记录表(qing_score)
来自的用户user_id,签到和兑换记录字段score(签到为正值,兑换为负值),积分信息info

CREATE TABLE `qing_score` (
  `id` int(10) NOT NULL AUTO_INCREMENT,
  `user_id` int(10) NOT NULL,
  `score` int(10) NOT NULL,
  `time` int(10) NOT NULL,
  `info` varchar(30) DEFAULT NULL,
  `source` tinyint(1) NOT NULL DEFAULT '1' COMMENT '1签到2推荐',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=72 DEFAULT CHARSET=utf8 COMMENT='会员积分';

2、积分兑换商品表qing_score_goods
记录兑换的商品需要多少积分,字段score表示需要的积分数量才能兑换的商品

CREATE TABLE `qing_score_goods` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `title` varchar(110) NOT NULL,
  `thumb` varchar(110) NOT NULL,
  `description` varchar(100) DEFAULT NULL,
  `content` text,
  `time` int(10) NOT NULL,
  `score` int(10) NOT NULL,
  `listorder` int(10) NOT NULL DEFAULT '0',
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=5 DEFAULT CHARSET=utf8 COMMENT='积分商品表';

在这里插入图片描述

3、积分换取商品记录表score_record
user_id记录哪个用户,goode_id记录哪个商品,score使用的积分数

CREATE TABLE `qing_score_record` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `score` int(11) NOT NULL,
  `goods_id` int(11) NOT NULL,
  `status` int(11) NOT NULL DEFAULT '1',
  `empress` varchar(100) DEFAULT NULL,
  `time` int(11) NOT NULL,
  `user_id` int(10) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=utf8 COMMENT='积分兑换记录';

在这里插入图片描述

会员签到功能实现

1、检测已登录的该用户今天是否签到,已经签到则今天不再签到
2、今天未签到则插入score积分记录表中

//会员签到
    public function sign(){
    	//验证用户是否登录
        $sessionUserData=$this->isLogin();
        //先检测今天是否签到
        $scoreData=Db::name('score')->where('user_id',$sessionUserData['id'])->whereDay('time')->where('source',1)->order('id desc')->find();
        if(!empty($scoreData)){
            return alert('你今天已经签到了','index',5);
        }

        $res=Db::name('score')->insert([
            'user_id'=>$sessionUserData['id'],
            'time'=>time(),
            'score'=>10,
            'info'=>'签到赚取积分'
        ]);
        if($res){
            return alert('签到成功','index',6);
        }else{
            return alert('签到失败','index',5);
        }
    }

积分换购流程

1、积分商品详情
1)根据id查找积分商品
2)统计该用户积分

实现代码:

public function score_goods_detail(){
        $sessionUserData=$this->isLogin();
        $id=input('id');
       //1、根据id查找积分商品
        $scoreGoodsData=Db::name('score_goods')->find($id);
        if(empty($scoreGoodsData)){
            return alert('没有改商品','score_shop',5);
        }

        //2、统计该用户积分
        $total_socre=Db::name('score')->where('user_id',$sessionUserData['id'])->sum('score');
        return view('',[
            'scoreGoodsData'=>$scoreGoodsData,
            'total_socre'=>$total_socre,
            'left_menu'=>32
        ]); 
    }

2、积分换购
1)根据id查找积分商品
2)统计用户积分并判断该用户积分是否大于积分商品里选中的商品的积分
3)开启异常捕捉,积分换购的积分换取商品记录表score_record插入一条记录,同时插入会员积分记录表负数积分信息

实现代码:

public function score_exchange(){
        $sessionUserData=$this->isLogin();
        $id=input('id');
        //1、根据id查找积分商品
        $scoreGoodsData=Db::name('score_goods')->find($id);
        if(empty($scoreGoodsData)){
            return json(['status'=>-1,'msg'=>'没有该商品']);
        }
        //2、统计用户积分并判断该用户积分是否大于积分商品里选中的商品的积分
        $total_socre=Db::name('score')->where('user_id',$sessionUserData['id'])->sum('score');
        if($total_socre>$scoreGoodsData['score']){
        //3、开启异常捕捉,积分换购的积分换取商品记录表score_record插入一条记录,同时插入会员积分记录表负数积分信息
            try{
                 //积分换购表
                Db::name('score_record')->insert([
                    'user_id'=>$sessionUserData['id'],
                    'score'=>$scoreGoodsData['score'],
                    'time'=>time(),
                    'goods_id'=>$id
                ]);

                Db::name('score')->insert([
                    'user_id'=>$sessionUserData['id'],
                    'score'=>0-$scoreGoodsData['score'],
                    'time'=>time(),
                    'info'=>'商品换购'
                ]);
            }catch (\Exception $e){
                return json(['status'=>-1,'msg'=>'服务端异常,换购失败']);
            }
           

            return json(['status'=>1,'msg'=>'商品换购成功']);

        }else{
            return json(['status'=>-1,'msg'=>'积分不足']);
        }

    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值