|
@@ -38,7 +38,15 @@ class Money extends Common
|
|
|
*/
|
|
|
public function getUserMoney()
|
|
|
{
|
|
|
- $this->success("获取成功!", \app\common\model\User::field("money,rebate_money,score,jewel,sound_coin,hammer")->find($this->auth->id));
|
|
|
+
|
|
|
+ $rs = Db::name('user')->field("rebate_money,score,sound_coin,hammer")->where('id',$this->auth->id)->find();
|
|
|
+
|
|
|
+ //用户钱包
|
|
|
+ $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
|
|
|
+ $rs['money'] = $userwallet['money'];
|
|
|
+ $rs['jewel'] = $userwallet['jewel'];
|
|
|
+
|
|
|
+ $this->success("获取成功!", $rs);
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -394,9 +402,9 @@ class Money extends Common
|
|
|
// 查询资金余额
|
|
|
$userModel = new \app\common\model\User();
|
|
|
$userInfo = $userModel->where('id',$user_id)->lock(true)->find();
|
|
|
- if (bcsub($money, $userInfo["money"], 2) > 0) {
|
|
|
+ /*if (bcsub($money, $userInfo["money"], 2) > 0) {
|
|
|
$this->error("资金余额不足!", [], 100);
|
|
|
- }
|
|
|
+ }*/
|
|
|
|
|
|
// 增加提现收益记录
|
|
|
$withdrawRate = (100 - config("site.withdrawRate")) / 100;
|
|
@@ -457,7 +465,7 @@ class Money extends Common
|
|
|
try {
|
|
|
$withdrawallogModel = new \app\common\model\UserWithdrawalLog();
|
|
|
// 减去用户可用资金余额
|
|
|
- $res1 = $userModel->where(["id" => $user_id])->setDec("money", $money);
|
|
|
+// $res1 = $userModel->where(["id" => $user_id])->setDec("money", $money);
|
|
|
// 增加用户冻结资金余额
|
|
|
$res2 = $userModel->where(["id" => $user_id])->setInc("frozen", $money);
|
|
|
// 新增用户提现记录申请
|
|
@@ -805,6 +813,7 @@ class Money extends Common
|
|
|
*/
|
|
|
public function exchangeSoundcoin()
|
|
|
{
|
|
|
+ exit;
|
|
|
// 接口防并发
|
|
|
if (!$this->apiLimit(1, 1000)) {
|
|
|
$this->error(__('Operation frequently'));
|
|
@@ -846,7 +855,7 @@ class Money extends Common
|
|
|
$exchexsoundlogModel = new \app\common\model\UserExchsoundLog();
|
|
|
$detail = "声币兑换钻石";
|
|
|
// 添加钻石流水记录
|
|
|
- $res1 = $jewellogModel->addUserJewelLog($this->auth->id, $exchangeMoney, "+", $userInfo["jewel"], $detail, 4);
|
|
|
+// $res1 = $jewellogModel->addUserJewelLog($this->auth->id, $exchangeMoney, "+", $userInfo["jewel"], $detail, 4);
|
|
|
|
|
|
// 添加兑换记录
|
|
|
$res2 = $exchexsoundlogModel->addExchsoundLog($this->auth->id, $scoin, $exchangeMoney);
|
|
@@ -856,7 +865,7 @@ class Money extends Common
|
|
|
// 减去用户声币余额
|
|
|
$res4 = $userModel->where(["id" => $this->auth->id])->setDec("sound_coin", $scoin);
|
|
|
// 增加用户钻石余额
|
|
|
- $res5 = $userModel->where(["id" => $this->auth->id])->setInc("jewel", $exchangeMoney);
|
|
|
+// $res5 = $userModel->where(["id" => $this->auth->id])->setInc("jewel", $exchangeMoney);
|
|
|
if ($res1 && $res2 && $res3 && $res4 && $res5) {
|
|
|
Db::commit();
|
|
|
$this->success("兑换成功!");
|
|
@@ -917,12 +926,12 @@ class Money extends Common
|
|
|
$this->error("声币余额不足!", [], 100);
|
|
|
}
|
|
|
|
|
|
- $moneylogModel = new \app\common\model\UserMoneyLog();
|
|
|
+// $moneylogModel = new \app\common\model\UserMoneyLog();
|
|
|
$soundlogModel = new \app\common\model\UserSoundcoinLog();
|
|
|
$exchangelogModel = new \app\common\model\UserExchangeLog();
|
|
|
$detail = "声币兑换余额";
|
|
|
// 添加资金流水记录
|
|
|
- $res1 = $moneylogModel->addRecord($this->auth->id, $exchangeMoney, "+", $userInfo["money"], $detail);
|
|
|
+// $res1 = $moneylogModel->addRecord($this->auth->id, $exchangeMoney, "+", $userInfo["money"], $detail);
|
|
|
// 添加兑换记录
|
|
|
$res2 = $exchangelogModel->addExchangeLog($this->auth->id, $scoin, $exchangeMoney);
|
|
|
// 添加声币流水记录
|
|
@@ -930,7 +939,7 @@ class Money extends Common
|
|
|
// 减去用户声币余额
|
|
|
$res4 = $userModel->where(["id" => $this->auth->id])->setDec("sound_coin", $scoin);
|
|
|
// 增加用户资金余额
|
|
|
- $res5 = $userModel->where(["id" => $this->auth->id])->setInc("money", $exchangeMoney);
|
|
|
+// $res5 = $userModel->where(["id" => $this->auth->id])->setInc("money", $exchangeMoney);
|
|
|
if ($res1 && $res2 && $res3 && $res4 && $res5) {
|
|
|
Db::commit();
|
|
|
$this->success("兑换成功!");
|
|
@@ -984,27 +993,34 @@ class Money extends Common
|
|
|
|
|
|
$userId = $this->auth->id;
|
|
|
// 查询余额
|
|
|
- $userModel = new \app\common\model\User();
|
|
|
- $userInfo = $userModel->lock('lock in share mode')->find($userId);
|
|
|
- if ($exchangeMoney > $userInfo["money"]) {
|
|
|
+ $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
|
|
|
+ if ($exchangeMoney > $userwallet["money"]) {
|
|
|
throw new Exception("余额不足!");
|
|
|
}
|
|
|
|
|
|
- $moneylogModel = new \app\common\model\UserMoneyLog();
|
|
|
- $jewellogModel = new \app\common\model\UserJewelLog();
|
|
|
- $exchangelogModel = new \app\common\model\UserExchangeLog();
|
|
|
- $detail = "余额兑换钻石";
|
|
|
- // 添加资金流水记录
|
|
|
- $res1 = $moneylogModel->addRecord($userId, $exchangeMoney, "-", $userInfo["money"], $detail,114);
|
|
|
+ //
|
|
|
+ $detail = '余额兑换钻石';
|
|
|
+
|
|
|
+ //减去用户余额
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,$exchangeMoney,'-',0,$detail,114,'money');
|
|
|
+ if($rs_wallet['status'] == false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs_wallet['msg']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //增加用户钻石余额
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id, $scoin, '+', 0, $detail, 14,'jewel');
|
|
|
+ if($rs_wallet['status'] == false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs_wallet['msg']);
|
|
|
+ }
|
|
|
+
|
|
|
// 添加兑换记录
|
|
|
+ $exchangelogModel = new \app\common\model\UserExchangeLog();
|
|
|
$res2 = $exchangelogModel->addExchangeLog($userId, $scoin, $exchangeMoney);
|
|
|
- // 添加钻石流水记录
|
|
|
- $res3 = $jewellogModel->addUserJewelLog($userId, $scoin, "+", $userInfo["jewel"], $detail, 14);
|
|
|
- // 减去用户余额
|
|
|
- $res4 = $userModel->where(["id" => $userId])->setDec("money", $exchangeMoney);
|
|
|
- // 增加用户钻石余额
|
|
|
- $res5 = $userModel->where(["id" => $userId])->setInc("jewel", $scoin);
|
|
|
- if ($res1 && $res2 && $res3 && $res4 && $res5) {
|
|
|
+
|
|
|
+
|
|
|
+ if ($res2) {
|
|
|
Db::commit();
|
|
|
$this->success("兑换成功!");
|
|
|
} else {
|
|
@@ -1101,8 +1117,8 @@ class Money extends Common
|
|
|
|
|
|
// 查询资金余额
|
|
|
$userModel = new \app\common\model\User();
|
|
|
- $userInfo = $userModel->get($this->auth->id);
|
|
|
- if ($money > $userInfo["money"]) {
|
|
|
+ $user_wallet = Db::name('user_wallet')->where(['user_id'=>$this->auth->id])->find();
|
|
|
+ if ($money > $user_wallet["money"]) {
|
|
|
$this->error("资金余额不足!", [], 100);
|
|
|
}
|
|
|
|
|
@@ -1110,7 +1126,13 @@ class Money extends Common
|
|
|
try {
|
|
|
$withdrawallogModel = new \app\common\model\UserWithdrawalLog();
|
|
|
// 减去用户可用资金余额
|
|
|
- $res1 = $userModel->where(["id" => $this->auth->id])->setDec("money", $money);
|
|
|
+ $res1 = true;
|
|
|
+ //扣余额
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,$money,'-',0,'申请提现',104,'money');
|
|
|
+ if($rs_wallet['status'] === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs_wallet['msg']);
|
|
|
+ }
|
|
|
// 增加用户冻结资金余额
|
|
|
$res2 = $userModel->where(["id" => $this->auth->id])->setInc("frozen", $money);
|
|
|
// 新增用户提现记录申请
|
|
@@ -1403,13 +1425,14 @@ class Money extends Common
|
|
|
*/
|
|
|
public function withdrawVerify($user_id)
|
|
|
{
|
|
|
+ exit;
|
|
|
if (!$user_id) return false;
|
|
|
// 统计用户所有兑换记录和提现记录 是否与余额匹配
|
|
|
$moneylog = \app\common\model\UserMoneyLog::where(["user_id" => $user_id, "mode" => "+"])->sum('value');
|
|
|
$withdraw = \app\common\model\UserWithdrawalLog::where(["user_id" => $user_id, "status" => ["in", [0, 1]]])->sum("money");
|
|
|
$withdraw = bcdiv($withdraw, 100,2);
|
|
|
$sum = bcsub($moneylog, $withdraw,2);
|
|
|
- $usermoney = \app\common\model\User::where(["id" => $user_id])->value("money");
|
|
|
+// $usermoney = \app\common\model\User::where(["id" => $user_id])->value("money");
|
|
|
if ($usermoney == $sum) {
|
|
|
return true;
|
|
|
} else {
|
|
@@ -1594,21 +1617,29 @@ class Money extends Common
|
|
|
try {
|
|
|
$orderModel = new \app\common\model\RecharOrder();
|
|
|
$userModel = new \app\common\model\User();
|
|
|
- $jewellogModel = new \app\common\model\UserJewelLog();
|
|
|
$rechargelogModel = new \app\common\model\UserRechargeLog();
|
|
|
$orderInfo = $orderModel->where(["order_no" => $out_trade_no])->find();
|
|
|
$userInfo = $userModel->where(["id" => $orderInfo["user_id"]])->find();
|
|
|
+ $userwallet = Db::name('user_wallet')->where('user_id',$orderInfo["user_id"])->find();
|
|
|
// 修改订单状态
|
|
|
$res1 = $orderModel->update(["status" => 1, 'platform' => 2], ["order_no" => $out_trade_no]);
|
|
|
// 修改用户钻石余额
|
|
|
- $res2 = $userModel->where(["id" => $orderInfo["user_id"]])->setInc("jewel", $orderInfo["jewel"]);
|
|
|
+ $res2 = true;
|
|
|
// 添加钻石流水记录
|
|
|
$detail = "充值";
|
|
|
- $res3 = $jewellogModel->addUserJewelLog($userInfo["id"], $orderInfo["jewel"], "+", $userInfo["jewel"], $detail, 1);
|
|
|
+ $res3 = true;
|
|
|
+ //增加用户钻石余额
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($userInfo["id"], $orderInfo["jewel"], "+", 0, $detail, 1,'jewel');
|
|
|
+ if($rs_wallet['status'] == false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($rs_wallet['msg']);
|
|
|
+ }
|
|
|
+
|
|
|
+ //
|
|
|
$rechargeCount = $rechargelogModel->where('user_id',$orderInfo["user_id"])->count();
|
|
|
$isFirstRecharge = $rechargeCount > 0 ? 0 : 1;
|
|
|
// 添加充值记录
|
|
|
- $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userInfo["jewel"], $orderInfo["jewel"], 2), $userInfo["money"], 2, 4, $isFirstRecharge, $userInfo["pre_userid"]);
|
|
|
+ $res4 = $rechargelogModel->addRecord($userInfo["id"], $orderInfo["jewel"], $payamount, bcadd($userwallet["jewel"], $orderInfo["jewel"], 2), $userwallet["money"], 2, 4, $isFirstRecharge, $userInfo["pre_userid"]);
|
|
|
if ($res1 && $res2 && $res3 && $res4) {
|
|
|
// 添加统计
|
|
|
$time = time();
|