|
|
@ -34,12 +34,16 @@ class OrderPartnerJob implements JobInterface |
|
|
|
|
|
|
|
|
|
|
|
public function fire($job, $data) |
|
|
|
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 { |
|
|
|
try { |
|
|
|
//初始化贡献值 |
|
|
|
//初始化贡献值 |
|
|
|
$bao_price = $mian_price = $ping_price = $total_price = 0; |
|
|
|
$bao_price = $mian_price = $ping_price = $total_price = 0; |
|
|
|
$bao_flowing = $mian_flowing = $ping_flowing = 0; |
|
|
|
$bao_flowing = $mian_flowing = $ping_flowing = 0; |
|
|
|
$brand_ids = $trade_ids = $user_log_data = []; |
|
|
|
$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% |
|
|
|
//查询商品类型 -报单区 100% 免单区66.7% 平价区66.7% |
|
|
|
$order_product = StoreOrderProduct::getDB() |
|
|
|
$order_product = StoreOrderProduct::getDB() |
|
|
|
->where('order_id', $data['order_id']) |
|
|
|
->where('order_id', $data['order_id']) |
|
|
@ -95,7 +99,6 @@ class OrderPartnerJob implements JobInterface |
|
|
|
throw new Exception('订单没有指定三种类型商品,不计入贡献值统计'); |
|
|
|
throw new Exception('订单没有指定三种类型商品,不计入贡献值统计'); |
|
|
|
} |
|
|
|
} |
|
|
|
//读取品牌所属分类 |
|
|
|
//读取品牌所属分类 |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($brand_ids)) { |
|
|
|
if (!empty($brand_ids)) { |
|
|
|
$brand_ids = array_unique($brand_ids); |
|
|
|
$brand_ids = array_unique($brand_ids); |
|
|
|
$cat_ids = StoreBrand::getDB()->whereIn('brand_id', $brand_ids)->column('brand_category_id'); |
|
|
|
$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'); |
|
|
|
$role_ids = array_column($brand_roles, 'id'); |
|
|
|
$brand_brand_data = array_column($brand_roles, null, 'id'); |
|
|
|
$brand_brand_data = array_column($brand_roles, null, 'id'); |
|
|
|
|
|
|
|
|
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
$role_list = UserPartner::getDB() |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->whereIn('partner_id', $role_ids) |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->where('uid', '<>', $data['uid']) |
|
|
|
->where('u.uid', '<>', $data['uid']) |
|
|
|
|
|
|
|
->field('u.*,p.partner_id') |
|
|
|
|
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
$user_count = count($user_list); |
|
|
|
foreach ($role_list as $buk => $buv) { |
|
|
|
foreach ($user_list as $buk => $buv) { |
|
|
|
|
|
|
|
$role_data = $brand_brand_data[$buv['partner_id']] ?? []; |
|
|
|
$role_data = $brand_brand_data[$buv['partner_id']] ?? []; |
|
|
|
if (!empty($role_data)) { |
|
|
|
if (!empty($role_data)) { |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcdiv($role_value, $user_count, 2); |
|
|
|
if (empty($buv['uid'])) { |
|
|
|
$user = User::getDB()->where('uid', $buv['uid'])->find(); |
|
|
|
$user = $admin_user; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$user = User::getDB()->where('uid', $buv['uid'])->find(); |
|
|
|
|
|
|
|
} |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->save(); |
|
|
|
$user->save(); |
|
|
|
$user_log_data[] = [ |
|
|
|
$user_log_data[] = [ |
|
|
@ -201,19 +204,20 @@ class OrderPartnerJob implements JobInterface |
|
|
|
|
|
|
|
|
|
|
|
$role_ids = array_column($trade_roles, 'id'); |
|
|
|
$role_ids = array_column($trade_roles, 'id'); |
|
|
|
$trade_trade_data = array_column($trade_roles, null, 'id'); |
|
|
|
$trade_trade_data = array_column($trade_roles, null, 'id'); |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
$role_list = UserPartner::getDB() |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->whereIn('partner_id', $role_ids) |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->where('uid', '<>', $data['uid']) |
|
|
|
->where('u.uid', '<>', $data['uid']) |
|
|
|
|
|
|
|
->field('u.*,p.partner_id') |
|
|
|
|
|
|
|
->select()->toArray(); |
|
|
|
->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']] ?? []; |
|
|
|
$role_data = $trade_trade_data[$tuv['partner_id']] ?? []; |
|
|
|
if (!empty($role_data)) { |
|
|
|
if (!empty($role_data)) { |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcdiv($role_value, $user_count, 2); |
|
|
|
if (empty($tuv['uid'])) { |
|
|
|
$user = User::getDB()->where('uid', $tuv['uid'])->find(); |
|
|
|
$user = $admin_user; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$user = User::getDB()->where('uid', $tuv['uid'])->find(); |
|
|
|
|
|
|
|
} |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->save(); |
|
|
|
$user->save(); |
|
|
|
$user_log_data[] = [ |
|
|
|
$user_log_data[] = [ |
|
|
@ -245,19 +249,21 @@ class OrderPartnerJob implements JobInterface |
|
|
|
|
|
|
|
|
|
|
|
$role_ids = array_column($area_roles, 'id'); |
|
|
|
$role_ids = array_column($area_roles, 'id'); |
|
|
|
$trade_trade_data = array_column($area_roles, null, 'id'); |
|
|
|
$trade_trade_data = array_column($area_roles, null, 'id'); |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
|
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
$role_list = UserPartner::getDB() |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->whereIn('partner_id', $role_ids) |
|
|
|
->where('u.uid', '<>', $data['uid']) |
|
|
|
->where('uid', '<>', $data['uid']) |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
|
|
|
|
->select()->toArray(); |
|
|
|
->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']] ?? []; |
|
|
|
$role_data = $trade_trade_data[$auv['partner_id']] ?? []; |
|
|
|
if (!empty($role_data)) { |
|
|
|
if (!empty($role_data)) { |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcdiv($role_value, $user_count, 2); |
|
|
|
if (empty($auv['uid'])) { |
|
|
|
$user = User::getDB()->where('uid', $auv['uid'])->find(); |
|
|
|
$user = $admin_user; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$user = User::getDB()->where('uid', $auv['uid'])->find(); |
|
|
|
|
|
|
|
} |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->save(); |
|
|
|
$user->save(); |
|
|
|
$user_log_data[] = [ |
|
|
|
$user_log_data[] = [ |
|
|
@ -280,22 +286,22 @@ class OrderPartnerJob implements JobInterface |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$role_ids = array_column($common_roles, 'id'); |
|
|
|
$role_ids = array_column($common_roles, 'id'); |
|
|
|
$common_trade_data = array_column($common_roles, null, 'id'); |
|
|
|
$common_trade_data = array_column($common_roles, null, 'id'); |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
$role_list = UserPartner::getDB() |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->whereIn('partner_id', $role_ids) |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
->where('uid', '<>', $data['uid']) |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
|
|
|
|
->where('u.uid', '<>', $data['uid']) |
|
|
|
|
|
|
|
->select(); |
|
|
|
->select(); |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($user_list)) { |
|
|
|
if (!empty($role_list)) { |
|
|
|
$user_list = $user_list->toArray(); |
|
|
|
$role_list = $role_list->toArray(); |
|
|
|
$user_count = count($user_list); |
|
|
|
foreach ($role_list as $cuk => $cuv) { |
|
|
|
foreach ($user_list as $cuk => $cuv) { |
|
|
|
|
|
|
|
$role_data = $common_trade_data[$cuv['partner_id']] ?? []; |
|
|
|
$role_data = $common_trade_data[$cuv['partner_id']] ?? []; |
|
|
|
if (!empty($role_data)) { |
|
|
|
if (!empty($role_data)) { |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); |
|
|
|
$role_value = bcdiv($role_value, $user_count, 2); |
|
|
|
if (empty($cuv['uid'])) { |
|
|
|
$user = User::getDB()->where('uid', $cuv['uid'])->find(); |
|
|
|
$user = $admin_user; |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
$user = User::getDB()->where('uid', $cuv['uid'])->find(); |
|
|
|
|
|
|
|
} |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
$user->save(); |
|
|
|
$user->save(); |
|
|
|
$user_log_data[] = [ |
|
|
|
$user_log_data[] = [ |
|
|
@ -310,7 +316,6 @@ class OrderPartnerJob implements JobInterface |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//批量增加用户贡献值日志 |
|
|
|
//批量增加用户贡献值日志 |
|
|
|
ValueContributionLog::getDB()->insertAll($user_log_data); |
|
|
|
ValueContributionLog::getDB()->insertAll($user_log_data); |
|
|
|
//社区等级判断 |
|
|
|
//社区等级判断 |
|
|
|