|
|
@@ -2539,6 +2539,8 @@ class StoreOrder extends BaseModel
|
|
|
$layer = 1;
|
|
|
$layer_award = sys_data('suit_sub_award');
|
|
|
$layer_award_real = [];
|
|
|
+ $company_award = false;
|
|
|
+ $operate_award = false;
|
|
|
foreach ($layer_award as $v) {
|
|
|
$layer_award_real[$v['layer']] = $v;
|
|
|
}
|
|
|
@@ -2553,65 +2555,67 @@ class StoreOrder extends BaseModel
|
|
|
$brokeragePrice_a = bcmul($award_award, $suit, 2);
|
|
|
$brokeragePrice_g = bcmul($award_group, $suit, 2);
|
|
|
$brokeragePrice_big = $brokeragePrice_a > $brokeragePrice_g ? $brokeragePrice_a : $brokeragePrice_g;
|
|
|
- $brokeragePrice_small = $brokeragePrice_a > $brokeragePrice_g ? $brokeragePrice_g : $brokeragePrice_a;
|
|
|
- if ($brokeragePrice_big == $brokeragePrice_small) {
|
|
|
- $brokeragePrice = $brokeragePrice_big;
|
|
|
- if ($brokeragePrice > $send) {
|
|
|
- $real_send = bcsub($brokeragePrice, $send, 2);
|
|
|
- if ($real_send > 0) {
|
|
|
- $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得极差奖励' . $real_send;
|
|
|
- $res = $res && UserBill::income('套装极差奖', $spread['uid'], 'now_money', 'brokerage', $real_send, $order['id'], bcadd($balance, $real_send, 2), $mark);
|
|
|
- $res = $res && User::where('uid', $spread['uid'])->inc('brokerage_price', $real_send)->update();
|
|
|
- $balance = bcadd($balance, $real_send, 2);
|
|
|
- $send = $brokeragePrice;
|
|
|
+// $brokeragePrice_small = $brokeragePrice_a > $brokeragePrice_g ? $brokeragePrice_g : $brokeragePrice_a;
|
|
|
+// if ($brokeragePrice_big == $brokeragePrice_small) {
|
|
|
+ $brokeragePrice = $brokeragePrice_big;
|
|
|
+ if ($brokeragePrice > $send) {
|
|
|
+ $real_send = bcsub($brokeragePrice, $send, 2);
|
|
|
+ if ($real_send > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得极差奖励' . $real_send;
|
|
|
+ $res = $res && UserBill::income('套装极差奖', $spread['uid'], 'now_money', 'brokerage', $real_send, $order['id'], bcadd($balance, $real_send, 2), $mark);
|
|
|
+ $res = $res && User::where('uid', $spread['uid'])->inc('brokerage_price', $real_send)->update();
|
|
|
+ $balance = bcadd($balance, $real_send, 2);
|
|
|
+ $send = $brokeragePrice;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($group_level['company_award'] > 0 || $award_level['company_award'] > 0 && !$company_award) {
|
|
|
+ $ratio = ($group_level['company_award'] > $award_level['company_award'] ? $group_level['company_award'] : $award_level['company_award']);
|
|
|
+ $spread_up = User::where('uid', $spread['uid'])->find();
|
|
|
+ $group_levels = SystemGroupLevel::where('company_award', '>', 0)->column('id');
|
|
|
+ $award_levels = SystemAwardLevel::where('company_award', '>', 0)->column('id');
|
|
|
+ while ($spread_up) {
|
|
|
+ if (in_array($spread_up['group_level'], $group_levels) || in_array($spread_up['award_level'], $award_levels)) {
|
|
|
+ $ratio -= 1;
|
|
|
+ break;
|
|
|
}
|
|
|
+ $spread_up = User::where('uid', $spread_up['uid'])->find();
|
|
|
}
|
|
|
- } else {
|
|
|
- $brokeragePrice = $brokeragePrice_small;
|
|
|
- if ($brokeragePrice > $send) {
|
|
|
- $real_send = bcsub($brokeragePrice, $send, 2);
|
|
|
- if ($real_send > 0) {
|
|
|
- $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得极差奖励' . $real_send;
|
|
|
- $res = $res && UserBill::income('套装极差奖', $spread['uid'], 'now_money', 'brokerage', $real_send, $order['id'], bcadd($balance, $real_send, 2), $mark);
|
|
|
- $res = $res && User::where('uid', $spread['uid'])->inc('brokerage_price', $real_send)->update();
|
|
|
- $balance = bcadd($balance, $real_send, 2);
|
|
|
- $send = $brokeragePrice;
|
|
|
+ $c = [];
|
|
|
+ $p = [$spread['uid']];
|
|
|
+ while ($p) {
|
|
|
+ $child = User::where('spread_uid', 'in', $p)->where(function ($query) use ($group_levels, $award_levels) {
|
|
|
+ $query->where('group_level', 'in', $group_levels)->whereOr('award_level', 'in', $award_levels);
|
|
|
+ })->column('uid');
|
|
|
+ if (count($child)) {
|
|
|
+ $c = array_merge($c, $child);
|
|
|
}
|
|
|
+ $p = User::where('spread_uid', 'in', $p)->where('uid', 'not in', $child)->column('uid');
|
|
|
}
|
|
|
- $brokeragePrice = $brokeragePrice_big;
|
|
|
- if ($brokeragePrice > $send) {
|
|
|
- $real_send = bcsub($brokeragePrice, $send, 2);
|
|
|
- if ($real_send > 0) {
|
|
|
- $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得极差奖励' . $real_send;
|
|
|
- $res = $res && UserBill::income('套装极差奖', $spread['uid'], 'now_money', 'brokerage', $real_send, $order['id'], bcadd($balance, $real_send, 2), $mark, 0, $big);
|
|
|
- $send = $brokeragePrice;
|
|
|
+ $ratio += count(array_unique($c));
|
|
|
+ if ($ratio > 0) {
|
|
|
+ $op_award = bcmul($suit_price, bcdiv($ratio, 100, 4), 2);
|
|
|
+ if ($op_award > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得运营公司奖励' . $op_award;
|
|
|
+ $res = $res && UserBill::income('运营公司奖', $spread['uid'], 'now_money', 'brokerage', $op_award, $order['id'], bcadd($balance, $op_award, 2), $mark);
|
|
|
+ $res = $res && User::where('uid', $spread['uid'])->inc('brokerage_price', $op_award)->update();
|
|
|
+ $balance = bcadd($balance, $op_award, 2);
|
|
|
}
|
|
|
}
|
|
|
+ $company_award = true;
|
|
|
+ }
|
|
|
+ if ($group_level['operate_award'] > 0 || $award_level['operate_award'] > 0 && !$operate_award) {
|
|
|
+ $ratio = ($group_level['operate_award'] > $award_level['operate_award'] ? $group_level['operate_award'] : $award_level['operate_award']);
|
|
|
+ if ($ratio > 0) {
|
|
|
+ $op_award = bcmul($suit_price, bcdiv($ratio, 100, 4), 2);
|
|
|
+ if ($op_award > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得运营公司奖励' . $op_award;
|
|
|
+ $res = $res && UserBill::income('运营公司奖', $spread['uid'], 'now_money', 'brokerage', $op_award, $order['id'], bcadd($balance, $op_award, 2), $mark);
|
|
|
+ $res = $res && User::where('uid', $spread['uid'])->inc('brokerage_price', $op_award)->update();
|
|
|
+ $balance = bcadd($balance, $op_award, 2);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $operate_award = true;
|
|
|
}
|
|
|
-// if ($group_level) {
|
|
|
-// if (!$award_level) {
|
|
|
-// $award = SystemGroupLevel::min('suit_award');
|
|
|
-// $brokeragePrice = bcmul($award, $suit, 2);
|
|
|
-// if ($brokeragePrice > $send) {
|
|
|
-// $real_send = bcsub($brokeragePrice, $send, 2);
|
|
|
-// $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得极差奖励' . $real_send;
|
|
|
-// $res = $res && UserBill::income('套装极差奖', $spread['uid'], 'now_money', 'brokerage', $real_send, $order['id'], $spread['brokerage_price'], $mark, 0);
|
|
|
-// $send = $brokeragePrice;
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// $award = $group_level['suit_award'] > $award_level['suit_award'] ? $award_level['suit_award'] : $group_level['suit_award'];
|
|
|
-// $brokeragePrice = bcmul($award, $suit, 2);
|
|
|
-// if ($brokeragePrice > $send) {
|
|
|
-// $real_send = bcsub($brokeragePrice, $send, 2);
|
|
|
-// if ($real_send > 0) {
|
|
|
-// $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得极差奖励' . $real_send;
|
|
|
-// $res = $res && UserBill::income('套装极差奖', $spread['uid'], 'now_money', 'brokerage', $real_send, $order['id'], bcadd($spread['brokerage_price'], $real_send, 2), $mark);
|
|
|
-// $res = $res && User::where('uid', $spread['uid'])->inc('brokerage_price', $real_send)->update();
|
|
|
-// $send = $brokeragePrice;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
}
|
|
|
$lay_award = $layer_award_real[$layer] ?? null;
|
|
|
if ($lay_award) {
|