|
|
@@ -919,7 +919,9 @@ class StoreOrder extends BaseModel
|
|
|
@file_put_contents('quanju.txt', $spread_uid . "-上级uid\r\n", 8);
|
|
|
|
|
|
if ($spread_uid > 0) {
|
|
|
- self::processRebate($order, $spread_uid, 0, 0);
|
|
|
+ $level_id = User::where('uid',$order['uid'])->value('level');
|
|
|
+ $level_grade = SystemUserLevel::where('uid', $level_id)->value('grade');
|
|
|
+ self::processRebate($order, $spread_uid, $level_grade,$order['total_price']);
|
|
|
}
|
|
|
if ($order['is_wholesale'] == 1) { //批发订单
|
|
|
self::wholesale($order); //批发订单返利
|
|
|
@@ -929,10 +931,6 @@ class StoreOrder extends BaseModel
|
|
|
return false !== $res;
|
|
|
}
|
|
|
|
|
|
- public static function userLevelRewards($order, $uid)
|
|
|
- {
|
|
|
-
|
|
|
- }
|
|
|
/**
|
|
|
* 无限级分销返利方法
|
|
|
* @param array $order 订单信息
|
|
|
@@ -978,47 +976,8 @@ class StoreOrder extends BaseModel
|
|
|
if (!empty($level_info)) {
|
|
|
$level_info = $level_info->toArray();
|
|
|
}
|
|
|
-// if ($parentLevel > 0) {
|
|
|
-// $parent_level_info= SystemUserLevel::where('grade')->where('is_del',0)->find();
|
|
|
-// if (!empty($parent_level_info)){
|
|
|
-// $parent_level_info = $parent_level_info->toArray();
|
|
|
-// if ()
|
|
|
-// }
|
|
|
- $spread_uid = User::where('uid', $order['uid'])->value('spread_uid');
|
|
|
- if ($spread_uid == $uid) { //如果订单用户上级uid和传参的uid相同说明是第一层
|
|
|
- @file_put_contents('quanju.txt', "-如果订单用户上级uid和传参的uid相同说明是第一层\r\n", 8);
|
|
|
-
|
|
|
- $shopping_cart = $order['cart_id'];
|
|
|
-// 先不考虑什么商品返现比例了
|
|
|
- foreach ($shopping_cart as $cart) {
|
|
|
-// @file_put_contents('quanju4.txt', $cart . "-购物车id2\r\n", 8);
|
|
|
- $product_radio = 0;
|
|
|
- $product_info = StoreCart::where('id', $cart)->find()->toArray();
|
|
|
- @file_put_contents('quanju.txt', json_encode($product_info) . "-购物车信息\r\n", 8);
|
|
|
-
|
|
|
- $product = StoreProductLevel::where('product_id', $product_info['product_id'])->where('level_id', $user['level'])->where('type', 1)->find(); //商品返现比例
|
|
|
- @file_put_contents('quanju.txt', StoreProductLevel::getlastsql() . "-返利比例sql\r\n", 8);
|
|
|
- @file_put_contents('quanju.txt', json_encode($product) . "-返利比例\r\n", 8);
|
|
|
-
|
|
|
- if (!empty($product)) {
|
|
|
- $product = $product->toArray();
|
|
|
- $product_radio = $product['rebate_ratio'];
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- if ($product_radio > 0) {
|
|
|
-// if ($user_radio>0){
|
|
|
- $product_price = StoreProduct::where('id', $product_info['product_id'])->value('price');
|
|
|
- $product_price = bcmul($product_price,$product_info['cart_num'],2);
|
|
|
- $rebate = bcmul($product_price, bcdiv($product_radio, 100, 2), 2); //商品返现金额
|
|
|
- $brokerage = bcadd($brokerage, $rebate, 2);
|
|
|
-// }
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- } else {
|
|
|
-// @file_put_contents('quanju.txt', json_encode($level_info) . "-等级信息\r\n", 8);
|
|
|
|
|
|
+// 从第一层就开始比较
|
|
|
if ($parentLevel > $level_info['grade']) { //如果上上级等级小于上级,就直接跳过
|
|
|
@file_put_contents('quanju.txt', "-如果上上级等级小于上级,就直接跳过\r\n", 8);
|
|
|
|
|
|
@@ -1035,7 +994,8 @@ class StoreOrder extends BaseModel
|
|
|
}
|
|
|
} elseif ($parentLevel < $level_info['grade']) { //如果上上级等级大于上级,就获取自己等级返利的佣金
|
|
|
@file_put_contents('quanju.txt', "-如果上上级等级大于上级,就获取自己等级返利的佣金\r\n", 8);
|
|
|
-
|
|
|
+ @file_put_contents('quanju.txt', "-如果上级高太多级,就把中间等级的奖励也都发了\r\n", 8);
|
|
|
+ $bc = bcsub($level_info['grade'],$parentLevel,2);
|
|
|
// StoreProductLevel::where('product_id',$)
|
|
|
$shopping_cart = $order['cart_id'];
|
|
|
// 先不考虑什么商品返现比例了
|
|
|
@@ -1043,12 +1003,30 @@ class StoreOrder extends BaseModel
|
|
|
// @file_put_contents('quanju4.txt', $cart . "-购物车id2\r\n", 8);
|
|
|
$product_radio = 0;
|
|
|
$product_info = StoreCart::where('id', $cart)->find()->toArray();
|
|
|
-
|
|
|
- $product = StoreProductLevel::where('product_id', $product_info['product_id'])->where('level_id', $user['level'])->where('type', 1)->find(); //商品返现比例
|
|
|
- if (!empty($product)) {
|
|
|
- $product = $product->toArray();
|
|
|
- $product_radio = $product['rebate_ratio'];
|
|
|
+ if ($bc > 1) {
|
|
|
+ // 获取上级和下级等级之间的所有等级id
|
|
|
+ $level_ids = SystemUserLevel::where('grade', '>', $parentLevel)
|
|
|
+ ->where('grade', '<=', $level_info['grade'])
|
|
|
+ ->column('id');
|
|
|
+
|
|
|
+ // 使用数据库max函数直接获取最高返现比例,性能更优
|
|
|
+ if (!empty($level_ids)) {
|
|
|
+ $product_radio = StoreProductLevel::where('product_id', $product_info['product_id'])
|
|
|
+ ->where('level_id', 'in', $level_ids)
|
|
|
+ ->where('type', 1)
|
|
|
+ ->sum('rebate_ratio');
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ $product = StoreProductLevel::where('product_id', $product_info['product_id'])
|
|
|
+ ->where('level_id', $user['level'])
|
|
|
+ ->where('type', 1)
|
|
|
+ ->find(); // 商品返现比例
|
|
|
+ if (!empty($product)) {
|
|
|
+ $product = $product->toArray();
|
|
|
+ $product_radio = $product['rebate_ratio'];
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
// @file_put_contents('quanju.txt', json_encode($product_info) . "-购物车信息\r\n", 8);
|
|
|
|
|
|
|
|
|
@@ -1063,7 +1041,7 @@ class StoreOrder extends BaseModel
|
|
|
|
|
|
}
|
|
|
}
|
|
|
- }
|
|
|
+// }
|
|
|
|
|
|
// }
|
|
|
@file_put_contents('quanju.txt', $brokerage . "-返利佣金金额\r\n", 8);
|