<?php

namespace App\Modules\User\Models;

use Illuminate\Database\Eloquent\Model;

class UserSign extends Model
{
    protected $table = 'user_sign';
    protected $fillable = ['uid','price','day','sign_time'];

    public function setCurrentTable($time=''){
        if($time == '201906'){
            $time = '';
        }
        if($time){
            $this->setTable('user_sign'.$time);
        }else{
            $this->setTable('user_sign');
        }
    }
    
    /**
     * 用户是否已签到
     * @param $uid
     * @param $day
     * @return mixed
     */
    public static function isSign($uid,$day){
        return self::where('uid',$uid)->where('day',$day)->first();
    }

    /**
     * 签到
     * @param $uid
     * @param $day
     * @return mixed
     */
    public static function sign($uid,$day,$fee){
        $data = ['uid'=>$uid,'price'=>$fee,'day'=>$day,'sign_time'=>time()];
        return self::create($data);
    }

    /**
     * 用户签到记录
     */
    public static function getUserSignRecord($uid){
        return self::where('uid',$uid)->select('price','sign_time')->orderBy('sign_time','desc')->paginate();
    }
}
