parent
fc4cb9a9ed
commit
60bcb3aa10
|
|
@ -173,10 +173,10 @@ class OrderCreatedListener
|
||||||
// 计算文创等级分红
|
// 计算文创等级分红
|
||||||
$culturalAgent = $agent;
|
$culturalAgent = $agent;
|
||||||
$culturalAgent['agent']['agent_level'] = $culturalAgent['agent']['cultural_level'];
|
$culturalAgent['agent']['agent_level'] = $culturalAgent['agent']['cultural_level'];
|
||||||
$culturalCommission = CommissionOrderService::getCommission($this->order, $culturalAgent, $this->set);
|
$culturalCommission = CommissionOrderService::getCommission($this->order, $culturalAgent['agent'], $this->set,1);
|
||||||
if ($culturalCommission['commission'] > 0) $this->addCommissionOrder($culturalCommission, $culturalAgent, $hierarchy, $level, 1);
|
|
||||||
else \Log::debug('订单分销没有佣金 - 文创等级'.$order_id,$agent['agent']);
|
|
||||||
|
|
||||||
|
if ($culturalCommission['commission'] > 0) $this->addCommissionOrder($culturalCommission, $culturalAgent, $hierarchy, $level, 1);
|
||||||
|
else \Log::debug('订单分销没有佣金 - 文创等级'.$order_id,$culturalAgent['agent']);
|
||||||
|
|
||||||
// 额外分红
|
// 额外分红
|
||||||
if (!$is_additiona_commission) {
|
if (!$is_additiona_commission) {
|
||||||
|
|
|
||||||
|
|
@ -9,9 +9,11 @@ use app\common\facades\Setting;
|
||||||
use app\common\helpers\PaginationHelper;
|
use app\common\helpers\PaginationHelper;
|
||||||
use app\common\helpers\Url;
|
use app\common\helpers\Url;
|
||||||
use app\common\models\Member;
|
use app\common\models\Member;
|
||||||
|
use app\common\models\Order;
|
||||||
use app\common\services\ExportService;
|
use app\common\services\ExportService;
|
||||||
use app\common\services\Session;
|
use app\common\services\Session;
|
||||||
use app\exports\FromArray;
|
use app\exports\FromArray;
|
||||||
|
use Yunshop\Commission\Listener\OrderCreatedListener;
|
||||||
use Yunshop\Commission\models\AgentLevel;
|
use Yunshop\Commission\models\AgentLevel;
|
||||||
use Yunshop\Commission\models\Agents;
|
use Yunshop\Commission\models\Agents;
|
||||||
use Yunshop\Commission\models\Log;
|
use Yunshop\Commission\models\Log;
|
||||||
|
|
@ -369,4 +371,10 @@ class AgentController extends BaseController
|
||||||
// });
|
// });
|
||||||
// })->export('xls');
|
// })->export('xls');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function test(){
|
||||||
|
|
||||||
|
|
||||||
|
// (new OrderCreatedListener())->handler(Order::find(213));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -180,30 +180,8 @@ class CommissionOrderService
|
||||||
if ($storeSetting) {
|
if ($storeSetting) {
|
||||||
$set = $storeSetting->value;
|
$set = $storeSetting->value;
|
||||||
if (empty($agent['agent_level'])) {
|
if (empty($agent['agent_level'])) {
|
||||||
|
|
||||||
/*Operation::create([
|
|
||||||
'uniacid' => $orderModel->uniacid,
|
|
||||||
'order_id' => $orderModel->id,
|
|
||||||
'uid' => $agent['member_id'],
|
|
||||||
'buy_uid' => $orderModel->uid,
|
|
||||||
'level_id' => $agent['agent_level_id'],
|
|
||||||
'ratio' => $set[$agent['hierarchy']],
|
|
||||||
'content' => "没有分销等级,返回门店默认比例[{$set[$agent['hierarchy']]}]"
|
|
||||||
]);*/
|
|
||||||
|
|
||||||
return $set[$agent['hierarchy']];
|
return $set[$agent['hierarchy']];
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/*Operation::create([
|
|
||||||
'uniacid' => $orderModel->uniacid,
|
|
||||||
'order_id' => $orderModel->id,
|
|
||||||
'uid' => $agent['member_id'],
|
|
||||||
'buy_uid' => $orderModel->uid,
|
|
||||||
'level_id' => $agent['agent_level_id'],
|
|
||||||
'ratio' => $set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate'],
|
|
||||||
'content' => "返回门店默认等级比例[{$set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate']}]"
|
|
||||||
]);*/
|
|
||||||
|
|
||||||
return $set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate'];
|
return $set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -214,56 +192,16 @@ class CommissionOrderService
|
||||||
if ($hotelSetting) {
|
if ($hotelSetting) {
|
||||||
$set = $hotelSetting->value;
|
$set = $hotelSetting->value;
|
||||||
if (empty($agent['agent_level'])) {
|
if (empty($agent['agent_level'])) {
|
||||||
|
|
||||||
/*Operation::create([
|
|
||||||
'uniacid' => $orderModel->uniacid,
|
|
||||||
'order_id' => $orderModel->id,
|
|
||||||
'uid' => $agent['member_id'],
|
|
||||||
'buy_uid' => $orderModel->uid,
|
|
||||||
'level_id' => $agent['agent_level_id'],
|
|
||||||
'ratio' => $set[$agent['hierarchy']],
|
|
||||||
'content' => "没有分销等级,返回门店默认比例[{$set[$agent['hierarchy']]}]"
|
|
||||||
]);*/
|
|
||||||
|
|
||||||
return $set[$agent['hierarchy']];
|
return $set[$agent['hierarchy']];
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
/*Operation::create([
|
|
||||||
'uniacid' => $orderModel->uniacid,
|
|
||||||
'order_id' => $orderModel->id,
|
|
||||||
'uid' => $agent['member_id'],
|
|
||||||
'buy_uid' => $orderModel->uid,
|
|
||||||
'level_id' => $agent['agent_level_id'],
|
|
||||||
'ratio' => $set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate'],
|
|
||||||
'content' => "返回门店默认等级比例[{$set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate']}]"
|
|
||||||
]);*/
|
|
||||||
|
|
||||||
return $set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate'];
|
return $set['rule']['level_' . $agent['agent_level']['id']][$agent['hierarchy'] . '_rate'];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (empty($agent['agent_level'])) {
|
if (empty($agent['agent_level'])) {
|
||||||
/*Operation::create([
|
|
||||||
'uniacid' => $orderModel->uniacid,
|
|
||||||
'order_id' => $orderModel->id,
|
|
||||||
'uid' => $agent['member_id'],
|
|
||||||
'buy_uid' => $orderModel->uid,
|
|
||||||
'level_id' => $agent['agent_level_id'],
|
|
||||||
'ratio' => $set[$agent['hierarchy']],
|
|
||||||
'content' => "没有分销等级,返回分销默认比例[{$set[$agent['hierarchy']]}]"
|
|
||||||
]);*/
|
|
||||||
return $set[$agent['hierarchy']];
|
return $set[$agent['hierarchy']];
|
||||||
} else {
|
} else {
|
||||||
/*Operation::create([
|
|
||||||
'uniacid' => $orderModel->uniacid,
|
|
||||||
'order_id' => $orderModel->id,
|
|
||||||
'uid' => $agent['member_id'],
|
|
||||||
'buy_uid' => $orderModel->uid,
|
|
||||||
'level_id' => $agent['agent_level_id'],
|
|
||||||
'ratio' => $agent['agent_level'][$agent['hierarchy']],
|
|
||||||
'content' => "返回分销等级比例[{$agent['agent_level'][$agent['hierarchy']]}]"
|
|
||||||
]);*/
|
|
||||||
return $agent['agent_level'][$agent['hierarchy']];
|
return $agent['agent_level'][$agent['hierarchy']];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -504,7 +442,7 @@ class CommissionOrderService
|
||||||
* @return array
|
* @return array
|
||||||
* 获取佣金 计算金额 计算公式 佣金比例 分销订单商品等数据
|
* 获取佣金 计算金额 计算公式 佣金比例 分销订单商品等数据
|
||||||
*/
|
*/
|
||||||
public static function getCommission($orderModel, $agent, $set){
|
public static function getCommission($orderModel, $agent, $set, $levelType = 0){
|
||||||
$orderGoods = $orderModel->hasManyOrderGoods;
|
$orderGoods = $orderModel->hasManyOrderGoods;
|
||||||
$commissionAmount = 0;
|
$commissionAmount = 0;
|
||||||
$formula = '';
|
$formula = '';
|
||||||
|
|
@ -536,6 +474,15 @@ class CommissionOrderService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//临时解决分销等级删除后,分销订单不能使用默认等级计算问题
|
||||||
|
if ($agent['cultural_level_id']) {
|
||||||
|
$agentLevelModel = AgentLevel::uniacid()->where('id', $agent['cultural_level_id'])->first();
|
||||||
|
if (!$agentLevelModel) {
|
||||||
|
$agent['cultural_level_id'] = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
foreach ($orderGoods as $key => $og) {
|
foreach ($orderGoods as $key => $og) {
|
||||||
$payment_amount = $og['payment_amount'];
|
$payment_amount = $og['payment_amount'];
|
||||||
|
|
@ -586,7 +533,7 @@ class CommissionOrderService
|
||||||
// $commissionAmount += $amount_dividend; //分佣计算金额
|
// $commissionAmount += $amount_dividend; //分佣计算金额
|
||||||
// $formula .= '+'.$countAmount['method'];//分佣计算方式
|
// $formula .= '+'.$countAmount['method'];//分佣计算方式
|
||||||
$rule = unserialize($commissionGoods['rule']);
|
$rule = unserialize($commissionGoods['rule']);
|
||||||
$agentRule = $rule['level_' . $agent['agent_level_id']];
|
$agentRule = $rule['level_' . ($levelType == 1 ? $agent['cultural_level_id'] : $agent['agent_level_id'])];
|
||||||
if ($agentRule[$agent['hierarchy'] . '_rate'] > 0) {
|
if ($agentRule[$agent['hierarchy'] . '_rate'] > 0) {
|
||||||
$is_general = $countAmount['is_general'];
|
$is_general = $countAmount['is_general'];
|
||||||
$commissionRate = $agentRule[$agent['hierarchy'] . '_rate'];
|
$commissionRate = $agentRule[$agent['hierarchy'] . '_rate'];
|
||||||
|
|
|
||||||
|
|
@ -121,6 +121,7 @@ class CulturalSpace extends BaseModel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 数据操作
|
// 数据操作
|
||||||
|
|
||||||
if (count($changeList) > 0) {
|
if (count($changeList) > 0) {
|
||||||
$newMemberList = [];
|
$newMemberList = [];
|
||||||
foreach($memberList as $key => $val){
|
foreach($memberList as $key => $val){
|
||||||
|
|
@ -135,9 +136,6 @@ class CulturalSpace extends BaseModel
|
||||||
|
|
||||||
DB::commit();
|
DB::commit();
|
||||||
} catch (\Exception $e) {
|
} catch (\Exception $e) {
|
||||||
|
|
||||||
|
|
||||||
debug($e->getMessage());
|
|
||||||
\Log::debug('文创空间 - 购买商品奖励贡献值 - 错误抛出', $e->getMessage());
|
\Log::debug('文创空间 - 购买商品奖励贡献值 - 错误抛出', $e->getMessage());
|
||||||
DB::rollBack();
|
DB::rollBack();
|
||||||
}
|
}
|
||||||
|
|
@ -291,27 +289,24 @@ class CulturalSpace extends BaseModel
|
||||||
->toArray();
|
->toArray();
|
||||||
// 循环处理:不存在则添加,并且赋值默认值;存在则使用已经存在的信息
|
// 循环处理:不存在则添加,并且赋值默认值;存在则使用已经存在的信息
|
||||||
$memberList = [];
|
$memberList = [];
|
||||||
$insertData = [];
|
|
||||||
foreach ($ids as $userId) {
|
foreach ($ids as $userId) {
|
||||||
if ($list[$userId]) {
|
if ($list[$userId]) {
|
||||||
// 存在
|
// 存在
|
||||||
$memberList[$userId] = $list[$userId];
|
$memberList[$userId] = $list[$userId];
|
||||||
} else {
|
} else {
|
||||||
// 不存在
|
// 不存在
|
||||||
$insertData[] = [
|
$id = self::insertGetId([
|
||||||
'uniacid' => \YunShop::app()->uniacid,
|
'uniacid' => \YunShop::app()->uniacid,
|
||||||
'uid' => $userId,
|
'uid' => $userId,
|
||||||
];
|
]);
|
||||||
$memberList[$userId] = [
|
$memberList[$userId] = [
|
||||||
'uniacid' => \YunShop::app()->uniacid,
|
|
||||||
'uid' => $userId,
|
'uid' => $userId,
|
||||||
'contribution' => 0
|
'contribution' => 0,
|
||||||
|
'id' => $id
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($insertData) self::insert($insertData);
|
|
||||||
|
|
||||||
return $memberList;
|
return $memberList;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue