lizhen_gitee 1 年之前
父节点
当前提交
2e8cb48995
共有 2 个文件被更改,包括 146 次插入166 次删除
  1. 123 0
      app/Common/Library/Alltools.php
  2. 23 166
      app/Jobs/RechargeJob.php

+ 123 - 0
app/Common/Library/Alltools.php

@@ -94,6 +94,129 @@ class Alltools {
         return true;
     }
 
+    //充值后奖金
+    public function recharge($user_id,$gold,$table,$payorder_id){
+
+        //充值者本人
+        $userinfo = Db::name('user')->field('id,username,group_id,intro_uid,invite_uid,gender')->where('id',$user_id)->find();
+
+        //个人直推邀请充值
+        if(!empty($userinfo['invite_uid']) && $userinfo['gender'] == 1 && empty($userinfo['intro_uid'])){
+            $recharge_invite_rate = config('site.invite_recharge_rate');
+            $jewel = bcdiv(bcmul($gold,$recharge_invite_rate,1),100,1);
+
+            $result = model('Wallet')->lockChangeAccountRemain($userinfo['invite_uid'],'jewel',$jewel,41, $userinfo['username'].'充值','pay_order',$payorder_id);
+            if($result['status']===false)
+            {
+                Db::rollback();
+                return false;
+            }
+        }
+
+        //没有推荐人,自己等级最高,女性充值不返
+        if(empty($userinfo['intro_uid']) || $userinfo['group_id'] == 3 || $userinfo['gender'] == 0){
+            return true;
+        }
+
+        //充值者上级
+        $intro_userinfo = Db::name('user')->field('id,username,group_id,intro_uid,gender')->where('id',$userinfo['intro_uid'])->find();
+        if(empty($intro_userinfo)){return true;}
+
+        //精确小数点
+        bcscale(2);
+
+        //上级是一级邀请A,本人为B普、B1(二级邀请人),贡献给A
+        if($intro_userinfo['group_id'] == 3){
+
+            $recharge_b2a_rate = config('site.recharge_b2a_rate');//b2a 与 b02a相等
+            $jewelA = bcdiv(bcmul($gold,$recharge_b2a_rate),100);
+
+            $result = model('Wallet')->lockChangeAccountRemain($intro_userinfo['id'],'agentjewel',$jewelA,51, $userinfo['username'].'充值','pay_order',$payorder_id);
+            if($result['status']===false)
+            {
+                Db::rollback();
+                return false;
+            }
+
+            return true;//结束了
+        }
+
+        //上级是二级邀请B1,本人C1,贡献给B和A(表面上说B的钱在A那里,但是有记录,有总额,不能提现即可)
+        if($intro_userinfo['group_id'] == 2 && $intro_userinfo['group_id'] > $userinfo['group_id']){
+
+
+            //充值者上上级,也就是A
+            $intro_intro_userinfo = Db::name('user')->field('id,username,group_id,intro_uid,gender')->where('id',$intro_userinfo['intro_uid'])->find();
+            if(empty($intro_intro_userinfo)){return true;}
+
+            if($intro_intro_userinfo['group_id'] == 3){
+
+                $recharge_c2a_rate = config('site.recharge_c2a_rate');
+                $jewelA = bcdiv(bcmul($gold,$recharge_c2a_rate),100);
+
+                $result = model('Wallet')->lockChangeAccountRemain($intro_intro_userinfo['id'],'agentjewel',$jewelA,51, $userinfo['username'].'充值','pay_order',$payorder_id);
+                if($result['status']===false)
+                {
+                    Db::rollback();
+                    return false;
+                }
+            }
+
+            return true;
+        }
+
+        //上级是普通用户,那自己肯定也是普通,则上级可能是D1、C1,找到上上级,如果也是普通C1,停止。如果上上级是B1,则一直追到A1
+        //上级是普通,自己可能是B1,这种不考虑,因为上级只能用普通网,自己相当于独立于超推网里的新分支,是后台新升级来的
+        if($intro_userinfo['group_id'] == 1 && $userinfo['group_id'] == 1){
+            //先给上级普通用户返
+            $recharge_d2c_rate = config('site.recharge_d2c_rate');//d2c  或   e2d
+            $jewelC = bcdiv(bcmul($gold,$recharge_d2c_rate),100);
+
+            $result = model('Wallet')->lockChangeAccountRemain($intro_userinfo['id'],'agentjewel',$jewelC,51, $userinfo['username'].'充值','pay_order',$payorder_id);
+            if($result['status']===false)
+            {
+                Db::rollback();
+                return false;
+            }
+
+            //充值者上上级
+            $intro_intro_userinfo = Db::name('user')->field('id,username,group_id,intro_uid,gender')->where('id',$intro_userinfo['intro_uid'])->find();
+            if(empty($intro_intro_userinfo)){return true;}
+
+            //上上级也是普通C1,说明自己在E1,上级是D1,停止
+            if($intro_intro_userinfo['group_id'] == 1){
+                return true;
+            }
+
+            //上上级是B1,上级是C1,自己是D1,
+            if($intro_intro_userinfo['group_id'] == 2){
+
+
+                //充值者上上级,也就是A
+                $intro_intro_intro_userinfo = Db::name('user')->field('id,username,group_id,intro_uid,gender')->where('id',$intro_intro_userinfo['intro_uid'])->find();
+                if(empty($intro_intro_intro_userinfo)){return true;}
+
+                if($intro_intro_intro_userinfo['group_id'] == 3){
+
+                    $recharge_c2a_rate = config('site.recharge_c2a_rate');
+                    $jewelA = bcdiv(bcmul($jewelC,$recharge_c2a_rate),100);
+
+                    $result = model('Wallet')->lockChangeAccountRemain($intro_intro_intro_userinfo['id'],'agentjewel',$jewelA,51, $userinfo['username'].'充值','pay_order',$payorder_id);
+                    if($result['status']===false)
+                    {
+                        Db::rollback();
+                        return false;
+                    }
+                }
+
+            }
+
+            return true;
+        }
+
+        return true;
+    }
+
     /**
      *
      * @param floatval $number 金额(正数进账,负数出账)

+ 23 - 166
app/Jobs/RechargeJob.php

@@ -12,6 +12,7 @@ use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Redis;
 use Illuminate\Support\Facades\Config;
 use Illuminate\Support\Facades\Log;
+use App\Common\Library\Alltools;
 
 class RechargeJob implements ShouldQueue
 {
@@ -42,7 +43,7 @@ class RechargeJob implements ShouldQueue
         $result = $this->goaaa();
 
 
-        if($result === false){
+        /*if($result === false){
             //防止失败
             $key = 'kgelavarel_giftjob_'.$this->msgid;
 
@@ -54,10 +55,30 @@ class RechargeJob implements ShouldQueue
             }else{
                 //echo 345;
             }
+        }*/
+    }
+
+    //主要调用
+    public function goaaa(){
+
+        //
+        $data = DB::table('mt_pay_order')->where('id',$this->msgid)->first();
+        if(empty($data)){return true;}
+
+        DB::beginTransaction();
+
+        $Alltools = new Alltools;
+        $result = $Alltools->shouyi($data->to_user_id,$data->money,'user_match_video_log',$this->msgid);
+        if($result !== true){
+            DB::rollBack();
+            return false;
         }
+
+        DB::commit();
+        return true;
     }
 
-    public function apiLimit($apiLimit = 1, $apiLimitTime = 1000, $key = '')
+    private function apiLimit($apiLimit = 1, $apiLimitTime = 1000, $key = '')
     {
         $app_name    = Config::get('app.name');// laravel name
         $key         = "{$app_name}:{$key}";
@@ -78,169 +99,5 @@ class RechargeJob implements ShouldQueue
         return true;
     }
 
-    public function goaaa(){
-        
-        //
-        $data = DB::table('hx_gift_user_party')->where('id',$this->msgid)->first();
-
-        DB::beginTransaction();
-
-        //用户信息
-        $authuser_info = DB::table('hx_user')->where('id',$data->user_id)->value('nickname');
-        $partyInfo     = DB::table('hx_party')->where('id',$data->party_id)->first();
-
-
-        $jewel_to_money = 1;
-        $user_id = $data->user_to_id;
-        // 添加获赠用户余额
-        if($data->getvalue > 0){
-            $getMoney = bcdiv($data->getvalue,$jewel_to_money,2);
-            if($getMoney > 0){
-                $rs_wallet = $this->lockChangeAccountRemain($user_id,$getMoney,'+',0,"{$authuser_info}送你{$data->gift_name}x{$data->number}",101,'money');
-                if($rs_wallet['status'] == false){
-                    Db::rollback();
-                    return false;
-                }
-            }
-        }
-
-        // 增加房主抽成
-        if ($partyInfo) {
-            $guilderMoney = $data->guildermoney;
-            if($guilderMoney > 0){
-                $touserInfo    = DB::table('hx_user')->where('id',$user_id)->value('nickname');
-                $rs_wallet = $this->lockChangeAccountRemain($partyInfo->user_id,$guilderMoney,'+',0,"{$authuser_info}送礼物{$data->gift_name}x{$data->number}给{$touserInfo},房间礼物抽成",102,'money');
-                if($rs_wallet['status'] == false){
-                    Db::rollback();
-                    return false;
-                }
-            }
-        }
-
-        Db::commit();
-        return true;
-    }
-
-
-    /**
-     *
-     * @param floatval $number 金额(正数进账,负数出账)
-     * @param $accountType 货币类型,money,score
-     * @param $logtype 日志的类型
-     * @param $remark  备注
-     * @param $user_id  用户id
-     * @param $table  来源表
-     * @param $data_id  表id
-     * @param $isAdmin 是否是管理员处理
-     * @return array
-     * @return array[status]
-     * @return array[msg]
-     * @return array[log_table]
-     * @return array[log_id]
-     */
-    public function lockChangeAccountRemain($user_id,$money,$mode,$before = 0,$remark='',$logtype,$accountType='money',$extend = [])
-    {
-        //初始化
-        $result = array(
-            'status'=>false,
-            'code' => 0, //报错时候采用
-            'msg'=>'',
-            'log_table' => '',
-            'log_id' => '',
-        );
-
-        //获取小数点
-        $point = $accountType == 'money' ? 2 : 0;
-        bcscale($point);
-
-        //钱包名称
-        $wallet_name = '余额';
-
-        //数字纠正
-        $money = abs($money);
-        if($mode == '-'){
-            $number = -$money;
-        }else{
-            $number = $money;
-        }
-
-        //检测
-        $number = floatval( $number );
-        if( $number == 0 )
-        {
-            $result['msg'] = '交易金额:0';
-            return $result;
-        }
-        if(0 === bccomp($number, 0)){
-            $result['msg'] = '交易金额:0';
-            return $result;
-        }
-
-
-        //检测
-        $wallet = DB::table('hx_user_wallet')->where('user_id',$user_id)->lockForUpdate()->first();
-        if(empty($wallet))
-        {
-            $result['msg'] = '不存在的用户';
-            return $result;
-        }
-
-        if(bccomp(bcadd($wallet->$accountType, $number), 0) === -1)
-        {
-            $result['code'] = 10;
-            $result['msg'] = $wallet_name.'余额不足!';
-            return $result;
-        }
-
-        if(0 !== bccomp($number, 0))
-        {
-
-            //钱币记录
-            $data = array();
-            $data['user_id'] = $user_id;
-            $data['value'] = $money;
-            $data['mode'] = $mode;
-            $data['before'] = $wallet->$accountType;
-            $data['balance'] = bcadd($wallet->$accountType, $number);
-            $data['detail'] = $remark;
-            $data['createtime'] = time();
-            $data['type'] = $logtype;
-            if ($accountType == 'jewel') {
-                $data['cityname'] = isset($extend['cityname']) ? $extend['cityname'] : '';
-            }
-            //新的方式
-            $rs1 = DB::table('hx_user_wallet')->where('user_id',$user_id)->update([$accountType => $data['balance']]);
-
-            /////////////
-            $log_table = 'hx_user_'.$accountType.'_log';
-
-            $rs2_id = DB::table($log_table)->insertGetId($data);
-
-            if($rs1 === false || $rs2_id === false){
-                $result['msg'] = '更新财务记录失败!';
-                return $result;
-            }
-
-
-            if( $rs1 !== false && $rs2_id !== false )
-            {
-                $result['status'] = true;
-                $result['msg'] = '账户余额已更新!';
-                $result['log_table'] = $accountType.'_log';
-                $result['log_id'] = $rs2_id;
-
-                return $result;
-            }
-            else
-            {
-                $result['msg'] = '更新财务记录失败!';
-                return $result;
-            }
-        } else {
-            $result['msg'] = '金额不足0.01';
-            return $result;
-        }
-
-    }
 
 }