TransactionRecharge.php 2.2 KB

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