1748153932 1 year ago
commit f876ca6025
  1. 5
      app/controller/api/Auth.php
  2. 49
      crmeb/jobs/OrderPartnerJob.php

@ -58,10 +58,11 @@ class Auth extends BaseController
{
public function test()
{
$order = StoreOrder::getDB()->where('order_id', 9)->find()->toArray();
echo '11';exit;
$order = StoreOrder::getDB()->where('order_id', 64)->find()->toArray();
$job = new OrderPartnerJob();
$res = $job->fire($order);
print_r($res);exit;
// $data = [
// 'tempId' => '',
// 'id' => '',

@ -33,8 +33,9 @@ use app\common\model\store\order\StoreOrderLevel;
class OrderPartnerJob implements JobInterface
{
public function fire($job, $data)
public function fire($job,$data)
{
$job->delete();
file_put_contents('/tmp/debug_partner', '开始处理贡献值订单:' . var_export($data, 1), 8);
try {
//初始化贡献值
@ -144,21 +145,21 @@ class OrderPartnerJob implements JobInterface
//读取消费等级增加生命值
$user_hb = 0;
$order_level = StoreOrderLevel::getDB()->order('level asc')->select();
if(!empty($order_level)){
foreach($order_level as $k=>$v){
if($total_price >= $v->min_price){
$user_hb = bcmul($total_price,$v->pay_hp,2);
if (!empty($order_level)) {
foreach ($order_level as $k => $v) {
if ($total_price >= $v->min_price) {
$user_hb = bcmul($total_price, $v->pay_hp, 2);
break;
}
}
}
//订单角色贡献值-30%
$user_value = bcmul($total_price, 0.3, 2);
if ($user_value > 0) {
$user = User::getDB()->where('uid', $data['uid'])->find();
$user->all_value = bcadd($user->all_value, $user_value, 2);
//增加生命值
if(!empty($user_hb)){
if (!empty($user_hb)) {
$user->hp_value = bcadd($user->hp_value, $user_hb, 2);
}
$user->save();
@ -170,6 +171,8 @@ class OrderPartnerJob implements JobInterface
'memo' => '订单消费贡献值',
'user_id' => $data['uid'],
];
}
//处理合作人角色是否包含此商品品牌
if (!empty($brand_ids)) {
@ -191,6 +194,7 @@ class OrderPartnerJob implements JobInterface
$role_data = $brand_brand_data[$buv['partner_id']] ?? [];
if (!empty($role_data)) {
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2);
if ($role_value > 0) {
if (empty($buv['uid'])) {
$user = User::getDB()->where('uid', $admin_id)->find();;
} else {
@ -207,6 +211,8 @@ class OrderPartnerJob implements JobInterface
'user_id' => $buv['uid'],
];
}
}
}
}
//处理合作人角色是否包含此商品行业
@ -229,6 +235,7 @@ class OrderPartnerJob implements JobInterface
$role_data = $trade_trade_data[$tuv['partner_id']] ?? [];
if (!empty($role_data)) {
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2);
if ($role_value) {
if (empty($tuv['uid'])) {
$user = User::getDB()->where('uid', $admin_id)->find();;
} else {
@ -247,6 +254,7 @@ class OrderPartnerJob implements JobInterface
}
}
}
}
//查询所属区域角色
if (!empty($address)) {
$province_id = $address['province_id'] ?? '';
@ -275,6 +283,7 @@ class OrderPartnerJob implements JobInterface
$role_data = $trade_trade_data[$auv['partner_id']] ?? [];
if (!empty($role_data)) {
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2);
if ($role_value > 0) {
if (empty($auv['uid'])) {
$user = User::getDB()->where('uid', $admin_id)->find();;
} else {
@ -291,6 +300,8 @@ class OrderPartnerJob implements JobInterface
'user_id' => $auv['uid'],
];
}
}
}
}
//查询大区角色
@ -298,16 +309,22 @@ class OrderPartnerJob implements JobInterface
$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)){
if (!empty($region_ids)) {
$region_roles = Partner::getDB()
->where('status', 1)
->whereNotIn('type', 2)
->whereNotIn('type', [2])
->whereIn('region_id', $region_ids)
->select()->toArray();
->select();
if (!empty($region_ids)) {
$region_roles = $region_roles->toArray();
} else {
$region_roles = [];
}
$role_ids = array_column($region_roles, 'id');
$regin_trade_data = array_column($region_roles, null, 'id');
@ -320,6 +337,7 @@ class OrderPartnerJob implements JobInterface
$role_data = $regin_trade_data[$ruv['partner_id']] ?? [];
if (!empty($role_data)) {
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2);
if ($role_value > 0) {
if (empty($ruv['uid'])) {
$user = User::getDB()->where('uid', $admin_id)->find();;
} else {
@ -336,6 +354,8 @@ class OrderPartnerJob implements JobInterface
'user_id' => $ruv['uid'],
];
}
}
}
}
}
@ -359,6 +379,7 @@ class OrderPartnerJob implements JobInterface
$role_data = $common_trade_data[$cuv['partner_id']] ?? [];
if (!empty($role_data)) {
$role_value = bcmul($total_price, $role_data['ratio'] / 100, 2);
if ($role_value > 0) {
if (empty($cuv['uid'])) {
$user = User::getDB()->where('uid', $admin_id)->find();;
} else {
@ -375,6 +396,8 @@ class OrderPartnerJob implements JobInterface
'user_id' => $cuv['uid'],
];
}
}
}
}
@ -382,9 +405,9 @@ class OrderPartnerJob implements JobInterface
ValueContributionLog::getDB()->insertAll($user_log_data);
echo 'ok';
} catch (\Exception $e) {
Log::info('订单角色贡献值处理失败; error : ' . $e->getMessage());
file_put_contents('/tmp/error_partner', '订单角色贡献值处理失败:' . var_export($e->getMessage(), 1), 8);
}
$job->delete();
}
@ -394,7 +417,7 @@ class OrderPartnerJob implements JobInterface
}
//贡献值转增值积分
public function addValue($uid,$num,$user_start)
public function addValue($uid, $num, $user_start)
{
//读取用户当前贡献值增长率

Loading…
Cancel
Save