Browse Source

收益兑换金币

lizhen_gitee 1 year ago
parent
commit
766d485c9f

+ 63 - 0
application/api/controller/Pay.php

@@ -174,4 +174,67 @@ class Pay extends Api
     }
 
 
+    //收益兑换金币 配置
+    public function moneytogold_config(){
+        $list = Db::name('moneytogold_config')->order('weigh asc,id asc')->select();
+        $data['goldconfig'] = $list;
+
+        $wallet = model('wallet')->getWallet($this->auth->id);
+        $data['wallet'] = $wallet;
+        $data['money_to_gold'] = config('site.money_to_gold');
+        $this->success('success',$data);
+    }
+
+    //收益兑换金币  兑换
+    public function moneytogold_exchange(){
+        $rc_id     = input_post('rc_id',0);
+        $freemoney = input_post('freemoney',0);
+
+        if(!$rc_id && !$freemoney){
+            $this->error('请选择或填写兑换金额');
+        }
+
+        $uid = $this->auth->id;
+        //赋值money
+        if($rc_id){
+            $recharge_config = Db::name('moneytogold_config')->where('id',$rc_id)->find();
+            $money = $recharge_config['money'] ?: 0;
+            $gold  = $recharge_config['gold'] ?: 0;
+        }
+
+        //自由输入覆盖
+        if(!empty($freemoney)){
+            $rc_id = 0;
+            $money = floatval($freemoney);
+            $bili = config('site.money_to_gold') ?: 10;
+            $gold  = bcmul($money,$bili,0);
+        }
+
+        //
+        if($money<=0)
+        {
+            $this->error('兑换金额必须大于0');
+        }
+
+        //扣除money
+        $rs_wallet = model('Wallet')->lockChangeAccountRemain($uid,'money',-$money,21, '收益兑换金币');
+        if($rs_wallet['status']===false)
+        {
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        //增加gold
+        $rs_wallet = model('Wallet')->lockChangeAccountRemain($uid,'gold',$gold,22, '收益兑换金币',$rs_wallet['log_table'],$rs_wallet['log_id']);
+        if($rs_wallet['status']===false)
+        {
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        Db::commit();
+        $this->success();
+    }
+
+
 }

+ 0 - 11
application/api/controller/Userwallet.php

@@ -22,17 +22,6 @@ class Userwallet extends Api
 
 
 
-    //充值记录
-    public function gold_recharge_log(){
-        $map = [
-            'user_id' => $this->auth->id,
-            'log_type'=> 10,
-        ];
-        $list = Db::name('user_gold_log')->field('id,change_value,remain,createtime')->where($map)->order('id desc')->autopage()->select();
-
-        $this->success('success',$list);
-    }
-
     //我的余额日志
     public function my_money_log(){
         $type = input_post('type',0);

+ 1 - 1
application/common/model/Wallet.php

@@ -148,7 +148,7 @@ class Wallet extends Model
                 {
                     $result['status'] = true;
                     $result['msg'] = '账户余额已更新!';
-                    $result['log_table'] = $accountType.'_log';
+                    $result['log_table'] = $log_table;
                     $result['log_id'] = $rs2_id;
 
                     return $result;

+ 2 - 0
application/extra/wallet.php

@@ -11,6 +11,8 @@ return [
         14 => '金币首充赠送',
         15 => '提现',      //money
 
+        21 => '收益兑换金币',//money -
+        22 => '收益兑换金币',//gold +
 
         31 => '购买装扮消费',
         41 => '签到赠送金币',