TransactionRecharge.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. namespace App\Module\Transaction\Models;
  3. use App\Module\Transaction\Enums\RECHARGE_STATUS;
  4. use Dcat\Admin\Traits\HasDateTimeFormatter;
  5. use Illuminate\Database\Eloquent\Model;
  6. /**
  7. * field start
  8. * field end
  9. */
  10. class TransactionRecharge extends Model
  11. {
  12. // attrlist start
  13. // arrlist end
  14. use HasDateTimeFormatter;
  15. protected $table = 'transaction_recharge';
  16. /**
  17. * @param $data
  18. * @return static
  19. */
  20. public static function insert($data): static
  21. {
  22. $model = new static;
  23. $model->transaction_id = $data['transaction_id'];
  24. $model->from_address = $data['from_address'];
  25. $model->to_address = $data['to_address'];
  26. $model->status = $data['status'];
  27. if ($model->save()) {
  28. return $model;
  29. }
  30. return false;
  31. }
  32. /**
  33. * @param $fromAddress
  34. * @return null
  35. * 检测地址是否有正在进行中的订单
  36. */
  37. public static function getOrderByFromAddress($fromAddress)
  38. {
  39. $query = self::query();
  40. $query->where('from_address', $fromAddress);
  41. $query->whereIn('status', [1, 50, 60, 70]);
  42. return $query->first();
  43. }
  44. /**
  45. * @param $transactionId
  46. * @return null
  47. * 获取充值单详情
  48. */
  49. public static function getDetail($transactionId)
  50. {
  51. $query = self::query();
  52. $query->where('transaction_id', $transactionId);
  53. return $query->first();
  54. }
  55. /**
  56. * @param $transactionId
  57. * @param $hash
  58. * @return int
  59. * 交易单添加hash
  60. */
  61. public static function addHash($transactionId, $hash)
  62. {
  63. $query = self::query();
  64. $query->where('transaction_id', $transactionId);
  65. return $query->update(['tx_hash' => $hash]);
  66. }
  67. /**
  68. * @param $hash
  69. * @return null
  70. * 校验hash唯一性(校验已完成状态充值单)
  71. */
  72. public static function checkHash($hash)
  73. {
  74. $query = self::query();
  75. $query->where('tx_hash', $hash);
  76. $query->where('status', RECHARGE_STATUS::COMPLETED);
  77. return $query->first();
  78. }
  79. }