From 309363a3261cc283c21a0dc8036e9f78adfff270 Mon Sep 17 00:00:00 2001 From: limu Date: Fri, 22 Dec 2023 16:54:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=98=9F=E5=88=97=E8=B0=83=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crmeb/jobs/OrderPartnerJob.php | 87 ++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 41 deletions(-) diff --git a/crmeb/jobs/OrderPartnerJob.php b/crmeb/jobs/OrderPartnerJob.php index 9e177a7..ae1dc55 100644 --- a/crmeb/jobs/OrderPartnerJob.php +++ b/crmeb/jobs/OrderPartnerJob.php @@ -34,12 +34,16 @@ class OrderPartnerJob implements JobInterface public function fire($job, $data) { - file_put_contents('/tmp/debug_partner', '开始处理贡献值订单:'.var_export($data, 1), 8); + file_put_contents('/tmp/debug_partner', '开始处理贡献值订单:' . var_export($data, 1), 8); try { //初始化贡献值 $bao_price = $mian_price = $ping_price = $total_price = 0; $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']) @@ -95,7 +99,6 @@ class OrderPartnerJob implements JobInterface throw new Exception('订单没有指定三种类型商品,不计入贡献值统计'); } //读取品牌所属分类 - if (!empty($brand_ids)) { $brand_ids = array_unique($brand_ids); $cat_ids = StoreBrand::getDB()->whereIn('brand_id', $brand_ids)->column('brand_category_id'); @@ -163,20 +166,20 @@ class OrderPartnerJob implements JobInterface $role_ids = array_column($brand_roles, 'id'); $brand_brand_data = array_column($brand_roles, null, 'id'); - $user_list = User::getDB()->alias('u') - ->leftJoin('UserPartner p', 'u.uid = p.uid') - ->whereIn('p.partner_id', $role_ids) - ->where('u.uid', '<>', $data['uid']) - ->field('u.*,p.partner_id') + $role_list = UserPartner::getDB() + ->whereIn('partner_id', $role_ids) + ->where('uid', '<>', $data['uid']) ->select()->toArray(); - $user_count = count($user_list); - foreach ($user_list as $buk => $buv) { + foreach ($role_list as $buk => $buv) { $role_data = $brand_brand_data[$buv['partner_id']] ?? []; if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); - $role_value = bcdiv($role_value, $user_count, 2); - $user = User::getDB()->where('uid', $buv['uid'])->find(); + if (empty($buv['uid'])) { + $user = $admin_user; + } else { + $user = User::getDB()->where('uid', $buv['uid'])->find(); + } $user->all_value = bcadd($user->all_value, $role_value, 2); $user->save(); $user_log_data[] = [ @@ -201,19 +204,20 @@ class OrderPartnerJob implements JobInterface $role_ids = array_column($trade_roles, 'id'); $trade_trade_data = array_column($trade_roles, null, 'id'); - $user_list = User::getDB()->alias('u') - ->leftJoin('UserPartner p', 'u.uid = p.uid') - ->whereIn('p.partner_id', $role_ids) - ->where('u.uid', '<>', $data['uid']) - ->field('u.*,p.partner_id') + $role_list = UserPartner::getDB() + ->whereIn('partner_id', $role_ids) + ->where('uid', '<>', $data['uid']) ->select()->toArray(); - $user_count = count($user_list); - foreach ($user_list as $tuk => $tuv) { + + foreach ($role_list as $tuk => $tuv) { $role_data = $trade_trade_data[$tuv['partner_id']] ?? []; if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); - $role_value = bcdiv($role_value, $user_count, 2); - $user = User::getDB()->where('uid', $tuv['uid'])->find(); + if (empty($tuv['uid'])) { + $user = $admin_user; + } else { + $user = User::getDB()->where('uid', $tuv['uid'])->find(); + } $user->all_value = bcadd($user->all_value, $role_value, 2); $user->save(); $user_log_data[] = [ @@ -245,19 +249,21 @@ class OrderPartnerJob implements JobInterface $role_ids = array_column($area_roles, 'id'); $trade_trade_data = array_column($area_roles, null, 'id'); - $user_list = User::getDB()->alias('u') - ->leftJoin('UserPartner p', 'u.uid = p.uid') - ->whereIn('p.partner_id', $role_ids) - ->where('u.uid', '<>', $data['uid']) - ->field('u.*,p.partner_id') + + $role_list = UserPartner::getDB() + ->whereIn('partner_id', $role_ids) + ->where('uid', '<>', $data['uid']) ->select()->toArray(); - $user_count = count($user_list); - foreach ($user_list as $auk => $auv) { + + foreach ($role_list as $auk => $auv) { $role_data = $trade_trade_data[$auv['partner_id']] ?? []; if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); - $role_value = bcdiv($role_value, $user_count, 2); - $user = User::getDB()->where('uid', $auv['uid'])->find(); + if (empty($auv['uid'])) { + $user = $admin_user; + } else { + $user = User::getDB()->where('uid', $auv['uid'])->find(); + } $user->all_value = bcadd($user->all_value, $role_value, 2); $user->save(); $user_log_data[] = [ @@ -280,22 +286,22 @@ class OrderPartnerJob implements JobInterface ->select()->toArray(); $role_ids = array_column($common_roles, 'id'); $common_trade_data = array_column($common_roles, null, 'id'); - $user_list = User::getDB()->alias('u') - ->leftJoin('UserPartner p', 'u.uid = p.uid') - ->field('u.*,p.partner_id') - ->whereIn('p.partner_id', $role_ids) - ->where('u.uid', '<>', $data['uid']) + $role_list = UserPartner::getDB() + ->whereIn('partner_id', $role_ids) + ->where('uid', '<>', $data['uid']) ->select(); - if (!empty($user_list)) { - $user_list = $user_list->toArray(); - $user_count = count($user_list); - foreach ($user_list as $cuk => $cuv) { + if (!empty($role_list)) { + $role_list = $role_list->toArray(); + foreach ($role_list as $cuk => $cuv) { $role_data = $common_trade_data[$cuv['partner_id']] ?? []; if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); - $role_value = bcdiv($role_value, $user_count, 2); - $user = User::getDB()->where('uid', $cuv['uid'])->find(); + if (empty($cuv['uid'])) { + $user = $admin_user; + } else { + $user = User::getDB()->where('uid', $cuv['uid'])->find(); + } $user->all_value = bcadd($user->all_value, $role_value, 2); $user->save(); $user_log_data[] = [ @@ -310,7 +316,6 @@ class OrderPartnerJob implements JobInterface } } - //批量增加用户贡献值日志 ValueContributionLog::getDB()->insertAll($user_log_data); //社区等级判断