UserBans.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Module\Ulogic\Models;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. /**
  7. * 用户封禁记录
  8. * *
  9. * * field start
  10. * field end
  11. */
  12. class UserBans extends Model
  13. {
  14. use HasDateTimeFormatter;
  15. use SoftDeletes;
  16. protected $table = 'user_bans';
  17. // attrlist start
  18. protected $fillable = [
  19. ];
  20. // attrlist end
  21. /**
  22. * @param $userId
  23. * @param $type
  24. * @param $adminId
  25. * @param $endTime
  26. * @return bool
  27. * 用户封禁
  28. */
  29. public static function create($userId, $type, $adminId = 0, $endTime = 0)
  30. {
  31. $model = new self();
  32. $model->user_id = $userId;
  33. $model->type = $type;
  34. $model->admin_id = $adminId;
  35. $model->end_time = $endTime;
  36. return $model->save();
  37. }
  38. /**
  39. * @param $userId
  40. * @param $type
  41. * @return null
  42. * 获取封禁信息
  43. */
  44. public static function getRow($userId, $type)
  45. {
  46. $query = self::query();
  47. $query->where(['user_id' => $userId, 'type' => $type]);
  48. if ($type == 1) {
  49. $query->where('end_time', '>', time());
  50. }
  51. return $query->first();
  52. }
  53. }