UserSign.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. <?php
  2. namespace App\Modules\User\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class UserSign extends Model
  5. {
  6. protected $table = 'user_sign';
  7. protected $fillable = ['uid','price','day','sign_time'];
  8. public function setCurrentTable($time=''){
  9. if($time){
  10. $this->setTable('user_sign'.$time);
  11. }else{
  12. $this->setTable('user_sign');
  13. }
  14. }
  15. /**
  16. * 用户是否已签到
  17. * @param $uid
  18. * @param $day
  19. * @return mixed
  20. */
  21. public static function isSign($uid,$day){
  22. return self::where('uid',$uid)->where('day',$day)->first();
  23. }
  24. /**
  25. * 签到
  26. * @param $uid
  27. * @param $day
  28. * @return mixed
  29. */
  30. public static function sign($uid,$day,$fee){
  31. $data = ['uid'=>$uid,'price'=>$fee,'day'=>$day,'sign_time'=>time()];
  32. return self::create($data);
  33. }
  34. /**
  35. * 用户签到记录
  36. */
  37. public static function getUserSignRecord($uid){
  38. return self::where('uid',$uid)->where('day','<',date('Y-m-d'))->select('price','sign_time')->orderBy('sign_time','desc')->paginate();
  39. }
  40. }