|
|
@@ -63,6 +63,65 @@ class LedgerWalletModel extends Model
|
|
|
return $this->lock(true)->where('user_id', $userID)->find();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新钱包余额并添加账变记录
|
|
|
+ * @param int $uid 用户ID
|
|
|
+ * @param string $asset 资产类型
|
|
|
+ * @param string $amount 金额 正:表示加 负:表示减
|
|
|
+ * @param int $action 账变类型
|
|
|
+ * @return void
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public function changeWalletAccount(int $uid, string $asset, string $amount, int $action, int $from_id = 0)
|
|
|
+ {
|
|
|
+ $available = $this->getWallet($uid);
|
|
|
+ if (empty($available)) {
|
|
|
+ // 创建钱包
|
|
|
+ (new LedgerWalletModel())->insertGetId([
|
|
|
+ 'user_id' => $uid,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+ // 账变资产模型
|
|
|
+ switch ($asset) {
|
|
|
+ case Asset::POWER:
|
|
|
+ $changeModel = new LedgerPowerChangeModel();
|
|
|
+ break;
|
|
|
+ case Asset::USDT:
|
|
|
+ $changeModel = new LedgerUsdtChangeModel();
|
|
|
+ break;
|
|
|
+ case Asset::TOKEN:
|
|
|
+ $changeModel = new LedgerTokenChangeModel();
|
|
|
+ break;
|
|
|
+ case Asset::DECLARATION:
|
|
|
+ $changeModel = new LedgerDeclarationChangeModel();
|
|
|
+ break;
|
|
|
+ case Asset::SMH:
|
|
|
+ $changeModel = new LedgerSmhChangeModel();
|
|
|
+ break;
|
|
|
+ case Asset::QUBIC:
|
|
|
+ $changeModel = new LedgerQubicChangeModel();
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ throw new Exception('币种错误:' . $asset);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新钱包余额
|
|
|
+ $newAmount = $this->changeWalletOnly($uid, $asset, $amount);
|
|
|
+
|
|
|
+ // 创建账变记录
|
|
|
+ $insertRs = $changeModel->insert([
|
|
|
+ 'user_id' => $uid,
|
|
|
+ 'from_id' => $from_id,
|
|
|
+ 'change_amount' => $amount,
|
|
|
+ 'present_amount' => $newAmount,
|
|
|
+ 'create_time' => time(),
|
|
|
+ 'action' => $action,
|
|
|
+ ]);
|
|
|
+
|
|
|
+ if (empty($insertRs)) {
|
|
|
+ throw new Exception('创建' . $asset . '账变记录失败');
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
|
|
|
/**
|
|
|
@@ -149,9 +208,6 @@ class LedgerWalletModel extends Model
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
-// dump('参数打印');
|
|
|
-// dump($power);
|
|
|
-
|
|
|
// 查询直推奖励比例
|
|
|
$directProfit = (new Config())->getValue('direct_income');
|
|
|
$directProfitFloat = floatval($directProfit);
|
|
|
@@ -159,11 +215,7 @@ class LedgerWalletModel extends Model
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- // 每直推一个增加20%,封顶收益为100%
|
|
|
-// $directProfitFloat = $directProfitFloat * ($parent['direct_num']);
|
|
|
-// if ($directProfitFloat > 1) {
|
|
|
-// $directProfitFloat = 1;
|
|
|
-// }
|
|
|
+
|
|
|
$directPower = $power * $directProfitFloat; // 可获得的直推奖励(算力)
|
|
|
|
|
|
if($directPower > 0){
|