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

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

@ -33,8 +33,9 @@ use app\common\model\store\order\StoreOrderLevel;
class OrderPartnerJob implements JobInterface 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); file_put_contents('/tmp/debug_partner', '开始处理贡献值订单:' . var_export($data, 1), 8);
try { try {
//初始化贡献值 //初始化贡献值
@ -144,32 +145,34 @@ class OrderPartnerJob implements JobInterface
//读取消费等级增加生命值 //读取消费等级增加生命值
$user_hb = 0; $user_hb = 0;
$order_level = StoreOrderLevel::getDB()->order('level asc')->select(); $order_level = StoreOrderLevel::getDB()->order('level asc')->select();
if(!empty($order_level)){ if (!empty($order_level)) {
foreach($order_level as $k=>$v){ foreach ($order_level as $k => $v) {
if($total_price >= $v->min_price){ if ($total_price >= $v->min_price) {
$user_hb = bcmul($total_price,$v->pay_hp,2); $user_hb = bcmul($total_price, $v->pay_hp, 2);
break; break;
} }
} }
} }
//订单角色贡献值-30% //订单角色贡献值-30%
$user_value = bcmul($total_price, 0.3, 2); $user_value = bcmul($total_price, 0.3, 2);
if ($user_value > 0) {
$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);
//增加生命值 //增加生命值
if(!empty($user_hb)){ if (!empty($user_hb)) {
$user->hp_value = bcadd($user->hp_value, $user_hb, 2); $user->hp_value = bcadd($user->hp_value, $user_hb, 2);
}
$user->save();
$user_log_data[] = [
'type' => 6,
'types_of' => 1,
'num' => $user_value,
'ctime' => date('Y-m-d H:i:s'),
'memo' => '订单消费贡献值',
'user_id' => $data['uid'],
];
} }
$user->save();
$user_log_data[] = [
'type' => 6,
'types_of' => 1,
'num' => $user_value,
'ctime' => date('Y-m-d H:i:s'),
'memo' => '订单消费贡献值',
'user_id' => $data['uid'],
];
//处理合作人角色是否包含此商品品牌 //处理合作人角色是否包含此商品品牌
if (!empty($brand_ids)) { if (!empty($brand_ids)) {
@ -191,21 +194,24 @@ class OrderPartnerJob implements JobInterface
$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);
if (empty($buv['uid'])) { if ($role_value > 0) {
$user = User::getDB()->where('uid', $admin_id)->find();; if (empty($buv['uid'])) {
} else { $user = User::getDB()->where('uid', $admin_id)->find();;
$user = User::getDB()->where('uid', $buv['uid'])->find(); } else {
$user = User::getDB()->where('uid', $buv['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' => $buv['uid'],
];
} }
$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' => $buv['uid'],
];
} }
} }
} }
@ -229,21 +235,23 @@ class OrderPartnerJob implements JobInterface
$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);
if (empty($tuv['uid'])) { if ($role_value) {
$user = User::getDB()->where('uid', $admin_id)->find();; if (empty($tuv['uid'])) {
} else { $user = User::getDB()->where('uid', $admin_id)->find();;
$user = User::getDB()->where('uid', $tuv['uid'])->find(); } else {
$user = User::getDB()->where('uid', $tuv['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' => $tuv['uid'],
];
} }
$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' => $tuv['uid'],
];
} }
} }
} }
@ -275,21 +283,24 @@ class OrderPartnerJob implements JobInterface
$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);
if (empty($auv['uid'])) { if ($role_value > 0) {
$user = User::getDB()->where('uid', $admin_id)->find();; if (empty($auv['uid'])) {
} else { $user = User::getDB()->where('uid', $admin_id)->find();;
$user = User::getDB()->where('uid', $auv['uid'])->find(); } else {
$user = User::getDB()->where('uid', $auv['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' => $auv['uid'],
];
} }
$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' => $auv['uid'],
];
} }
} }
} }
@ -298,16 +309,22 @@ class OrderPartnerJob implements JobInterface
$region_ids = []; $region_ids = [];
if (!empty($province_id) && !empty($region_list)) { if (!empty($province_id) && !empty($region_list)) {
foreach ($region_list as $rv) { foreach ($region_list as $rv) {
if (in_array($province_id, $rv['province_ids'])) { if (in_array($province_id, $rv['province_ids'])) {
$region_ids[] = $rv['id']; $region_ids[] = $rv['id'];
} }
} }
if(!empty($region_ids)){ if (!empty($region_ids)) {
$region_roles = Partner::getDB() $region_roles = Partner::getDB()
->where('status', 1) ->where('status', 1)
->whereNotIn('type', 2) ->whereNotIn('type', [2])
->whereIn('region_id', $region_ids) ->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'); $role_ids = array_column($region_roles, 'id');
$regin_trade_data = array_column($region_roles, null, 'id'); $regin_trade_data = array_column($region_roles, null, 'id');
@ -320,21 +337,24 @@ class OrderPartnerJob implements JobInterface
$role_data = $regin_trade_data[$ruv['partner_id']] ?? []; $role_data = $regin_trade_data[$ruv['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);
if (empty($ruv['uid'])) { if ($role_value > 0) {
$user = User::getDB()->where('uid', $admin_id)->find();; if (empty($ruv['uid'])) {
} else { $user = User::getDB()->where('uid', $admin_id)->find();;
$user = User::getDB()->where('uid', $ruv['uid'])->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'],
];
} }
$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'],
];
} }
} }
} }
@ -359,21 +379,24 @@ class OrderPartnerJob implements JobInterface
$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);
if (empty($cuv['uid'])) { if ($role_value > 0) {
$user = User::getDB()->where('uid', $admin_id)->find();; if (empty($cuv['uid'])) {
} else { $user = User::getDB()->where('uid', $admin_id)->find();;
$user = User::getDB()->where('uid', $cuv['uid'])->find(); } else {
$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'],
];
} }
$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'],
];
} }
} }
} }
@ -382,9 +405,9 @@ class OrderPartnerJob implements JobInterface
ValueContributionLog::getDB()->insertAll($user_log_data); ValueContributionLog::getDB()->insertAll($user_log_data);
echo 'ok'; echo 'ok';
} catch (\Exception $e) { } 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