quguofeng vor 2 Jahren
Ursprung
Commit
e23867ca02

+ 57 - 1
app/common/repositories/store/StorePercentageRepository.php

@@ -15,6 +15,7 @@ namespace app\common\repositories\store;
 
 use app\common\dao\store\StorePercentageDao as dao;
 use app\common\repositories\BaseRepository;
+use app\common\repositories\store\order\StoreOrderRepository;
 
 /**
  * @mixin dao
@@ -22,9 +23,64 @@ use app\common\repositories\BaseRepository;
 class StorePercentageRepository extends BaseRepository
 {
 
+    public $one_register_percentage;
+    public $two_register_percentage;
+    public $one_attention_percentage;
+    public $two_attention_percentage;
+    public $one_order_percentage;
+    public $two_order_percentage;
     public function __construct(dao $dao)
     {
         $this->dao = $dao;
+        $this->one_register_percentage = 5;
+        $this->two_register_percentage = 3;
+        $this->one_attention_percentage = 8;
+        $this->two_attention_percentage = 6;
+        $this->one_order_percentage = 8;
+        $this->two_order_percentage = 6;
+    }
+    //抵扣返利比
+    public function deduction_percentage($deduction_type,$passivity_user_id,$order_id,StoreOrderRepository $order_epository){
+        switch ($deduction_type){
+            case 1:
+                $deduction_num = $this->one_register_percentage;
+                break;
+            case  2:
+                $deduction_num = $this->two_register_percentage;
+                break;
+            case 3:
+                $deduction_num = $this->one_attention_percentage;
+                break;
+            case  4:
+                $deduction_num = $this->two_attention_percentage;
+                break;
+            case 5:
+                $deduction_num = $this->one_order_percentage;
+                break;
+            case  6:
+                $deduction_num = $this->two_order_percentage;
+                break;
+        }
+        if($deduction_num <= 0){
+            return false;
+        }
+        $order_info = $order_epository->findOrCreate(array('order_id'=>$order_id));
+        $order_status = $order_info->status;
+        if(!in_array($order_status,[0,1,4])){
+            return false;
+        }
+        $residue_percentage = $order_info->residue_percentage - $deduction_num;
+        if($residue_percentage <= 0 && $order_status == 4){
+            $order_status = 0;
+        }
+        $order_epository->update($order_id,array('residue_percentage'=>$residue_percentage,'status'=>$order_status));
+        $percentage_data = array(
+            'user_id' => $order_info->uid,
+            'deduction_num' => $deduction_num,
+            'deduction_type' => $deduction_type,
+            'passivity_user_id' => $passivity_user_id,
+            'order_id' => $order_id
+        );
+        $this->create($percentage_data);
     }
-
 }

+ 5 - 35
app/controller/api/Auth.php

@@ -424,46 +424,16 @@ class Auth extends BaseController
             $order_info = $order_epository->findOrCreate(array('order_id'=>$data['order_id']));
             if($order_info->uid){
                 $pid = $order_info->uid;
-                if($order_info->residue_percentage > 0){
-                    $order_id = $data['order_id'];
-                }
+                $order_id = $data['order_id'];
             }
         }
         $user = $repository->registr($data['phone'], $data['pwd'], $data['user_type'],$pid,$order_id);
         if($user->order_id){
             //一级注册折扣百分比
-            $one_register_percentage = 5;
-            $two_register_percentage = 3;
-            //扣减订单剩余支付百分比
-            if($one_register_percentage > 0 && in_array($order_info->status,[0,1,4])){
-                //一级注册折扣比
-                $order_epository->update($user->order_id,array('residue_percentage'=>$order_info->residue_percentage - $one_register_percentage));
-                $store_percentage = app()->make(StorePercentageRepository::class);
-                $percentage_data = array(
-                    'user_id' => $order_info->uid,
-                    'deduction_num' => $one_register_percentage,
-                    'deduction_type' => 1,
-                    'passivity_user_id' => $user->uid,
-                    'order_id' => $order_info->order_id
-                );
-                $store_percentage->create($percentage_data);
-            }
-            if($two_register_percentage > 0 && in_array($order_info->status,[0,1,4])){
-                $p_user = $repository->get($pid);
-                if($p_user->order_id){
-                    $p_order_info = $order_epository->findOrCreate(array('order_id'=>$p_user->order_id));
-                    //二级注册折扣比
-                    $order_epository->update($p_user->order_id,array('residue_percentage'=>$p_order_info->residue_percentage - $two_register_percentage));
-                    $store_percentage = app()->make(StorePercentageRepository::class);
-                    $percentage_data = array(
-                        'user_id' => $p_order_info->uid,
-                        'deduction_num' => $two_register_percentage,
-                        'deduction_type' => 2,
-                        'passivity_user_id' => $user->uid,
-                        'order_id' => $p_order_info->order_id
-                    );
-                    $store_percentage->create($percentage_data);
-                }
+            $store_percentage->deduction_percentage(1,$user->uid,$user->order_id);
+            $p_user = $repository->get($pid);
+            if($p_user->order_id){
+                $store_percentage->deduction_percentage(2,$user->uid,$p_user->order_id);
             }
         }
         if ($auth){