|
@@ -914,6 +914,81 @@ class Money extends Common
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 钻石兑换余额
|
|
|
+ */
|
|
|
+ public function jewelExchange()
|
|
|
+ {
|
|
|
+ $id = $this->request->param('id',0);
|
|
|
+ $jewel = $this->request->param('jewel',0);
|
|
|
+
|
|
|
+ // 接口防并发
|
|
|
+ if (!$this->apiLimit(1, 1000)) {
|
|
|
+ $this->error(__('Operation frequently'));
|
|
|
+ }
|
|
|
+ $exchange_id = $this->request->request("exchange_id");// 兑换声币配置ID
|
|
|
+ $sound_coin = $this->request->request("sound_coin");// 输入具体声币数量
|
|
|
+ if (!$sound_coin && !$exchange_id) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+
|
|
|
+ if ($sound_coin > 0) {
|
|
|
+ $scoin = $sound_coin;
|
|
|
+ // 获取配置信息
|
|
|
+ $conf = config("site.soundcoinTomoney");
|
|
|
+ $exchangeMoney = round(($sound_coin * ($conf / 100)) / 100, 2);
|
|
|
+ if ($exchangeMoney < 0.01) $this->error(__('声币兑换数量太小啦!'));
|
|
|
+ } else {
|
|
|
+ // 获取兑换配置信息
|
|
|
+ $exchangeModel = new \app\common\model\ExchangeConfig();
|
|
|
+ $exchangeInfo = $exchangeModel->get($exchange_id);
|
|
|
+ if (!$exchangeInfo) $this->error("配置信息未找到");
|
|
|
+ $exchangeMoney = $exchangeInfo["money"] / 100;
|
|
|
+ $scoin = $exchangeInfo["sound_coin"];
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ try {
|
|
|
+ // 查询声币余额
|
|
|
+ $userModel = new \app\common\model\User();
|
|
|
+ $userInfo = $userModel->lock('lock in share mode')->find($this->auth->id);
|
|
|
+ if ($scoin > $userInfo["sound_coin"]) {
|
|
|
+ $this->error("声币余额不足!", [], 100);
|
|
|
+ }
|
|
|
+
|
|
|
+ $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);
|
|
|
+ // 添加兑换记录
|
|
|
+ $res2 = $exchangelogModel->addExchangeLog($this->auth->id, $scoin, $exchangeMoney);
|
|
|
+ // 添加声币流水记录
|
|
|
+ $res3 = $soundlogModel->addUserSoundcoinLog($this->auth->id, $scoin, "-", $userInfo["sound_coin"], $detail, 3, $res2);
|
|
|
+ // 减去用户声币余额
|
|
|
+ $res4 = $userModel->where(["id" => $this->auth->id])->setDec("sound_coin", $scoin);
|
|
|
+ // 增加用户资金余额
|
|
|
+ $res5 = $userModel->where(["id" => $this->auth->id])->setInc("money", $exchangeMoney);
|
|
|
+ if ($res1 && $res2 && $res3 && $res4 && $res5) {
|
|
|
+ Db::commit();
|
|
|
+ $this->success("兑换成功!");
|
|
|
+ } else {
|
|
|
+ $this->error("操作失败!");
|
|
|
+ }
|
|
|
+ } catch (ValidateException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (PDOException $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ } catch (Exception $e) {
|
|
|
+ Db::rollback();
|
|
|
+ $this->error($e->getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
// /**
|
|
|
// * 兑换
|
|
|
// */
|
|
@@ -1065,6 +1140,21 @@ class Money extends Common
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
+ * 获取钻石兑换余额配置信息
|
|
|
+ */
|
|
|
+ public function getExchmoneyConfig()
|
|
|
+ {
|
|
|
+ $list = \app\common\model\ExchmoneyConfig::field("id,jewel,money")->select();
|
|
|
+ if (!$list) $this->error("配置信息为空!");
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ $list[$k]["id"] = (int)$v["id"];
|
|
|
+ $list[$k]["jewel"] = (int)$v["jewel"];
|
|
|
+ $list[$k]["money"] = $v["money"] / 100;
|
|
|
+ }
|
|
|
+ $this->success("获取成功!", $list);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
* 获取声币兑换钻石配置信息
|
|
|
*/
|
|
|
public function getExchsoundConfig()
|