|
|
@ -32,25 +32,26 @@ use app\common\repositories\user\UserAddressRepository; |
|
|
|
class OrderPartnerJob implements JobInterface |
|
|
|
class OrderPartnerJob implements JobInterface |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
|
|
|
|
public function fire($job, $data) |
|
|
|
public function fire($job,$data) |
|
|
|
{ |
|
|
|
{ |
|
|
|
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; |
|
|
|
$brand_ids = $trade_ids = $user_log_data = []; |
|
|
|
$brand_ids = $trade_ids = $user_log_data = []; |
|
|
|
//查询商品类型 -报单区 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']) |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$product_ids = array_column($order_product, null, $order_product['product_id']); |
|
|
|
|
|
|
|
$prodcut_temp = []; |
|
|
|
$prodcut_temp = []; |
|
|
|
foreach ($order_product as $pk => $pv) { |
|
|
|
foreach ($order_product as $pk => $pv) { |
|
|
|
|
|
|
|
$product_ids[] = $pv['product_id']; |
|
|
|
$prodcut_temp[$pv['product_id']] = $pv; |
|
|
|
$prodcut_temp[$pv['product_id']] = $pv; |
|
|
|
} |
|
|
|
} |
|
|
|
$product_list = Product::getDB()->alias('a') |
|
|
|
$product_list = Product::getDB()->alias('a') |
|
|
|
->leftJoin('Spu b', 'a.product_id = b.product_id') |
|
|
|
->leftJoin('StoreSpu b', 'a.product_id = b.product_id') |
|
|
|
->field('a.*,b.mer_labels') |
|
|
|
->field('a.*,b.mer_labels') |
|
|
|
->whereIn('product_id', $product_ids) |
|
|
|
->whereIn('a.product_id', $product_ids) |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$has_contribute = false; |
|
|
|
$has_contribute = false; |
|
|
|
if (!empty($product_list)) { |
|
|
|
if (!empty($product_list)) { |
|
|
@ -60,6 +61,7 @@ class OrderPartnerJob implements JobInterface |
|
|
|
$has_contribute = true; |
|
|
|
$has_contribute = true; |
|
|
|
//计算报单区 100%金额 |
|
|
|
//计算报单区 100%金额 |
|
|
|
$bao_price = $prodcut_temp[$v['product_id']]['product_price']; |
|
|
|
$bao_price = $prodcut_temp[$v['product_id']]['product_price']; |
|
|
|
|
|
|
|
$bao_flowing = bcadd($bao_flowing, $bao_price, 2); |
|
|
|
$total_price = bcadd($total_price, $bao_price, 2); |
|
|
|
$total_price = bcadd($total_price, $bao_price, 2); |
|
|
|
} elseif ($v['mer_labels'] == ',2,') { |
|
|
|
} elseif ($v['mer_labels'] == ',2,') { |
|
|
|
$brand_ids[] = $v['brand_id']; |
|
|
|
$brand_ids[] = $v['brand_id']; |
|
|
@ -67,6 +69,7 @@ class OrderPartnerJob implements JobInterface |
|
|
|
if ($prodcut_temp[$v['product_id']]['product_price'] > 0 && $data['commission_rate'] > 0) { |
|
|
|
if ($prodcut_temp[$v['product_id']]['product_price'] > 0 && $data['commission_rate'] > 0) { |
|
|
|
//计算当前商品的毛利占比 |
|
|
|
//计算当前商品的毛利占比 |
|
|
|
$has_contribute = true; |
|
|
|
$has_contribute = true; |
|
|
|
|
|
|
|
$mian_flowing = bcadd($mian_flowing, $prodcut_temp[$v['product_id']]['product_price'], 2); |
|
|
|
$mian_rate = bcdiv($prodcut_temp[$v['product_id']]['product_price'], $data['pay_price'], 3); |
|
|
|
$mian_rate = bcdiv($prodcut_temp[$v['product_id']]['product_price'], $data['pay_price'], 3); |
|
|
|
$mian_price = bcmul($data['commission_rate'], $mian_rate, 2); |
|
|
|
$mian_price = bcmul($data['commission_rate'], $mian_rate, 2); |
|
|
|
$mian_price = bcmul($mian_price, 0.667, 2); |
|
|
|
$mian_price = bcmul($mian_price, 0.667, 2); |
|
|
@ -76,6 +79,7 @@ class OrderPartnerJob implements JobInterface |
|
|
|
$brand_ids[] = $v['brand_id']; |
|
|
|
$brand_ids[] = $v['brand_id']; |
|
|
|
if ($prodcut_temp[$v['product_id']]['product_price'] > 0 && $data['commission_rate'] > 0) { |
|
|
|
if ($prodcut_temp[$v['product_id']]['product_price'] > 0 && $data['commission_rate'] > 0) { |
|
|
|
$has_contribute = true; |
|
|
|
$has_contribute = true; |
|
|
|
|
|
|
|
$ping_flowing = bcadd($ping_flowing, $prodcut_temp[$v['product_id']]['product_price'], 2); |
|
|
|
$ping_rate = bcdiv($prodcut_temp[$v['product_id']]['product_price'], $data['pay_price'], 3); |
|
|
|
$ping_rate = bcdiv($prodcut_temp[$v['product_id']]['product_price'], $data['pay_price'], 3); |
|
|
|
$ping_price = bcmul($data['commission_rate'], $ping_rate, 2); |
|
|
|
$ping_price = bcmul($data['commission_rate'], $ping_rate, 2); |
|
|
|
$ping_price = bcmul($ping_price, 0.667, 2); |
|
|
|
$ping_price = bcmul($ping_price, 0.667, 2); |
|
|
@ -90,7 +94,9 @@ class OrderPartnerJob implements JobInterface |
|
|
|
throw new Exception('订单没有指定三种类型商品,不计入贡献值统计'); |
|
|
|
throw new Exception('订单没有指定三种类型商品,不计入贡献值统计'); |
|
|
|
} |
|
|
|
} |
|
|
|
//读取品牌所属分类 |
|
|
|
//读取品牌所属分类 |
|
|
|
|
|
|
|
|
|
|
|
if (!empty($brand_ids)) { |
|
|
|
if (!empty($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'); |
|
|
|
$trade_ids = $cat_ids; |
|
|
|
$trade_ids = $cat_ids; |
|
|
|
$all_cat_ids = StoreBrandCategory::getDB()->whereIn('store_brand_category_id', $cat_ids)->column('path'); |
|
|
|
$all_cat_ids = StoreBrandCategory::getDB()->whereIn('store_brand_category_id', $cat_ids)->column('path'); |
|
|
@ -125,10 +131,12 @@ class OrderPartnerJob implements JobInterface |
|
|
|
'district_id' => $address['district_id'] ?? '', |
|
|
|
'district_id' => $address['district_id'] ?? '', |
|
|
|
'street_id' => $address['street_id'] ?? '', |
|
|
|
'street_id' => $address['street_id'] ?? '', |
|
|
|
'created_time' => date('Y-m-d H:i:s'), |
|
|
|
'created_time' => date('Y-m-d H:i:s'), |
|
|
|
|
|
|
|
'baodan_liushui' => $bao_flowing, |
|
|
|
]; |
|
|
|
]; |
|
|
|
StoreOrderContribute::getDB()->insert($contribute_insert); |
|
|
|
StoreOrderContribute::getDB()->insert($contribute_insert); |
|
|
|
//订单角色贡献值-30% |
|
|
|
//订单角色贡献值-30% |
|
|
|
$user_value = bcmul($total_price, 0.3, 2); |
|
|
|
$user_value = bcmul($total_price, 0.3, 2); |
|
|
|
|
|
|
|
|
|
|
|
$user = User::getDB()->where('uid', $data['uid'])->find(); |
|
|
|
$user = User::getDB()->where('uid', $data['uid'])->find(); |
|
|
|
$user->all_value = bcadd($user->all_value, $user_value, 2); |
|
|
|
$user->all_value = bcadd($user->all_value, $user_value, 2); |
|
|
|
$user->save(); |
|
|
|
$user->save(); |
|
|
@ -148,14 +156,17 @@ class OrderPartnerJob implements JobInterface |
|
|
|
->where('status', 1) |
|
|
|
->where('status', 1) |
|
|
|
->whereIn('brand_id', $brand_ids) |
|
|
|
->whereIn('brand_id', $brand_ids) |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$role_ids = array_column($brand_roles, null, 'id'); |
|
|
|
|
|
|
|
$brand_brand_data = array_column($brand_roles, 'id'); |
|
|
|
$role_ids = array_column($brand_roles, 'id'); |
|
|
|
|
|
|
|
$brand_brand_data = array_column($brand_roles, null, 'id'); |
|
|
|
|
|
|
|
|
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->where('uid', '<>', $data['uid']) |
|
|
|
->where('u.uid', '<>', $data['uid']) |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
|
|
|
|
|
|
|
|
$user_count = count($user_list); |
|
|
|
$user_count = count($user_list); |
|
|
|
foreach ($user_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']] ?? []; |
|
|
@ -178,17 +189,19 @@ class OrderPartnerJob implements JobInterface |
|
|
|
} |
|
|
|
} |
|
|
|
//处理合作人角色是否包含此商品行业 |
|
|
|
//处理合作人角色是否包含此商品行业 |
|
|
|
if (!empty($trade_ids)) { |
|
|
|
if (!empty($trade_ids)) { |
|
|
|
|
|
|
|
|
|
|
|
$trade_roles = Partner::getDB() |
|
|
|
$trade_roles = Partner::getDB() |
|
|
|
->where('type', 4) |
|
|
|
->where('type', 4) |
|
|
|
->where('status', 1) |
|
|
|
->where('status', 1) |
|
|
|
->whereIn('trade_id', $trade_ids) |
|
|
|
->whereIn('trade_id', $trade_ids) |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$role_ids = array_column($trade_roles, null, 'id'); |
|
|
|
|
|
|
|
$trade_trade_data = array_column($trade_roles, 'id'); |
|
|
|
$role_ids = array_column($trade_roles, 'id'); |
|
|
|
|
|
|
|
$trade_trade_data = array_column($trade_roles,null, 'id'); |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->where('uid', '<>', $data['uid']) |
|
|
|
->where('u.uid', '<>', $data['uid']) |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$user_count = count($user_list); |
|
|
|
$user_count = count($user_list); |
|
|
@ -219,18 +232,20 @@ class OrderPartnerJob implements JobInterface |
|
|
|
$street_id = $address['street_id'] ?? ''; |
|
|
|
$street_id = $address['street_id'] ?? ''; |
|
|
|
$area_ids = [$province_id, $city_id, $district_id, $street_id]; |
|
|
|
$area_ids = [$province_id, $city_id, $district_id, $street_id]; |
|
|
|
$area_ids = array_values(array_filter($area_ids)); |
|
|
|
$area_ids = array_values(array_filter($area_ids)); |
|
|
|
|
|
|
|
|
|
|
|
$area_roles = Partner::getDB() |
|
|
|
$area_roles = Partner::getDB() |
|
|
|
->where('is_area', 1) |
|
|
|
->where('is_area', 1) |
|
|
|
->where('status', 1) |
|
|
|
->where('status', 1) |
|
|
|
->whereNotIn('type', [3, 4]) |
|
|
|
->whereNotIn('type', [3, 4]) |
|
|
|
->whereIn('area_id', $area_ids) |
|
|
|
->whereIn('area_id', $area_ids) |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$role_ids = array_column($area_roles, null, 'id'); |
|
|
|
|
|
|
|
$trade_trade_data = array_column($area_roles, 'id'); |
|
|
|
$role_ids = array_column($area_roles, 'id'); |
|
|
|
|
|
|
|
$trade_trade_data = array_column($area_roles, null,'id'); |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
$user_list = User::getDB()->alias('u') |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->leftJoin('UserPartner p', 'u.uid = p.uid') |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->whereIn('p.partner_id', $role_ids) |
|
|
|
->where('uid', '<>', $data['uid']) |
|
|
|
->where('u.uid', '<>', $data['uid']) |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
->field('u.*,p.partner_id') |
|
|
|
->select()->toArray(); |
|
|
|
->select()->toArray(); |
|
|
|
$user_count = count($user_list); |
|
|
|
$user_count = count($user_list); |
|
|
@ -247,7 +262,7 @@ class OrderPartnerJob implements JobInterface |
|
|
|
'types_of' => 1, |
|
|
|
'types_of' => 1, |
|
|
|
'num' => $role_value, |
|
|
|
'num' => $role_value, |
|
|
|
'ctime' => date('Y-m-d H:i:s'), |
|
|
|
'ctime' => date('Y-m-d H:i:s'), |
|
|
|
'memo' => '订单消费行业贡献值', |
|
|
|
'memo' => '订单消费区域贡献值', |
|
|
|
'user_id' => $auv['uid'], |
|
|
|
'user_id' => $auv['uid'], |
|
|
|
]; |
|
|
|
]; |
|
|
|
} |
|
|
|
} |
|
|
@ -255,13 +270,52 @@ class OrderPartnerJob implements JobInterface |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
//查询通用角色 |
|
|
|
//查询通用角色 |
|
|
|
|
|
|
|
$common_roles = Partner::getDB() |
|
|
|
|
|
|
|
->where('type', 1) |
|
|
|
|
|
|
|
->where('is_area', 0) |
|
|
|
|
|
|
|
->where('status', 1) |
|
|
|
|
|
|
|
->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']) |
|
|
|
|
|
|
|
->select(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!empty($user_list)){ |
|
|
|
|
|
|
|
$user_list = $user_list->toArray(); |
|
|
|
|
|
|
|
$user_count = count($user_list); |
|
|
|
|
|
|
|
foreach ($user_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(); |
|
|
|
|
|
|
|
$user->all_value = bcadd($user->all_value, $role_value, 2); |
|
|
|
|
|
|
|
$user->save(); |
|
|
|
|
|
|
|
$user_log_data[] = [ |
|
|
|
|
|
|
|
'type' => 5, |
|
|
|
|
|
|
|
'types_of' => 1, |
|
|
|
|
|
|
|
'num' => $role_value, |
|
|
|
|
|
|
|
'ctime' => date('Y-m-d H:i:s'), |
|
|
|
|
|
|
|
'memo' => '订单消费通用贡献值', |
|
|
|
|
|
|
|
'user_id' => $cuv['uid'], |
|
|
|
|
|
|
|
]; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//批量增加用户贡献值日志 |
|
|
|
//批量增加用户贡献值日志 |
|
|
|
ValueContributionLog::getDB()->insertAll($user_log_data); |
|
|
|
ValueContributionLog::getDB()->insertAll($user_log_data); |
|
|
|
|
|
|
|
echo 'ok'; |
|
|
|
} catch (\Exception $e) { |
|
|
|
} catch (\Exception $e) { |
|
|
|
Log::info('订单角色贡献值处理失败; error : ' . $e->getMessage()); |
|
|
|
Log::info('订单角色贡献值处理失败; error : ' . $e->getMessage()); |
|
|
|
} |
|
|
|
} |
|
|
|
$job->delete(); |
|
|
|
$job->delete(); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function failed($data) |
|
|
|
public function failed($data) |
|
|
|