Kirin 2 роки тому
батько
коміт
33c2190827

+ 2 - 0
app/admin/controller/user/UserAwardLevel.php

@@ -35,6 +35,7 @@ class UserAwardLevel extends AuthController
         $field[] = Form::number('suit_award', "套装极差奖", isset($vipinfo) ? $vipinfo->suit_award : 0)->min(0)->col(8);
         $field[] = Form::number('level_num', "直推套装单数", isset($vipinfo) ? $vipinfo->level_num : 0)->min(0)->col(8);
         $field[] = Form::radio('is_show', '是否显示', isset($vipinfo) ? $vipinfo->is_show : 0)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])->col(8);
+        $field[] = Form::radio('system_award', '参与加权分红', isset($vipinfo) ? $vipinfo->system_award : 0)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(8);
         $field[] = Form::textarea('explain', '等级说明', isset($vipinfo) ? $vipinfo->explain : '');
 
         $form = Form::make_post_form('添加等级设置', $field, Url::buildUrl('save', ['id' => $id]), 2);
@@ -55,6 +56,7 @@ class UserAwardLevel extends AuthController
             ['level_num', 0],
             ['is_show', ''],
             ['explain', ''],
+            ['system_award', 0],
         ]);
         if (!$data['name']) JsonService::fail('请输入等级名称');
         SystemGroupLevel::beginTrans();

+ 2 - 0
app/admin/controller/user/UserGroupLevel.php

@@ -36,6 +36,7 @@ class UserGroupLevel extends AuthController
         $field[] = Form::number('group_award', "普通商品极差奖(%)", isset($vipinfo) ? $vipinfo->group_award : 0)->min(0)->col(8);
         $field[] = Form::number('integral_group_award', "积分商品极差奖(%)", isset($vipinfo) ? $vipinfo->integral_group_award : 0)->min(0)->col(8);
         $field[] = Form::number('level_num', "伞下套装单数", isset($vipinfo) ? $vipinfo->level_num : 0)->min(0)->col(8);
+        $field[] = Form::radio('system_award', '参与加权分红', isset($vipinfo) ? $vipinfo->system_award : 0)->options([['label' => '是', 'value' => 1], ['label' => '否', 'value' => 0]])->col(8);
         $field[] = Form::radio('is_show', '是否显示', isset($vipinfo) ? $vipinfo->is_show : 0)->options([['label' => '显示', 'value' => 1], ['label' => '隐藏', 'value' => 0]])->col(8);
         $field[] = Form::textarea('explain', '等级说明', isset($vipinfo) ? $vipinfo->explain : '');
 
@@ -58,6 +59,7 @@ class UserGroupLevel extends AuthController
             ['integral_group_award', 0],
             ['level_num', 0],
             ['is_show', ''],
+            ['system_award', 0],
             ['explain', ''],
         ]);
         if (!$data['name']) JsonService::fail('请输入等级名称');

+ 44 - 0
app/models/store/StoreOrder.php

@@ -855,6 +855,7 @@ class StoreOrder extends BaseModel
         $res2 = $res2 && self::addSuit($order);
         $res2 = $res2 && StoreOrder::sendSuit($order);
         $res2 = $res2 && StoreOrder::sendGroupAward($order);
+        $res2 = $res2 && StoreOrder::sendAllSystemAward($order);
         $res2 = $res2 && SystemGroupLevel::checkLevel($order['uid']);
         $res2 = $res2 && SystemAwardLevel::checkLevel($order['uid']);
         event('OrderPaySuccess', [$order, $formId]);
@@ -2618,6 +2619,49 @@ class StoreOrder extends BaseModel
         return $res;
     }
 
+    public static function sendAllSystemAward($order): bool
+    {
+//        return true;
+        //TODO 营销产品不返佣金
+        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']);
+
+        $cartInfo = StoreOrderCartInfo::whereIn('cart_id', $order['cart_id'])->column('cart_info');
+        $suit = 0;
+        $suit_price = 0;
+        foreach ($cartInfo as $value) {
+            $product = json_decode($value, true);
+            if (isset($product['productInfo'])) {
+                $productInfo = $product['productInfo'];
+                if ($product['is_suit']) {
+                    $suit += $product['cart_num'] ?? 0;
+                    $suit_price += ($productInfo['attrInfo']['price'] ?? $product['price']) * $product['cart_num'];
+                }
+            }
+        }
+
+        $levels = SystemGroupLevel::where('system_award', 1)->column('id');
+        $levels2 = SystemAwardLevel::where('system_award', 1)->column('id');
+
+        $users = User::where('group_level', 'in', $levels)->whereOr('award_level', 'in', $levels2)
+            ->select();
+        $res = true;
+
+        $award = bcdiv(bcmul(100, $suit, 2), count($users), 2);
+
+        if ($suit && $award) {
+            foreach ($users as $v) {
+                $mark = '用户' . $userInfo['nickname'] . '(' . $order['uid'] . ')' . '购买套装商品,获得董事分红' . $award;
+                $res = $res && UserBill::income('董事加权分红', $v['uid'], 'now_money', 'brokerage', $award, $order['id'], bcadd($v['brokerage_price'], $award, 2), $mark);
+                $res = $res && User::where('uid', $v['uid'])->inc('brokerage_price', $award)->update();
+            }
+        }
+        return $res;
+    }
+
     public static function sendSuit($order): bool
     {
 //        return true;