diff --git a/app/controller/api/Auth.php b/app/controller/api/Auth.php index a65f44c..4dc3056 100644 --- a/app/controller/api/Auth.php +++ b/app/controller/api/Auth.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' => '', diff --git a/crmeb/jobs/OrderPartnerJob.php b/crmeb/jobs/OrderPartnerJob.php index d2a709b..cf7f4d8 100644 --- a/crmeb/jobs/OrderPartnerJob.php +++ b/crmeb/jobs/OrderPartnerJob.php @@ -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,32 +145,34 @@ 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); - - $user = User::getDB()->where('uid', $data['uid'])->find(); - $user->all_value = bcadd($user->all_value, $user_value, 2); - //增加生命值 - if(!empty($user_hb)){ - $user->hp_value = bcadd($user->hp_value, $user_hb, 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)) { + $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)) { @@ -191,21 +194,24 @@ 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 (empty($buv['uid'])) { - $user = User::getDB()->where('uid', $admin_id)->find();; - } else { - $user = User::getDB()->where('uid', $buv['uid'])->find(); + if ($role_value > 0) { + if (empty($buv['uid'])) { + $user = User::getDB()->where('uid', $admin_id)->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']] ?? []; if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); - if (empty($tuv['uid'])) { - $user = User::getDB()->where('uid', $admin_id)->find();; - } else { - $user = User::getDB()->where('uid', $tuv['uid'])->find(); + if ($role_value) { + if (empty($tuv['uid'])) { + $user = User::getDB()->where('uid', $admin_id)->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']] ?? []; if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); - if (empty($auv['uid'])) { - $user = User::getDB()->where('uid', $admin_id)->find();; - } else { - $user = User::getDB()->where('uid', $auv['uid'])->find(); + if ($role_value > 0) { + if (empty($auv['uid'])) { + $user = User::getDB()->where('uid', $admin_id)->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 = []; 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,21 +337,24 @@ 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 (empty($ruv['uid'])) { - $user = User::getDB()->where('uid', $admin_id)->find();; - } else { - $user = User::getDB()->where('uid', $ruv['uid'])->find(); + if ($role_value > 0) { + if (empty($ruv['uid'])) { + $user = User::getDB()->where('uid', $admin_id)->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']] ?? []; if (!empty($role_data)) { $role_value = bcmul($total_price, $role_data['ratio'] / 100, 2); - if (empty($cuv['uid'])) { - $user = User::getDB()->where('uid', $admin_id)->find();; - } else { - $user = User::getDB()->where('uid', $cuv['uid'])->find(); + if ($role_value > 0) { + if (empty($cuv['uid'])) { + $user = User::getDB()->where('uid', $admin_id)->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); 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) { //读取用户当前贡献值增长率