UserBans.php 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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. * * @property int $id 主键id
  11. * * @property int $user_id 用户id
  12. * * @property int $type 封禁类型
  13. * * @property int $admin_id 操作人
  14. * * @property int $end_time 封禁结束时间
  15. * * @property string $created_at
  16. * * @property string $updated_at
  17. * * @property string $deleted_at
  18. * * field end
  19. */
  20. class UserBans extends Model
  21. {
  22. use HasDateTimeFormatter;
  23. use SoftDeletes;
  24. protected $table = 'user_bans';
  25. /**
  26. * @param $userId
  27. * @param $type
  28. * @param $adminId
  29. * @param $endTime
  30. * @return bool
  31. * 用户封禁
  32. */
  33. public static function create($userId, $type, $adminId = 0, $endTime = 0)
  34. {
  35. $model = new self();
  36. $model->user_id = $userId;
  37. $model->type = $type;
  38. $model->admin_id = $adminId;
  39. $model->end_time = $endTime;
  40. return $model->save();
  41. }
  42. /**
  43. * @param $userId
  44. * @param $type
  45. * @return null
  46. * 获取封禁信息
  47. */
  48. public static function getRow($userId, $type)
  49. {
  50. $query = self::query();
  51. $query->where(['user_id' => $userId, 'type' => $type]);
  52. if ($type == 1) {
  53. $query->where('end_time', '>', time());
  54. }
  55. return $query->first();
  56. }
  57. }