| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394 |
- <?php
- namespace App\Module\Transaction\Models;
- use App\Module\Transaction\Enums\RECHARGE_STATUS;
- use Dcat\Admin\Traits\HasDateTimeFormatter;
- use UCore\ModelCore;
- /**
- * 充值记录
- *
- * field start
- * field end
- */
- class TransactionRecharge extends ModelCore
- {
- // attrlist start
- // arrlist end
- use HasDateTimeFormatter;
- protected $table = 'transaction_recharge';
- /**
- * @param $data
- * @return static
- */
- public static function insert($data): static
- {
- $model = new static;
- $model->transaction_id = $data['transaction_id'];
- $model->from_address = $data['from_address'];
- $model->to_address = $data['to_address'];
- $model->status = $data['status'];
- if ($model->save()) {
- return $model;
- }
- return false;
- }
- /**
- * @param $fromAddress
- * @return null
- * 检测地址是否有正在进行中的订单
- */
- public static function getOrderByFromAddress($fromAddress)
- {
- $query = self::query();
- $query->where('from_address', $fromAddress);
- $query->whereIn('status', [1, 50, 60, 70]);
- return $query->first();
- }
- /**
- * @param $transactionId
- * @return null
- * 获取充值单详情
- */
- public static function getDetail($transactionId)
- {
- $query = self::query();
- $query->where('transaction_id', $transactionId);
- return $query->first();
- }
- /**
- * @param $transactionId
- * @param $hash
- * @return int
- * 交易单添加hash
- */
- public static function addHash($transactionId, $hash)
- {
- $query = self::query();
- $query->where('transaction_id', $transactionId);
- return $query->update(['tx_hash' => $hash]);
- }
- /**
- * @param $hash
- * @return null
- * 校验hash唯一性(校验已完成状态充值单)
- */
- public static function checkHash($hash)
- {
- $query = self::query();
- $query->where('tx_hash', $hash);
- $query->where('status', RECHARGE_STATUS::COMPLETED);
- return $query->first();
- }
- }
|