SignInRewardConfig.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. /**
  5. * 签到奖励配置模型
  6. *
  7. * @property int $DayNumber 签到第几天
  8. * @property int $RewardScore 签到奖励积分
  9. */
  10. class SignInRewardConfig extends Model
  11. {
  12. // 使用 DayNumber 作为主键(代替自增的 id)
  13. protected $primaryKey = 'DayNumber';
  14. protected $keyType = 'int';
  15. public $incrementing = false; // 禁用自增
  16. // SQL Server 表名:三部分命名
  17. protected $table = 'QPAccountsDB.dbo.SignInRewardConfig';
  18. // 无时间戳字段(该表没有 created_at/updated_at)
  19. public $timestamps = false;
  20. // 可批量赋值的属性
  21. protected $fillable = [
  22. 'DayNumber',
  23. 'RewardScore',
  24. ];
  25. // 字段转换
  26. protected $casts = [
  27. 'DayNumber' => 'integer',
  28. 'RewardScore' => 'integer',
  29. ];
  30. /**
  31. * 获取分页列表,按 DayNumber 排序
  32. *
  33. * @param int $perPage
  34. * @return \Illuminate\Pagination\Paginator
  35. */
  36. public static function getPaginatedList($perPage = 10)
  37. {
  38. return self::orderBy('DayNumber', 'asc')->paginate($perPage);
  39. }
  40. /**
  41. * 根据天数查找奖励
  42. *
  43. * @param int $dayNumber
  44. * @return SignInRewardConfig|null
  45. */
  46. public static function findByDay($dayNumber)
  47. {
  48. return self::where('DayNumber', $dayNumber)->first();
  49. }
  50. }