UserBans.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. /**
  18. * @param $userId
  19. * @param $type
  20. * @param $adminId
  21. * @param $endTime
  22. * @return bool
  23. * 用户封禁
  24. */
  25. public static function create($userId, $type, $adminId = 0, $endTime = 0)
  26. {
  27. $model = new self();
  28. $model->user_id = $userId;
  29. $model->type = $type;
  30. $model->admin_id = $adminId;
  31. $model->end_time = $endTime;
  32. return $model->save();
  33. }
  34. /**
  35. * @param $userId
  36. * @param $type
  37. * @return null
  38. * 获取封禁信息
  39. */
  40. public static function getRow($userId, $type)
  41. {
  42. $query = self::query();
  43. $query->where(['user_id' => $userId, 'type' => $type]);
  44. if ($type == 1) {
  45. $query->where('end_time', '>', time());
  46. }
  47. return $query->first();
  48. }
  49. }