Jelajahi Sumber

部分提现

lizhen_gitee 1 tahun lalu
induk
melakukan
767cb97c2f

+ 6 - 1
addons/unishop/behavior/Order.php

@@ -134,6 +134,7 @@ class Order
 
         // 订单价格
         $orderPrice = 0;
+        $orderbenjin= 0;
         $ordershouyi= 0;
 
         // 条件一
@@ -172,8 +173,12 @@ class Order
             }
             $orderPrice = bcadd($orderPrice, bcmul($productInfo['sales_price'], $numbers[$key], 0), 0);
 
+            //订单本金
             //订单收益
+            $benjin = $productInfo['sales_price']-($productInfo['pifa_price']*$productInfo['pifa_number']);
             $shouyi = $productInfo['sales_price']-($productInfo['pifa_price']*$productInfo['pifa_number'])+$productInfo['pifa_shouyi'];
+
+            $orderbenjin= bcadd($orderbenjin, bcmul($benjin, $numbers[$key], 0), 0);
             $ordershouyi= bcadd($ordershouyi, bcmul($shouyi, $numbers[$key], 0), 0);
 
 
@@ -208,7 +213,7 @@ class Order
             $coupon = [];
         }
 
-        $params = [$products, $delivery, $coupon, $baseProductInfo, $address, $orderPrice, $ordershouyi, $specs, $numbers];
+        $params = [$products, $delivery, $coupon, $baseProductInfo, $address, $orderPrice, $orderbenjin, $ordershouyi, $specs, $numbers];
     }
 
     /**

+ 2 - 1
addons/unishop/model/Order.php

@@ -228,7 +228,7 @@ class Order extends Model
         $data['userId'] = $userId;
 
         Hook::listen('create_order_before', $params, $data);
-        list($products, $delivery, $coupon, $baseProductInfos, $address, $orderPrice,$ordershouyi, $specs, $numbers) = $params;
+        list($products, $delivery, $coupon, $baseProductInfos, $address, $orderPrice, $orderbenjin, $ordershouyi, $specs, $numbers) = $params;
 
         // 获取雪花算法分布式id,方便以后扩展
         $snowflake = new Snowflake();
@@ -256,6 +256,7 @@ class Order extends Model
             'status' => self::STATUS_NORMAL,
 
             //追加
+            'order_benjin' => $orderbenjin,
             'order_shouyi' => $ordershouyi,
         ]);
 

+ 11 - 2
application/admin/controller/Userwithdraw.php

@@ -90,8 +90,8 @@ class Userwithdraw extends Backend
             $rs = Db::name('user_withdraw')->where('id',$id)->update($data);
 
 
-            //tag任务赠送金币
-            if($status == 1){
+            //审核通过,且全部提现的
+            if($status == 1 && $info['from'] == 1){
                 //1封号,账户异常,联系客服
                 Db::name('user')->where('id',$info['user_id'])->update(['status'=>0]);
 
@@ -135,6 +135,15 @@ class Userwithdraw extends Backend
                     Db::rollback();
                     $this->error($wallet_rs['msg']);
                 }
+
+                //部分提现:日志的提现id,改为0
+                if($info['from'] == 2){
+                    $rs_bufen = Db::name('user_score_log')->where('withdraw_id',$info['id'])->update(['withdraw_id'=>0]);
+                    if ($rs_bufen === false) {
+                        Db::rollback();
+                        $this->error('申请兑换失败');
+                    }
+                }
             }
             Db::commit();
 

+ 32 - 7
application/api/controller/Money.php

@@ -15,17 +15,25 @@ class Money extends Api
 
     //配置
     public function withdraw_config(){
-        //部分提现,下单收益+直推返佣
-        $map = [
+        //部分提现,直推返佣+下单收益
+        $map1 = [
             'user_id'  => $this->auth->id,
             'log_type' => 3,
             'withdraw_id' => 0,
         ];
-        $bufenscore = Db::name('user_score_log')->where($map)->sum('change_value');
+        $zhitui = Db::name('user_score_log')->where($map1)->sum('change_value');
+
+        $map2 = [
+            'user_id'  => $this->auth->id,
+            'log_type' => 5,
+            'withdraw_id' => 0,
+        ];
+        $shouyi = Db::name('user_score_log')->where($map2)->sum('shouyi');
+
 
         $data = [
             'score' => model('wallet')->getWallet($this->auth->id,'score'),
-            'score_bufen' => $bufenscore,
+            'score_bufen' => bcadd($zhitui,$shouyi),
             'min_withdrawal_money' => config('site.min_withdrawal_money'),
             'max_withdrawal_money' => config('site.max_withdrawal_money'),
             'type_1' => Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('type',1)->where('status',1)->field('realname,banknumber,bankname')->find(),
@@ -57,20 +65,36 @@ class Money extends Api
         if($from == 'all'){
             $user_money = model('wallet')->getWallet($this->auth->id,'score');
         }else{
-            $map = [
+
+            //部分提现,直推返佣+下单收益
+            $map1 = [
                 'user_id'  => $this->auth->id,
                 'log_type' => 3,
                 'withdraw_id' => 0,
             ];
-            $user_money = Db::name('user_score_log')->where($map)->sum('change_value');
+            $zhitui = Db::name('user_score_log')->where($map1)->sum('change_value');
+
+            $map2 = [
+                'user_id'  => $this->auth->id,
+                'log_type' => 5,
+                'withdraw_id' => 0,
+            ];
+            $shouyi = Db::name('user_score_log')->where($map2)->sum('shouyi');
+
+            $user_money = bcadd($zhitui,$shouyi);
+
             //记录id,等会修改状态
-            $user_score_log_ids = Db::name('user_score_log')->where($map)->column('id');
+            $user_score_log_ids_1 = Db::name('user_score_log')->where($map1)->column('id');
+            $user_score_log_ids_2 = Db::name('user_score_log')->where($map2)->column('id');
+
+            $user_score_log_ids = array_merge($user_score_log_ids_1,$user_score_log_ids_2);
         }
 
         if ($user_money <= 0) {
             $this->error('积分不足');
         }
 
+        $data = [];
         $data['order_no'] = createUniqueNo('T',$this->auth->id);
         $data['user_id']  = $this->auth->id;
         $data['score']    = $user_money;
@@ -80,6 +104,7 @@ class Money extends Api
         $data['bankname']   = input('bankname','');
         $data['createtime'] = time();
         $data['status'] = 0;
+        $data['from'] = ($from == 'all') ? 1 : 2; //all=1,bufen=2
 
 
         //开启事务

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

@@ -67,7 +67,7 @@ class Wallet extends Model
      * @return array[log_table]
      * @return array[log_id]
      */
-    public function lockChangeAccountRemain($user_id,$accountType='money',$number,$logtype='',$remark='',$table='',$table_id=0,$table_uid=0)
+    public function lockChangeAccountRemain($user_id,$accountType='money',$number,$logtype='',$remark='',$table='',$table_id=0,$table_uid=0,$shouyi = 0)
     {
         //初始化
         $result = array(
@@ -126,6 +126,7 @@ class Wallet extends Model
             $data['table'] = $table;
             $data['table_id'] = $table_id;
             $data['table_uid'] = $table_uid;
+            $data['shouyi'] = $shouyi;
             $data['remark'] = $remark;
             $data['createtime'] = time();
             $data['updatetime'] = time();

+ 1 - 1
application/extra/wallet.php

@@ -10,7 +10,7 @@ return [
         3  => '直推代理奖励', //支付后立刻获得 score +
         4  => '间推代理奖励', //支付后立刻获得 score +   废弃了
 
-        5  => '下单收益',    //订单10日结算 score +
+        5  => '下单收益',    //订单10日结算 score +  (包含本金+收益)
 
         6  => '总代奖励',    //订单10日结算 score +     废弃了
         7  => '总代奖励(间推)',//订单10日结算 score +    废弃了

+ 3 - 1
application/index/controller/Plantask.php

@@ -114,7 +114,9 @@ class Plantask extends Controller
 
         //买家得到收益
         if($order['order_shouyi'] > 0){
-            $rs_wallet = model('wallet')->lockChangeAccountRemain($order['user_id'],'score',$order['order_shouyi'],5,'下单收益','unishop_order',$order['id'],$order['user_id']);
+            $shouyi = bcsub($order['order_shouyi'],$order['order_benjin']);  //可提现收益
+            $remark = '本金:'.$order['order_benjin'].',收益:'.$shouyi;
+            $rs_wallet = model('wallet')->lockChangeAccountRemain($order['user_id'],'score',$order['order_shouyi'],5,$remark,'unishop_order',$order['id'],$order['user_id'],$shouyi);
             if($rs_wallet['status'] === false){
                 echo $rs_wallet['msg'];
                 Db::rollback();