diff --git a/crmeb/jobs/OrderPartnerJob.php b/crmeb/jobs/OrderPartnerJob.php index ae1dc55..90c4098 100644 --- a/crmeb/jobs/OrderPartnerJob.php +++ b/crmeb/jobs/OrderPartnerJob.php @@ -41,9 +41,6 @@ class OrderPartnerJob implements JobInterface $bao_flowing = $mian_flowing = $ping_flowing = 0; $brand_ids = $trade_ids = $user_log_data = []; $admin_id = config('partner.gongxian_admin_id') ?? ''; - if (!empty($admin_id)) { - $admin_user = User::getDB()->where('uid', $admin_id)->find(); - } //查询商品类型 -报单区 100% 免单区66.7% 平价区66.7% $order_product = StoreOrderProduct::getDB() ->where('order_id', $data['order_id']) @@ -176,7 +173,7 @@ class OrderPartnerJob implements JobInterface if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); if (empty($buv['uid'])) { - $user = $admin_user; + $user = User::getDB()->where('uid', $admin_id)->find();; } else { $user = User::getDB()->where('uid', $buv['uid'])->find(); } @@ -214,7 +211,7 @@ class OrderPartnerJob implements JobInterface if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); if (empty($tuv['uid'])) { - $user = $admin_user; + $user = User::getDB()->where('uid', $admin_id)->find();; } else { $user = User::getDB()->where('uid', $tuv['uid'])->find(); } @@ -260,7 +257,7 @@ class OrderPartnerJob implements JobInterface if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); if (empty($auv['uid'])) { - $user = $admin_user; + $user = User::getDB()->where('uid', $admin_id)->find();; } else { $user = User::getDB()->where('uid', $auv['uid'])->find(); } @@ -277,6 +274,52 @@ class OrderPartnerJob implements JobInterface } } } + //查询大区角色 + $region_list = config('partner.region_type'); + $region_ids = []; + if (!empty($province_id) && !empty($region_list)) { + foreach ($region_list as $rv) { + if (in_array($province_id, $rv['province_ids'])) { + $region_ids[] = $rv['id']; + } + } + if(!empty($region_ids)){ + $region_roles = Partner::getDB() + ->where('status', 1) + ->whereNotIn('type', 2) + ->whereIn('region_id', $region_ids) + ->select()->toArray(); + $role_ids = array_column($region_roles, 'id'); + $regin_trade_data = array_column($region_roles, null, 'id'); + + $role_list = UserPartner::getDB() + ->whereIn('partner_id', $role_ids) + ->where('uid', '<>', $data['uid']) + ->select()->toArray(); + + foreach ($role_list as $ruk => $ruv) { + $role_data = $regin_trade_data[$ruv['partner_id']] ?? []; + if (!empty($role_data)) { + $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); + if (empty($ruv['uid'])) { + $user = User::getDB()->where('uid', $admin_id)->find();; + } else { + $user = User::getDB()->where('uid', $ruv['uid'])->find(); + } + $user->all_value = bcadd($user->all_value, $role_value, 2); + $user->save(); + $user_log_data[] = [ + 'type' => 6, + 'types_of' => 1, + 'num' => $role_value, + 'ctime' => date('Y-m-d H:i:s'), + 'memo' => '订单消费大区贡献值', + 'user_id' => $ruv['uid'], + ]; + } + } + } + } //查询通用角色 $common_roles = Partner::getDB() @@ -298,7 +341,7 @@ class OrderPartnerJob implements JobInterface if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); if (empty($cuv['uid'])) { - $user = $admin_user; + $user = User::getDB()->where('uid', $admin_id)->find();; } else { $user = User::getDB()->where('uid', $cuv['uid'])->find(); }