Commit ea0fcc46 by haojie

1

parent 6974e94b
...@@ -36,7 +36,7 @@ class InscriptionTrading extends Model ...@@ -36,7 +36,7 @@ class InscriptionTrading extends Model
]; ];
// 一对一 // 一对一
public function inscription() public function inscriptions()
{ {
return $this->hasOne(Inscriptions::class, 'order_id', 'id'); return $this->hasOne(Inscriptions::class, 'order_id', 'id');
} }
......
...@@ -13,4 +13,9 @@ class Inscriptions extends Model ...@@ -13,4 +13,9 @@ class Inscriptions extends Model
// 允许批量赋值 // 允许批量赋值
protected $fillable = ['transaction_hash', 'current_owner', 'content_uri', 'uri_p', 'uri_op', 'uri_tick', 'uri_id', 'uri_amt', 'creator', 'creation_timestamp']; protected $fillable = ['transaction_hash', 'current_owner', 'content_uri', 'uri_p', 'uri_op', 'uri_tick', 'uri_id', 'uri_amt', 'creator', 'creation_timestamp'];
public function order()
{
return $this->belongsTo(InscriptionTrading::class, 'order_id', 'id');
}
} }
...@@ -13,9 +13,18 @@ class InscriptionService ...@@ -13,9 +13,18 @@ class InscriptionService
public const InscriptionDomain = 'https://eth-script-indexer-eca25c4cf43b.herokuapp.com'; public const InscriptionDomain = 'https://eth-script-indexer-eca25c4cf43b.herokuapp.com';
// 创建铭文信息 // 创建铭文信息
public function create($data) public function createOrUpdate($data)
{ {
Inscriptions::query()->create($data); $order_id = $data['order_id'] ?? '';
if ($order_id) {
$model = Inscriptions::query()->where('order_id', $order_id)->first();
if ($model) {
$model->update($data);
} else {
return Inscriptions::query()->create($data);
}
}
return false;
} }
public function getWalletInscription($address = '') public function getWalletInscription($address = '')
......
...@@ -99,13 +99,33 @@ public function getRedisTask($user) ...@@ -99,13 +99,33 @@ public function getRedisTask($user)
} }
// 更新铭文数据 // 更新铭文数据
public function updateInscription($data) public function updateInscription($data, $order_id = 0)
{ {
// 铭文信息必须包含指定字段 // 铭文信息必须包含指定字段
$fields = ['transaction_hash', 'current_owner', 'content_uri', 'creator', 'creation_timestamp']; $fields = ['transaction_hash', 'current_owner', 'content_uri', 'creator', 'creation_timestamp'];
// $content_uri = 'data:,{"p":"erc-20","op":"mint","tick":"eths","id":"11532","amt":"1000"}';
// 校验铭文信息 // 校验铭文信息
$inscription = app(CommonService::class)->customValidate($data, $fields, '缺少必要的铭文信息'); $inscription = app(CommonService::class)->customValidate($data, $fields, '缺少必要的铭文信息');
// 过滤出铭文信息
preg_match('/{.*}/', $inscription['content_uri'], $matches);
$content_uri = $matches[0];
if ($content_uri && $order_id != 0) {
$content_uri = json_decode($content_uri, true);
// 获取对应的
$inscriptionInfo = [];
$inscriptionInfo['order_id'] = $order_id;
$inscriptionInfo['transaction_hash'] = $inscription['transaction_hash'];
$inscriptionInfo['current_owner'] = $inscription['current_owner'];
$inscriptionInfo['content_uri'] = $inscription['content_uri'];
$inscriptionInfo['creator'] = $inscription['creator'];
$inscriptionInfo['creation_timestamp'] = $inscription['creation_timestamp'];
$inscriptionInfo['uri_p'] = $content_uri['p'] ?? '';
$inscriptionInfo['uri_op'] = $content_uri['op'] ?? '';
$inscriptionInfo['uri_tick'] = $content_uri['tick'] ?? '';
$inscriptionInfo['uri_id'] = $content_uri['id'] ?? '';
$inscriptionInfo['uri_amt'] = $content_uri['amt'] ?? '';
app(InscriptionService::class)->createOrUpdate($inscriptionInfo);
}
return $inscription; return $inscription;
} }
...@@ -376,7 +396,8 @@ public function check($data) ...@@ -376,7 +396,8 @@ public function check($data)
public function search($pageType, $address, $type, $page, $limit) public function search($pageType, $address, $type, $page, $limit)
{ {
$filed = ['inscription', 'status', 'original_amount', 'sell_fee', 'seller_receive_hash']; $filed = ['inscription', 'status', 'original_amount', 'sell_fee', 'seller_receive_hash'];
$model = $this->model(); $model = InscriptionTrading::with(['inscriptions']);
// $model = InscriptionTrading::query();
if (blank($address) || blank($type) || blank($pageType)) { if (blank($address) || blank($type) || blank($pageType)) {
throw new UserException(1, '非法操作'); throw new UserException(1, '非法操作');
} }
......
<?php
$content_uri = 'data:,{"p":"erc-20","op":"mint","tick":"eths","id":"11532","amt":"1000"}';
// 获取 $content_uri 中的 {} 内容
preg_match('/{.*}/', $content_uri, $matches);
$content_uri = $matches[0];
// 转换为php数组
$content_uri = json_decode($content_uri, true);
var_dump($content_uri);
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment