SmartPushUserSign.php 1.6 KB

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