LhcOrder.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. <?php
  2. namespace App\Models;
  3. use App\Models\LhcLottery;
  4. use App\Models\LhcOrderItem;
  5. class LhcOrder extends BaseModel
  6. {
  7. protected $table = 'lhc_order';
  8. protected $fillable = ['issue','ordernum','member_id','game','gameplay','number','odds','amount','lottery_status','win_amount','profit_and_loss','is_faker','remark','type','total_amount','bet_source'];
  9. protected $hidden = [];
  10. public $timestamps = true;
  11. protected $dateFormat = 'U'; // U 代表 UNIX 时间戳(int)
  12. const STATUS_STAY = 0; // 待开奖
  13. const STATUS_LOSS = 1; // 未中奖
  14. const STATUS_WIN = 2; // 已中奖
  15. const STATUS_REFUND = 3; // 已退款
  16. const SOURCE_TELEGRAM = 'telegram';
  17. const SOURCE_FRONTEND = 'frontend';
  18. public function lottery()
  19. {
  20. return $this->belongsTo(LhcLottery::class, 'issue', 'issue')
  21. ->select('issue', 'type', 'open_code', 'open_time', 'is_settlement');
  22. }
  23. public function items() {
  24. return $this->hasMany(LhcOrderItem::class, 'ordernum', 'ordernum');
  25. }
  26. /**
  27. * 历史订单主表未写入盈亏时,根据派奖金额和总投注额补齐接口返回值。
  28. */
  29. protected function getProfitAndLossAttribute($value): string
  30. {
  31. if ($value !== null && $value !== '') {
  32. return (string)$value;
  33. }
  34. $status = (int)($this->attributes['lottery_status'] ?? self::STATUS_STAY);
  35. if (!in_array($status, [self::STATUS_LOSS, self::STATUS_WIN], true)) {
  36. return '0.00';
  37. }
  38. $winAmount = (string)($this->attributes['win_amount'] ?? 0);
  39. $betAmount = $this->attributes['total_amount'] ?? $this->attributes['amount'] ?? 0;
  40. return bcsub($winAmount, (string)$betAmount, 2);
  41. }
  42. public static function getRemark($type)
  43. {
  44. if ($type == 1) {
  45. return '新澳门六合彩';
  46. } elseif ($type == 2) {
  47. return '香港六合彩';
  48. } elseif ($type == 3) {
  49. return '澳门六合彩';
  50. } elseif ($type == 4) {
  51. return '极速六合彩';
  52. } elseif ($type == 5) {
  53. return '加拿大28';
  54. } elseif ($type == 6) {
  55. return '极速28';
  56. } elseif ($type == 7) {
  57. return '极速赛车';
  58. } elseif ($type == 8) {
  59. return '极速时时彩';
  60. } elseif ($type == 9) {
  61. return '极速飞艇';
  62. } elseif ($type == 10) {
  63. return 'SG时时彩';
  64. } elseif ($type == 11) {
  65. return 'SG飞艇';
  66. } elseif ($type == 12) {
  67. return '极速快3';
  68. } elseif ($type == 13) {
  69. return 'SG快3';
  70. }
  71. return '';
  72. }
  73. }