SmartPushUserSign.php 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. <?php
  2. namespace App\Modules\User\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class SmartPushUserSign extends Model
  5. {
  6. protected $table = 'smart_push_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 deleteSmartPushUserSignByTime($end_time)
  21. {
  22. $max_id = self::where('day','<=',$end_time)->max('id');
  23. $min_id = self::where('day','<=',$end_time)->min('id');
  24. if($max_id)
  25. {
  26. while (true)
  27. {
  28. $t_max_id = min($min_id + 50000, $max_id);
  29. $affect_rows = self::where('id','>=',$min_id)->where('id','<=',$t_max_id)->delete();
  30. $min_id = $t_max_id;
  31. if(!$affect_rows) break;
  32. sleep(1);
  33. }
  34. }
  35. return true;
  36. }
  37. /**
  38. * 签到
  39. * @param $uid
  40. * @param $day
  41. * @return mixed
  42. */
  43. public static function sign($uid,$day,$fee){
  44. $data = ['uid'=>$uid,'price'=>$fee,'day'=>$day,'sign_time'=>time()];
  45. return self::create($data);
  46. }
  47. /**
  48. * 用户签到记录
  49. */
  50. public static function getUserSignRecord($uid){
  51. return self::where('uid',$uid)->select('price','sign_time')->orderBy('sign_time','desc')->paginate();
  52. }
  53. }