LhcOrder.php 2.7 KB

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