Compare commits
10 Commits
aa40614965
...
7e3eba92e2
| Author | SHA1 | Date | |
|---|---|---|---|
| 7e3eba92e2 | |||
| 81a95f47a0 | |||
| 4b47fe7250 | |||
| 01e93acdd8 | |||
| 6ce37d789f | |||
| 489090382f | |||
| 4b8f205e86 | |||
| 1161f06aeb | |||
| 6d242ae973 | |||
| 025dab4c2c |
1
.gitignore
vendored
1
.gitignore
vendored
@ -17,3 +17,4 @@ yarn-error.log
|
|||||||
/.fleet
|
/.fleet
|
||||||
/.idea
|
/.idea
|
||||||
/.vscode
|
/.vscode
|
||||||
|
test.php
|
||||||
|
|||||||
201
app/Bean/Model/Api/Order/CustomerUserPostOrderBean.php
Normal file
201
app/Bean/Model/Api/Order/CustomerUserPostOrderBean.php
Normal file
@ -0,0 +1,201 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Model\Api\Order;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
use App\Models\Api\Wallet\CustomerWalletCurrencyModel;
|
||||||
|
|
||||||
|
class CustomerUserPostOrderBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $id;
|
||||||
|
protected $sn;
|
||||||
|
protected $pay_status;
|
||||||
|
protected $buyer_uid;
|
||||||
|
protected $buyer_currency_code = CustomerWalletCurrencyModel::CODE_USDT_TRC20;
|
||||||
|
protected $seller_uid;
|
||||||
|
protected $seller_currency_code = CustomerWalletCurrencyModel::CODE_USDT_TRC20;
|
||||||
|
protected $pid;
|
||||||
|
protected $post_history_id;
|
||||||
|
protected $amount;
|
||||||
|
protected $buyer_wallet_transaction_id;
|
||||||
|
protected $seller_wallet_transaction_id;
|
||||||
|
protected $wallet_checkbook_id;
|
||||||
|
protected $dispute_status;
|
||||||
|
protected $dispute_result_status;
|
||||||
|
protected $created_at;
|
||||||
|
protected $updated_at;
|
||||||
|
|
||||||
|
public function getBuyerCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->buyer_currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerCurrencyCode($buyer_currency_code): void
|
||||||
|
{
|
||||||
|
$this->buyer_currency_code = $buyer_currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->seller_currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerCurrencyCode($seller_currency_code): void
|
||||||
|
{
|
||||||
|
$this->seller_currency_code = $seller_currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSn()
|
||||||
|
{
|
||||||
|
return $this->sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSn($sn): void
|
||||||
|
{
|
||||||
|
$this->sn = $sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPayStatus()
|
||||||
|
{
|
||||||
|
return $this->pay_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPayStatus($pay_status): void
|
||||||
|
{
|
||||||
|
$this->pay_status = $pay_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerUid()
|
||||||
|
{
|
||||||
|
return $this->buyer_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerUid($buyer_uid): void
|
||||||
|
{
|
||||||
|
$this->buyer_uid = $buyer_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerUid()
|
||||||
|
{
|
||||||
|
return $this->seller_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerUid($seller_uid): void
|
||||||
|
{
|
||||||
|
$this->seller_uid = $seller_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPid()
|
||||||
|
{
|
||||||
|
return $this->pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPid($pid): void
|
||||||
|
{
|
||||||
|
$this->pid = $pid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPostHistoryId()
|
||||||
|
{
|
||||||
|
return $this->post_history_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPostHistoryId($post_history_id): void
|
||||||
|
{
|
||||||
|
$this->post_history_id = $post_history_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount()
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAmount($amount): void
|
||||||
|
{
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerWalletTransactionId()
|
||||||
|
{
|
||||||
|
return $this->buyer_wallet_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerWalletTransactionId($buyer_wallet_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->buyer_wallet_transaction_id = $buyer_wallet_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerWalletTransactionId()
|
||||||
|
{
|
||||||
|
return $this->seller_wallet_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerWalletTransactionId($seller_wallet_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->seller_wallet_transaction_id = $seller_wallet_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWalletCheckbookId()
|
||||||
|
{
|
||||||
|
return $this->wallet_checkbook_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWalletCheckbookId($wallet_checkbook_id): void
|
||||||
|
{
|
||||||
|
$this->wallet_checkbook_id = $wallet_checkbook_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDisputeStatus()
|
||||||
|
{
|
||||||
|
return $this->dispute_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDisputeStatus($dispute_status): void
|
||||||
|
{
|
||||||
|
$this->dispute_status = $dispute_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDisputeResultStatus()
|
||||||
|
{
|
||||||
|
return $this->dispute_result_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDisputeResultStatus($dispute_result_status): void
|
||||||
|
{
|
||||||
|
$this->dispute_result_status = $dispute_result_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return $this->updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt($updated_at): void
|
||||||
|
{
|
||||||
|
$this->updated_at = $updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
277
app/Bean/Model/Api/Order/CustomerUserPostOrderDisputeBean.php
Normal file
277
app/Bean/Model/Api/Order/CustomerUserPostOrderDisputeBean.php
Normal file
@ -0,0 +1,277 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Model\Api\Order;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class CustomerUserPostOrderDisputeBean extends BaseBean
|
||||||
|
{
|
||||||
|
public $id;
|
||||||
|
public $post_order_id;
|
||||||
|
public $status;
|
||||||
|
public $chat_group_id;
|
||||||
|
public $seller_submit_datetime;
|
||||||
|
public $buyer_submit_datetime;
|
||||||
|
public $result_status;
|
||||||
|
public $buyer_uid;
|
||||||
|
public $buyer_pay_dispute_status;
|
||||||
|
public $buyer_pay_amount;
|
||||||
|
public $buyer_pay_transaction_id;
|
||||||
|
public $buyer_dispute_fee_pay_status;
|
||||||
|
public $buyer_dispute_fee_amount;
|
||||||
|
public $buyer_dispute_fee_pay_transaction_id;
|
||||||
|
public $seller_pay_dispute_status;
|
||||||
|
public $seller_uid;
|
||||||
|
public $seller_pay_amount;
|
||||||
|
public $seller_pay_transaction_id;
|
||||||
|
public $seller_desc_key;
|
||||||
|
public $seller_desc;
|
||||||
|
public $admin_remark;
|
||||||
|
public $admin_uid;
|
||||||
|
public $created_at;
|
||||||
|
public $updated_at;
|
||||||
|
|
||||||
|
public function getBuyerUid()
|
||||||
|
{
|
||||||
|
return $this->buyer_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerUid($buyer_uid): void
|
||||||
|
{
|
||||||
|
$this->buyer_uid = $buyer_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerUid()
|
||||||
|
{
|
||||||
|
return $this->seller_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerUid($seller_uid): void
|
||||||
|
{
|
||||||
|
$this->seller_uid = $seller_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerDisputeFeePayStatus()
|
||||||
|
{
|
||||||
|
return $this->buyer_dispute_fee_pay_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerDisputeFeePayStatus($buyer_dispute_fee_pay_status): void
|
||||||
|
{
|
||||||
|
$this->buyer_dispute_fee_pay_status = $buyer_dispute_fee_pay_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPostOrderId()
|
||||||
|
{
|
||||||
|
return $this->post_order_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPostOrderId($post_order_id): void
|
||||||
|
{
|
||||||
|
$this->post_order_id = $post_order_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus()
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus($status): void
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getChatGroupId()
|
||||||
|
{
|
||||||
|
return $this->chat_group_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setChatGroupId($chat_group_id): void
|
||||||
|
{
|
||||||
|
$this->chat_group_id = $chat_group_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerSubmitDatetime()
|
||||||
|
{
|
||||||
|
return $this->seller_submit_datetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerSubmitDatetime($seller_submit_datetime): void
|
||||||
|
{
|
||||||
|
$this->seller_submit_datetime = $seller_submit_datetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerSubmitDatetime()
|
||||||
|
{
|
||||||
|
return $this->buyer_submit_datetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerSubmitDatetime($buyer_submit_datetime): void
|
||||||
|
{
|
||||||
|
$this->buyer_submit_datetime = $buyer_submit_datetime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResultStatus()
|
||||||
|
{
|
||||||
|
return $this->result_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResultStatus($result_status): void
|
||||||
|
{
|
||||||
|
$this->result_status = $result_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerPayDisputeStatus()
|
||||||
|
{
|
||||||
|
return $this->buyer_pay_dispute_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerPayDisputeStatus($buyer_pay_dispute_status): void
|
||||||
|
{
|
||||||
|
$this->buyer_pay_dispute_status = $buyer_pay_dispute_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerPayAmount()
|
||||||
|
{
|
||||||
|
return $this->buyer_pay_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerPayAmount($buyer_pay_amount): void
|
||||||
|
{
|
||||||
|
$this->buyer_pay_amount = $buyer_pay_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerPayTransactionId()
|
||||||
|
{
|
||||||
|
return $this->buyer_pay_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerPayTransactionId($buyer_pay_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->buyer_pay_transaction_id = $buyer_pay_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerDisputeFeeAmount()
|
||||||
|
{
|
||||||
|
return $this->buyer_dispute_fee_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerDisputeFeeAmount($buyer_dispute_fee_amount): void
|
||||||
|
{
|
||||||
|
$this->buyer_dispute_fee_amount = $buyer_dispute_fee_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBuyerDisputeFeePayTransactionId()
|
||||||
|
{
|
||||||
|
return $this->buyer_dispute_fee_pay_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBuyerDisputeFeePayTransactionId($buyer_dispute_fee_pay_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->buyer_dispute_fee_pay_transaction_id = $buyer_dispute_fee_pay_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerPayDisputeStatus()
|
||||||
|
{
|
||||||
|
return $this->seller_pay_dispute_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerPayDisputeStatus($seller_pay_dispute_status): void
|
||||||
|
{
|
||||||
|
$this->seller_pay_dispute_status = $seller_pay_dispute_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerPayAmount()
|
||||||
|
{
|
||||||
|
return $this->seller_pay_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerPayAmount($seller_pay_amount): void
|
||||||
|
{
|
||||||
|
$this->seller_pay_amount = $seller_pay_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerPayTransactionId()
|
||||||
|
{
|
||||||
|
return $this->seller_pay_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerPayTransactionId($seller_pay_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->seller_pay_transaction_id = $seller_pay_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerDescKey()
|
||||||
|
{
|
||||||
|
return $this->seller_desc_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerDescKey($seller_desc_key): void
|
||||||
|
{
|
||||||
|
$this->seller_desc_key = $seller_desc_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSellerDesc()
|
||||||
|
{
|
||||||
|
return $this->seller_desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSellerDesc($seller_desc): void
|
||||||
|
{
|
||||||
|
$this->seller_desc = $seller_desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdminRemark()
|
||||||
|
{
|
||||||
|
return $this->admin_remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAdminRemark($admin_remark): void
|
||||||
|
{
|
||||||
|
$this->admin_remark = $admin_remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAdminUid()
|
||||||
|
{
|
||||||
|
return $this->admin_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAdminUid($admin_uid): void
|
||||||
|
{
|
||||||
|
$this->admin_uid = $admin_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return $this->updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt($updated_at): void
|
||||||
|
{
|
||||||
|
$this->updated_at = $updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
121
app/Bean/Model/Api/Wallet/CustomerWalletBalanceBean.php
Normal file
121
app/Bean/Model/Api/Wallet/CustomerWalletBalanceBean.php
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Model\Api\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class CustomerWalletBalanceBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $id;
|
||||||
|
protected $uid;
|
||||||
|
protected $currency_code;
|
||||||
|
protected $total_amount;
|
||||||
|
protected $frozen_amount;
|
||||||
|
protected $available_amount;
|
||||||
|
protected $security_amount;
|
||||||
|
protected $recharge_wallet_addr;
|
||||||
|
protected $created_at;
|
||||||
|
protected $updated_at;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUid()
|
||||||
|
{
|
||||||
|
return $this->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUid($uid): void
|
||||||
|
{
|
||||||
|
$this->uid = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrencyCode($currency_code): void
|
||||||
|
{
|
||||||
|
$this->currency_code = $currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTotalAmount()
|
||||||
|
{
|
||||||
|
return $this->total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTotalAmount($total_amount): void
|
||||||
|
{
|
||||||
|
$this->total_amount = $total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFrozenAmount()
|
||||||
|
{
|
||||||
|
return $this->frozen_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFrozenAmount($frozen_amount): void
|
||||||
|
{
|
||||||
|
$this->frozen_amount = $frozen_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAvailableAmount()
|
||||||
|
{
|
||||||
|
return $this->available_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAvailableAmount($available_amount): void
|
||||||
|
{
|
||||||
|
$this->available_amount = $available_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSecurityAmount()
|
||||||
|
{
|
||||||
|
return $this->security_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSecurityAmount($security_amount): void
|
||||||
|
{
|
||||||
|
$this->security_amount = $security_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRechargeWalletAddr()
|
||||||
|
{
|
||||||
|
return $this->recharge_wallet_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRechargeWalletAddr($recharge_wallet_addr): void
|
||||||
|
{
|
||||||
|
$this->recharge_wallet_addr = $recharge_wallet_addr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return $this->updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt($updated_at): void
|
||||||
|
{
|
||||||
|
$this->updated_at = $updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,235 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Model\Api\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
use App\Models\Api\Wallet\CustomerWalletCurrencyModel;
|
||||||
|
use App\Models\Api\Wallet\CustomerWalletBalanceTransactionModel;
|
||||||
|
|
||||||
|
class CustomerWalletBalanceTransactionBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $id;
|
||||||
|
protected $type;
|
||||||
|
protected $status = CustomerWalletBalanceTransactionModel::STATUS_WAIT;
|
||||||
|
protected $wallet_id;
|
||||||
|
protected $uid;
|
||||||
|
protected $currency_code = CustomerWalletCurrencyModel::CODE_USDT_TRC20;
|
||||||
|
protected $amount = 0;
|
||||||
|
protected $fee_amount = 0;
|
||||||
|
protected $before_total_amount;
|
||||||
|
protected $after_total_amount;
|
||||||
|
protected $source_params;
|
||||||
|
protected $remark;
|
||||||
|
protected $target_uid;
|
||||||
|
protected $target_post_order_id;
|
||||||
|
protected $target_post_order_dispute_id;
|
||||||
|
protected $sign;
|
||||||
|
protected $callback_time;
|
||||||
|
protected $delay_payment_time;
|
||||||
|
protected $created_at;
|
||||||
|
protected $updated_at;
|
||||||
|
|
||||||
|
public function getFeeAmount(): int
|
||||||
|
{
|
||||||
|
return $this->fee_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFeeAmount(int $fee_amount): void
|
||||||
|
{
|
||||||
|
$this->fee_amount = $fee_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getTargetPostOrderDisputeId()
|
||||||
|
{
|
||||||
|
return $this->target_post_order_dispute_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTargetPostOrderDisputeId($target_post_order_dispute_id): void
|
||||||
|
{
|
||||||
|
$this->target_post_order_dispute_id = $target_post_order_dispute_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus(): int
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus(int $status): void
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWalletId()
|
||||||
|
{
|
||||||
|
return $this->wallet_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWalletId($wallet_id): void
|
||||||
|
{
|
||||||
|
$this->wallet_id = $wallet_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUid()
|
||||||
|
{
|
||||||
|
return $this->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUid($uid): void
|
||||||
|
{
|
||||||
|
$this->uid = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyCode(): string
|
||||||
|
{
|
||||||
|
return $this->currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrencyCode(string $currency_code): void
|
||||||
|
{
|
||||||
|
$this->currency_code = $currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount(): int
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAmount(int $amount): void
|
||||||
|
{
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBeforeTotalAmount()
|
||||||
|
{
|
||||||
|
return $this->before_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBeforeTotalAmount($before_total_amount): void
|
||||||
|
{
|
||||||
|
$this->before_total_amount = $before_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAfterTotalAmount()
|
||||||
|
{
|
||||||
|
return $this->after_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAfterTotalAmount($after_total_amount): void
|
||||||
|
{
|
||||||
|
$this->after_total_amount = $after_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSourceParams()
|
||||||
|
{
|
||||||
|
return $this->source_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSourceParams($source_params): void
|
||||||
|
{
|
||||||
|
$this->source_params = $source_params;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRemark()
|
||||||
|
{
|
||||||
|
return $this->remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRemark($remark): void
|
||||||
|
{
|
||||||
|
$this->remark = $remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTargetUid()
|
||||||
|
{
|
||||||
|
return $this->target_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTargetUid($target_uid): void
|
||||||
|
{
|
||||||
|
$this->target_uid = $target_uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTargetPostOrderId()
|
||||||
|
{
|
||||||
|
return $this->target_post_order_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTargetPostOrderId($target_post_order_id): void
|
||||||
|
{
|
||||||
|
$this->target_post_order_id = $target_post_order_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSign()
|
||||||
|
{
|
||||||
|
return $this->sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSign($sign): void
|
||||||
|
{
|
||||||
|
$this->sign = $sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCallbackTime()
|
||||||
|
{
|
||||||
|
return $this->callback_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCallbackTime($callback_time): void
|
||||||
|
{
|
||||||
|
$this->callback_time = $callback_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDelayPaymentTime()
|
||||||
|
{
|
||||||
|
return $this->delay_payment_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDelayPaymentTime($delay_payment_time): void
|
||||||
|
{
|
||||||
|
$this->delay_payment_time = $delay_payment_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return $this->updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt($updated_at): void
|
||||||
|
{
|
||||||
|
$this->updated_at = $updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
13
app/Bean/Model/Base/BaseBean.php
Normal file
13
app/Bean/Model/Base/BaseBean.php
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Model\Base;
|
||||||
|
|
||||||
|
use EasySwoole\Spl\SplBean;
|
||||||
|
|
||||||
|
abstract class BaseBean extends SplBean
|
||||||
|
{
|
||||||
|
function toArrayNotNull(): array
|
||||||
|
{
|
||||||
|
return $this->toArray(self::FILTER_NOT_NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
9
app/Bean/Model/Base/TmplBean.php
Normal file
9
app/Bean/Model/Base/TmplBean.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Model\Base;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class TmplBean extends BaseBean
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,305 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Model\Wallet\Platform;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class WalletPlatformBalanceTransactionBean extends BaseBean
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $sn;
|
||||||
|
protected $type;
|
||||||
|
protected $status;
|
||||||
|
protected $platform_id;
|
||||||
|
protected $balance_id;
|
||||||
|
protected $currency_code;
|
||||||
|
protected $block_transaction_id;
|
||||||
|
protected $bind_wallet_address_id;
|
||||||
|
protected $bind_wallet_address;
|
||||||
|
protected $from_wallet_address_id;
|
||||||
|
protected $from_wallet_address;
|
||||||
|
protected $to_wallet_address_id;
|
||||||
|
protected $to_wallet_address;
|
||||||
|
|
||||||
|
protected $uid;
|
||||||
|
protected $amount = 0;
|
||||||
|
protected $fee_amount = 0;
|
||||||
|
protected $before_total_amount;
|
||||||
|
protected $after_total_amount;
|
||||||
|
protected $remark;
|
||||||
|
protected $source_wallet_id;
|
||||||
|
protected $callback_time;
|
||||||
|
protected $callback_wallet_address_transaction_id;
|
||||||
|
protected $is_notify;
|
||||||
|
protected $created_at;
|
||||||
|
protected $updated_at;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSn()
|
||||||
|
{
|
||||||
|
return $this->sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSn($sn): void
|
||||||
|
{
|
||||||
|
$this->sn = $sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBindWalletAddressId()
|
||||||
|
{
|
||||||
|
return $this->bind_wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBindWalletAddressId($bind_wallet_address_id): void
|
||||||
|
{
|
||||||
|
$this->bind_wallet_address_id = $bind_wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBindWalletAddress()
|
||||||
|
{
|
||||||
|
return $this->bind_wallet_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBindWalletAddress($bind_wallet_address): void
|
||||||
|
{
|
||||||
|
$this->bind_wallet_address = $bind_wallet_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFromWalletAddressId()
|
||||||
|
{
|
||||||
|
return $this->from_wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFromWalletAddressId($from_wallet_address_id): void
|
||||||
|
{
|
||||||
|
$this->from_wallet_address_id = $from_wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFromWalletAddress()
|
||||||
|
{
|
||||||
|
return $this->from_wallet_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFromWalletAddress($from_wallet_address): void
|
||||||
|
{
|
||||||
|
$this->from_wallet_address = $from_wallet_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getToWalletAddressId()
|
||||||
|
{
|
||||||
|
return $this->to_wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setToWalletAddressId($to_wallet_address_id): void
|
||||||
|
{
|
||||||
|
$this->to_wallet_address_id = $to_wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getToWalletAddress()
|
||||||
|
{
|
||||||
|
return $this->to_wallet_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setToWalletAddress($to_wallet_address): void
|
||||||
|
{
|
||||||
|
$this->to_wallet_address = $to_wallet_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function getCallbackWalletAddressTransactionId()
|
||||||
|
{
|
||||||
|
return $this->callback_wallet_address_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCallbackWalletAddressTransactionId($callback_wallet_address_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->callback_wallet_address_transaction_id = $callback_wallet_address_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUid()
|
||||||
|
{
|
||||||
|
return $this->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUid($uid): void
|
||||||
|
{
|
||||||
|
$this->uid = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getSourceWalletId()
|
||||||
|
{
|
||||||
|
return $this->source_wallet_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSourceWalletId($source_wallet_id): void
|
||||||
|
{
|
||||||
|
$this->source_wallet_id = $source_wallet_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBalanceId()
|
||||||
|
{
|
||||||
|
return $this->balance_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBalanceId($balance_id): void
|
||||||
|
{
|
||||||
|
$this->balance_id = $balance_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus()
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus($status): void
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlatformId()
|
||||||
|
{
|
||||||
|
return $this->platform_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPlatformId($platform_id): void
|
||||||
|
{
|
||||||
|
$this->platform_id = $platform_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrencyCode($currency_code): void
|
||||||
|
{
|
||||||
|
$this->currency_code = $currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTransactionId()
|
||||||
|
{
|
||||||
|
return $this->block_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTransactionId($block_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->block_transaction_id = $block_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getFeeAmount()
|
||||||
|
{
|
||||||
|
return $this->fee_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFeeAmount($fee_amount): void
|
||||||
|
{
|
||||||
|
$this->fee_amount = $fee_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount()
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAmount($amount): void
|
||||||
|
{
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getBeforeTotalAmount()
|
||||||
|
{
|
||||||
|
return $this->before_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBeforeTotalAmount($before_total_amount): void
|
||||||
|
{
|
||||||
|
$this->before_total_amount = $before_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAfterTotalAmount()
|
||||||
|
{
|
||||||
|
return $this->after_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAfterTotalAmount($after_total_amount): void
|
||||||
|
{
|
||||||
|
$this->after_total_amount = $after_total_amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRemark()
|
||||||
|
{
|
||||||
|
return $this->remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRemark($remark): void
|
||||||
|
{
|
||||||
|
$this->remark = $remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCallbackTime()
|
||||||
|
{
|
||||||
|
return $this->callback_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCallbackTime($callback_time): void
|
||||||
|
{
|
||||||
|
$this->callback_time = $callback_time;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function getIsNotify()
|
||||||
|
{
|
||||||
|
return $this->is_notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsNotify($is_notify): void
|
||||||
|
{
|
||||||
|
$this->is_notify = $is_notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return $this->updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt($updated_at): void
|
||||||
|
{
|
||||||
|
$this->updated_at = $updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
90
app/Bean/Model/Wallet/Platform/WalletPlatformBean.php
Normal file
90
app/Bean/Model/Wallet/Platform/WalletPlatformBean.php
Normal file
@ -0,0 +1,90 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Model\Wallet\Platform;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class WalletPlatformBean extends BaseBean
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $name;
|
||||||
|
protected $code;
|
||||||
|
protected $appid;
|
||||||
|
protected $secret;
|
||||||
|
protected $notify_ip;
|
||||||
|
protected $created_at;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name): void
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCode()
|
||||||
|
{
|
||||||
|
return $this->code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCode($code): void
|
||||||
|
{
|
||||||
|
$this->code = $code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAppid()
|
||||||
|
{
|
||||||
|
return $this->appid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAppid($appid): void
|
||||||
|
{
|
||||||
|
$this->appid = $appid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSecret()
|
||||||
|
{
|
||||||
|
return $this->secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSecret($secret): void
|
||||||
|
{
|
||||||
|
$this->secret = $secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getNotifyIp()
|
||||||
|
{
|
||||||
|
return $this->notify_ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setNotifyIp($notify_ip): void
|
||||||
|
{
|
||||||
|
$this->notify_ip = $notify_ip;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
79
app/Bean/Model/Wallet/Tron/WalletTronBlockBean.php
Normal file
79
app/Bean/Model/Wallet/Tron/WalletTronBlockBean.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Model\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class WalletTronBlockBean extends BaseBean
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $status;
|
||||||
|
protected $block_id;
|
||||||
|
protected $block_num;
|
||||||
|
protected $block_timestamp;
|
||||||
|
protected $created_at;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus()
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus($status): void
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockId()
|
||||||
|
{
|
||||||
|
return $this->block_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockId($block_id): void
|
||||||
|
{
|
||||||
|
$this->block_id = $block_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockNum()
|
||||||
|
{
|
||||||
|
return $this->block_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockNum($block_num): void
|
||||||
|
{
|
||||||
|
$this->block_num = $block_num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTimestamp()
|
||||||
|
{
|
||||||
|
return $this->block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTimestamp($block_timestamp): void
|
||||||
|
{
|
||||||
|
$this->block_timestamp = $block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
124
app/Bean/Model/Wallet/Wallet/WalletAddressBean.php
Normal file
124
app/Bean/Model/Wallet/Wallet/WalletAddressBean.php
Normal file
@ -0,0 +1,124 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Model\Wallet\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class WalletAddressBean extends BaseBean
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $use_status;
|
||||||
|
protected $currency_code;
|
||||||
|
|
||||||
|
protected $balance;
|
||||||
|
protected $address_hex;
|
||||||
|
protected $address_base58;
|
||||||
|
protected $private_key;
|
||||||
|
protected $remark;
|
||||||
|
protected $created_at;
|
||||||
|
protected $updated_at;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUseStatus()
|
||||||
|
{
|
||||||
|
return $this->use_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUseStatus($use_status): void
|
||||||
|
{
|
||||||
|
$this->use_status = $use_status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrencyCode($currency_code): void
|
||||||
|
{
|
||||||
|
$this->currency_code = $currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBalance()
|
||||||
|
{
|
||||||
|
return $this->balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBalance($balance): void
|
||||||
|
{
|
||||||
|
$this->balance = $balance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddressHex()
|
||||||
|
{
|
||||||
|
return $this->address_hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAddressHex($address_hex): void
|
||||||
|
{
|
||||||
|
$this->address_hex = $address_hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddressBase58()
|
||||||
|
{
|
||||||
|
return $this->address_base58;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAddressBase58($address_base58): void
|
||||||
|
{
|
||||||
|
$this->address_base58 = $address_base58;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPrivateKey()
|
||||||
|
{
|
||||||
|
return $this->private_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPrivateKey($private_key): void
|
||||||
|
{
|
||||||
|
$this->private_key = $private_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRemark()
|
||||||
|
{
|
||||||
|
return $this->remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRemark($remark): void
|
||||||
|
{
|
||||||
|
$this->remark = $remark;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUpdatedAt()
|
||||||
|
{
|
||||||
|
return $this->updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUpdatedAt($updated_at): void
|
||||||
|
{
|
||||||
|
$this->updated_at = $updated_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
169
app/Bean/Model/Wallet/Wallet/WalletAddressTransactionBean.php
Normal file
169
app/Bean/Model/Wallet/Wallet/WalletAddressTransactionBean.php
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Model\Wallet\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class WalletAddressTransactionBean extends BaseBean
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $currency_code;
|
||||||
|
protected $type;
|
||||||
|
protected $wallet_address_id;
|
||||||
|
protected $amount;
|
||||||
|
protected $block_transaction_id;
|
||||||
|
protected $block_number;
|
||||||
|
protected $block_event_name;
|
||||||
|
protected $block_from_address;
|
||||||
|
protected $block_to_address;
|
||||||
|
protected $block_value;
|
||||||
|
protected $block_timestamp;
|
||||||
|
protected $created_at;
|
||||||
|
protected $is_notify;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrencyCode($currency_code): void
|
||||||
|
{
|
||||||
|
$this->currency_code = $currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWalletAddressId()
|
||||||
|
{
|
||||||
|
return $this->wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWalletAddressId($wallet_address_id): void
|
||||||
|
{
|
||||||
|
$this->wallet_address_id = $wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount()
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAmount($amount): void
|
||||||
|
{
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTransactionId()
|
||||||
|
{
|
||||||
|
return $this->block_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTransactionId($block_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->block_transaction_id = $block_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockNumber()
|
||||||
|
{
|
||||||
|
return $this->block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockNumber($block_number): void
|
||||||
|
{
|
||||||
|
$this->block_number = $block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockEventName()
|
||||||
|
{
|
||||||
|
return $this->block_event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockEventName($block_event_name): void
|
||||||
|
{
|
||||||
|
$this->block_event_name = $block_event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockFromAddress()
|
||||||
|
{
|
||||||
|
return $this->block_from_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockFromAddress($block_from_address): void
|
||||||
|
{
|
||||||
|
$this->block_from_address = $block_from_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockToAddress()
|
||||||
|
{
|
||||||
|
return $this->block_to_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockToAddress($block_to_address): void
|
||||||
|
{
|
||||||
|
$this->block_to_address = $block_to_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockValue()
|
||||||
|
{
|
||||||
|
return $this->block_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockValue($block_value): void
|
||||||
|
{
|
||||||
|
$this->block_value = $block_value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTimestamp()
|
||||||
|
{
|
||||||
|
return $this->block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTimestamp($block_timestamp): void
|
||||||
|
{
|
||||||
|
$this->block_timestamp = $block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIsNotify()
|
||||||
|
{
|
||||||
|
return $this->is_notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsNotify($is_notify): void
|
||||||
|
{
|
||||||
|
$this->is_notify = $is_notify;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
79
app/Bean/Model/Wallet/Wallet/WalletPlatformBindBean.php
Normal file
79
app/Bean/Model/Wallet/Wallet/WalletPlatformBindBean.php
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Model\Wallet\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class WalletPlatformBindBean extends BaseBean
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $platform_id;
|
||||||
|
protected $wallet_address_id;
|
||||||
|
protected $currency_code;
|
||||||
|
protected $uid;
|
||||||
|
protected $created_at;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPlatformId()
|
||||||
|
{
|
||||||
|
return $this->platform_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPlatformId($platform_id): void
|
||||||
|
{
|
||||||
|
$this->platform_id = $platform_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWalletAddressId()
|
||||||
|
{
|
||||||
|
return $this->wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWalletAddressId($wallet_address_id): void
|
||||||
|
{
|
||||||
|
$this->wallet_address_id = $wallet_address_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrencyCode($currency_code): void
|
||||||
|
{
|
||||||
|
$this->currency_code = $currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUid()
|
||||||
|
{
|
||||||
|
return $this->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUid($uid): void
|
||||||
|
{
|
||||||
|
$this->uid = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCreatedAt($created_at): void
|
||||||
|
{
|
||||||
|
$this->created_at = $created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
37
app/Bean/Queue/Api/QueueAddPostBean.php
Normal file
37
app/Bean/Queue/Api/QueueAddPostBean.php
Normal file
@ -0,0 +1,37 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueAddPostBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_add_post';
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $type;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
41
app/Bean/Queue/Api/QueueUserActiveStatusBean.php
Normal file
41
app/Bean/Queue/Api/QueueUserActiveStatusBean.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueUserActiveStatusBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_user_active_status';
|
||||||
|
|
||||||
|
protected $uid;
|
||||||
|
protected $queue_created_at;
|
||||||
|
|
||||||
|
public function getUid()
|
||||||
|
{
|
||||||
|
return $this->uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUid($uid): void
|
||||||
|
{
|
||||||
|
$this->uid = $uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getQueueCreatedAt()
|
||||||
|
{
|
||||||
|
return $this->queue_created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setQueueCreatedAt($queue_created_at): void
|
||||||
|
{
|
||||||
|
$this->queue_created_at = $queue_created_at;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
35
app/Bean/Queue/QueueBaseBean.php
Normal file
35
app/Bean/Queue/QueueBaseBean.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class QueueBaseBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $try_limt = 3;
|
||||||
|
protected $try_times = 0;
|
||||||
|
|
||||||
|
public function IncrTryTimes($num = 1): void
|
||||||
|
{
|
||||||
|
$this->try_times += $num;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkTryTimes(): bool
|
||||||
|
{
|
||||||
|
if($this->try_times >= $this->try_limt) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTryTimes(): int
|
||||||
|
{
|
||||||
|
return $this->try_times;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getDelaySeconds($seconds = 30): int
|
||||||
|
{
|
||||||
|
return $seconds * $this->try_times;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
123
app/Bean/Queue/Wallet/QueueEventBean.php
Normal file
123
app/Bean/Queue/Wallet/QueueEventBean.php
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
use App\Bean\Sdk\Wallet\Tron\EventResultBean;
|
||||||
|
use App\Bean\Sdk\Wallet\Tron\EventResultTypeBean;
|
||||||
|
|
||||||
|
class QueueEventBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_wallet_address_transaction';
|
||||||
|
protected $block_number;
|
||||||
|
protected $block_timestamp;
|
||||||
|
protected $caller_contract_address;
|
||||||
|
protected $contract_address;
|
||||||
|
protected $event;
|
||||||
|
protected $event_index;
|
||||||
|
protected $event_name;
|
||||||
|
protected EventResultBean $result;
|
||||||
|
protected EventResultTypeBean $result_type;
|
||||||
|
protected $transaction_id;
|
||||||
|
|
||||||
|
public function getBlockNumber()
|
||||||
|
{
|
||||||
|
return $this->block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockNumber($block_number): void
|
||||||
|
{
|
||||||
|
$this->block_number = $block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTimestamp()
|
||||||
|
{
|
||||||
|
return $this->block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTimestamp($block_timestamp): void
|
||||||
|
{
|
||||||
|
$this->block_timestamp = $block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCallerContractAddress()
|
||||||
|
{
|
||||||
|
return $this->caller_contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCallerContractAddress($caller_contract_address): void
|
||||||
|
{
|
||||||
|
$this->caller_contract_address = $caller_contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContractAddress()
|
||||||
|
{
|
||||||
|
return $this->contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContractAddress($contract_address): void
|
||||||
|
{
|
||||||
|
$this->contract_address = $contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEvent()
|
||||||
|
{
|
||||||
|
return $this->event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEvent($event): void
|
||||||
|
{
|
||||||
|
$this->event = $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventIndex()
|
||||||
|
{
|
||||||
|
return $this->event_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventIndex($event_index): void
|
||||||
|
{
|
||||||
|
$this->event_index = $event_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventName()
|
||||||
|
{
|
||||||
|
return $this->event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventName($event_name): void
|
||||||
|
{
|
||||||
|
$this->event_name = $event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResult(): EventResultBean
|
||||||
|
{
|
||||||
|
return $this->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResult(EventResultBean $result): void
|
||||||
|
{
|
||||||
|
$this->result = $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResultType(): EventResultTypeBean
|
||||||
|
{
|
||||||
|
return $this->result_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResultType(EventResultTypeBean $result_type): void
|
||||||
|
{
|
||||||
|
$this->result_type = $result_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTransactionId()
|
||||||
|
{
|
||||||
|
return $this->transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTransactionId($transaction_id): void
|
||||||
|
{
|
||||||
|
$this->transaction_id = $transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
84
app/Bean/Queue/Wallet/QueueNotifyToPlatformBean.php
Normal file
84
app/Bean/Queue/Wallet/QueueNotifyToPlatformBean.php
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Queue\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueNotifyToPlatformBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_notify_to_platform';
|
||||||
|
|
||||||
|
const TYPE_WITHDRAW = 1;
|
||||||
|
|
||||||
|
protected $type;
|
||||||
|
protected $sn;
|
||||||
|
protected $amount;
|
||||||
|
protected $currency_code;
|
||||||
|
protected $status;
|
||||||
|
protected $platform_id;
|
||||||
|
|
||||||
|
public function getPlatformId()
|
||||||
|
{
|
||||||
|
return $this->platform_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPlatformId($platform_id): void
|
||||||
|
{
|
||||||
|
$this->platform_id = $platform_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSn()
|
||||||
|
{
|
||||||
|
return $this->sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSn($sn): void
|
||||||
|
{
|
||||||
|
$this->sn = $sn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount()
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAmount($amount): void
|
||||||
|
{
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCurrencyCode()
|
||||||
|
{
|
||||||
|
return $this->currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCurrencyCode($currency_code): void
|
||||||
|
{
|
||||||
|
$this->currency_code = $currency_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getStatus()
|
||||||
|
{
|
||||||
|
return $this->status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStatus($status): void
|
||||||
|
{
|
||||||
|
$this->status = $status;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
35
app/Bean/Queue/Wallet/QueueWalletBlockBean.php
Normal file
35
app/Bean/Queue/Wallet/QueueWalletBlockBean.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueWalletBlockBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_wallet_block';
|
||||||
|
|
||||||
|
protected $id;
|
||||||
|
protected $block_number;
|
||||||
|
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id): void
|
||||||
|
{
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockNumber()
|
||||||
|
{
|
||||||
|
return $this->block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockNumber($block_number): void
|
||||||
|
{
|
||||||
|
$this->block_number = $block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
25
app/Bean/Queue/Wallet/QueueWalletBlockTransactionBean.php
Normal file
25
app/Bean/Queue/Wallet/QueueWalletBlockTransactionBean.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Queue\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueWalletBlockTransactionBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_wallet_block_transaction';
|
||||||
|
|
||||||
|
protected array $data = [];
|
||||||
|
|
||||||
|
public function getData(): array
|
||||||
|
{
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setData(array $data): void
|
||||||
|
{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
69
app/Bean/Queue/Wallet/QueueWalletPlatformTransactionBean.php
Normal file
69
app/Bean/Queue/Wallet/QueueWalletPlatformTransactionBean.php
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Bean\Queue\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueWalletPlatformTransactionBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_wallet_platform_transaction';
|
||||||
|
|
||||||
|
protected $wallet_id;
|
||||||
|
protected $wallet_transaction_id;
|
||||||
|
protected $block_transaction_id;
|
||||||
|
protected $amount;
|
||||||
|
protected $type;
|
||||||
|
|
||||||
|
public function getWalletId()
|
||||||
|
{
|
||||||
|
return $this->wallet_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWalletId($wallet_id): void
|
||||||
|
{
|
||||||
|
$this->wallet_id = $wallet_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getWalletTransactionId()
|
||||||
|
{
|
||||||
|
return $this->wallet_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setWalletTransactionId($wallet_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->wallet_transaction_id = $wallet_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTransactionId()
|
||||||
|
{
|
||||||
|
return $this->block_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTransactionId($block_transaction_id): void
|
||||||
|
{
|
||||||
|
$this->block_transaction_id = $block_transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAmount()
|
||||||
|
{
|
||||||
|
return $this->amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAmount($amount): void
|
||||||
|
{
|
||||||
|
$this->amount = $amount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Queue\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\QueueBaseBean;
|
||||||
|
|
||||||
|
class QueueWalletPlatformWithdrawTransferBean extends QueueBaseBean
|
||||||
|
{
|
||||||
|
const QUEUE_NAME = 'queue_wallet_platform_withdraw_transfer';
|
||||||
|
|
||||||
|
protected $transaction_id;
|
||||||
|
|
||||||
|
public function getTransactionId()
|
||||||
|
{
|
||||||
|
return $this->transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTransactionId($transaction_id): void
|
||||||
|
{
|
||||||
|
$this->transaction_id = $transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
88
app/Bean/Sdk/Wallet/Tron/AccountTransactionBean.php
Normal file
88
app/Bean/Sdk/Wallet/Tron/AccountTransactionBean.php
Normal file
@ -0,0 +1,88 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class AccountTransactionBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $transaction_id;
|
||||||
|
protected AccountTransactionTokenInfoBean $token_info;
|
||||||
|
protected $block_timestamp;
|
||||||
|
protected $from;
|
||||||
|
protected $to;
|
||||||
|
protected $type;
|
||||||
|
protected $value;
|
||||||
|
|
||||||
|
public function getTransactionId()
|
||||||
|
{
|
||||||
|
return $this->transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTransactionId($transaction_id): void
|
||||||
|
{
|
||||||
|
$this->transaction_id = $transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTokenInfo(): AccountTransactionTokenInfoBean
|
||||||
|
{
|
||||||
|
return $this->token_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTokenInfo(AccountTransactionTokenInfoBean $token_info): void
|
||||||
|
{
|
||||||
|
$this->token_info = $token_info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTimestamp()
|
||||||
|
{
|
||||||
|
return $this->block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTimestamp($block_timestamp): void
|
||||||
|
{
|
||||||
|
$this->block_timestamp = $block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFrom()
|
||||||
|
{
|
||||||
|
return $this->from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFrom($from): void
|
||||||
|
{
|
||||||
|
$this->from = $from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTo()
|
||||||
|
{
|
||||||
|
return $this->to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTo($to): void
|
||||||
|
{
|
||||||
|
$this->to = $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getType()
|
||||||
|
{
|
||||||
|
return $this->type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setType($type): void
|
||||||
|
{
|
||||||
|
$this->type = $type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value): void
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
55
app/Bean/Sdk/Wallet/Tron/AccountTransactionTokenInfoBean.php
Normal file
55
app/Bean/Sdk/Wallet/Tron/AccountTransactionTokenInfoBean.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class AccountTransactionTokenInfoBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $symbol;
|
||||||
|
protected $address;
|
||||||
|
protected $decimals;
|
||||||
|
protected $name;
|
||||||
|
|
||||||
|
public function getSymbol()
|
||||||
|
{
|
||||||
|
return $this->symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSymbol($symbol): void
|
||||||
|
{
|
||||||
|
$this->symbol = $symbol;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddress()
|
||||||
|
{
|
||||||
|
return $this->address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAddress($address): void
|
||||||
|
{
|
||||||
|
$this->address = $address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDecimals()
|
||||||
|
{
|
||||||
|
return $this->decimals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDecimals($decimals): void
|
||||||
|
{
|
||||||
|
$this->decimals = $decimals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setName($name): void
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
119
app/Bean/Sdk/Wallet/Tron/BlockEventBean.php
Normal file
119
app/Bean/Sdk/Wallet/Tron/BlockEventBean.php
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class BlockEventBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $block_number;
|
||||||
|
protected $block_timestamp;
|
||||||
|
protected $caller_contract_address;
|
||||||
|
protected $contract_address;
|
||||||
|
protected $event;
|
||||||
|
protected $event_index;
|
||||||
|
protected $event_name;
|
||||||
|
protected BlockEventResultBean $result;
|
||||||
|
protected $result_type;
|
||||||
|
protected $transaction_id;
|
||||||
|
|
||||||
|
public function getBlockNumber()
|
||||||
|
{
|
||||||
|
return $this->block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockNumber($block_number): void
|
||||||
|
{
|
||||||
|
$this->block_number = $block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTimestamp()
|
||||||
|
{
|
||||||
|
return $this->block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTimestamp($block_timestamp): void
|
||||||
|
{
|
||||||
|
$this->block_timestamp = $block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCallerContractAddress()
|
||||||
|
{
|
||||||
|
return $this->caller_contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCallerContractAddress($caller_contract_address): void
|
||||||
|
{
|
||||||
|
$this->caller_contract_address = $caller_contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContractAddress()
|
||||||
|
{
|
||||||
|
return $this->contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContractAddress($contract_address): void
|
||||||
|
{
|
||||||
|
$this->contract_address = $contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEvent()
|
||||||
|
{
|
||||||
|
return $this->event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEvent($event): void
|
||||||
|
{
|
||||||
|
$this->event = $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventIndex()
|
||||||
|
{
|
||||||
|
return $this->event_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventIndex($event_index): void
|
||||||
|
{
|
||||||
|
$this->event_index = $event_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventName()
|
||||||
|
{
|
||||||
|
return $this->event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventName($event_name): void
|
||||||
|
{
|
||||||
|
$this->event_name = $event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResult()
|
||||||
|
{
|
||||||
|
return $this->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResult($result): void
|
||||||
|
{
|
||||||
|
$this->result = $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResultType()
|
||||||
|
{
|
||||||
|
return $this->result_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResultType($result_type): void
|
||||||
|
{
|
||||||
|
$this->result_type = $result_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTransactionId()
|
||||||
|
{
|
||||||
|
return $this->transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTransactionId($transaction_id): void
|
||||||
|
{
|
||||||
|
$this->transaction_id = $transaction_id;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
44
app/Bean/Sdk/Wallet/Tron/BlockEventResultBean.php
Normal file
44
app/Bean/Sdk/Wallet/Tron/BlockEventResultBean.php
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class BlockEventResultBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $from;
|
||||||
|
protected $to;
|
||||||
|
protected $value;
|
||||||
|
|
||||||
|
public function getFrom()
|
||||||
|
{
|
||||||
|
return $this->from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFrom($from): void
|
||||||
|
{
|
||||||
|
$this->from = $from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTo()
|
||||||
|
{
|
||||||
|
return $this->to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTo($to): void
|
||||||
|
{
|
||||||
|
$this->to = $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value): void
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
120
app/Bean/Sdk/Wallet/Tron/EventBean.php
Normal file
120
app/Bean/Sdk/Wallet/Tron/EventBean.php
Normal file
@ -0,0 +1,120 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class EventBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $block_number;
|
||||||
|
protected $block_timestamp;
|
||||||
|
protected $caller_contract_address;
|
||||||
|
protected $contract_address;
|
||||||
|
protected $event;
|
||||||
|
protected $event_index;
|
||||||
|
protected $event_name;
|
||||||
|
protected EventResultBean $result;
|
||||||
|
protected EventResultTypeBean $result_type;
|
||||||
|
protected $transaction_id;
|
||||||
|
|
||||||
|
public function getBlockNumber()
|
||||||
|
{
|
||||||
|
return $this->block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockNumber($block_number): void
|
||||||
|
{
|
||||||
|
$this->block_number = $block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTimestamp()
|
||||||
|
{
|
||||||
|
return $this->block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTimestamp($block_timestamp): void
|
||||||
|
{
|
||||||
|
$this->block_timestamp = $block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCallerContractAddress()
|
||||||
|
{
|
||||||
|
return $this->caller_contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCallerContractAddress($caller_contract_address): void
|
||||||
|
{
|
||||||
|
$this->caller_contract_address = $caller_contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContractAddress()
|
||||||
|
{
|
||||||
|
return $this->contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContractAddress($contract_address): void
|
||||||
|
{
|
||||||
|
$this->contract_address = $contract_address;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEvent()
|
||||||
|
{
|
||||||
|
return $this->event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEvent($event): void
|
||||||
|
{
|
||||||
|
$this->event = $event;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventIndex()
|
||||||
|
{
|
||||||
|
return $this->event_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventIndex($event_index): void
|
||||||
|
{
|
||||||
|
$this->event_index = $event_index;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getEventName()
|
||||||
|
{
|
||||||
|
return $this->event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEventName($event_name): void
|
||||||
|
{
|
||||||
|
$this->event_name = $event_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResult(): EventResultBean
|
||||||
|
{
|
||||||
|
return $this->result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResult(EventResultBean $result): void
|
||||||
|
{
|
||||||
|
$this->result = $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResultType(): EventResultTypeBean
|
||||||
|
{
|
||||||
|
return $this->result_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResultType(EventResultTypeBean $result_type): void
|
||||||
|
{
|
||||||
|
$this->result_type = $result_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTransactionId()
|
||||||
|
{
|
||||||
|
return $this->transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTransactionId($transaction_id): void
|
||||||
|
{
|
||||||
|
$this->transaction_id = $transaction_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
43
app/Bean/Sdk/Wallet/Tron/EventResultBean.php
Normal file
43
app/Bean/Sdk/Wallet/Tron/EventResultBean.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class EventResultBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $from;
|
||||||
|
protected $to;
|
||||||
|
protected $value;
|
||||||
|
|
||||||
|
public function getFrom()
|
||||||
|
{
|
||||||
|
return $this->from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFrom($from): void
|
||||||
|
{
|
||||||
|
$this->from = $from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTo()
|
||||||
|
{
|
||||||
|
return $this->to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTo($to): void
|
||||||
|
{
|
||||||
|
$this->to = $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value): void
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
43
app/Bean/Sdk/Wallet/Tron/EventResultTypeBean.php
Normal file
43
app/Bean/Sdk/Wallet/Tron/EventResultTypeBean.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class EventResultTypeBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $from;
|
||||||
|
protected $to;
|
||||||
|
protected $value;
|
||||||
|
|
||||||
|
public function getFrom()
|
||||||
|
{
|
||||||
|
return $this->from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFrom($from): void
|
||||||
|
{
|
||||||
|
$this->from = $from;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTo()
|
||||||
|
{
|
||||||
|
return $this->to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTo($to): void
|
||||||
|
{
|
||||||
|
$this->to = $to;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getValue()
|
||||||
|
{
|
||||||
|
return $this->value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setValue($value): void
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
55
app/Bean/Sdk/Wallet/Tron/MetaBean.php
Normal file
55
app/Bean/Sdk/Wallet/Tron/MetaBean.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class MetaBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $at;
|
||||||
|
protected $fingerprint;
|
||||||
|
protected MetaLinksBean $links;
|
||||||
|
protected $page_size;
|
||||||
|
|
||||||
|
public function getAt()
|
||||||
|
{
|
||||||
|
return $this->at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAt($at): void
|
||||||
|
{
|
||||||
|
$this->at = $at;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getFingerprint()
|
||||||
|
{
|
||||||
|
return $this->fingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setFingerprint($fingerprint): void
|
||||||
|
{
|
||||||
|
$this->fingerprint = $fingerprint;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getLinks(): MetaLinksBean
|
||||||
|
{
|
||||||
|
return $this->links;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setLinks(MetaLinksBean $links): void
|
||||||
|
{
|
||||||
|
$this->links = $links;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPageSize()
|
||||||
|
{
|
||||||
|
return $this->page_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPageSize($page_size): void
|
||||||
|
{
|
||||||
|
$this->page_size = $page_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
10
app/Bean/Sdk/Wallet/Tron/MetaLinksBean.php
Normal file
10
app/Bean/Sdk/Wallet/Tron/MetaLinksBean.php
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class MetaLinksBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $next;
|
||||||
|
|
||||||
|
}
|
||||||
34
app/Bean/Sdk/Wallet/Tron/NowBlockBean.php
Normal file
34
app/Bean/Sdk/Wallet/Tron/NowBlockBean.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class NowBlockBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $block_number;
|
||||||
|
protected $block_timestamp;
|
||||||
|
|
||||||
|
public function getBlockNumber()
|
||||||
|
{
|
||||||
|
return $this->block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockNumber($block_number): void
|
||||||
|
{
|
||||||
|
$this->block_number = $block_number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getBlockTimestamp()
|
||||||
|
{
|
||||||
|
return $this->block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setBlockTimestamp($block_timestamp): void
|
||||||
|
{
|
||||||
|
$this->block_timestamp = $block_timestamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
43
app/Bean/Sdk/Wallet/Tron/ResponseBean.php
Normal file
43
app/Bean/Sdk/Wallet/Tron/ResponseBean.php
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class ResponseBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $data;
|
||||||
|
protected bool $success;
|
||||||
|
protected MetaBean $meta;
|
||||||
|
|
||||||
|
public function getData()
|
||||||
|
{
|
||||||
|
return $this->data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setData($data): void
|
||||||
|
{
|
||||||
|
$this->data = $data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getSuccess(): bool
|
||||||
|
{
|
||||||
|
return $this->success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setSuccess($success): void
|
||||||
|
{
|
||||||
|
$this->success = $success;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getMeta(): MetaBean
|
||||||
|
{
|
||||||
|
return $this->meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setMeta($meta): void
|
||||||
|
{
|
||||||
|
$this->meta = $meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
55
app/Bean/Sdk/Wallet/Tron/TokenAddressBean.php
Normal file
55
app/Bean/Sdk/Wallet/Tron/TokenAddressBean.php
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class TokenAddressBean extends BaseBean
|
||||||
|
{
|
||||||
|
public $private_key;
|
||||||
|
public $public_key;
|
||||||
|
public $address_hex;
|
||||||
|
public $address_base58;
|
||||||
|
|
||||||
|
public function getPrivateKey()
|
||||||
|
{
|
||||||
|
return $this->private_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPrivateKey($private_key): void
|
||||||
|
{
|
||||||
|
$this->private_key = $private_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPublicKey()
|
||||||
|
{
|
||||||
|
return $this->public_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPublicKey($public_key): void
|
||||||
|
{
|
||||||
|
$this->public_key = $public_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddressHex()
|
||||||
|
{
|
||||||
|
return $this->address_hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAddressHex($address_hex): void
|
||||||
|
{
|
||||||
|
$this->address_hex = $address_hex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAddressBase58()
|
||||||
|
{
|
||||||
|
return $this->address_base58;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAddressBase58($address_base58): void
|
||||||
|
{
|
||||||
|
$this->address_base58 = $address_base58;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
33
app/Bean/Sdk/Wallet/Tron/TransferTransactionBean.php
Normal file
33
app/Bean/Sdk/Wallet/Tron/TransferTransactionBean.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Sdk\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class TransferTransactionBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $txID;
|
||||||
|
protected $raw_data;
|
||||||
|
|
||||||
|
public function getTxID()
|
||||||
|
{
|
||||||
|
return $this->txID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTxID($txID): void
|
||||||
|
{
|
||||||
|
$this->txID = $txID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRawData()
|
||||||
|
{
|
||||||
|
return $this->raw_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRawData($raw_data): void
|
||||||
|
{
|
||||||
|
$this->raw_data = $raw_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
23
app/Bean/Service/HttpServiceConfigBean.php
Normal file
23
app/Bean/Service/HttpServiceConfigBean.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Service;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class HttpServiceConfigBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected bool $is_return_json = true;
|
||||||
|
|
||||||
|
public function isIsReturnJson(): bool
|
||||||
|
{
|
||||||
|
return $this->is_return_json;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setIsReturnJson(bool $is_return_json): void
|
||||||
|
{
|
||||||
|
$this->is_return_json = $is_return_json;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
66
app/Bean/Service/HttpServiceReturnLogBean.php
Normal file
66
app/Bean/Service/HttpServiceReturnLogBean.php
Normal file
@ -0,0 +1,66 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Bean\Service;
|
||||||
|
|
||||||
|
use App\Bean\Model\Base\BaseBean;
|
||||||
|
|
||||||
|
class HttpServiceReturnLogBean extends BaseBean
|
||||||
|
{
|
||||||
|
protected $request_url;
|
||||||
|
protected $request_data;
|
||||||
|
protected $request_header;
|
||||||
|
protected $response_body;
|
||||||
|
protected $response_status_code;
|
||||||
|
|
||||||
|
public function getResponseStatusCode()
|
||||||
|
{
|
||||||
|
return $this->response_status_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResponseStatusCode($response_status_code): void
|
||||||
|
{
|
||||||
|
$this->response_status_code = $response_status_code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequestUrl()
|
||||||
|
{
|
||||||
|
return $this->request_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRequestUrl($request_url): void
|
||||||
|
{
|
||||||
|
$this->request_url = $request_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequestData()
|
||||||
|
{
|
||||||
|
return $this->request_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRequestData($request_data): void
|
||||||
|
{
|
||||||
|
$this->request_data = $request_data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getRequestHeader()
|
||||||
|
{
|
||||||
|
return $this->request_header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setRequestHeader($request_header): void
|
||||||
|
{
|
||||||
|
$this->request_header = $request_header;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getResponseBody()
|
||||||
|
{
|
||||||
|
return $this->response_body;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setResponseBody($response_body): void
|
||||||
|
{
|
||||||
|
$this->response_body = $response_body;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -29,24 +29,36 @@ abstract class BaseCache
|
|||||||
{
|
{
|
||||||
$sCacheKey = $this->getPrimaryKey();
|
$sCacheKey = $this->getPrimaryKey();
|
||||||
$aData = $this->loadData();
|
$aData = $this->loadData();
|
||||||
|
|
||||||
if (empty($aData)) return false;
|
if (empty($aData)) return false;
|
||||||
return Cache::put($sCacheKey, serialize($aData), self::CACHE_TTL);
|
return Cache::put($sCacheKey, $aData, self::CACHE_TTL);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract function loadData(): array|null;
|
abstract function loadData(): array|string|null;
|
||||||
|
|
||||||
function getCacheData($primary_key = null): array|null
|
function get($key): array|string|null
|
||||||
{
|
{
|
||||||
|
return $this->getCacheData($key);
|
||||||
|
}
|
||||||
|
function del($key): bool
|
||||||
|
{
|
||||||
|
return $this->delCacheData($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCacheData($primary_key = null): array|string|null
|
||||||
|
{
|
||||||
|
|
||||||
if ($primary_key === null) $primary_key = $this->primary_key;
|
if ($primary_key === null) $primary_key = $this->primary_key;
|
||||||
if (empty($primary_key)) return [];
|
if (empty($primary_key)) return [];
|
||||||
$sCacheKey = $this->getPrimaryKey($primary_key);
|
$sCacheKey = $this->getPrimaryKey($primary_key);
|
||||||
$sData = Cache::get($sCacheKey);
|
$sData = Cache::get($sCacheKey);
|
||||||
if (empty($sData)) {
|
if (empty($sData)) {
|
||||||
$this->primary_key = $primary_key;
|
$this->primary_key = $primary_key;
|
||||||
if($this->loadToCache()) $sData = Cache::get($sCacheKey);
|
|
||||||
|
if ($this->loadToCache()) $sData = Cache::get($sCacheKey);
|
||||||
}
|
}
|
||||||
if (empty($sData)) return null;
|
if (empty($sData)) return null;
|
||||||
return unserialize($sData);
|
return $sData;
|
||||||
}
|
}
|
||||||
|
|
||||||
//根据primary_key获取缓存数据单个值,不指定key就默认获取所有
|
//根据primary_key获取缓存数据单个值,不指定key就默认获取所有
|
||||||
@ -55,7 +67,7 @@ abstract class BaseCache
|
|||||||
if ($primary_key === null) $primary_key = $this->primary_key;
|
if ($primary_key === null) $primary_key = $this->primary_key;
|
||||||
if (empty($primary_key)) return false;
|
if (empty($primary_key)) return false;
|
||||||
$aData = $this->getCacheData($primary_key);
|
$aData = $this->getCacheData($primary_key);
|
||||||
if(empty($aData)) return null;
|
if (empty($aData)) return null;
|
||||||
if (empty($key)) return $aData;
|
if (empty($key)) return $aData;
|
||||||
return $aData[$key] ?? '';
|
return $aData[$key] ?? '';
|
||||||
}
|
}
|
||||||
@ -68,4 +80,10 @@ abstract class BaseCache
|
|||||||
return Cache::forget($sCacheKey);
|
return Cache::forget($sCacheKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearAll(): bool
|
||||||
|
{
|
||||||
|
if (empty($this->primary_prefix)) return false;
|
||||||
|
return Cache::forget($this->primary_prefix);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
42
app/Cache/Base/KeyBaseCache.php
Normal file
42
app/Cache/Base/KeyBaseCache.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Cache\Base;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
|
||||||
|
abstract class KeyBaseCache
|
||||||
|
{
|
||||||
|
protected string $prefix = 'Key:'; //缓存前缀
|
||||||
|
const CACHE_TTL = 60 * 60 * 24 * 3; //缓存时间 3天
|
||||||
|
|
||||||
|
function getByKey($key): string|array|bool|null
|
||||||
|
{
|
||||||
|
return Cache::get($key);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setKey($key, $value): bool
|
||||||
|
{
|
||||||
|
return Cache::put($this->getKey($key), $value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setKeyWithExp($key, $value, $exp = self::CACHE_TTL): bool
|
||||||
|
{
|
||||||
|
return Cache::put($this->getKey($key), $value, $exp);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPrefix(): string
|
||||||
|
{
|
||||||
|
return $this->prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getKey($key): string
|
||||||
|
{
|
||||||
|
return $this->getPrefix().$key;
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeKey($key): bool
|
||||||
|
{
|
||||||
|
return Cache::forget($this->getKey($key));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
59
app/Cache/Base/SetBaseCache.php
Normal file
59
app/Cache/Base/SetBaseCache.php
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Cache\Base;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Cache;
|
||||||
|
use Illuminate\Support\Facades\Redis;
|
||||||
|
|
||||||
|
//无序集合缓存基类
|
||||||
|
abstract class SetBaseCache
|
||||||
|
{
|
||||||
|
|
||||||
|
protected $client;
|
||||||
|
protected string $prefix = 'Set:'; //缓存前缀
|
||||||
|
protected string $set_name = ''; //集合名
|
||||||
|
const CACHE_TTL = 60 * 60 * 24 * 3; //缓存时间 3天
|
||||||
|
|
||||||
|
function getRedis()
|
||||||
|
{
|
||||||
|
if(!$this->client) $this->client = Redis::client();
|
||||||
|
return $this->client ;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAll(): bool
|
||||||
|
{
|
||||||
|
return $this->getRedis()->sMembers($this->getSetName());
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkKey($value): bool
|
||||||
|
{
|
||||||
|
return $this->getRedis()->sIsMember($this->getSetName(),$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function setKey($value): bool
|
||||||
|
{
|
||||||
|
return $this->getRedis()->sAdd($this->getSetName(),$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function removeKey($value): bool
|
||||||
|
{
|
||||||
|
return $this->getRedis()->sRem($this->getSetName(),$value);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getCount()
|
||||||
|
{
|
||||||
|
return $this->getRedis()->sCard($this->getSetName());
|
||||||
|
}
|
||||||
|
|
||||||
|
function getPrefix(): string
|
||||||
|
{
|
||||||
|
return $this->prefix;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getSetName(): string
|
||||||
|
{
|
||||||
|
return $this->getPrefix().$this->set_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -10,20 +10,23 @@ abstract class TableBaseCache extends BaseCache
|
|||||||
public array $get_columns = ['*'];
|
public array $get_columns = ['*'];
|
||||||
public array $get_exclude_columns = [];
|
public array $get_exclude_columns = [];
|
||||||
|
|
||||||
function loadTable(): array|null
|
function loadTable(): array|string|null
|
||||||
{
|
{
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function loadData(): array|null
|
function loadData(): array|string|null
|
||||||
{
|
{
|
||||||
|
|
||||||
//默认获取表数据方式
|
//默认获取表数据方式
|
||||||
if (!empty($table_class)) {
|
if (!empty($table_class)) {
|
||||||
|
|
||||||
$oTable = new $this->table_class();
|
$oTable = new $this->table_class();
|
||||||
//排除不需要的字段
|
//排除不需要的字段
|
||||||
if (!empty($this->get_exclude_columns) && $this->get_columns != ['*']) $this->get_columns = array_diff($this->get_columns, $this->get_exclude_columns);
|
if (!empty($this->get_exclude_columns) && $this->get_columns != ['*']) $this->get_columns = array_diff($this->get_columns, $this->get_exclude_columns);
|
||||||
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
||||||
if($oData->isEmpty()) return null;
|
if ($oData->isEmpty()) return null;
|
||||||
$aData = $oData->toArray();
|
$aData = $oData->toArray();
|
||||||
//排除不需要的字段
|
//排除不需要的字段
|
||||||
if (!empty($this->get_exclude_columns) && $this->get_columns == ['*'] && !empty($aData)) {
|
if (!empty($this->get_exclude_columns) && $this->get_columns == ['*'] && !empty($aData)) {
|
||||||
|
|||||||
23
app/Cache/Key/TronKeyCache.php
Normal file
23
app/Cache/Key/TronKeyCache.php
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Cache\Key;
|
||||||
|
|
||||||
|
use App\Cache\Base\KeyBaseCache;
|
||||||
|
|
||||||
|
class TronKeyCache extends KeyBaseCache
|
||||||
|
{
|
||||||
|
protected string $prefix = 'WalletTronKeyCache:'; //缓存前缀
|
||||||
|
|
||||||
|
const NOW_BLOCK = 'nowBlock'; //当前区块
|
||||||
|
|
||||||
|
function setNowBlock(string $block): bool
|
||||||
|
{
|
||||||
|
return $this->setKey(self::NOW_BLOCK, $block);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNowBlock(): bool|array|string|null
|
||||||
|
{
|
||||||
|
return $this->getByKey(self::NOW_BLOCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
11
app/Cache/Set/TronWalletAddressSetCache.php
Normal file
11
app/Cache/Set/TronWalletAddressSetCache.php
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Cache\Set;
|
||||||
|
|
||||||
|
use App\Cache\Base\SetBaseCache;
|
||||||
|
|
||||||
|
class TronWalletAddressSetCache extends SetBaseCache
|
||||||
|
{
|
||||||
|
protected string $set_name = 'TronWalletAddressSetCache:'; //缓存前缀
|
||||||
|
|
||||||
|
}
|
||||||
42
app/Cache/Table/Api/TableCustomerSettingCache.php
Normal file
42
app/Cache/Table/Api/TableCustomerSettingCache.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Cache\Table\Api;
|
||||||
|
|
||||||
|
use App\Cache\Base\TableBaseCache;
|
||||||
|
use App\Models\Api\Other\CustomerSettingModel;
|
||||||
|
|
||||||
|
//用户缓存用户基础信息(结构自己组装不完全等于数据表)uid为主键
|
||||||
|
class TableCustomerSettingCache extends TableBaseCache
|
||||||
|
{
|
||||||
|
|
||||||
|
public string $table_class = CustomerSettingModel::class;
|
||||||
|
public string $primary_prefix = 'TableCustomerSettingCache:'; //后面跟name
|
||||||
|
|
||||||
|
public string $primary_key_column = 'name';
|
||||||
|
public array $get_columns = [
|
||||||
|
'value',
|
||||||
|
];
|
||||||
|
|
||||||
|
const NAME_WITHDRAW_FEE_AMOUNT = 'withdraw_fee_amount';
|
||||||
|
|
||||||
|
//只存值 key为name value为value
|
||||||
|
function loadData(): array|string|null
|
||||||
|
{
|
||||||
|
$oTable = new $this->table_class();
|
||||||
|
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
||||||
|
if ($oData->isEmpty()) return null;
|
||||||
|
$aData = $oData->toArray();
|
||||||
|
|
||||||
|
if (empty($aData)) return null;
|
||||||
|
return $aData['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWithdrawFeeAmount(): string|null
|
||||||
|
{
|
||||||
|
$res = $this->get(self::NAME_WITHDRAW_FEE_AMOUNT);
|
||||||
|
if (empty($res)) $res = 0;
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Cache\Table;
|
|
||||||
|
namespace App\Cache\Table\Api;
|
||||||
|
|
||||||
use App\Cache\Base\TableBaseCache;
|
use App\Cache\Base\TableBaseCache;
|
||||||
use App\Models\Api\Customer\CustomerUserModel;
|
use App\Models\Api\Customer\CustomerUserModel;
|
||||||
@ -17,6 +18,18 @@ class TableCustomerUserCache extends TableBaseCache
|
|||||||
'google_auth_secret',
|
'google_auth_secret',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function loadData(): array|string|null
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
$oTable = new $this->table_class();
|
||||||
|
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
||||||
|
|
||||||
|
if (!$oData) return null;
|
||||||
|
|
||||||
|
$aData = $oData->toArray();
|
||||||
|
if (empty($aData)) return null;
|
||||||
|
|
||||||
|
return $aData;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
26
app/Cache/Table/Wallet/TableWalletPlatformCache.php
Normal file
26
app/Cache/Table/Wallet/TableWalletPlatformCache.php
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Cache\Table\Wallet;
|
||||||
|
|
||||||
|
use App\Cache\Base\TableBaseCache;
|
||||||
|
use App\Models\Wallet\Other\WalletSettingModel;
|
||||||
|
use App\Models\Wallet\Platform\WalletPlatformModel;
|
||||||
|
|
||||||
|
//用户缓存用户基础信息(结构自己组装不完全等于数据表)uid为主键
|
||||||
|
class TableWalletPlatformCache extends TableBaseCache
|
||||||
|
{
|
||||||
|
|
||||||
|
public string $table_class = WalletPlatformModel::class;
|
||||||
|
public string $primary_prefix = 'TableWalletPlatformCache:'; //后面跟name
|
||||||
|
|
||||||
|
public string $primary_key_column = 'id';
|
||||||
|
public array $get_columns = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'code',
|
||||||
|
'appid',
|
||||||
|
'secret',
|
||||||
|
'notify_ip',
|
||||||
|
'created_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
41
app/Cache/Table/Wallet/TableWalletSettingCache.php
Normal file
41
app/Cache/Table/Wallet/TableWalletSettingCache.php
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Cache\Table\Wallet;
|
||||||
|
|
||||||
|
use App\Cache\Base\TableBaseCache;
|
||||||
|
use App\Models\Wallet\Other\WalletSettingModel;
|
||||||
|
|
||||||
|
//用户缓存用户基础信息(结构自己组装不完全等于数据表)uid为主键
|
||||||
|
class TableWalletSettingCache extends TableBaseCache
|
||||||
|
{
|
||||||
|
|
||||||
|
public string $table_class = WalletSettingModel::class;
|
||||||
|
public string $primary_prefix = 'TableWalletSettingCache:'; //后面跟name
|
||||||
|
|
||||||
|
public string $primary_key_column = 'name';
|
||||||
|
public array $get_columns = [
|
||||||
|
'value',
|
||||||
|
];
|
||||||
|
|
||||||
|
const NAME_WITHDRAW_FEE_AMOUNT = 'withdraw_fee_amount';
|
||||||
|
|
||||||
|
//只存值 key为name value为value
|
||||||
|
function loadData(): array|string|null
|
||||||
|
{
|
||||||
|
$oTable = new $this->table_class();
|
||||||
|
$oData = $oTable->findItemByWhere([$this->primary_key_column => $this->primary_key], $this->get_columns);
|
||||||
|
if ($oData->isEmpty()) return null;
|
||||||
|
$aData = $oData->toArray();
|
||||||
|
|
||||||
|
if (empty($aData)) return null;
|
||||||
|
return $aData['value'];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWithdrawFeeAmount(): string|null
|
||||||
|
{
|
||||||
|
$res = $this->get(self::NAME_WITHDRAW_FEE_AMOUNT);
|
||||||
|
if (empty($res)) $res = 0;
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,18 +1,18 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands\Api;
|
||||||
|
|
||||||
use App\Models\Api\Customer\CustomerUserExtendModel;
|
use App\Models\Api\Customer\CustomerUserExtendModel;
|
||||||
use Illuminate\Console\Command;
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
class DailyCheckUserActiveStatus extends Command
|
class DailyCheckUserActiveStatusCmd extends Command
|
||||||
{
|
{
|
||||||
/**
|
/**
|
||||||
* The name and signature of the console command.
|
* The name and signature of the console command.
|
||||||
*
|
*
|
||||||
* @var string
|
* @var string
|
||||||
*/
|
*/
|
||||||
protected $signature = 'app:daily-check-user-active-status';
|
protected $signature = 'app:daily-check-user-active-status-cmd';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The console command description.
|
* The console command description.
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Api;
|
||||||
|
|
||||||
|
use App\Models\Api\Wallet\CustomerWalletBalanceTransactionModel;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class HourCustomerWalletTrsDelayPayCmd extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'app:hour-customer-wallet-trs-delay-pay-cmd';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = '每小时检查用户钱包交易延迟支付';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->info('每小时检查用户钱包交易延迟支付');
|
||||||
|
$this->info('开始...');
|
||||||
|
$oCustomerWalletBalanceTransactionModel = new CustomerWalletBalanceTransactionModel();
|
||||||
|
$oCustomerWalletBalanceTransactionModel->dealDelayPaymentTransactionCmd();
|
||||||
|
$this->info('结束...');
|
||||||
|
}
|
||||||
|
}
|
||||||
35
app/Console/Commands/Api/SecondsWalletBlockCheckCmd.php
Normal file
35
app/Console/Commands/Api/SecondsWalletBlockCheckCmd.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Console\Commands\Api;
|
||||||
|
|
||||||
|
use App\Service\Wallet\Coin\Tron\UsdtTrx20Service;
|
||||||
|
use Illuminate\Console\Command;
|
||||||
|
|
||||||
|
class SecondsWalletBlockCheckCmd extends Command
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name and signature of the console command.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $signature = 'app:seconds-wallet-block-check-cmd';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The console command description.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $description = '每2秒检查最新链上区块';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the console command.
|
||||||
|
*/
|
||||||
|
public function handle()
|
||||||
|
{
|
||||||
|
$this->info('每2秒检查最新链上区块');
|
||||||
|
$this->info('开始...');
|
||||||
|
$oUsdtTrx20Service = new UsdtTrx20Service();
|
||||||
|
$oUsdtTrx20Service->checkNowBlock();
|
||||||
|
$this->info('结束...');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -13,7 +13,9 @@ class Kernel extends ConsoleKernel
|
|||||||
protected function schedule(Schedule $schedule): void
|
protected function schedule(Schedule $schedule): void
|
||||||
{
|
{
|
||||||
// $schedule->command('inspire')->hourly();
|
// $schedule->command('inspire')->hourly();
|
||||||
$schedule->command('app:daily-check-user-active-status')->dailyAt('00:30')->onOneServer();
|
$schedule->command('app:daily-check-user-active-status-cmd')->dailyAt('00:30')->onOneServer();
|
||||||
|
$schedule->command('app:hour-customer-wallet-trs-delay-pay-cmd')->hourly()->onOneServer();
|
||||||
|
$schedule->command('app:seconds-wallet-block-check-cmd')->everyTwoSeconds()->onOneServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
8
app/Const/Prefix.php
Normal file
8
app/Const/Prefix.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Const;
|
||||||
|
|
||||||
|
class Prefix{
|
||||||
|
|
||||||
|
const ORDER_SN_PREFIX = 'SN_';
|
||||||
|
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Exceptions;
|
namespace App\Exceptions;
|
||||||
|
|
||||||
use App\Service\ReplyService;
|
use App\Service\Api\ReplyService;
|
||||||
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@ -27,6 +27,7 @@ class Handler extends ExceptionHandler
|
|||||||
*/
|
*/
|
||||||
public function register(): void
|
public function register(): void
|
||||||
{
|
{
|
||||||
|
|
||||||
$this->renderable(function (NotFoundHttpException $e, Request $request) {
|
$this->renderable(function (NotFoundHttpException $e, Request $request) {
|
||||||
return ReplyService::error( 'record not find');
|
return ReplyService::error( 'record not find');
|
||||||
});
|
});
|
||||||
|
|||||||
8
app/Exceptions/PlatformNotifyException.php
Normal file
8
app/Exceptions/PlatformNotifyException.php
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
class PlatformNotifyException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
7
app/Exceptions/QueueException.php
Normal file
7
app/Exceptions/QueueException.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
class QueueException extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
7
app/Exceptions/WalletException.php
Normal file
7
app/Exceptions/WalletException.php
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
class WalletException extends \Exception
|
||||||
|
{
|
||||||
|
}
|
||||||
9
app/Exceptions/WalletSdkException.php
Normal file
9
app/Exceptions/WalletSdkException.php
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Exceptions;
|
||||||
|
|
||||||
|
class WalletSdkException extends \Exception
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Http\Controllers\Base;
|
namespace App\Http\Controllers\Base;
|
||||||
|
|
||||||
use App\Service\ReplyService;
|
use App\Service\Api\ReplyService;
|
||||||
use Illuminate\Routing\Controller;
|
use Illuminate\Routing\Controller;
|
||||||
|
|
||||||
abstract class BaseController extends Controller
|
abstract class BaseController extends Controller
|
||||||
@ -29,7 +29,7 @@ abstract class BaseController extends Controller
|
|||||||
|
|
||||||
function error($msg = 'error', $data = []): \Illuminate\Http\JsonResponse
|
function error($msg = 'error', $data = []): \Illuminate\Http\JsonResponse
|
||||||
{
|
{
|
||||||
ReplyService::error($msg, $data);
|
return ReplyService::error($msg, $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,9 +7,9 @@ use App\Const\VrCode;
|
|||||||
use App\Exceptions\AppException;
|
use App\Exceptions\AppException;
|
||||||
use App\Http\Controllers\Base\CustomerBaseController;
|
use App\Http\Controllers\Base\CustomerBaseController;
|
||||||
use App\Models\Api\Customer\CustomerUserModel;
|
use App\Models\Api\Customer\CustomerUserModel;
|
||||||
use App\Service\AuthService;
|
use App\Service\Api\AuthService;
|
||||||
use App\Service\ImService;
|
use App\Service\Api\ImService;
|
||||||
use App\Service\VrCodeService;
|
use App\Service\Api\VrCodeService;
|
||||||
use App\Tools\Tools;
|
use App\Tools\Tools;
|
||||||
|
|
||||||
class CustomerUserController extends CustomerBaseController
|
class CustomerUserController extends CustomerBaseController
|
||||||
@ -49,6 +49,7 @@ class CustomerUserController extends CustomerBaseController
|
|||||||
{
|
{
|
||||||
$oAuthService = new AuthService();
|
$oAuthService = new AuthService();
|
||||||
$token = $oAuthService->getTokenFromReq();
|
$token = $oAuthService->getTokenFromReq();
|
||||||
|
var_dump($token);
|
||||||
$aUser = $oAuthService->getCurrentUser();
|
$aUser = $oAuthService->getCurrentUser();
|
||||||
$data = [
|
$data = [
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
@ -102,8 +103,8 @@ class CustomerUserController extends CustomerBaseController
|
|||||||
$oAuthService = new AuthService();
|
$oAuthService = new AuthService();
|
||||||
$oImService = new ImService();
|
$oImService = new ImService();
|
||||||
$token = $oAuthService->createTokenToUser($oUser->id, $device);
|
$token = $oAuthService->createTokenToUser($oUser->id, $device);
|
||||||
$imToken = $oImService->authUserToken($oUser->id, $device);
|
$imToken = "test";
|
||||||
|
//$imToken = $oImService->authUserToken($oUser->id, $device);
|
||||||
$data = [
|
$data = [
|
||||||
'token' => $token,
|
'token' => $token,
|
||||||
'im_token' => $imToken,
|
'im_token' => $imToken,
|
||||||
@ -157,7 +158,7 @@ class CustomerUserController extends CustomerBaseController
|
|||||||
$password = $request->input('password');
|
$password = $request->input('password');
|
||||||
$device = $request->input('device');
|
$device = $request->input('device');
|
||||||
$sVrCode = $request->input('vr_code');
|
$sVrCode = $request->input('vr_code');
|
||||||
|
var_dump($sVrCode);
|
||||||
|
|
||||||
//check vrcode
|
//check vrcode
|
||||||
$oVrCodeService = new VrCodeService();
|
$oVrCodeService = new VrCodeService();
|
||||||
@ -186,7 +187,8 @@ class CustomerUserController extends CustomerBaseController
|
|||||||
|
|
||||||
//向im注册
|
//向im注册
|
||||||
$oImService = new ImService();
|
$oImService = new ImService();
|
||||||
if (!$oImService->userUserRegister($oUser->id)) throw new AppException('im register error');
|
//暂时不注册
|
||||||
|
// if (!$oImService->userUserRegister($oUser->id)) throw new AppException('im register error');
|
||||||
|
|
||||||
$oAuthService = new AuthService();
|
$oAuthService = new AuthService();
|
||||||
$token = $oAuthService->createTokenToUser($oUser->id, $device);
|
$token = $oAuthService->createTokenToUser($oUser->id, $device);
|
||||||
|
|||||||
@ -6,7 +6,7 @@ namespace App\Http\Controllers\Follow;
|
|||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Http\Controllers\Base\BaseController;
|
use App\Http\Controllers\Base\BaseController;
|
||||||
use App\Models\Api\Follow\FollowModel;
|
use App\Models\Api\Follow\FollowModel;
|
||||||
use App\Service\AuthService;
|
use App\Service\Api\AuthService;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
|
|
||||||
|
|||||||
@ -4,7 +4,7 @@
|
|||||||
namespace App\Http\Controllers\Post;
|
namespace App\Http\Controllers\Post;
|
||||||
|
|
||||||
use App\Http\Controllers\Base\BaseController;
|
use App\Http\Controllers\Base\BaseController;
|
||||||
use App\Service\AuthService;
|
use App\Service\Api\AuthService;
|
||||||
|
|
||||||
class PostController extends BaseController
|
class PostController extends BaseController
|
||||||
{
|
{
|
||||||
|
|||||||
@ -5,8 +5,8 @@ use App\Const\VrCode;
|
|||||||
use App\Exceptions\AppException;
|
use App\Exceptions\AppException;
|
||||||
use App\Http\Controllers\Base\CustomerBaseController;
|
use App\Http\Controllers\Base\CustomerBaseController;
|
||||||
use App\Models\Api\Customer\CustomerUserModel;
|
use App\Models\Api\Customer\CustomerUserModel;
|
||||||
use App\Service\AuthService;
|
use App\Service\Api\AuthService;
|
||||||
use App\Service\VrCodeService;
|
use App\Service\Api\VrCodeService;
|
||||||
use Illuminate\Support\Facades\Validator;
|
use Illuminate\Support\Facades\Validator;
|
||||||
use Psr\Container\ContainerExceptionInterface;
|
use Psr\Container\ContainerExceptionInterface;
|
||||||
use Psr\Container\NotFoundExceptionInterface;
|
use Psr\Container\NotFoundExceptionInterface;
|
||||||
@ -40,7 +40,7 @@ class SmsController extends CustomerBaseController
|
|||||||
|
|
||||||
$validator = Validator::make($aReqData, [
|
$validator = Validator::make($aReqData, [
|
||||||
'phone_area' => 'required|alpha_dash:ascii|max:5',
|
'phone_area' => 'required|alpha_dash:ascii|max:5',
|
||||||
'phone' => 'required|numeric|max:15',
|
'phone' => 'required|digits_between:6,15',
|
||||||
]);
|
]);
|
||||||
if ($validator->fails()) {
|
if ($validator->fails()) {
|
||||||
return $this->error($validator->errors()->first());
|
return $this->error($validator->errors()->first());
|
||||||
|
|||||||
@ -4,7 +4,7 @@ namespace App\Http\Middleware;
|
|||||||
|
|
||||||
use App\Const\Responses;
|
use App\Const\Responses;
|
||||||
use App\Models\Api\Customer\CustomerUserModel;
|
use App\Models\Api\Customer\CustomerUserModel;
|
||||||
use App\Service\AuthService;
|
use App\Service\Api\AuthService;
|
||||||
use Closure;
|
use Closure;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Symfony\Component\HttpFoundation\Response;
|
use Symfony\Component\HttpFoundation\Response;
|
||||||
|
|||||||
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Models\Api\Post\PostPushBoxModel;
|
use App\Models\Api\Post\PostPushBoxModel;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
@ -28,7 +29,17 @@ class AddPostQueue implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(array $params): void
|
public function handle(array $params): void
|
||||||
{
|
{
|
||||||
|
$bean = new QueueAddPostBean($params);
|
||||||
$oPostPushBoxModel = new PostPushBoxModel();
|
$oPostPushBoxModel = new PostPushBoxModel();
|
||||||
$oPostPushBoxModel->addPostQueueConsumer($params);
|
$oPostPushBoxModel->addPostQueueConsumer($bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueAddPostBean $bean,$delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueAddPostBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1,7 +1,8 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Jobs;
|
namespace App\Jobs\Api;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueUserActiveStatusBean;
|
||||||
use App\Models\Api\Customer\CustomerUserExtendModel;
|
use App\Models\Api\Customer\CustomerUserExtendModel;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
@ -26,7 +27,17 @@ class UserActiveStatusQueue implements ShouldQueue
|
|||||||
*/
|
*/
|
||||||
public function handle(array $params): void
|
public function handle(array $params): void
|
||||||
{
|
{
|
||||||
|
$bean = new QueueUserActiveStatusBean($params);
|
||||||
$oCustomerUserExtendModel = new CustomerUserExtendModel();
|
$oCustomerUserExtendModel = new CustomerUserExtendModel();
|
||||||
$oCustomerUserExtendModel->activeUserStatusQueueConsumer($params);
|
$oCustomerUserExtendModel->activeUserStatusQueueConsumer($bean);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueUserActiveStatusBean $bean,$delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueUserActiveStatusBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
46
app/Jobs/Wallet/WalletAddressTransactionQueue.php
Normal file
46
app/Jobs/Wallet/WalletAddressTransactionQueue.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Wallet\QueueEventBean;
|
||||||
|
use App\Service\Wallet\Coin\Tron\UsdtTrx20Service;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class WalletAddressTransactionQueue implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//钱包地址交易账变处理队列
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(array $params): void
|
||||||
|
{
|
||||||
|
$oQueueEventBean = new QueueEventBean($params);
|
||||||
|
$oUsdtTrx20Service = new UsdtTrx20Service();
|
||||||
|
try {
|
||||||
|
$oUsdtTrx20Service->walletAddressTransactionConsumer($oQueueEventBean);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueEventBean $bean,$delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueEventBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
|
}
|
||||||
|
}
|
||||||
46
app/Jobs/Wallet/WalletBlockQueue.php
Normal file
46
app/Jobs/Wallet/WalletBlockQueue.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Wallet\QueueWalletBlockBean;
|
||||||
|
use App\Service\Wallet\Coin\Tron\UsdtTrx20Service;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class WalletBlockQueue implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//处理tron区块任务
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(array $params): void
|
||||||
|
{
|
||||||
|
$oQueueWalletBlockBean = new QueueWalletBlockBean($params);
|
||||||
|
$oUsdtTrx20Service = new UsdtTrx20Service();
|
||||||
|
try {
|
||||||
|
$oUsdtTrx20Service->tronBlockConsumer($oQueueWalletBlockBean);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueWalletBlockBean $bean,$delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueWalletBlockBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
|
}
|
||||||
|
}
|
||||||
46
app/Jobs/Wallet/WalletBlockTransactionQueue.php
Normal file
46
app/Jobs/Wallet/WalletBlockTransactionQueue.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Wallet\QueueWalletBlockTransactionBean;
|
||||||
|
use App\Service\Wallet\Coin\Tron\UsdtTrx20Service;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class WalletBlockTransactionQueue implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(array $params): void
|
||||||
|
{
|
||||||
|
$oQueueWalletBlockTransactionBean = new QueueWalletBlockTransactionBean($params);
|
||||||
|
$oUsdtTrx20Service = new UsdtTrx20Service();
|
||||||
|
try {
|
||||||
|
$oUsdtTrx20Service->tronBlockTransactionConsumer($oQueueWalletBlockTransactionBean);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueWalletBlockTransactionBean $bean, $delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueWalletBlockTransactionBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
|
}
|
||||||
|
}
|
||||||
42
app/Jobs/Wallet/WalletNotifyToPlatformQueue.php
Normal file
42
app/Jobs/Wallet/WalletNotifyToPlatformQueue.php
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Wallet\QueueNotifyToPlatformBean;
|
||||||
|
use App\Service\Wallet\PlatformNotifyService;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class WalletNotifyToPlatformQueue implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//通知到平台
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(array $params): void
|
||||||
|
{
|
||||||
|
$oPlatformNotifyService = new PlatformNotifyService();
|
||||||
|
$oPlatformNotifyService->notifyToPlatform(new QueueNotifyToPlatformBean($params));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueNotifyToPlatformBean $bean, $delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueNotifyToPlatformBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
|
}
|
||||||
|
}
|
||||||
58
app/Jobs/Wallet/WalletPlatformTransactionQueue.php
Normal file
58
app/Jobs/Wallet/WalletPlatformTransactionQueue.php
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Wallet\QueueWalletPlatformTransactionBean;
|
||||||
|
use App\Models\Wallet\Wallet\WalletAddressTransactionModel;
|
||||||
|
use App\Service\Wallet\PlatformRechargeService;
|
||||||
|
use App\Service\Wallet\PlatformWithdrawService;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class WalletPlatformTransactionQueue implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//处理平台到账账变
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(array $params): void
|
||||||
|
{
|
||||||
|
$bean = new QueueWalletPlatformTransactionBean($params);
|
||||||
|
$oWithdrawService = new PlatformWithdrawService();
|
||||||
|
$oRechargeSService = new PlatformRechargeService();
|
||||||
|
try {
|
||||||
|
$type = $bean->getType();
|
||||||
|
//提现
|
||||||
|
if ($type == WalletAddressTransactionModel::TYPE_WITHDRAW) {
|
||||||
|
$oWithdrawService->walletPlatformTransactionConsumer($bean);
|
||||||
|
}
|
||||||
|
//充值
|
||||||
|
if ($type == WalletAddressTransactionModel::TYPE_RECHARGE) {
|
||||||
|
$oRechargeSService->walletPlatformTransactionConsumer($bean);
|
||||||
|
}
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueWalletPlatformTransactionBean $bean, $delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueWalletPlatformTransactionBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
|
}
|
||||||
|
}
|
||||||
46
app/Jobs/Wallet/WalletPlatformWithdrawTransferQueue.php
Normal file
46
app/Jobs/Wallet/WalletPlatformWithdrawTransferQueue.php
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Jobs\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Wallet\QueueWalletPlatformWithdrawTransferBean;
|
||||||
|
use App\Service\Wallet\PlatformWithdrawService;
|
||||||
|
use Illuminate\Bus\Queueable;
|
||||||
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||||
|
use Illuminate\Foundation\Bus\Dispatchable;
|
||||||
|
use Illuminate\Queue\InteractsWithQueue;
|
||||||
|
use Illuminate\Queue\SerializesModels;
|
||||||
|
|
||||||
|
class WalletPlatformWithdrawTransferQueue implements ShouldQueue
|
||||||
|
{
|
||||||
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new job instance.
|
||||||
|
*/
|
||||||
|
public function __construct()
|
||||||
|
{
|
||||||
|
//处理提现任务
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Execute the job.
|
||||||
|
*/
|
||||||
|
public function handle(array $params): void
|
||||||
|
{
|
||||||
|
$bean = new QueueWalletPlatformWithdrawTransferBean($params);
|
||||||
|
$oService = new PlatformWithdrawService();
|
||||||
|
try {
|
||||||
|
$oService->withdrawTransferConsumer($bean);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function putToQueue(QueueWalletPlatformWithdrawTransferBean $bean, $delaySec = null): \Illuminate\Foundation\Bus\PendingDispatch
|
||||||
|
{
|
||||||
|
$queue = self::dispatch($bean->toArrayNotNull())->onQueue(QueueWalletPlatformWithdrawTransferBean::QUEUE_NAME);
|
||||||
|
if(!empty($delaySec)){
|
||||||
|
$queue->delay(now()->addSeconds($delaySec));
|
||||||
|
}
|
||||||
|
return $queue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,39 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use App\Models\Wallet\PlatformUser\WalletPlatformUserTransactionModel;
|
|
||||||
use App\Models\Wallet\Wallet\WalletAddrModel;
|
|
||||||
use App\Models\Wallet\Wallet\WalletAddrTransactionModel;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class WalletAddrTransactionChangeQueue implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//钱包账变队列,用于处理用户和平台账变
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*/
|
|
||||||
public function handle(array $params): void
|
|
||||||
{
|
|
||||||
|
|
||||||
$wallet_addr_transaction_id = $params['wallet_addr_transaction_id'];
|
|
||||||
$wallet_addr_transaction_type = $params['wallet_addr_transaction_type'];
|
|
||||||
|
|
||||||
$oWalletAddrModel = new WalletAddrModel();
|
|
||||||
$oWalletAddrModel->walletAddrTransactionChangeConsumer($wallet_addr_transaction_id, $wallet_addr_transaction_type);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Jobs;
|
|
||||||
|
|
||||||
use App\Models\Wallet\PlatformUser\WalletPlatformUserTransactionModel;
|
|
||||||
use Illuminate\Bus\Queueable;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldBeUnique;
|
|
||||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
||||||
use Illuminate\Foundation\Bus\Dispatchable;
|
|
||||||
use Illuminate\Queue\InteractsWithQueue;
|
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
|
|
||||||
class WalletPlatformUserWithdrawQueue implements ShouldQueue
|
|
||||||
{
|
|
||||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create a new job instance.
|
|
||||||
*/
|
|
||||||
public function __construct()
|
|
||||||
{
|
|
||||||
//处理平台用户提现
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Execute the job.
|
|
||||||
*/
|
|
||||||
public function handle(array $params): void
|
|
||||||
{
|
|
||||||
$id = $params['wallet_platform_user_transaction_id'];
|
|
||||||
$oWalletPlatformUserTransactionModel = new WalletPlatformUserTransactionModel();
|
|
||||||
$oWalletPlatformUserTransactionModel->withdrawConsumer($id);
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
namespace App\Models\Api\Customer;
|
namespace App\Models\Api\Customer;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueUserActiveStatusBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Jobs\UserActiveStatusQueue;
|
use App\Jobs\Api\UserActiveStatusQueue;
|
||||||
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
use App\Models\Api\Post\PostPushBoxModel;
|
use App\Models\Api\Post\PostPushBoxModel;
|
||||||
use App\Models\Api\WebSocket\CustomerWsHistoryModel;
|
use App\Models\Api\WebSocket\CustomerWsHistoryModel;
|
||||||
use App\Models\Api\Base\ApiBaseModel;
|
|
||||||
use App\Structs\QueueUserActiveStatusStruct;
|
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
@ -46,11 +46,27 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
return $this->addItem($aItem);
|
return $this->addItem($aItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function initExtend($uid): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
|
{
|
||||||
|
if (!$uid) throw new ModelException('uid error');
|
||||||
|
if ($this->findItem($uid, ['uid'])) return null; //已存在
|
||||||
|
|
||||||
|
$sDateTime = date('Y-m-d H:i:s');
|
||||||
|
$aItem = [
|
||||||
|
'uid' => $uid,
|
||||||
|
'is_active' => 1,
|
||||||
|
'fans_num' => 0,
|
||||||
|
'follow_num' => 0,
|
||||||
|
'updated_at' => $sDateTime,
|
||||||
|
];
|
||||||
|
return $this->addItem($aItem);
|
||||||
|
}
|
||||||
|
|
||||||
//增加当前粉丝总数
|
//增加当前粉丝总数
|
||||||
function incrFansNum($uid): int
|
function incrFansNum($uid): int
|
||||||
{
|
{
|
||||||
$oExtend = $this->findItem($uid, 'uid');
|
$oExtend = $this->findItem($uid, 'uid');
|
||||||
if (!$oExtend) throw new ModelException('user extend not found');
|
if (!$oExtend) $this->initExtend($uid);
|
||||||
return $this->newQuery()->where('uid', $uid)->increment('fans_num');
|
return $this->newQuery()->where('uid', $uid)->increment('fans_num');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -58,7 +74,7 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
function decrFansNum($uid): int
|
function decrFansNum($uid): int
|
||||||
{
|
{
|
||||||
$oExtend = $this->findItem($uid, 'uid');
|
$oExtend = $this->findItem($uid, 'uid');
|
||||||
if (!$oExtend) throw new ModelException('user extend not found');
|
if (!$oExtend)$this->addExtend();
|
||||||
return $this->newQuery()->where('uid', $uid)->decrement('fans_num');
|
return $this->newQuery()->where('uid', $uid)->decrement('fans_num');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +82,7 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
function incrFollowNum($uid): int
|
function incrFollowNum($uid): int
|
||||||
{
|
{
|
||||||
$oExtend = $this->findItem($uid, 'uid');
|
$oExtend = $this->findItem($uid, 'uid');
|
||||||
if (!$oExtend) throw new ModelException('user extend not found');
|
if (!$oExtend) $this->initExtend($uid);
|
||||||
return $this->newQuery()->where('uid', $uid)->increment('follow_num');
|
return $this->newQuery()->where('uid', $uid)->increment('follow_num');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +90,7 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
function decrFollowNum($uid): int
|
function decrFollowNum($uid): int
|
||||||
{
|
{
|
||||||
$oExtend = $this->findItem($uid, 'uid');
|
$oExtend = $this->findItem($uid, 'uid');
|
||||||
if (!$oExtend) throw new ModelException('user extend not found');
|
if (!$oExtend) $this->initExtend($uid);
|
||||||
return $this->newQuery()->where('uid', $uid)->decrement('follow_num');
|
return $this->newQuery()->where('uid', $uid)->decrement('follow_num');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +130,11 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
if ($res) {
|
if ($res) {
|
||||||
//记录日志
|
//记录日志
|
||||||
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($oUserExtend->uid, $oUserExtend->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($oUserExtend->uid, $oUserExtend->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
||||||
$this->activeUserStatusToQueueProducer($oUserExtend->uid); //投递到消息队列
|
//投递到消息队列
|
||||||
|
$oQueueUserActiveStatusBean = new QueueUserActiveStatusBean();
|
||||||
|
$oQueueUserActiveStatusBean->setUid($oUserExtend->uid);
|
||||||
|
$oQueueUserActiveStatusBean->setQueueCreatedAt(date('Y-m-d H:i:s'));
|
||||||
|
UserActiveStatusQueue::putToQueue($oQueueUserActiveStatusBean);
|
||||||
}
|
}
|
||||||
} else { //三日内不活跃
|
} else { //三日内不活跃
|
||||||
if ($oUserExtend->is_active == self::IS_ACTIVE_NO) continue; //已经是不活跃用户
|
if ($oUserExtend->is_active == self::IS_ACTIVE_NO) continue; //已经是不活跃用户
|
||||||
@ -150,7 +170,11 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
if ($res) {
|
if ($res) {
|
||||||
//记录日志
|
//记录日志
|
||||||
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($uid, $oCustomerUserExtendModel->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
$oCustomerChangeInfoLogModel->addUserActiveStatusLog($uid, $oCustomerUserExtendModel->is_active, self::IS_ACTIVE_YES, CustomerChangeInfoLogModel::REMARK_DAILY_CHECK_USER_ACTIVE_STATUS_YES);
|
||||||
$this->activeUserStatusToQueueProducer($uid); //投递到消息队列
|
//投递到消息队列
|
||||||
|
$oQueueUserActiveStatusBean = new QueueUserActiveStatusBean();
|
||||||
|
$oQueueUserActiveStatusBean->setUid($uid);
|
||||||
|
$oQueueUserActiveStatusBean->setQueueCreatedAt(date('Y-m-d H:i:s'));
|
||||||
|
UserActiveStatusQueue::putToQueue($oQueueUserActiveStatusBean);
|
||||||
}
|
}
|
||||||
Db::commit();
|
Db::commit();
|
||||||
}catch (\Exception $e){
|
}catch (\Exception $e){
|
||||||
@ -160,18 +184,10 @@ class CustomerUserExtendModel extends ApiBaseModel
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//投递到消息队列,处理活跃推送信箱更新问题
|
|
||||||
function activeUserStatusToQueueProducer($uid): void
|
|
||||||
{
|
|
||||||
$params = QueueUserActiveStatusStruct::PARAMS;
|
|
||||||
$params['uid'] = $uid;
|
|
||||||
$params['queueCreatedAt'] = date('Y-m-d H:i:s');
|
|
||||||
UserActiveStatusQueue::dispatch($params)->onQueue(QueueUserActiveStatusStruct::QUEUE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
function activeUserStatusQueueConsumer($params): void
|
function activeUserStatusQueueConsumer(QueueUserActiveStatusBean $bean): void
|
||||||
{
|
{
|
||||||
$uid = $params['uid'];
|
$uid = $bean->getUid();
|
||||||
$oPostPushBoxModel = new PostPushBoxModel();
|
$oPostPushBoxModel = new PostPushBoxModel();
|
||||||
$oPostPushBoxModel->pullBigFanMasterPostConsumer($uid);
|
$oPostPushBoxModel->pullBigFanMasterPostConsumer($uid);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
namespace App\Models\Api\Customer;
|
namespace App\Models\Api\Customer;
|
||||||
|
|
||||||
use App\Cache\Table\TableCustomerUserCache;
|
use App\Cache\Table\Api\TableCustomerUserCache;
|
||||||
use App\Models\Api\Base\ApiBaseModel;
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
@ -109,12 +109,15 @@ class CustomerUserModel extends ApiBaseModel
|
|||||||
{
|
{
|
||||||
$oTableCustomerUserCache = new TableCustomerUserCache();
|
$oTableCustomerUserCache = new TableCustomerUserCache();
|
||||||
$oTableCustomerUserCache->setPrimaryKey($iUid);
|
$oTableCustomerUserCache->setPrimaryKey($iUid);
|
||||||
|
|
||||||
return $oTableCustomerUserCache->getCacheData();
|
return $oTableCustomerUserCache->getCacheData();
|
||||||
// return Cache::remember($this->getCacheKey($iUid), RedisConst::ORM_FIND_CACHE_SECOND, function () use ($iUid) {
|
// return Cache::remember($this->getCacheKey($iUid), RedisConst::ORM_FIND_CACHE_SECOND, function () use ($iUid) {
|
||||||
// return $this->findItem($iUid);
|
// return $this->findItem($iUid);
|
||||||
// });
|
// });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// function delItemFromCache($iUid): bool
|
// function delItemFromCache($iUid): bool
|
||||||
// {
|
// {
|
||||||
// return Cache::delete($this->getCacheKey($iUid));
|
// return Cache::delete($this->getCacheKey($iUid));
|
||||||
|
|||||||
@ -28,7 +28,7 @@ class FollowHistoryModel extends ApiBaseModel
|
|||||||
*/
|
*/
|
||||||
function addFollowHistory($method, $uid, $follow_uid): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
|
function addFollowHistory($method, $uid, $follow_uid): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
{
|
{
|
||||||
if(!in_array($method,self::METHOD)) throw new ModelException('method error');
|
if(!array_key_exists($method,self::METHOD)) throw new ModelException('method error');
|
||||||
$aItem['method'] = $method;
|
$aItem['method'] = $method;
|
||||||
$aItem['uid'] = $uid;
|
$aItem['uid'] = $uid;
|
||||||
$aItem['follow_uid'] = $follow_uid;
|
$aItem['follow_uid'] = $follow_uid;
|
||||||
|
|||||||
280
app/Models/Api/Order/CustomerUserPostOrderDisputeModel.php
Normal file
280
app/Models/Api/Order/CustomerUserPostOrderDisputeModel.php
Normal file
@ -0,0 +1,280 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Api\Order;
|
||||||
|
|
||||||
|
use App\Bean\Model\Api\Order\CustomerUserPostOrderDisputeBean;
|
||||||
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
|
use App\Models\Api\Wallet\CustomerWalletBalanceTransactionModel;
|
||||||
|
use App\Tools\Logs;
|
||||||
|
use App\Tools\Times;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Spatie\FlareClient\Api;
|
||||||
|
|
||||||
|
class CustomerUserPostOrderDisputeModel extends ApiBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'customer_user_post_order_dispute';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'post_order_id',
|
||||||
|
'status',
|
||||||
|
'chat_group_id',
|
||||||
|
'seller_submit_datetime',
|
||||||
|
'buyer_submit_datetime',
|
||||||
|
'result_status',
|
||||||
|
'buyer_uid',
|
||||||
|
'buyer_pay_dispute_status',
|
||||||
|
'buyer_pay_amount',
|
||||||
|
'buyer_pay_transaction_id',
|
||||||
|
'buyer_dispute_fee_pay_status',
|
||||||
|
'buyer_dispute_fee_amount',
|
||||||
|
'buyer_dispute_fee_pay_transaction_id',
|
||||||
|
'seller_uid',
|
||||||
|
'seller_pay_dispute_status',
|
||||||
|
'seller_pay_amount',
|
||||||
|
'seller_pay_transaction_id',
|
||||||
|
'seller_desc_key',
|
||||||
|
'seller_desc',
|
||||||
|
'admin_remark',
|
||||||
|
'admin_uid',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
const STATUS_NO_DISPUTE = 1;
|
||||||
|
const STATUS_WAITING = 2;
|
||||||
|
const STATUS_PROCESSING = 3;
|
||||||
|
const STATUS_FINISH = 4;
|
||||||
|
const STATUS_CANCEL = 5;
|
||||||
|
const STATUS = [
|
||||||
|
self::STATUS_NO_DISPUTE => '无纠纷',
|
||||||
|
self::STATUS_WAITING => '待处理',
|
||||||
|
self::STATUS_PROCESSING => '处理中',
|
||||||
|
self::STATUS_FINISH => '处理完成',
|
||||||
|
self::STATUS_CANCEL => '取消',
|
||||||
|
];
|
||||||
|
|
||||||
|
const RESULT_STATUS_SELLER_RESPLITY = 1;
|
||||||
|
const RESULT_STATUS_BUYER_RESPLITY = 2;
|
||||||
|
const RESULT_STATUS_EACH_RESPLITY = 3;
|
||||||
|
const RESULT_STATUS_OVERRULE = 4;
|
||||||
|
const RESULT_STATUS = [
|
||||||
|
self::RESULT_STATUS_SELLER_RESPLITY => '卖家责任',
|
||||||
|
self::RESULT_STATUS_BUYER_RESPLITY => '买家责任',
|
||||||
|
self::RESULT_STATUS_EACH_RESPLITY => '双方责任',
|
||||||
|
self::RESULT_STATUS_OVERRULE => '驳回',
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
const PAY_DISPUTE_STATUS_WAITING = 1;
|
||||||
|
const PAY_DISPUTE_STATUS_SUCCESS = 2;
|
||||||
|
const PAY_DISPUTE_STATUS_FAIL = 3;
|
||||||
|
const PAY_DISPUTE_STATUS = [
|
||||||
|
self::PAY_DISPUTE_STATUS_WAITING => '待处理',
|
||||||
|
self::PAY_DISPUTE_STATUS_SUCCESS => '成功',
|
||||||
|
self::PAY_DISPUTE_STATUS_FAIL => '失败',
|
||||||
|
];
|
||||||
|
|
||||||
|
const BUYER_DISPUTE_FEE_PAY_STATUS_NO = 1;
|
||||||
|
const BUYER_DISPUTE_FEE_PAY_STATUS_YES = 2;
|
||||||
|
const BUYER_DISPUTE_FEE_PAY_STATUS = [
|
||||||
|
self::BUYER_DISPUTE_FEE_PAY_STATUS_NO => '未支付',
|
||||||
|
self::BUYER_DISPUTE_FEE_PAY_STATUS_YES => '已支付',
|
||||||
|
];
|
||||||
|
|
||||||
|
//纠纷管理员接单
|
||||||
|
public function disputeAdminAccept($dispute_id, $admin_uid, $is_change_admin = false): bool|int
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$datetimeNow = Times::getNowDateTime();
|
||||||
|
DB::beginTransaction();
|
||||||
|
$resModel = $this->findItem($dispute_id);
|
||||||
|
if (!$resModel) throw new ModelException('dispute not found');
|
||||||
|
if ($resModel->status != self::STATUS_WAITING) throw new ModelException('dispute status error');
|
||||||
|
if (!empty($resModel->admin_uid) && !$is_change_admin) throw new ModelException('already have admin');
|
||||||
|
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $resModel->id,
|
||||||
|
'status' => self::STATUS_PROCESSING,
|
||||||
|
'admin_uid' => $admin_uid,
|
||||||
|
'updated_at' => $datetimeNow,
|
||||||
|
];
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('update dispute status fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//创建纠纷
|
||||||
|
public function createDispute($post_order_id)
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$datetimeNow = Times::getNowDateTime();
|
||||||
|
DB::beginTransaction();
|
||||||
|
$oCustomerUserPostOrderModel = new CustomerUserPostOrderModel();
|
||||||
|
$resCustomerUserPostOrderModel = $oCustomerUserPostOrderModel->findItem($post_order_id);
|
||||||
|
if (!$resCustomerUserPostOrderModel) throw new \Exception('order not found');
|
||||||
|
if ($resCustomerUserPostOrderModel->pay_status != CustomerUserPostOrderModel::PAY_STATUS_PAID) throw new ModelException('order already in dispute');
|
||||||
|
if ($resCustomerUserPostOrderModel->dispute_status != CustomerUserPostOrderModel::DISPUTE_STATUS_UN_DISPUTE) throw new ModelException('order already in dispute');
|
||||||
|
//更新订单纠纷状态
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $resCustomerUserPostOrderModel->id,
|
||||||
|
'dispute_status' => CustomerUserPostOrderModel::DISPUTE_STATUS_WAITING,
|
||||||
|
'updated_at' => $datetimeNow,
|
||||||
|
];
|
||||||
|
$res = $oCustomerUserPostOrderModel->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('update order dispute status fail');
|
||||||
|
//创建纠纷
|
||||||
|
$bean = new CustomerUserPostOrderDisputeBean();
|
||||||
|
$bean->setBuyerUid($resCustomerUserPostOrderModel->buyer_uid);
|
||||||
|
$bean->setSellerUid($resCustomerUserPostOrderModel->seller_uid);
|
||||||
|
$bean->setPostOrderId($post_order_id);
|
||||||
|
$bean->setStatus(self::STATUS_WAITING);
|
||||||
|
$bean->setBuyerDisputeFeePayStatus(self::BUYER_DISPUTE_FEE_PAY_STATUS_NO);
|
||||||
|
//@@计算纠纷申诉费用
|
||||||
|
$bean->setBuyerDisputeFeeAmount(5); //默认5u
|
||||||
|
$bean->setCreatedAt($datetimeNow);
|
||||||
|
$bean->setUpdatedAt($datetimeNow);
|
||||||
|
$resModel = $this->addItem($bean->toArrayNotNull());
|
||||||
|
if (!$resModel) throw new ModelException('create dispute fail');
|
||||||
|
|
||||||
|
//创建聊天群组
|
||||||
|
$chat_id = $this->createChatGroupForDispute($resModel->id);
|
||||||
|
if (!$chat_id) throw new ModelException('create chat group fail');
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $resModel->id,
|
||||||
|
'chat_group_id' => $chat_id,
|
||||||
|
];
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('update chat group id fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return $resModel->id;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//@@创建聊天群组用于纠纷
|
||||||
|
function createChatGroupForDispute($dispute_id)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//纠纷判罚
|
||||||
|
public function disputePenalty($dispute_id, $result_status, $buyer_amount, $seller_amount, $admin_uid, $admin_remark): bool|int
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
if (
|
||||||
|
!in_array(
|
||||||
|
$result_status,
|
||||||
|
[self::RESULT_STATUS_SELLER_RESPLITY, self::RESULT_STATUS_BUYER_RESPLITY, self::RESULT_STATUS_EACH_RESPLITY, self::RESULT_STATUS_OVERRULE]
|
||||||
|
)
|
||||||
|
) throw new ModelException('result_status error');
|
||||||
|
$datetimeNow = Times::getNowDateTime();
|
||||||
|
DB::beginTransaction();
|
||||||
|
$resModel = $this->findItem($dispute_id);
|
||||||
|
if (!$resModel) throw new ModelException('dispute not found');
|
||||||
|
if ($resModel->status != self::STATUS_PROCESSING) throw new ModelException('dispute status error');
|
||||||
|
if ($resModel->admin_uid != $admin_uid) throw new ModelException('admin_uid error');
|
||||||
|
$oCustomerUserPostOrderModel = new CustomerUserPostOrderModel();
|
||||||
|
$resCustomerUserPostOrderModel = $oCustomerUserPostOrderModel->findItem($resModel->post_order_id);
|
||||||
|
if (!$resCustomerUserPostOrderModel) throw new ModelException('order not found');
|
||||||
|
if ($resCustomerUserPostOrderModel->dispute_status != CustomerUserPostOrderModel::DISPUTE_STATUS_PROCESSING) throw new ModelException('order dispute status error');
|
||||||
|
//更新订单状态
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $resCustomerUserPostOrderModel->id,
|
||||||
|
'dispute_status' => CustomerUserPostOrderModel::DISPUTE_STATUS_FINISH,
|
||||||
|
'dispute_result_status' => $result_status,
|
||||||
|
'updated_at' => $datetimeNow,
|
||||||
|
];
|
||||||
|
$res = $oCustomerUserPostOrderModel->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('update order dispute status fail');
|
||||||
|
|
||||||
|
//执行金额处理
|
||||||
|
$oCustomerWalletBalanceTransactionModel = new CustomerWalletBalanceTransactionModel();
|
||||||
|
$buyer_pay_status = self::PAY_DISPUTE_STATUS_SUCCESS;
|
||||||
|
$seller_pay_status = self::PAY_DISPUTE_STATUS_SUCCESS;
|
||||||
|
//执行买家
|
||||||
|
$resBuyerTrsId = $this->changeUserAmountDispute(
|
||||||
|
$resCustomerUserPostOrderModel->buyer_uid,
|
||||||
|
$resCustomerUserPostOrderModel->buyer_currency_code,
|
||||||
|
$buyer_amount,
|
||||||
|
$resModel->id,
|
||||||
|
);
|
||||||
|
if (!$resBuyerTrsId) {
|
||||||
|
$buyer_pay_status = self::PAY_DISPUTE_STATUS_FAIL;
|
||||||
|
$this->changeUserAmountNotEnough($resCustomerUserPostOrderModel->buyer_uid, $resCustomerUserPostOrderModel->buyer_currency_code, $buyer_amount);
|
||||||
|
}
|
||||||
|
//执行卖家
|
||||||
|
$resSellerTrsId = $this->changeUserAmountDispute(
|
||||||
|
$resCustomerUserPostOrderModel->seller_uid,
|
||||||
|
$resCustomerUserPostOrderModel->seller_currency_code,
|
||||||
|
$seller_amount,
|
||||||
|
$resModel->id,
|
||||||
|
);
|
||||||
|
if (!$resSellerTrsId) {
|
||||||
|
$seller_pay_status = self::PAY_DISPUTE_STATUS_FAIL;
|
||||||
|
$this->changeUserAmountNotEnough($resCustomerUserPostOrderModel->seller_uid, $resCustomerUserPostOrderModel->seller_currency_code, $seller_amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//更新纠纷
|
||||||
|
$updateItem = [
|
||||||
|
'status' => self::STATUS_FINISH,
|
||||||
|
'result_status' => $result_status,
|
||||||
|
'admin_remark' => $admin_remark,
|
||||||
|
'updated_at' => $datetimeNow,
|
||||||
|
'buyer_pay_amount' => $buyer_amount,
|
||||||
|
'buyer_pay_dispute_status' => $buyer_pay_status,
|
||||||
|
'seller_pay_amount' => $seller_amount,
|
||||||
|
'seller_pay_dispute_status' => $seller_pay_status,
|
||||||
|
];
|
||||||
|
if ($buyer_pay_status == self::PAY_DISPUTE_STATUS_SUCCESS) $updateItem['buyer_pay_transaction_id'] = $resBuyerTrsId;
|
||||||
|
if ($seller_pay_status == self::PAY_DISPUTE_STATUS_SUCCESS) $updateItem['seller_pay_transaction_id'] = $resSellerTrsId;
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('update dispute status fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//@@金额不足处理
|
||||||
|
function changeUserAmountNotEnough($uid, $currency_code, $amount, $remark = '')
|
||||||
|
{
|
||||||
|
//@@冻结用户提款功能
|
||||||
|
//@@提交到定期扣款任务
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//纠纷金额处理
|
||||||
|
function changeUserAmountDispute($uid, $currency_code, $amount, $dispute_id, $remark = ''): bool|int
|
||||||
|
{
|
||||||
|
if ($amount == 0) return true;
|
||||||
|
$oCustomerWalletBalanceTransactionModel = new CustomerWalletBalanceTransactionModel();
|
||||||
|
if ($amount > 0) {
|
||||||
|
$res = $oCustomerWalletBalanceTransactionModel->typeDisputeAdd($uid, $currency_code, $amount, $dispute_id, $remark);
|
||||||
|
} else {
|
||||||
|
$res = $oCustomerWalletBalanceTransactionModel->typeDisputeSub($uid, $currency_code, $amount, $dispute_id, $remark);
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
102
app/Models/Api/Order/CustomerUserPostOrderModel.php
Normal file
102
app/Models/Api/Order/CustomerUserPostOrderModel.php
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models\Api\Order;
|
||||||
|
|
||||||
|
use App\Bean\Model\Api\Order\CustomerUserPostOrderBean;
|
||||||
|
use App\Const\Prefix;
|
||||||
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
|
use App\Models\Api\Post\PostHistoryModel;
|
||||||
|
use App\Models\Api\Wallet\CustomerWalletBalanceTransactionModel;
|
||||||
|
use App\Tools\Logs;
|
||||||
|
use App\Tools\Times;
|
||||||
|
use App\Tools\Tools;
|
||||||
|
|
||||||
|
class CustomerUserPostOrderModel extends ApiBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'customer_user_post_order';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'sn',
|
||||||
|
'pay_status',
|
||||||
|
'buyer_uid',
|
||||||
|
'seller_uid',
|
||||||
|
'pid',
|
||||||
|
'post_history_id',
|
||||||
|
'amount',
|
||||||
|
'buyer_wallet_transaction_id',
|
||||||
|
'seller_wallet_transaction_id',
|
||||||
|
'dispute_status',
|
||||||
|
'dispute_result_status',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
const PAY_STATUS_UNPAID = 1;
|
||||||
|
const PAY_STATUS_PAID = 2;
|
||||||
|
const PAY_STATUS_PAID_FAIL = 3;
|
||||||
|
const PAY_STATUS_CANCEL = 4;
|
||||||
|
const PAY_STATUS = [
|
||||||
|
self::PAY_STATUS_UNPAID => '未支付',
|
||||||
|
self::PAY_STATUS_PAID => '已支付',
|
||||||
|
self::PAY_STATUS_PAID_FAIL => '支付失败',
|
||||||
|
self::PAY_STATUS_CANCEL => '取消',
|
||||||
|
];
|
||||||
|
|
||||||
|
const DISPUTE_STATUS_UN_DISPUTE = 1;
|
||||||
|
const DISPUTE_STATUS_WAITING = 2;
|
||||||
|
const DISPUTE_STATUS_PROCESSING = 3;
|
||||||
|
const DISPUTE_STATUS_FINISH = 4;
|
||||||
|
|
||||||
|
const DISPUTE_STATUS = [
|
||||||
|
self::DISPUTE_STATUS_UN_DISPUTE => '未申诉',
|
||||||
|
self::DISPUTE_STATUS_WAITING => '申诉待处理',
|
||||||
|
self::DISPUTE_STATUS_PROCESSING => '申诉处理中',
|
||||||
|
self::DISPUTE_STATUS_FINISH => '申诉完成',
|
||||||
|
];
|
||||||
|
|
||||||
|
//订单购买
|
||||||
|
public function buy($buyer_uid, $seller_id,$currency_code, $amount, $post_id): bool|int
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
$sn = Tools::genSnowflakeId(Prefix::ORDER_SN_PREFIX);
|
||||||
|
$datetimeNow = Times::getNowDateTime();
|
||||||
|
$bean = new CustomerUserPostOrderBean();
|
||||||
|
|
||||||
|
$bean->setAmount(abs($amount));
|
||||||
|
$bean->setSn($sn);
|
||||||
|
$bean->setPayStatus(self::PAY_STATUS_UNPAID);
|
||||||
|
$bean->setBuyerUid($buyer_uid); //买家
|
||||||
|
$bean->setSellerUid($seller_id); //卖家
|
||||||
|
$bean->setPid($post_id);
|
||||||
|
$bean->setBuyerCurrencyCode($currency_code); //买家
|
||||||
|
$bean->setSellerCurrencyCode($currency_code); //卖家
|
||||||
|
$bean->setDisputeStatus(self::DISPUTE_STATUS_UN_DISPUTE); //纠纷状态
|
||||||
|
$bean->setCreatedAt($datetimeNow);
|
||||||
|
$bean->setUpdatedAt($datetimeNow);
|
||||||
|
|
||||||
|
//查找post_history_id做快照
|
||||||
|
$oPostHistoryModel = new PostHistoryModel();
|
||||||
|
$resPostHistoryModel = $oPostHistoryModel->findLastPostId($post_id,['id']);
|
||||||
|
if(!$resPostHistoryModel) throw new ModelException('post_history_id not found');
|
||||||
|
$bean->setPostHistoryId($resPostHistoryModel->id);
|
||||||
|
|
||||||
|
$res = $this->addItem($bean->toArrayNotNull());
|
||||||
|
if(!$res) throw new ModelException('order add fail');
|
||||||
|
$bean->setId($res->id);
|
||||||
|
|
||||||
|
//进行支付
|
||||||
|
$oCustomerWalletBalanceTransactionModel = new CustomerWalletBalanceTransactionModel();
|
||||||
|
$res = $oCustomerWalletBalanceTransactionModel->typeOrderPay($bean); //订单支付,内部会进行order状态的更新
|
||||||
|
if(!$res) throw new ModelException('order pay fail');
|
||||||
|
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return $bean->getId();
|
||||||
|
}catch (\Exception $e){
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'catchErr', $e, func_get_args());
|
||||||
|
// throw new ModelException($e->getMessage());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
20
app/Models/Api/Other/CustomerSettingModel.php
Normal file
20
app/Models/Api/Other/CustomerSettingModel.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Api\Other;
|
||||||
|
|
||||||
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
|
|
||||||
|
class CustomerSettingModel extends ApiBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'customer_setting';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'value',
|
||||||
|
'customer_setting',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
}
|
||||||
@ -44,5 +44,15 @@ class PostHistoryModel extends ApiBaseModel
|
|||||||
return $this->addItem($aItem);
|
return $this->addItem($aItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取最新的历史记录(=当前)
|
||||||
|
function findLastPostId($post_id,$col = ['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
||||||
|
{
|
||||||
|
return $this->newQuery()
|
||||||
|
->where('oid',$post_id)
|
||||||
|
->where('method','!=',self::METHOD_DEL)
|
||||||
|
->orderBy('created_at','desc')
|
||||||
|
->first($col);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace App\Models\Api\Post;
|
namespace App\Models\Api\Post;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Jobs\Api\AddPostQueue;
|
||||||
use App\Models\Api\Base\ApiBaseModel;
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
use App\Models\Api\Post\Structs\PostParamsStruct;
|
use App\Models\Api\Post\Structs\PostParamsStruct;
|
||||||
use App\Tools\Tools;
|
use App\Tools\Tools;
|
||||||
@ -82,7 +84,11 @@ class PostModel extends ApiBaseModel
|
|||||||
$aItem['created_at'] = $sDateTime;
|
$aItem['created_at'] = $sDateTime;
|
||||||
$res = $this->addItem($aItem);
|
$res = $this->addItem($aItem);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$this->pushToQueue(self::TYPE_POST, $res->id);
|
//发送到消息队列处理新增post
|
||||||
|
$oQueueAddPostBean = new QueueAddPostBean();
|
||||||
|
$oQueueAddPostBean->setId($res->id);
|
||||||
|
$oQueueAddPostBean->setType(self::TYPE_POST);
|
||||||
|
AddPostQueue::putToQueue(new QueueAddPostBean(['id' => $res->id, 'type' => $type]));
|
||||||
}
|
}
|
||||||
return $res;
|
return $res;
|
||||||
}
|
}
|
||||||
@ -99,12 +105,6 @@ class PostModel extends ApiBaseModel
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//发送到消息队列处理新增post
|
|
||||||
function pushToQueue($type, $id): void
|
|
||||||
{
|
|
||||||
PostPushBoxModel::addPostQueueProducer(['type' => $type, 'id' => $id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @throws ModelException
|
* @throws ModelException
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -2,14 +2,14 @@
|
|||||||
|
|
||||||
namespace App\Models\Api\Post;
|
namespace App\Models\Api\Post;
|
||||||
|
|
||||||
|
use App\Bean\Queue\Api\QueueAddPostBean;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Jobs\AddPostQueue;
|
use App\Jobs\Api\AddPostQueue;
|
||||||
use App\Models\Api\Base\ApiBaseModel;
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
use App\Models\Api\Comment\PostCommentModel;
|
use App\Models\Api\Comment\PostCommentModel;
|
||||||
use App\Models\Api\Customer\CustomerUserExtendModel;
|
use App\Models\Api\Customer\CustomerUserExtendModel;
|
||||||
use App\Models\Api\Follow\FollowModel;
|
use App\Models\Api\Follow\FollowModel;
|
||||||
use App\Models\Api\Post\Structs\PostParamsStruct;
|
use App\Models\Api\Post\Structs\PostParamsStruct;
|
||||||
use App\Structs\QueueAddPostStruct;
|
|
||||||
use App\Tools\CollectOffsetLimit;
|
use App\Tools\CollectOffsetLimit;
|
||||||
use App\Tools\Tools;
|
use App\Tools\Tools;
|
||||||
use Illuminate\Database\Eloquent\Casts\Attribute;
|
use Illuminate\Database\Eloquent\Casts\Attribute;
|
||||||
@ -82,22 +82,16 @@ class PostPushBoxModel extends ApiBaseModel
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function addPostQueueProducer(array $params): void
|
|
||||||
{
|
|
||||||
AddPostQueue::dispatch($params)->onQueue(QueueAddPostStruct::QUEUE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 提交后调用事件,在消费队列跑推送
|
* 提交后调用事件,在消费队列跑推送
|
||||||
* @throws ModelException
|
* @throws ModelException
|
||||||
*/
|
*/
|
||||||
function addPostQueueConsumer(array $params)
|
function addPostQueueConsumer(QueueAddPostBean $bean)
|
||||||
{
|
{
|
||||||
if (empty($params)) return false;
|
$id = $bean->getId();
|
||||||
if (isset($params['id'])) return false;
|
$type = $bean->getType();
|
||||||
if (isset($params['type'])) return false;
|
if (empty($id)) return false;
|
||||||
$id = $params['id'];
|
if (empty($type)) return false;
|
||||||
$type = $params['type'];
|
|
||||||
|
|
||||||
if (!in_array($type, [self::TYPE_POST, self::TYPE_REPOST, self::TYPE_COMMENT])) return false;
|
if (!in_array($type, [self::TYPE_POST, self::TYPE_REPOST, self::TYPE_COMMENT])) return false;
|
||||||
if (empty($id)) return false;
|
if (empty($id)) return false;
|
||||||
|
|||||||
130
app/Models/Api/Wallet/CustomerWalletBalanceModel.php
Normal file
130
app/Models/Api/Wallet/CustomerWalletBalanceModel.php
Normal file
@ -0,0 +1,130 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Api\Wallet;
|
||||||
|
|
||||||
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class CustomerWalletBalanceModel extends ApiBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'customer_wallet_balance';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'uid',
|
||||||
|
'currency_code',
|
||||||
|
'total_amount',
|
||||||
|
'frozen_amount',
|
||||||
|
'available_amount',
|
||||||
|
'security_amount',
|
||||||
|
'recharge_wallet_addr',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
function frozenAmount($id,$amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'frozen_amount' => DB::raw('frozen_amount + '. $amount),
|
||||||
|
'available_amount' => DB::raw('available_amount - '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function unFrozenAmount($id,$amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'frozen_amount' => DB::raw('frozen_amount - '. $amount),
|
||||||
|
'available_amount' => DB::raw('available_amount + '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function subFrozenAmount($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'total_amount' => DB::raw('total_amount - '. $amount),
|
||||||
|
'frozen_amount' => DB::raw('frozen_amount - '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addFrozenAmount($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'total_amount' => DB::raw('total_amount + '. $amount),
|
||||||
|
'frozen_amount' => DB::raw('frozen_amount + '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function subAvailableAmount($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'total_amount' => DB::raw('total_amount - '. $amount),
|
||||||
|
'available_amount' => DB::raw('available_amount - '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addAvailableAmount($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'total_amount' => DB::raw('total_amount + '. $amount),
|
||||||
|
'available_amount' => DB::raw('available_amount + '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function balanceToSecurity($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'total_amount' => DB::raw('total_amount - '. $amount),
|
||||||
|
'available_amount' => DB::raw('available_amount - '. $amount),
|
||||||
|
'security_amount' => DB::raw('security_amount + '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function securityToBalance($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'total_amount' => DB::raw('total_amount + '. $amount),
|
||||||
|
'available_amount' => DB::raw('available_amount + '. $amount),
|
||||||
|
'security_amount' => DB::raw('security_amount - '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function subSecurityAmount($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'security_amount' => DB::raw('security_amount - '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findByUidCurrencyCode($uid, $currency_code): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
|
{
|
||||||
|
return $this->findItemByWhere(['uid' => $uid, 'currency_code' => $currency_code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
883
app/Models/Api/Wallet/CustomerWalletBalanceTransactionModel.php
Normal file
883
app/Models/Api/Wallet/CustomerWalletBalanceTransactionModel.php
Normal file
@ -0,0 +1,883 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Api\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Model\Api\Order\CustomerUserPostOrderBean;
|
||||||
|
use App\Bean\Model\Api\Wallet\CustomerWalletBalanceTransactionBean;
|
||||||
|
use App\Cache\Table\Api\TableCustomerSettingCache;
|
||||||
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
|
use App\Models\Api\Order\CustomerUserPostOrderModel;
|
||||||
|
use App\Tools\Logs;
|
||||||
|
use App\Tools\Math;
|
||||||
|
use App\Tools\Times;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class CustomerWalletBalanceTransactionModel extends ApiBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'customer_wallet_balance_transaction';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'type',
|
||||||
|
'status',
|
||||||
|
'wallet_id',
|
||||||
|
'uid',
|
||||||
|
'currency_code',
|
||||||
|
'amount',
|
||||||
|
'fee_amount',
|
||||||
|
'before_total_amount',
|
||||||
|
'after_total_amount',
|
||||||
|
'source_params',
|
||||||
|
'remark',
|
||||||
|
'target_uid',
|
||||||
|
'target_post_order_id',
|
||||||
|
'target_post_order_dispute_id',
|
||||||
|
'sign',
|
||||||
|
'callback_time',
|
||||||
|
'delay_payment_time',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
const TYPE_RECHARGE_ADD = 1;
|
||||||
|
const TYPE_WITHDRAW_DEC = 2;
|
||||||
|
const TYPE_ORDER_PAY_DEC = 3;
|
||||||
|
const TYPE_ORDER_RECEIVE_ADD = 4;
|
||||||
|
const TYPE_ORDER_REFUND_SUB = 5;
|
||||||
|
const TYPE_BALANCE_TO_SECURITY = 6;
|
||||||
|
const TYPE_SECURITY_TO_BALANCE = 7;
|
||||||
|
const TYPE_DISPUTE_ADD = 8;
|
||||||
|
const TYPE_DISPUTE_SUB = 9;
|
||||||
|
const TYPE_TRANSACTION_FEE_SUB = 10;
|
||||||
|
const TYPE_TRANSACTION_FEE_ADD = 11;
|
||||||
|
const TYPE_ADMIN_ADD = 12;
|
||||||
|
const TYPE_ADMIN_SUB = 13;
|
||||||
|
const TYPE_TRANSFER_TO_USER_DEC = 14;
|
||||||
|
const TYPE_TRANSFER_RECEIVE_ADD = 15;
|
||||||
|
const TYPE_ORDER_DISPUTE_FEE_DEC = 16;
|
||||||
|
const TYPE_ORDER_DISPUTE_FEE_ADD = 17;
|
||||||
|
const TYPE = [
|
||||||
|
self::TYPE_RECHARGE_ADD => '充值',
|
||||||
|
self::TYPE_WITHDRAW_DEC => '提现',
|
||||||
|
self::TYPE_ORDER_PAY_DEC => '订单支付',
|
||||||
|
self::TYPE_ORDER_RECEIVE_ADD => '订单收款',
|
||||||
|
self::TYPE_ORDER_REFUND_SUB => '订单退款',
|
||||||
|
self::TYPE_BALANCE_TO_SECURITY => '余额转保证金',
|
||||||
|
self::TYPE_SECURITY_TO_BALANCE => '保证金转余额',
|
||||||
|
self::TYPE_DISPUTE_ADD => '纠纷加款',
|
||||||
|
self::TYPE_DISPUTE_SUB => '纠纷扣款',
|
||||||
|
self::TYPE_TRANSACTION_FEE_SUB => '交易手续费扣除',
|
||||||
|
self::TYPE_TRANSACTION_FEE_ADD => '交易手续费增加',
|
||||||
|
self::TYPE_ADMIN_ADD => '管理员加款',
|
||||||
|
self::TYPE_ADMIN_SUB => '管理员扣款',
|
||||||
|
self::TYPE_TRANSFER_TO_USER_DEC => '转账给用户',
|
||||||
|
self::TYPE_TRANSFER_RECEIVE_ADD => '转账收款',
|
||||||
|
self::TYPE_ORDER_DISPUTE_FEE_DEC => '纠纷仲裁费用扣除',
|
||||||
|
self::TYPE_ORDER_DISPUTE_FEE_ADD => '纠纷仲裁费用退还',
|
||||||
|
];
|
||||||
|
|
||||||
|
const STATUS_WAIT = 1;
|
||||||
|
const STATUS_PROCESSING = 2;
|
||||||
|
const STATUS_SUCCESS = 3;
|
||||||
|
const STATUS_FAIL = 4;
|
||||||
|
const STATUS_DELAY_PAYMENT = 5;
|
||||||
|
const STATUS = [
|
||||||
|
self::STATUS_WAIT => '等待处理',
|
||||||
|
self::STATUS_PROCESSING => '处理中',
|
||||||
|
self::STATUS_SUCCESS => '成功',
|
||||||
|
self::STATUS_FAIL => '失败',
|
||||||
|
self::STATUS_DELAY_PAYMENT => '延期到账',
|
||||||
|
];
|
||||||
|
|
||||||
|
const SOURCE_PARAMS_BALANCE = 1;
|
||||||
|
const SOURCE_PARAMS_SECURITY = 2;
|
||||||
|
const SOURCE_PARAMS = [
|
||||||
|
self::SOURCE_PARAMS_BALANCE => '余额',
|
||||||
|
self::SOURCE_PARAMS_SECURITY => '保证金',
|
||||||
|
];
|
||||||
|
|
||||||
|
function getDelayPayList($datetime, $col = ['*']): \Illuminate\Database\Eloquent\Collection|array
|
||||||
|
{
|
||||||
|
return $this->newQuery()->where('status', self::STATUS_DELAY_PAYMENT)->where('delay_payment_time', '<=', $datetime)->limit(100)->get($col);
|
||||||
|
}
|
||||||
|
|
||||||
|
//纠纷仲裁费用退还
|
||||||
|
function typeOrderDisputeFeeAdd($uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_ORDER_DISPUTE_FEE_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->addAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('order dispute fee add fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//纠纷仲裁费用扣除
|
||||||
|
function typeOrderDisputeFeeDec($uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //账变负数
|
||||||
|
$bean->setType(self::TYPE_ORDER_DISPUTE_FEE_DEC);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
if (Math::bcComp($resWalletBalanceModel->available_amount, abs($bean->getAmount())) != -1) throw new ModelException('balance not enough');
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->subAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('order dispute fee dec fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//处理延期账变
|
||||||
|
function dealDelayPaymentTransactionCmd(): void
|
||||||
|
{
|
||||||
|
$datetimeNow = Times::getNowDateTime();
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
while (true) {
|
||||||
|
$resList = $this->getDelayPayList($datetimeNow, ['id']);
|
||||||
|
if ($resList->isEmpty()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
foreach ($resList as $itemId) {
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$item = $this->findItem($itemId->id);
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findItem($item->wallet_id);
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $item->id,
|
||||||
|
'status' => self::STATUS_SUCCESS,
|
||||||
|
'updated_at' => Times::getNowDateTime(),
|
||||||
|
];
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('updateItem fail');
|
||||||
|
$res = $oCustomerWalletBalanceModel->unFrozenAmount($item->wallet_id, $item->amount);
|
||||||
|
if (!$res) throw new ModelException('unFrozenAmount fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//转账给用户
|
||||||
|
function typeTransferToUser($uid, $target_uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$senderWalletTransactionBean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$receiverWalletTransactionBean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
|
||||||
|
$senderWalletTransactionBean->setUid($uid);
|
||||||
|
$senderWalletTransactionBean->setTargetUid($target_uid);
|
||||||
|
$senderWalletTransactionBean->setCurrencyCode($currency_code);
|
||||||
|
$senderWalletTransactionBean->setAmount(-abs($amount)); //账变负数
|
||||||
|
$senderWalletTransactionBean->setType(self::TYPE_TRANSFER_TO_USER_DEC);
|
||||||
|
$senderWalletTransactionBean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$senderWalletTransactionBean->setRemark($remark);
|
||||||
|
|
||||||
|
$receiverWalletTransactionBean->setUid($target_uid);
|
||||||
|
$receiverWalletTransactionBean->setTargetUid($uid);
|
||||||
|
$receiverWalletTransactionBean->setCurrencyCode($currency_code);
|
||||||
|
$receiverWalletTransactionBean->setAmount(abs($amount)); //账变正数
|
||||||
|
$receiverWalletTransactionBean->setType(self::TYPE_TRANSFER_RECEIVE_ADD);
|
||||||
|
$receiverWalletTransactionBean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$receiverWalletTransactionBean->setRemark($remark);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询发送人余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resSenderWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($senderWalletTransactionBean->getUid(), $senderWalletTransactionBean->getCurrencyCode());
|
||||||
|
if (!$resSenderWalletBalanceModel) throw new ModelException('sender wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resSenderWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resSenderWalletBalanceModel->id);
|
||||||
|
//查询接收人余额
|
||||||
|
$resReceiverWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($receiverWalletTransactionBean->getUid(), $receiverWalletTransactionBean->getCurrencyCode());
|
||||||
|
if (!$resReceiverWalletBalanceModel) throw new ModelException('receiver wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resReceiverWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resReceiverWalletBalanceModel->id);
|
||||||
|
|
||||||
|
//检查发送人余额是否足够
|
||||||
|
if (Math::bcComp($resSenderWalletBalanceModel->available_amount, abs($senderWalletTransactionBean->getAmount())) != -1) throw new ModelException('balance not enough');
|
||||||
|
$senderWalletTransactionBean->setWalletId($resSenderWalletBalanceModel->id);
|
||||||
|
$senderWalletTransactionBean->setBeforeTotalAmount($resSenderWalletBalanceModel->total_amount);
|
||||||
|
$senderWalletTransactionBean->setAfterTotalAmount(Math::bcAdd($resSenderWalletBalanceModel->total_amount, $senderWalletTransactionBean->getAmount()));
|
||||||
|
|
||||||
|
//发送人新增账变
|
||||||
|
$res = $this->addTransaction($senderWalletTransactionBean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//发送人变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->subAvailableAmount($senderWalletTransactionBean->getWalletId(), $senderWalletTransactionBean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('transfer to user dec fail');
|
||||||
|
|
||||||
|
//接收人账变
|
||||||
|
$receiverWalletTransactionBean->setWalletId($resReceiverWalletBalanceModel->id);
|
||||||
|
$receiverWalletTransactionBean->setBeforeTotalAmount($resReceiverWalletBalanceModel->total_amount);
|
||||||
|
$receiverWalletTransactionBean->setAfterTotalAmount(Math::bcAdd($resReceiverWalletBalanceModel->total_amount, $receiverWalletTransactionBean->getAmount()));
|
||||||
|
//接收人新增账变
|
||||||
|
$res = $this->addTransaction($receiverWalletTransactionBean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//接收人变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->addAvailableAmount($receiverWalletTransactionBean->getWalletId(), $receiverWalletTransactionBean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('transfer receive add fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//管理员扣除
|
||||||
|
function typeAdminSub($uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //账变负数
|
||||||
|
$bean->setType(self::TYPE_ADMIN_SUB);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
if (Math::bcComp($resWalletBalanceModel->available_amount, abs($bean->getAmount())) != -1) throw new ModelException('balance not enough');
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->subAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('admin sub fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//管理员增加
|
||||||
|
function typeAdminAdd($uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_ADMIN_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->addAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('admin add fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//手续费增加
|
||||||
|
function typeTransactionFeeAdd($uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_TRANSACTION_FEE_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->addAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('transaction fee add fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//手续费扣除
|
||||||
|
function typeTransactionFeeSub($uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //账变负数
|
||||||
|
$bean->setType(self::TYPE_TRANSACTION_FEE_SUB);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
//检查余额是否足够
|
||||||
|
if (Math::bcComp($resWalletBalanceModel->available_amount, abs($bean->getAmount())) != -1) { //从余额中扣除
|
||||||
|
$bean->setSourceParams(self::SOURCE_PARAMS_BALANCE);
|
||||||
|
$res = $oCustomerWalletBalanceModel->subAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
} else if (Math::bcComp($resWalletBalanceModel->security_amount, abs($bean->getAmount())) != -1) { //从保证金中扣除
|
||||||
|
$bean->setSourceParams(self::SOURCE_PARAMS_SECURITY);
|
||||||
|
$res = $oCustomerWalletBalanceModel->subSecurityAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
} else {
|
||||||
|
throw new ModelException('balance and security not enough');
|
||||||
|
}
|
||||||
|
if (!$res) throw new ModelException('transaction fee sub fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//仲裁判罚扣除
|
||||||
|
function typeDisputeSub($uid, $currency_code, $amount, $target_post_order_dispute_id, $remark = null): bool|int
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //账变负数
|
||||||
|
$bean->setType(self::TYPE_DISPUTE_SUB);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
$bean->setTargetPostOrderDisputeId($target_post_order_dispute_id);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
|
||||||
|
//新增账变
|
||||||
|
$resModel = $this->addTransaction($bean);
|
||||||
|
if (!$resModel) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
//检查余额是否足够
|
||||||
|
if (Math::bcComp($resWalletBalanceModel->available_amount, abs($bean->getAmount())) != -1) { //从余额中扣除
|
||||||
|
$bean->setSourceParams(self::SOURCE_PARAMS_BALANCE);
|
||||||
|
$res = $oCustomerWalletBalanceModel->subAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
} else if (Math::bcComp($resWalletBalanceModel->security_amount, abs($bean->getAmount())) != -1) { //从保证金中扣除
|
||||||
|
$bean->setSourceParams(self::SOURCE_PARAMS_SECURITY);
|
||||||
|
$res = $oCustomerWalletBalanceModel->subSecurityAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
} else {
|
||||||
|
throw new ModelException('balance and security not enough');
|
||||||
|
}
|
||||||
|
if (!$res) throw new ModelException('dispute sub fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return $resModel->id;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//仲裁判罚增加
|
||||||
|
function typeDisputeAdd($uid, $currency_code, $amount, $target_post_order_dispute_id, $remark = null): bool|int
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_DISPUTE_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
$bean->setTargetPostOrderDisputeId($target_post_order_dispute_id);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$resModel = $this->addTransaction($bean);
|
||||||
|
if (!$resModel) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$res = $oCustomerWalletBalanceModel->addAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('dispute add fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return $resModel->id;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//押金转余额
|
||||||
|
function typeSecurityToBalance($uid, $currency_code, $amount): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_SECURITY_TO_BALANCE);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
|
||||||
|
//检查保证金是否足够
|
||||||
|
if (Math::bcComp($resWalletBalanceModel->security_amount, abs($bean->getAmount())) == -1) throw new ModelException('security not enough');
|
||||||
|
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
|
||||||
|
//变更余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$res = $oCustomerWalletBalanceModel->securityToBalance($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('securityToBalance fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//余额转押金
|
||||||
|
function typeBalanceToSecurity($uid, $currency_code, $amount): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //账变负数
|
||||||
|
$bean->setType(self::TYPE_BALANCE_TO_SECURITY);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
|
||||||
|
//检查余额是否足够
|
||||||
|
if (Math::bcComp($resWalletBalanceModel->available_amount, abs($bean->getAmount())) == -1) throw new ModelException('balance not enough');
|
||||||
|
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
|
||||||
|
//变更余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$res = $oCustomerWalletBalanceModel->balanceToSecurity($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('balanceToSecurity fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//订单支付
|
||||||
|
function typeOrderPay(CustomerUserPostOrderBean $orderBean): bool
|
||||||
|
{
|
||||||
|
//初始检测
|
||||||
|
if ($orderBean->getBuyerCurrencyCode() != $orderBean->getSellerCurrencyCode()) throw new ModelException('currency_code not match');
|
||||||
|
if ($orderBean->getBuyerUid() == $orderBean->getSellerUid()) throw new ModelException('buyer_uid can not match seller_uid');
|
||||||
|
if ($orderBean->getAmount() <= 0) throw new ModelException('amount error');
|
||||||
|
$orderBean->setAmount(abs($orderBean->getAmount())); //限制正数
|
||||||
|
|
||||||
|
$buyerWalletTransactionBean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$sellerWalletTransactionBean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
//买家初始化
|
||||||
|
$buyerWalletTransactionBean->setType(self::TYPE_ORDER_PAY_DEC);
|
||||||
|
$buyerWalletTransactionBean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$buyerWalletTransactionBean->setAmount(-$orderBean->getAmount()); //负数
|
||||||
|
$buyerWalletTransactionBean->setUid($orderBean->getBuyerUid());
|
||||||
|
$buyerWalletTransactionBean->setCurrencyCode($orderBean->getBuyerCurrencyCode());
|
||||||
|
$buyerWalletTransactionBean->setTargetPostOrderId($orderBean->getId());
|
||||||
|
//卖家初始化
|
||||||
|
$sellerWalletTransactionBean->setType(self::TYPE_ORDER_RECEIVE_ADD);
|
||||||
|
$sellerWalletTransactionBean->setStatus(self::STATUS_DELAY_PAYMENT);
|
||||||
|
$sellerWalletTransactionBean->setAmount($orderBean->getAmount()); //正数
|
||||||
|
$sellerWalletTransactionBean->setUid($orderBean->getSellerUid());
|
||||||
|
$sellerWalletTransactionBean->setCurrencyCode($orderBean->getSellerCurrencyCode());
|
||||||
|
$sellerWalletTransactionBean->setTargetPostOrderId($orderBean->getId());
|
||||||
|
//@@计算订单延期到账时间
|
||||||
|
$delay_payment_time = Times::getNowDateTimeAddDays(1);
|
||||||
|
$sellerWalletTransactionBean->setDelayPaymentTime($delay_payment_time);
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询买家余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resBuyerWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($buyerWalletTransactionBean->getUid(), $buyerWalletTransactionBean->getCurrencyCode());
|
||||||
|
if (!$resBuyerWalletBalanceModel) throw new ModelException('buyer wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resBuyerWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resBuyerWalletBalanceModel->id);
|
||||||
|
//检查买家余额是否足够
|
||||||
|
if (Math::bcComp($resBuyerWalletBalanceModel->available_amount, abs($orderBean->getAmount())) == -1) throw new ModelException('buyer balance not enough');
|
||||||
|
|
||||||
|
//设置买家卖家钱包id
|
||||||
|
$buyerWalletTransactionBean->setWalletId($resBuyerWalletBalanceModel->id);
|
||||||
|
$buyerWalletTransactionBean->setBeforeTotalAmount($resBuyerWalletBalanceModel->total_amount);
|
||||||
|
$buyerWalletTransactionBean->setAfterTotalAmount(Math::bcAdd($resBuyerWalletBalanceModel->total_amount, $buyerWalletTransactionBean->getAmount()));
|
||||||
|
//设置卖家卖家钱包id
|
||||||
|
$resSellerWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($sellerWalletTransactionBean->getUid(), $sellerWalletTransactionBean->getCurrencyCode());
|
||||||
|
if (!$resSellerWalletBalanceModel) throw new ModelException('seller wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resSellerWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resSellerWalletBalanceModel->id);
|
||||||
|
$sellerWalletTransactionBean->setWalletId($resSellerWalletBalanceModel->id);
|
||||||
|
$sellerWalletTransactionBean->setBeforeTotalAmount($resSellerWalletBalanceModel->total_amount);
|
||||||
|
$sellerWalletTransactionBean->setAfterTotalAmount(Math::bcAdd($resSellerWalletBalanceModel->total_amount, $sellerWalletTransactionBean->getAmount()));
|
||||||
|
|
||||||
|
//买家新增账变
|
||||||
|
$resBuyerTransaction = $this->addTransaction($buyerWalletTransactionBean);
|
||||||
|
if (!$resBuyerTransaction) throw new ModelException('buyer addTransaction fail');
|
||||||
|
$buyerWalletTransactionBean->setId($resBuyerTransaction->id);
|
||||||
|
//买家变更余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$res = $oCustomerWalletBalanceModel->subAvailableAmount($buyerWalletTransactionBean->getWalletId(), $buyerWalletTransactionBean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('buyer order pay fail');
|
||||||
|
|
||||||
|
//卖家新增账变
|
||||||
|
$resSellerTransaction = $this->addTransaction($sellerWalletTransactionBean);
|
||||||
|
if (!$resSellerTransaction) throw new ModelException('seller addTransaction fail');
|
||||||
|
$sellerWalletTransactionBean->setId($resSellerTransaction->id);
|
||||||
|
//卖家变更余额
|
||||||
|
$res = $oCustomerWalletBalanceModel->addFrozenAmount($sellerWalletTransactionBean->getWalletId(), $sellerWalletTransactionBean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('seller order receive fail');
|
||||||
|
|
||||||
|
//更新订单状态
|
||||||
|
$oCustomerUserPostOrderModel = new CustomerUserPostOrderModel();
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $orderBean->getId(),
|
||||||
|
'pay_status' => CustomerUserPostOrderModel::PAY_STATUS_PAID,
|
||||||
|
'buyer_wallet_transaction_id' => $buyerWalletTransactionBean->getId(),
|
||||||
|
'seller_wallet_transaction_id' => $sellerWalletTransactionBean->getId(),
|
||||||
|
'updated_at' => Times::getNowDateTime(),
|
||||||
|
];
|
||||||
|
$res = $oCustomerUserPostOrderModel->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('updateItem fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//发起提现
|
||||||
|
function typeWithdrawFirst($uid, $currency_code, $amount): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //负数
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setType(self::TYPE_WITHDRAW_DEC);
|
||||||
|
$bean->setStatus(self::STATUS_PROCESSING);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//获取提现手续费
|
||||||
|
$oTableCustomerSettingCache = new TableCustomerSettingCache();
|
||||||
|
$withdraw_fee = $oTableCustomerSettingCache->getWithdrawFeeAmount();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
//检查余额是否足够
|
||||||
|
if (Math::bcComp(Math::bcSub($resWalletBalanceModel->available_amount, $withdraw_fee), abs($bean->getAmount())) == -1) throw new ModelException('balance not enough');
|
||||||
|
|
||||||
|
$bean->setFeeAmount($withdraw_fee);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//先扣除手续费
|
||||||
|
$res = $this->typeTransactionFeeSub($uid, $currency_code, $withdraw_fee, $res->id . ' withdraw fee');
|
||||||
|
if (!$res) throw new ModelException('withdraw fee fail');
|
||||||
|
//变更余额
|
||||||
|
//先冻结,等回调成功再扣减
|
||||||
|
$res = $oCustomerWalletBalanceModel->frozenAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('withdraw fail');
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
//@@发送到提现通知钱包队列
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//提现回调
|
||||||
|
function typeWithdrawSecondCallback($id, $status, $remark = null): bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$resModel = $this->findItem($id);
|
||||||
|
if (!$resModel) throw new ModelException('transaction not found');
|
||||||
|
if ($resModel->status != self::STATUS_PROCESSING) throw new ModelException('transaction status error');
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findItem($resModel->wallet_id);
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
|
||||||
|
if ($status == self::STATUS_SUCCESS) {
|
||||||
|
//扣减冻结金额
|
||||||
|
$res = $oCustomerWalletBalanceModel->subFrozenAmount($resModel->wallet_id, $resModel->amount);
|
||||||
|
if (!$res) throw new ModelException('withdraw fail');
|
||||||
|
//更新账变状态
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'status' => self::STATUS_SUCCESS,
|
||||||
|
'updated_at' => Times::getNowDateTime(),
|
||||||
|
'before_total_amount' => $resWalletBalanceModel->total_amount,
|
||||||
|
'after_total_amount' => Math::bcAdd($resWalletBalanceModel->total_amount, $resModel->amount)
|
||||||
|
];
|
||||||
|
if (!empty($remark)) $updateItem['remark'] = $remark;
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('updateItem fail');
|
||||||
|
} else { //失败
|
||||||
|
//解冻
|
||||||
|
$res = $oCustomerWalletBalanceModel->unFrozenAmount($resModel->wallet_id, $resModel->amount);
|
||||||
|
if (!$res) throw new ModelException('withdraw fail');
|
||||||
|
//更新账变状态
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'status' => self::STATUS_FAIL,
|
||||||
|
'updated_at' => Times::getNowDateTime(),
|
||||||
|
];
|
||||||
|
if (!empty($remark)) $updateItem['remark'] = $remark;
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('updateItem fail');
|
||||||
|
//返还手续费
|
||||||
|
$res = $this->typeTransactionFeeAdd($resModel->uid, $resModel->currency_code, $resModel->fee_amount, $resModel->id . ' withdraw fail return fee');
|
||||||
|
if (!$res) throw new ModelException('withdraw fail return fee fail');
|
||||||
|
}
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//充值
|
||||||
|
function typeRecharge($uid, $currency_code, $amount): bool
|
||||||
|
{
|
||||||
|
$bean = new CustomerWalletBalanceTransactionBean();
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setType(self::TYPE_RECHARGE_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询用户余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByUidCurrencyCode($bean->getUid(), $bean->getCurrencyCode());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
//加悲观锁
|
||||||
|
$resWalletBalanceModel = $oCustomerWalletBalanceModel->findByWhereWithLock($resWalletBalanceModel->id);
|
||||||
|
$bean->setWalletId($resWalletBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resWalletBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$oCustomerWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$res = $oCustomerWalletBalanceModel->addAvailableAmount($bean->getWalletId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('recharge fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__.'typeRecharge error rollBack', $e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTransaction(CustomerWalletBalanceTransactionBean &$bean): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
if (!$bean->getWalletId()) throw new ModelException('wallet_id is required');
|
||||||
|
if (!$bean->getType()) throw new ModelException('type is required');
|
||||||
|
if (!$bean->getStatus()) $bean->setStatus(self::STATUS_WAIT);
|
||||||
|
if (empty($bean->getUid()) || empty($bean->getBeforeTotalAmount())) {
|
||||||
|
$oWalletBalanceModel = new CustomerWalletBalanceModel();
|
||||||
|
$resWalletBalanceModel = $oWalletBalanceModel->findItem($bean->getWalletId());
|
||||||
|
if (!$resWalletBalanceModel) throw new ModelException('wallet not found');
|
||||||
|
$bean->setUid($resWalletBalanceModel->uid);
|
||||||
|
$bean->setBeforeTotalAmount($resWalletBalanceModel->total_amount);
|
||||||
|
}
|
||||||
|
$bean->setCreatedAt(Times::getNowDateTime());
|
||||||
|
$bean->setUpdatedAt(Times::getNowDateTime());
|
||||||
|
return $this->addItem($bean->toArrayNotNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
29
app/Models/Api/Wallet/CustomerWalletCurrencyModel.php
Normal file
29
app/Models/Api/Wallet/CustomerWalletCurrencyModel.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models\Api\Wallet;
|
||||||
|
|
||||||
|
use App\Models\Api\Base\ApiBaseModel;
|
||||||
|
use Spatie\FlareClient\Api;
|
||||||
|
|
||||||
|
class CustomerWalletCurrencyModel extends ApiBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'customer_wallet_currency';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'type',
|
||||||
|
'name',
|
||||||
|
'code',
|
||||||
|
'token',
|
||||||
|
'transfer_rate',
|
||||||
|
'desc',
|
||||||
|
'created_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
const TYPE_CASH = 1;
|
||||||
|
const TYPE_CRYPTO_COIN = 2;
|
||||||
|
const TYPE = [
|
||||||
|
self::TYPE_CASH => '现金',
|
||||||
|
self::TYPE_CRYPTO_COIN => '加密货币',
|
||||||
|
];
|
||||||
|
const CODE_USDT_TRC20 = 'USDT_TRC20';
|
||||||
|
}
|
||||||
@ -8,6 +8,13 @@ class BaseModel extends Model
|
|||||||
{
|
{
|
||||||
public $timestamps = false;
|
public $timestamps = false;
|
||||||
|
|
||||||
|
const LOCK_TYPE_FOR_UPDATE = 1;
|
||||||
|
const LOCK_TYPE_FOR_SHARE = 2;
|
||||||
|
const LOCK_TYPE = [
|
||||||
|
self::LOCK_TYPE_FOR_UPDATE => '悲观锁',
|
||||||
|
self::LOCK_TYPE_FOR_SHARE => '乐观锁',
|
||||||
|
];
|
||||||
|
|
||||||
function checkColInFill($aItem)
|
function checkColInFill($aItem)
|
||||||
{
|
{
|
||||||
foreach ($aItem as $key => $value) {
|
foreach ($aItem as $key => $value) {
|
||||||
@ -43,7 +50,8 @@ class BaseModel extends Model
|
|||||||
if(!$col) $col = $this->primaryKey;
|
if(!$col) $col = $this->primaryKey;
|
||||||
$aItem = $this->checkColInFill($aItem);
|
$aItem = $this->checkColInFill($aItem);
|
||||||
if (empty($aItem)) return false;
|
if (empty($aItem)) return false;
|
||||||
if (isset($aItem[$col])) return false;
|
if (!isset($aItem[$col])) return false;
|
||||||
|
if (empty($aItem[$col])) return false;
|
||||||
return $this->newQuery()->where($col,$aItem[$col])->update($aItem);
|
return $this->newQuery()->where($col,$aItem[$col])->update($aItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -63,6 +71,28 @@ class BaseModel extends Model
|
|||||||
return $this->newQuery()->where($aWhere)->get($col);
|
return $this->newQuery()->where($aWhere)->get($col);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function findByPrimaryKeyWithLock($id,$lock_type = self::LOCK_TYPE_FOR_UPDATE): Model|\Illuminate\Database\Eloquent\Builder|null
|
||||||
|
{
|
||||||
|
$model = $this->newQuery()->where($this->primaryKey, $id);
|
||||||
|
if($lock_type == self::LOCK_TYPE_FOR_SHARE){
|
||||||
|
$model = $model->sharedLock();
|
||||||
|
}elseif ($lock_type == self::LOCK_TYPE_FOR_UPDATE){
|
||||||
|
$model = $model->lockForUpdate();
|
||||||
|
}
|
||||||
|
return $model->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
function findByWhereWithLock($id,$col=['*'],$lock_type = self::LOCK_TYPE_FOR_UPDATE): Model|\Illuminate\Database\Eloquent\Builder|null
|
||||||
|
{
|
||||||
|
$model = $this->newQuery()->where($this->primaryKey, $id);
|
||||||
|
if($lock_type == self::LOCK_TYPE_FOR_SHARE){
|
||||||
|
$model = $model->sharedLock();
|
||||||
|
}elseif ($lock_type == self::LOCK_TYPE_FOR_UPDATE){
|
||||||
|
$model = $model->lockForUpdate();
|
||||||
|
}
|
||||||
|
return $model->first($col);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Models\Wallet\Wallet;
|
|
||||||
|
namespace App\Models\Wallet\Other;
|
||||||
|
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
|
|
||||||
@ -11,6 +12,7 @@ class WalletSettingModel extends WalletBaseModel
|
|||||||
'id',
|
'id',
|
||||||
'name',
|
'name',
|
||||||
'value',
|
'value',
|
||||||
|
'remark',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
];
|
];
|
||||||
@ -67,57 +67,70 @@ class WalletPlatformBalanceModel extends WalletBaseModel
|
|||||||
}
|
}
|
||||||
return $resModel;
|
return $resModel;
|
||||||
}
|
}
|
||||||
|
function frozenAmount($id,$amount): bool|int
|
||||||
//增加平台余额
|
|
||||||
function incAvailableBalance($id, $amount): bool
|
|
||||||
{
|
{
|
||||||
$amount = abs($amount);
|
$amount = abs($amount);
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['total_amount', 'available_amount']);
|
$updateItem = [
|
||||||
if (!$oModel) throw new ModelException('找不到id');
|
'id' => $id,
|
||||||
$oModel->frozen_amount = Db::raw('total_amount + ' . $amount);
|
'frozen_amount' => DB::raw('frozen_amount + '. $amount),
|
||||||
$oModel->available_amount = Db::raw('available_amount + ' . $amount);
|
'available_amount' => DB::raw('available_amount - '. $amount),
|
||||||
return $oModel->save();
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
//扣除平台余额
|
function unFrozenAmount($id,$amount): bool|int
|
||||||
function decAvailableBalance($id, $amount): bool
|
|
||||||
{
|
{
|
||||||
$amount = abs($amount);
|
$amount = abs($amount);
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['total_amount', 'available_amount']);
|
$updateItem = [
|
||||||
if (!$oModel) throw new ModelException('找不到id');
|
'id' => $id,
|
||||||
$oModel->frozen_amount = Db::raw('total_amount - ' . $amount);
|
'frozen_amount' => DB::raw('frozen_amount - '. $amount),
|
||||||
$oModel->available_amount = Db::raw('available_amount - ' . $amount);
|
'available_amount' => DB::raw('available_amount + '. $amount),
|
||||||
return $oModel->save();
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
function decFrozenAmountById($id, $amount): int
|
function subFrozenAmount($id, $amount): bool|int
|
||||||
{
|
{
|
||||||
$amount = abs($amount);
|
$amount = abs($amount);
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['total_amount', 'frozen_amount']);
|
$updateItem = [
|
||||||
if (!$oModel) throw new ModelException('找不到id');
|
'id' => $id,
|
||||||
$oModel->frozen_amount = Db::raw('frozen_amount - ' . $amount);
|
'total_amount' => DB::raw('total_amount - '. $amount),
|
||||||
$oModel->total_amount = Db::raw('total_amount - ' . $amount);
|
'frozen_amount' => DB::raw('frozen_amount - '. $amount),
|
||||||
return $oModel->save();
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
function unFrozenAmountById($id, $amount): int
|
function addFrozenAmount($id, $amount): bool|int
|
||||||
{
|
{
|
||||||
$amount = abs($amount);
|
$amount = abs($amount);
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['frozen_amount', 'available_amount']);
|
$updateItem = [
|
||||||
if (!$oModel) throw new ModelException('找不到id');
|
'id' => $id,
|
||||||
$oModel->frozen_amount = Db::raw('frozen_amount - ' . $amount);
|
'total_amount' => DB::raw('total_amount + '. $amount),
|
||||||
$oModel->available_amount = Db::raw('available_amount + ' . $amount);
|
'frozen_amount' => DB::raw('frozen_amount + '. $amount),
|
||||||
return $oModel->save();
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
function frozenAmountById($id, $amount): int
|
function subAvailableAmount($id, $amount): bool|int
|
||||||
{
|
{
|
||||||
$amount = abs($amount);
|
$amount = abs($amount);
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['frozen_amount', 'available_amount']);
|
$updateItem = [
|
||||||
if (!$oModel) throw new ModelException('找不到id');
|
'id' => $id,
|
||||||
$oModel->frozen_amount = Db::raw('frozen_amount + ' . $amount);
|
'total_amount' => DB::raw('total_amount - '. $amount),
|
||||||
$oModel->available_amount = Db::raw('available_amount - ' . $amount);
|
'available_amount' => DB::raw('available_amount - '. $amount),
|
||||||
return $oModel->save();
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addAvailableAmount($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'total_amount' => DB::raw('total_amount + '. $amount),
|
||||||
|
'available_amount' => DB::raw('available_amount + '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -2,245 +2,466 @@
|
|||||||
|
|
||||||
namespace App\Models\Wallet\Platform;
|
namespace App\Models\Wallet\Platform;
|
||||||
|
|
||||||
|
|
||||||
|
use App\Bean\Model\Wallet\Platform\WalletPlatformBalanceTransactionBean;
|
||||||
|
use App\Bean\Queue\Wallet\QueueNotifyToPlatformBean;
|
||||||
|
use App\Bean\Queue\Wallet\QueueWalletPlatformWithdrawTransferBean;
|
||||||
|
use App\Cache\Table\Wallet\TableWalletSettingCache;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Jobs\Wallet\WalletNotifyToPlatformQueue;
|
||||||
|
use App\Jobs\Wallet\WalletPlatformWithdrawTransferQueue;
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
use App\Models\Wallet\Wallet\WalletCurrencyModel;
|
use App\Models\Wallet\Wallet\WalletAddressModel;
|
||||||
|
use App\Tools\Logs;
|
||||||
use App\Tools\Math;
|
use App\Tools\Math;
|
||||||
use App\Tools\Times;
|
use App\Tools\Times;
|
||||||
use App\Tools\Tools;
|
use App\Tools\Tools;
|
||||||
use Illuminate\Support\Facades\DB;
|
use Illuminate\Support\Facades\DB;
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class WalletPlatformBalanceTransactionModel extends WalletBaseModel
|
class WalletPlatformBalanceTransactionModel extends WalletBaseModel
|
||||||
{
|
{
|
||||||
protected $table = 'wallet_platform_balance_transaction';
|
protected $table = 'wallet_address_transaction';
|
||||||
protected $primaryKey = 'id';
|
protected $primaryKey = 'id';
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'id',
|
'id',
|
||||||
|
'sn',
|
||||||
'type',
|
'type',
|
||||||
'status',
|
'status',
|
||||||
'platform_id',
|
'platform_id',
|
||||||
'currency_id',
|
|
||||||
'currency_code',
|
'currency_code',
|
||||||
'currency_type',
|
'balance_id',
|
||||||
'from_wallet_addr_id',
|
'block_transaction_id',
|
||||||
'from_user_transaction_id',
|
'bind_wallet_address_id',
|
||||||
'from_uid',
|
'bind_wallet_address',
|
||||||
'wallet_addr',
|
'from_wallet_address_id',
|
||||||
'from_wallet_transaction_id',
|
'from_wallet_address',
|
||||||
'received_amount',
|
'to_wallet_address_id',
|
||||||
'entered_amount',
|
'to_wallet_address',
|
||||||
|
'uid',
|
||||||
|
'amount',
|
||||||
'fee_amount',
|
'fee_amount',
|
||||||
'before_total_amount',
|
'before_total_amount',
|
||||||
'after_total_amount',
|
'after_total_amount',
|
||||||
'desc_key',
|
|
||||||
'desc',
|
|
||||||
'remark',
|
'remark',
|
||||||
'sign',
|
'source_wallet_id',
|
||||||
|
'callback_time',
|
||||||
|
'callback_wallet_address_transaction_id',
|
||||||
|
'is_notify',
|
||||||
'created_at',
|
'created_at',
|
||||||
'updated_at',
|
'updated_at',
|
||||||
];
|
];
|
||||||
|
|
||||||
const TYPE_USER_RECHARGE = 1;
|
const TYPE_RECHARGE_ADD = 1;
|
||||||
const TYPE_USER_WITHDRAW = 2;
|
const TYPE_WITHDRAW_DEC = 2;
|
||||||
const TYPE_ADMIN_ADD = 3;
|
|
||||||
const TYPE_ADMIN_DEC = 4;
|
const TYPE_TRANSACTION_FEE_SUB = 10;
|
||||||
|
const TYPE_TRANSACTION_FEE_ADD = 11;
|
||||||
|
const TYPE_ADMIN_ADD = 12;
|
||||||
|
const TYPE_ADMIN_SUB = 13;
|
||||||
const TYPE = [
|
const TYPE = [
|
||||||
self::TYPE_USER_RECHARGE => '用户充值',
|
self::TYPE_RECHARGE_ADD => '充值',
|
||||||
self::TYPE_USER_WITHDRAW => '用户提现',
|
self::TYPE_WITHDRAW_DEC => '提现',
|
||||||
self::TYPE_ADMIN_ADD => '管理员加',
|
self::TYPE_TRANSACTION_FEE_SUB => '交易手续费扣款',
|
||||||
self::TYPE_ADMIN_DEC => '管理员减',
|
self::TYPE_TRANSACTION_FEE_ADD => '交易手续费加款',
|
||||||
|
self::TYPE_ADMIN_ADD => '管理员加款',
|
||||||
|
self::TYPE_ADMIN_SUB => '管理员扣款',
|
||||||
];
|
];
|
||||||
|
|
||||||
const STATUS_WAITING_QUEUE = 1;
|
const STATUS_WAIT = 1;
|
||||||
const STATUS_CHAIN_WAITING_CALLBACK = 2;
|
const STATUS_PROCESSING = 2;
|
||||||
const STATUS_SUCCESS = 3;
|
const STATUS_SUCCESS = 3;
|
||||||
const STATUS_FAIL = 4;
|
const STATUS_FAIL = 4;
|
||||||
const STATUS = [
|
const STATUS = [
|
||||||
self::STATUS_WAITING_QUEUE => '等待队列',
|
self::STATUS_WAIT => '等待处理',
|
||||||
self::STATUS_CHAIN_WAITING_CALLBACK => '链上等待回调',
|
self::STATUS_PROCESSING => '处理中',
|
||||||
self::STATUS_SUCCESS => '成功',
|
self::STATUS_SUCCESS => '成功',
|
||||||
self::STATUS_FAIL => '失败',
|
self::STATUS_FAIL => '失败',
|
||||||
];
|
];
|
||||||
|
|
||||||
function addPlatformTransaction(
|
const IS_NOTIFY_WAIT = 1;
|
||||||
$type,
|
const IS_NOTIFY_PROCESS = 2;
|
||||||
$status,
|
const IS_NOTIFY_FINISH = 3;
|
||||||
$received_amount,
|
const IS_NOTIFY_FAIL = 4;
|
||||||
$entered_amount,
|
const IS_NOTIFY = [
|
||||||
$platform_id,
|
self::IS_NOTIFY_WAIT => '待处理',
|
||||||
$currency_code,
|
self::IS_NOTIFY_PROCESS => '处理中',
|
||||||
$from_uid = '',
|
self::IS_NOTIFY_FINISH => '处理完成',
|
||||||
$from_user_transaction_id = '',
|
self::IS_NOTIFY_FAIL => '处理失败',
|
||||||
$from_wallet_addr_id = '',
|
|
||||||
$wallet_addr = '',
|
|
||||||
$desc_key = '',
|
|
||||||
$desc = '',
|
|
||||||
$remark = '',
|
|
||||||
): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
|
||||||
$received_amount = abs($received_amount);
|
|
||||||
$entered_amount = abs($entered_amount);
|
|
||||||
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
|
||||||
$oWalletCurrencyModel = new WalletCurrencyModel();
|
|
||||||
$resWalletPlatformBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalance($platform_id, $currency_code);
|
|
||||||
if (!$resWalletPlatformBalanceModel) throw new ModelException('platform balance not found');
|
|
||||||
$resWalletCurrencyModel = $oWalletCurrencyModel->findByCode($currency_code);
|
|
||||||
if (!$resWalletCurrencyModel) throw new ModelException('currency_code error');
|
|
||||||
|
|
||||||
if (in_array($type, [self::TYPE_ADMIN_DEC, self::TYPE_USER_WITHDRAW])) {
|
|
||||||
if (Math::bcComp($resWalletPlatformBalanceModel->available_amount, $received_amount) == -1) throw new ModelException('platform balance not enough');
|
|
||||||
}
|
|
||||||
//提现费率计算
|
|
||||||
$fee_amount = 0;
|
|
||||||
if ($type == self::TYPE_USER_WITHDRAW) {
|
|
||||||
$fee_amount = $oWalletCurrencyModel->computeTransferRate($received_amount, $oWalletCurrencyModel->transfer_rate);
|
|
||||||
$entered_amount = Math::bcSub($received_amount, $fee_amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
if($type == self::TYPE_USER_RECHARGE){
|
|
||||||
$fee_amount = Math::bcSub($received_amount, $entered_amount);
|
|
||||||
}
|
|
||||||
|
|
||||||
$insert = [
|
|
||||||
'type' => $type,
|
|
||||||
'status' => $status,
|
|
||||||
'platform_id' => $platform_id,
|
|
||||||
'currency_id' => $resWalletPlatformBalanceModel->currency_id,
|
|
||||||
'currency_code' => $resWalletPlatformBalanceModel->currency_code,
|
|
||||||
'currency_type' => $resWalletPlatformBalanceModel->currency_type,
|
|
||||||
'from_wallet_addr_id' => $from_wallet_addr_id,
|
|
||||||
'from_user_transaction_id' => $from_user_transaction_id,
|
|
||||||
'from_uid' => $from_uid,
|
|
||||||
'wallet_addr' => $wallet_addr,
|
|
||||||
'received_amount' => $received_amount,
|
|
||||||
'entered_amount' => $entered_amount,
|
|
||||||
'fee_amount' => $fee_amount,
|
|
||||||
'before_total_amount' => $resWalletPlatformBalanceModel->total_amount,
|
|
||||||
'after_total_amount' => Math::bcAdd($resWalletPlatformBalanceModel->total_amount, $entered_amount),
|
|
||||||
'desc_key' => $desc_key,
|
|
||||||
'desc' => $desc,
|
|
||||||
'remark' => $remark,
|
|
||||||
];
|
];
|
||||||
// $insert['sign'] = '';
|
|
||||||
$insert['created_at'] = Times::getNowDateTime();
|
|
||||||
$insert['updated_at'] = Times::getNowDateTime();
|
|
||||||
return $this->addItem($insert);
|
|
||||||
}
|
|
||||||
|
|
||||||
//增加提现账变并且冻结平台金额
|
//管理员扣款
|
||||||
function newWithdrawPlatformTransaction(
|
function typeAdminSub($platform_id, $uid, $currency_code, $amount, $remark = null): bool
|
||||||
$amount,
|
|
||||||
$platform_id,
|
|
||||||
$currency_code,
|
|
||||||
$uid,
|
|
||||||
): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
{
|
||||||
|
$bean = new WalletPlatformBalanceTransactionBean();
|
||||||
|
$bean->setPlatformId($platform_id);
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //负数
|
||||||
|
$bean->setType(self::TYPE_ADMIN_SUB);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
try {
|
try {
|
||||||
Db::beginTransaction();
|
DB::beginTransaction();
|
||||||
$resModel = $this->addPlatformTransaction(self::TYPE_USER_WITHDRAW, self::STATUS_WAITING_QUEUE, $amount,$amount, $platform_id, $currency_code,$uid);
|
//查询平台余额
|
||||||
if(!$resModel) throw new ModelException('addPlatformTransaction error');
|
|
||||||
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
||||||
$res = $oWalletPlatformBalanceModel->findPlatformBalance($platform_id,$currency_code);
|
$resBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalanceOrCreate($platform_id, $currency_code);
|
||||||
if (!$res) throw new ModelException('findPlatformBalance error');
|
if (!$resBalanceModel) throw new ModelException('findPlatformBalanceOrCreate error');
|
||||||
$res = $oWalletPlatformBalanceModel->frozenAmountById($oWalletPlatformBalanceModel->id, $amount); //变更平台余额
|
//加悲观锁
|
||||||
if (!$res) throw new ModelException('frozenAmountById error');
|
$resBalanceModel = $oWalletPlatformBalanceModel->findByWhereWithLock($resBalanceModel->id);
|
||||||
Db::commit();
|
|
||||||
return $resModel;
|
|
||||||
}catch (\Exception $e) {
|
|
||||||
Db::rollBack();
|
|
||||||
Log::error('newWithdrawPlatformTransaction', ['code' => $e->getCode(), 'error' => $e->getMessage()]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
$bean->setBalanceId($resBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcSub($resBalanceModel->total_amount, abs($amount)));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oWalletPlatformBalanceModel->subAvailableAmount($bean->getBalanceId(), abs($amount));
|
||||||
|
if (!$res) throw new ModelException('subAvailableAmount fail');
|
||||||
|
|
||||||
//成功提现处理
|
DB::commit();
|
||||||
function withdrawSuccByUserTransactionId($user_transaction_id, $remark = ''): bool
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
{
|
|
||||||
try{
|
|
||||||
Db::beginTransaction();
|
|
||||||
$resModel = $this->findItemByWhere(['from_user_transaction_id' => $user_transaction_id, 'type' => self::TYPE_USER_WITHDRAW]);
|
|
||||||
if (!$resModel) return false;
|
|
||||||
if (!in_array($resModel->status, [self::STATUS_WAITING_QUEUE, self::STATUS_CHAIN_WAITING_CALLBACK])) return false;
|
|
||||||
$resModel->status = self::STATUS_SUCCESS;
|
|
||||||
if(!empty($remark)) $resModel->remark = $remark;
|
|
||||||
$resModel->updated_at = Times::getNowDateTime();
|
|
||||||
$res = $resModel->save();
|
|
||||||
if(!$res) throw new ModelException('save error');
|
|
||||||
|
|
||||||
//扣除平台冻结余额
|
|
||||||
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
|
||||||
$resWalletPlatformBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalance($resModel->platform_id, $resModel->currency_code);
|
|
||||||
if (!$resWalletPlatformBalanceModel) throw new ModelException('platform balance not found');
|
|
||||||
$res = $oWalletPlatformBalanceModel->decFrozenAmountById($resWalletPlatformBalanceModel->id, $resModel->received_amount);
|
|
||||||
if (!$res) throw new ModelException('incBalance error');
|
|
||||||
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
}catch (\Exception $e){
|
|
||||||
Db::rollBack();
|
|
||||||
Log::error('withdrawSuccByUserTransactionIdErr', ['code' => $e->getCode(), 'error' => $e->getMessage()]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
//失败提现处理
|
|
||||||
function withdrawErrByUserTransactionId($user_transaction_id, $remark = ''): bool
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
Db::beginTransaction();
|
|
||||||
$resModel = $this->findItemByWhere(['from_user_transaction_id' => $user_transaction_id, 'type' => self::TYPE_USER_WITHDRAW]);
|
|
||||||
if (!$resModel) throw new ModelException('user transaction not found');
|
|
||||||
if (!in_array($resModel->status, [self::STATUS_WAITING_QUEUE, self::STATUS_CHAIN_WAITING_CALLBACK])) throw new ModelException('status error');
|
|
||||||
//更改账变状态
|
|
||||||
$resModel->status = self::STATUS_FAIL;
|
|
||||||
if(!empty($remark)) $resModel->remark = $remark;
|
|
||||||
$res = $resModel->save();
|
|
||||||
if (!$res) throw new ModelException('save error');
|
|
||||||
|
|
||||||
//解冻平台余额
|
|
||||||
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
|
||||||
$resWalletPlatformBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalance($resModel->platform_id, $resModel->currency_code);
|
|
||||||
if (!$resWalletPlatformBalanceModel) throw new ModelException('platform balance not found');
|
|
||||||
$res = $oWalletPlatformBalanceModel->unFrozenAmountById($resWalletPlatformBalanceModel->id, $resModel->received_amount);
|
|
||||||
if (!$res) throw new ModelException('incBalance error');
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
return true;
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
Db::rollBack();
|
DB::rollBack();
|
||||||
Log::error('withdrawErrByUserTransactionIdErr', ['code' => $e->getCode(), 'error' => $e->getMessage()]);
|
Logs::ErrLog(__FUNCTION__ . ' rollBack', $e, func_get_args());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function newRechargePlatformTransaction(
|
//管理员加款
|
||||||
$resWalletAddrTransactionModel,
|
function typeAdminAdd($platform_id, $uid, $currency_code, $amount, $remark = null): bool
|
||||||
$resWalletPlatformUserTransactionModel,
|
{
|
||||||
$amount,
|
$bean = new WalletPlatformBalanceTransactionBean();
|
||||||
$platform_id,
|
$bean->setPlatformId($platform_id);
|
||||||
$currency_code,
|
$bean->setUid($uid);
|
||||||
): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_ADMIN_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询平台余额
|
||||||
|
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalanceOrCreate($platform_id, $currency_code);
|
||||||
|
if (!$resBalanceModel) throw new ModelException('findPlatformBalanceOrCreate error');
|
||||||
|
//加悲观锁
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findByWhereWithLock($resBalanceModel->id);
|
||||||
|
$bean->setBalanceId($resBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oWalletPlatformBalanceModel->addAvailableAmount($bean->getBalanceId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('addAvailableAmount fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//手续费扣除
|
||||||
|
function typeTransactionFeeSub($platform_id, $uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new WalletPlatformBalanceTransactionBean();
|
||||||
|
$bean->setPlatformId($platform_id);
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //负数
|
||||||
|
$bean->setType(self::TYPE_TRANSACTION_FEE_SUB);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询平台余额
|
||||||
|
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalanceOrCreate($platform_id, $currency_code);
|
||||||
|
if (!$resBalanceModel) throw new ModelException('findPlatformBalanceOrCreate error');
|
||||||
|
//加悲观锁
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findByWhereWithLock($resBalanceModel->id);
|
||||||
|
|
||||||
|
$bean->setBalanceId($resBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcSub($resBalanceModel->total_amount, abs($amount)));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oWalletPlatformBalanceModel->subAvailableAmount($bean->getBalanceId(), abs($amount));
|
||||||
|
if (!$res) throw new ModelException('subAvailableAmount fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//手续费增加
|
||||||
|
function typeTransactionFeeAdd($platform_id, $uid, $currency_code, $amount, $remark = null): bool
|
||||||
|
{
|
||||||
|
$bean = new WalletPlatformBalanceTransactionBean();
|
||||||
|
$bean->setPlatformId($platform_id);
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_TRANSACTION_FEE_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setRemark($remark);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//查询平台余额
|
||||||
|
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalanceOrCreate($platform_id, $currency_code);
|
||||||
|
if (!$resBalanceModel) throw new ModelException('findPlatformBalanceOrCreate error');
|
||||||
|
//加悲观锁
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findByWhereWithLock($resBalanceModel->id);
|
||||||
|
|
||||||
|
$bean->setBalanceId($resBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oWalletPlatformBalanceModel->addAvailableAmount($bean->getBalanceId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('addAvailableAmount fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//充值
|
||||||
|
function typeRecharge($platform_id, $uid, $currency_code, $amount, $to_wallet_address_id = null, $tid = null, $callback_wallet_address_transaction_id = null): bool
|
||||||
|
{
|
||||||
|
$bean = new WalletPlatformBalanceTransactionBean();
|
||||||
|
$bean->setBlockTransactionId($tid);
|
||||||
|
$bean->setPlatformId($platform_id);
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(abs($amount)); //正数
|
||||||
|
$bean->setType(self::TYPE_RECHARGE_ADD);
|
||||||
|
$bean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$bean->setCallbackWalletAddressTransactionId($callback_wallet_address_transaction_id);
|
||||||
|
$bean->setToWalletAddressId($to_wallet_address_id);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//检测钱包地址和当前绑定地址是否一致
|
||||||
|
$oWalletPlatformBindModel = new WalletPlatformBindModel();
|
||||||
|
$resBindModel = $oWalletPlatformBindModel->findBind($platform_id, $uid, $currency_code);
|
||||||
|
if (!$resBindModel) throw new ModelException('WalletPlatformBindModel findBind error');
|
||||||
|
//查找钱包地址
|
||||||
|
$oWalletAddressModel = new WalletAddressModel();
|
||||||
|
$resWalletAddressModel = $oWalletAddressModel->findItem($resBindModel->wallet_address_id);
|
||||||
|
if (!$resWalletAddressModel) throw new ModelException('WalletAddressModel findItem error');
|
||||||
|
//检测异步到账地址是否和绑定地址一致
|
||||||
|
if (!empty($wallet_address_id)) {
|
||||||
|
if ($resWalletAddressModel->id != $to_wallet_address_id) throw new ModelException('wallet_address_id not same');
|
||||||
|
}
|
||||||
|
$bean->setBindWalletAddressId($resWalletAddressModel->id);
|
||||||
|
$bean->setBindWalletAddress($resWalletAddressModel->address_base58);
|
||||||
|
|
||||||
|
//查询平台余额
|
||||||
|
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalanceOrCreate($platform_id, $currency_code);
|
||||||
|
if (!$resBalanceModel) throw new ModelException('findPlatformBalanceOrCreate error');
|
||||||
|
//加悲观锁
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findByWhereWithLock($resBalanceModel->id);
|
||||||
|
$bean->setBalanceId($resBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcAdd($resBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//变更余额
|
||||||
|
$res = $oWalletPlatformBalanceModel->addAvailableAmount($bean->getBalanceId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('addAvailableAmount fail');
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' rollBack', $e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//发起提现
|
||||||
|
function typeWithdrawFirst($platform_id, $uid, $currency_code, $amount, $to_address = null): bool
|
||||||
|
{
|
||||||
|
$bean = new WalletPlatformBalanceTransactionBean();
|
||||||
|
$bean->setPlatformId($platform_id);
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setCurrencyCode($currency_code);
|
||||||
|
$bean->setAmount(-abs($amount)); //负数
|
||||||
|
$bean->setType(self::TYPE_WITHDRAW_DEC);
|
||||||
|
$bean->setStatus(self::STATUS_WAIT);
|
||||||
|
$bean->setToWalletAddress($to_address);
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//获取提现手续费
|
||||||
|
$oTableWalletSettingCache = new TableWalletSettingCache();
|
||||||
|
$withdraw_fee = $oTableWalletSettingCache->getWithdrawFeeAmount();
|
||||||
|
//查询平台余额
|
||||||
|
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalanceOrCreate($platform_id, $currency_code);
|
||||||
|
if (!$resBalanceModel) throw new ModelException('findPlatformBalanceOrCreate error');
|
||||||
|
//加悲观锁
|
||||||
|
$resBalanceModel = $oWalletPlatformBalanceModel->findByWhereWithLock($resBalanceModel->id);
|
||||||
|
//检查余额是否足够
|
||||||
|
if (Math::bcComp(Math::bcSub($resBalanceModel->available_amount, $withdraw_fee), abs($bean->getAmount())) == -1) throw new ModelException('available_amount not enough');
|
||||||
|
$bean->setBalanceId($resBalanceModel->id);
|
||||||
|
$bean->setBeforeTotalAmount($resBalanceModel->total_amount);
|
||||||
|
$bean->setAfterTotalAmount(Math::bcSub($resBalanceModel->total_amount, $bean->getAmount()));
|
||||||
|
$bean->setFeeAmount($withdraw_fee);
|
||||||
|
|
||||||
|
//查询当前绑定地址
|
||||||
|
$oWalletPlatformBindModel = new WalletPlatformBindModel();
|
||||||
|
$resBindModel = $oWalletPlatformBindModel->findBind($platform_id, $uid, $currency_code);
|
||||||
|
if (!$resBindModel) throw new ModelException('findBind error');
|
||||||
|
//查找钱包地址
|
||||||
|
$oWalletAddressModel = new WalletAddressModel();
|
||||||
|
$resWalletAddressModel = $oWalletAddressModel->findItem($resBindModel->wallet_address_id);
|
||||||
|
if (!$resWalletAddressModel) throw new ModelException('WalletAddressModel findItem error');
|
||||||
|
$bean->setBindWalletAddressId($resWalletAddressModel->id);
|
||||||
|
$bean->setBindWalletAddress($resWalletAddressModel->address_base58);
|
||||||
|
|
||||||
|
//新增账变
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction fail');
|
||||||
|
//先扣除手续费
|
||||||
|
$res = $this->typeTransactionFeeSub($platform_id, $uid, $currency_code, $withdraw_fee, $res->id .'withdraw fee');
|
||||||
|
if (!$res) throw new ModelException('withdraw fee fail');
|
||||||
|
//变更余额
|
||||||
|
//先冻结,等回调成功再扣减
|
||||||
|
$res = $oWalletPlatformBalanceModel->frozenAmount($bean->getBalanceId(), $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('frozenAmount fail');
|
||||||
|
|
||||||
|
//投递到提现处理队列
|
||||||
|
$oQueueWalletPlatformWithdrawBean = new QueueWalletPlatformWithdrawTransferBean();
|
||||||
|
$oQueueWalletPlatformWithdrawBean->setTransactionId($bean->getId());
|
||||||
|
WalletPlatformWithdrawTransferQueue::putToQueue($oQueueWalletPlatformWithdrawBean);
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . 'rollBack', $e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//提现回调
|
||||||
|
function typeWithdrawSecondCallback($id, $status, $remark = null, $callback_wallet_address_transaction_id = null): bool
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
Db::beginTransaction();
|
DB::beginTransaction();
|
||||||
$resModel = $this->addPlatformTransaction(self::TYPE_USER_RECHARGE, self::STATUS_SUCCESS, $amount,$amount, $platform_id, $currency_code,$resWalletPlatformUserTransactionModel->uid,$resWalletPlatformUserTransactionModel->id,$resWalletAddrTransactionModel->wallet_addr_id,$resWalletAddrTransactionModel->wallet_addr);
|
//获取账变
|
||||||
if(!$resModel) throw new ModelException('addPlatformTransaction error');
|
$resModel = $this->findItem($id);
|
||||||
|
if (!$resModel) throw new ModelException('findItem error');
|
||||||
|
if ($resModel->status != self::STATUS_PROCESSING) throw new ModelException('status error');
|
||||||
|
//查询平台余额
|
||||||
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
||||||
$resWalletPlatformBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalance($platform_id,$currency_code);
|
$resBalanceModel = $oWalletPlatformBalanceModel->findItem($resModel->balance_id);
|
||||||
if (!$resWalletPlatformBalanceModel) throw new ModelException('findPlatformBalance error');
|
if (!$resBalanceModel) throw new ModelException('WalletPlatformBalanceModel findItem error');
|
||||||
$res = $oWalletPlatformBalanceModel->incAvailableBalance($resWalletPlatformBalanceModel->id, $amount); //变更平台余额
|
//加悲观锁
|
||||||
if (!$res) throw new ModelException('frozenAmountById error');
|
$resBalanceModel = $oWalletPlatformBalanceModel->findByWhereWithLock($resBalanceModel->id);
|
||||||
Db::commit();
|
|
||||||
return $resModel;
|
if ($status == self::STATUS_SUCCESS) {
|
||||||
}catch (\Exception $e) {
|
//变更余额
|
||||||
Db::rollBack();
|
$res = $oWalletPlatformBalanceModel->subFrozenAmount($resModel->balance_id, $resModel->amount);
|
||||||
Log::error('newWithdrawPlatformTransaction', ['code' => $e->getCode(), 'error' => $e->getMessage()]);
|
if (!$res) throw new ModelException('subFrozenAmount error');
|
||||||
return false;
|
//更新账变状态
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'status' => self::STATUS_SUCCESS,
|
||||||
|
'remark' => $remark,
|
||||||
|
'updated_at' => Times::getNowDateTime(),
|
||||||
|
'callback_time' => Times::getNowDateTime(),
|
||||||
|
'after_total_amount' => Math::bcAdd($resBalanceModel->total_amount, $resModel->amount),
|
||||||
|
'before_total_amount' => $resBalanceModel->total_amount,
|
||||||
|
'callback_wallet_address_transaction_id' => $callback_wallet_address_transaction_id,
|
||||||
|
];
|
||||||
|
if (!empty($remark)) $updateItem['remark'] = $remark;
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('updateItem error');
|
||||||
|
//投递到通知平台队列
|
||||||
|
$oQueueNotifyToPlatformBean = new QueueNotifyToPlatformBean();
|
||||||
|
$oQueueNotifyToPlatformBean->setType(QueueNotifyToPlatformBean::TYPE_WITHDRAW);
|
||||||
|
$oQueueNotifyToPlatformBean->setPlatformId($resModel->platform_id);
|
||||||
|
$oQueueNotifyToPlatformBean->setCurrencyCode($resModel->currency_code);
|
||||||
|
$oQueueNotifyToPlatformBean->setAmount($resModel->amount);
|
||||||
|
$oQueueNotifyToPlatformBean->setStatus(self::STATUS_SUCCESS);
|
||||||
|
$oQueueNotifyToPlatformBean->setSn($resModel->sn);
|
||||||
|
|
||||||
|
WalletNotifyToPlatformQueue::putToQueue($oQueueNotifyToPlatformBean);
|
||||||
|
} else {
|
||||||
|
//变更余额
|
||||||
|
$res = $oWalletPlatformBalanceModel->unFrozenAmount($resModel->balance_id, $resModel->amount);
|
||||||
|
if (!$res) throw new ModelException('unFrozenAmount error');
|
||||||
|
//更新账变状态
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'status' => self::STATUS_FAIL,
|
||||||
|
'updated_at' => Times::getNowDateTime(),
|
||||||
|
'callback_time' => Times::getNowDateTime(),
|
||||||
|
'callback_wallet_address_transaction_id' => $callback_wallet_address_transaction_id,
|
||||||
|
];
|
||||||
|
if (!empty($remark)) $updateItem['remark'] = $remark;
|
||||||
|
$res = $this->updateItem($updateItem);
|
||||||
|
if (!$res) throw new ModelException('updateItem error');
|
||||||
|
//返还手续费
|
||||||
|
$res = $this->typeTransactionFeeAdd($resModel->platform_id, $resModel->uid, $resModel->currency_code, $resModel->fee_amount, $resModel->id . 'withdraw fail return fee');
|
||||||
|
if (!$res) throw new ModelException('withdraw fail return fee fail');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function addTransaction(WalletPlatformBalanceTransactionBean &$bean): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
if (!$bean->getPlatformId()) throw new ModelException('addTransaction getPlatformId is required');
|
||||||
|
if (!$bean->getCurrencyCode()) throw new ModelException('addTransaction getCurrencyCode is required');
|
||||||
|
if (!$bean->getType()) throw new ModelException('addTransaction getType is required');
|
||||||
|
if (!$bean->getStatus()) throw new ModelException('addTransaction getStatus is required');
|
||||||
|
if (!$bean->getBalanceId()) throw new ModelException('addTransaction getBalanceId is required');
|
||||||
|
if (!$bean->getBindWalletAddressId()) throw new ModelException('addTransaction getBindWalletAddressId is required');
|
||||||
|
if (empty($bean->getSn())) $bean->setSn(Tools::genUuid());
|
||||||
|
$bean->setCreatedAt(Times::getNowDateTime());
|
||||||
|
return $this->addItem($bean->toArrayNotNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
function findByBlockTransactionId(string $tid, $type): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
|
{
|
||||||
|
if (!in_array($type, [self::TYPE_RECHARGE_ADD, self::TYPE_WITHDRAW_DEC])) throw new ModelException('type error');
|
||||||
|
return $this->findItemByWhere(['block_transaction_id' => $tid, 'type' => $type]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,47 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Wallet\Platform;
|
||||||
|
|
||||||
|
use App\Bean\Model\Wallet\Wallet\WalletPlatformBindBean;
|
||||||
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
|
use App\Models\Wallet\Wallet\WalletAddressModel;
|
||||||
|
use App\Models\Wallet\Wallet\WalletCurrencyModel;
|
||||||
|
use App\Tools\Logs;
|
||||||
|
use App\Tools\Math;
|
||||||
|
use App\Tools\Times;
|
||||||
|
use App\Tools\Tools;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class WalletPlatformBindHistoryModel extends WalletBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'wallet_platform_bind_history';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'orgi_id',
|
||||||
|
'platform_id',
|
||||||
|
'wallet_address_id',
|
||||||
|
'currency_code',
|
||||||
|
'uid',
|
||||||
|
'orgi_created_at',
|
||||||
|
'remark',
|
||||||
|
'created_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
function addHistory($aItem,$remark = ''): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
$aItem['orgi_created_at'] = $aItem['created_at'];
|
||||||
|
$aItem['orgi_id'] = $aItem['id'];
|
||||||
|
unset($aItem['id']);
|
||||||
|
unset($aItem['created_at']);
|
||||||
|
$aItem['remark'] = $remark;
|
||||||
|
$aItem['created_at'] = Times::getNowDateTime();
|
||||||
|
return $this->addItem($aItem);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
169
app/Models/Wallet/Platform/WalletPlatformBindModel.php
Normal file
169
app/Models/Wallet/Platform/WalletPlatformBindModel.php
Normal file
@ -0,0 +1,169 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Wallet\Platform;
|
||||||
|
|
||||||
|
use App\Bean\Model\Wallet\Wallet\WalletPlatformBindBean;
|
||||||
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
|
use App\Models\Wallet\Wallet\WalletAddressModel;
|
||||||
|
use App\Models\Wallet\Wallet\WalletCurrencyModel;
|
||||||
|
use App\Tools\Logs;
|
||||||
|
use App\Tools\Math;
|
||||||
|
use App\Tools\Times;
|
||||||
|
use App\Tools\Tools;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class WalletPlatformBindModel extends WalletBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'wallet_platform_bind';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'platform_id',
|
||||||
|
'wallet_address_id',
|
||||||
|
'currency_code',
|
||||||
|
'uid',
|
||||||
|
'created_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
public function getBindInfo($platformId, $walletAddressId, $currencyCode, $uid): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
||||||
|
{
|
||||||
|
return $this->newQuery()
|
||||||
|
->where('platform_id', $platformId)
|
||||||
|
->where('wallet_address_id', $walletAddressId)
|
||||||
|
->where('currency_code', $currencyCode)
|
||||||
|
->where('uid', $uid)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkIsBind($platformId, $uid, $currencyCode): bool
|
||||||
|
{
|
||||||
|
$res = $this->findBind($platformId, $uid, $currencyCode,['id']);
|
||||||
|
if($res) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function findBind($platformId, $uid, $currencyCode,$cols = ['*']): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
||||||
|
{
|
||||||
|
if(empty($uid)) $uid = 0; //平台默认充提地址
|
||||||
|
return $this->newQuery()
|
||||||
|
->where('platform_id', $platformId)
|
||||||
|
->where('currency_code', $currencyCode)
|
||||||
|
->where('uid', $uid)
|
||||||
|
->first($cols)
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
//查找空余钱包地址分配给平台
|
||||||
|
function addBindWallet($platformId, $uid = null, $currencyCode = WalletCurrencyModel::CODE_USDT_TRC20): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
$res = $this->checkIsBind($platformId, $uid, $currencyCode);
|
||||||
|
if($res) return false;
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
//检测是否已经绑定
|
||||||
|
$this->getBindInfo( $platformId, $uid, $currencyCode);
|
||||||
|
$oWalletAddressModel = new WalletAddressModel();
|
||||||
|
$resWalletAddressModel = $oWalletAddressModel->findFreeAddress($currencyCode);
|
||||||
|
if ($resWalletAddressModel) {
|
||||||
|
throw new ModelException("can not find free address");
|
||||||
|
}
|
||||||
|
$bean = new WalletPlatformBindBean();
|
||||||
|
$bean->setPlatformId($platformId);
|
||||||
|
$bean->setCurrencyCode($currencyCode);
|
||||||
|
$bean->setUid($uid);
|
||||||
|
$bean->setWalletAddressId($resWalletAddressModel->id);
|
||||||
|
$bean->setCreatedAt(Times::getNowDateTime());
|
||||||
|
$res = $this->addItem($bean->toArrayNotNull());
|
||||||
|
if(!$res) throw new ModelException("add bind fail");
|
||||||
|
//更新钱包地址状态
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $resWalletAddressModel->id,
|
||||||
|
'use_status' => WalletAddressModel::USE_STATUS_USING,
|
||||||
|
];
|
||||||
|
$res = $oWalletAddressModel->updateItem($updateItem);
|
||||||
|
if(!$res) throw new ModelException("change use_status fail wallet_address_id:{$resWalletAddressModel->id}");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, $bean->toArrayNotNull());
|
||||||
|
return true;
|
||||||
|
}catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//解绑
|
||||||
|
function unBindWithUid($platformId, $uid, $currencyCode = WalletCurrencyModel::CODE_USDT_TRC20,$remark = ''): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
$res = $this->checkIsBind($platformId, $uid, $currencyCode);
|
||||||
|
if(!$res) return true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
$oWalletAddressModel = new WalletAddressModel();
|
||||||
|
$oWalletPlatformBindModel = new WalletPlatformBindModel();
|
||||||
|
$resWalletPlatformBindModel = $oWalletPlatformBindModel->newQuery()
|
||||||
|
->where('platform_id', $platformId)
|
||||||
|
->where('currency_code', $currencyCode)
|
||||||
|
->where('uid', $uid)
|
||||||
|
->first();
|
||||||
|
if (!$resWalletPlatformBindModel) return true;
|
||||||
|
|
||||||
|
//废弃原有地址
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $resWalletPlatformBindModel->id,
|
||||||
|
'use_status' => WalletAddressModel::USE_STATUS_USED,
|
||||||
|
];
|
||||||
|
$res = $oWalletAddressModel->updateItem($updateItem);
|
||||||
|
if(!$res) throw new ModelException("change used use_status fail wallet_address_id:{$resWalletPlatformBindModel->wallet_address_id}");
|
||||||
|
|
||||||
|
//删除原有绑定记录
|
||||||
|
$res = $oWalletPlatformBindModel->delItem($resWalletPlatformBindModel->id);
|
||||||
|
if(!$res) throw new ModelException("delete bind fail");
|
||||||
|
|
||||||
|
//原有绑定记录添加到历史
|
||||||
|
$oWalletPlatformBindHistoryModel = new WalletPlatformBindHistoryModel();
|
||||||
|
$res = $oWalletPlatformBindHistoryModel->addHistory($resWalletPlatformBindModel->toArray(),$remark);
|
||||||
|
if(!$res) throw new ModelException("add history fail");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
}catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//绑定检测是否已绑定,未绑定则绑定,已绑定则解绑再绑定新地址
|
||||||
|
function bindWallet( $platformId, $currencyCode = WalletCurrencyModel::CODE_USDT_TRC20, $uid = null): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
try {
|
||||||
|
DB::beginTransaction();
|
||||||
|
|
||||||
|
$res = $this->unBindWithUid($platformId, $uid, $currencyCode);
|
||||||
|
if(!$res) throw new ModelException("unBindWithUid fail");
|
||||||
|
|
||||||
|
$res = $this->addBindWallet($platformId, $uid, $currencyCode);
|
||||||
|
if(!$res) throw new ModelException("addBindWallet fail");
|
||||||
|
|
||||||
|
DB::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, func_get_args());
|
||||||
|
return true;
|
||||||
|
}catch (\Exception $e) {
|
||||||
|
DB::rollBack();
|
||||||
|
Logs::ErrLog(__FUNCTION__ . ' ' . 'rollBack', $e, func_get_args());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,6 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
namespace App\Models\Wallet\Platform;
|
namespace App\Models\Wallet\Platform;
|
||||||
|
|
||||||
|
use App\Cache\Table\Wallet\TableWalletPlatformCache;
|
||||||
use App\Exceptions\ModelException;
|
use App\Exceptions\ModelException;
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
use App\Tools\Times;
|
use App\Tools\Times;
|
||||||
@ -49,10 +50,19 @@ class WalletPlatformModel extends WalletBaseModel
|
|||||||
return $resModel;
|
return $resModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
//@@给平台下发用户信息
|
function updateItem($aItem,$col = null): bool|int
|
||||||
static function userTransactionNotifyToPlatform($user_transaction_id)
|
|
||||||
{
|
{
|
||||||
|
$res = parent::updateItem($aItem,$col); // TODO: Change the autogenerated stub
|
||||||
|
if($res && isset($aItem[$this->primaryKey])) {
|
||||||
|
$this->delTableCache($aItem[$this->primaryKey]);
|
||||||
|
}
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
function delTableCache($key): bool
|
||||||
|
{
|
||||||
|
$oTableWalletPlatformCache = new TableWalletPlatformCache();
|
||||||
|
return $oTableWalletPlatformCache->del($key);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,351 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Wallet\PlatformUser;
|
|
||||||
|
|
||||||
use App\Cache\Lock\WalletPlatformUserTransactionLock;
|
|
||||||
use App\Exceptions\ModelException;
|
|
||||||
use App\Jobs\UserActiveStatusQueue;
|
|
||||||
use App\Jobs\WalletPlatformUserWithdrawQueue;
|
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
|
||||||
use App\Models\Wallet\Platform\WalletPlatformBalanceModel;
|
|
||||||
use App\Models\Wallet\Platform\WalletPlatformBalanceTransactionModel;
|
|
||||||
use App\Models\Wallet\Wallet\WalletAddrModel;
|
|
||||||
use App\Models\Wallet\Wallet\WalletAddrTransactionModel;
|
|
||||||
use App\Models\Wallet\Wallet\WalletCurrencyModel;
|
|
||||||
use App\Structs\QueueUserActiveStatusStruct;
|
|
||||||
use App\Structs\QueueWalletPlatformUserWithdrawStruct;
|
|
||||||
use App\Tools\Math;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class WalletPlatformUserTransactionModel extends WalletBaseModel
|
|
||||||
{
|
|
||||||
protected $table = 'wallet_platform_user_transaction';
|
|
||||||
protected $primaryKey = 'id';
|
|
||||||
protected $fillable = [
|
|
||||||
'id',
|
|
||||||
'type',
|
|
||||||
'platform_id',
|
|
||||||
'uid',
|
|
||||||
'currency_id',
|
|
||||||
'currency_code',
|
|
||||||
'currency_type',
|
|
||||||
'from_wallet_addr_id',
|
|
||||||
'wallet_addr',
|
|
||||||
'from_wallet_transaction_id',
|
|
||||||
'received_amount',
|
|
||||||
'entered_amount',
|
|
||||||
'fee_amount',
|
|
||||||
'desc_key',
|
|
||||||
'desc',
|
|
||||||
'remark',
|
|
||||||
'sign',
|
|
||||||
'platform_notify_status',
|
|
||||||
'created_at',
|
|
||||||
'updated_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
const TYPE_RECHARGE = 1;
|
|
||||||
const TYPE_WITHDRAW = 2;
|
|
||||||
const TYPE = [
|
|
||||||
self::TYPE_RECHARGE => '充值',
|
|
||||||
self::TYPE_WITHDRAW => '提现',
|
|
||||||
];
|
|
||||||
|
|
||||||
const STATUS_WAITING_QUEUE = 1;
|
|
||||||
const STATUS_CODE_PROCESSING = 2;
|
|
||||||
const STATUS_CHAIN_WAITING = 3;
|
|
||||||
const STATUS_SUCCESS = 4;
|
|
||||||
const STATUS_FAIL = 5;
|
|
||||||
const STATUS = [
|
|
||||||
self::STATUS_WAITING_QUEUE => '等待队列',
|
|
||||||
self::STATUS_CODE_PROCESSING => '程序处理中',
|
|
||||||
self::STATUS_CHAIN_WAITING => '链上等待',
|
|
||||||
self::STATUS_SUCCESS => '成功',
|
|
||||||
self::STATUS_FAIL => '失败',
|
|
||||||
];
|
|
||||||
|
|
||||||
const DESC_KEY_NOT_FOUND_WITHDRAW_AMOUNT_WALLET_ADDR = 'notFoundWithdrawAmountWalletAddr';
|
|
||||||
const DESC_KEY_WITHDRAW_WALLET_AMOUNT_LOW = 'withdrawWalletAmountLow';
|
|
||||||
const DESC_KEY_WITHDRAW_CALL_CHAIN_WRONG = 'withdrawCallChainWrong';
|
|
||||||
|
|
||||||
const DESC = [
|
|
||||||
self::DESC_KEY_NOT_FOUND_WITHDRAW_AMOUNT_WALLET_ADDR => '未找到足额提现金额钱包地址',
|
|
||||||
self::DESC_KEY_WITHDRAW_WALLET_AMOUNT_LOW => '提现钱包金额不足',
|
|
||||||
self::DESC_KEY_WITHDRAW_CALL_CHAIN_WRONG => '提现调用链上接口失败',
|
|
||||||
];
|
|
||||||
|
|
||||||
//请求提现发起
|
|
||||||
function withdrawFirst($amount, $platform_id, $uid, $currency_code, $desc_key = null, $remark = ''): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
Db::beginTransaction();
|
|
||||||
$amount = abs($amount);
|
|
||||||
//检查平台余额
|
|
||||||
$oWalletPlatformBalanceModel = new WalletPlatformBalanceModel();
|
|
||||||
$resWalletPlatformBalanceModel = $oWalletPlatformBalanceModel->findPlatformBalance($platform_id, $currency_code);
|
|
||||||
if (!$resWalletPlatformBalanceModel) throw new ModelException('platform_id or currency_code error');
|
|
||||||
if (Math::bcComp($resWalletPlatformBalanceModel->available_amount, $amount) == -1) throw new ModelException('platform balance not enough');
|
|
||||||
|
|
||||||
//冻结平台余额并增加账变
|
|
||||||
$oWalletPlatformBalanceTransactionModel = new WalletPlatformBalanceTransactionModel();
|
|
||||||
$resWalletPlatformBalanceTransactionModel = $oWalletPlatformBalanceTransactionModel->newWithdrawPlatformTransaction($amount, $platform_id, $currency_code,$uid);
|
|
||||||
if (!$resWalletPlatformBalanceTransactionModel) throw new ModelException('newWithdrawPlatformTransaction error');
|
|
||||||
|
|
||||||
//根据币种计算费率
|
|
||||||
$oWalletCurrencyModel = new WalletCurrencyModel();
|
|
||||||
$oWalletCurrencyModel = $oWalletCurrencyModel->findByCode($currency_code);
|
|
||||||
if (!$oWalletCurrencyModel) throw new ModelException('currency_code error');
|
|
||||||
$fee_amount = $oWalletCurrencyModel->computeTransferRate($amount, $oWalletCurrencyModel->transfer_rate);
|
|
||||||
//预计费率计算
|
|
||||||
if ($fee_amount <= 0) throw new ModelException('fee_amount error');
|
|
||||||
$desc = isset(self::DESC[$desc_key]) ? self::DESC[$desc_key] : '';
|
|
||||||
$resModel = $this->addWithdrawTransaction($platform_id, $uid, $oWalletCurrencyModel, $amount, $fee_amount, $desc_key, $desc, $remark);
|
|
||||||
if (!$resModel) throw new ModelException('addItem error');
|
|
||||||
$oWalletPlatformBalanceTransactionModel->updateItem([
|
|
||||||
'id' => $resWalletPlatformBalanceTransactionModel->id,
|
|
||||||
'from_user_transaction_id' => $resModel->id,
|
|
||||||
]);
|
|
||||||
$this->putWithdrawToQueue($resModel->id); //投递到队列处理
|
|
||||||
Db::commit();
|
|
||||||
Log::info('newWithdrawSucc', ['platform_id' => $platform_id, 'uid' => $uid, 'currency_code' => $currency_code, 'amount' => $amount]);
|
|
||||||
return $resModel;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollBack();
|
|
||||||
Log::error('newWithdrawErr', ['platform_id' => $platform_id, 'uid' => $uid, 'currency_code' => $currency_code, 'amount' => $amount, 'msg' => $e->getMessage()]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function addWithdrawTransaction($platform_id, $uid, $oWalletCurrencyModel, $amount, $fee_amount, $desc_key = null, $desc = '', $remark = ''): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
|
||||||
$insert = [
|
|
||||||
'type' => self::TYPE_WITHDRAW,
|
|
||||||
'status' => self::STATUS_WAITING_QUEUE,
|
|
||||||
'platform_id' => $platform_id,
|
|
||||||
'uid' => $uid,
|
|
||||||
'currency_id' => $oWalletCurrencyModel->id,
|
|
||||||
'currency_code' => $oWalletCurrencyModel->code,
|
|
||||||
'currency_type' => $oWalletCurrencyModel->type,
|
|
||||||
'received_amount' => abs($amount),
|
|
||||||
// 'entered_amount' => abs($entered_amount),
|
|
||||||
'fee_amount' => abs($fee_amount),
|
|
||||||
'desc_key' => $desc_key ?? '',
|
|
||||||
'desc' => $desc,
|
|
||||||
'remark' => $remark,
|
|
||||||
'created_at' => date('Y-m-d H:i:s'),
|
|
||||||
];
|
|
||||||
return $this->addItem($insert);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addRechargeTransaction($resWalletAddrTransactionModel,$platform_id, $uid, $oWalletCurrencyModel, $amount, $desc_key = null, $desc = '', $remark = ''): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
|
||||||
$amount = abs($amount);
|
|
||||||
$insert = [
|
|
||||||
'type' => self::TYPE_RECHARGE,
|
|
||||||
'status' => self::STATUS_SUCCESS, //充提成功
|
|
||||||
'platform_id' => $platform_id,
|
|
||||||
'uid' => $uid,
|
|
||||||
'currency_id' => $oWalletCurrencyModel->id,
|
|
||||||
'currency_code' => $oWalletCurrencyModel->code,
|
|
||||||
'currency_type' => $oWalletCurrencyModel->type,
|
|
||||||
'from_wallet_addr_id' => $resWalletAddrTransactionModel->wallet_addr_id,
|
|
||||||
'wallet_addr' => $resWalletAddrTransactionModel->wallet_addr,
|
|
||||||
'from_wallet_transaction_id' => $resWalletAddrTransactionModel->id,
|
|
||||||
'received_amount' => $amount,
|
|
||||||
'entered_amount' => $amount,
|
|
||||||
'desc_key' => $desc_key ?? '',
|
|
||||||
'desc' => $desc,
|
|
||||||
'remark' => $remark,
|
|
||||||
'created_at' => date('Y-m-d H:i:s'),
|
|
||||||
];
|
|
||||||
return $this->addItem($insert);
|
|
||||||
}
|
|
||||||
|
|
||||||
function addTransactionWithPlatformBalance($resWalletAddrTransactionModel,$platform_id, $uid, $oWalletCurrencyModel, $amount, $desc_key = null, $desc = '', $remark = '')
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
Db::beginTransaction();
|
|
||||||
$resModel = $this->addRechargeTransaction($resWalletAddrTransactionModel,$platform_id, $uid, $oWalletCurrencyModel, $amount, $desc_key, $desc, $remark);
|
|
||||||
if(!$resModel) throw new ModelException('addRechargeTransaction error');
|
|
||||||
$oWalletPlatformBalanceTransactionModel = new WalletPlatformBalanceTransactionModel();
|
|
||||||
$res = $oWalletPlatformBalanceTransactionModel->newRechargePlatformTransaction($resWalletAddrTransactionModel,$resModel,$amount, $platform_id, $oWalletCurrencyModel->code);
|
|
||||||
if(!$res) throw new ModelException('newRechargePlatformTransaction error');
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
}catch (\Exception $e) {
|
|
||||||
Db::rollBack();
|
|
||||||
Log::error('addTransactionWithBalance', ['platform_id' => $platform_id, 'uid' => $uid, 'amount' => $amount, 'msg' => $e->getMessage()]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//@@投递到rabbitmq队列处理
|
|
||||||
function putWithdrawToQueue($wallet_platform_user_transaction_id): void
|
|
||||||
{
|
|
||||||
$params = [
|
|
||||||
'wallet_platform_user_transaction_id' => $wallet_platform_user_transaction_id,
|
|
||||||
];
|
|
||||||
WalletPlatformUserWithdrawQueue::dispatch($params)->onQueue(QueueWalletPlatformUserWithdrawStruct::QUEUE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
//处理用户提现队列,发起链上提现
|
|
||||||
function withdrawConsumer($id): void
|
|
||||||
{
|
|
||||||
//@新增任务处理表
|
|
||||||
//查询前先检查redis中锁
|
|
||||||
$oWalletPlatformUserTransactionLock = new WalletPlatformUserTransactionLock();
|
|
||||||
$isLock = $oWalletPlatformUserTransactionLock->checkLock($oWalletPlatformUserTransactionLock->getWithdrawKey($id));
|
|
||||||
if ($isLock) return; //有锁就跳过
|
|
||||||
//加锁
|
|
||||||
$isLock = $oWalletPlatformUserTransactionLock->setLock($oWalletPlatformUserTransactionLock->getWithdrawKey($id));
|
|
||||||
if (!$isLock) return; //加锁失败
|
|
||||||
//查询任务
|
|
||||||
$resWalletPlatformUserTransactionModel = $this->findItem($id);
|
|
||||||
if (!$resWalletPlatformUserTransactionModel) throw new ModelException('id error');
|
|
||||||
if ($resWalletPlatformUserTransactionModel->type != self::TYPE_WITHDRAW) throw new ModelException('type error');
|
|
||||||
if ($resWalletPlatformUserTransactionModel->status != self::STATUS_WAITING_QUEUE) throw new ModelException('status error');
|
|
||||||
$resWalletPlatformUserTransactionModel->status = self::STATUS_CODE_PROCESSING;
|
|
||||||
$resWalletPlatformUserTransactionModel->save();
|
|
||||||
|
|
||||||
//获取提现地址
|
|
||||||
$oWalletAddrModel = new WalletAddrModel();
|
|
||||||
try {
|
|
||||||
$resWalletAddrModel = $oWalletAddrModel->findWithdrawAddrWithAmount($resWalletPlatformUserTransactionModel->received_amount, $resWalletPlatformUserTransactionModel->currency_code);
|
|
||||||
if (!$resWalletAddrModel) throw new ModelException('not found withdraw amount wallet addr');
|
|
||||||
} catch (ModelException $e) { //未找到足额提现金额钱包地址
|
|
||||||
$code = $e->getCode();
|
|
||||||
$msg = $e->getMessage();
|
|
||||||
$resWalletPlatformUserTransactionModel->status = self::STATUS_FAIL;
|
|
||||||
if ($code == ModelException::CODE_WALLET_AMOUNT_ADDR_NOT_FOUND) { //未找到足额提现金额钱包地址
|
|
||||||
$resWalletPlatformUserTransactionModel->desc_key = self::DESC_KEY_NOT_FOUND_WITHDRAW_AMOUNT_WALLET_ADDR;
|
|
||||||
$resWalletPlatformUserTransactionModel->desc = self::DESC[self::DESC_KEY_NOT_FOUND_WITHDRAW_AMOUNT_WALLET_ADDR];
|
|
||||||
}
|
|
||||||
if ($code == ModelException::CODE_WALLET_ADDR_BALANCE_LOW) { //提现钱包金额不足
|
|
||||||
$resWalletPlatformUserTransactionModel->desc_key = self::DESC_KEY_WITHDRAW_WALLET_AMOUNT_LOW;
|
|
||||||
$resWalletPlatformUserTransactionModel->desc = self::DESC[self::DESC_KEY_WITHDRAW_WALLET_AMOUNT_LOW];
|
|
||||||
}
|
|
||||||
|
|
||||||
$resWalletPlatformUserTransactionModel->save();
|
|
||||||
$this->withdrawFailUnLock($id); //解锁
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
$resWalletPlatformUserTransactionModel->from_wallet_addr_id = $resWalletAddrModel->id;
|
|
||||||
$resWalletPlatformUserTransactionModel->wallet_addr = $resWalletAddrModel->addr;
|
|
||||||
$resWalletPlatformUserTransactionModel->save();
|
|
||||||
|
|
||||||
//增加钱包账变
|
|
||||||
$oWalletAddrTransactionModel = new WalletAddrTransactionModel();
|
|
||||||
$resWalletAddrTransactionModel = $oWalletAddrTransactionModel->newPlatformUserWithdraw(
|
|
||||||
$resWalletAddrModel->id,
|
|
||||||
$resWalletPlatformUserTransactionModel->entered_amount,
|
|
||||||
$resWalletPlatformUserTransactionModel->id
|
|
||||||
);
|
|
||||||
if (!$resWalletAddrTransactionModel) {
|
|
||||||
$this->withdrawFailUnLock($id); //解锁
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
//调用链上接口
|
|
||||||
$resChain = $oWalletAddrModel->callWalletAddrChainTransferApi($resWalletPlatformUserTransactionModel->id, $resWalletAddrModel->id);
|
|
||||||
if (!$resChain) { //链上提现失败
|
|
||||||
$resWalletPlatformUserTransactionModel->status = self::STATUS_FAIL;
|
|
||||||
$resWalletPlatformUserTransactionModel->desc_key = self::DESC_KEY_WITHDRAW_CALL_CHAIN_WRONG;
|
|
||||||
$resWalletPlatformUserTransactionModel->desc = self::DESC[self::DESC_KEY_WITHDRAW_CALL_CHAIN_WRONG];
|
|
||||||
$resWalletPlatformUserTransactionModel->save();
|
|
||||||
//解冻钱包余额
|
|
||||||
$oWalletAddrTransactionModel->platformUserWithdrawCallback($resWalletAddrTransactionModel->id, $resWalletAddrTransactionModel->received_amount, WalletAddrTransactionModel::STATUS_FAIL);
|
|
||||||
$this->withdrawFailUnLock($id); //解锁
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$resWalletPlatformUserTransactionModel->status = self::STATUS_CHAIN_WAITING;
|
|
||||||
$resWalletPlatformUserTransactionModel->save();
|
|
||||||
$this->withdrawFailUnLock($id); //解锁
|
|
||||||
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Log::error('withdrawConsumer', ['id' => $id, 'msg' => $e->getMessage()]);
|
|
||||||
$this->withdrawFailUnLock($id); //解锁
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//用户提现失败解锁并返还平台余额
|
|
||||||
function withdrawFailUnLock($id): void
|
|
||||||
{
|
|
||||||
//返还用户余额
|
|
||||||
$oWalletPlatformBalanceTransactionModel = new WalletPlatformBalanceTransactionModel();
|
|
||||||
$oWalletPlatformBalanceTransactionModel->withdrawErrByUserTransactionId($id);
|
|
||||||
//解锁
|
|
||||||
$oWalletPlatformUserTransactionLock = new WalletPlatformUserTransactionLock();
|
|
||||||
$oWalletPlatformUserTransactionLock->unLock($oWalletPlatformUserTransactionLock->getWithdrawKey($id));
|
|
||||||
}
|
|
||||||
|
|
||||||
//提现链上回调监听
|
|
||||||
function listenWithdrawCallback($wallet_addr_transaction_id): void
|
|
||||||
{
|
|
||||||
Log::info('listenWithdrawCallback', ['wallet_addr_transaction_id' => $wallet_addr_transaction_id]);
|
|
||||||
//查找钱包账变
|
|
||||||
$oWalletAddrTransactionModel = new WalletAddrTransactionModel();
|
|
||||||
$resWalletAddrTransactionModel = $oWalletAddrTransactionModel->findItem($wallet_addr_transaction_id);
|
|
||||||
if (!$resWalletAddrTransactionModel) throw new ModelException('wallet_addr_transaction_id error');
|
|
||||||
if ($resWalletAddrTransactionModel->type !== WalletAddrTransactionModel::TYPE_TRANSFER) throw new ModelException('wallet_addr_transaction_type error');
|
|
||||||
if (!in_array($resWalletAddrTransactionModel->status, [WalletAddrTransactionModel::STATUS_SUCCESS, WalletAddrTransactionModel::STATUS_FAIL])) throw new ModelException('status error');
|
|
||||||
if ($resWalletAddrTransactionModel->status == WalletAddrTransactionModel::STATUS_SUCCESS) $status = self::STATUS_SUCCESS;
|
|
||||||
if ($resWalletAddrTransactionModel->status == WalletAddrTransactionModel::STATUS_FAIL) $status = self::STATUS_FAIL;
|
|
||||||
if (empty($resWalletAddrTransactionModel->platform_user_transaction_id)) throw new ModelException('platform_user_transaction_id error');
|
|
||||||
$id = $resWalletAddrTransactionModel->platform_user_transaction_id;
|
|
||||||
|
|
||||||
if (!in_array($status, [self::STATUS_SUCCESS, self::STATUS_FAIL])) throw new ModelException('status error');
|
|
||||||
$resWalletPlatformUserTransactionModel = $this->findItem($id);
|
|
||||||
if (!$resWalletPlatformUserTransactionModel) throw new ModelException('id error');
|
|
||||||
if ($resWalletPlatformUserTransactionModel->type != self::TYPE_WITHDRAW) throw new ModelException('type error');
|
|
||||||
if ($resWalletPlatformUserTransactionModel->status != self::STATUS_CHAIN_WAITING) throw new ModelException('status error');
|
|
||||||
//用户账变处理
|
|
||||||
$resWalletPlatformUserTransactionModel->status = $status;
|
|
||||||
$resWalletPlatformUserTransactionModel->save();
|
|
||||||
|
|
||||||
//平台余额和账变处理
|
|
||||||
$oWalletPlatformBalanceTransactionModel = new WalletPlatformBalanceTransactionModel();
|
|
||||||
if ($status == self::STATUS_SUCCESS) { //成功
|
|
||||||
$oWalletPlatformBalanceTransactionModel->withdrawSuccByUserTransactionId($id);
|
|
||||||
} else { //失败
|
|
||||||
$oWalletPlatformBalanceTransactionModel->withdrawErrByUserTransactionId($id);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function listenRechargeCallback($wallet_addr_transaction_id): void
|
|
||||||
{
|
|
||||||
Log::info('listenRechargeCallback', ['wallet_addr_transaction_id' => $wallet_addr_transaction_id]);
|
|
||||||
//查找钱包账变
|
|
||||||
$oWalletAddrTransactionModel = new WalletAddrTransactionModel();
|
|
||||||
$resWalletAddrTransactionModel = $oWalletAddrTransactionModel->findItem($wallet_addr_transaction_id);
|
|
||||||
if (!$resWalletAddrTransactionModel) throw new ModelException('wallet_addr_transaction_id error');
|
|
||||||
if ($resWalletAddrTransactionModel->type !== WalletAddrTransactionModel::TYPE_RECHARGE) throw new ModelException('wallet_addr_transaction_type error');
|
|
||||||
if (!in_array($resWalletAddrTransactionModel->status, [WalletAddrTransactionModel::STATUS_SUCCESS, WalletAddrTransactionModel::STATUS_FAIL])) throw new ModelException('status error');
|
|
||||||
if ($resWalletAddrTransactionModel->status == WalletAddrTransactionModel::STATUS_SUCCESS) $status = self::STATUS_SUCCESS;
|
|
||||||
if ($resWalletAddrTransactionModel->status == WalletAddrTransactionModel::STATUS_FAIL) $status = self::STATUS_FAIL;
|
|
||||||
if ($status != self::STATUS_SUCCESS) throw new ModelException('status not success');
|
|
||||||
|
|
||||||
$oWalletCurrencyModel = new WalletCurrencyModel();
|
|
||||||
$resWalletCurrencyModel = $oWalletCurrencyModel->findItem($resWalletAddrTransactionModel->currency_id);
|
|
||||||
|
|
||||||
//查找用户绑定钱包地址
|
|
||||||
$oWalletPlatformUserWalletAddrModel = new WalletPlatformUserWalletAddrModel();
|
|
||||||
$resWalletPlatformUserWalletAddrModel = $oWalletPlatformUserWalletAddrModel->findByWalletAddrId($resWalletAddrTransactionModel->wallet_addr_id);
|
|
||||||
if (!$resWalletPlatformUserWalletAddrModel) throw new ModelException('找不到wallet_addr_id绑定用户');
|
|
||||||
|
|
||||||
//给用户增加账变/平台增加账变增加余额
|
|
||||||
$this->addTransactionWithPlatformBalance(
|
|
||||||
$resWalletAddrTransactionModel,
|
|
||||||
$resWalletPlatformUserWalletAddrModel->platform_id,
|
|
||||||
$resWalletPlatformUserWalletAddrModel->uid,
|
|
||||||
$resWalletCurrencyModel,
|
|
||||||
$resWalletAddrTransactionModel->received_amount,
|
|
||||||
);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,44 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Models\Wallet\PlatformUser;
|
|
||||||
|
|
||||||
use App\Exceptions\ModelException;
|
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
|
||||||
|
|
||||||
class WalletPlatformUserWalletAddrHistoryModel extends WalletBaseModel
|
|
||||||
{
|
|
||||||
protected $table = 'wallet_platform_user_wallet_addr';
|
|
||||||
protected $primaryKey = 'id';
|
|
||||||
protected $fillable = [
|
|
||||||
'id',
|
|
||||||
'type',
|
|
||||||
'desc',
|
|
||||||
'platform_id',
|
|
||||||
'uid',
|
|
||||||
'username',
|
|
||||||
'nickname',
|
|
||||||
'wallet_addr_id',
|
|
||||||
'wallet_addr',
|
|
||||||
'currency_id',
|
|
||||||
'currency_code',
|
|
||||||
'created_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
const TYPE_BIND = 1;
|
|
||||||
const TYPE_UNBIND = 2;
|
|
||||||
const TYPE = [
|
|
||||||
self::TYPE_BIND => '绑定',
|
|
||||||
self::TYPE_UNBIND => '解绑',
|
|
||||||
];
|
|
||||||
|
|
||||||
function addUserWalletAddrHistory($aItem,$type,$desc = ''): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|array|null
|
|
||||||
{
|
|
||||||
if(!in_array($type,self::TYPE)) throw new ModelException('type error');
|
|
||||||
unset($aItem['id']);//去掉id(主键)
|
|
||||||
$aItem['type'] = $type;
|
|
||||||
$aItem['desc'] = $desc;
|
|
||||||
$sDateTime = date('Y-m-d H:i:s');
|
|
||||||
$aItem['created_at'] = $sDateTime;
|
|
||||||
return $this->addItem($aItem);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,81 +0,0 @@
|
|||||||
<?php
|
|
||||||
namespace App\Models\Wallet\PlatformUser;
|
|
||||||
|
|
||||||
use App\Exceptions\ModelException;
|
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
|
||||||
use App\Models\Wallet\Wallet\WalletAddrModel;
|
|
||||||
use App\Tools\Times;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
|
|
||||||
class WalletPlatformUserWalletAddrModel extends WalletBaseModel
|
|
||||||
{
|
|
||||||
protected $table = 'wallet_platform_user_wallet_addr';
|
|
||||||
protected $primaryKey = 'id';
|
|
||||||
protected $fillable = [
|
|
||||||
'id',
|
|
||||||
'platform_id',
|
|
||||||
'uid',
|
|
||||||
'username',
|
|
||||||
'nickname',
|
|
||||||
'wallet_addr_id',
|
|
||||||
'wallet_addr',
|
|
||||||
'currency_id',
|
|
||||||
'currency_code',
|
|
||||||
'created_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
//根据平台用户生成新充值地址,或者解绑旧有地址
|
|
||||||
function genUserWalletAddr($platform_id, $uid, $currency_code,$mode = WalletPlatformUserWalletAddrHistoryModel::TYPE_BIND): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
|
||||||
//先删除原有地址
|
|
||||||
$resOldModel = $this->findUserWalletAddr($platform_id, $uid, $currency_code);
|
|
||||||
if($mode == WalletPlatformUserWalletAddrHistoryModel::TYPE_BIND && $resOldModel){ //默认检测是否已经绑定过
|
|
||||||
throw new ModelException('已经绑定过地址');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
DB::beginTransaction();
|
|
||||||
//从钱包地址表取值
|
|
||||||
$walletAddrModel = new WalletAddrModel();
|
|
||||||
$oWalletPlatformUserWalletAddrHistoryModel = new WalletPlatformUserWalletAddrHistoryModel();
|
|
||||||
$walletAddrModel = $walletAddrModel->findUnusedAddrPutUsing($currency_code);
|
|
||||||
if(!$walletAddrModel) throw new ModelException('获取新地址失败');
|
|
||||||
if($mode == WalletPlatformUserWalletAddrHistoryModel::TYPE_UNBIND){
|
|
||||||
if($resOldModel){
|
|
||||||
$res = $this->delItem($resOldModel->id);
|
|
||||||
if(!$res) throw new ModelException('删除原有地址失败');
|
|
||||||
$res = $oWalletPlatformUserWalletAddrHistoryModel->addUserWalletAddrHistory($resOldModel->toArray(),WalletPlatformUserWalletAddrHistoryModel::TYPE_UNBIND);
|
|
||||||
if(!$res) throw new ModelException('增加历史绑定地址失败');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$insert = [
|
|
||||||
'platform_id' => $platform_id,
|
|
||||||
'uid' => $uid,
|
|
||||||
'wallet_addr_id' => $walletAddrModel->id,
|
|
||||||
'wallet_addr' => $walletAddrModel->addr,
|
|
||||||
'currency_id' => $walletAddrModel->currency_id,
|
|
||||||
'currency_code' => $walletAddrModel->currency_code,
|
|
||||||
'created_at' => Times::getNowDateTime(),
|
|
||||||
];
|
|
||||||
$resModel = $this->addItem($insert);
|
|
||||||
if($resModel) $oWalletPlatformUserWalletAddrHistoryModel->addUserWalletAddrHistory($resModel->toArray(),WalletPlatformUserWalletAddrHistoryModel::TYPE_BIND);
|
|
||||||
DB::commit();
|
|
||||||
}catch (\Exception $e) {
|
|
||||||
DB::rollBack();
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $resModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
function findUserWalletAddr($platform_id, $uid, $currency_code): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
|
||||||
{
|
|
||||||
return $this->findItemByWhere(['platform_id' => $platform_id, 'uid' => $uid, 'currency_code' => $currency_code]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function findByWalletAddrId($wallet_addr_id): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
|
||||||
{
|
|
||||||
return $this->findItemByWhere(['from_wallet_addr_id' => $wallet_addr_id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
49
app/Models/Wallet/Tron/WalletTronBlockModel.php
Normal file
49
app/Models/Wallet/Tron/WalletTronBlockModel.php
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\Models\Wallet\Tron;
|
||||||
|
|
||||||
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
|
use App\Tools\Math;
|
||||||
|
use App\Tools\Times;
|
||||||
|
|
||||||
|
class WalletTronBlockModel extends WalletBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'wallet_tron_block';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'status',
|
||||||
|
'block_id',
|
||||||
|
'block_num',
|
||||||
|
'block_timestamp',
|
||||||
|
'created_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
const STATUS_WAIT = 1;
|
||||||
|
const STATUS_PROCESS = 2;
|
||||||
|
const STATUS_FINISH = 3;
|
||||||
|
const STATUS_FAIL = 4;
|
||||||
|
const STATUS = [
|
||||||
|
self::STATUS_WAIT => '等待',
|
||||||
|
self::STATUS_PROCESS => '处理中',
|
||||||
|
self::STATUS_FINISH => '完成',
|
||||||
|
self::STATUS_FAIL => '处理失败',
|
||||||
|
];
|
||||||
|
|
||||||
|
function insertByBlockNum($blockNum): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
$data = [
|
||||||
|
'block_num' => $blockNum,
|
||||||
|
'status' => self::STATUS_WAIT,
|
||||||
|
'created_at' => Times::getNowDateTime(),
|
||||||
|
|
||||||
|
];
|
||||||
|
return $this->addItem($data);
|
||||||
|
}
|
||||||
|
|
||||||
|
function getLastBlockNumber()
|
||||||
|
{
|
||||||
|
return $this->newQuery()->orderBy('block_num', 'desc')->value('block_num');
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -1,312 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Wallet\Wallet;
|
|
||||||
|
|
||||||
use App\Exceptions\ModelException;
|
|
||||||
use App\Jobs\WalletAddrTransactionChangeQueue;
|
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
|
||||||
use App\Models\Wallet\Platform\WalletPlatformBalanceTransactionModel;
|
|
||||||
use App\Models\Wallet\Platform\WalletPlatformModel;
|
|
||||||
use App\Models\Wallet\PlatformUser\WalletPlatformUserTransactionModel;
|
|
||||||
use App\Models\Wallet\PlatformUser\WalletPlatformUserWalletAddrModel;
|
|
||||||
use App\Structs\QueueWalletAddrTransactionChangeStruct;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class WalletAddrModel extends WalletBaseModel
|
|
||||||
{
|
|
||||||
protected $table = 'wallet_addr';
|
|
||||||
protected $primaryKey = 'id';
|
|
||||||
protected $fillable = [
|
|
||||||
'id',
|
|
||||||
'role',
|
|
||||||
'type',
|
|
||||||
'use_status',
|
|
||||||
'addr',
|
|
||||||
'secret',
|
|
||||||
'desc_key',
|
|
||||||
'desc',
|
|
||||||
'remark',
|
|
||||||
'currency_id',
|
|
||||||
'currency_code',
|
|
||||||
'total_amount',
|
|
||||||
'frozen_amount',
|
|
||||||
'available_amount',
|
|
||||||
'recharge_num',
|
|
||||||
'recharge_amount',
|
|
||||||
'withdraw_num',
|
|
||||||
'withdraw_amount',
|
|
||||||
'created_at',
|
|
||||||
'updated_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
const ROLE_USER = 1;
|
|
||||||
const ROLE_SYSTEM = 2;
|
|
||||||
const ROLE = [
|
|
||||||
self::ROLE_USER => '用户',
|
|
||||||
self::ROLE_SYSTEM => '系统',
|
|
||||||
];
|
|
||||||
|
|
||||||
const TYPE_CASH = 1;
|
|
||||||
const TYPE_CRYPTO_COIN = 2;
|
|
||||||
const TYPE = [
|
|
||||||
self::TYPE_CASH => '现金',
|
|
||||||
self::TYPE_CRYPTO_COIN => '加密货币',
|
|
||||||
];
|
|
||||||
|
|
||||||
const USE_STATUS_UNUSED = 1;
|
|
||||||
const USE_STATUS_USING = 2;
|
|
||||||
const USE_STATUS_USED = 3;
|
|
||||||
const USE_STATUS = [
|
|
||||||
self::USE_STATUS_UNUSED => '未使用',
|
|
||||||
self::USE_STATUS_USING => '使用中',
|
|
||||||
self::USE_STATUS_USED => '已使用',
|
|
||||||
];
|
|
||||||
|
|
||||||
const DESC_KEY_USER_RECHARGE = 'userRecharge';
|
|
||||||
const DESC_KEY_USER_WITHDRAW = 'userWithdraw';
|
|
||||||
const DESC = [
|
|
||||||
self::DESC_KEY_USER_RECHARGE => '用户充值',
|
|
||||||
self::DESC_KEY_USER_WITHDRAW => '用户提现',
|
|
||||||
];
|
|
||||||
|
|
||||||
function addAddr($addr, $secret, $currency_code = WalletCurrencyModel::CODE_USDT_TRC20, $desc_key = '', $desc = '', $remark = '', $available_amount = 0, $role = self::ROLE_USER, $type = self::TYPE_CRYPTO_COIN, $use_status = self::USE_STATUS_UNUSED): int
|
|
||||||
{
|
|
||||||
$oWalletCurrencyModel = (new WalletCurrencyModel())->findByCode($currency_code, ['id', 'code']);
|
|
||||||
if (!$oWalletCurrencyModel) throw new ModelException('币种不存在');
|
|
||||||
return $this->newQuery()->insertGetId([
|
|
||||||
'role' => $role,
|
|
||||||
'type' => $type,
|
|
||||||
'use_status' => $use_status,
|
|
||||||
'addr' => $addr,
|
|
||||||
'secret' => $secret,
|
|
||||||
'desc_key' => $desc_key,
|
|
||||||
'desc' => $desc,
|
|
||||||
'remark' => $remark,
|
|
||||||
'currency_id' => $oWalletCurrencyModel->id,
|
|
||||||
'currency_code' => $oWalletCurrencyModel->code,
|
|
||||||
'total_amount' => $available_amount,
|
|
||||||
'available_amount' => $available_amount,
|
|
||||||
'created_at' => date('Y-m-d H:i:s'),
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function findAddr($currency_code = WalletCurrencyModel::CODE_USDT_TRC20, $use_status = self::USE_STATUS_UNUSED): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
|
||||||
{
|
|
||||||
return $this->newQuery()->where('currency_code', $currency_code)->where('use_status', $use_status)->first();
|
|
||||||
}
|
|
||||||
|
|
||||||
function findUnusedAddrPutUsing($currency_code = WalletCurrencyModel::CODE_USDT_TRC20): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
|
||||||
{
|
|
||||||
$resModel = $this->newQuery()->where('currency_code', $currency_code)->where('use_status', self::USE_STATUS_UNUSED)->first();
|
|
||||||
if (!$resModel) {
|
|
||||||
//@@获取不到地址就发送到队列生成新地址
|
|
||||||
$this->makeNewWalletAddr($currency_code);
|
|
||||||
throw new ModelException('获取地址失败');
|
|
||||||
}
|
|
||||||
$resModel->use_status = self::USE_STATUS_USING;
|
|
||||||
$resModel->save();
|
|
||||||
return $resModel;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function makeNewWalletAddr($currency_code = WalletCurrencyModel::CODE_USDT_TRC20)
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
function changeUseStatus($id, $use_status): int
|
|
||||||
{
|
|
||||||
return $this->newQuery()->where('id', $id)->update(['use_status' => $use_status]);
|
|
||||||
}
|
|
||||||
|
|
||||||
function incAvailableAmount($id, $amount): int
|
|
||||||
{
|
|
||||||
$amount = abs($amount);
|
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['total_amount', 'available_amount']);
|
|
||||||
if (!$oModel) throw new ModelException('找不到wallet_addr_id');
|
|
||||||
$oModel->frozen_amount = Db::raw('available_amount + ' . $amount);
|
|
||||||
$oModel->total_amount = Db::raw('total_amount + ' . $amount);
|
|
||||||
return $oModel->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
function decAvailableAmount($id, $amount): int
|
|
||||||
{
|
|
||||||
$amount = abs($amount);
|
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['total_amount', 'available_amount']);
|
|
||||||
if (!$oModel) throw new ModelException('找不到wallet_addr_id');
|
|
||||||
$oModel->frozen_amount = Db::raw('available_amount - ' . $amount);
|
|
||||||
$oModel->total_amount = Db::raw('total_amount - ' . $amount);
|
|
||||||
return $oModel->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
function decFrozenAmountById($id, $amount): int
|
|
||||||
{
|
|
||||||
$amount = abs($amount);
|
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['total_amount', 'frozen_amount']);
|
|
||||||
if (!$oModel) throw new ModelException('找不到wallet_addr_id');
|
|
||||||
$oModel->frozen_amount = Db::raw('frozen_amount - ' . $amount);
|
|
||||||
$oModel->total_amount = Db::raw('total_amount - ' . $amount);
|
|
||||||
return $oModel->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
function unFrozenAmountById($id, $amount): int
|
|
||||||
{
|
|
||||||
$amount = abs($amount);
|
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['frozen_amount', 'available_amount']);
|
|
||||||
if (!$oModel) throw new ModelException('找不到wallet_addr_id');
|
|
||||||
$oModel->frozen_amount = Db::raw('frozen_amount - ' . $amount);
|
|
||||||
$oModel->available_amount = Db::raw('available_amount + ' . $amount);
|
|
||||||
return $oModel->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
function frozenAmountById($id, $amount): int
|
|
||||||
{
|
|
||||||
$amount = abs($amount);
|
|
||||||
$oModel = $this->newQuery()->where('id', $id)->first(['frozen_amount', 'available_amount']);
|
|
||||||
if (!$oModel) throw new ModelException('找不到wallet_addr_id');
|
|
||||||
$oModel->frozen_amount = Db::raw('frozen_amount + ' . $amount);
|
|
||||||
$oModel->available_amount = Db::raw('available_amount - ' . $amount);
|
|
||||||
return $oModel->save();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 充值回调监听
|
|
||||||
* @throws ModelException
|
|
||||||
*/
|
|
||||||
function walletAddrTransactionChangeConsumer($wallet_addr_transaction_id,$wallet_addr_transaction_type): void
|
|
||||||
{
|
|
||||||
Log::info('walletAddrTransactionChangeConsumer', ['wallet_addr_transaction_id' => $wallet_addr_transaction_id,]);
|
|
||||||
$oWalletPlatformUserTransactionModel = new WalletPlatformUserTransactionModel();
|
|
||||||
if($wallet_addr_transaction_type == WalletAddrTransactionModel::TYPE_RECHARGE){
|
|
||||||
$oWalletPlatformUserTransactionModel->listenRechargeCallback($wallet_addr_transaction_id);
|
|
||||||
}
|
|
||||||
if($wallet_addr_transaction_type == WalletAddrTransactionModel::TYPE_TRANSFER){
|
|
||||||
$oWalletPlatformUserTransactionModel->listenWithdrawCallback($wallet_addr_transaction_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
//提现链上回调监听
|
|
||||||
function listenWalletAddrCallback($chain_sn, $token, $type, $addr, $amount, $status): void
|
|
||||||
{
|
|
||||||
//@@新增表记录每个地址的监听消息
|
|
||||||
Log::info('listenWalletAddrCallbackParams', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status]);
|
|
||||||
if (!in_array($type, [WalletAddrTransactionModel::TYPE_RECHARGE, WalletAddrTransactionModel::TYPE_TRANSFER])) {
|
|
||||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'error' => 'type类型错误']);
|
|
||||||
throw new ModelException('type类型错误');
|
|
||||||
}
|
|
||||||
//充值不成功默认不处理
|
|
||||||
if($type == WalletAddrTransactionModel::TYPE_RECHARGE && $status != WalletAddrTransactionModel::STATUS_SUCCESS){
|
|
||||||
Log::error('listenWalletAddrCallbackStatus', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'error' => '充值失败']);
|
|
||||||
throw new ModelException('链上充值失败');
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Db::beginTransaction();
|
|
||||||
$oWalletCurrencyModel = (new WalletCurrencyModel())->findByToken($token);
|
|
||||||
if (!$oWalletCurrencyModel) {
|
|
||||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'error' => '币种不存在']);
|
|
||||||
throw new ModelException('币种不存在');
|
|
||||||
}
|
|
||||||
//查找钱包地址
|
|
||||||
$resModel = $this->findItemByWhere([
|
|
||||||
'currency_id' => $oWalletCurrencyModel->id,
|
|
||||||
'addr' => $addr,
|
|
||||||
]);
|
|
||||||
if (!$resModel) {
|
|
||||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'error' => '地址不存在']);
|
|
||||||
throw new ModelException('地址不存在');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type == WalletAddrTransactionModel::TYPE_RECHARGE) { //充值到账
|
|
||||||
$res = $this->incAvailableAmount($resModel->id, $amount);
|
|
||||||
} else { //提现到账
|
|
||||||
//查询账变表提现记录中是否存在
|
|
||||||
$oWalletAddrTransactionModel = new WalletAddrTransactionModel();
|
|
||||||
$resWalletAddrTransactionModel = $oWalletAddrTransactionModel->findItemByWhere([
|
|
||||||
'wallet_addr_id' => $resModel->id,
|
|
||||||
'type' => WalletAddrTransactionModel::TYPE_TRANSFER,
|
|
||||||
'block_sn' => $chain_sn,
|
|
||||||
]);
|
|
||||||
if ($resWalletAddrTransactionModel->status != WalletAddrTransactionModel::STATUS_WAITING_CHAIN_CALLBACK) { //已经处理过
|
|
||||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'wallet_addr_id' => $resModel->id, 'wallet_transaction_id' => $resWalletAddrTransactionModel->id, 'error' => '该提现条目已经处理过']);
|
|
||||||
throw new ModelException('该提现条目已经处理过');
|
|
||||||
}
|
|
||||||
if ($resWalletAddrTransactionModel) { //存在就扣除冻结金额
|
|
||||||
$res = $resWalletAddrTransactionModel->platformUserWithdrawCallback($resModel->id,$amount,$status);
|
|
||||||
} else { //未找到就直接扣除余额
|
|
||||||
$res = $this->decAvailableAmount($resModel->id, $amount);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$res) {
|
|
||||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'wallet_addr_id' => $resModel->id, 'error' => '修改地址余额失败']);
|
|
||||||
throw new ModelException('修改地址余额失败');
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($type == WalletAddrTransactionModel::TYPE_TRANSFER && $resWalletAddrTransactionModel) { //提现已有账变,修改账变状态即可
|
|
||||||
$res = $oWalletAddrTransactionModel->updateItem([
|
|
||||||
'id' => $resWalletAddrTransactionModel->id,
|
|
||||||
'status' => $status,
|
|
||||||
]);
|
|
||||||
if (!$res) {
|
|
||||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'wallet_addr_id' => $resModel->id, 'wallet_transaction_id' => $resWalletAddrTransactionModel->id, 'error' => '修改账变状态失败']);
|
|
||||||
throw new ModelException('修改账变状态失败');
|
|
||||||
}
|
|
||||||
} else { //充值和未记录的转账,增加到钱包账变记录
|
|
||||||
$oWalletAddrTransactionModel = new WalletAddrTransactionModel();
|
|
||||||
$res = $oWalletAddrTransactionModel->addTransaction($resModel->id, $type, WalletAddrTransactionModel::ROLE_SYSTEM, $status, $amount);
|
|
||||||
if (!$res) {
|
|
||||||
Log::error('listenWalletAddrCallbackErr', ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'wallet_addr_id' => $resModel->id, 'error' => '增加到钱包账变记录失败']);
|
|
||||||
throw new ModelException('增加到钱包账变记录失败');
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//成功记录日志
|
|
||||||
$log = ['token' => $token, 'addr' => $addr, 'amount' => $amount, 'status' => $status, 'wallet_addr_id' => $resModel->id, 'info' => '监听钱包处理成功'];
|
|
||||||
if (isset($resWalletAddrTransactionModel) && $resWalletAddrTransactionModel->id) $log['wallet_transaction_id'] = $resWalletAddrTransactionModel->id;
|
|
||||||
Log::info('listenWalletAddrCallbackSucc', $log);
|
|
||||||
|
|
||||||
//投递到钱包账变队列
|
|
||||||
self::putWalletAddrTransactionChangeQueue($resWalletAddrTransactionModel->id, $resWalletAddrTransactionModel->type);
|
|
||||||
|
|
||||||
Db::commit();
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollBack();
|
|
||||||
throw $e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static function putWalletAddrTransactionChangeQueue($wallet_addr_transaction_id, $type): void
|
|
||||||
{
|
|
||||||
WalletAddrTransactionChangeQueue::dispatch([
|
|
||||||
'wallet_addr_transaction_id_id' => $wallet_addr_transaction_id,
|
|
||||||
'wallet_addr_transaction_type' => $type,
|
|
||||||
])->onQueue(QueueWalletAddrTransactionChangeStruct::QUEUE_NAME);
|
|
||||||
}
|
|
||||||
|
|
||||||
function findWithdrawAddrWithAmount($amount, $currency_code = WalletCurrencyModel::CODE_USDT_TRC20): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
|
||||||
{
|
|
||||||
//获取当前系统使用中的热钱包
|
|
||||||
$oModel = $this->findItemByWhere([
|
|
||||||
'currency_code' => $currency_code,
|
|
||||||
'use_status' => self::USE_STATUS_USING,
|
|
||||||
'role' => self::ROLE_SYSTEM,
|
|
||||||
['available_amount', '>=', $amount]
|
|
||||||
]);
|
|
||||||
if (!$oModel) throw new ModelException(ModelException::CODE[ModelException::CODE_WALLET_AMOUNT_ADDR_NOT_FOUND], ModelException::CODE_WALLET_AMOUNT_ADDR_NOT_FOUND);
|
|
||||||
if ($oModel->available_amount < $amount) throw new ModelException(ModelException::CODE[ModelException::CODE_WALLET_ADDR_BALANCE_LOW], ModelException::CODE_WALLET_ADDR_BALANCE_LOW);
|
|
||||||
return $oModel;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//@@调用链上接口,发起转账,要返回链上交易订单号用于追踪并更新到数据库
|
|
||||||
function callWalletAddrChainTransferApi($id, $wallet_addr_id): bool
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,208 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models\Wallet\Wallet;
|
|
||||||
|
|
||||||
use App\Exceptions\ModelException;
|
|
||||||
use App\Models\Wallet\Base\WalletBaseModel;
|
|
||||||
use App\Models\Wallet\Platform\WalletPlatformBalanceModel;
|
|
||||||
use App\Tools\Math;
|
|
||||||
use App\Tools\Times;
|
|
||||||
use Illuminate\Support\Facades\DB;
|
|
||||||
use Illuminate\Support\Facades\Log;
|
|
||||||
|
|
||||||
class WalletAddrTransactionModel extends WalletBaseModel
|
|
||||||
{
|
|
||||||
protected $table = 'wallet_addr_transaction';
|
|
||||||
protected $primaryKey = 'id';
|
|
||||||
protected $fillable = [
|
|
||||||
'id',
|
|
||||||
'block_sn',
|
|
||||||
'type',
|
|
||||||
'role',
|
|
||||||
'wallet_addr_id',
|
|
||||||
'currency_id',
|
|
||||||
'currency_code',
|
|
||||||
'received_amount',
|
|
||||||
'entered_amount',
|
|
||||||
'fee_amount',
|
|
||||||
'before_total_amount',
|
|
||||||
'after_total_amount',
|
|
||||||
'desc_key',
|
|
||||||
'desc',
|
|
||||||
'remark',
|
|
||||||
'platform_user_transaction_id',
|
|
||||||
'sign',
|
|
||||||
'created_at',
|
|
||||||
];
|
|
||||||
|
|
||||||
const TYPE_RECHARGE = 1;
|
|
||||||
const TYPE_TRANSFER = 2;
|
|
||||||
const TYPE_FROZEN = 3;
|
|
||||||
const TYPE_UN_FROZEN = 4;
|
|
||||||
const TYPE = [
|
|
||||||
self::TYPE_RECHARGE => '充值',
|
|
||||||
self::TYPE_TRANSFER => '转账',
|
|
||||||
self::TYPE_FROZEN => '冻结',
|
|
||||||
self::TYPE_UN_FROZEN => '解冻',
|
|
||||||
];
|
|
||||||
|
|
||||||
const ROLE_USER = 1;
|
|
||||||
const ROLE_SYSTEM = 2;
|
|
||||||
const ROLE_ADMIN = 3;
|
|
||||||
const ROLE_OTHER = 4;
|
|
||||||
const ROLE = [
|
|
||||||
self::ROLE_USER => '用户操作',
|
|
||||||
self::ROLE_SYSTEM => '系统操作',
|
|
||||||
self::ROLE_ADMIN => '管理员操作',
|
|
||||||
self::ROLE_OTHER => '其他操作',
|
|
||||||
];
|
|
||||||
|
|
||||||
const STATUS_WAITING_CHAIN_CALLBACK = 1;
|
|
||||||
const STATUS_SUCCESS = 2;
|
|
||||||
const STATUS_FAIL = 3;
|
|
||||||
const STATUS = [
|
|
||||||
self::STATUS_WAITING_CHAIN_CALLBACK => '等待链回调',
|
|
||||||
self::STATUS_SUCCESS => '成功',
|
|
||||||
self::STATUS_FAIL => '失败',
|
|
||||||
];
|
|
||||||
|
|
||||||
const DESC_KEY_WITHDRAW_FROZEN = 'withdrawFrozen';
|
|
||||||
const DESC_KEY_WITHDRAW_UN_FROZEN = 'withdrawUnFrozen';
|
|
||||||
const DESC_KEY_WITHDRAW_DETECT = 'withdrawDetect';
|
|
||||||
const DESC = [
|
|
||||||
self::DESC_KEY_WITHDRAW_FROZEN => '提现冻结',
|
|
||||||
self::DESC_KEY_WITHDRAW_UN_FROZEN => '提现解冻',
|
|
||||||
self::DESC_KEY_WITHDRAW_DETECT => '提现成功扣除',
|
|
||||||
];
|
|
||||||
|
|
||||||
//@@钱包账变处理
|
|
||||||
|
|
||||||
function addTransaction(
|
|
||||||
$wallet_addr_id,
|
|
||||||
$type,
|
|
||||||
$role,
|
|
||||||
$status,
|
|
||||||
$received_amount,
|
|
||||||
$entered_amount = null,
|
|
||||||
$fee_amount = null,
|
|
||||||
$desc_key = '',
|
|
||||||
$remark = '',
|
|
||||||
$platform_user_transaction_id = null,
|
|
||||||
): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
|
||||||
$entered_amount = abs($entered_amount);
|
|
||||||
|
|
||||||
$oWalletAddrModel = new WalletAddrModel();
|
|
||||||
$resWalletAddrModel = $oWalletAddrModel->findItem($wallet_addr_id);
|
|
||||||
|
|
||||||
$received_amount = abs($received_amount);
|
|
||||||
if (empty($fee_amount)) $fee_amount = 0;
|
|
||||||
if (empty($entered_amount)) $entered_amount = Math::bcSub($received_amount, $fee_amount);
|
|
||||||
|
|
||||||
$desc = '';
|
|
||||||
if (!empty($desc_key) && isset(self::DESC[$desc_key])) $desc = self::DESC[$desc_key];
|
|
||||||
|
|
||||||
if ($type == self::TYPE_RECHARGE) { //充值
|
|
||||||
$after_total_amount = Math::bcAdd($oWalletAddrModel->total_amount, $entered_amount);
|
|
||||||
} elseif ($type == self::TYPE_TRANSFER) { //转账
|
|
||||||
$after_total_amount = Math::bcSub($oWalletAddrModel->total_amount, $entered_amount);
|
|
||||||
} elseif (in_array($type, [self::TYPE_FROZEN, self::TYPE_UN_FROZEN])) { //冻结/解冻
|
|
||||||
$after_total_amount = $oWalletAddrModel->total_amount;
|
|
||||||
} else {
|
|
||||||
throw new ModelException('未知类型');
|
|
||||||
}
|
|
||||||
|
|
||||||
$insert = [
|
|
||||||
'type' => $type,
|
|
||||||
'role' => $role,
|
|
||||||
'status' => $status,
|
|
||||||
'currency_id' => $resWalletAddrModel->currency_id,
|
|
||||||
'currency_code' => $resWalletAddrModel->currency_code,
|
|
||||||
'received_amount' => $received_amount,
|
|
||||||
'entered_amount' => $entered_amount,
|
|
||||||
'fee_amount' => $fee_amount,
|
|
||||||
'before_total_amount' => $oWalletAddrModel->total_amount,
|
|
||||||
'after_total_amount' => $after_total_amount,
|
|
||||||
'desc_key' => $desc_key,
|
|
||||||
'desc' => $desc,
|
|
||||||
'remark' => $remark,
|
|
||||||
'platform_user_transaction_id' => $platform_user_transaction_id,
|
|
||||||
];
|
|
||||||
// $insert['sign'] = '';
|
|
||||||
$insert['created_at'] = Times::getNowDateTime();
|
|
||||||
return $this->addItem($insert);
|
|
||||||
}
|
|
||||||
|
|
||||||
//用户发起提现
|
|
||||||
function newPlatformUserWithdraw(
|
|
||||||
$wallet_addr_id,
|
|
||||||
$received_amount,
|
|
||||||
$platform_user_transaction_id,
|
|
||||||
): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
|
||||||
{
|
|
||||||
try {
|
|
||||||
Db::beginTransaction();
|
|
||||||
//查询钱包
|
|
||||||
$oWalletAddrModel = new WalletAddrModel();
|
|
||||||
$resWalletAddrModel = $oWalletAddrModel->findItem($wallet_addr_id);
|
|
||||||
if (!$resWalletAddrModel) return false;
|
|
||||||
|
|
||||||
if (Math::bcComp($resWalletAddrModel->available_amount, $received_amount) == -1) throw new ModelException('余额不足');
|
|
||||||
|
|
||||||
//冻结钱包余额
|
|
||||||
$res = $oWalletAddrModel->frozenAmountById($wallet_addr_id, $received_amount);
|
|
||||||
if (!$res) throw new ModelException('钱包余额冻结失败');
|
|
||||||
|
|
||||||
//增加钱包账变
|
|
||||||
$res = $this->addTransaction(
|
|
||||||
$wallet_addr_id,
|
|
||||||
$type = self::TYPE_TRANSFER,
|
|
||||||
$role = self::ROLE_USER,
|
|
||||||
$status = self::STATUS_WAITING_CHAIN_CALLBACK,
|
|
||||||
$received_amount,
|
|
||||||
$entered_amount = null,
|
|
||||||
$fee_amount = null,
|
|
||||||
$desc_key = '',
|
|
||||||
$remark = '',
|
|
||||||
$platform_user_transaction_id,
|
|
||||||
);
|
|
||||||
if (!$res) throw new ModelException('钱包账变失败');
|
|
||||||
Db::commit();
|
|
||||||
return $res;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollBack();
|
|
||||||
Log::error('newPlatformUserWithdraw', ['wallet_addr_id' => $wallet_addr_id, 'received_amount' => $received_amount, 'platform_user_transaction_id' => $platform_user_transaction_id, 'msg' => $e->getMessage()]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function platformUserWithdrawCallback($wallet_transaction_id, $amount, $status)
|
|
||||||
{
|
|
||||||
if (!in_array($status, [self::STATUS_SUCCESS, self::STATUS_FAIL])) throw new ModelException('提现状态错误');
|
|
||||||
$resModel = $this->findItem($wallet_transaction_id);
|
|
||||||
if (!$resModel) throw new ModelException('钱包账变不存在');
|
|
||||||
$oWalletAddrModel = new WalletAddrModel();
|
|
||||||
try {
|
|
||||||
Db::beginTransaction();
|
|
||||||
if ($status == self::STATUS_SUCCESS) {
|
|
||||||
$res = $oWalletAddrModel->decFrozenAmountById($resModel->wallet_addr_id, $amount);
|
|
||||||
if (!$res) throw new ModelException('扣除冻结失败');
|
|
||||||
} else if ($status == WalletAddrTransactionModel::STATUS_FAIL) { //失败就解冻金额
|
|
||||||
$resModel->status = WalletAddrTransactionModel::STATUS_FAIL;
|
|
||||||
$res = $resModel->save();
|
|
||||||
if (!$res) throw new ModelException('更新状态失败');
|
|
||||||
$res = $oWalletAddrModel->unFrozenAmountById($resModel->id, $resModel->received_amount);
|
|
||||||
if (!$res) throw new ModelException('解冻失败');
|
|
||||||
}
|
|
||||||
Db::commit();
|
|
||||||
return true;
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
Db::rollBack();
|
|
||||||
Log::error('platformUserWithdrawCallback', ['wallet_transaction_id' => $wallet_transaction_id, 'amount' => $amount, 'status' => $status, 'msg' => $e->getMessage()]);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
146
app/Models/Wallet/Wallet/WalletAddressModel.php
Normal file
146
app/Models/Wallet/Wallet/WalletAddressModel.php
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Wallet\Wallet;
|
||||||
|
|
||||||
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class WalletAddressModel extends WalletBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'wallet_address';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'role',
|
||||||
|
'role_tags',
|
||||||
|
'use_status',
|
||||||
|
'currency_code',
|
||||||
|
'balance',
|
||||||
|
'address_hex',
|
||||||
|
'address_base58',
|
||||||
|
'private_key',
|
||||||
|
'remark',
|
||||||
|
'created_at',
|
||||||
|
'updated_at',
|
||||||
|
];
|
||||||
|
|
||||||
|
const USE_STATUS_FREE = 1;
|
||||||
|
const USE_STATUS_USING = 2;
|
||||||
|
const USE_STATUS_USED = 3;
|
||||||
|
const USE_STATUS = [
|
||||||
|
self::USE_STATUS_FREE => '空闲',
|
||||||
|
self::USE_STATUS_USING => '使用中',
|
||||||
|
self::USE_STATUS_USED => '废弃',
|
||||||
|
];
|
||||||
|
|
||||||
|
const ROLE_PLATFORM = 1;
|
||||||
|
const ROLE_SYSTEM = 2;
|
||||||
|
const ROLE = [
|
||||||
|
self::ROLE_PLATFORM => '平台',
|
||||||
|
self::ROLE_SYSTEM => '系统',
|
||||||
|
];
|
||||||
|
|
||||||
|
const ROLE_TAGS_WALLET= 1;
|
||||||
|
const ROLE_TAGS_WITHDRAW = 2;
|
||||||
|
const ROLE_TAGS_COLLECTION = 3;
|
||||||
|
const ROLE_TAGS = [
|
||||||
|
self::ROLE_TAGS_WALLET => '钱包',
|
||||||
|
self::ROLE_TAGS_WITHDRAW => '提现',
|
||||||
|
self::ROLE_TAGS_COLLECTION => '归集',
|
||||||
|
];
|
||||||
|
|
||||||
|
//查找空闲钱包地址
|
||||||
|
function findFreeAddress($currency_code = WalletCurrencyModel::CODE_USDT_TRC20): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
||||||
|
{
|
||||||
|
return $this->newQuery()
|
||||||
|
->where('use_status', self::USE_STATUS_FREE)
|
||||||
|
->where('currency_code', $currency_code)
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function findByAddressHex(string $sAddressHex, $currency_code = WalletCurrencyModel::CODE_USDT_TRC20): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
|
{
|
||||||
|
return $this->findItemByWhere(['address_hex' => $sAddressHex, 'currency_code' => $currency_code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findByAddressBase58(string $sAddressBase58, $currency_code = WalletCurrencyModel::CODE_USDT_TRC20): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
|
{
|
||||||
|
return $this->findItemByWhere(['address_base58' => $sAddressBase58, 'currency_code' => $currency_code]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function findByAddress(string $sAddress, $currency_code = WalletCurrencyModel::CODE_USDT_TRC20): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
|
{
|
||||||
|
return $this->newQuery()->where('currency_code', $currency_code)
|
||||||
|
->where(function ($query) use ($sAddress) {
|
||||||
|
$query->where('address_hex', $sAddress)
|
||||||
|
->orWhere('address_base58', $sAddress);
|
||||||
|
})
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
function findWithdrawWallet($currency_code,$amount): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|null
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
return $this->findItemByWhere([
|
||||||
|
'role' => self::ROLE_PLATFORM,
|
||||||
|
'role_tags' => self::ROLE_TAGS_WITHDRAW,
|
||||||
|
'currency_code' => $currency_code,
|
||||||
|
'balance' => ['>=', $amount],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateRoleTags($id, array $role_tags): bool|int
|
||||||
|
{
|
||||||
|
$tags_values = array_keys(self::ROLE_TAGS);
|
||||||
|
foreach ($role_tags as $val){
|
||||||
|
if (!in_array($val, array_keys($tags_values))) return false;
|
||||||
|
}
|
||||||
|
$role_tags = array_unique($role_tags);
|
||||||
|
asort($role_tags);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'role_tags' => implode(',', $role_tags),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkRoleTags(string $role_tag, array $aRoleTags): bool
|
||||||
|
{
|
||||||
|
asort($aRoleTags);
|
||||||
|
$tmp1 = implode(',', $aRoleTags);
|
||||||
|
return $tmp1 == $role_tag;
|
||||||
|
}
|
||||||
|
|
||||||
|
function decodePrivateKey(string $private_key): string
|
||||||
|
{
|
||||||
|
return $private_key;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
function subBalance($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'balance' => DB::raw('balance - '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
function addBalance($id, $amount): bool|int
|
||||||
|
{
|
||||||
|
$amount = abs($amount);
|
||||||
|
$updateItem = [
|
||||||
|
'id' => $id,
|
||||||
|
'balance' => DB::raw('balance + '. $amount),
|
||||||
|
];
|
||||||
|
return $this->updateItem($updateItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
135
app/Models/Wallet/Wallet/WalletAddressTransactionModel.php
Normal file
135
app/Models/Wallet/Wallet/WalletAddressTransactionModel.php
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models\Wallet\Wallet;
|
||||||
|
|
||||||
|
use App\Bean\Model\Wallet\Wallet\WalletAddressTransactionBean;
|
||||||
|
use App\Exceptions\ModelException;
|
||||||
|
use App\Models\Wallet\Base\WalletBaseModel;
|
||||||
|
use App\Tools\Logs;
|
||||||
|
use App\Tools\Math;
|
||||||
|
use App\Tools\Times;
|
||||||
|
use Illuminate\Support\Facades\DB;
|
||||||
|
|
||||||
|
class WalletAddressTransactionModel extends WalletBaseModel
|
||||||
|
{
|
||||||
|
protected $table = 'wallet_address_transaction';
|
||||||
|
protected $primaryKey = 'id';
|
||||||
|
protected $fillable = [
|
||||||
|
'id',
|
||||||
|
'currency_code',
|
||||||
|
'type',
|
||||||
|
'wallet_address_id',
|
||||||
|
'amount',
|
||||||
|
'block_transaction_id',
|
||||||
|
'block_number',
|
||||||
|
'block_event_name',
|
||||||
|
'block_from_address',
|
||||||
|
'block_to_address',
|
||||||
|
'block_value',
|
||||||
|
'block_timestamp',
|
||||||
|
'created_at',
|
||||||
|
'is_notify',
|
||||||
|
];
|
||||||
|
|
||||||
|
const TYPE_RECHARGE = 1;
|
||||||
|
const TYPE_WITHDRAW = 2;
|
||||||
|
const TYPE = [
|
||||||
|
self::TYPE_RECHARGE => '转入',
|
||||||
|
self::TYPE_WITHDRAW => '转出',
|
||||||
|
];
|
||||||
|
|
||||||
|
const IS_NOTIFY_WAIT = 1;
|
||||||
|
const IS_NOTIFY_PROCESS = 2;
|
||||||
|
const IS_NOTIFY_FINISH = 3;
|
||||||
|
const IS_NOTIFY_FAIL = 4;
|
||||||
|
const IS_NOTIFY = [
|
||||||
|
self::IS_NOTIFY_WAIT => '待处理',
|
||||||
|
self::IS_NOTIFY_PROCESS => '处理中',
|
||||||
|
self::IS_NOTIFY_FINISH => '处理完成',
|
||||||
|
self::IS_NOTIFY_FAIL => '处理失败',
|
||||||
|
];
|
||||||
|
|
||||||
|
function typeRecharge(WalletAddressTransactionBean &$bean): bool
|
||||||
|
{
|
||||||
|
//查重
|
||||||
|
$oRes = $this->findByBlockTransactionId($bean->getBlockTransactionId(), WalletAddressTransactionModel::TYPE_RECHARGE);
|
||||||
|
if ($oRes) throw new ModelException('BlockTransactionId already exists');
|
||||||
|
//根据value计算amount
|
||||||
|
if($bean->getBlockValue() == null) throw new ModelException('getBlockValue is required');
|
||||||
|
$amount = Math::valueToAmount($bean->getBlockValue());
|
||||||
|
$bean->setAmount(abs($amount));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Db::beginTransaction();
|
||||||
|
//增加交易记录
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction error');
|
||||||
|
$bean->setId($res->id);
|
||||||
|
//增加钱包地址余额
|
||||||
|
$oWalletAddressModel = new WalletAddressModel();
|
||||||
|
$resWalletAddressModel = $oWalletAddressModel->findItem($bean->getWalletAddressId());
|
||||||
|
if(!$resWalletAddressModel) throw new ModelException('WalletAddressModel findItem error');
|
||||||
|
$res = $oWalletAddressModel->addBalance($resWalletAddressModel->id, $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('WalletAddressModel addBalance error');
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, $bean->toArrayNotNull());
|
||||||
|
return true;
|
||||||
|
}catch (\Exception $e){
|
||||||
|
Db::rollBack();
|
||||||
|
Logs::ErrLog('typeRecharge error rollBack', $e, $bean->toArrayNotNull());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function typeWithdraw(WalletAddressTransactionBean $bean)
|
||||||
|
{
|
||||||
|
//查重
|
||||||
|
$oRes = $this->findByBlockTransactionId($bean->getBlockTransactionId(), WalletAddressTransactionModel::TYPE_WITHDRAW);
|
||||||
|
if ($oRes) throw new ModelException('BlockTransactionId already exists');
|
||||||
|
//根据value计算amount
|
||||||
|
if($bean->getBlockValue() == null) throw new ModelException('getBlockValue is required');
|
||||||
|
$amount = Math::valueToAmount($bean->getBlockValue());
|
||||||
|
$bean->setAmount(-abs($amount));
|
||||||
|
|
||||||
|
try {
|
||||||
|
Db::beginTransaction();
|
||||||
|
//增加交易记录
|
||||||
|
$res = $this->addTransaction($bean);
|
||||||
|
if (!$res) throw new ModelException('addTransaction error');
|
||||||
|
//扣除钱包地址余额
|
||||||
|
$oWalletAddressModel = new WalletAddressModel();
|
||||||
|
$resWalletAddressModel = $oWalletAddressModel->findItem($bean->getWalletAddressId());
|
||||||
|
if(!$resWalletAddressModel) throw new ModelException('WalletAddressModel findItem error');
|
||||||
|
$res = $oWalletAddressModel->subBalance($resWalletAddressModel->id, $bean->getAmount());
|
||||||
|
if (!$res) throw new ModelException('WalletAddressModel addBalance error');
|
||||||
|
|
||||||
|
Db::commit();
|
||||||
|
Logs::SuccLog(__FUNCTION__, $bean->toArrayNotNull());
|
||||||
|
return true;
|
||||||
|
}catch (\Exception $e){
|
||||||
|
Db::rollBack();
|
||||||
|
Logs::ErrLog('typeRecharge error rollBack', $e, $bean->toArrayNotNull());
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function addTransaction(WalletAddressTransactionBean &$bean): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Builder|bool
|
||||||
|
{
|
||||||
|
if (!$bean->getWalletAddressId()) throw new ModelException('getWalletAddressId is required');
|
||||||
|
if (!$bean->getType()) throw new ModelException('type is required');
|
||||||
|
|
||||||
|
$bean->setCreatedAt(Times::getNowDateTime());
|
||||||
|
return $this->addItem($bean->toArrayNotNull());
|
||||||
|
}
|
||||||
|
|
||||||
|
function findByBlockTransactionId(string $tid,$type): \Illuminate\Database\Eloquent\Model|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Builder|array|null
|
||||||
|
{
|
||||||
|
if(!in_array($type,[self::TYPE_RECHARGE,self::TYPE_WITHDRAW])) throw new ModelException('type error');
|
||||||
|
return $this->findItemByWhere(['block_transaction_id' => $tid,'type' => $type]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user