LhcOrder.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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'];
  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. public function lottery()
  17. {
  18. return $this->belongsTo(LhcLottery::class, 'issue', 'issue')
  19. ->select('issue', 'type', 'open_code', 'open_time', 'is_settlement');
  20. }
  21. public function items() {
  22. return $this->hasMany(LhcOrderItem::class, 'ordernum', 'ordernum');
  23. }
  24. /**
  25. * 历史订单主表未写入盈亏时,根据派奖金额和总投注额补齐接口返回值。
  26. */
  27. protected function getProfitAndLossAttribute($value): string
  28. {
  29. if ($value !== null && $value !== '') {
  30. return (string)$value;
  31. }
  32. $status = (int)($this->attributes['lottery_status'] ?? self::STATUS_STAY);
  33. if (!in_array($status, [self::STATUS_LOSS, self::STATUS_WIN], true)) {
  34. return '0.00';
  35. }
  36. $winAmount = (string)($this->attributes['win_amount'] ?? 0);
  37. $betAmount = $this->attributes['total_amount'] ?? $this->attributes['amount'] ?? 0;
  38. return bcsub($winAmount, (string)$betAmount, 2);
  39. }
  40. public static function getRemark($type)
  41. {
  42. if ($type == 1) {
  43. return '新澳门六合彩';
  44. } elseif ($type == 2) {
  45. return '香港六合彩';
  46. } elseif ($type == 3) {
  47. return '澳门六合彩';
  48. } elseif ($type == 4) {
  49. return '极速六合彩';
  50. } elseif ($type == 5) {
  51. return '加拿大28';
  52. } elseif ($type == 6) {
  53. return '极速28';
  54. } elseif ($type == 7) {
  55. return '极速赛车';
  56. } elseif ($type == 8) {
  57. return '极速时时彩';
  58. } elseif ($type == 9) {
  59. return '极速飞艇';
  60. } elseif ($type == 10) {
  61. return 'SG时时彩';
  62. } elseif ($type == 11) {
  63. return 'SG飞艇';
  64. } elseif ($type == 12) {
  65. return '极速快3';
  66. } elseif ($type == 13) {
  67. return 'SG快3';
  68. }
  69. return '';
  70. }
  71. }