|
@@ -2709,6 +2709,217 @@ class StoreOrder extends BaseModel
|
|
|
return $res;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ public static function sendGroupAwardSee($order): bool
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ if (isset($order['combination_id']) && $order['combination_id']) return true;
|
|
|
+ if (isset($order['seckill_id']) && $order['seckill_id']) return true;
|
|
|
+ if (isset($order['bargain_id']) && $order['bargain_id']) return true;
|
|
|
+ $userInfo = User::getUserInfo($order['uid']);
|
|
|
+ $spread = User::getUserInfo($userInfo['spread_uid']);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $order['cart_id'])->column('cart_info');
|
|
|
+ $suit = 0;
|
|
|
+ $suit_exit = 0;
|
|
|
+ $suit_award = 0;
|
|
|
+ $suit_price = 0;
|
|
|
+ $extra_price = 0;
|
|
|
+ foreach ($cartInfo as $value) {
|
|
|
+ $product = json_decode($value, true);
|
|
|
+ if (isset($product['productInfo'])) {
|
|
|
+ $productInfo = $product['productInfo'];
|
|
|
+ if (($productInfo['attrInfo']['brokerage_suit'] ?? 0) > 0) {
|
|
|
+ $suit_award += $product['productInfo']['attrInfo']['brokerage_suit'] * $product['cart_num'];
|
|
|
+ $suit_price += ($productInfo['attrInfo']['price'] ?? $product['price']) * $product['cart_num'];
|
|
|
+ if ($product['is_suit']) $suit_exit += $product['cart_num'] ?? 0;
|
|
|
+ }
|
|
|
+ if ($product['is_suit']) {
|
|
|
+ $suit += $product['cart_num'] ?? 0;
|
|
|
+ $suit_price += ($productInfo['attrInfo']['price'] ?? $product['price']) * $product['cart_num'];
|
|
|
+ }
|
|
|
+ if (!$product['is_award']) {
|
|
|
+ $extra_price += ($productInfo['attrInfo']['price'] ?? $product['price']) * $product['cart_num'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $res = true;
|
|
|
+ $suit_recommend = sys_config('suit_recommend', 0, true);
|
|
|
+ if ($spread) {
|
|
|
+
|
|
|
+ $brokeragePrice = bcmul($suit_recommend, $suit - $suit_exit, 2);
|
|
|
+ $brokeragePrice = bcadd($suit_award, $brokeragePrice, 2);
|
|
|
+ if ($brokeragePrice > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得推荐奖励' . $brokeragePrice;
|
|
|
+ var_dump($mark);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $send = 0;
|
|
|
+ $send_normal = 0;
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ while ($spread) {
|
|
|
+ $group_level = SystemGroupLevel::get($spread['group_level']);
|
|
|
+ $award_level = SystemGroupLevel::get($spread['award_level']);
|
|
|
+ $balance = $spread['brokerage_price'];
|
|
|
+ if ($suit) {
|
|
|
+ $award_group = $group_level['suit_award'] ?? 0;
|
|
|
+ $award_award = $award_level['suit_award'] ?? 0;
|
|
|
+ $big = $award_group > $award_award ? $group_level['id'] : $award_level['id'];
|
|
|
+ $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 = $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['spread_uid'])->find();
|
|
|
+ $group_levels = SystemGroupLevel::where('company_award', '>', 0)->column('id');
|
|
|
+ $p_ratio = 0;
|
|
|
+ $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;
|
|
|
+ $p_ratio = 1;
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ $spread_up = User::where('uid', $spread_up['spread_uid'])->find();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ 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);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($p_ratio > 0) {
|
|
|
+ $op_award = bcmul($suit_price, bcdiv($p_ratio, 100, 4), 2);
|
|
|
+ if ($op_award > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得分公司奖奖励' . $op_award;
|
|
|
+ $res = $res && UserBill::income('分公司奖', $spread_up['uid'], 'now_money', 'brokerage', $op_award, $order['id'], bcadd($spread_up['brokerage_price'], $op_award, 2), $mark);
|
|
|
+ $res = $res && User::where('uid', $spread_up['uid'])->inc('brokerage_price', $op_award)->update();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $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;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $lay_award = $layer_award_real[$layer] ?? null;
|
|
|
+ if ($lay_award) {
|
|
|
+ $sps = User::where('spread_uid', $spread['uid'])->column('uid');
|
|
|
+ $count = 0;
|
|
|
+ foreach ($sps as $vvv) {
|
|
|
+ if (StoreOrder::where('uid', $vvv)->where('paid', 1)->where('refund_status', 0)->where('is_del', 0)->where('is_system_del', 0)
|
|
|
+ ->where('suit', '>', 0)->find()) {
|
|
|
+ $count++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($count >= $lay_award['recommend']
|
|
|
+ || StoreOrder::where('uid', $spread['uid'])
|
|
|
+ ->where('paid', 1)
|
|
|
+ ->where('refund_status', 0)
|
|
|
+ ->where('is_del', 0)
|
|
|
+ ->where('is_system_del', 0)
|
|
|
+ ->where('suit', '>', 0)
|
|
|
+ ->sum('suit') >= 25) {
|
|
|
+ if ($suit) {
|
|
|
+ $brokeragePrice = bcmul($lay_award['award'], $suit, 2);
|
|
|
+ if ($brokeragePrice > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得见点奖励' . $brokeragePrice;
|
|
|
+ var_dump($mark);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($order['use_integral'] > 0) {
|
|
|
+ $brokeragePrice = bcmul(bcdiv($lay_award['integral_award'], 100, 4), bcsub(bcsub($order['total_price'], $suit_price, 2), $extra_price, 2), 2);
|
|
|
+ if ($brokeragePrice > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买积分商品,获得见点奖励' . $brokeragePrice;
|
|
|
+ var_dump($mark);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ $layer++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$group_level) {
|
|
|
+ $group_award_basic = sys_config('group_award_basic', 0);
|
|
|
+ $integral_group_award_basic = sys_config('integral_group_award_basic', 0);
|
|
|
+ $brokeragePrice = bcmul(bcdiv($group_award_basic, 100, 4), bcsub(bcsub($order['total_price'], $suit_price, 2), $extra_price, 2), 2);
|
|
|
+ if ($order['use_integral'] > 0) $brokeragePrice = bcmul(bcdiv($integral_group_award_basic, 100, 4), bcsub(bcsub($order['total_price'], $suit_price, 2), $extra_price, 2), 2);
|
|
|
+ } else {
|
|
|
+ $brokeragePrice = bcmul(bcdiv($group_level['group_award'], 100, 4), bcsub(bcsub($order['total_price'], $suit_price, 2), $extra_price, 2), 2);
|
|
|
+ if ($order['use_integral'] > 0) $brokeragePrice = bcmul(bcdiv($group_level['integral_group_award'], 100, 4), bcsub(bcsub($order['total_price'], $suit_price, 2), $extra_price, 2), 2);
|
|
|
+ }
|
|
|
+ if ($brokeragePrice > $send_normal) {
|
|
|
+ $real_send = bcsub($brokeragePrice, $send_normal, 2);
|
|
|
+ if ($real_send > 0) {
|
|
|
+ $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买' . ($order['use_integral'] > 0 ? '积分' : '普通') . '商品,获得极差奖励' . $real_send;
|
|
|
+ var_dump($mark);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $spread = User::getUserInfo($spread['spread_uid']);
|
|
|
+ }
|
|
|
+ return $res;
|
|
|
+ }
|
|
|
+
|
|
|
public static function sendAllSystemAward($order): bool
|
|
|
{
|
|
|
|