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