添加:经销商等级分为普通经销商和文创经销商

添加:普通经销商提成和文创经销商补贴分开计算,如果同时存在两种身份则可以同时领取提成和补贴
添加:经销商提成修改为普通添加和文创补贴。文创补贴只能在下个月才能申请提现
This commit is contained in:
wuhui_zzw 2023-11-04 17:01:17 +08:00
parent a38500fedf
commit 2a992b56c7
17 changed files with 686 additions and 332 deletions

View File

@ -95,15 +95,10 @@ class IncomeWithdrawController extends ApiController
$all_withdraw_income = 0;
foreach ($income_config as $key => $income) {
//余额不计算 拍卖预付款不计算
if ($income['type'] == 'balance' || $income['type'] == 'auction_prepayment') {
continue;
}
if ($income['type'] == 'balance' || $income['type'] == 'auction_prepayment') continue;
//获取收入独立设置
$this->setIncomeSet($income['type']);
//附值手续费、劳务税(收银台不计算手续费、劳务税)
if ($income['type'] == 'kingtimes_provider' || $income['type'] == 'kingtimes_distributor') {
$this->poundage_rate = 0;
@ -123,7 +118,7 @@ class IncomeWithdrawController extends ApiController
$all_withdraw_income += $data['income'];
$income_data[] = $data;
}
//dd($income_data);
//增加经销商提现显示口爱心值
if ($income['type'] == 'teamDividend') {
@ -134,6 +129,7 @@ class IncomeWithdrawController extends ApiController
$deductionLove['deduction_value'] = $teamDividendWithdraw->deductionAmount($this->withdraw_amounts);
}
}
$withdraw_rich_text = WithdrawRichText::uniacid()->first() ?: [];
$data = [
'data' => $income_data,
@ -468,9 +464,31 @@ class IncomeWithdrawController extends ApiController
* 可提现数据 item
* @return array
*/
private function getItemData($key, $income)
{
$this->withdraw_amounts = $this->getIncomeModel()->where('incometable_type', $income['class'])->sum('amount');
private function getItemData($key, $income){
if($income['type'] == 'teamDividend'){
// 普通经销商佣金
$this->withdraw_amounts = Income::uniacid()
->leftJoin('yz_team_dividend','yz_team_dividend.id','yz_member_income.incometable_id')
->where('yz_member_income.incometable_type', $income['class'])
->where('yz_member_income.status', Income::STATUS_INITIAL)
->where('yz_member_income.member_id', \YunShop::app()->getMemberId())
->whereNotIn('yz_team_dividend.type', [4,5])
->sum('yz_member_income.amount');
}else if($income['type'] == 'teamDividendCultural'){
// 文创经销商补贴 仅查询一个月前的未提现金额
$startTime = strtotime(date("Y-m-1"));// 本月1号0点
$this->withdraw_amounts = Income::uniacid()
->leftJoin('yz_team_dividend','yz_team_dividend.id','yz_member_income.incometable_id')
->where('yz_member_income.incometable_type', $income['class'])
->where('yz_member_income.status', Income::STATUS_INITIAL)
->where('yz_member_income.member_id', \YunShop::app()->getMemberId())
->where('yz_member_income.created_at', '<',$startTime)
->whereIn('yz_team_dividend.type', [4,5])
->sum('yz_member_income.amount');
}else{
$this->withdraw_amounts = $this->getIncomeModel()->where('incometable_type', $income['class'])->sum('amount');
}
$can = $this->incomeIsCanWithdraw();
if ($income['type'] == 'commission') {
@ -552,6 +570,7 @@ class IncomeWithdrawController extends ApiController
$data['allow_withdrawal_date'] = implode(',',$withdrawDate);
}
return $data;
}

View File

@ -90,10 +90,14 @@ class OrderCreatedListener
$agents = GetAgentsService::index($set, $order->uid, $order->create_time);
\Log::debug('经销商-获取经销商',$agents);
foreach ($order->hasManyOrderGoods as $order_goods) {
// 普通经销商提成处理
$TeamReturnService->setData($order, $set, $buyMember, $order_goods, $agents);
$TeamReturnService->handle();
$this->totalDividend += $TeamReturnService->totalDividend;
// 文创津贴(补贴)处理
$TeamReturnService->setData($order, $set, $buyMember, $order_goods, $agents,1);
$TeamReturnService->handle();
$this->totalDividend += $TeamReturnService->totalDividend;
}
// 订单插件分红记录

View File

@ -13,6 +13,7 @@ use Yunshop\TeamDividend\Listener\OrderPaidListener;
use Yunshop\TeamDividend\Listener\OrderReceiveListener;
use Yunshop\TeamDividend\Listener\RegisterByAgentListener;
use Yunshop\TeamDividend\models\TeamDividendAgencyModel;
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
use Yunshop\TeamDividend\services\GoodsDetailService;
class PluginApplication extends \app\common\services\PluginApplication
@ -634,11 +635,16 @@ class PluginApplication extends \app\common\services\PluginApplication
]);
}
public function getIncomeItems()
{
public function getIncomeItems(){
$lang = \Setting::get('shop.lang', ['lang' => 'zh_cn'])['zh_cn']['team_dividend'];
$title = $lang['title'] ?: trans('Yunshop\TeamDividend::index.name');
$dividend = $lang['dividend'] ?: trans('Yunshop\TeamDividend::index.dividend');
$teamDividendCulturalName = '服务津贴';
$uid = \YunShop::app()->getMemberId();
if($uid > 0){
$culturalLevelId = TeamDividendAgencyModel::uniacid()->where('uid',$uid)->value('cultural_level_id');
$teamDividendCulturalName = TeamDividendLevelModel::uniacid()->where('id',$culturalLevelId)->value('cultural_level_name');
}
return [
'teamDividend' => [
'title' => $lang['title'] ?: trans('Yunshop\TeamDividend::index.title'),
@ -651,7 +657,13 @@ class PluginApplication extends \app\common\services\PluginApplication
'type' => 'storeManager',
'type_name' => '店长店补',
'class' => 'Yunshop\TeamDividend\Common\models\StoreManagerRecordModel',
]
],
'teamDividendCultural' => [
'title' => $teamDividendCulturalName,
'type' => 'teamDividendCultural',
'type_name' => $teamDividendCulturalName,
'class' => 'Yunshop\TeamDividend\models\TeamDividendModel',
],
];
}
@ -706,27 +718,12 @@ class PluginApplication extends \app\common\services\PluginApplication
*/
$events->subscribe(\Yunshop\TeamDividend\Listener\AreaDividendListener::class);
// 店长相关
\Event::listen('cron.collectJobs', function () {
// 每天0点30 执行一次店长信息统计
\Cron::add('Team-dividend-store-manager', '30 0 * * *', function () {
\Log::debug('--- 经销商 - 店长统计 - 开始 ----');
(new StoreManagerModel())->infoStatistics();
return;
});
// 每天1点30 执行一次店长信息统计
\Cron::add('Team-dividend-store-manager-settlement', '30 1 * * *', function () {
\Log::debug('--- 经销商 - 店长结算 - 开始 ----');
(new StoreManagerModel())->settlement();
return;
});
});
}
public function cronConfig()
{
public function cronConfig(){
\Event::listen('cron.collectJobs', function () {
// 经销商佣金结算 由10分钟执行一次修改为1分钟执行一次 2023-9-25
\Cron::add('Team-dividend', '*/1 * * * *', function () {
@ -758,6 +755,20 @@ class PluginApplication extends \app\common\services\PluginApplication
return;
});
});
// 店长相关
\Event::listen('cron.collectJobs', function () {
// 每天0点30 执行一次店长信息统计
\Cron::add('Team-dividend-store-manager', '30 0 * * *', function () {
\Log::debug('--- 经销商 - 店长统计 - 开始 ----');
(new StoreManagerModel())->infoStatistics();
return;
});
// 每天1点30 执行一次店长信息统计
\Cron::add('Team-dividend-store-manager-settlement', '30 1 * * *', function () {
\Log::debug('--- 经销商 - 店长结算 - 开始 ----');
(new StoreManagerModel())->settlement();
return;
});
});
}
}

View File

@ -10,14 +10,19 @@ use app\common\exceptions\ShopException;
use app\common\helpers\PaginationHelper;
use app\common\helpers\Url;
use app\common\models\Member;
use app\common\models\Order;
use Illuminate\Support\Facades\DB;
use Yunshop\TeamDividend\admin\models\TeamDividendAgencyModel;
use Yunshop\TeamDividend\jobs\NewUpgrateJob;
use Yunshop\TeamDividend\models\CodeRecordModel;
use Yunshop\TeamDividend\models\Log;
use Yunshop\TeamDividend\models\OrderModel;
use Yunshop\TeamDividend\models\TeamDividendLevelModel;
use Yunshop\TeamDividend\models\TeamDividendLevelUpgrade;
use Yunshop\TeamDividend\models\Uplog;
use Yunshop\TeamDividend\services\GetAgentsService;
use Yunshop\TeamDividend\services\ReturnConfig;
use Yunshop\TeamDividend\services\UpgradeService;
use Yunshop\TeamDividend\services\FundPoolAwardService;
use app\common\services\ExportService;
@ -146,35 +151,23 @@ class TeamAgencyController extends BaseController
$level_list = TeamDividendLevelModel::getList()->get();
if (\Request::getMethod() == 'POST') {
$agentData = \YunShop::request()->team;
// $agent = TeamDividendAgencyModel::getAgencyInfoByUid($agentData['uid']);
// if($agent){
// return $this->message('添加失败,此会员已是代理商', '', 'error');
// }
$agentData['uniacid'] = \YunShop::app()->uniacid;
$agentData['upgrade_at'] = time();
if((int)$agentData['level'] <= 0) return $this->message('添加失败,请选择代理等级!', '', 'error');
// 其他验证
$agency_model = new TeamDividendAgencyModel();
$agency_model->fill($agentData);
$validator = $agency_model->validator();
if ($validator->fails()) {
$this->error($validator->messages());
} else {
// $agency_model->uniacid = \YunShop::app()->uniacid;
// $agency_model->uid = $agentData['uid'];
// $agency_model->level = $agentData['level'];
// $agency_model->parent_id = floatval($agentData['parent_id']);
// $agency_model->relation = $agentData['relation'];
if ($agency_model->save()) {
// 升级后等级
$c_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find($agentData['level']);
// 升级前等级
$o_level = NULL;
// 升级日志
Uplog::addLog($agency_model, $o_level, $c_level);
//签合同
$data=[
'member_id'=>$agentData['uid'],
@ -186,14 +179,6 @@ class TeamAgencyController extends BaseController
if ($upgrade_set) {
$set = \Setting::get('plugin.team_dividend');
// if ($set['is_activation_code'] && isset($set['code_level'])) {
// $level_set = TeamDividendLevelModel::getLevelById($set['code_level']);
//
// (new UpgradeService())->senCode($agentData['uid'], $upgrade_set[0]->code_num, $set['code_level'], $level_set->level_name);
// \Log::debug('激活码');
// }
if ($set['is_activation_code'] && $upgrade_set[0]->code_num) {
$level_list = TeamDividendLevelModel::getList()->get();
$code_num = unserialize($upgrade_set[0]->code_num);
@ -355,25 +340,22 @@ class TeamAgencyController extends BaseController
public function change()
{
$id = \YunShop::request()->id;
$levelId = \YunShop::request()->value;
$agency = TeamDividendAgencyModel::find($id);
$level = $agency->level;
$agency->level = \YunShop::request()->value;
$agency->upgrade_at = time();
$levelInfo = TeamDividendLevelModel::find($levelId);
// 等级类型0=普通等级1=文创等级
if((int)$levelInfo->level_type == 1){
$level = $agency->cultural_level_id;
$agency->cultural_level_id = $levelId;
$agency->cultural_upgrade_at = time();
}else{
$level = $agency->level;
$agency->level = \YunShop::request()->value;
$agency->upgrade_at = time();
}
if ($agency->save()) {
// 经销商等级变动记录
/*Log::create([
'uid' => $agency->uid,
'befor_level_id' => $level,
'up_code' => '无',
'after_level_id' => $agency->level,
'remark' => '后台修改',
'level_ups' => []
]);*/
// 升级后等级
$c_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find($agency->level);
// 升级前等级
@ -390,7 +372,7 @@ class TeamAgencyController extends BaseController
$set = \Setting::get('plugin.team_dividend');
if ($set['is_activation_code'] && $upgrade_set[0]->code_num) {
$level_list = TeamDividendLevelModel::getList()->get();
$code_num = is_array($upgrade_set[0]->code_num) ? $upgrade_set[0]->code_num : unserialize($upgrade_set[0]->code_num) ? : [];
$code_num = (is_array($upgrade_set[0]->code_num) ? $upgrade_set[0]->code_num : unserialize($upgrade_set[0]->code_num)) ?: [];
foreach($level_list as $key => $level) {
if($code_num['level_'.$level->id]) {
(new UpgradeService())->senCode($agency->uid, $code_num['level_'.$level->id], $level->id, $level->level_name);
@ -406,4 +388,38 @@ class TeamAgencyController extends BaseController
}
}
public function test(){
//因为model偶尔会出现status异常的问题所以重新查询一遍
// $model = Order::with('hasManyOrderGoods')->find(84);
// $set = \Setting::get('plugin.team_dividend');
// (new NewUpgrateJob($model->uid, $set, $model->uniacid, TeamDividendLevelUpgrade::ORDER_PAY, $model))->handle();
// $order = Order::find(87);
// $TeamReturnService = ReturnConfig::getClass();
// if (app('plugins')->isEnabled('team-sideways')) debug('经销商订单创建终止:team-sideways');
// $set = $order->getSetting('plugin.team_dividend');
// if (!$set['is_team_dividend']) debug('是否开启经销商插件');
// $buyMember = $order->belongsToMember;
// $agents = GetAgentsService::index($set, $order->uid, $order->create_time);
// foreach ($order->hasManyOrderGoods as $order_goods) {
// // 普通经销商提成处理
// $TeamReturnService->setData($order, $set, $buyMember, $order_goods, $agents);
// $TeamReturnService->handle();
// $this->totalDividend += $TeamReturnService->totalDividend;
// // 文创津贴(补贴)处理
// $TeamReturnService->setData($order, $set, $buyMember, $order_goods, $agents,1);
// $TeamReturnService->handle();
// $this->totalDividend += $TeamReturnService->totalDividend;
// }
// debug(['总分红金额(包括津贴和补贴)'=>$this->totalDividend]);
debug("结束");
}
}

View File

@ -61,7 +61,7 @@ class TeamDividendLevelSetController extends BaseController
$validator = $team_dividend_level_model->validator();
if ($validator->fails()) {
$this->error($validator->messages());
return $this->message(reset(array_values($validator->messages()->getMessages())[0]),'', 'error');
} else {
if ($team_dividend_level_model->save()) {

View File

@ -67,46 +67,28 @@ class NewUpgrateJob implements ShouldQueue
$agents = $agentService->getAgents();
// 循环上级
foreach ($agents as $agent) {
// 循环等级
$this->eachLevelHandle($agent);
// 黑名单不升级
if ($agent['teamDividend']->is_black) continue;
// 升级处理
$this->eachLevelHandle($agent);// 普通等级升级处理
$this->eachCulturalLevelHandle($agent);// 文创等级升级处理
}
// 订单支付成功 处理权重值相关内容(因为需要兼容 用户不是经销商,但是成为经销商后当前订单如果存在赠送权重值,则需要同步赠送。因此只能在这里调用赠送操作
if($this->order_status == TeamDividendLevelUpgrade::ORDER_PAY && $this->order){
(new WeightValue())->giveInit($this->order);
}
}
/**
* @name 查询等级权重比当前大的等级集合
* @param $agent
* @return mixed
* @author
*/
public function eachLevelHandle($agent)
{
if ($agent['teamDividend']->is_black){ //黑名单不升级
return;
}
// $up_code = $this->setting['upgrate_type'] == 1 ? '或' : '与';
// 普通等级升级处理
public function eachLevelHandle($agent){
// 升级日志
$this->uplogService = new UplogService($agent['uid'], \YunShop::app()->uniacid, $agent['teamDividend']->level, $this->setting['upgrate_type']);
$this->uplogService->setUpCode(1);
// 原 升级 类
$oldUpgrade = new UpgradeService();
$upgradeLevels = $this->getUpgrateLevelsByWeight($agent);
// 经销商等级变动记录
/*$logModel = Log::create([
'uid' => $agent['uid'],
'befor_level_id' => $agent['teamDividend']->level,
'up_code' => $up_code,
'after_level_id' => '-1',
'remark' => '升级预备',
'level_ups' => []
]);*/
if ($upgradeLevels->isEmpty()) {
/*$logModel->remark = '没有更高的等级可以升级';
$logModel->save();*/
@ -347,6 +329,216 @@ class NewUpgrateJob implements ShouldQueue
$this->uplogService->resetCondition();
}
}
// 文创等级升级处理
public function eachCulturalLevelHandle($agent){
// 升级日志
$this->uplogService = new UplogService($agent['uid'], \YunShop::app()->uniacid, $agent['teamDividend']->cultural_level_id, $this->setting['upgrate_type']);
$this->uplogService->setUpCode(1);
// 原 升级 类
$oldUpgrade = new UpgradeService();
$upgradeLevels = $this->getUpgrateLevelsByWeight($agent,1);
if ($upgradeLevels->isEmpty()) return;
\Log::debug('经销商升级 - 文创等级 - 开始处理:');
// 默认可以升级
$upgradeRet = false;
foreach ($upgradeLevels as $level) {
// 判断:如果当前等级人数已经达到限制 则不升级(上限小于等于已存在数量 不能升级到该等级)
$hasNum = (int)Uplog::uniacid()->where('after_level_id',$level->id)->count(DB::raw('DISTINCT(uid)'));
if((int)$level->number_limit <= $hasNum && (int)$level->number_limit > 0) continue;
// 没有升级条件
if (!$level->hasOneUpgradeSet || !$level->hasOneUpgradeSet->parase) {
continue;
}
// 升级条件
$parase = unserialize($level->hasOneUpgradeSet->parase);
// 升级后的等级设置
$afterLevelSetting = $level->toArray();
$afterLevelSetting['has_one_upgrade_set']['parase'] = unserialize($afterLevelSetting['has_one_upgrade_set']['parase']);
$this->uplogService->setAfterLevelSetting($afterLevelSetting);
// 升级后的等级id
$this->uplogService->setAfterLevelId($level['id']);
// 升级条件 组
$upgradeGroup = $parase[0]['group'];
if ($this->order) {
if ($parase[0]['become'] != $this->order_status) {
continue;
}
}
if ($parase[0]['become'] == TeamDividendLevelUpgrade::ORDER_PAY) $order_status = Order::WAIT_SEND;
else $order_status = Order::COMPLETE;
if ($upgradeGroup) {
// 升级条件编号
$upgradeGroupSerialNumber = TeamDividendLevelUpgrade::getUpgradeIsSerialNumber();
foreach ($upgradeGroup as $group_item) {
// $group_item = 1001,1002,1003
if (!$group_item) continue;
$groupArr = explode(',', $group_item);
//todo 2019/7/4 改为false 不明白为什么要先赋值true
$upgradeGroupRet = false;
foreach ($groupArr as $value) {
// order_money_2
$typeName = $upgradeGroupSerialNumber[$value];
// 指定经销商等级
if ($value > 2000) {
$level_id = $value - 2000;
$typeName = 'level_' . $level_id . '_' . $parase[1]['level'][$level_id];
}
// 升级类
$upgrateService = new UpgrateConditionService($agent['uid'], $this->setting, $parase[1], $this->uniacid, $typeName, $order_status, $this->order, $this->uplogService);
// 升级方法
\Log::debug('===123分组方法名:' . $typeName);
$func = $this->getFunctionName($typeName);
if (!method_exists($upgrateService, $func)) {
continue;
}
$upgradeGroupRet = $upgrateService->$func();
// 条件组, 必须满足全部条件,不论设置的是或还是与
if (!$upgradeGroupRet) {
break;
}
}
$upgradeRet = $upgradeGroupRet;
// 条件 或
if ($this->setting['upgrate_type'] == 1) {
// 假 继续循环
if (!$upgradeGroupRet) continue;
// 真 跳出循环
break;
}
// 条件 与
if (!$upgradeGroupRet) {
$upgradeRet = $upgradeGroupRet;
break;
}
}
}
// 是否继续进行
$next = true;
if ($this->setting['upgrate_type'] == 1) {
// 如果升级方式为 或 $upgradeRet 为真 不继续
if ($upgradeRet) $next = false;
} else {
// 如果升级方式为 与 $upgradeRet 为假 不继续
if (!$upgradeRet && $upgradeGroup) $next = false;
}
// 升级条件 单个 与 升级结果为false
if ($next) {
$upgradeOnly = $parase[0];
$upgradeToLevel = $upgradeOnly['level'];
$upgradeToGroupLevel = $upgradeOnly['group_level'];
$upgradeToFirstChildLevel = $upgradeOnly['first_child_level'];
unset($upgradeOnly['become']);
unset($upgradeOnly['group']);
unset($upgradeOnly['level']);
unset($upgradeOnly['group_level']);
unset($upgradeOnly['first_child_level']);
foreach ($upgradeToLevel as $levelId => $ret) {
$upgradeOnly['level_' . $levelId . '_' . $parase[1]['level'][$levelId]] = '1';
}
foreach ($upgradeToGroupLevel as $levelId => $ret) {
$upgradeOnly['group_level_' . $levelId . '_' . $parase[1]['group_level'][$levelId]] = '1';
}
foreach ($upgradeToFirstChildLevel as $levelId => $ret) {
$upgradeOnly['first_child_level_' . $levelId . '_' . $parase[1]['first_child_level'][$levelId]] = '1';
}
// \Log::debug('经销商升级 - 继续 - 循环体:',$upgradeOnly);
foreach ($upgradeOnly as $upgrade => $only_item) {
// 升级类
$upgrateService = new UpgrateConditionService($agent['uid'], $this->setting, $parase[1], $this->uniacid, $upgrade, $order_status, $this->order, $this->uplogService);
// 升级方法
\Log::debug('===123单个方法名:' . $upgrade);
$func = $this->getFunctionName($upgrade);
// 升级条件 结果
if (!method_exists($upgrateService, $func)) {
continue;
}
$upgrateOnlyRet = $upgrateService->$func();
$upgradeRet = $upgrateOnlyRet;
// 升级 或
if ($this->setting['upgrate_type'] == 1) {
// 假 继续循环
if (!$upgrateOnlyRet) continue;
// 真 跳出循环
break;
}
// 升级 与
if (!$upgrateOnlyRet) break;
}
}
// 升级 退出
if ($upgradeRet) {
if (Redis::setnx('team_dividend_up' . $agent['uid'], 1)) {
Redis::expire('team_dividend_up' . $agent['uid'], 2);
} else {
sleep(2);
}
$agency = TeamDividendAgencyModel::getAgencyInfoByUid($agent['uid']);
if ($agency) {
$o_level = $agency->hasOneLevel->level_name;
$o_dividend_ratio = $agency->hasOneLevel->dividend_ratio;
//升级
$agency->cultural_level_id = $level->id;
$agency->cultural_upgrade_at = time();
$agency->save();
//升级通知
$oldUpgrade->agencyUpgradeNotify($agent['uid'], $o_level, $o_dividend_ratio, $level->id);
} else {
if (Member::find($agent['uid'])){
//会员升级为团队代理
$this->memberUpgradeToAgency($agent['uid'], $level->id,1);
//更新上级代理团队的下级代理总人数
$oldUpgrade->updateChildAgencyNumForParent($agent['uid']);
//团队代理人数升级
$oldUpgrade->upgradeForAgency($agent['uid']);
//成为团队代理通知
$oldUpgrade->becomeAgencyNotify($agent['uid']);
//新增下级团队代理通知
$member_model = Member::getUserInfos($agent['uid'])->first();
//新增下级团队代理通知
if ($member_model && !empty($member_model->yzMember->parent_id)) {
$oldUpgrade->newChileAgencyNotify($member_model->yzMember->parent_id, $agent['uid']);
}
}
}
// 升级日志
$this->uplogService->store();
// 记录
$agentData = [
'member_id' => $agent['uid'],
'created_at' => time(),
];
//监听经销商签合同
event(new \app\common\events\plugin\TeamDividendEvent($agentData));
//监听会员同步等级
$pluginLevel = [
'member_id' => $agent['uid'],
'level_id' => $level->id,
'plugin_type' => 3,
'self_up' => 1,
];
event(new \app\common\events\PluginLevelEvent($pluginLevel));
// 升级奖励
$this->upgradeAward($agent['uid'], $level);
// 奖励激活码
$this->awardCode($agent['uid'], $level);
// 升级后退出
break;
}
$this->uplogService->resetCondition();
}
}
/**
* @name 升级奖励激活码
@ -371,15 +563,8 @@ class NewUpgrateJob implements ShouldQueue
}
}
/**
* @name 升级奖励积分爱心值
* @param $uid
* @param $level
* @throws \app\common\exceptions\ShopException
* @author
*/
public function upgradeAward($uid, $level)
{
// 升级奖励
public function upgradeAward($uid, $level){
$isPluginGold = \YunShop::plugin()->get('love');//爱心值插件
$upgradeRewardPoint = $level->upgrade_reward_point;
$upgradeRewardGold = $level->upgrade_reward_gold;
@ -445,70 +630,60 @@ class NewUpgrateJob implements ShouldQueue
return Str::camel(preg_replace("/\\d+/", '', $str));
}
/**
* @name 获取当前会员的等级权重
* @param $agent
* @return int
* @author
*/
private function getLevelWeight($agent)
// 查询等级权重比当前大的等级集合 - 根据等级类型查询
private function getUpgrateLevelsByWeight($agent,$levelType = 0)
{
$levelWeight = 0;
if ($agent['teamDividend']) {
// 等级升级设置关联查询
$agentLevel = TeamDividendLevelModel::with([
'hasOneUpgradeSet',
])
->where('id', $agent['teamDividend']->level)
->first();
if ($agentLevel) {
$levelWeight = $agentLevel->level_weight;
// 升级前的等级设置
$agentLevel = $agentLevel->toArray();
$agentLevel['has_one_upgrade_set']['parase'] = unserialize($agentLevel['has_one_upgrade_set']['parase']);
$this->uplogService->setBeforeLevelSetting($agentLevel);
}
}
return $levelWeight;
}
/**
* @name 查询等级权重比当前大的等级集合
* @param $agent
* @return mixed
* @author
*/
private function getUpgrateLevelsByWeight($agent)
{
$levelWeight = $this->getLevelWeight($agent);
$levelWeight = $this->getLevelWeight($agent,$levelType);
$upgradeLevels = TeamDividendLevelModel::select()
->with(['hasOneUpgradeSet'])
->where('uniacid', $this->uniacid)
->where('level_weight', '>', $levelWeight)
->where('level_type','=',(int)$levelType)
->orderBy('level_weight', 'desc')
->get();
return $upgradeLevels;
}
/**
* @name 会员成为经销商
* @param $uid
* @param $levelId
* @author
*/
private function memberUpgradeToAgency($uid, $levelId)
{
// 获取当前会员的等级权重 - 根据等级类型查询
private function getLevelWeight($agent,$levelType){
$levelWeight = 0;
if($agent['teamDividend']){
// 等级升级设置关联查询
$agentLevel = TeamDividendLevelModel::with(['hasOneUpgradeSet'])
->when($levelType == 1,function($query) use ($agent){
// 文创等级
$query->where('id',$agent['teamDividend']->cultural_level_id);
},function($query) use ($agent){
// 普通等级
$query->where('id',$agent['teamDividend']->level);
})
->first();
if($agentLevel){
$levelWeight = $agentLevel->level_weight;
// 升级前的等级设置
$agentLevel = $agentLevel->toArray();
$agentLevel['has_one_upgrade_set']['parase'] = unserialize($agentLevel['has_one_upgrade_set']['parase']);
$this->uplogService->setBeforeLevelSetting($agentLevel);
}
}
return $levelWeight;
}
// 会员成为经销商
private function memberUpgradeToAgency($uid, $levelId,$levelType = 0){
$member = Member::getUserInfos($uid)->first();
TeamDividendAgencyModel::replace([
$data = [
'uniacid' => \YunShop::app()->uniacid,
'uid' => $member->uid,
'parent_id' => floatval($member->yzMember->parent_id),
'level' => $levelId,
'relation' => $member->yzMember->relation,
'upgrade_at' => time(),
]);
];
if($levelType == 1){
$data['cultural_level_id'] = $levelId;
$data['cultural_upgrade_at'] = time();
}else{
$data['level'] = $levelId;
$data['upgrade_at'] = time();
}
TeamDividendAgencyModel::replace($data);
}
}

View File

@ -135,26 +135,43 @@ class TeamDividendAgencyModel extends BackendModel
$result = $result->whereBetween('yz_team_dividend_agency.created_at', $range);
}
}
$result = $result->with(
['hasOneLevel' => function($query){
return $query->select(['*']);
},'hasOneMember' => function($query){
return $query->select(['*']);
},'toParent' => function($query){
return $query->select('uid', 'realname', 'mobile');
},'hasManyTeamDividend' => function($query){
return $query->selectRaw('member_id, status, sum(dividend_amount) as total_amount')->groupBy('member_id','status');
}])->orderBy('id', 'desc');
$result = $result->with([
'hasOneLevel' => function($query){
return $query->select(['*']);
},
'culturalLevel' => function($query){
return $query->select(['id','level_name','level_weight','level_type','dividend_ratio','award_ratio','culate_model']);
},
'hasOneMember' => function($query){
return $query->select(['*']);
},
'toParent' => function($query){
return $query->select('uid','realname','mobile');
},
'hasManyTeamDividend' => function($query){
return $query->selectRaw('member_id, status, sum(dividend_amount) as total_amount')
->groupBy('member_id','status');
}
])
->orderBy('id','desc');
return $result;
}
public function culturalLevel(){
return $this->hasOne(TeamDividendLevelModel::class, 'id', 'cultural_level_id');
}
public static function getAgencyInfoByUid($uid)
{
return self::uniacid()
->with('hasOneLevel')
->with(['hasOneLevel'=>function($query){
$query->select(['id','award_gratitude','award_ratio','dividend_ratio','level_weight']);
},'culturalLevel'=>function($query){
$query->select(['id','award_gratitude','award_ratio','dividend_ratio','level_weight']);
}])
->where('uid', $uid)
->first();
}

View File

@ -198,7 +198,7 @@ class TeamDividendLevelModel extends BackendModel
'level_weight' => [
'required',
'integer',
Rule::unique($this->table)->ignore($this->id)->where('uniacid', $this->uniacid)->whereNull('deleted_at'),
Rule::unique($this->table)->ignore($this->id)->where('uniacid', $this->uniacid)->where('level_type', $this->level_type)->whereNull('deleted_at'),
'min:1'
],
'upgrade_reward_point' => 'required',

View File

@ -200,6 +200,12 @@ class TeamDividendModel extends BaseModel
case 3:
$this->TypeService = '额外分红';
break;
case 4:
$this->TypeService = '津贴(补贴)';
break;
case 5:
$this->TypeService = '津贴(补贴)平级奖';
break;
}
}
return $this->TypeService;

View File

@ -28,7 +28,11 @@ class GetAgentsService
// 所有上级
$parents = MemberParent::with([
'hasOneTeam' => function ($team) {
$team->with(['hasOneLevel']);
$team->with(['hasOneLevel'=>function($query){
$query->select(['id','award_gratitude','award_ratio','dividend_ratio','level_weight']);
},'culturalLevel'=>function($query){
$query->select(['id','award_gratitude','award_ratio','dividend_ratio','level_weight']);
}]);
}
])->whereHas('hasOneParentMember')
->where('member_id', $uid)

View File

@ -24,6 +24,7 @@ class GetAmountService
public $amount;
public $fixed;
public $ratio;
private $dividendType = 0;
/**
* GetAmountService constructor.
@ -34,9 +35,11 @@ class GetAmountService
* @param $team_goods
* @param $finish_ratio
* @param $finish_price
* @param $dividendType
*/
public function __construct($agent, $order, $order_goods, $set, $team_goods, $finish_ratio, $finish_price)
public function __construct($agent, $order, $order_goods, $set, $team_goods, $finish_ratio, $finish_price, $dividendType = 0)
{
$this->dividendType = $dividendType;
$this->agent = $agent;
$this->order = $order;
$this->order_goods = $order_goods;
@ -154,7 +157,7 @@ class GetAmountService
*/
public function getAwardHierarchy()
{
$award_hierarchy = $this->agent['has_one_level']['award_hierarchy'];
$award_hierarchy = $this->dividendType == 1 ? $this->agent['cultural_level']['award_hierarchy'] : $this->agent['has_one_level']['award_hierarchy'];
if ($this->hasPeers()) {
$hierarchys = $this->getHierarchys();
$hierarchy_level = $hierarchys[$this->agent['level']];
@ -172,7 +175,7 @@ class GetAmountService
*/
public function getAwardHierarchyRatio()
{
$ratio = $this->agent['has_one_level']['award_ratio'];
$ratio = $this->dividendType == 1 ? $this->agent['cultural_level']['award_ratio'] : $this->agent['has_one_level']['award_ratio'];
if ($this->hasPeers()) {
$hierarchys = $this->getHierarchys();
$hierarchy_level = $hierarchys[$this->agent['level']];
@ -293,8 +296,14 @@ class GetAmountService
// 收银台商品 与 存在独立奖励设置 else 商城
if ($this->hasDividendRate()) {
// 经销商奖励比例 - 下级经销商奖励比例 = 奖励比例
$ratio = bcsub($this->agent['has_one_level']['dividend_ratio'], $this->finish_ratio,2);
$this->finish_ratio = $this->agent['has_one_level']['dividend_ratio'];
if($this->dividendType == 1){
$ratio = bcsub($this->agent['cultural_level']['dividend_ratio'], $this->finish_ratio,2);
$this->finish_ratio = $this->agent['cultural_level']['dividend_ratio'];
}else{
$ratio = bcsub($this->agent['has_one_level']['dividend_ratio'], $this->finish_ratio,2);
$this->finish_ratio = $this->agent['has_one_level']['dividend_ratio'];
}
return $ratio;
} else {
// 商城商品设置奖励比例 else 商城商品设置奖励固定金额
@ -306,8 +315,13 @@ class GetAmountService
}
}
} else {
$ratio = bcsub($this->agent['has_one_level']['dividend_ratio'], $this->finish_ratio,2);
$this->finish_ratio = $this->agent['has_one_level']['dividend_ratio'];
if($this->dividendType == 1){
$ratio = bcsub($this->agent['cultural_level']['dividend_ratio'], $this->finish_ratio,2);
$this->finish_ratio = $this->agent['cultural_level']['dividend_ratio'];
}else{
$ratio = bcsub($this->agent['has_one_level']['dividend_ratio'], $this->finish_ratio,2);
$this->finish_ratio = $this->agent['has_one_level']['dividend_ratio'];
}
return $ratio;
}
}

View File

@ -59,20 +59,12 @@ class TeamReturnService
protected $flat_prize_limit;
// public function __construct($order, $set, $buyMember, $order_goods, $agents)
// {
// $this->order = $order;
// $this->set = $set;
// $this->buyMember = $buyMember;
// $this->order_goods = $order_goods;
// $this->agents = $agents;
// $this->team_goods = GoodsTeamDividend::getGoodsByGoodsId($this->order_goods->goods_id)->first();
// $this->levels = TeamDividendLevelModel::uniacid()->orderBy('level_weight','asc')->get()->toArray();
//
// }
private $dividendType = 0;// 分红类型0=普通经销商提成1=文创经销商津贴(补贴)
public function setData($order, $set, $buyMember, $order_goods, $agents)
{
public function setData($order, $set, $buyMember, $order_goods, $agents, $dividendType = 0){
$this->dividendType = $dividendType;
$this->order = $order;
$this->set = $set;
$this->buyMember = $buyMember;
@ -93,12 +85,9 @@ class TeamReturnService
$this->running();
}
private function running()
{
private function running(){
foreach ($this->agents as $agent) {
$this->amount_service = new GetAmountService($agent, $this->order, $this->order_goods, $this->set, $this->team_goods, $this->finish_ratio, $this->finish_price);
$this->amount_service = new GetAmountService($agent, $this->order, $this->order_goods, $this->set, $this->team_goods, $this->finish_ratio, $this->finish_price, $this->dividendType);
//商品分红限制 不计入平级奖层级 不算感恩奖
if ($agent['is_black'] || $this->getIsRestrict($agent)) {
continue;
@ -109,10 +98,8 @@ class TeamReturnService
$this->order_goods->payment_amount = $this->order_goods->goods_price;
}
}
// 感恩奖
$this->gratitudeAward($agent);
// 经销商奖励
$this->dividendAward($agent);
// 平级奖
@ -146,17 +133,18 @@ class TeamReturnService
return;
}
// 如果 已完成经销商奖励金额 * 经销商等级设置的感恩奖比例 <= 0
$amount = proportionMath($this->finish_team_award_amount,$agent['has_one_level']['award_gratitude']);
if($this->dividendType == 1) $amount = proportionMath($this->finish_team_award_amount,$agent['cultural_level']['award_gratitude']);
else $amount = proportionMath($this->finish_team_award_amount,$agent['has_one_level']['award_gratitude']);
if ($amount <= 0) {
return;
}
$dividendData = [
'amount' => $this->finish_team_award_amount,
'dividend_rate' => $agent['has_one_level']['award_gratitude'],
'amount' => $this->finish_team_award_amount,
'dividend_rate' => $this->dividendType == 1 ? $agent['cultural_level']['award_gratitude'] : $agent['has_one_level']['award_gratitude'],
'lower_level_rate' => 0,
'dividend_amount' => $amount,
'type' => 2
'dividend_amount' => $amount,
'type' => 2
];
//添加到明细
$dividend_model = $this->addDividend($agent, $dividendData);
@ -165,12 +153,12 @@ class TeamReturnService
$member = Member::getMemberByUid($agent['uid'])->with('hasOneFans')->first();
$notice = [
'lower_level_name' => $this->buyMember->nickname,
'order_amount' => $this->order->price,
'amount' => $this->finish_team_award_amount,
'dividendRate' => $agent['has_one_level']['award_gratitude'],
'rate' => $this->lower_ratio,
'dividend_amount' => $amount,
'dividend_id' => $dividend_model ? $dividend_model->id : 0,
'order_amount' => $this->order->price,
'amount' => $this->finish_team_award_amount,
'dividendRate' => $this->dividendType == 1 ? $agent['cultural_level']['award_gratitude'] : $agent['has_one_level']['award_gratitude'],
'rate' => $this->lower_ratio,
'dividend_amount' => $amount,
'dividend_id' => $dividend_model ? $dividend_model->id : 0,
];
if ($this->set['notice_event'] == 1) {
NoticeLog::create([
@ -332,11 +320,21 @@ class TeamReturnService
return;
}
if ($last_agent['has_one_level']['id'] != $agent['has_one_level']['id']){
\Log::debug('经销商平级奖限制,下级经销商等级与当前会员不相等',$this->order->id.'_'.$this->order_goods->id.'_'.$agent['uid']);
return;
if($this->dividendType == 1){
if ($last_agent['cultural_level']['id'] != $agent['cultural_level']['id']){
\Log::debug('经销商平级奖限制,下级经销商等级与当前会员不相等',$this->order->id.'_'.$this->order_goods->id.'_'.$agent['uid']);
return;
}
}else{
if ($last_agent['has_one_level']['id'] != $agent['has_one_level']['id']){
\Log::debug('经销商平级奖限制,下级经销商等级与当前会员不相等',$this->order->id.'_'.$this->order_goods->id.'_'.$agent['uid']);
return;
}
}
$yz_member = MemberShopInfo::where('member_id',$last_agent['uid'])->first();
if (!$yz_member || $yz_member->parent_id != $agent['uid']){
\Log::debug('经销商平级奖限制,下级经销商非当前会员直属下级',$this->order->id.'_'.$this->order_goods->id.'_'.$agent['uid']);
@ -350,11 +348,11 @@ class TeamReturnService
$member = Member::getMemberByUid($agent['uid'])->with('hasOneFans')->first();
$notice = [
'lower_level_name' => $this->buyMember->nickname,
'order_amount' => $this->order->price,
'amount' => $dividendData['amount'],
'dividendRate' => $agent['has_one_level']['award_ratio'],
'dividend_amount' => $dividendData['dividend_amount'],
'dividend_id' => $dividend_model ? $dividend_model->id : 0,
'order_amount' => $this->order->price,
'amount' => $dividendData['amount'],
'dividendRate' => $this->dividendType == 1 ? $agent['cultural_level']['award_ratio'] : $agent['has_one_level']['award_ratio'],
'dividend_amount' => $dividendData['dividend_amount'],
'dividend_id' => $dividend_model ? $dividend_model->id : 0,
];
if ($this->set['notice_event'] == 1) {
NoticeLog::create([
@ -391,20 +389,37 @@ class TeamReturnService
//计算总获得分红
$dividendData['amount'] = $this->order_goods->total * $dividend_extra['level_' . $agent['level']];
$agent['has_one_level']['dividend_ratio'] = 1;
if (!isset($this->extraHierarchy['first_weight'])) {
$this->extraHierarchy['first_weight'] = $agent['has_one_level']['level_weight'];
}
if (!empty($this->extraHierarchy['weight'])) {
if ($agent['has_one_level']['level_weight'] <= $this->extraHierarchy['weight']) {
return;
if($this->dividendType == 1) {
$agent['cultural_level']['dividend_ratio'] = 1;
$agent['cultural_level']['dividend_ratio'] = 1;
if (!isset($this->extraHierarchy['first_weight'])) {
$this->extraHierarchy['first_weight'] = $agent['cultural_level']['level_weight'];
}
if (!empty($this->extraHierarchy['weight'])) {
if ($agent['cultural_level']['level_weight'] <= $this->extraHierarchy['weight']) {
return;
}
}
$this->extraHierarchy['weight'] = $agent['cultural_level']['level_weight'];
//查看等级是否小于或等于第一级
$this->extraHierarchy['finish_weight'] = $agent['cultural_level']['level_weight'] - $this->extraHierarchy['first_weight'];
}
else {
$agent['has_one_level']['dividend_ratio'] = 1;
if (!isset($this->extraHierarchy['first_weight'])) {
$this->extraHierarchy['first_weight'] = $agent['has_one_level']['level_weight'];
}
if (!empty($this->extraHierarchy['weight'])) {
if ($agent['has_one_level']['level_weight'] <= $this->extraHierarchy['weight']) {
return;
}
}
$this->extraHierarchy['weight'] = $agent['has_one_level']['level_weight'];
//查看等级是否小于或等于第一级
$this->extraHierarchy['finish_weight'] = $agent['has_one_level']['level_weight'] - $this->extraHierarchy['first_weight'];
}
$this->extraHierarchy['weight'] = $agent['has_one_level']['level_weight'];
//查看等级是否小于或等于第一级
$this->extraHierarchy['finish_weight'] = $agent['has_one_level']['level_weight'] - $this->extraHierarchy['first_weight'];
if ($this->extraHierarchy['finish_weight'] < 0) {
return;
}
@ -451,41 +466,26 @@ class TeamReturnService
$this->extraCount++;
}
private function addDividend($agent, $dividendData)
{
private function addDividend($agent, $dividendData){
$dividendData += [
'uniacid' => $this->order->uniacid,
'member_id' => $agent['uid'],
'order_sn' => $this->order->order_sn,
'order_amount' => $this->order->price,
'agent_level' => $agent['level'],
'status' => 0,
'create_month' => date('Y-m'),
'settle_days' => $this->set['settle_days'] ?: 0,
'culate_method'=>intval($this->set['culate_method']) ? : 0,
'created_at' => time()
'uniacid' => $this->order->uniacid,
'member_id' => $agent['uid'],
'order_sn' => $this->order->order_sn,
'order_amount' => $this->order->price,
'agent_level' => $agent['level'],
'status' => 0,
'create_month' => date('Y-m'),
'settle_days' => $this->set['settle_days'] ?: 0,
'culate_method' => intval($this->set['culate_method']) ?: 0,
'created_at' => time(),
];
// 判断:如果当前是 文创津贴(补贴) 修改对应的类型值
if($this->dividendType == 1) $dividendData['type'] = $dividendData['type'] == 1 ? 5 : 4;
//如果存在对应记录 todo 由于商品不同规格的数据相同会重复
// $exist = TeamDividendModel::where([
// 'member_id' => $agent['uid'],
// 'agent_level' => $agent['level'],
// 'order_sn' => $dividendData['order_sn'],
// 'type' => $dividendData['type'],
// ])->count();
// if ($exist) {
// \Log::info("订单{$dividendData['order_sn']}:", "经销商{$agent['uid']}的{$dividendData['type']}分红记录已存在");
// return;
// }
//取小数点后两位数四舍五入 例如设置独立金额0.003元
if (round($dividendData['dividend_amount'], 2) <= 0) {
return;
}
if (empty($dividendData['lower_level_rate'])){
$dividendData['lower_level_rate'] = 0;
}
if (round($dividendData['dividend_amount'], 2) <= 0) return;
if (empty($dividendData['lower_level_rate'])) $dividendData['lower_level_rate'] = 0;
//todo 防止多队列支付先走
$order = \app\common\models\Order::find($this->order->id);

View File

@ -28,29 +28,31 @@ class AgentsService
{
return $this->agents;
}
private function _init()
{
private function _init(){
// 开启内购
//if ($this->setting['buy_self'] == 1) {
$teamDividend = TeamDividendAgencyModel::select(['uid', 'level'])
->where('uid', $this->uid)
->first();
$this->agents[] = [
'uid' => $this->uid,
'teamDividend' => $teamDividend
];
$teamDividend = TeamDividendAgencyModel::select(['uid','level','cultural_level_id'])
->where('uid',$this->uid)
->first();
$this->agents[] = [
'uid' => $this->uid,
'teamDividend' => $teamDividend
];
//}
// 上级
$agents = MemberParent::with(['hasOneTeamDividendAgency'])
->where('member_id', $this->uid)
->orderBy('level', 'asc')
$agents = MemberParent::with([
'hasOneTeamDividendAgency' => function($query){
$query->select(['uid','level','cultural_level_id']);
}
])
->where('member_id',$this->uid)
->orderBy('level','asc')
->get();
if (!$agents->isEmpty()) {
foreach ($agents as $agent) {
if(!$agents->isEmpty()){
foreach($agents as $agent){
$this->agents[] = [
'uid' => $agent->parent_id,
'teamDividend' => $agent->hasOneTeamDividendAgency
'uid' => $agent->parent_id,
'teamDividend' => $agent->hasOneTeamDividendAgency
];
}
}

View File

@ -65,6 +65,8 @@
<option value='1' @if($search['type'] == '1') selected @endif>平级奖励</option>
<option value='2' @if($search['type'] == '2') selected @endif>感恩奖励</option>
<option value='3' @if($search['type'] == '3') selected @endif>额外分红</option>
<option value='4' @if($search['type'] == '4') selected @endif>津贴(补贴)</option>
<option value='5' @if($search['type'] == '5') selected @endif>津贴(补贴)平级奖</option>
</select>
</div>

View File

@ -82,6 +82,20 @@
<span class="help-block">等级权重,数字越大级别越高。</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">等级类型</label>
<div class="col-sm-6 col-xs-6">
<div class="input-group">
<label class="radio-inline">
<input type="radio" name="dividend[level_type]" value="0" @if (empty($dividend->level_type)) checked @endif> 普通等级
</label>
<label class="radio-inline">
<input type="radio" name="dividend[level_type]" value="1" @if (1 == $dividend->level_type) checked @endif style="margin: 4px 0 0; position:inherit"> 文创等级
</label>
</div>
<span class="help-block">用户升级到普通等级会改变经销商等级不会改变文创等级,升级到文创等级则不会改变经销商等级只会改变文创等级</span>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label"><span
style="color:red">*</span> 等级名称</label>
@ -90,6 +104,14 @@
value="{{$dividend->level_name}}"/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">
<span style="color:red">*</span> 文创补贴名称
</label>
<div class="col-sm-6 col-xs-6">
<input type='text' name='dividend[cultural_level_name]' class="form-control" value="{{$dividend->cultural_level_name}}"/>
</div>
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">身份类型</label>
<div class="col-sm-6 col-xs-6">
@ -141,7 +163,9 @@
</div>
<div class="form-group">
<label class="col-xs-12 col-sm-3 col-md-2 control-label">提成比例</label>
<label class="col-xs-12 col-sm-3 col-md-2 control-label">
<span id="dividend_ratio_text">{{ $dividend->level_type == 1 ? '补贴(津贴)比例' : '提成比例' }}</span>
</label>
<div class="col-sm-6 col-xs-6">
<div class='input-group'>
<input type='text' name='dividend[dividend_ratio]'
@ -1226,6 +1250,17 @@
})
})
// 等级类型改变
$(document).on('change',"[name='dividend[level_type]']",function(){
let val = $(this).val();
val = parseInt(val) && !isNaN(parseInt(val)) ? parseInt(val) : parseInt(0);
// 0=普通等级 1=文创等级
$("#dividend_ratio_text").html(val === parseInt(1) ? '补贴(津贴)比例' : '提成比例');
});
</script>
<script type="text/javascript">
let ladder = JSON.parse(`{!! $wv['ladder'] ?? json_encode([]) !!}`) || {};

View File

@ -1,6 +1,11 @@
@extends('layouts.base')
@section('title', trans('经销商等级'))
@section('content')
<style>
.panel-body .label{
font-size: 14px!important;
}
</style>
<div class="w1200 ">
<script type="text/javascript" src="./resource/js/lib/jquery-ui-1.10.3.min.js"></script>
<link rel="stylesheet" type="text/css" href="{{static_url('css/font-awesome.min.css')}}">
@ -19,29 +24,49 @@
<table class="table table-hover">
<thead class="navbar-inner">
<tr>
<th width="6%">等级权重</th>
<th width="16%">等级名称</th>
<th width="16%">提成比例</th>
<th width="15%">激活码发放</th>
<th width="15%">平级奖励层级</th>
<th width="16%">平级奖励比例</th>
<th width="16%">操作</th>
<th style="width: 100px;text-align: center;">等级权重</th>
<th style="text-align: center;">等级名称</th>
<th style="text-align: center;">等级类型</th>
<th style="width: 150px;text-align: center;">提成比例(%)</th>
<th style="width: 150px;text-align: center;">补贴(津贴)比例(%)</th>
{{--<th style="width: 245px;text-align: center;">激活码发放</th>--}}
<th style="width: 150px;text-align: center;">平级奖励层级</th>
<th style="width: 150px;text-align: center;">平级奖励比例</th>
<th style="text-align: center;">操作</th>
</tr>
</thead>
<tbody>
@foreach($list['data'] as $item)
<tr>
<td>
<input type="text" class="form-control"
name="display_order[{{$item['id']}}]"
value="{{$item['level_weight']}}">
<td style="text-align: center;">
<input type="text" class="form-control" name="display_order[{{$item['id']}}]" value="{{$item['level_weight']}}">
</td>
<td>{{$item['level_name']}}</td>
<td>{{$item['dividend_ratio']}}</td>
<td>{{array_sum(unserialize($item['code_num']))}}</td>
<td>{{$item['award_hierarchy']}}</td>
<td>{{$item['award_ratio']}}</td>
<td>
<td style="text-align: center;">{{$item['level_name']}}</td>
<td style="text-align: center;">
@if($item['level_type'] == 1)
<span class="label label-warning">文创等级</span>
@else
<span class="label label-default">普通等级</span>
@endif
</td>
<td style="text-align: center;">
@if($item['level_type'] == 1)
-
@else
{{$item['dividend_ratio']}}
@endif
</td>
<td style="text-align: center;">
@if($item['level_type'] == 1)
{{$item['dividend_ratio']}}
@else
-
@endif
</td>
{{--<td style="text-align: center;">{{array_sum(unserialize($item['code_num']))}}</td>--}}
<td style="text-align: center;">{{$item['award_hierarchy']}}</td>
<td style="text-align: center;">{{$item['award_ratio']}}</td>
<td style="text-align: center;">
<a class="btn btn-default" href="{!! yzWebUrl('plugin.team-dividend.admin.team-dividend-level-set.edit', ['id'=>$item['id']]) !!}">编辑</a>
<a class="btn btn-default" href="{!! yzWebUrl('plugin.team-dividend.admin.team-dividend-level-set.deleted', ['id'=>$item['id']]) !!}" onclick="return confirm('{{$delete_msg}}');return false;">删除</a>
</td>

View File

@ -14,6 +14,9 @@
padding-bottom: 80px;
overflow: hidden !important;
}
.panel-body .label{
font-size: 13px!important;
}
</style>
<div class="w1200 ">
<div class=" rightlist ">
@ -107,15 +110,22 @@
<table class="table table-hover" >
<thead class="navbar-inner">
<tr>
<th style="width: 50px;">ID</th>
<th style="width: 50px;">UID</th>
<th style="width: 160px;">成为经销商时间<br>升级时间</th>
<th style="width: 80px;text-align: center;">
<span class="label label-default">ID</span>
<br>
<span class="label label-warning">UID</span>
</th>
<th style="width: 160px;">成为经销商时间<br>普通等级升级时间<br>文创等级升级时间</th>
<th style="width: 120px;">经销商</th>
<th style="width: 120px;">等级</th>
<th style="width: 100px;">排名</th>
<th style="width: 150px;">名额(剩余/已使用)</th>
<th width="8.5%">直属总经销商人数</th>
<th width="8.5%">经销商比例<br>累计提成</th>
<th width="8.5%">
提成比例<br>累计提成
<hr style="margin: 5px 0!important;"/>
补贴(津贴)比例<br>累计补贴(津贴)
</th>
<th width="8.5%">已结算提成<br>未结算提成</th>
<th width="13%">黑名单<br>变动时间</th>
<th width="8.5%">团队业绩<br>团队商品销量</th>
@ -125,67 +135,81 @@
<tbody>
@foreach($list['data'] as $item)
<tr>
<td>{{$item['id']}}</td>
<td>{{$item['has_one_member']['uid']}}</td>
<td style="text-align: center;">
<span class="label label-default">{{$item['id']}}</span>
<br>
<span class="label label-warning">{{$item['has_one_member']['uid']}}</span>
</td>
<td>
{{$item['created_at']}}
<br>
{{$item['upgrade_at'] ? date('Y-m-d H:i:s',$item['upgrade_at']) : '/'}}
<br>
{{$item['cultural_upgrade_at'] ? date('Y-m-d H:i:s',$item['cultural_upgrade_at']) : '/'}}
</td>
@if ($item['has_one_member'])
<td>
<a href="{!! yzWebUrl('member.member.detail', ['id'=>$item['has_one_member']['uid']]) !!}"><img src="{{$item['has_one_member']['avatar']}}" style="width:30px;height:30px;padding:1px;border:1px solid #ccc"><BR>{{$item['has_one_member']['nickname']}}</a>
</td>
@else
<td style="height: 59px">
@if ($item['has_one_member'])
<a href="{!! yzWebUrl('member.member.detail', ['id'=>$item['has_one_member']['uid']]) !!}">
<img src="{{$item['has_one_member']['avatar']}}" style="width:30px;height:30px;padding:1px;border:1px solid #ccc">
<br>
{{$item['has_one_member']['nickname']}}
</a>
@else
未更新
@endif
</td>
@endif
<td title="{{$item['has_one_level']['level_name']}}" class='tdedit' width="26%">
<td title="{{$item['has_one_level']['level_name']}}" class='tdedit'>
<span class=' fa-edit-item' style='cursor:pointer'>
<span class="title">{{$item['has_one_level']['level_name']}}</span>
<span class="title">{{$item['has_one_level']['level_name'] ?? '/'}}</span>
<i class='fa fa-pencil' style="display:none"></i>
</span>
<div class="input-group level" style="display:none">
<select class="form-control tpl-agent-level" name="level_id" data-agencyid="{{$item['id']}}">
<option>请选择等级</option>
@foreach($level as $value)
<option value="{{$value->id}}"
@if($item['level']==$value->id)
selected
@endif
>{{$value->level_name}}</option>
@if($value->level_type == 0)
<option value="{{$value->id}}" @if($item['level']==$value->id) selected @endif>{{$value->level_name}}</option>
@endif
@endforeach
</select>
</div>
<br />
<span class=' fa-edit-item' style='cursor:pointer'>
<span class="title">{{$item['cultural_level']['level_name'] ?? '/'}}</span>
<i class='fa fa-pencil' style="display:none"></i>
</span>
<div class="input-group level" style="display:none">
<select class="form-control tpl-agent-level" name="level_id" data-agencyid="{{$item['id']}}">
<option>请选择等级</option>
@foreach($level as $value)
@if($value->level_type == 1)
<option value="{{$value->id}}" @if($item['cultural_level_id']==$value->id) selected @endif>{{$value->level_name}}</option>
@endif
@endforeach
</select>
</div>
</td>
<td>
@foreach($item['rank_list'] as $rankItem)
<p>{{$rankItem['level_name']}}{{$rankItem['ranking']}}</p>
@endforeach
</td>
<td>
{{$item['surplus_quota']}} / {{$item['use_quota']}}
</td>
<td>{{$item['surplus_quota']}} / {{$item['use_quota']}}</td>
<td>
{{$item['total'] ?? 0}}
<a href="{{yzWebUrl('plugin.team-dividend.admin.team-agency',['uid'=>$item['uid']])}}">
查看
</a>
</td>
<td>
{{$item['has_one_level']['dividend_ratio']}}%
<br>
{{$item['has_many_team_dividend'][2]['total_amount'] + $item['has_many_team_dividend'][1]['total_amount'] + $item['has_many_team_dividend'][0]['total_amount']}}
<hr style="margin: 5px 0!important;"/>
{{$item['cultural_level']['dividend_ratio'] ?? 0}}%
<br>
0
</td>
{{--<td>{{$item['dividend_final']}}</td>--}}
{{--<td>{{$item['dividend_open']}}</td>--}}
{{--<td>{{$item['dividend_total']}}</td>--}}
<td>
@if($item['has_many_team_dividend'][0]['status'] == 1)
{{$item['has_many_team_dividend'][0]['total_amount']}}
@ -197,15 +221,15 @@
0
@endif
<br>
@if($item['has_many_team_dividend'][0]['status'] === 0)
{{$item['has_many_team_dividend'][0]['total_amount']}}
@elseif($item['has_many_team_dividend'][1]['status'] === 0)
{{$item['has_many_team_dividend'][1]['total_amount']}}
@elseif($item['has_many_team_dividend'][2]['status'] === 0)
{{$item['has_many_team_dividend'][2]['total_amount']}}
@else
0
@endif
@if($item['has_many_team_dividend'][0]['status'] === 0)
{{$item['has_many_team_dividend'][0]['total_amount']}}
@elseif($item['has_many_team_dividend'][1]['status'] === 0)
{{$item['has_many_team_dividend'][1]['total_amount']}}
@elseif($item['has_many_team_dividend'][2]['status'] === 0)
{{$item['has_many_team_dividend'][2]['total_amount']}}
@else
0
@endif
</td>
<td>
@if($item['is_black'])