lizhen_gitee 1 anno fa
parent
commit
70e8b01396
2 ha cambiato i file con 34 aggiunte e 24 eliminazioni
  1. 1 1
      addons/unishop/behavior/Order.php
  2. 33 23
      application/api/controller/Money.php

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

@@ -171,8 +171,8 @@ class Order
                 throw new Exception(__('Insufficient inventory,%s pieces left', $productInfo['stock']));
             }
             $orderPrice = bcadd($orderPrice, bcmul($productInfo['sales_price'], $numbers[$key], 0), 0);
-//            $ordershouyi= bcadd($ordershouyi, bcmul($productInfo['pifa_shouyi'], $numbers[$key], 2), 2);
 
+            //订单收益
             $shouyi = $productInfo['sales_price']-($productInfo['pifa_price']*$productInfo['pifa_number'])+$productInfo['pifa_shouyi'];
             $ordershouyi= bcadd($ordershouyi, bcmul($shouyi, $numbers[$key], 0), 0);
 

+ 33 - 23
application/api/controller/Money.php

@@ -18,14 +18,14 @@ class Money extends Api
         //部分提现,下单收益+直推返佣
         $map = [
             'user_id'  => $this->auth->id,
-            'log_type' => ['IN',[3,5]],
+            'log_type' => 3,
             'withdraw_id' => 0,
         ];
-        $score = Db::name('user_score_log')->where($map)->sum('change_value');
+        $bufenscore = Db::name('user_score_log')->where($map)->sum('change_value');
 
         $data = [
             'score' => model('wallet')->getWallet($this->auth->id,'score'),
-            'score_bufen' => $score,
+            'score_bufen' => $bufenscore,
             '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(),
@@ -39,11 +39,14 @@ class Money extends Api
     //提现
     public function scorewithdraw() {
         $type = input('type', 0, 'intval'); //类型:1=支付宝,2=微信,3=银行
-        /*$money = input('score', '', 'intval');
+        $from = input('from','all');
 
-        if ($money <= 0) {
-            $this->error('请输入正确兑换积分');
-        }*/
+        if(!in_array($type,[1,2,3])){
+            $this->error('参数错误');
+        }
+        if(!in_array($from,['all','bufen'])){
+            $this->error('参数错误');
+        }
 
         $check = Db::name('user_withdraw')->where('user_id',$this->auth->id)->where('status',0)->find();
         if($check){
@@ -51,28 +54,25 @@ class Money extends Api
         }
 
         //余额查询
-        $user_money = model('wallet')->getWallet($this->auth->id,'score');
-        /*if ($user_money < $money) {
-            $this->error('余额不足');
-        }*/
-        if ($user_money <= 0) {
-            $this->error('积分不足');
+        if($from == 'all'){
+            $user_money = model('wallet')->getWallet($this->auth->id,'score');
+        }else{
+            $map = [
+                'user_id'  => $this->auth->id,
+                'log_type' => 3,
+                'withdraw_id' => 0,
+            ];
+            $user_money = Db::name('user_score_log')->where($map)->sum('change_value');
+            //记录id,等会修改状态
+            $user_score_log_ids = Db::name('user_score_log')->where($map)->column('id');
         }
 
-        //查询最低最高提现金额
-        /*$min_withdrawal_money = config('site.min_withdrawal_money') ? config('site.min_withdrawal_money') : 1;
-        $max_withdrawal_money = config('site.max_withdrawal_money') ? config('site.max_withdrawal_money') : 50000;
-        if ($money < $min_withdrawal_money) {
-            $this->error('最低提现金额' . $min_withdrawal_money . '元');
+        if ($user_money <= 0) {
+            $this->error('积分不足');
         }
-        if ($money > $max_withdrawal_money) {
-            $this->error('最高提现金额' . $max_withdrawal_money . '元');
-        }*/
-
 
         $data['order_no'] = createUniqueNo('T',$this->auth->id);
         $data['user_id']  = $this->auth->id;
-//        $data['score']    = $money;
         $data['score']    = $user_money;
         $data['type']     = $type;
         $data['realname']   = input('realname','');
@@ -91,6 +91,16 @@ class Money extends Api
             $this->error('申请兑换失败');
         }
 
+        //积分日志改状态
+        if($from == 'bufen'){
+            $rs_bufen = Db::name('user_score_log')->where('id','IN',$user_score_log_ids)->update(['withdraw_id'=>$log_id]);
+            if ($rs_bufen === false) {
+                Db::rollback();
+                $this->error('申请兑换失败');
+            }
+        }
+
+        //扣积分
         $rs_wallet = model('wallet')->lockChangeAccountRemain($this->auth->id,'score',-$data['score'],2,'积分兑换','user_withdraw',$log_id);
         if ($rs_wallet['status'] == false) {
             $this->error($rs_wallet['msg']);