Browse Source

分销余额转到余额

lizhen_gitee 2 months ago
parent
commit
7083457d35

+ 60 - 1
application/api/controller/Intro.php

@@ -301,7 +301,66 @@ class Intro extends Api
 
     }
 
-    //
+    //转余额。减少intromoney ,充值到 money,走一遍notify
+    public function transform(){
+        $freemoney = input('freemoney',0);
+        if(!$freemoney){
+            $this->error('请填写金额');
+        }
+
+        $money = floatval($freemoney);
+
+        $min = 1;
+        if($money < $min){
+            $this->error('转换金额不能小于'.$min);
+        }
+
+        $user_money = model('wallet')->getwallet($this->auth->id,'intromoney');
+        if($money > $user_money){
+            $this->error('转换金额不能大于可提现余额');
+        }
+
+        Db::startTrans();
+
+        //扣除money
+        $rs_wallet = model('Wallet')->lockChangeAccountRemain($this->auth->id,'intromoney',-$money,115,'转为充值余额');
+        if($rs_wallet['status']===false)
+        {
+            Db::rollback();
+            $this->error($rs_wallet['msg']);
+        }
+
+        //创建充值订单
+        $data = [];
+        $data['user_id'] = $this->auth->id;
+        $data['out_trade_no'] = createUniqueNo('TP',$this->auth->id); // 数据库订单号加密
+        $data['order_amount'] = $money;
+        $data['createtime'] = time();
+
+        $data['pay_type'] = 'transform'; //区别正常充值,唯一字段
+        $data['platform'] = '';
+        $data['order_status'] = 0;
+        $data['table_name'] = 'money_recharge';
+        $data['table_id'] = 0;
+        $data['args'] = '';
+
+        $orderid = Db::name('pay_order')->insertGetId($data);
+        if(!$orderid){
+            Db::rollback();
+            $this->error('转入失败');
+        }
+
+        Db::commit();
+
+        //立刻开始回调
+        $notify = controller('Notify')->recharge_notify_do($data['out_trade_no'],15,'佣金转入充值');
+        if(!$notify){
+            $this->error('充值失败,请联系客服');
+        }
+
+        $this->success('操作成功');
+
+    }
 
 
 

+ 2 - 2
application/api/controller/Notify.php

@@ -67,7 +67,7 @@ class Notify extends Api
     }
 
     //充值金币 逻辑
-    private function recharge_notify_do($out_trade_no){
+    public function recharge_notify_do($out_trade_no,$log_type = 10,$remark = '余额充值'){
 
         Db::startTrans();
         $orderInfo = Db::name('pay_order')->where(['out_trade_no' => $out_trade_no])->lock(true)->find();
@@ -85,7 +85,7 @@ class Notify extends Api
 
         //逻辑开始
         //$args = json_decode($orderInfo['args'],true);
-        $result = model('Wallet')->lockChangeAccountRemain($user_id,'money',$orderInfo['order_amount'],10, '余额充值','pay_order',$orderInfo['id']);
+        $result = model('Wallet')->lockChangeAccountRemain($user_id,'money',$orderInfo['order_amount'],$log_type, $remark,'pay_order',$orderInfo['id']);
         if($result['status']===false)
         {
             Db::rollback();

+ 2 - 0
application/extra/wallet.php

@@ -9,6 +9,7 @@ return [
         1 => '系统调节',//money + -
 
         10 => '余额充值',//money +
+        15 => '佣金转入充值', //money +
 
         31 => '商城购物',//money -
 //        32 => '商城退款',//money +
@@ -16,6 +17,7 @@ return [
         101 => '直推返佣',  //intromoney +
         102 => '间推返佣',  //intromoney +
         111 => '团队返佣',  //intromoney +
+        115 => '转为充值余额',  //intromoney -
 
         121 => '钱包余额提现',//intromoney -
         122 => '提现拒绝返回',//intromoney +