AgentWithdrawal.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class AgentWithdrawal extends Model
  5. {
  6. /**
  7. * 数据库连接名
  8. */
  9. protected $connection = 'mysql';
  10. /**
  11. * 与模型关联的表名
  12. */
  13. protected $table = 'webgame.agent_withdrawals';
  14. /**
  15. * 可批量赋值的属性
  16. */
  17. protected $fillable = [
  18. 'UserID',
  19. 'amount',
  20. 'before_balance',
  21. 'after_balance',
  22. 'status',
  23. 'remarks',
  24. 'order_sn',
  25. 'admin_id',
  26. 'admin_name',
  27. 'process_time'
  28. ];
  29. /**
  30. * 应该转换为日期的属性
  31. *
  32. * @var array
  33. */
  34. protected $dates = [
  35. 'process_time',
  36. 'created_at',
  37. 'updated_at'
  38. ];
  39. /**
  40. * 状态常量
  41. */
  42. const STATUS_PENDING = 0; // 处理中
  43. const STATUS_COMPLETED = 1; // 已完成
  44. const STATUS_REJECTED = 2; // 已拒绝
  45. /**
  46. * 获取状态文本
  47. *
  48. * @return string
  49. */
  50. public function getStatusTextAttribute()
  51. {
  52. switch ($this->status) {
  53. case self::STATUS_PENDING:
  54. return 'Pending';
  55. case self::STATUS_COMPLETED:
  56. return 'Completed';
  57. case self::STATUS_REJECTED:
  58. return 'Rejected';
  59. default:
  60. return 'Unknown';
  61. }
  62. }
  63. /**
  64. * 获取关联的用户信息
  65. */
  66. public function userInfo()
  67. {
  68. return $this->belongsTo(AgentUserInfo::class, 'UserID', 'UserID');
  69. }
  70. /**
  71. * 生成唯一订单号
  72. *
  73. * @return string
  74. */
  75. public static function generateOrderSn()
  76. {
  77. return 'AW' . date('YmdHis') . mt_rand(1000, 9999);
  78. }
  79. }