|
@@ -58,6 +58,7 @@ class Attire extends Api
|
|
// 判断用户钻石余额是否充足
|
|
// 判断用户钻石余额是否充足
|
|
$userModel = new \app\common\model\User();
|
|
$userModel = new \app\common\model\User();
|
|
$userInfo = $userModel->where(["id"=>$this->auth->id])->find();
|
|
$userInfo = $userModel->where(["id"=>$this->auth->id])->find();
|
|
|
|
+ $userwallet = Db::name('user_wallet')->where('user_id',$this->auth->id)->find();
|
|
if(!$userInfo) {
|
|
if(!$userInfo) {
|
|
$this->error("用户信息获取失败!");
|
|
$this->error("用户信息获取失败!");
|
|
}
|
|
}
|
|
@@ -66,19 +67,26 @@ class Attire extends Api
|
|
if(!$attireInfo) {
|
|
if(!$attireInfo) {
|
|
$this->error("装扮信息获取失败!");
|
|
$this->error("装扮信息获取失败!");
|
|
}
|
|
}
|
|
- if($userInfo["jewel"] < $attireInfo["price"]) {
|
|
|
|
|
|
+ if($userwallet["jewel"] < $attireInfo["price"]) {
|
|
$this->error("您的余额不足,请先充值!");
|
|
$this->error("您的余额不足,请先充值!");
|
|
}
|
|
}
|
|
// 进行购买逻辑
|
|
// 进行购买逻辑
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
try{
|
|
try{
|
|
- $userjewellogModel = new \app\common\model\UserJewelLog();
|
|
|
|
// 扣除用户钻石余额
|
|
// 扣除用户钻石余额
|
|
$where = [];
|
|
$where = [];
|
|
$where["id"] = $this->auth->id;
|
|
$where["id"] = $this->auth->id;
|
|
- $res1 = $userModel->where($where)->setDec("jewel",$attireInfo["price"]);
|
|
|
|
|
|
+ $res1 = true;
|
|
// 添加当前用户钻石流水记录
|
|
// 添加当前用户钻石流水记录
|
|
- $res2 = $userjewellogModel->addUserJewelLog($this->auth->id, $attireInfo["price"], "-", $userInfo["jewel"], "购买装扮扣除" . $attireInfo["price"] . "钻石!", 6);
|
|
|
|
|
|
+ $res2 = true;
|
|
|
|
+
|
|
|
|
+ //增加用户钻石余额
|
|
|
|
+ $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id, $attireInfo["price"], "-", 0, "购买装扮扣除" . $attireInfo["price"] . "钻石!", 6,'jewel');
|
|
|
|
+ if($rs_wallet['status'] == false){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error($rs_wallet['msg']);
|
|
|
|
+ }
|
|
|
|
+
|
|
// 添加装扮购买记录
|
|
// 添加装扮购买记录
|
|
$data = [];
|
|
$data = [];
|
|
$data["user_id"] = $this->auth->id;
|
|
$data["user_id"] = $this->auth->id;
|