签到 和 签到展示

public function signin(){
        $user =  Db::name('user')->field('id,score,sign_days,last_sign')->where('id',$this->auth->id)->find();
        $today = strtotime(date('Y-m-d'));
        if($user['last_sign'] == $today){
            $this->success('今天已经签到过了');
        }else{
            if(($user['last_sign'] == strtotime(date("Y-m-d",time()-86400)))){
                $add = 0;
                $sign_days = $user['sign_days']+1;
                if($sign_days%7 == 1) {
                    $add = getConfig('one');
                }elseif($sign_days%7 == 2) {
                    $add = getConfig('two');
                }elseif($sign_days%7 == 3) {
                    $add = getConfig('three');
                }elseif($sign_days%7 == 4) {
                    $add = getConfig('four');
                }elseif($sign_days%7 == 5) {
                    $add = getConfig('five');
                }elseif($sign_days%7 == 6) {
                    $add = getConfig('six');
                }elseif($sign_days%7 == 0) {
                    $add = getConfig('seven');
                }
                $signin = ['last_sign'=>strtotime(date('Y-m-d')),'sign_days'=>$sign_days,'score'=>$user['score']+$add];
            }else{
                $add = getConfig('one');
                $signin = ['last_sign'=>strtotime(date('Y-m-d')),'sign_days'=>1,'score'=>$user['score']+$add];
            }
            $data = [
                'user_id'    => $this->auth->id,
                'date'       => $today,
                'score'      => $add,
                'createtime' => time(),
                'updatetime' => time()
            ];
            Db::startTrans();
            try{
                $r1 = Db::name('user')->where('id',$this->auth->id)->update($signin);
                $r2 = Db::name('usersign')->insert($data);
                if($r1 !== false && $r2){
                    Db::commit();
                    $this->success('签到成功',$add);
                }else{
                    Db::rollBack();
                    $this->error('签到失败');
                }
            }catch (Exception $e){
                Db::rollBack();
                $this->error('服务器忙,稍后请重试');
            }
        }
    }

    /**
     *notes:签到展示
     *auther:李耀殿<13592627031@163.com>
     *time:2021/12/20 0020下午 5:03
     */

    public function signlist(){
        $user_sign =  Db::name('user')->field('id,score,sign_days,last_sign')->where('id',$this->auth->id)->find();
        $user_sign['count'] = DB::name('usersign')->where('user_id',$this->auth->id)->count();
        $tod = strtotime(date('Y-m-d'));
        if($user_sign['last_sign'] == $tod){
            $user_sign['sign'] = 1;
        }else{
            $user_sign['sign'] = 0;
            $sign_day = $user_sign['sign_days']+1;
            if($sign_day%7 == 1) {
                $user_sign['sign_score'] = getConfig('one');
            }elseif($sign_day%7 == 2) {
                $user_sign['sign_score'] = getConfig('two');
            }elseif($sign_day%7 == 3) {
                $user_sign['sign_score'] = getConfig('three');
            }elseif($sign_day%7 == 4) {
                $user_sign['sign_score'] = getConfig('four');
            }elseif($sign_day%7 == 5) {
                $user_sign['sign_score'] = getConfig('five');
            }elseif($sign_day%7 == 6) {
                $user_sign['sign_score'] = getConfig('six');
            }elseif($sign_day%7 == 0) {
                $user_sign['sign_score'] = getConfig('seven');
            }
        }
        $this->success('查询成功',$user_sign);
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

炒鸡时光机

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值