TempsUserSign.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. <?php
  2. namespace App\Modules\User\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class TempsUserSign extends Model
  5. {
  6. protected $table = 'temps_user_sign';
  7. protected $fillable = ['uid','price','day','sign_time'];
  8. /**
  9. * 用户是否已签到
  10. * @param $uid
  11. * @param $day
  12. * @return mixed
  13. */
  14. public static function isSign($uid,$day){
  15. return self::where('uid',$uid)->where('day',$day)->first();
  16. }
  17. /**
  18. * 删除N天前的数据,保留热数据
  19. */
  20. static function deleteTempsUserSignByTime($end_time)
  21. {
  22. while (true)
  23. {
  24. $affect_rows = self::where('day','<=',$end_time)->limit(50000)->delete();
  25. if(!$affect_rows) break;
  26. sleep(1);
  27. }
  28. return true;
  29. //return self::where('day','<=',$end_time)->delete();
  30. }
  31. /**
  32. * 签到
  33. * @param $uid
  34. * @param $day
  35. * @return mixed
  36. */
  37. public static function sign($uid,$day,$fee){
  38. $data = ['uid'=>$uid,'price'=>$fee,'day'=>$day,'sign_time'=>time()];
  39. return self::create($data);
  40. }
  41. /**
  42. * 用户签到记录
  43. */
  44. public static function getUserSignRecord($uid){
  45. return self::where('uid',$uid)->select('price','sign_time')->orderBy('sign_time','desc')->paginate();
  46. }
  47. }