Integration mall function table design structure and integration function module

The structure design of the points mall function table

1.
The user user_id from which the member score record form (qing_score) comes from, the check-in and redemption record field score (check-in is a positive value, the conversion is a negative value), the point information 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. The points redemption product table qing_score_goods
records how many points are needed for the goods to be redeemed, and the field score indicates the number of points required to redeem the goods

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='积分商品表';

Insert picture description here

3. The product record table score_record
user_id records which user, which product goode_id records, and the number of points used by 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='积分兑换记录';

Insert picture description here

Member sign-in function realization

1. Detect whether the logged-in user has signed in today, and if he has already signed in, he will not sign
in today. 2. If he has not signed in today, he will insert it into the score record table.

//会员签到
    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);
        }
    }

Points redemption process

1. Details of points products
1) Find points products according to id
2) Count the user points

Implementation code:

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. Point redemption
1) Find points products based on id
2) Count user points and determine whether the user points are greater than the points of the selected product in the points product
3) Turn on exception capture, and insert a record in the score_record table for points redeemed for points redemption. At the same time, insert the negative points information of the member points record table

Implementation code:

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'=>'积分不足']);
        }

    }

Guess you like

Origin blog.csdn.net/weixin_39218464/article/details/114271778