diff --git a/plugins/collection-room/src/PluginApplication.php b/plugins/collection-room/src/PluginApplication.php index a86bb4c0..5e090c6b 100644 --- a/plugins/collection-room/src/PluginApplication.php +++ b/plugins/collection-room/src/PluginApplication.php @@ -9,6 +9,9 @@ use Yunshop\CollectionRoom\models\CollectionRoomIdentifierModel; class PluginApplication extends \app\common\services\PluginApplication{ protected function setMenuConfig(){ + + + return []; \app\backend\modules\menu\Menu::current()->setPluginMenu('collection-room', [ 'name' => '典藏室', 'type' => 'marketing', diff --git a/plugins/cultural-space/src/PluginApplication.php b/plugins/cultural-space/src/PluginApplication.php index 0fcd3463..b2da8ffc 100644 --- a/plugins/cultural-space/src/PluginApplication.php +++ b/plugins/cultural-space/src/PluginApplication.php @@ -11,6 +11,8 @@ use Yunshop\CulturalSpace\models\CulturalSpaceAreaCycle; class PluginApplication extends \app\common\services\PluginApplication{ protected function setMenuConfig(){ + + return []; \app\backend\modules\menu\Menu::current()->setPluginMenu('cultural-space', [ 'name' => '文创空间', 'type' => 'marketing', diff --git a/plugins/team-dividend/lang/zh-CN/index.php b/plugins/team-dividend/lang/zh-CN/index.php index 2b445d50..a3b76d5a 100644 --- a/plugins/team-dividend/lang/zh-CN/index.php +++ b/plugins/team-dividend/lang/zh-CN/index.php @@ -1,6 +1,6 @@ getSetting('plugin.team_dividend'); - // \Log::debug('经销商管理基础设置',$set); + \Log::debug('经销商管理基础设置',$set); //是否开启经销商插件 if (!$set['is_team_dividend']) { @@ -88,22 +88,17 @@ class OrderCreatedListener $buyMember = $order->belongsToMember; $agents = GetAgentsService::index($set, $order->uid, $order->create_time); - // \Log::debug('经销商-获取经销商',$agents); - try{ - foreach ($order->hasManyOrderGoods as $order_goods) { - // 普通经销商提成处理 - $TeamReturnService->setData($order, $set, $buyMember, $order_goods, $agents); - $TeamReturnService->handle(); - $this->totalDividend += $TeamReturnService->totalDividend; - } - // 订单插件分红记录 - (new OrderBonusJob('yz_team_dividend', 'team-dividend', 'order_sn', 'order_sn', 'dividend_amount', $order, $this->totalDividend))->handle(); + \Log::debug('经销商-获取经销商',$agents); + foreach ($order->hasManyOrderGoods as $order_goods) { - }catch(\Exception $e){ - \Log::debug('经销商奖励 - 错误',$e->getMessage()); + $TeamReturnService->setData($order, $set, $buyMember, $order_goods, $agents); + $TeamReturnService->handle(); + $this->totalDividend += $TeamReturnService->totalDividend; } - \Log::debug('经销商奖励完成',$this->totalDividend); + // 订单插件分红记录 + (new OrderBonusJob('yz_team_dividend', 'team-dividend', 'order_sn', 'order_sn', 'dividend_amount', $order, $this->totalDividend))->handle(); + \Log::debug('经销商奖励完成'); return; } diff --git a/plugins/team-dividend/src/Listener/OrderPaidListener.php b/plugins/team-dividend/src/Listener/OrderPaidListener.php index 172efa09..38635cef 100644 --- a/plugins/team-dividend/src/Listener/OrderPaidListener.php +++ b/plugins/team-dividend/src/Listener/OrderPaidListener.php @@ -1,6 +1,6 @@ status >= 1 ? 1 : 0; - // \Log::debug('--------更改已支付状态 0/1--------', [ - // 'order_status' => $model->status, - // 'is_pay' => $teamDividendData['is_pay'], - // 'order_sn' => $model->order_sn, - // ]); + \Log::debug('--------更改已支付状态 0/1--------', [ + 'order_status' => $model->status, + 'is_pay' => $teamDividendData['is_pay'], + 'order_sn' => $model->order_sn, + ]); $team_dividend_ids = TeamDividendModel::where('order_sn', $model->order_sn)->orderBy('id', 'asc')->pluck('id'); $result = TeamDividendModel::whereIn('id', $team_dividend_ids)->update($teamDividendData); // $teamDividendWhere = ['order_sn' => $model->order_sn]; // $result = TeamDividendModel::updatedTeamDividend($teamDividendData, $teamDividendWhere); -// \Log::debug('--------记录更新影响条数--------', $result); + \Log::debug('--------记录更新影响条数--------', $result); //支付后发送公众号消息通知 (new SendMessageService($model))->handle(); diff --git a/plugins/team-dividend/src/Listener/WithdrawApplyListener.php b/plugins/team-dividend/src/Listener/WithdrawApplyListener.php index d12dd06f..299c9a2c 100644 --- a/plugins/team-dividend/src/Listener/WithdrawApplyListener.php +++ b/plugins/team-dividend/src/Listener/WithdrawApplyListener.php @@ -5,7 +5,7 @@ * Email: livsyitian@163.com * QQ: 995265288 * IDE: PhpStorm - * User: + * User: 芸众商城 www.yunzshop.com ****************************************************************/ diff --git a/plugins/team-dividend/src/PluginApplication.php b/plugins/team-dividend/src/PluginApplication.php index 8b016782..3205fcfd 100644 --- a/plugins/team-dividend/src/PluginApplication.php +++ b/plugins/team-dividend/src/PluginApplication.php @@ -13,7 +13,6 @@ 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 @@ -578,137 +577,81 @@ class PluginApplication extends \app\common\services\PluginApplication ], ], // 店长管理 - // 'team_dividend_store_manager' => [ - // 'name' => '店长管理', - // 'url' => 'plugin.team-dividend.admin.store-manager.index', - // 'url_params' => '', - // 'permit' => 1, - // 'menu' => 1, - // 'icon' => '', - // 'item' => 'team_dividend', - // 'parents' => ['team_dividend'], - // 'child' => [ - // 'team_dividend_store_manager_index' => [ - // 'name' => '店长列表', - // 'url' => 'plugin.team-dividend.admin.store-manager.index', - // 'url_params' => '', - // 'permit' => 1, - // 'menu' => 0, - // 'icon' => '', - // 'item' => 'team_dividend_store_manager_index', - // 'parents' => ['team_dividend', 'team_dividend_store_manager'], - // ], - // 'team_dividend_store_manager_addInfo' => [ - // 'name' => '添加店长', - // 'url' => 'plugin.team-dividend.admin.store-manager.addInfo', - // 'url_params' => '', - // 'permit' => 1, - // 'menu' => 0, - // 'icon' => '', - // 'item' => 'team_dividend_store_manager_addInfo', - // 'parents' => ['team_dividend', 'team_dividend_store_manager'], - // ], - // 'team_dividend_store_manager_change_status' => [ - // 'name' => '删除店长', - // 'url' => 'plugin.team-dividend.admin.store-manager.change-status', - // 'url_params' => '', - // 'permit' => 1, - // 'menu' => 0, - // 'icon' => '', - // 'item' => 'team_dividend_store_manager_change_status', - // 'parents' => ['team_dividend', 'team_dividend_store_manager'], - // ], - // 'team_dividend_store_manager_change_see_info' => [ - // 'name' => '查看店补', - // 'url' => 'plugin.team-dividend.admin.store-manager.see-info', - // 'url_params' => '', - // 'permit' => 1, - // 'menu' => 0, - // 'icon' => '', - // 'item' => 'team_dividend_store_manager_see_info', - // 'parents' => ['team_dividend', 'team_dividend_store_manager'], - // ], - // - // ] - // ], + 'team_dividend_store_manager' => [ + 'name' => '店长管理', + 'url' => 'plugin.team-dividend.admin.store-manager.index', + 'url_params' => '', + 'permit' => 1, + 'menu' => 1, + 'icon' => '', + 'item' => 'team_dividend', + 'parents' => ['team_dividend'], + 'child' => [ + 'team_dividend_store_manager_index' => [ + 'name' => '店长列表', + 'url' => 'plugin.team-dividend.admin.store-manager.index', + 'url_params' => '', + 'permit' => 1, + 'menu' => 0, + 'icon' => '', + 'item' => 'team_dividend_store_manager_index', + 'parents' => ['team_dividend', 'team_dividend_store_manager'], + ], + 'team_dividend_store_manager_addInfo' => [ + 'name' => '添加店长', + 'url' => 'plugin.team-dividend.admin.store-manager.addInfo', + 'url_params' => '', + 'permit' => 1, + 'menu' => 0, + 'icon' => '', + 'item' => 'team_dividend_store_manager_addInfo', + 'parents' => ['team_dividend', 'team_dividend_store_manager'], + ], + 'team_dividend_store_manager_change_status' => [ + 'name' => '删除店长', + 'url' => 'plugin.team-dividend.admin.store-manager.change-status', + 'url_params' => '', + 'permit' => 1, + 'menu' => 0, + 'icon' => '', + 'item' => 'team_dividend_store_manager_change_status', + 'parents' => ['team_dividend', 'team_dividend_store_manager'], + ], + 'team_dividend_store_manager_change_see_info' => [ + 'name' => '查看店补', + 'url' => 'plugin.team-dividend.admin.store-manager.see-info', + 'url_params' => '', + 'permit' => 1, + 'menu' => 0, + 'icon' => '', + 'item' => 'team_dividend_store_manager_see_info', + 'parents' => ['team_dividend', 'team_dividend_store_manager'], + ], - // 团队信息 - 'team_dividend_team' => [ - 'name' => '团队信息', - 'url' => 'plugin.team-dividend.admin.team.index', - 'url_params' => '', - 'permit' => 1, - 'menu' => 1, - 'icon' => '', - 'item' => 'team_dividend', - 'parents' => ['team_dividend'], - 'child' => [ - 'team_dividend_team_index' => [ - 'name' => '团队信息', - 'url' => 'plugin.team-dividend.admin.team.index', - 'url_params' => '', - 'permit' => 1, - 'menu' => 0, - 'icon' => '', - 'item' => 'team_dividend_team_index', - 'parents' => ['team_dividend', 'team_dividend_team'], - ], - ] - ], + ] + ], ] ]); } - 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'); - // $teamDividendCulturalName = !empty($teamDividendCulturalName) ? $teamDividendCulturalName : '生态建设'; - // } return [ 'teamDividend' => [ - 'title' => '团队收益',//$lang['title'] ?: trans('Yunshop\TeamDividend::index.title'), + 'title' => $lang['title'] ?: trans('Yunshop\TeamDividend::index.title'), 'type' => 'teamDividend', - 'type_name' => '团队收益',//$title.$dividend, + 'type_name' => $title.$dividend, 'class' => 'Yunshop\TeamDividend\models\TeamDividendModel', ], - // 'storeManager' => [ - // 'title' => '店补', - // 'type' => 'storeManager', - // 'type_name' => '店长店补', - // 'class' => 'Yunshop\TeamDividend\Common\models\StoreManagerRecordModel', - // ], - // 'teamDividendCultural' => [ - // 'title' => $teamDividendCulturalName, - // 'type' => 'teamDividendCultural', - // 'type_name' => $teamDividendCulturalName, - // 'class' => 'Yunshop\TeamDividend\models\TeamDividendModel', - // ], - - 'ecological_services' => [ - 'title' => '生态服务', - 'type' => 'ecological_services', - 'type_name' => '生态服务', - 'class' => 'Yunshop\TeamDividend\models\TeamDividendModel', - ], - 'ecological_construction' => [ - 'title' => '经销商受益',//'生态建设', - 'type' => 'ecological_construction', - 'type_name' => '经销商受益',//'生态建设', - 'class' => 'Yunshop\TeamDividend\models\TeamDividendModel', - ], - 'ecological_contribution' => [ - 'title' => '生态贡献', - 'type' => 'ecological_contribution', - 'type_name' => '生态贡献', - 'class' => 'Yunshop\TeamDividend\models\TeamDividendModel', - ], - + 'storeManager' => [ + 'title' => '店补', + 'type' => 'storeManager', + 'type_name' => '店长店补', + 'class' => 'Yunshop\TeamDividend\Common\models\StoreManagerRecordModel', + ] ]; } @@ -763,12 +706,27 @@ 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 () { @@ -800,20 +758,6 @@ 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; - }); - }); + } } \ No newline at end of file diff --git a/plugins/team-dividend/src/admin/CodeRecordController.php b/plugins/team-dividend/src/admin/CodeRecordController.php index 347530dd..f4ae3cbd 100644 --- a/plugins/team-dividend/src/admin/CodeRecordController.php +++ b/plugins/team-dividend/src/admin/CodeRecordController.php @@ -106,8 +106,8 @@ class CodeRecordController extends BaseController // $excel->setTitle('Office 2005 XLSX Document'); // // // Chain the setters -// $excel->setCreator('') -// ->setLastModifiedBy("") +// $excel->setCreator('芸众商城') +// ->setLastModifiedBy("芸众商城") // ->setSubject("Office 2005 XLSX Test Document") // ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.") // ->setKeywords("office 2005 openxml php") diff --git a/plugins/team-dividend/src/admin/LevelConditionController.php b/plugins/team-dividend/src/admin/LevelConditionController.php index 8108bd4c..e40cae73 100644 --- a/plugins/team-dividend/src/admin/LevelConditionController.php +++ b/plugins/team-dividend/src/admin/LevelConditionController.php @@ -1,6 +1,6 @@ select([DB::raw("sum(give_limit) as total_quota"),'uid']) - ->whereIn('uid',$uidS) - ->orderBy('created_at','ASC') - ->groupBy('uid') - ->get() - ->toArray(); - $quotaInfo = array_column($quotaInfo,'total_quota','uid'); - // 已使用 - $useQuota = TeamDividendAgencyModel::uniacid() - ->select([DB::raw("count(id) as total_use_quota"),'give_uid']) - ->whereIn('give_uid',$uidS) - ->groupBy('uid') - ->get() - ->toArray(); - $useQuota = array_column($useQuota,'total_use_quota','give_uid'); + $level = TeamDividendLevelModel::getList()->get(); + + + foreach ($list['data'] as $key => $item) { $list['data'][$key]['total'] = count($item['has_many_member_children']); - // 剩余名额处理 - $list['data'][$key]['total_quota'] = (int)$quotaInfo[$item['uid']]; - $list['data'][$key]['surplus_quota'] = (int)$quotaInfo[$item['uid']] - (int)$useQuota[$item['uid']]; - $list['data'][$key]['use_quota'] = (int)$useQuota[$item['uid']]; - // 排名处理 - $list['data'][$key]['rank_list'] = array_filter(array_map(function($rankInfo) use ($item){ - $rankSort = (string)$rankInfo['up_log'][$item['uid']]; - if(($rankSort === '0' || $rankSort) && $rankInfo['level_type'] == 0) { - return [ - 'id' => $rankInfo['id'], - 'level_name' => $rankInfo['level_name'], - 'ranking' => ((int)$rankInfo['up_log'][$item['uid']] + 1), - ]; - } - return []; - },$rankList)); } - - - $level = TeamDividendLevelModel::getList()->where('level_type',0)->get(); - $culturalLevel = TeamDividendLevelModel::getList()->where('level_type',1)->get(); - return view('Yunshop\TeamDividend::admin.team-agency', [ 'list' => $list, 'endtime' => $endtime, @@ -140,7 +97,6 @@ class TeamAgencyController extends BaseController 'pager' => $pager, 'title' => $title, 'level' => $level, - 'culturalLevel' => $culturalLevel, 'request' => \YunShop::request(), ])->render(); } @@ -152,29 +108,71 @@ class TeamAgencyController extends BaseController */ public function add() { + $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 && (int)$agentData['cultural_level_id'] <= 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']; - try{ - TeamDividendAgencyModel::addTeamAgency($agentData); + if ($agency_model->save()) { + //签合同 + $data=[ + 'member_id'=>$agentData['uid'], + 'created_at' => time(), + ]; + event(new \app\common\events\plugin\TeamDividendEvent($data)); + //激活码 + $upgrade_set = (new UpgradeService())->getUpgradeById($agentData['level']); + + if ($upgrade_set) { + $set = \Setting::get('plugin.team_dividend'); - return $this->message('经销商操作成功', yzWebUrl('plugin.team-dividend.admin.team-agency')); - }catch(\Exception $e){ - return $this->message($e->getMessage(), '', 'error'); + // 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); + foreach($level_list as $key => $level) { + if($code_num['level_'.$level->id]) { + (new UpgradeService())->senCode($agentData['uid'], $code_num['level_'.$level->id], $level->id, $level->level_name); + } + } + \Log::debug('激活码'); + } + } + (new UpgradeService())->becomeAgencyNotify($agentData['uid']); + //直推奖 todo 直推奖不用了 + // (new UpgradeService())->sendBonus($agentData['uid']); + // \Log::debug('直推奖'); + + return $this->message('经销商操作成功', yzWebUrl('plugin.team-dividend.admin.team-agency')); + } } - } - $level_list = TeamDividendLevelModel::getList()->where('level_type',0)->get(); - $cultural_level = TeamDividendLevelModel::getList()->where('level_type',1)->get(); - return view('Yunshop\TeamDividend::admin.team-agency-add', [ - 'level' => $level_list, - 'cultural_level' => $cultural_level + 'level' => $level_list ])->render(); } @@ -231,7 +229,7 @@ class TeamAgencyController extends BaseController } } } - $export_data[0] = ['ID', '会员', '推荐人会员ID', '成为代理时间', '推荐人姓名', '推荐人手机号', '经销商', '手机号','等级', '文创等级', '一级(直系)总经销商人数', '分红比例', '已结算分红', '未结算分红', '累计结算分红','团队业绩','团队商品销量']; + $export_data[0] = ['ID', '会员', '推荐人会员ID', '成为代理时间', '推荐人姓名', '推荐人手机号', '经销商', '手机号','等级', '一级(直系)总经销商人数', '分红比例', '已结算分红', '未结算分红', '累计结算分红','团队业绩','团队商品销量']; foreach ($list as $key => $item) { if (!empty($item['status'])) { $status = '已使用'; @@ -257,7 +255,6 @@ class TeamAgencyController extends BaseController $item['dividend_open'] = 0; $item['dividend_total'] = $item['has_many_team_dividend'][2]['total_amount'] + $item['has_many_team_dividend'][1]['total_amount'] + $item['has_many_team_dividend'][0]['total_amount']?:0; - $export_data[$key + 1] = [ $item['id'], $item['has_one_member']['uid'], @@ -268,7 +265,6 @@ class TeamAgencyController extends BaseController $item['has_one_member']['username'], $item['has_one_member']['mobile'], $item['has_one_level']['level_name'], - $item['cultural_level']['level_name'], $item['total'], $item['has_one_level']['dividend_ratio'], $item['dividend_final'], @@ -284,8 +280,8 @@ class TeamAgencyController extends BaseController // $excel->setTitle('Office 2005 XLSX Document'); // // // Chain the setters -// $excel->setCreator('') -// ->setLastModifiedBy("") +// $excel->setCreator('芸众商城') +// ->setLastModifiedBy("芸众商城") // ->setSubject("Office 2005 XLSX Test Document") // ->setDescription("Test document for Office 2005 XLSX, generated using PHP classes.") // ->setKeywords("office 2005 openxml php") @@ -315,108 +311,55 @@ class TeamAgencyController extends BaseController public function change() { $id = \YunShop::request()->id; - $levelId = \YunShop::request()->value; - $leveType = \YunShop::request()->leve_type; - - TeamDividendAgencyModel::changeLevel($id,$levelId,$leveType); - } + $agency = TeamDividendAgencyModel::find($id); + $level = $agency->level; + $agency->level = \YunShop::request()->value; + $agency->upgrade_at = time(); - public function test(){ + if ($agency->save()) { - // 经销商升级模拟 - // $model = Order::with('hasManyOrderGoods')->find(34); - // $set = \Setting::get('plugin.team_dividend'); - // (new NewUpgrateJob($model->uid, $set, $model->uniacid, TeamDividendLevelUpgrade::ORDER_PAY, $model))->handle(); + // 经销商等级变动记录 + /*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); + // 升级前等级 + $o_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find($level); - // 经销商提成模拟 - // $order = Order::find(43); - // $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; - // } - - - - // 等级 升级记录校准 - /*$teamDividendList = TeamDividendAgencyModel::uniacid()->select(['id','uid','level','cultural_level_id'])->get()->toArray(); - $notUpLog = []; - foreach($teamDividendList as $teamInfo){ - // 判断:普通等级是否存在升级记录 - if((int)$teamInfo['level'] > 0){ - $isHasLevelLog = (int)Uplog::uniacid()->where('uid',$teamInfo['uid'])->where('after_level_id',$teamInfo['level'])->value('id'); - if($isHasLevelLog <= 0) $notUpLog[$teamInfo['id']]['level_res'] = $teamInfo; - } - // 文创等级是否存在升级记录 - if((int)$teamInfo['cultural_level_id'] > 0){ - $isHasCulturalLevelLog = (int)Uplog::uniacid()->where('uid',$teamInfo['uid'])->where('after_level_id',$teamInfo['cultural_level_id'])->value('id'); - if($isHasCulturalLevelLog <= 0) { - $teamInfo['info_count'] = Uplog::uniacid()->where('uid',$teamInfo['uid'])->count(); - $teamInfo['info_max_id'] = Uplog::uniacid()->where('uid',$teamInfo['uid'])->max('id'); - $teamInfo['info_list'] = Uplog::uniacid()->select('id','uid','before_level_id','after_level_id')->where('uid',$teamInfo['uid'])->get()->toArray(); - $notUpLog[$teamInfo['id']]['cultural_level_res'] = $teamInfo; - - - // if($teamInfo['info_count'] >= 2 && $teamInfo['cultural_level_id'] == 6){ - // Uplog::uniacid()->where('id',$teamInfo['info_max_id'])->update([ - // 'after_level_id' => $teamInfo['cultural_level_id'], - // 'after_level_setting' => '{"id":6,"uniacid":2,"level_name":"\u6d88\u8d39\u5546","cultural_level_name":"\u5e02\u573a\u670d\u52a1\u6d25\u8d34","level_weight":1,"level_type":1,"dividend_ratio":0,"code_num":"0","award_hierarchy":0,"award_ratio":"0","created_at":"2023-11-24 15:05:32","updated_at":"2023-11-30 10:49:36","deleted_at":null,"upgrade_reward_point":"0.00","upgrade_reward_gold":"0.00","award_gratitude":"0","hierarchy_limit":0,"auto_withdraw_day":"","auto_withdraw_period":"","number_limit":0,"culate_model":0,"current_md":null,"upgrade_reward_draw":0,"identity_type":0,"give_limit":0,"give_limit_level_id":5,"has_one_upgrade_set":{"id":6,"uniacid":"2","dividend_id":6,"parase":[{"self_buy_count":"1","become":"0"},{"order_money_2":"","order_num_2":"","order_money":"","first_money":"","order_count":"","first_order_count":"","first_order_count_to_goods":"","team_order_amount":"","team_shop_order_amount":"","team_profit_amount":"","team_goods_amount":"","team_goods_amount_to_goods":"","team_merchants_count":"","team_member_count":"","team_member_count_to_goods":"","first_lower_team_count":"","first_lower_team_count_to_goods":"","all_lower_team_count":"","first_lower_count":"","self_buy_money":"1","self_buy_count":"1","level":{"13":"","12":"","11":"","10":"","9":"","8":"","5":"","7":"","4":"","6":"","3":""},"first_child_level":{"13":"","12":"","11":"","10":"","9":"","8":"","5":"","7":"","4":"","6":"","3":""},"group_level":{"13":"","12":"","11":"","10":"","9":"","8":"","5":"","7":"","4":"","6":"","3":""},"level_line_num":"","level_line_level_id":"5","oneself":"0","level_line_people":"","level_line_area_num":"","level_line_area_level_id":"1","level_line_area_people":"","settle_money":"","first_cost_count":"","first_cost_num":"","dividend_and_peer_sum":"","first_second_cost_count":"","first_second_cost_num":"","team_new_order_number":"","team_new_order_number_to_goods":"","one_or_two":{"one_or_two_level_id":"5","one_or_two_people":""},"goods":"","many_good":["12","13","14"]}],"created_at":"2023-11-24 15:05:32","updated_at":"2023-11-30 10:49:36","deleted_at":null}}' - // - // - // ]); - // } - + // 升级日志 + Uplog::addLog($agency, $o_level, $c_level); + if ($c_level->level_weight > $o_level->level_weight) { + //激活码 + $upgrade_set = (new UpgradeService())->getUpgradeById($agency->level); + if ($upgrade_set) { + $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) ? : []; + 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); + } + } + \Log::debug('激活码'); + } } + + //代理商升级通知 + (new UpgradeService())->agencyUpgradeNotify($agency->uid, $o_level->level_name, $o_level->dividend_ratio_name, $agency->level); } } - - debug([ - '总数' => count($notUpLog), - 'uid' => implode(',',array_column(array_column($notUpLog,'cultural_level_res'),'uid')), - '列表' => $notUpLog - - ]);*/ - - - - // 全部订单重新处理分红 - // $orderList = Order::uniacid()->get(); - // foreach($orderList as $order){ - // // $order = Order::find(43); - // $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; - // } - // } - - - - - - debug("结束。。。"); } - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/admin/TeamDividendLevelSetController.php b/plugins/team-dividend/src/admin/TeamDividendLevelSetController.php index 99ad6c53..4a21f3eb 100644 --- a/plugins/team-dividend/src/admin/TeamDividendLevelSetController.php +++ b/plugins/team-dividend/src/admin/TeamDividendLevelSetController.php @@ -10,7 +10,6 @@ use Illuminate\Support\Str; use Yunshop\TeamDividend\admin\models\LevelRedPack; use Yunshop\TeamDividend\models\TeamDividendLevelModel; use Yunshop\TeamDividend\models\TeamDividendLevelUpgrade; -use Yunshop\WeightValue\models\GoodsWeightValue; class TeamDividendLevelSetController extends BaseController { @@ -61,7 +60,7 @@ class TeamDividendLevelSetController extends BaseController $validator = $team_dividend_level_model->validator(); if ($validator->fails()) { - return $this->message(reset(array_values($validator->messages()->getMessages())[0]),'', 'error'); + $this->error($validator->messages()); } else { if ($team_dividend_level_model->save()) { @@ -81,13 +80,6 @@ class TeamDividendLevelSetController extends BaseController $upgrade_modle->save(); - - // 权重值处理 - $wv = request()->wv ?? []; - $wv['is_open'] = 1;// 经销商设置 默认开启 - if($wv) GoodsWeightValue::relationSave($team_dividend_level_model->id, $wv, 'created',true); - - return $this->message('经销商等级操作成功', yzWebUrl('plugin.team-dividend.admin.team-dividend-level-set'), 'success'); } } @@ -208,7 +200,6 @@ class TeamDividendLevelSetController extends BaseController $data['hierarchy_limit'] = !empty($data['hierarchy_limit']) ? $data['hierarchy_limit'] : 0; $data['auto_withdraw_day'] = !empty($data['auto_withdraw_day']) ? $data['auto_withdraw_day'] : ''; $data['auto_withdraw_period'] = !empty($data['auto_withdraw_period']) ? $data['auto_withdraw_period'] : ''; - $data['number_limit'] = !empty($data['number_limit']) ? $data['number_limit'] : 0; $dividend_model->fill($data); $validator = $dividend_model->validator(); @@ -244,11 +235,6 @@ class TeamDividendLevelSetController extends BaseController $upgrade_modle->save(); } - // 权重值处理 - $wv = request()->wv ?? []; - $wv['is_open'] = 1;// 经销商设置 默认开启 - if($wv) GoodsWeightValue::relationSave($id, $wv, 'updated',true); - return $this->message('经销商等级操作成功', yzWebUrl('plugin.team-dividend.admin.team-dividend-level-set'), 'success'); } } @@ -258,12 +244,6 @@ class TeamDividendLevelSetController extends BaseController $goldSet = array_pluck(\Setting::getAllByGroup('Love')->toArray(), 'value', 'key'); $goldTitle = $goldSet['name'] ? $goldSet['name'] : '爱心值'; $settingData = \Setting::get('plugin.team_dividend'); - - // 权重值信息 - $wv = (new GoodsWeightValue())->getGoodsSet($id,true)->first(); - $wv = $wv ? $wv->toArray() : []; - - return view('Yunshop\TeamDividend::admin.level-set-add', [ 'dividend' => $dividend_model, 'code_num' => $dividend_model->code_num, @@ -277,7 +257,6 @@ class TeamDividendLevelSetController extends BaseController 'goldTitle' => $goldTitle, 'settingData' => $settingData, 'goods' => $goods, - 'wv' => $wv ])->render(); } diff --git a/plugins/team-dividend/src/admin/models/LevelRedPack.php b/plugins/team-dividend/src/admin/models/LevelRedPack.php index aca593a4..eddb9dc9 100644 --- a/plugins/team-dividend/src/admin/models/LevelRedPack.php +++ b/plugins/team-dividend/src/admin/models/LevelRedPack.php @@ -1,6 +1,6 @@ errorJson('激活码使用失败'); } } - - - // 业绩是否完成 - public function performanceComplete(){ - // 基本参数 - $target = 500000; - $isComplete = 0; - $memberId = \YunShop::app()->getMemberId(); - $areaAmount = 0; - if($memberId > 0){ - // 获取直推下级列表 - $subIds = MemberChild::uniacid() - ->where('level',1) - ->where('member_id',$memberId) - ->pluck('child_id') - ->toArray(); - $subPerformance = [];// 每条线的业绩 - foreach($subIds as $subUid){ - $lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray(); - $lineAllUid[] = $subUid; - $subPerformance[$subUid] = Order::uniacid() - ->leftJoin('yz_order_goods','yz_order_goods.order_id','yz_order.id') - ->leftJoin('yz_goods_cultural_space','yz_goods_cultural_space.goods_id','yz_order_goods.goods_id') - ->whereIn('yz_order.uid',$lineAllUid) - ->where('yz_order.status','>',0) - ->where('yz_goods_cultural_space.is_open',0) - ->sum('yz_order_goods.payment_amount'); - // $subPerformance[$subUid] = Order::whereIn('uid',$lineAllUid)->where('status','>=',0)->sum('yz_order.price'); - } - // 计算业绩 - $teamAmount = (float)sprintf("%.2f",array_sum($subPerformance));// 总业绩 - $maxAmount = max($subPerformance);// 最大一条线的业绩 - $areaAmount = (float)sprintf("%.2f",$teamAmount - $maxAmount);// 小区业绩 = 总业绩 - 最大一条线的业绩 - $isComplete = $areaAmount >= $target ? 1 : 0; - } - - return $this->successJson('业绩是否完成', [ - 'is_complete' => $isComplete, - 'area_amount' => $areaAmount - ]); - } - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/api/RedPackController.php b/plugins/team-dividend/src/api/RedPackController.php index 825fef9f..7809b986 100644 --- a/plugins/team-dividend/src/api/RedPackController.php +++ b/plugins/team-dividend/src/api/RedPackController.php @@ -1,6 +1,6 @@ getAgents(); // 循环上级 foreach ($agents as $agent) { - // 黑名单不升级 - if ($agent['teamDividend']->is_black) continue; - // 升级处理 - \Log::debug('经销商升级 - 开始:',$agent['uid']); - $this->eachLevelHandle($agent);// 普通等级升级处理 - $this->eachCulturalLevelHandle($agent);// 文创等级升级处理 - } - - - // 订单支付成功 处理权重值相关内容(因为需要兼容 用户不是经销商,但是成为经销商后当前订单如果存在赠送权重值,则需要同步赠送。因此只能在这里调用赠送操作 ) - if($this->order_status == TeamDividendLevelUpgrade::ORDER_PAY && $this->order){ - (new WeightValue())->giveInit($this->order); + // 循环等级 + $this->eachLevelHandle($agent); } } - // 普通等级升级处理 - public function eachLevelHandle($agent){ + /** + * @name 查询等级权重比当前大的等级集合 + * @param $agent + * @return mixed + * @author + */ + public function eachLevelHandle($agent) + { + if ($agent['teamDividend']->is_black){ //黑名单不升级 + return; + } + // $up_code = $this->setting['upgrate_type'] == 1 ? '或' : '与'; // 升级日志 $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();*/ return; } - // \Log::debug('经销商升级 - 开始处理:',$agent['uid']); + // 默认可以升级 $upgradeRet = false; foreach ($upgradeLevels as $level) { - // \Log::debug('经销商升级 - 当前等级信息:',$level->toArray()); - // 判断:如果当前等级人数已经达到限制 则不升级(上限小于等于已存在数量 不能升级到该等级) - $hasNum = (int)Uplog::uniacid()->where('after_level_id',$level->id)->count(DB::raw('DISTINCT(uid)')); - // \Log::debug('经销商升级 - 数量限制比较:',[$hasNum,(int)$level->number_limit]); - if((int)$level->number_limit <= $hasNum && (int)$level->number_limit > 0) continue; - //dump($level->level_name); // 没有升级条件 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']); + // 记录 //$logModel->level_ups = $parase[0]; + // 升级条件 组 $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(); @@ -155,7 +164,7 @@ class NewUpgrateJob implements ShouldQueue // 升级类 $upgrateService = new UpgrateConditionService($agent['uid'], $this->setting, $parase[1], $this->uniacid, $typeName, $order_status, $this->order, $this->uplogService); // 升级方法 - // \Log::debug('===123分组方法名:' . $typeName); + \Log::debug('===123分组方法名:' . $typeName); $func = $this->getFunctionName($typeName); if (!method_exists($upgrateService, $func)) { @@ -188,13 +197,15 @@ class NewUpgrateJob implements ShouldQueue $next = true; // 如果升级方式为 或 $upgradeRet 为真 不继续 if ($this->setting['upgrate_type'] == 1) { - if ($upgradeRet) $next = false; - + if ($upgradeRet) { + $next = false; + } } else { // 如果升级方式为 与 $upgradeRet 为假 不继续 - if (!$upgradeRet && $upgradeGroup) $next = false; + if (!$upgradeRet && $upgradeGroup) { + $next = false; + } } - // \Log::debug('经销商升级 - 是否继续:',$next); // 升级条件 单个 与 升级结果为false if ($next) { $upgradeOnly = $parase[0]; @@ -217,12 +228,12 @@ class NewUpgrateJob implements ShouldQueue 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); + \Log::debug('===123单个方法名:' . $upgrade); $func = $this->getFunctionName($upgrade); // 升级条件 结果 if (!method_exists($upgrateService, $func)) { @@ -330,216 +341,6 @@ 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('经销商升级 - 文创等级 - 开始处理:',$agent['uid']); - // 默认可以升级 - $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, 1); - // 升级方法 - \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, 1); - // 升级方法 - \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 升级奖励激活码 @@ -564,8 +365,15 @@ class NewUpgrateJob implements ShouldQueue } } - // 升级奖励 - public function upgradeAward($uid, $level){ + /** + * @name 升级奖励积分爱心值 + * @param $uid + * @param $level + * @throws \app\common\exceptions\ShopException + * @author + */ + public function upgradeAward($uid, $level) + { $isPluginGold = \YunShop::plugin()->get('love');//爱心值插件 $upgradeRewardPoint = $level->upgrade_reward_point; $upgradeRewardGold = $level->upgrade_reward_gold; @@ -614,10 +422,6 @@ class NewUpgrateJob implements ShouldQueue ]; (new LoveChangeService())->teamLevelAward($data); } - // 升级赠送权重值 - (new WeightValue())->upgradeGiveInit($uid,(int)$level->id); - // 升级赠送画 - CollectionRoomModel::addInfo($uid,(int)$level->id); } /** @@ -631,60 +435,70 @@ class NewUpgrateJob implements ShouldQueue return Str::camel(preg_replace("/\\d+/", '', $str)); } - - // 查询等级权重比当前大的等级集合 - 根据等级类型查询 - private function getUpgrateLevelsByWeight($agent,$levelType = 0) + /** + * @name 获取当前会员的等级权重 + * @param $agent + * @return int + * @author + */ + private function 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; - } - // 获取当前会员的等级权重 - 根据等级类型查询 - private function getLevelWeight($agent,$levelType){ $levelWeight = 0; - if($agent['teamDividend']){ + 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); - }) + $agentLevel = TeamDividendLevelModel::with([ + 'hasOneUpgradeSet', + ]) + ->where('id', $agent['teamDividend']->level) ->first(); - if($agentLevel){ + if ($agentLevel) { $levelWeight = $agentLevel->level_weight; + // 升级前的等级设置 - $agentLevel = $agentLevel->toArray(); + $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){ + + /** + * @name 查询等级权重比当前大的等级集合 + * @param $agent + * @return mixed + * @author + */ + private function getUpgrateLevelsByWeight($agent) + { + $levelWeight = $this->getLevelWeight($agent); + $upgradeLevels = TeamDividendLevelModel::select() + ->with(['hasOneUpgradeSet']) + ->where('uniacid', $this->uniacid) + ->where('level_weight', '>', $levelWeight) + ->orderBy('level_weight', 'desc') + ->get(); + return $upgradeLevels; + } + + /** + * @name 会员成为经销商 + * @param $uid + * @param $levelId + * @author + */ + private function memberUpgradeToAgency($uid, $levelId) + { $member = Member::getUserInfos($uid)->first(); - $data = [ + + TeamDividendAgencyModel::replace([ 'uniacid' => \YunShop::app()->uniacid, 'uid' => $member->uid, 'parent_id' => floatval($member->yzMember->parent_id), + 'level' => $levelId, 'relation' => $member->yzMember->relation, - ]; - if($levelType == 1){ - $data['cultural_level_id'] = $levelId; - $data['cultural_upgrade_at'] = time(); - }else{ - $data['level'] = $levelId; - $data['upgrade_at'] = time(); - } - TeamDividendAgencyModel::replace($data); + 'upgrade_at' => time(), + ]); } } \ No newline at end of file diff --git a/plugins/team-dividend/src/jobs/RedPackJob.php b/plugins/team-dividend/src/jobs/RedPackJob.php index 67e7fbfa..4bd2140c 100644 --- a/plugins/team-dividend/src/jobs/RedPackJob.php +++ b/plugins/team-dividend/src/jobs/RedPackJob.php @@ -1,6 +1,6 @@ 1, - 'is_hierarchy' => 1, - 'is_restrict' => 0, - 'has_dividend' => 0, + 'is_dividend' => 1, + 'is_hierarchy' => 1, + 'is_restrict' => 0, + 'has_dividend' => 0, 'has_dividend_price' => 0, - 'has_dividend_rate' => 0, - 'commission_rates' => 0 + 'has_dividend_rate' => 0, ]; - public static function getGoodsByGoodsId($giidsId){ - return self::where('goods_id', $giidsId)->where('is_dividend', '1'); + public static function getGoodsByGoodsId($giidsId) + { + return self::where('goods_id', $giidsId) + ->where('is_dividend', '1'); } public static function relationSave($goodsId, $data, $operate) @@ -64,7 +65,6 @@ class GoodsTeamDividend extends BaseModel $data['has_dividend_rates'] = $data['has_dividend_rates'] ? serialize($data['has_dividend_rates']) : ''; $data['has_hierarchys'] = serialize($data['has_hierarchys']); $data['has_dividend_extra'] = $data['has_dividend_extra'] ? serialize($data['has_dividend_extra']) : ''; - $data['commission_rates'] = $data['commission_rates'] ? serialize($data['commission_rates']) : ''; $dividendModel->setRawAttributes($data); return $dividendModel->save(); } diff --git a/plugins/team-dividend/src/models/Log.php b/plugins/team-dividend/src/models/Log.php index 6d5cc3d1..282c1fb1 100644 --- a/plugins/team-dividend/src/models/Log.php +++ b/plugins/team-dividend/src/models/Log.php @@ -1,6 +1,6 @@ where('level', $parame['level_id']); } - if (!empty($parame['cultural_level_id'])) { - $result = $result->where('cultural_level_id', $parame['cultural_level_id']); - } - if (!empty($parame['member_id'])) { $result = $result->whereHas('hasOneMember', function ($query) use ($parame) { $query->where('uid', $parame['member_id']); @@ -144,43 +135,26 @@ class TeamDividendAgencyModel extends BackendModel $result = $result->whereBetween('yz_team_dividend_agency.created_at', $range); } } - $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'); + + $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'); return $result; } - public function culturalLevel(){ - return $this->hasOne(TeamDividendLevelModel::class, 'id', 'cultural_level_id'); - } - - public static function getAgencyInfoByUid($uid) { return self::uniacid() - ->with(['hasOneLevel'=>function($query){ - // $query->select(['id','award_gratitude','award_ratio','dividend_ratio','level_weight','level_type','commission_ratio']); - },'culturalLevel'=>function($query){ - // $query->select(['id','award_gratitude','award_ratio','dividend_ratio','level_weight','level_type','commission_ratio']); - }]) + ->with('hasOneLevel') ->where('uid', $uid) ->first(); } @@ -243,13 +217,7 @@ class TeamDividendAgencyModel extends BackendModel if (!$uids = MemberShopInfo::uniacid()->where('parent_id',$pid)->pluck('member_id')->toArray()){ return 0; } - return self::uniacid()->whereIn('uid',$uids) - ->where(function($query) use ($level){ - $query->where('level',$level) - ->orWhere('cultural_level_id',$level); - }) - // ->where('level', $level) - ->count(DB::raw("distinct(uid)")); + return self::uniacid()->whereIn('uid',$uids)->where('level', $level)->count(DB::raw("distinct(uid)")); // return self::uniacid() // ->where('parent_id', $pid) // ->where('level', $level) @@ -329,254 +297,4 @@ class TeamDividendAgencyModel extends BackendModel return true; } - /** - * Common: 判断:当前等级是否为用户成为过的经销商中 等级最小的 - * Author: wu-hui - * Time: 2023/10/26 18:03 - * @param $uid - * @param $teamLevelId - * @return bool - */ - public function isMinLevel($uid,$teamLevelId){ - $allLv = Uplog::uniacid() - ->select([ - 'yz_team_dividend_uplog.after_level_id', - 'yz_team_dividend_level.level_weight', - 'yz_team_dividend_level.id', - ]) - ->join('yz_team_dividend_level','yz_team_dividend_level.id','yz_team_dividend_uplog.after_level_id') - ->where('uid',$uid) - ->groupBy('after_level_id') - ->get() - ->toArray(); - // 判断:当前等级是否为最小等级 - $minWeight = (int)min(array_column($allLv,'level_weight'));// 最小权重值 - $weightList = array_column($allLv,'level_weight','after_level_id'); - - return (boolean)((int)$minWeight == (int)$weightList[$teamLevelId]); - } - - - public function addTeamAgency($agentData){ - // 其他验证 - $agency_model = new \Yunshop\TeamDividend\admin\models\TeamDividendAgencyModel(); - $agency_model->fill($agentData); - $validator = $agency_model->validator(); - if ($validator->fails()) { - throw new \Exception($validator->messages()->first()); - } else { - if ($agency_model->save()) { - // 升级后等级 - $c_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find($agentData['level']); - // 升级前等级 - $o_level = NULL; - // 升级日志 - Uplog::addLog($agency_model, $o_level, $c_level); - - - if((int)$agentData['cultural_level_id'] > 0){ - // 升级后等级 - $c_c_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find((int)$agentData['cultural_level_id']); - // 升级前等级 - $o_c_level = NULL; - // 升级日志 - Uplog::addLog($agency_model, $o_c_level, $c_c_level); - } - - - //签合同 - $data=[ - 'member_id'=>$agentData['uid'], - 'created_at' => time(), - ]; - event(new \app\common\events\plugin\TeamDividendEvent($data)); - //激活码 - $upgrade_set = (new UpgradeService())->getUpgradeById($agentData['level']); - - if ($upgrade_set) { - $set = \Setting::get('plugin.team_dividend'); - if ($set['is_activation_code'] && $upgrade_set[0]->code_num) { - $level_list = TeamDividendLevelModel::getList()->get(); - $code_num = unserialize($upgrade_set[0]->code_num); - foreach($level_list as $key => $level) { - if($code_num['level_'.$level->id]) { - (new UpgradeService())->senCode($agentData['uid'], $code_num['level_'.$level->id], $level->id, $level->level_name); - } - } - \Log::debug('激活码'); - } - } - (new UpgradeService())->becomeAgencyNotify($agentData['uid']); - - }else{ - throw new \Exception('添加失败'); - } - } - } - - public function changeLevel($id,$levelId,$leveType){ - $agency = TeamDividendAgencyModel::find($id); - - // 等级类型:''=普通等级,cultural=文创等级 - if((string)$leveType == 'cultural'){ - $level = $agency->cultural_level_id; - $agency->cultural_level_id = $levelId; - $agency->cultural_upgrade_at = time(); - }else{ - $level = $agency->level; - $agency->level = $levelId; - $agency->upgrade_at = time(); - } - - // 升级后等级 - $c_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find($leveType == 'cultural' ? $agency->cultural_level_id : $agency->level); - // 升级前等级 - $o_level = TeamDividendLevelModel::with(['hasOneUpgradeSet'])->find($level); - - - if($c_level && $o_level && $c_level->level_type != $o_level->level_type ){ - // 非默认等级 且 类型不一致,升级失败 - return false; - } - - - if ($agency->save()) { - // 升级日志 - Uplog::addLog($agency, $o_level, $c_level); - - if ($c_level->level_weight > $o_level->level_weight) { - //激活码 - $upgrade_set = (new UpgradeService())->getUpgradeById($agency->level); - - if ($upgrade_set) { - $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)) ?: []; - 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); - } - } - \Log::debug('激活码'); - } - } - - //代理商升级通知 - (new UpgradeService())->agencyUpgradeNotify($agency->uid, $o_level->level_name, $o_level->dividend_ratio_name, $agency->level); - } - } - } - - - /** - * Common: 团队信息 - 获取全部团队信息列表(分页) - * Author: wu-hui - * Time: 2024/01/05 13:32 - * @param $pageSize - * @param $search - * @return array - */ - public static function teamGetAllList($pageSize,$search){ - // 条件生成 - $where = []; - if($search['uid'] > 0) $where[] = ['uid','=',$search['uid']]; - // 列表获取 - $model = self::uniacid() - ->select(['id','uid']) - ->where($where) - ->when(!empty($search['nickname']),function($query) use ($search){ - // 合伙人 昵称|真实姓名搜索 - $ids = Member::where('nickname','like',"%{$search['nickname']}%") - ->orwhere('realname','like',"%{$search['nickname']}%") - ->pluck('uid'); - if($ids) $ids = $ids->toArray(); - $query->whereIn('uid',(array)$ids); - }) - ->with([ - 'hasOneMember' => function($query){ - $query->select(['uid','nickname','realname','avatar']); - } - ]) - ->orderBy('created_at','DESC') - ->orderBy('id','DESC'); - $list = $model->paginate($pageSize); - - return $list ? $list->toArray() : []; - } - /** - * Common: 团队信息 - 获某个用户的所有团队业绩信息(仅获取直推团队) - * Author: wu-hui - * Time: 2024/01/05 13:37 - * @param $uid - * @return array - */ - public static function teamGetPerformanceList($uid):array{ - // 获取直推下级列表 - $subIds = MemberChild::uniacid() - ->where('level',1) - ->where('member_id',$uid) - ->pluck('child_id') - ->toArray(); - $data = [ - 'line_list' => [],// 每条线的信息 - 'min_line' => [],// 业绩最少的一条线的信息 - 'max_line' => [],// 业绩最多的一条线的信息 - ]; - foreach($subIds as $subUid){ - $lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray(); - $lineAllUid[] = $subUid; - $subPerformance = Order::uniacid() - ->leftJoin('yz_order_goods','yz_order_goods.order_id','yz_order.id') - ->leftJoin('yz_goods_cultural_space','yz_goods_cultural_space.goods_id','yz_order_goods.goods_id') - ->whereIn('yz_order.uid',$lineAllUid) - ->where('yz_order.status','>',0) - ->where('yz_goods_cultural_space.is_open',1) - ->sum('yz_order_goods.payment_amount'); - // 信息处理赋值 - $currentLineData = [ - 'sub_uid' => $subUid, - 'line_all_uid' => implode(',',$lineAllUid), - 'performance' => $subPerformance, - ]; - $data['line_list'][] = $currentLineData; - // 判断:当前线是否为最小业绩 - if((float)$currentLineData['performance'] < (float)$data['min_line']['performance'] || (float)$data['min_line']['performance'] <= 0){ - $data['min_line'] = $currentLineData; - } - // 判断:当前线是否为大区业绩 - if((float)$currentLineData['performance'] > (float)$data['max_line']['performance']){ - $data['max_line'] = $currentLineData; - } - } - - return $data; - } - /** - * Common: 团队信息 - 获取全部经销商的小区业绩之和 - * Author: wu-hui - * Time: 2024/01/05 14:08 - * @return float|int - */ - public static function teamMinAreaSumAmount(){ - // 小区业绩 = 总业绩 - 最大一条线的业绩 - $uidList = self::uniacid()->pluck('uid'); - $totalPerformance = 0;// 全平台所有用户小区业绩之和 - foreach($uidList as $uid){ - // 获取团队业绩信息 - $teamPerformance = (new CulturalSpace())->getTeamOrderAmount($uid); - $totalPerformance += (float)$teamPerformance['area_amount']; - } - - return $totalPerformance; - } - - - - - - - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/models/TeamDividendLevelModel.php b/plugins/team-dividend/src/models/TeamDividendLevelModel.php index a10ce306..4e188ae9 100644 --- a/plugins/team-dividend/src/models/TeamDividendLevelModel.php +++ b/plugins/team-dividend/src/models/TeamDividendLevelModel.php @@ -17,14 +17,13 @@ class TeamDividendLevelModel extends BackendModel protected $guarded = ['']; public $attributes = [ 'upgrade_reward_point' => 0, - 'upgrade_reward_gold' => 0, - 'code_num' => 0, - 'award_hierarchy' => 0, - 'award_ratio' => 0, - 'award_gratitude' => 0, - 'auto_withdraw_day' => 0, + 'upgrade_reward_gold' => 0, + 'code_num' => 0, + 'award_hierarchy' => 0, + 'award_ratio' => 0, + 'award_gratitude' => 0, + 'auto_withdraw_day' => 0, 'auto_withdraw_period' => 0, - 'number_limit' => 0, ]; /** @@ -198,7 +197,7 @@ class TeamDividendLevelModel extends BackendModel 'level_weight' => [ 'required', 'integer', - Rule::unique($this->table)->ignore($this->id)->where('uniacid', $this->uniacid)->where('level_type', $this->level_type)->whereNull('deleted_at'), + Rule::unique($this->table)->ignore($this->id)->where('uniacid', $this->uniacid)->whereNull('deleted_at'), 'min:1' ], 'upgrade_reward_point' => 'required', @@ -209,47 +208,4 @@ class TeamDividendLevelModel extends BackendModel 'award_ratio' => 'required' ]; } - /** - * Common: 获取全部的等级信息 - * Author: wu-hui - * Time: 2023/10/23 9:16 - * @param $field - * @return mixed - */ - public static function getAll($field){ - return self::getList()->select($field)->get()->toArray(); - } - - public function upLog(){ - return $this->hasMany(Uplog::class, 'after_level_id', 'id'); - } - /** - * Common: 获取所有等级所有经销商排名信息 - * Author: wu-hui - * Time: 2023/10/23 15:45 - * @return array|false|null - */ - public static function getRanking(){ - // 获取全部经销商 以此来获取排名信息 - $upRank = TeamDividendLevelModel::uniacid() - ->select(['id','level_name','level_weight','level_type']) - ->with(['upLog'=>function($query){ - $query->select(['id','uid','after_level_id','created_at']) - ->orderBy('created_at','ASC') - ->groupBy('after_level_id') - ->groupBy('uid'); - }]) - ->get(); - $allTeamDividend = $upRank->map(function($upItem){ - return [ - 'id' => $upItem->id, - 'level_name' => $upItem->level_name, - 'level_type' => $upItem->level_type, - 'up_log' => array_flip($upItem->upLog->pluck('uid')->toArray()), - ]; - })->toArray(); - return array_column($allTeamDividend,null,'id'); - } - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php b/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php index 2cf9935c..c2419f52 100644 --- a/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php +++ b/plugins/team-dividend/src/models/TeamDividendLevelUpgrade.php @@ -70,33 +70,8 @@ class TeamDividendLevelUpgrade extends BackendModel '1030' => 'agent_love', // 会员累计获得{{ LOVE_NAME }}数量达到 '1031' => 'team_new_order_number', // 团队新订单数量满 '1032' => 'team_shop_order_amount', // 团队自营订单实付金额满 - '1050' => 'one_or_two', // 直推间推 某个等级 满多少人 - '1051' => 'team_consumption_people',// 团队消费人数满多少人 支持去除人数最多的线 ]; // 等级为 2000 + 等级id return $ret; } - /** - * Common: 获取所有升级商品(仅限条件开启状态) - * Author: wu-hui - * Time: 2023/10/18 15:32 - * @return []|array - */ - public static function getUpgradeGoods(){ - $list = self::uniacid()->pluck('parase'); - $goodsIds = []; - foreach($list as $key => $item){ - $parase = unserialize($item); - if((int)$parase[0]['goods'] == 1) $goodsIds = array_merge($goodsIds,[$parase[1]['goods']]); - if((int)$parase[0]['many_good'] == 1) $goodsIds = array_merge($goodsIds,(array)$parase[1]['many_good']); - } - - return array_unique($goodsIds); - } - - - - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/models/TeamDividendModel.php b/plugins/team-dividend/src/models/TeamDividendModel.php index 24902575..70275715 100644 --- a/plugins/team-dividend/src/models/TeamDividendModel.php +++ b/plugins/team-dividend/src/models/TeamDividendModel.php @@ -200,15 +200,6 @@ class TeamDividendModel extends BaseModel case 3: $this->TypeService = '额外分红'; break; - case 4: - $this->TypeService = '经销商受益';//生态建设 - break; - case 5: - $this->TypeService = '生态贡献'; - break; - case 6: - $this->TypeService = '生态服务';// 生态服务 - break; } } return $this->TypeService; @@ -470,29 +461,4 @@ class TeamDividendModel extends BaseModel return $query->orderBy('yz_team_dividend.id', 'desc'); } - /** - * Common: 获取用户某个类型的提成 - * Author: wu-hui - * Time: 2023/11/20 15:15 - * @param int $uid 用户id - * @param int $type 4=生态建设,5=生态贡献,6=生态服务 - * @param string $incomeStatus all=全部收益;undrawn=未提现收益,withdrawn=已提现收益 - * @return mixed - */ - public static function getTypeTotalIncome(int $uid,int $type,string $incomeStatus = 'all'){ - return self::uniacid() - ->leftJoin('yz_member_income', function ($join) { - $join->on('yz_member_income.member_id', 'yz_team_dividend.member_id')->on('yz_member_income.incometable_id', 'yz_team_dividend.id'); - }) - ->where('yz_member_income.dividend_code',2) - ->where('yz_team_dividend.type',$type) - ->where('yz_team_dividend.member_id',$uid) - ->when($incomeStatus != 'all',function($query) use ($incomeStatus){ - $query->where('yz_member_income.status',$incomeStatus == 'undrawn' ? 0 : 1); - }); - } - - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/models/TeamUpgradeReward.php b/plugins/team-dividend/src/models/TeamUpgradeReward.php index 69d3576f..9717187e 100644 --- a/plugins/team-dividend/src/models/TeamUpgradeReward.php +++ b/plugins/team-dividend/src/models/TeamUpgradeReward.php @@ -1,6 +1,6 @@ toArray() : []; - $afterLevelSetting = !is_null($afterLevel) ? $afterLevel->toArray() : []; + $afterLevelSetting = $afterLevel->toArray(); $uplogService = new UplogService($agency->uid, $agency->uniacid, $beforeLevelSetting['id']); $beforeLevelSetting['has_one_upgrade_set']['parase'] = unserialize($beforeLevelSetting['has_one_upgrade_set']['parase']); $uplogService->setBeforeLevelSetting($beforeLevelSetting); @@ -97,17 +95,6 @@ class Uplog extends BaseModel $uplogService->setAfterLevelId($afterLevelSetting['id']); $uplogService->setUpCode($upCode); $uplogService->store(); - - - - if(!is_null($afterLevel)){ - \Log::debug('经销商等级变更 - 权重值操作:',['uid' => $agency->uid,'old_lv'=>$beforeLevelSetting['id'],'lv'=>$afterLevelSetting['id']]); - // 经销商升级赠送权重值处理 - (new WeightValue())->upgradeGiveInit((int)$agency->uid,(int)$afterLevelSetting['id']); - // 会员升级经销商 赠送画 - CollectionRoomModel::addInfo((int)$agency->uid,(int)$afterLevelSetting['id']); - } - } public static function boot() @@ -117,34 +104,4 @@ class Uplog extends BaseModel $builder->uniacid(); }); } - /** - * Common: 获取某个用户持有某个等级的名额信息 - * Author: wu-hui - * Time: 2023/10/24 19:04 - * @param $uid - * @param $teamLevelId - * @return int[] - */ - public static function getQuota($uid,$teamLevelId){ - $info = Uplog::uniacid() - ->where('uid',$uid) - ->where('after_level_id',$teamLevelId) - ->orderBy('created_at','ASC') - ->first(); - // 已使用 - $useQuota = TeamDividendAgencyModel::uniacid() - ->where('give_uid',$uid) - ->where('give_level_id',$info['give_limit_level_id']) - ->count(); - - return [ - 'total_quota' => (int)$info->give_limit,// 总数 - 'use_quota' => (int)$useQuota,// 已使用 - 'surplus_quota' => (int)$info->give_limit - (int)$useQuota,// 剩余 - 'give_limit_level_id' => (int)$info->give_limit_level_id,// 升级等级id - ]; - } - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/observers/DealerObserver.php b/plugins/team-dividend/src/observers/DealerObserver.php index 5e32cc9d..62cb0137 100644 --- a/plugins/team-dividend/src/observers/DealerObserver.php +++ b/plugins/team-dividend/src/observers/DealerObserver.php @@ -1,4 +1,14 @@ getOriginal('level') != $model->level) { - /** - * @var TeamDividendAgencyModel $model - */ event(new LevelChangeEvent($model)); - // 判断:如果当前等级人数已经达到限制 则不升级(上限小于等于已存在数量 不能升级到该等级) - // $hasNum = (int)TeamDividendAgencyModel::uniacid()->where('uid','!=',$model->uid)->where('level',$model->level)->count(); - $hasNum = (int)Uplog::uniacid()->where('after_level_id',$model->level)->where('uid','!=',$model->uid)->count(DB::raw('DISTINCT(uid)')); - $levelNumberLimit = (int)TeamDividendLevelModel::uniacid()->where('id',$model->level)->value('number_limit'); - if((int)$levelNumberLimit <= $hasNum && (int)$levelNumberLimit > 0) return false; } } - // 添加前 - public function creating(Model $model){ + public function creating(Model $model) + { /** * @var TeamDividendAgencyModel $model */ event(new LevelChangeEvent($model)); - // 判断:如果当前等级人数已经达到限制 则不升级(上限小于等于已存在数量 不能升级到该等级) - // $hasNum = (int)TeamDividendAgencyModel::uniacid()->where('uid','!=',$model->uid)->where('level',$model->level)->count(); - $hasNum = (int)Uplog::uniacid()->where('after_level_id',$model->level)->where('uid','!=',$model->uid)->count(DB::raw('DISTINCT(uid)')); - $levelNumberLimit = (int)TeamDividendLevelModel::uniacid()->where('id',$model->level)->value('number_limit'); - if((int)$levelNumberLimit <= $hasNum && (int)$levelNumberLimit > 0) return false; - } - - - } diff --git a/plugins/team-dividend/src/services/GetAgentsService.php b/plugins/team-dividend/src/services/GetAgentsService.php index c74fdaf6..52ebbcfc 100644 --- a/plugins/team-dividend/src/services/GetAgentsService.php +++ b/plugins/team-dividend/src/services/GetAgentsService.php @@ -1,6 +1,6 @@ function ($team) { - $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']); - }]); + $team->with(['hasOneLevel']); } ])->whereHas('hasOneParentMember') ->where('member_id', $uid) diff --git a/plugins/team-dividend/src/services/GetAmountService.php b/plugins/team-dividend/src/services/GetAmountService.php index ea383e84..a6ddb4ef 100644 --- a/plugins/team-dividend/src/services/GetAmountService.php +++ b/plugins/team-dividend/src/services/GetAmountService.php @@ -1,6 +1,6 @@ dividendType = $dividendType; $this->agent = $agent; $this->order = $order; $this->order_goods = $order_goods; $this->set = $set; $this->team_goods = $team_goods; $this->finish_ratio = $finish_ratio; - $this->finish_ratio_service = $finish_ratio_service; $this->finish_price = $finish_price; } @@ -60,11 +56,6 @@ class GetAmountService return unserialize($this->team_goods->has_dividend_rates); } - private function getCommissionRates() - { - return unserialize($this->team_goods->commission_rates); - } - /** * @name 商品独立设置-固定金额-解序列化 * @author @@ -163,10 +154,10 @@ class GetAmountService */ public function getAwardHierarchy() { - $award_hierarchy = $this->dividendType == 1 ? $this->agent['cultural_level']['award_hierarchy'] : $this->agent['has_one_level']['award_hierarchy']; + $award_hierarchy = $this->agent['has_one_level']['award_hierarchy']; if ($this->hasPeers()) { $hierarchys = $this->getHierarchys(); - $hierarchy_level = $hierarchys[$this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level']]; + $hierarchy_level = $hierarchys[$this->agent['level']]; if ($hierarchy_level && $hierarchy_level['hierarchy'] > 0) { $award_hierarchy = $hierarchy_level['hierarchy']; } @@ -181,10 +172,10 @@ class GetAmountService */ public function getAwardHierarchyRatio() { - $ratio = $this->dividendType == 1 ? $this->agent['cultural_level']['award_ratio'] : $this->agent['has_one_level']['award_ratio']; + $ratio = $this->agent['has_one_level']['award_ratio']; if ($this->hasPeers()) { $hierarchys = $this->getHierarchys(); - $hierarchy_level = $hierarchys[$this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level']]; + $hierarchy_level = $hierarchys[$this->agent['level']]; $ratio = $hierarchy_level['ratio']; } return $ratio; @@ -198,19 +189,19 @@ class GetAmountService if ($this->hasDividend()) { if ($this->hasDividendRates()) { $dividend_rates = $this->getDividendRates(); - $ratio = $dividend_rates['level_' . ($this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level'])]; - // if (isset($ratio) && $ratio > 0) { + $ratio = $dividend_rates['level_' . $this->agent['level']]; + if (isset($ratio) && $ratio > 0) { // 提成结算金额 $amount = $this->order_goods->payment_amount; return $amount; - // } + } } // 商城商品设置奖励固定金额 if ($this->hasDividendPrices()) { $dividend_prices = $this->getDividendPrices(); // 提成结算金额 - $amount = $this->order_goods->total * $dividend_prices['level_' . ($this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level'])]; + $amount = $this->order_goods->total * $dividend_prices['level_' . $this->agent['level']]; } } if ($this->order->plugin_id == 48 && app('plugins')->isEnabled('hotel-supply')) { @@ -258,7 +249,7 @@ class GetAmountService \Log::debug('经销商特殊结算商城商品1---',$this->order_goods->payment_amount); $dividend_prices = $this->getDividendPrices(); // 提成结算金额 - $this->amount = $this->order_goods->total * $dividend_prices['level_' . ($this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level'])]; + $this->amount = $this->order_goods->total * $dividend_prices['level_' . $this->agent['level']]; $this->fixed = 1; $this->ratio = 0; // 奖励金额 @@ -302,86 +293,30 @@ class GetAmountService // 收银台商品 与 存在独立奖励设置 else 商城 if ($this->hasDividendRate()) { // 经销商奖励比例 - 下级经销商奖励比例 = 奖励比例 - 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']; - } - + $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 { // 商城商品设置奖励比例 else 商城商品设置奖励固定金额 if ($this->hasDividendRates()) { $dividend_rates = $this->getDividendRates(); - $ratio = bcsub($dividend_rates['level_'. ($this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level'])], $this->finish_ratio,2); - $this->finish_ratio = $dividend_rates['level_' . ($this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level'])]; + $ratio = bcsub($dividend_rates['level_'. $this->agent['level']], $this->finish_ratio,2); + $this->finish_ratio = $dividend_rates['level_' . $this->agent['level']]; return $ratio; } } - } - else { - // 基础设置 - 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']; - } + } 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; } } - // 获取生态服务比例 - public function getServiceRatio(){ - // 商品独立设置 else 基础设置 - if($this->hasDividend()){ - // 收银台商品 与 存在独立奖励设置 else 商城 - if($this->hasDividendRate()){ - // 经销商奖励比例 - 下级经销商奖励比例 = 奖励比例 - if($this->dividendType == 1){ - $ratio = bcsub($this->agent['cultural_level']['commission_ratio'],$this->finish_ratio_service,2); - $this->finish_ratio_service = $this->agent['cultural_level']['commission_ratio']; - } - else{ - $ratio = bcsub($this->agent['has_one_level']['commission_ratio'],$this->finish_ratio_service,2); - $this->finish_ratio_service = $this->agent['has_one_level']['commission_ratio']; - } - return $ratio; - } - else{ - // 商城商品设置奖励比例 else 商城商品设置奖励固定金额 - if($this->hasDividendRates()){ - $dividend_rates = $this->getCommissionRates(); - $ratio = bcsub($dividend_rates['level_'.($this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level'])],$this->finish_ratio_service,2); - $this->finish_ratio_service = $dividend_rates['level_'.($this->dividendType == 1 ? $this->agent['cultural_level_id'] : $this->agent['level'])]; - return $ratio; - } - } - } - else{ - // 基础设置 - if($this->dividendType == 1){ - $ratio = bcsub($this->agent['cultural_level']['commission_ratio'],$this->finish_ratio_service,2); - $this->finish_ratio_service = $this->agent['cultural_level']['commission_ratio']; - } - else{ - $ratio = bcsub($this->agent['has_one_level']['commission_ratio'],$this->finish_ratio_service,2); - $this->finish_ratio_service = $this->agent['has_one_level']['commission_ratio']; - } - return $ratio; - } - } - - - /** * 获取最大奖励 */ - public function getTotalDividend(){ + public function getTotalDividend() + { $maxRatio = max(TeamDividendLevelModel::uniacid()->select('dividend_ratio')->get()->toArray()); if ($this->hasDividend()) { @@ -416,13 +351,4 @@ class GetAmountService } - - - - - - - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/services/RedpackFailureService.php b/plugins/team-dividend/src/services/RedpackFailureService.php index a02dfcda..2add01a4 100644 --- a/plugins/team-dividend/src/services/RedpackFailureService.php +++ b/plugins/team-dividend/src/services/RedpackFailureService.php @@ -1,6 +1,6 @@ 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 $upUserDividendAmount = 0;// 上一位用户的经销商佣金提成金额 只有存在佣金时才会刷新该数据,如果用户为领取佣金则该金额保留 直到某位用户获取佣金为止 - - public function setData($order, $set, $buyMember, $order_goods, $agents){ + public function setData($order, $set, $buyMember, $order_goods, $agents) + { $this->order = $order; $this->set = $set; $this->buyMember = $buyMember; @@ -75,34 +81,24 @@ class TeamReturnService $this->team_goods = GoodsTeamDividend::getGoodsByGoodsId($this->order_goods->goods_id)->first(); $this->levels = TeamDividendLevelModel::uniacid()->orderBy('level_weight','asc')->get()->toArray(); $this->flat_prize_limit = 0; - // \Log::debug('经销商创建-team_goods:' . $this->order_goods->goods_id, $this->team_goods ? $this->team_goods->toArray() : []); + \Log::debug('经销商创建-team_goods:' . $this->order_goods->goods_id, $this->team_goods ? $this->team_goods->toArray() : []); + $this->init(); + } public function handle() { if (!$this->team_goods) return; - // 判断:文创空间商品 不参与普通分红;非文创空间商品不参与文创空间相关分红 - $isOpenCultural = (int)GoodsCulturalSpace::uniacid()->where('goods_id',$this->order_goods->goods_id)->value('is_open'); - if($isOpenCultural){ - // 开启文创空间 - // 文创处理 - $this->flat_prize_limit = 0; - $this->dividendType = 1; - $this->init(); - $this->totalDividend(); - $this->running(); - }else{ - // 未开启文创空间 - // 普通处理 - $this->init(); - $this->totalDividend(); - $this->running(); - } + $this->totalDividend(); + $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->dividendType, $this->finish_ratio_service); + + $this->amount_service = new GetAmountService($agent, $this->order, $this->order_goods, $this->set, $this->team_goods, $this->finish_ratio, $this->finish_price); + //商品分红限制 不计入平级奖层级 不算感恩奖 if ($agent['is_black'] || $this->getIsRestrict($agent)) { continue; @@ -113,24 +109,25 @@ class TeamReturnService $this->order_goods->payment_amount = $this->order_goods->goods_price; } } + // 感恩奖 $this->gratitudeAward($agent); + // 经销商奖励 $this->dividendAward($agent); - // 生态服务 - if($this->dividendType == 1) $this->dividendAwardService($agent); // 平级奖 $this->hierarchyAward($agent); // 额外分红 $this->extraDividend($agent); } + } private function totalDividend() { - $amount_service = new GetAmountService('', $this->order, $this->order_goods, $this->set, $this->team_goods, $this->finish_ratio, $this->finish_price,$this->dividendType,$this->finish_ratio_service); + $amount_service = new GetAmountService('', $this->order, $this->order_goods, $this->set, $this->team_goods, $this->finish_ratio, $this->finish_price); // 经销商奖励总金额 不包括感恩奖和平级奖 - $this->totalDividend += $amount_service->getTotalDividend(); + $this->totalDividend = $amount_service->getTotalDividend(); } // 感恩奖 @@ -149,18 +146,17 @@ class TeamReturnService return; } // 如果 已完成经销商奖励金额 * 经销商等级设置的感恩奖比例 <= 0 - 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']); + $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' => $this->dividendType == 1 ? $agent['cultural_level']['award_gratitude'] : $agent['has_one_level']['award_gratitude'], + 'amount' => $this->finish_team_award_amount, + 'dividend_rate' => $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); @@ -169,12 +165,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' => $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, + '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, ]; if ($this->set['notice_event'] == 1) { NoticeLog::create([ @@ -195,12 +191,13 @@ class TeamReturnService // 经销商奖励 private function dividendAward($agent) { + //平级跳出 - if ($this->dividend_level_ids[$this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']]) { + if ($this->dividend_level_ids[$agent['level']]) { return; } // 平级奖处理初始化 - $this->dividend_level_ids[$this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']]['hierarchy'] = 0; + $this->dividend_level_ids[$agent['level']]['hierarchy'] = 0; $this->hierarchy_uid = $agent['uid']; // 分红比例 @@ -216,7 +213,7 @@ class TeamReturnService return; } - $this->upUserDividendAmount = $dividend_amount; + // 计算基数 $amount = $this->amount_service->amount; @@ -229,6 +226,7 @@ class TeamReturnService ]; // 分红 $dividend_model = $this->addDividend($agent, $dividendData); + $member = Member::getMemberByUid($agent['uid'])->with('hasOneFans')->first(); $notice = [ 'lower_level_name' => $this->buyMember->nickname, @@ -255,69 +253,25 @@ class TeamReturnService $this->setAttributeTheValue($dividendData['dividend_amount'], $agent); } - // 生态服务 - private function dividendAwardService($agent){ - // 生态服务比例 - $ratio = $this->amount_service->getServiceRatio(); - // 生态服务金额 - $dividend_amount = $this->amount_service->getDividendAmount($ratio); - if($dividend_amount <= 0) return; - // 计算基数 - $amount = $this->amount_service->amount; - $dividendData = [ - 'dividend_amount' => $dividend_amount, - 'type' => 6, - 'amount' => $amount, - 'dividend_rate' => $ratio, - 'lower_level_rate' => $this->finish_ratio_service ?: 0 - ]; - // 生态服务受益 - $dividend_model = $this->addDividend($agent,$dividendData); - $member = Member::getMemberByUid($agent['uid'])->with('hasOneFans')->first(); - $notice = [ - 'lower_level_name' => $this->buyMember->nickname, - 'order_amount' => $this->order->price, - 'amount' => $dividendData['amount'], - 'dividendRate' => $ratio, - 'rate' => $this->finish_ratio_service, - 'dividend_amount' => $dividendData['dividend_amount'], - 'order_sn' => $this->order->order_sn, - 'dividend_id' => $dividend_model ? $dividend_model->id : 0, - ]; - if($this->set['notice_event'] == 1){ - NoticeLog::create([ - 'uniacid' => \YunShop::app()->uniacid, - 'uid' => $agent['uid'], - 'order_id' => $this->order->id, - 'type' => $dividendData['type'], - 'notice_data' => json_encode($notice), - ]); - } - else{ - MessageService::dividendOrder($notice,$member->hasOneFans); - } - // 属性赋值 - $this->finish_ratio_service = $this->amount_service->finish_ratio_service; - //保存已获得分红的分红金额 感恩奖触发就清0 - $this->finish_team_award_amount = $dividend_amount; - //保存已获得分红的分红金额 (ps:上级是固定金额 减去 该金额) - $this->finish_price = $this->amount_service->amount; - // 获得奖励的UID - $this->award_uid = $agent['uid']; - $this->obtainInfos[$this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']] = $dividend_amount; - } - // 平级奖 private function hierarchyAward($agent) { // 是否开启平级奖 - if (!$this->set['is_flat_prize']) return; + if (!$this->set['is_flat_prize']) { + return; + } // 商品是否开启平级奖 - if (!$this->amount_service->isHierarchy()) return; - if ($this->flat_prize_limit) return; + if (!$this->amount_service->isHierarchy()) { + return; + } + + if ($this->flat_prize_limit) { + \Log::debug('经销商平级奖限制,取消平级奖', $this->order->id.'_'.$this->order_goods->id.'_'.$agent['uid']); + return; + } // 经销商奖励层级 经销商等级奖励层级 >= 当前奖励层级 - $dividend_level = $this->dividend_level_ids[$this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']]; + $dividend_level = $this->dividend_level_ids[$agent['level']]; if ($dividend_level == null) { return; } @@ -326,20 +280,17 @@ class TeamReturnService if ($dividend_level && ($award_hierarchy <= $dividend_level['hierarchy'] || $this->hierarchy_uid == $agent['uid'])) { return; } - // 平级奖奖励比例 $award_ratio = $this->amount_service->getAwardHierarchyRatio(); - if (!isset($award_ratio) || $award_ratio <= 0) return; - // 计算结算金额 普通经销商为订单金额,文创经销商为上一位的分红佣金 - if($this->dividendType == 1){ - // 文创等级 使用上一位的分红佣金 - $amount = $this->upUserDividendAmount; - }else{ - // 普通等级 使用订单金额 - $amount = $this->amount_service->getAwardHierarchyAmount(); + if (!isset($award_ratio) || $award_ratio <= 0) { + return; + } + $amount = $this->amount_service->getAwardHierarchyAmount(); + if ($amount <= 0) { + return; } - if ($amount <= 0) return; $dividend_amount = proportionMath($amount, $award_ratio); + $dividendData = [ 'amount' => $amount, 'dividend_rate' => $award_ratio, @@ -348,9 +299,10 @@ class TeamReturnService 'hierarchy' => $dividend_level['hierarchy'] + 1, 'dividend_amount' => $dividend_amount ]; + // 是否开启平级奖下级获得经销商奖励计算方式 if ($this->set['calculate_formula'] == 1) { - $finishPrice = $this->obtainInfos[$this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']]; + $finishPrice = $this->obtainInfos[$agent['level']]; if (!$finishPrice) { return; } @@ -380,21 +332,11 @@ class TeamReturnService 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; - } + 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']); @@ -408,11 +350,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' => $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, + '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, ]; if ($this->set['notice_event'] == 1) { NoticeLog::create([ @@ -427,7 +369,7 @@ class TeamReturnService } // 平级奖层数增加 - $this->dividend_level_ids[$this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']]['hierarchy'] += 1; + $this->dividend_level_ids[$agent['level']]['hierarchy'] += 1; } //额外分红 @@ -442,44 +384,27 @@ class TeamReturnService return; } - if (!$dividend_extra['level_' . ($this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level'])]) { + if (!$dividend_extra['level_' . $agent['level']]) { return; } //计算总获得分红 - $dividendData['amount'] = $this->order_goods->total * $dividend_extra['level_' . ($this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level'])]; + $dividendData['amount'] = $this->order_goods->total * $dividend_extra['level_' . $agent['level']]; - 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']; + $agent['has_one_level']['dividend_ratio'] = 1; + + if (!isset($this->extraHierarchy['first_weight'])) { + $this->extraHierarchy['first_weight'] = $agent['has_one_level']['level_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; } - 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; } @@ -490,7 +415,7 @@ class TeamReturnService } $dividendData['member_id'] = $agent['uid']; - $dividendData['agent_level'] = $this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']; + $dividendData['agent_level'] = $agent['level']; $dividendData['dividend_rate'] = 0; $dividendData['type'] = 3; $dividendData['lower_level_rate'] = $this->finish_ratio; @@ -526,27 +451,41 @@ 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' => $this->dividendType == 1 ? $agent['cultural_level_id'] : $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'] < 6) { - if($dividendData['type'] == 1) $dividendData['type'] = 5; - else if($dividendData['type'] == 0) $dividendData['type'] = 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); @@ -578,7 +517,7 @@ class TeamReturnService // $this->dividend_level_ids[$agent['level']]['hierarchy'] = 0; // 获得奖励的UID $this->award_uid = $agent['uid']; - $this->obtainInfos[$this->dividendType == 1 ? $agent['cultural_level_id'] : $agent['level']] = $dividend_amount; + $this->obtainInfos[$agent['level']] = $dividend_amount; } /** @@ -630,9 +569,5 @@ class TeamReturnService $this->extraCount = 0; // 获得经销商奖励的等级id与金额 $this->obtainInfos = []; - // 上一位获取的佣金 只有存在新佣金时才会刷新,否则不刷新 - $this->upUserDividendAmount = 0; - // 已获得生态服务奖励的比例 - $this->finish_ratio_service = 0; } } \ No newline at end of file diff --git a/plugins/team-dividend/src/services/TestService.php b/plugins/team-dividend/src/services/TestService.php index 3a97e0b5..b0e6116d 100644 --- a/plugins/team-dividend/src/services/TestService.php +++ b/plugins/team-dividend/src/services/TestService.php @@ -1,6 +1,6 @@ $name->nickname, 'dividend_id' => $item['id'], ]; - // \Log::debug('===================hahaha==========',$notice); + \Log::debug('===================hahaha==========',$notice); MessageService::dividend($notice, $member->hasOneFans); } DB::commit(); diff --git a/plugins/team-dividend/src/services/upgrate/AgentsService.php b/plugins/team-dividend/src/services/upgrate/AgentsService.php index 75df2bf4..561ba447 100644 --- a/plugins/team-dividend/src/services/upgrate/AgentsService.php +++ b/plugins/team-dividend/src/services/upgrate/AgentsService.php @@ -1,6 +1,6 @@ agents; } - private function _init(){ + + private function _init() + { // 开启内购 //if ($this->setting['buy_self'] == 1) { - $teamDividend = TeamDividendAgencyModel::select(['uid','level','cultural_level_id']) - ->where('uid',$this->uid) - ->first(); - $this->agents[] = [ - 'uid' => $this->uid, - 'teamDividend' => $teamDividend - ]; + $teamDividend = TeamDividendAgencyModel::select(['uid', 'level']) + ->where('uid', $this->uid) + ->first(); + $this->agents[] = [ + 'uid' => $this->uid, + 'teamDividend' => $teamDividend + ]; //} // 上级 - $agents = MemberParent::with([ - 'hasOneTeamDividendAgency' => function($query){ - $query->select(['uid','level','cultural_level_id']); - } - ]) - ->where('member_id',$this->uid) - ->orderBy('level','asc') + $agents = MemberParent::with(['hasOneTeamDividendAgency']) + ->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 ]; } } diff --git a/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php b/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php index 9873b7e8..77f03b9b 100644 --- a/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php +++ b/plugins/team-dividend/src/services/upgrate/UpgrateConditionService.php @@ -1,12 +1,13 @@ uid = $uid; - $this->set = $set; - $this->upgradeParase = $upgradeParase; - $this->typeName = $typeName; - $this->order_status = $order_status; - $this->order = $order; + public function __construct($uid, $set, $upgradeParase, $uniacid, $typeName, $order_status, $order, $uplogService) + { + $this->uid = $uid; + $this->set = $set; + $this->upgradeParase = $upgradeParase; + $this->typeName = $typeName; + $this->order_status = $order_status; + $this->order = $order; \YunShop::app()->uniacid = $uniacid; - $this->levelType = $levelType; + $this->uplogService = $uplogService; } - private function addLogChild($result,$condition = NULL){ + + private function addLogChild($result, $condition = null) + { $data = [ //'log_id' => $this->log_id, 'type_name' => $this->typeName, - 'result' => $result + 'result' => $result ]; - if($condition == NULL){ + if ($condition == null) { $data['condition'] = $this->upgradeParase[$this->typeName]; - } - else{ + } else { $data['condition'] = $condition; } // 记录详情 LogChild::create($data); } - private function addErrorChild($condition){ + + private function addErrorChild($condition) + { $data = [ //'log_id' => $this->log_id, 'type_name' => $this->typeName, - 'result' => -1 + 'result' => -1 ]; - if($condition == NULL){ + if ($condition == null) { $data['condition'] = $this->upgradeParase[$this->typeName]; - } - else{ + } else { $data['condition'] = $condition; } // 记录详情 LogChild::create($data); } + /** * @name 一级客户订单金额满,不加[订单状态]限制 - * @return bool * @author + * @return bool */ - public function firstMoney(){ + public function firstMoney() + { $type = intval($this->upgradeParase[$this->typeName]); - if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; - } - else{ - $column = 'yz_order.price'; + }else{ + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户'.$amount_name.'满', 'func_name' => 'firstMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $orderPrice = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid) - ->where('yz_member_children.level',1) + + $orderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid) + ->where('yz_member_children.level', 1) ->sum($column); - $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; + $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($orderPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户'.$amount_name.'满', 'func_name' => 'firstMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 一级客户订单数量满,指定商品ID,不加[订单状态]限制 - * @return bool * @author + * @return bool */ - public function firstOrderCount(){ + public function firstOrderCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户订单数量满,指定商品ID', 'func_name' => 'firstOrderCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_order_count_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $orderCount = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid) - ->where('yz_member_children.level',1) + + $orderCount = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid) + ->where('yz_member_children.level', 1) ->count('yz_order.id'); // first_order_count_to_goods $firstOrderCountToGoods = intval($this->upgradeParase['first_order_count_to_goods']); - if($firstOrderCountToGoods > 0){ - $orderCount = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + if ($firstOrderCountToGoods > 0) { + $orderCount = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->join('yz_order_goods',function($join){ - $join->on('yz_order_goods.order_id','=','yz_order.id'); + ->join('yz_order_goods',function ($join){ + $join->on('yz_order_goods.order_id', '=', 'yz_order.id'); }) - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid) - ->where('yz_member_children.level',1) - ->where('yz_order_goods.goods_id',$firstOrderCountToGoods) + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid) + ->where('yz_member_children.level', 1) + ->where('yz_order_goods.goods_id', $firstOrderCountToGoods) ->count('yz_order.id'); } + $condition = $orderCount >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($orderCount); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户订单数量满,指定商品ID', 'func_name' => 'firstOrderCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_order_count_to_goods']), - 'complete' => $orderCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 二级客户订单金额满or一、二级客户订单金额满,不加[订单状态]限制 order_money_2 or order_money - * @return bool * @author + * @return bool */ - public function orderMoney(){ - if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + public function orderMoney() + { + if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; - } - else{ - $column = 'yz_order.price'; + }else{ + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } + $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户'.$amount_name.'满', 'func_name' => 'orderMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + // order_money_2 $ret[2] = 2 or order_money - $ret = explode('_',$this->typeName); - if(isset($ret[2]) && intval($ret[2]) > 0){ + $ret = explode('_', $this->typeName); + if (isset($ret[2]) && intval($ret[2]) > 0) { $logremark = '只统计二级'; - $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid) - ->where('yz_member_children.level',intval($ret[2])); - } - else{ + $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid) + ->where('yz_member_children.level', intval($ret[2])); + } else { $logremark = '统计一二级'; - $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid) - ->whereIn('yz_member_children.level',[1,2]); + $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid) + ->whereIn('yz_member_children.level', [1, 2]); } + $orderPrice = $build->sum($column); + $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($orderPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户'.$amount_name.'满['.$logremark.']', 'func_name' => 'orderMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 二级客户订单数量满,不加[订单状态]限制 - * @return bool * @author + * @return bool */ - public function orderNum(){ + public function orderNum() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '二级客户订单数量满', 'func_name' => 'orderNum', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + // order_num_2 $ret[2] = 2 - $ret = explode('_',$this->typeName); - $orderCount = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid) - ->where('yz_member_children.level',intval($ret[2])) + $ret = explode('_', $this->typeName); + $orderCount = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid) + ->where('yz_member_children.level', intval($ret[2])) ->count('yz_order.id'); + $condition = $orderCount >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($orderCount); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '二级客户订单数量满', 'func_name' => 'orderNum', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 一、二级客户订单数量满,不加[订单状态]限制 - * @return bool * @author + * @return bool */ - public function orderCount(){ + public function orderCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户订单数量满', 'func_name' => 'orderCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $orderPrice = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid) - ->whereIn('yz_member_children.level',[1,2]) + + $orderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) + ->join('yz_order','yz_member_children.child_id', '=', 'yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid) + ->whereIn('yz_member_children.level', [1, 2]) ->count('yz_order.id'); + $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($orderPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户订单数量满', 'func_name' => 'orderCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 直推参与认购人数达到xx人 - * @return bool * @author + * @return bool */ - public function firstLowerSubscription(){ - if(!app('plugins')->isEnabled('subscription')){ - return FALSE; + public function firstLowerSubscription() + { + if (!app('plugins')->isEnabled('subscription')) { + return false; } $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直推参与认购人数达到xx人', 'func_name' => 'firstLowerSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + $childIds = MemberChild::select() ->where('member_id',$this->uid) ->where('level',1) ->pluck('child_id'); - if($childIds->isEmpty()){ - return FALSE; + if ($childIds->isEmpty()) { + return false; } - $count = BuyModel::whereIn('uid',$childIds) - ->where('quantity','>',0) - ->count(DB::raw('DISTINCT(uid)')); + + $count = BuyModel::whereIn('uid', $childIds)->where('quantity', '>', 0)->count(DB::raw('DISTINCT(uid)')); $condition = $count >= $this->upgradeParase[$this->typeName]; + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直推参与认购人数达到['.$count.']人', 'func_name' => 'firstLowerSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + + return false; } + /** * @name 团队参与认购额度累计达到xx额度 - * @return bool * @author + * @return bool */ - public function teamSubscription(){ - if(!app('plugins')->isEnabled('subscription')){ - return FALSE; + public function teamSubscription() + { + if (!app('plugins')->isEnabled('subscription')) { + return false; } $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队参与认购额度累计达到xx额度', 'func_name' => 'teamSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $total = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_subscription_user_buy','yz_member_children.child_id','=','yz_subscription_user_buy.uid') + + $total = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id'])->join('yz_subscription_user_buy','yz_member_children.child_id','=','yz_subscription_user_buy.uid') ->where('yz_member_children.member_id',$this->uid) ->sum('yz_subscription_user_buy.quantity'); + $condition = $total >= $this->upgradeParase[$this->typeName]; $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队参与认购额度累计达到['.$total.']额度', 'func_name' => 'teamSubscription', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + + return false; } + /** * @name 团队业绩金额满,[订单状态]-已完成 - * @return bool * @author + * @return bool */ - public function teamOrderAmount(){ + public function teamOrderAmount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; }else{ - $column = 'yz_order.price'; + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } - if(!$type){ + if (!$type) { + //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩'.$amount_name.'满', 'func_name' => 'teamOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - // 获取直推下级列表 - $subIds = MemberChild::uniacid() - ->where('level',1) - ->where('member_id',$this->uid) - ->pluck('child_id') - ->toArray(); - $subPerformance = [];// 每条线的业绩 - foreach($subIds as $subUid){ - $lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray(); - $lineAllUid[] = $subUid; - $subPerformance[$subUid] = Order::uniacid() - ->leftJoin('yz_order_goods','yz_order_goods.order_id','yz_order.id') - ->leftJoin('yz_goods_cultural_space','yz_goods_cultural_space.goods_id','yz_order_goods.goods_id') - ->whereIn('yz_order.uid',$lineAllUid) - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_goods_cultural_space.is_open', $this->levelType == 1 ? 1 : 0) - ->sum(Setting::get('plugin.team_dividend.level_up_choose') == 1 ? 'yz_order_goods.goods_price' : 'yz_order_goods.payment_amount'); - // $subPerformance[$subUid] = Order::whereIn('uid',$lineAllUid)->where('status','>=',$this->order_status)->sum($column); - } - // 计算团队总业绩 判断:是否去除最大业绩 - $maxAmount = 0; - if((int)$this->upgradeParase['team_order_amount_close_max'] == 1) $maxAmount = max($subPerformance); - $teamOrderPrice = (float)sprintf("%.2f",array_sum($subPerformance) - $maxAmount); - // 判断:是否开启自购 - $logremark = '不计算自购订单'; + + $teamOrderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id'])->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id',$this->uid) + ->sum($column); + $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ - $logremark = '计算自购订单'; - $teamOrderPrice += Order::where('uid',$this->uid) - ->where('status','>=',$this->order_status) + $logremark = '计算自购订单'; + $teamOrderPrice += Order::where('uid', $this->uid) + ->where('status', '>=', $this->order_status) ->sum($column); } - // 判断:是否符合条件 + + $condition = $teamOrderPrice >= $this->upgradeParase[$this->typeName]; + + /*dump($this->typeName); + dump($this->upgradeParase[$this->typeName]); + dump($teamOrderPrice); + return true;*/ + + // 记录详情 + //$this->addLogChild($teamOrderPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩'.$amount_name.'满['.$logremark.']', 'func_name' => 'teamOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $teamOrderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $teamOrderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition) return TRUE; - return FALSE; + + if ($condition) { + return true; + } + return false; } /** * @name 团队自营订单实付金额满,[订单状态]-已完成 - * @return bool * @author + * @return bool */ - public function teamShopOrderAmount(){ + public function teamShopOrderAmount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + + if (!$type) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队自营订单实付金额满', 'func_name' => 'teamShopOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $teamOrderPrice = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) - ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_order.plugin_id',0) + + $teamOrderPrice = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id'])->join('yz_order','yz_member_children.child_id','=','yz_order.uid') + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_order.plugin_id', 0) ->where('yz_member_children.member_id',$this->uid) ->sum('yz_order.price'); - $logremark = '不计算自购订单'; + $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ - $logremark = '计算自购订单'; - $teamOrderPrice += Order::where('uid',$this->uid) - ->where('status','>=',$this->order_status) - ->where('plugin_id',0) + $logremark = '计算自购订单'; + $teamOrderPrice += Order::where('uid', $this->uid) + ->where('status', '>=', $this->order_status) + ->where('plugin_id', 0) ->sum('yz_order.price'); } + + $condition = $teamOrderPrice >= $this->upgradeParase[$this->typeName]; + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队自营订单实付金额满['.$logremark.']', 'func_name' => 'teamShopOrderAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $teamOrderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $teamOrderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 团队商品数量满,指定商品ID,[订单状态]-已完成 - * @return bool * @author + * @return bool */ - public function teamGoodsAmount(){ + public function teamGoodsAmount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商品数量满,指定商品ID', 'func_name' => 'teamGoodsAmount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_goods_amount_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + + $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->join('yz_order_goods',function($join){ - $join->on('yz_order_goods.order_id','=','yz_order.id'); + ->join('yz_order_goods',function ($join){ + $join->on('yz_order_goods.order_id', '=', 'yz_order.id'); }) - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_member_children.member_id',$this->uid); + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_member_children.member_id', $this->uid); + $countToGoods = intval($this->upgradeParase['team_goods_amount_to_goods']); - if($countToGoods > 0){ - $build->where('yz_order_goods.goods_id',$countToGoods); + if ($countToGoods > 0) { + $build->where('yz_order_goods.goods_id', $countToGoods); } $team_goods_total = $build->sum('yz_order_goods.total'); - $logremark = '不计算自购订单'; + $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ $logremark = '计算自购订单'; //加上指定商品的条件 - $self_build = Order::where('uid',$this->uid) - ->where('status','>=',$this->order_status); - if($countToGoods > 0){ - $self_build->whereHas('orderGoods',function($query) use ($countToGoods){ + $self_build = Order::where('uid', $this->uid)->where('status', '>=', $this->order_status); + if ($countToGoods > 0) { + $self_build ->whereHas('orderGoods',function ($query) use($countToGoods){ $query->where('goods_id',$countToGoods); }); } $team_goods_total += $self_build->sum('goods_total'); } + $condition = $team_goods_total >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($team_goods_total); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商品数量满,指定商品ID['.$logremark.']', 'func_name' => 'teamGoodsAmount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_goods_amount_to_goods']), - 'complete' => $team_goods_total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $team_goods_total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 直属经销商人数,指定商品ID - * @return bool * @author + * @return bool */ - public function firstLowerTeamCount(){ + public function firstLowerTeamCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直属经销商人数,指定商品ID', 'func_name' => 'firstLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_lower_team_count_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + $agentCount = TeamDividendAgencyModel::getFirstAgencyNum($this->uid); + $firstLowerTeamCountToGoods = intval($this->upgradeParase['first_lower_team_count_to_goods']); - if($firstLowerTeamCountToGoods > 0){ + if ($firstLowerTeamCountToGoods > 0) { $agentCount = MemberChild::select() - ->whereHas('hasOneTeam',function($team){ - $team->select(['id','uid']); + ->whereHas('hasOneTeam', function ($team) { + $team->select(['id', 'uid']); }) - ->whereHas('hasManyOrder',function($order) use ($firstLowerTeamCountToGoods){ - $order->whereHas('hasManyOrderGoods',function($order_goods) use ($firstLowerTeamCountToGoods){ - $order_goods->where('goods_id',$firstLowerTeamCountToGoods); + ->whereHas('hasManyOrder', function ($order) use ($firstLowerTeamCountToGoods) { + $order->whereHas('hasManyOrderGoods', function ($order_goods) use ($firstLowerTeamCountToGoods) { + $order_goods->where('goods_id', $firstLowerTeamCountToGoods); }); }) - ->where('member_id',$this->uid) - ->where('level',1) + ->where('member_id', $this->uid) + ->where('level', 1) ->uniacid() ->count(); } + $condition = $agentCount >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($agentCount); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '直属经销商人数,指定商品ID', 'func_name' => 'firstLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_lower_team_count_to_goods']), - 'complete' => $agentCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $agentCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 团队经销商人数 - * @return bool * @author + * @return bool */ - public function allLowerTeamCount(){ + public function allLowerTeamCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队经销商人数', 'func_name' => 'allLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $children = MemberChild::uniacid() - ->select(['child_id']) - ->where('member_id',$this->uid) - ->get() - ->toArray(); - $total_ids = array_column($children,'child_id'); + + $children = MemberChild::uniacid()->select(['child_id'])->where('member_id',$this->uid)->get()->toArray(); + $total_ids = array_column($children,'child_id'); $agentCount = 0; - foreach(array_chunk($total_ids,5000) as $ids){ - $agentCount += TeamDividendAgencyModel::whereIn('uid',$ids) - ->count(); + foreach (array_chunk($total_ids,5000) as $ids) { + $agentCount += TeamDividendAgencyModel::whereIn('uid', $ids)->count(); } $condition = $agentCount >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($agentCount); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队经销商人数', 'func_name' => 'allLowerTeamCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $agentCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $agentCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 一级客户人数满 - * @return bool * @author + * @return bool */ - public function firstLowerCount(){ + public function firstLowerCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户人数满', 'func_name' => 'firstLowerCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + $fisrtCount = MemberChild::select() - ->where('member_id',$this->uid) - ->where('level',1) + ->where('member_id', $this->uid) + ->where('level', 1) ->count(); + $condition = $fisrtCount >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($fisrtCount); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户人数满', 'func_name' => 'firstLowerCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $fisrtCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $fisrtCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 自购订单金额满 - * @return bool * @author + * @return bool */ - public function selfBuyMoney(){ + public function selfBuyMoney() + { $type = intval($this->upgradeParase[$this->typeName]); - if(Setting::get('plugin.team_dividend.level_up_choose') == 1){ - $column = 'yz_order.goods_price'; + if (Setting::get('plugin.team_dividend.level_up_choose') == 1){ + $column = 'yz_order.goods_price'; $amount_name = '订单商品现价'; - } - else{ - $column = 'yz_order.price'; + }else{ + $column = 'yz_order.price'; $amount_name = '订单实付金额'; } - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购'.$amount_name.'满', 'func_name' => 'selfBuyMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $orderPrice = Order::where('uid',$this->uid) - ->where('status','>=',$this->order_status) + + $orderPrice = Order::where('uid', $this->uid) + ->where('status', '>=', $this->order_status) ->sum($column); - $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; + $condition = $orderPrice >= $this->upgradeParase[$this->typeName]; + + // 记录详情 //$this->addLogChild($orderPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购'.$amount_name.'满', 'func_name' => 'selfBuyMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 自购订单数量满 - * @return bool * @author + * @return bool */ - public function selfBuyCount(){ + public function selfBuyCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购订单数量满', 'func_name' => 'selfBuyCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $orderCount = Order::where('uid',$this->uid) - ->where('status','>=',$this->order_status) + + $orderCount = Order::where('uid', $this->uid) + ->where('status', '>=', $this->order_status) ->count(); + $condition = $orderCount >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($orderCount); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '自购订单数量满', 'func_name' => 'selfBuyCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $orderCount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $orderCount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 结算分红金额满 - * @return bool * @author + * @return bool */ - public function settleMoney(){ + public function settleMoney() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '结算分红金额满', 'func_name' => 'settleMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $amount = TeamDividendModel::uniacid() - ->where('member_id',$this->uid) - ->where('status',1) + + $amount = TeamDividendModel::uniacid() + ->where('member_id', $this->uid) + ->where('status', 1) ->sum('dividend_amount'); $condition = $amount >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($amount); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '结算分红金额满', 'func_name' => 'settleMoney', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $amount, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $amount, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 一级客户消费满first_cost_count,人数达到 first_cost_num - * @return bool * @author + * @return bool */ - public function firstCostCount(){ + public function firstCostCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type || !intval($this->upgradeParase['first_cost_num'])){ + + if (!$type || !intval($this->upgradeParase['first_cost_num'])) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户消费满,人数达到', 'func_name' => 'firstCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_cost_num']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $member = YzMemberModel::childFirstMember($this->uid) - ->get(); - $count = 0; - if($member){ - foreach($member as $rows){ - $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id,$this->order_status); - if($price_total >= $this->upgradeParase[$this->typeName]){ + + $member = YzMemberModel::childFirstMember($this->uid)->get(); + $count = 0; + if ($member) { + foreach ($member as $rows) { + $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id, $this->order_status); + if ($price_total >= $this->upgradeParase[$this->typeName]) { $count++; } } } $condition = $count >= $this->upgradeParase['first_cost_num']; + // 记录详情 //$this->addLogChild($count, $this->upgradeParase['first_cost_num']); + /*$data = [ 'log_id' => $this->log_id, 'type_name' => 'first_cost_num', @@ -931,767 +1058,875 @@ class UpgrateConditionService{ 'condition' => $this->upgradeParase['first_cost_num'] ]; LogChild::create($data);*/ + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一级客户消费满,人数达到', 'func_name' => 'firstCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_cost_num']), - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 一级客户消费满first_second_cost_count,人数达到 first_second_cost_num - * @return bool * @author + * @return bool */ - public function firstSecondCostCount(){ + public function firstSecondCostCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type || !intval($this->upgradeParase['first_second_cost_num'])){ + + if (!$type || !intval($this->upgradeParase['first_second_cost_num'])) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户消费满,人数达到', 'func_name' => 'firstSecondCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_second_cost_num']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $member = MemberParent::uniacid() - ->where('parent_id',$this->uid) - ->whereIn('level',[1,2]) - ->get(); - $count = 0; - $condition = FALSE; - if($member){ - foreach($member as $rows){ - $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id,$this->order_status); - if($price_total >= $this->upgradeParase[$this->typeName]){ + + $member = MemberParent::uniacid()->where('parent_id',$this->uid)->whereIn('level',[1,2])->get(); + + $count = 0; + $condition = false; + if ($member) { + foreach ($member as $rows) { + $price_total = OrderModel::statisticsMemberGoodsPrice($rows->member_id, $this->order_status); + if ($price_total >= $this->upgradeParase[$this->typeName]) { $count++; if($count >= $this->upgradeParase['first_second_cost_num']){ - $condition = TRUE; + $condition = true; break; } } } } + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '一、二级客户消费满,人数达到', 'func_name' => 'firstSecondCostCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['first_second_cost_num']), - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + + /** * @name 团队商家数量满 - * @return bool * @author + * @return bool */ - public function teamMerchantsCount(){ + public function teamMerchantsCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; - } - $exist_supplier = app('plugins')->isEnabled('supplier'); - $exist_store = app('plugins')->isEnabled('store-cashier'); - $count = 0; - if($exist_supplier || $exist_store){ - $childIds = MemberChild::select('child_id') - ->where('member_id',$this->uid) - ->pluck('child_id'); - if($exist_supplier){ - $supplierCount = Supplier::whereIn('member_id',$childIds) + return false; + } + + $exist_supplier = app('plugins')->isEnabled('supplier'); + $exist_store = app('plugins')->isEnabled('store-cashier'); + $count = 0; + if ($exist_supplier || $exist_store) { + $childIds = MemberChild::select('child_id') + ->where('member_id', $this->uid) + ->pluck('child_id'); + if ($exist_supplier) { + + $supplierCount = Supplier::whereIn('member_id', $childIds) ->count(); + $count += $supplierCount; } - if($exist_store){ + if ($exist_store) { - $storeCount = Store::whereIn('uid',$childIds) + $storeCount = Store::whereIn('uid', $childIds) ->count(); + $count += $storeCount; } + $condition = $count >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($count); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } } $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队商家数量满', 'func_name' => 'teamMerchantsCount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行[没开启供应商或门店插件(供应商状态:'.$exist_supplier.'|门店状态'.$exist_store.')]' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行[没开启供应商或门店插件(供应商状态:'.$exist_supplier.'|门店状态'.$exist_store.')]' ]); - return FALSE; + return false; } + /** * @name 团队下级人数满,指定商品ID - * @return bool * @author + * @return bool */ - public function teamMemberCount(){ + public function teamMemberCount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队下级人数满,指定商品ID', 'func_name' => 'teamMemberCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_member_count_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + $count = MemberChild::select() - ->where('member_id',$this->uid) + ->where('member_id', $this->uid) ->uniacid() ->count(); // 指定商品的团队下级人数 $teamMemberCountToGoods = intval($this->upgradeParase['team_member_count_to_goods']); - if($teamMemberCountToGoods > 0){ + if ($teamMemberCountToGoods > 0) { $count = MemberChild::select() - ->whereHas('hasManyOrder',function($order) use ($teamMemberCountToGoods){ - $order->whereHas('hasManyOrderGoods',function($order_goods) use ($teamMemberCountToGoods){ - $order_goods->where('goods_id',$teamMemberCountToGoods); + ->whereHas('hasManyOrder', function ($order) use ($teamMemberCountToGoods) { + $order->whereHas('hasManyOrderGoods', function ($order_goods) use ($teamMemberCountToGoods) { + $order_goods->where('goods_id', $teamMemberCountToGoods); }); }) - ->where('member_id',$this->uid) + ->where('member_id', $this->uid) ->uniacid() ->count(); } $condition = $count >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($count); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队下级人数满,指定商品ID', 'func_name' => 'teamMemberCount', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_member_count_to_goods']), - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 购买指定商品 - * @return bool * @author + * @return bool */ - public function goods(){ + public function goods() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品', 'func_name' => 'goods', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - if($this->order){ - $order_goods = $this->order->hasManyOrderGoods->where('goods_id',$this->upgradeParase[$this->typeName]) - ->where('uid',$this->uid) - ->first(); - if($order_goods){ + + if ($this->order) { + $order_goods = $this->order->hasManyOrderGoods->where('goods_id', $this->upgradeParase[$this->typeName])->where('uid',$this->uid)->first(); + if ($order_goods) { //$this->addLogChild(1); //return true; - $condition = TRUE; + $condition = true; } } - if(!$condition){ - $condition = OrderModel::assignGoodsToMember($this->uid,$this->upgradeParase[$this->typeName],$this->order_status); + + if (!$condition) { + $condition = OrderModel::assignGoodsToMember($this->uid, $this->upgradeParase[$this->typeName], $this->order_status); } + + /*dump($this->typeName); dump($condition); - return true;*/ // 记录详情 + return true;*/ + + // 记录详情 //$this->addLogChild($condition); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品', 'func_name' => 'goods', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $condition, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $condition, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 购买指定商品之一 - * @return bool * @author + * @return bool */ - public function manyGood(){ - if(!$this->upgradeParase[$this->typeName]){ + public function manyGood() + { + if (!$this->upgradeParase[$this->typeName]) { //$this->addErrorChild($type); $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品之一', 'func_name' => 'manyGood', 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $condition = OrderModel::assignManyGoodToMember($this->uid,$this->upgradeParase[$this->typeName],$this->order_status); + + $condition = OrderModel::assignManyGoodToMember($this->uid, $this->upgradeParase[$this->typeName], $this->order_status); + // 记录详情 //$this->addLogChild($condition); - if(is_array($this->upgradeParase[$this->typeName])){ + if (is_array($this->upgradeParase[$this->typeName])) { $goodsIds = '|'; - foreach($this->upgradeParase[$this->typeName] as $item){ - $goodsIds .= $item.'|'; + foreach ($this->upgradeParase[$this->typeName] as $item) { + $goodsIds .= $item . '|'; } } $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '购买指定商品之一', 'func_name' => 'manyGood', 'condition' => $goodsIds, - 'complete' => $condition, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $condition, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 指定一个经销商等级下的人数满足多少人(直推) - * @return bool * @author + * @return bool */ - public function level(){ - $ret = explode('_',$this->typeName); + public function level() + { + $ret = explode('_', $this->typeName); + $type = intval($ret[2]); - if(!$type){ + if (!$type) { //$this->addErrorChild($ret[2]); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(直推)', 'func_name' => 'level', 'condition' => '等级id['.$ret[1].']', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $count = TeamDividendAgencyModel::getLevelNumAgency($this->uid,$ret[1]); + $count = TeamDividendAgencyModel::getLevelNumAgency($this->uid, $ret[1]); $condition = $count >= $ret[2]; + // 记录详情 //$this->addLogChild($count, $ret[2]); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(直推)', 'func_name' => 'level', 'condition' => '等级id['.$ret[1].']条件['.$ret[1].']', - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } - public function teamDividendLevelList(){ - if(!$this->team_dividend_level_list){ - $this->team_dividend_level_list = TeamDividendLevelModel::uniacid() - ->get(); + + public function teamDividendLevelList() + { + if (!$this->team_dividend_level_list) { + $this->team_dividend_level_list = TeamDividendLevelModel::uniacid()->get(); } return $this->team_dividend_level_list; } + + public function firstChildLevel(){ - $ret = explode('_',$this->typeName); - if(!$type = intval($ret[4])){ + $ret = explode('_', $this->typeName); + + if (!$type = intval($ret[4])) { $msg = '未设置升级人数,不执行'; - } - elseif(!$level_id = intval($ret[3])){ + } elseif (!$level_id = intval($ret[3])) { $msg = '未设置升级等级,不执行'; - } - elseif((!$team_dividend_level_list = $this->teamDividendLevelList()) || $team_dividend_level_list->isEmpty()){ + } elseif ((!$team_dividend_level_list = $this->teamDividendLevelList()) || $team_dividend_level_list->isEmpty()) { $msg = '经销商等级为空'; - } - else{ + } else { $msg = ''; } - if(!$msg){ - if(!$min_level = $team_dividend_level_list->where('id',intval($level_id)) - ->first()){ + + if (!$msg) { + if (!$min_level = $team_dividend_level_list->where('id', intval($level_id))->first()) { $msg = '指定经销商等级不存在'; } - if(!$higher_ids = $this->team_dividend_level_list->where('level_weight','>=',$min_level->level_weight) - ->pluck('id') - ->toArray()){ + + if (!$higher_ids = $this->team_dividend_level_list->where('level_weight', '>=', $min_level->level_weight)->pluck('id')->toArray()) { $msg = '不存在更高的等级'; } } - if($msg){ + + if ($msg) { //$this->addErrorChild($ret[3]); $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定权重不低于指定经销商等级的直属下级满足多少人', 'func_name' => 'firstChildLevel', 'condition' => '权重不低于等级id['.$level_id.']的直属下级人数['.$type.']', - 'complete' => '', - 'result' => '', - 'remark' => $msg + 'complete' => '', + 'result' => '', + 'remark' => $msg ]); - return FALSE; + return false; } - $count = MemberChild::uniacid() - ->where('member_id',$this->uid) - ->where('level',1) - ->whereHas('hasOneTeam',function($query) use ($higher_ids){ - $query->whereIn('level',$higher_ids); + + $count = MemberChild::uniacid() + ->where('member_id', $this->uid) + ->where('level', 1) + ->whereHas('hasOneTeam', function ($query) use ($higher_ids) { + $query->whereIn('level', $higher_ids); }) ->count(); $condition = $count >= $type; + + // 记录详情 //$this->addLogChild($count, $ret[3]); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定权重不低于指定经销商等级的直属下级满足多少人', 'func_name' => 'firstChildLevel', 'condition' => '权重不低于等级id['.$level_id.']直属下级人数['.$type.']', - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 指定一个经销商等级下的人数满足多少人(团队) - * @return bool * @author + * @return bool */ - public function groupLevel(){ - $ret = explode('_',$this->typeName); + public function groupLevel() + { + $ret = explode('_', $this->typeName); + $type = intval($ret[3]); - if(!$type){ + if (!$type) { //$this->addErrorChild($ret[3]); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(团队)', 'func_name' => 'groupLevel', 'condition' => '等级id['.$ret[2].']人数['.$type.']', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $count = MemberChild::uniacid() - ->where('member_id',$this->uid) - ->whereHas('hasOneTeam',function($query) use ($ret){ - $query->where('level',$ret[2]); + + $count = MemberChild::uniacid() + ->where('member_id', $this->uid) + ->whereHas('hasOneTeam', function ($query) use ($ret) { + $query->where('level', $ret[2]); }) ->count(); $condition = $count >= $ret[3]; + + // 记录详情 //$this->addLogChild($count, $ret[3]); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '指定一个经销商等级下的人数满足多少人(团队)', 'func_name' => 'groupLevel', 'condition' => '等级id['.$ret[2].']人数['.$type.']', - 'complete' => $count, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $count, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * 团队业绩利润满XXX元 */ - public function teamProfitAmount(){ + public function teamProfitAmount() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩利润满XXX元', 'func_name' => 'teamProfitAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $children = MemberChild::uniacid() - ->select(['child_id']) - ->where('member_id',$this->uid) - ->get() - ->toArray(); - $ids = array_column($children,'child_id'); + + $children = MemberChild::uniacid()->select(['child_id'])->where('member_id',$this->uid)->get()->toArray(); + $ids = array_column($children,'child_id'); if($this->set['including_self'] == 1){ - array_push($ids,$this->uid); + array_push ($ids, $this->uid); } + $teamProfitPrice = OrderIncomeCount::uniacid() ->selectRaw('sum(price - cost_price) as profit') ->whereIn('uid',$ids) - ->where('status','>=',$this->order_status) - ->first()->profit; + ->where('status', '>=', $this->order_status) + ->first() + ->profit; + $condition = $teamProfitPrice >= $this->upgradeParase[$this->typeName]; + // 记录详情 //$this->addLogChild($teamProfitPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队业绩利润满XXX元', 'func_name' => 'teamProfitAmount', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $teamProfitPrice, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $teamProfitPrice, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } /** * 会员持有爱心值数量达到 */ - public function agentLove(){ + public function agentLove() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有爱心值数量达到XXX', 'func_name' => 'agentLove', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - if(!app('plugins')->isEnabled('love')){ - return FALSE; + + if (!app('plugins')->isEnabled('love')) { + return false; } - $total = LoveRecords::where('member_id',$this->uid) - ->where('type',1) - ->sum('change_value'); + $total = LoveRecords::where('member_id', $this->uid)->where('type',1)->sum('change_value'); + $condition = $total >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($teamProfitPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有爱心值数量达到XXX', 'func_name' => 'agentLove', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } /** * 会员持有消费积分数量达到 */ - public function agentIntegral(){ + public function agentIntegral() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有消费积分数量达到XXX', 'func_name' => 'agentIntegral', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - if(!app('plugins')->isEnabled('integral')){ - return FALSE; + + if (!app('plugins')->isEnabled('integral')) { + return false; } - $total = IntegralMemberModel::where('uid',$this->uid) - ->value('integral'); + $total = IntegralMemberModel::where('uid', $this->uid)->value('integral'); + $condition = $total >= $this->upgradeParase[$this->typeName]; // 记录详情 //$this->addLogChild($teamProfitPrice); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '会员持有消费积分数量达到XXX', 'func_name' => 'agentIntegral', 'condition' => $this->upgradeParase[$this->typeName], - 'complete' => $total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } + /** * @name 团队新订单数量满,指定商品ID - * @return bool * @author + * @return bool */ - public function teamNewOrderNumber(){ + public function teamNewOrderNumber() + { $type = intval($this->upgradeParase[$this->typeName]); - if(!$type){ + if (!$type) { //$this->addErrorChild($type); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队新订单数量满,指定商品ID', 'func_name' => 'teamNewOrderNumber', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_new_order_number_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - $agent = TeamDividendAgencyModel::uniacid() - ->where('uid',$this->uid) - ->first(); - if(!$agent){ + + $agent = TeamDividendAgencyModel::uniacid()->where('uid', $this->uid)->first(); + if (!$agent) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队新订单数量满,指定商品ID', 'func_name' => 'teamNewOrderNumber', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_new_order_number_to_goods']), - 'complete' => '', - 'result' => '', - 'remark' => '不是经销商身份不触发该升级条件' + 'complete' => '', + 'result' => '', + 'remark' => '不是经销商身份不触发该升级条件' ]); - return FALSE; + + return false; } - $build = MemberChild::select(['yz_member_children.child_id','yz_member_children.member_id']) + $build = MemberChild::select(['yz_member_children.child_id', 'yz_member_children.member_id']) ->join('yz_order','yz_member_children.child_id','=','yz_order.uid') - ->join('yz_order_goods',function($join){ - $join->on('yz_order_goods.order_id','=','yz_order.id'); + ->join('yz_order_goods',function ($join){ + $join->on('yz_order_goods.order_id', '=', 'yz_order.id'); }) - ->where('yz_order.status','>=',$this->order_status) - ->where('yz_order.created_at','>=',$agent->upgrade_at) - ->where('yz_member_children.member_id',$this->uid); + ->where('yz_order.status', '>=', $this->order_status) + ->where('yz_order.created_at', '>=', $agent->upgrade_at) + ->where('yz_member_children.member_id', $this->uid); + $countToGoods = intval($this->upgradeParase['team_new_order_number_to_goods']); - if($countToGoods > 0){ - $build->where('yz_order_goods.goods_id',$countToGoods); + if ($countToGoods > 0) { + $build->where('yz_order_goods.goods_id', $countToGoods); } - $team_goods_total = $build->get() - ->count(); + $team_goods_total = $build->get()->count(); + $logremark = '不计算自购订单'; if($this->set['including_self'] == 1){ $logremark = '计算自购订单'; //加上指定商品的条件 - $self_build = Order::where('uid',$this->uid) - ->where('status','>=',$this->order_status) - ->where('created_at','>=',$agent->upgrade_at); - if($countToGoods > 0){ - $self_build->whereHas('orderGoods',function($query) use ($countToGoods){ + $self_build = Order::where('uid', $this->uid)->where('status', '>=', $this->order_status)->where('created_at', '>=', $agent->upgrade_at); + if ($countToGoods > 0) { + $self_build ->whereHas('orderGoods',function ($query) use($countToGoods){ $query->where('goods_id',$countToGoods); }); } $team_goods_total += $self_build->count(); } $condition = $team_goods_total >= $this->upgradeParase[$this->typeName]; + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '团队新订单数量满,指定商品ID['.$logremark.']', 'func_name' => 'teamNewOrderNumber', 'condition' => $this->upgradeParase[$this->typeName].'|'.intval($this->upgradeParase['team_new_order_number_to_goods']), - 'complete' => $team_goods_total, - 'result' => $condition, - 'remark' => $condition ? '满足条件' : '不满足条件' + 'complete' => $team_goods_total, + 'result' => $condition, + 'remark' => $condition ? '满足条件' : '不满足条件' ]); - if($condition){ - return TRUE; + + if ($condition) { + return true; } - return FALSE; + return false; } - public function dividendAndPeerSum(){ - $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); - if(bccomp($type,0,2) != 1){ + + public function dividendAndPeerSum() + { + $type = bcadd($this->upgradeParase[$this->typeName] ?: 0, 0, 2); + if (bccomp($type, 0, 2) != 1) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '个人获得佣金(含经销商提成和平级奖)满'.$type, + 'type' => $this->typeName, + 'type_name' => '个人获得佣金(含经销商提成和平级奖)满' . $type, 'func_name' => 'dividendAndPeerSum', 'condition' => $type, - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + return false; } - $sum = TeamDividendModel::uniacid() - ->where('member_id',$this->uid) - ->where('status',1) - ->whereIn('type',[0,1]) + $sum = TeamDividendModel::uniacid()->where('member_id', $this->uid) + ->where('status', 1) + ->whereIn('type', [0, 1]) ->sum('dividend_amount'); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '个人获得佣金(含经销商提成和平级奖)满'.$type, + 'type' => $this->typeName, + 'type_name' => '个人获得佣金(含经销商提成和平级奖)满' . $type, 'func_name' => 'dividendAndPeerSum', 'condition' => $type, - 'complete' => $sum, - 'result' => '', - 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', + 'complete' => $sum, + 'result' => '', + 'remark' => bccomp($sum, $type, 2) == -1 ? '不满足条件' : '满足条件', ]); - return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; + + return bccomp($sum, $type, 2) == -1 ? false : true; + } - public function groupLoveAfterBlack(){ + + + public function groupLoveAfterBlack() + { $msg = ''; - if(!app('plugins')->isEnabled('love')){ + if (!app('plugins')->isEnabled('love')) { $msg = '爱心值插件未开启'; } - $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); - if(bccomp($type,0,2) != 1){ + + $type = bcadd($this->upgradeParase[$this->typeName] ?: 0, 0, 2); + if (bccomp($type, 0, 2) != 1) { $msg = '未设置条件,不执行'; } - if($msg){ + + if ($msg){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '移出黑名单后团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, + 'type' => $this->typeName, + 'type_name' => '移出黑名单后团队累计自购赠送冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, 'func_name' => 'groupLoveAfterBlack', 'condition' => $type, - 'complete' => '', - 'result' => '', - 'remark' => $msg + 'complete' => '', + 'result' => '', + 'remark' => $msg ]); - return FALSE; + return false; } - $sum = 0; - $group_ids = MemberChildren::where('member_id',$this->uid) - ->pluck('child_id') - ->toArray(); - if($group_ids){ + + $sum = 0; + $group_ids = MemberChildren::where('member_id', $this->uid)->pluck('child_id')->toArray(); + if ($group_ids) { $black_time = 0; - if($agent = TeamDividendAgencyModel::where('member_id',$this->uid) - ->first()){ - if($agent->black_time){ + if ($agent = TeamDividendAgencyModel::where('member_id',$this->uid)->first()){ + if ($agent->black_time){ $black_time = $agent->black_time; } } - $sum = LoveRecords::whereIn('member_id',$group_ids) - ->where('source',ConstService::SOURCE_AWARD) - ->where('value_type',ConstService::VALUE_TYPE_FROZE) + $sum = LoveRecords::whereIn('member_id', $group_ids) + ->where('source', ConstService::SOURCE_AWARD) + ->where('value_type', ConstService::VALUE_TYPE_FROZE) ->where('created_at','>',$black_time) ->sum('change_value'); } + $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '移出黑名单后团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, + 'type' => $this->typeName, + 'type_name' => '移出黑名单后团队累计自购赠送冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, 'func_name' => 'groupLove', 'condition' => $type, - 'complete' => $sum, - 'result' => '', - 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', + 'complete' => $sum, + 'result' => '', + 'remark' => bccomp($sum, $type, 2) == -1 ? '不满足条件' : '满足条件', ]); - return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; + + return bccomp($sum, $type, 2) == -1 ? false : true; } - public function groupLove(){ + + + public function groupLove() + { $msg = ''; - if(!app('plugins')->isEnabled('love')){ + if (!app('plugins')->isEnabled('love')) { $msg = '爱心值插件未开启'; } - $type = bcadd($this->upgradeParase[$this->typeName] ?: 0,0,2); - if(bccomp($type,0,2) != 1){ + + $type = bcadd($this->upgradeParase[$this->typeName] ?: 0, 0, 2); + if (bccomp($type, 0, 2) != 1) { $msg = '未设置条件,不执行'; } - if($msg){ + + if ($msg){ $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '团队累计自购赠送冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, + 'type' => $this->typeName, + 'type_name' => '团队累计自购赠送冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, 'func_name' => 'groupLove', 'condition' => $type, - 'complete' => '', - 'result' => '', - 'remark' => $msg + 'complete' => '', + 'result' => '', + 'remark' => $msg ]); - return FALSE; + return false; } - $sum = 0; - $group_ids = MemberChildren::where('member_id',$this->uid) - ->pluck('child_id') - ->toArray(); - if($group_ids){ - $sum = LoveRecords::whereIn('member_id',$group_ids) - ->where('source',ConstService::SOURCE_AWARD) - ->where('value_type',ConstService::VALUE_TYPE_FROZE) + + $sum = 0; + $group_ids = MemberChildren::where('member_id', $this->uid)->pluck('child_id')->toArray(); + if ($group_ids) { + $sum = LoveRecords::whereIn('member_id', $group_ids) + ->where('source', ConstService::SOURCE_AWARD) + ->where('value_type', ConstService::VALUE_TYPE_FROZE) ->sum('change_value'); } + $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '团队累计冻结'.(defined('LOVE_NAME') ? LOVE_NAME : '爱心值').'满'.$type, + 'type' => $this->typeName, + 'type_name' => '团队累计冻结' . (defined('LOVE_NAME') ? LOVE_NAME : '爱心值') . '满' . $type, 'func_name' => 'groupLove', 'condition' => $type, - 'complete' => $sum, - 'result' => '', - 'remark' => bccomp($sum,$type,2) == -1 ? '不满足条件' : '满足条件', + 'complete' => $sum, + 'result' => '', + 'remark' => bccomp($sum, $type, 2) == -1 ? '不满足条件' : '满足条件', ]); - return bccomp($sum,$type,2) == -1 ? FALSE : TRUE; + + return bccomp($sum, $type, 2) == -1 ? false : true; } + + + /** * 几条线 $this->upgradeParase['level_line_num'] * 等级id $this->upgradeParase['level_line_level_id'] @@ -1700,98 +1935,119 @@ class UpgrateConditionService{ * 每条线必须有多少会员以上 $this->upgradeParase['level_line_people'] * @return bool */ - public function levelLine(){ + public function levelLine() + { // 0条线 - if($this->upgradeParase['level_line_num'] <= 0){ + if ($this->upgradeParase['level_line_num'] <= 0) { //$this->addErrorChild($this->upgradeParase['level_line_num']); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - \Log::debug('经销商升级条件:几条线',$this->upgradeParase); + + \Log::debug('经销商升级条件:几条线', $this->upgradeParase); //查询 会员一级下线 的集合 $firstLowers = YzMemberModel::select('member_id') - ->where('parent_id',$this->uid) + ->where('parent_id', $this->uid) ->get(); - \Log::debug('经销商升级条件:几条线,下级',$firstLowers); + \Log::debug('经销商升级条件:几条线,下级', $firstLowers); // 没有直属下级 返回 false - if($firstLowers->isEmpty()){ + if ($firstLowers->isEmpty()) { //$this->addErrorChild(0); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].'],没有直属下级', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + // 升级条件的等级id $levelId = $this->upgradeParase['level_line_level_id']; + //人数为空或0默认赋值1 $this->upgradeParase['level_line_people'] = $this->upgradeParase['level_line_people'] ?: 1; - $ret = 0; - foreach($firstLowers as $firstLower){ + $ret = 0; + + foreach ($firstLowers as $firstLower) { // 执行次数 大于等于 条件设置的几条线 /*if ($num >= $this->upgradeParase['level_line_num']) { break; } $num += 1;*/ + $people = 0; + $buildRet = $this->getBuild($levelId); + //一级下级 - $selfRet = $buildRet['selfBuild']->where('uid',$firstLower->member_id) - ->first(); - if($selfRet){ + $selfRet = $buildRet['selfBuild']->where('uid', $firstLower->member_id)->first(); + if ($selfRet) { $people += 1; } - $count = $buildRet['build']->where('member_id',$firstLower->member_id) + + $count = $buildRet['build'] + ->where('member_id', $firstLower->member_id) ->count(); - if($count > 0){ + + if ($count > 0) { $people += $count; } // 满足指定人数 - if($people >= $this->upgradeParase['level_line_people']){ + if ($people >= $this->upgradeParase['level_line_people']) { $ret += 1; continue; } + + } - if($ret >= $this->upgradeParase['level_line_num']){ + + if ($ret >= $this->upgradeParase['level_line_num']) { //$this->addLogChild($ret, $this->upgradeParase['level_line_num']); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].']需满足人数['.$this->upgradeParase['level_line_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '满足条件' ]); - return TRUE; - } - else{ + + return true; + } else { //$this->addLogChild($ret, $this->upgradeParase['level_line_num']); + $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该等级', 'func_name' => 'levelLine', 'condition' => '几条线['.$this->upgradeParase['level_line_num'].']需满足人数['.$this->upgradeParase['level_line_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '不满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '不满足条件' ]); - return FALSE; + + return false; } } + /** * 区域代理 * 几条线 $this->upgradeParase['level_line_area_num'] @@ -1801,311 +2057,185 @@ class UpgrateConditionService{ * 每条线必须有多少会员以上 $this->upgradeParase['level_line_area_people'] * @return bool */ - public function levelLineArea(){ - if(!app('plugins')->isEnabled('area-dividend')) return FALSE; + public function levelLineArea() + { + if (!app('plugins')->isEnabled('area-dividend')) return false; // 0条线 - if($this->upgradeParase['level_line_area_num'] <= 0){ + if ($this->upgradeParase['level_line_area_num'] <= 0) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该区域等级', 'func_name' => 'levelLineArea', 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } - \Log::debug('经销商升级条件:区域几条线',$this->upgradeParase); + + \Log::debug('经销商升级条件:区域几条线', $this->upgradeParase); //查询 会员一级下线 的集合 $firstLowers = YzMemberModel::select('member_id') - ->where('parent_id',$this->uid) + ->where('parent_id', $this->uid) ->get(); - \Log::debug('经销商升级条件:区域几条线,下级',$firstLowers); + \Log::debug('经销商升级条件:区域几条线,下级', $firstLowers); // 没有直属下级 返回 false - if($firstLowers->isEmpty()){ + if ($firstLowers->isEmpty()) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足区域该等级', 'func_name' => 'levelLineArea', 'condition' => '几条线['.$this->upgradeParase['level_line_area_num'].'],没有直属下级', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' + 'complete' => '', + 'result' => '', + 'remark' => '未设置条件,不执行' ]); - return FALSE; + + return false; } + // 升级条件的等级id $levelId = $this->upgradeParase['level_line_area_level_id']; + //人数为空或0默认赋值1 $this->upgradeParase['level_line_area_people'] = $this->upgradeParase['level_line_area_people'] ?: 1; - $ret = 0; - foreach($firstLowers as $firstLower){ + $ret = 0; + + foreach ($firstLowers as $firstLower) { // 执行次数 大于等于 条件设置的几条线 + $people = 0; + $buildRet = $this->getAreaBuild($levelId); + //一级下级 - $selfRet = $buildRet['selfBuild']->where('member_id',$firstLower->member_id) - ->first(); - if($selfRet){ + $selfRet = $buildRet['selfBuild']->where('member_id', $firstLower->member_id)->first(); + if ($selfRet) { $people += 1; } - $count = $buildRet['build']->where('yz_area_dividend_agent.member_id',$firstLower->member_id) + + $count = $buildRet['build'] + ->where('yz_area_dividend_agent.member_id', $firstLower->member_id) ->count(); - if($count > 0){ + + if ($count > 0) { $people += $count; } // 满足指定人数 - if($people >= $this->upgradeParase['level_line_area_people']){ + if ($people >= $this->upgradeParase['level_line_area_people']) { $ret += 1; continue; } + + } - if($ret >= $this->upgradeParase['level_line_area_num']){ + + if ($ret >= $this->upgradeParase['level_line_area_num']) { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该区域等级', 'func_name' => 'levelLineArea', 'condition' => '几条线['.$this->upgradeParase['level_line_area_num'].']需满足人数['.$this->upgradeParase['level_line_area_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '满足条件' ]); - return TRUE; - } - else{ + + return true; + } else { $this->uplogService->pushCondition([ - 'type' => $this->typeName, + 'type' => $this->typeName, 'type_name' => '每条线必须有一个会员满足该区域等级', 'func_name' => 'levelLineArea', 'condition' => '几条线['.$this->upgradeParase['level_line_area_num'].']需满足人数['.$this->upgradeParase['level_line_area_people'].']', - 'complete' => $ret, - 'result' => '', - 'remark' => '不满足条件' + 'complete' => $ret, + 'result' => '', + 'remark' => '不满足条件' ]); - return FALSE; + + return false; } } - private function getBuild($levelId){ + + + + + private function getBuild($levelId) + { $nowLevel = TeamDividendLevelModel::select() - ->where('id',$levelId) + ->where('id', $levelId) ->first(); // 本级 else 以上 - if($this->upgradeParase['oneself'] == 0){ - $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_team_dividend_agency.cultural_level_id','yz_member_children.member_id']) + if ($this->upgradeParase['oneself'] == 0) { + $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_member_children.member_id']) ->join('yz_team_dividend_agency','yz_member_children.child_id','yz_team_dividend_agency.uid') - ->where(function($query) use ($levelId){ - $query->where('yz_team_dividend_agency.level',$levelId) - ->orWhere('yz_team_dividend_agency.cultural_level_id',$levelId); - }); - // ->whereHas('hasOneTeam', function ($teamModel) use ($levelId) { - // $teamModel->where('level', $levelId); - // }); + ->where('yz_team_dividend_agency.level',$levelId); +// ->whereHas('hasOneTeam', function ($teamModel) use ($levelId) { +// $teamModel->where('level', $levelId); +// }); $selfBuild = TeamDividendAgencyModel::select() - ->where('level',$nowLevel ? $levelId : -99); - } - else{ + ->where('level', $nowLevel ? $levelId : -99); + } else { // 条件等级 // 比 大于等级权重的等级id的集合 $levelIds = [-999]; - if($nowLevel){ + if ($nowLevel){ $levelIds = TeamDividendLevelModel::select() - ->where('level_weight','>=',$nowLevel->level_weight) + ->where('level_weight', '>=', $nowLevel->level_weight) ->pluck('id') ->toArray(); // 把 条件等级id 加入数组 $levelIds[] = $levelId; } - $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_member_children.member_id']) + $build = MemberChild::select(['yz_member_children.child_id','yz_team_dividend_agency.level','yz_member_children.member_id']) ->join('yz_team_dividend_agency','yz_member_children.child_id','yz_team_dividend_agency.uid') - ->where(function($query) use ($levelIds){ - $query->whereIn('yz_team_dividend_agency.level',$levelIds) - ->orWhereIn('yz_team_dividend_agency.cultural_level_id',$levelIds); - }); + ->whereIn('yz_team_dividend_agency.level',$levelIds); $selfBuild = TeamDividendAgencyModel::select() - ->where(function($query) use ($levelIds){ - $query->whereIn('yz_team_dividend_agency.level',$levelIds) - ->orWhereIn('yz_team_dividend_agency.cultural_level_id',$levelIds); - }); + ->whereIn('level', $levelIds); } return [ - 'build' => $build, + 'build' => $build, 'selfBuild' => $selfBuild ]; } - private function getAreaBuild($levelId){ + + private function getAreaBuild($levelId) + { // 本级 else 以上 - // if ($this->upgradeParase['area_oneself'] == 0) { - $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) - ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') - ->where('yz_area_dividend_agent.agent_level',$levelId); - $selfBuild = AreaDividendAgent::select() - ->where('agent_level',$levelId); - // } else { - // 条件等级 - // 比 大于等级权重的等级id的集合 - // $levelIds = []; - // for ($i=1;$i<5;$i++) { - // if ($i >= $levelId) { - // // 把 条件等级id 加入数组 - // $levelIds[] = $i; - // } - // } - // - // $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) - // ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') - // ->whereIn('yz_area_dividend_agent.agent_level',$levelId); - // $selfBuild = AreaDividendAgent::select() - // ->whereIn('agent_level', $levelIds); - // } +// if ($this->upgradeParase['area_oneself'] == 0) { + $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) + ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') + ->where('yz_area_dividend_agent.agent_level',$levelId); + + $selfBuild = AreaDividendAgent::select() + ->where('agent_level', $levelId); +// } else { + // 条件等级 + // 比 大于等级权重的等级id的集合 +// $levelIds = []; +// for ($i=1;$i<5;$i++) { +// if ($i >= $levelId) { +// // 把 条件等级id 加入数组 +// $levelIds[] = $i; +// } +// } +// +// $build = MemberChild::select(['yz_member_children.child_id','yz_area_dividend_agent.agent_level','yz_member_children.member_id']) +// ->join('yz_area_dividend_agent','yz_member_children.child_id','yz_area_dividend_agent.member_id') +// ->whereIn('yz_area_dividend_agent.agent_level',$levelId); +// $selfBuild = AreaDividendAgent::select() +// ->whereIn('agent_level', $levelIds); +// } return [ - 'build' => $build, + 'build' => $build, 'selfBuild' => $selfBuild ]; } - /** - * Common: 升级条件 - 直推间推多少人 - * Author: wu-hui - * Time: 2023/10/25 14:37 - * @return bool - */ - public function oneOrTwo(){ - try{ - // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 开始处理:',$this->uid); - $upgradeSet = $this->upgradeParase[$this->typeName]; - // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 基本设置:',$upgradeSet); - if(!$upgradeSet){ - $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '直推间推人数', - 'func_name' => 'oneOrTwo', - 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => '未设置条件,不执行' - ]); - return FALSE; - } - // 条件判断 - $oneLvAndTwoLvNum = MemberParent::getOneOrTwoList($this->uid); - $subMemberIds = array_column($oneLvAndTwoLvNum,'member_id'); - // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 下级UID:',$subMemberIds); - // 获取 直推间推成员中有多少 现在或者曾经是某个等级的经销商 - $hasNum = (int)Uplog::uniacid() - ->where('after_level_id',$upgradeSet['one_or_two_level_id']) - ->whereIn('uid',$subMemberIds) - ->count(DB::raw('DISTINCT(uid)')); - // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 人数:',$hasNum); - // 判断:是否达到升级要求 需求人数小于等于当前人数-达成升级条件 - $people = (int)$upgradeSet['one_or_two_people'] > 0 ? (int)$upgradeSet['one_or_two_people'] : 1; - $isReach = (boolean)($people <= $hasNum); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '直推间推人数', - 'func_name' => 'oneOrTwo', - 'condition' => '', - 'result' => '', - 'remark' => $isReach ? '满足条件' : '不满足条件' - ]); - - // \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 是否达到条件:',[ - // '需求人数' => $people, - // '当前人数' => $hasNum, - // 'is_reach' => $isReach - // ]); - if($isReach) return true; - - }catch(\Exception $e){ - \Log::debug('经销商升级 - 升级条件 - 直推间推人数 - 错误:',$e->getMessage()); - } - - return false; - } - /** - * Common: 升级条件 - 团队消费人数多少人,支持去除人数最多的线 - * Author: wu-hui - * Time: 2023/12/15 17:52 - * @return bool - */ - public function teamConsumptionPeople(){ - try{ - $upgradeSet = $this->upgradeParase[$this->typeName]; - if(!$upgradeSet) throw new \Exception('未设置条件,不执行'); - // 获取直推下级列表 - $subIds = MemberChild::uniacid() - ->where('level',1) - ->where('member_id',$this->uid) - ->pluck('child_id') - ->toArray(); - if(count($subIds) <= 0) throw new \Exception('无直推下级信息,不执行'); - $eachLineUid = [];// 每条线的用户id列表 - $maxPeopleInfo = [ - 'max_num' => 0,// 最大线人数 - 'sub_uid' => 0,// 最大线所属直推用户id - ]; - foreach($subIds as $subUid){ - // 获取每条件的用户id - $lineAllUid = MemberChild::uniacid()->where('member_id',$subUid)->pluck('child_id')->toArray(); - $lineAllUid[] = $subUid; - $eachLineUid[$subUid] = $lineAllUid; - // 判断:当前线用户数量是否为最多 - if($maxPeopleInfo['max_num'] <= count($eachLineUid[$subUid])) { - $maxPeopleInfo = [ - 'max_num' => count($eachLineUid[$subUid]),// 最大线人数 - 'sub_uid' => $subUid,// 最大线所属直推用户id - ]; - } - } - // 判断:是否去除人数最多的那条线 - if((int)$upgradeSet['team_consumption_people_close_max'] == 1) unset($eachLineUid[$maxPeopleInfo['sub_uid']]); - if(count($eachLineUid) <= 0) throw new \Exception('无有效团队信息,不执行'); - // 计算:消费总人数 - $allSubIds = []; - foreach($eachLineUid as $eachLineInfo){ - $allSubIds = array_merge($allSubIds,$eachLineInfo); - } - $consumptionPeople = Order::uniacid() - ->leftJoin('yz_order_goods','yz_order_goods.order_id','yz_order.id') - ->leftJoin('yz_goods_cultural_space','yz_goods_cultural_space.goods_id','yz_order_goods.goods_id') - ->whereIn('yz_order.uid',$allSubIds) - ->where('yz_order.status','>',0) - ->where('yz_goods_cultural_space.is_open',$this->levelType == 1 ? 1 : 0) - ->distinct('yz_order.uid') - ->count(); - // 判断:是否达到升级要求 需求人数小于等于当前人数-达成升级条件 - $people = (int)$upgradeSet['team_consumption_people_total'] > 0 ? (int)$upgradeSet['team_consumption_people_total'] : 1; - $isReach = (boolean)($people <= $consumptionPeople); - $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '团队消费人数多少人', - 'func_name' => 'teamConsumptionPeople', - 'condition' => '', - 'result' => '', - 'remark' => $isReach ? '满足条件' : '不满足条件' - ]); - if($isReach) return true; - - }catch(\Exception $e){ - $this->uplogService->pushCondition([ - 'type' => $this->typeName, - 'type_name' => '团队消费人数多少人', - 'func_name' => 'teamConsumptionPeople', - 'condition' => '', - 'complete' => '', - 'result' => '', - 'remark' => $e->getMessage() - ]); - \Log::debug('经销商升级 - 升级条件 - 团队消费人数多少人 - 错误:',$e->getMessage()); - } - - return false; - } - - - } \ No newline at end of file diff --git a/plugins/team-dividend/src/services/upgrate/UplogService.php b/plugins/team-dividend/src/services/upgrate/UplogService.php index a5b97275..341be3f3 100644 --- a/plugins/team-dividend/src/services/upgrate/UplogService.php +++ b/plugins/team-dividend/src/services/upgrate/UplogService.php @@ -4,7 +4,6 @@ namespace Yunshop\TeamDividend\services\upgrate; -use Yunshop\TeamDividend\models\TeamDividendLevelModel; use Yunshop\TeamDividend\models\Uplog; class UplogService @@ -53,13 +52,6 @@ class UplogService public function store() { - - if($this->uplogModel->after_level_id > 0){ - $lvInfo = TeamDividendLevelModel::find($this->uplogModel->after_level_id); - $this->uplogModel->give_limit = (int)$lvInfo->give_limit; - $this->uplogModel->give_limit_level_id = (int)$lvInfo->give_limit_level_id; - } - $this->uplogModel->conditions = $this->conditions; $this->uplogModel->save(); } diff --git a/plugins/team-dividend/src/services/withdraw/IncomeWithdrawApply.php b/plugins/team-dividend/src/services/withdraw/IncomeWithdrawApply.php index d4455007..a313f28c 100644 --- a/plugins/team-dividend/src/services/withdraw/IncomeWithdrawApply.php +++ b/plugins/team-dividend/src/services/withdraw/IncomeWithdrawApply.php @@ -5,7 +5,7 @@ * Email: livsyitian@163.com * QQ: 995265288 * IDE: PhpStorm - * User: + * User: 芸众商城 www.yunzshop.com ****************************************************************/ diff --git a/plugins/team-dividend/src/widgets/DividendVueWidget.php b/plugins/team-dividend/src/widgets/DividendVueWidget.php index c3b313a9..e9afd5f5 100644 --- a/plugins/team-dividend/src/widgets/DividendVueWidget.php +++ b/plugins/team-dividend/src/widgets/DividendVueWidget.php @@ -31,17 +31,16 @@ class DividendVueWidget extends BaseGoodsWidget $item['has_dividend_rates'] = unserialize($item['has_dividend_rates']); $item['has_hierarchys'] = unserialize($item['has_hierarchys']); $item['has_dividend_extra'] = unserialize($item['has_dividend_extra']); - $item['commission_rates'] = unserialize($item['commission_rates']); $dividendLevel = TeamDividendLevelModel::getList()->get()->toArray(); foreach ($dividendLevel as $key=>$value) { $dividendLevel[$key]['has_dividend_rates'] = isset($item['has_dividend_rates']['level_'.$value['id']])?$item['has_dividend_rates']['level_'.$value['id']]:''; //提成比例百分比 $dividendLevel[$key]['has_dividend_prices'] = isset($item['has_dividend_prices']['level_'.$value['id']])?$item['has_dividend_prices']['level_'.$value['id']]:''; //提成比例固定 $dividendLevel[$key]['has_dividend_extra'] = isset($item['has_dividend_extra']['level_'.$value['id']])?$item['has_dividend_extra']['level_'.$value['id']]:''; //提成比例-额外奖励 - $dividendLevel[$key]['commission_rates'] = isset($item['commission_rates']['level_'.$value['id']])?$item['commission_rates']['level_'.$value['id']]:''; // $dividendLevel[$key]['hierarchy'] = isset($item['has_hierarchys'][$value['id']]['hierarchy'])?$item['has_hierarchys'][$value['id']]['hierarchy']:''; //提成比例-额外奖励 $dividendLevel[$key]['ratio'] = isset($item['has_hierarchys'][$value['id']]['ratio'])?$item['has_hierarchys'][$value['id']]['ratio']:''; //提成比例-额外奖励 + } $data['teamSet'] = $set; diff --git a/plugins/team-dividend/src/widgets/DividendWidget.php b/plugins/team-dividend/src/widgets/DividendWidget.php index 0ceca70c..856e12df 100644 --- a/plugins/team-dividend/src/widgets/DividendWidget.php +++ b/plugins/team-dividend/src/widgets/DividendWidget.php @@ -18,7 +18,6 @@ class DividendWidget extends Widget $item['has_dividend_rates'] = unserialize($item['has_dividend_rates']); $item['has_hierarchys'] = unserialize($item['has_hierarchys']); $item['has_dividend_extra'] = unserialize($item['has_dividend_extra']); - $item['commission_rates'] = unserialize($item['commission_rates']); $dividendLevel = TeamDividendLevelModel::getList()->get()->toArray(); return view('Yunshop\TeamDividend::admin.goods', [ diff --git a/plugins/team-dividend/src/widgets/TeamDividendWithdrawWidget.php b/plugins/team-dividend/src/widgets/TeamDividendWithdrawWidget.php index b325f4a4..51f06fe3 100644 --- a/plugins/team-dividend/src/widgets/TeamDividendWithdrawWidget.php +++ b/plugins/team-dividend/src/widgets/TeamDividendWithdrawWidget.php @@ -10,20 +10,11 @@ class TeamDividendWithdrawWidget extends Widget public function run() { $set = Setting::get('withdraw.teamDividend', ['roll_out_limit' => '', 'poundage_rate' => '']); - // $teamDividendCulturalSet = Setting::get('withdraw.teamDividendCultural', ['roll_out_limit' => '', 'poundage_rate' => '']); - - - $ecological_services = Setting::get('withdraw.ecological_services', ['roll_out_limit' => '', 'poundage_rate' => '']); - $ecological_construction = Setting::get('withdraw.ecological_construction', ['roll_out_limit' => '', 'poundage_rate' => '']); - $ecological_contribution = Setting::get('withdraw.ecological_contribution', ['roll_out_limit' => '', 'poundage_rate' => '']); - + $shopSet = Setting::get('withdraw.storeManager', ['roll_out_limit' => '', 'poundage_rate' => '']); return view('Yunshop\TeamDividend::admin.withdraw-set', [ 'set' => $set, - // 'teamDividendCulturalSet' => $teamDividendCulturalSet, - 'ecological_services' => $ecological_services, - 'ecological_construction' => $ecological_construction, - 'ecological_contribution' => $ecological_contribution, + 'shop_set' => $shopSet ])->render(); } } \ No newline at end of file diff --git a/plugins/team-dividend/views/admin/dividend-list.blade.php b/plugins/team-dividend/views/admin/dividend-list.blade.php index 1b375797..9dcb3652 100644 --- a/plugins/team-dividend/views/admin/dividend-list.blade.php +++ b/plugins/team-dividend/views/admin/dividend-list.blade.php @@ -65,9 +65,6 @@ - - - @@ -131,33 +128,33 @@ - - - - - - - - - - - - + + + + + + + + + + + + @foreach($list['data'] as $row) - - - - + + + - - - - - - - - + + + + + + diff --git a/plugins/team-dividend/views/admin/goods.blade.php b/plugins/team-dividend/views/admin/goods.blade.php index a9f06c0f..46a3b20d 100644 --- a/plugins/team-dividend/views/admin/goods.blade.php +++ b/plugins/team-dividend/views/admin/goods.blade.php @@ -67,8 +67,7 @@ - - + @if( $teamSet['is_extra_award'] ) @endif @@ -82,38 +81,34 @@ + @if( $teamSet['is_extra_award'] ) - @if( $teamSet['is_extra_award'] ) - @endif @endforeach +
ID提成时间会员ID订单号经销商经销商等级
分红类型 / 分红比例
订单金额提成结算金额下级经销商提成提成金额提成状态操作ID提成时间会员ID订单号经销商经销商等级
分红类型 / 分红比例
订单金额提成结算金额下级经销商提成提成金额提成状态操作
{{$row['id']}}{{$row['created_at']}}{{$row['member_id']}} + {{$row['id']}}{{$row['created_at']}}{{$row['member_id']}} {{$row['order_sn']}} + + {{$row['level_name']}}
- {{ $row['type_name'] }} - 比例:{{$row['dividend_rate']}}%
{{$row['order_amount']}}{{$row['amount']}}{{$row['lower_level_rate']}}%{{$row['dividend_amount']}}{{$row['status_name']}} + {{ $row['type_name'] }} + - + 比例:{{$row['dividend_rate']}}%{{$row['order_amount']}}{{$row['amount']}}{{$row['lower_level_rate']}}%{{$row['dividend_amount']}}{{$row['status_name']}} 查看详情
经销商等级提成比例/{{--生态建设--}}经销商受益比例生态服务比例提成比例额外奖励
- +
% 固定
- +
- -
%
+ +
-
- -
-
-
- - 如果比例都为空或等于0,则使用固定金额规则,如果比例和金额都为空或等于0则不获得提成
- (ps:为了确保经销商能获得提成,建议统一设置为比例或者统一设置为固定金额,如果高等级设置比例低等级设置固定金额,有可能会造成部分经销商无提成) -
- - 商品启用经销商独立提成:如果商品经销商独立提成设置的是比例,那么平级奖计算金额则按照商品实际支付金额计算; - 如果商品经销商独立提成设置的是固定金额,那么平级奖计算金额则按照固定金额计算 - + 如果比例都为空或等于0,则使用固定金额规则,如果比例和金额都为空或等于0则不获得提成
(ps:为了确保经销商能获得提成,建议统一设置为比例或者统一设置为固定金额,如果高等级设置比例低等级设置固定金额,有可能会造成部分经销商无提成)
+ 商品启用经销商独立提成:如果商品经销商独立提成设置的是比例,那么平级奖计算金额则按照商品实际支付金额计算; + 如果商品经销商独立提成设置的是固定金额,那么平级奖计算金额则按照固定金额计算 diff --git a/plugins/team-dividend/views/admin/level-set-add.blade.php b/plugins/team-dividend/views/admin/level-set-add.blade.php index 04ead7a8..f83139c3 100644 --- a/plugins/team-dividend/views/admin/level-set-add.blade.php +++ b/plugins/team-dividend/views/admin/level-set-add.blade.php @@ -5,62 +5,14 @@ .radio-inline + .radio-inline { margin: 0; } + .row { width: 100%; } + #goodsthumb { margin-left: 20px; } - .weight-value-content{} - .weight-value-content .title{ - display: flex; - height: 30px; - line-height: 32px; - font-size: 16px; - color: #333; - font-weight: 600; - } - .weight-value-content .title-left{ - width: 4px; - height: 18px; - margin-top: 6px; - background: #29ba9c; - display: inline-block; - margin-right: 10px; - } - .weight-value-content .title-content{ - font-size: 14px; - flex: 1; - } - .weight-value-content .weight-value-top-content{ - height: 34px; - display: -webkit-inline-box; - } - .weight-value-content .weight-value-top-content .weight-value-lable{ - width: 70px!important; - height: 34px; - line-height: 20px; - } - .weight-value-content .weight-value-top-content .weight-value-radio{ - padding-right: 55px; - height: 34px; - } - .weight-value-content .weight-value-top-content .radio-inline{ - padding: 0px!important; - width: 50%; - margin-left: 10px; - display: inline-flex; - flex-direction: row; - flex-wrap: nowrap; - align-items: center; - justify-content: flex-start; - } - .weight-value-content .weight-value-top-content .radio-inline:nth-child(2){ - margin-left: 20px!important; - } - .del-ladder-btn{ - cursor: pointer; - }
@@ -82,20 +34,7 @@ 等级权重,数字越大级别越高。
-
- -
-
- - -
- 用户升级到普通等级会改变经销商等级不会改变文创等级,升级到文创等级则不会改变经销商等级只会改变文创等级 -
-
+
@@ -104,68 +43,9 @@ value="{{$dividend->level_name}}"/>
+
- -
- -
-
-
- -
-
- - - - -
-
-
-
- -
-
- -
-
- 当前等级总人数达到指定数量后,其他人则不能升级到当前等级。为空或者0则不限制人数 -
-
-
- -
-
- -
-
- 升级后赠送的名额,该名额可以赠送给其他用户,让其升级到指定等级! -
-
-
- -
- -
-
-
- +
-
- -
-
- -
%
-
-
-
@@ -197,20 +68,7 @@ 超过层级限制,无法获得经销商提成,感恩奖也随之无法获得
-
- -
-
- - -
- 当前等级的用户是否参与市场津贴 -
-
+
@@ -304,13 +162,16 @@
- {{-- 直推间推 某个等级 满多少人 START --}} -
- -
- {{-- 直推间推 某个等级 满多少人 END --}} - - - {{-- 直推间推 某个等级 满多少人 START --}} -
- -
- {{-- 直推间推 某个等级 满多少人 END --}} - - - -
+
+ +
@@ -903,12 +716,14 @@
+
+ @if($settingData['is_activation_code'])
@@ -965,76 +780,18 @@
@endif - {{-- 升级奖励 start--}} +
- +
-
积分
- +
-
-
数藏画
- -
-
- 数藏画仅第一次升级到当前等级赠送。如果降级后重新升级到当前等级则不会赠送 - {{-- 权重值 --}} -
-
-
-
权重值设置
-
-
-
赠送方式
-
- - -
-
- 普通赠送-赠送指定的权重值;阶梯赠送-根据用户成为经销商的时间顺序排序,获取对应的权重值;超过最大名次则不赠送权重值 - {{--
-
赠送级别
-
- - - -
-
- 二级-赠送购买人、购买人上级;三级-赠送购买人、购买人上级、购买人上级的上级--}} - {{--赠送固定值--}} -
-
赠送
- -
权重值
-
- {{--阶梯赠送 - 根据成为当前等级经销商的等级排名 进行赠送--}} -
-
- {{--阶梯内容渲染--}} -
- 例如:设置小于等于10赠送100权重值;小于等于32赠送120权重值。则第1~10位经销商赠送100权重值,第11~32位经销商赠送120权重值,第33位及之后所有经销商均不赠送权重值 - - - -
-
- {{-- 权重值 end --}} - 权重值仅第一次升级到当前等级赠送。如果降级后重新升级到当前等级则不会赠送
- {{-- 升级奖励 end--}} @if($isPluginGold)
@@ -1048,6 +805,7 @@
@endif +
@@ -1057,6 +815,7 @@
+
@@ -1068,6 +827,7 @@
+
@@ -1083,6 +843,7 @@
+ @if(is_null($settingData['withdraw_type']) || $settingData['withdraw_type'] == 0)
@@ -1103,6 +864,7 @@
@endif +
@@ -1145,6 +907,7 @@
+
+ +
- @endsection \ No newline at end of file diff --git a/plugins/team-dividend/views/admin/level-set.blade.php b/plugins/team-dividend/views/admin/level-set.blade.php index 5501ab59..789ba663 100644 --- a/plugins/team-dividend/views/admin/level-set.blade.php +++ b/plugins/team-dividend/views/admin/level-set.blade.php @@ -1,11 +1,6 @@ @extends('layouts.base') @section('title', trans('经销商等级')) @section('content') -
@@ -24,59 +19,29 @@ - - - - - - - - {{----}} - - - + + + + + + + @foreach($list['data'] as $item) - - - - - - - - {{----}} - - - + + + + + diff --git a/plugins/team-dividend/views/admin/team-agency-add.blade.php b/plugins/team-dividend/views/admin/team-agency-add.blade.php index 2064b1bc..951671ac 100644 --- a/plugins/team-dividend/views/admin/team-agency-add.blade.php +++ b/plugins/team-dividend/views/admin/team-agency-add.blade.php @@ -8,6 +8,7 @@
  • 添加团队代理
  • +
    @@ -38,6 +39,7 @@ {{----}}
    +
    @@ -45,24 +47,14 @@ {{----}}
    +
    -
    -
    -
    - -
    -
    diff --git a/plugins/team-dividend/views/admin/team-agency.blade.php b/plugins/team-dividend/views/admin/team-agency.blade.php index 945a733f..e8c5b4d0 100644 --- a/plugins/team-dividend/views/admin/team-agency.blade.php +++ b/plugins/team-dividend/views/admin/team-agency.blade.php @@ -14,9 +14,6 @@ padding-bottom: 80px; overflow: hidden !important; } - .panel-body .label{ - font-size: 13px!important; - }
    @@ -49,7 +46,7 @@
    -
    +
    -
    - -
    +
    - -
    +
    ID等级权重等级名称等级类型提成比例(%){{--生态建设--}}经销商受益比例(%)生态服务比例(%)激活码发放平级奖励层级平级奖励比例操作等级权重等级名称提成比例激活码发放平级奖励层级平级奖励比例操作
    {{$item['id']}} - + + {{$item['level_name']}} - @if($item['level_type'] == 1) - 文创等级 - @else - 普通等级 - @endif - - @if($item['level_type'] == 1) - - - @else - {{$item['dividend_ratio']}} - @endif - - @if($item['level_type'] == 1) - {{$item['dividend_ratio']}} - @else - - - @endif - - @if($item['level_type'] == 1) - {{$item['commission_ratio']}} - @else - - - @endif - {{array_sum(unserialize($item['code_num']))}}{{$item['award_hierarchy']}}{{$item['award_ratio']}} + {{$item['level_name']}}{{$item['dividend_ratio']}}{{array_sum(unserialize($item['code_num']))}}{{$item['award_hierarchy']}}{{$item['award_ratio']}} 编辑 删除
    - - - - - - + + + + + - + @@ -144,77 +123,59 @@ @foreach($list['data'] as $item) - + + + @if ($item['has_one_member']) - + @endif + - - + + + {{----}} + {{----}} + {{----}}
    - ID -
    - UID -
    成为经销商时间
    普通等级升级时间
    文创等级升级时间
    经销商等级排名名额(剩余/已使用)ID会员ID成为经销商时间
    升级时间
    经销商等级 直属总经销商人数 - 提成比例
    累计提成 -
    - {{--生态建设比例
    累计生态建设--}} - 经销商受益比例
    累计经销商受益 -
    经销商比例
    累计提成
    已结算提成
    未结算提成
    黑名单
    变动时间
    团队业绩
    团队商品销量
    - {{$item['id']}} -
    - {{$item['has_one_member']['uid']}} -
    {{$item['id']}}{{$item['has_one_member']['uid']}} {{$item['created_at']}}
    {{$item['upgrade_at'] ? date('Y-m-d H:i:s',$item['upgrade_at']) : '/'}} -
    - {{$item['cultural_upgrade_at'] ? date('Y-m-d H:i:s',$item['cultural_upgrade_at']) : '/'}}
    - @if ($item['has_one_member']) - - -
    - {{$item['has_one_member']['nickname']}} -
    - @else - 未更新 - @endif +
    {{$item['has_one_member']['nickname']}}
    + @else + + 未更新 + - {{$item['has_one_level']['level_name'] ?? '/'}} + {{$item['has_one_level']['level_name']}} + -
    - - {{$item['cultural_level']['level_name'] ?? '/'}} - - - +
    - @foreach($item['rank_list'] as $rankItem) -

    {{$rankItem['level_name']}}:{{$rankItem['ranking']}}

    - @endforeach -
    {{$item['surplus_quota']}} / {{$item['use_quota']}} {{$item['total'] ?? 0}}人 查看 + {{$item['has_one_level']['dividend_ratio']}}%
    {{$item['has_many_team_dividend'][2]['total_amount'] + $item['has_many_team_dividend'][1]['total_amount'] + $item['has_many_team_dividend'][0]['total_amount']}} -
    - {{$item['cultural_level']['dividend_ratio'] ?? 0}}% -
    - 0
    {{$item['dividend_final']}}{{$item['dividend_open']}}{{$item['dividend_total']}} @if($item['has_many_team_dividend'][0]['status'] == 1) {{$item['has_many_team_dividend'][0]['total_amount']}} @@ -226,15 +187,15 @@ 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 + @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['is_black']) @@ -321,31 +282,18 @@ $('.fa-edit-item').click(function () { $(this).closest('span').hide(); $(this).next('.level').show(); - }); - $('.level').mouseover(function () { - // console.log('mouseover'); - }).mouseout(function () { - $(this).prev('.fa-edit-item').show(); - $(this).closest('.level').hide(); }); - - let is_submit = true; $('.tpl-agent-level').change(function () { var agencyId = $(this).data('agencyid'); - var leve_type = $(this).data('leve_type'); var levelId = $(this).val(); - - if(is_submit){ - is_submit = false; - fastChange(agencyId, levelId, leve_type); - } + fastChange(agencyId, levelId); }); - function fastChange(id, value, leve_type) { + function fastChange(id, value) { $.ajax({ url: "{!! yzWebUrl('plugin.team-dividend.admin.team-agency.change') !!}", type: "post", - data: {id: id, value: value, leve_type: leve_type}, + data: {id: id, value: value}, cache: false, success: function ($data) { console.log($data); diff --git a/plugins/team-dividend/views/admin/withdraw-set.blade.php b/plugins/team-dividend/views/admin/withdraw-set.blade.php index 44897d49..992dfc28 100644 --- a/plugins/team-dividend/views/admin/withdraw-set.blade.php +++ b/plugins/team-dividend/views/admin/withdraw-set.blade.php @@ -1,15 +1,11 @@ -
    - {{--经销商提成提现设置--}} -
    -
    -
    {{ trans('Yunshop\TeamDividend::index.withdraw') }}设置
    +
    + 经销商设置
    - + 当前代理的佣金达到此额度时才能提现
    @@ -18,14 +14,10 @@
    @@ -36,29 +28,21 @@
    - {{--服务津贴提现设置--}} -{{--
    -
    -
    服务津贴提现设置
    +
    + 店补设置
    - + 当前代理的佣金达到此额度时才能提现
    @@ -67,14 +51,10 @@
    @@ -85,63 +65,9 @@
    -
    -
    - --}} - - -
    -
    -
    生态服务设置
    -
    -
    - -
    - - 当生态服务达到此额度时才能提现 -
    -
    -
    - -
    -
    - - -
    -
    -
    -
    - -
    -
    -
    @@ -149,111 +75,6 @@
    -
    -
    -
    {{--生态建设--}}经销商受益设置
    -
    -
    - -
    - - 当{{--生态建设--}}经销商受益达到此额度时才能提现 -
    -
    -
    - -
    -
    - - -
    -
    -
    -
    - -
    -
    - -
    -
    -
    - - -
    -
    -
    生态贡献设置
    -
    -
    - -
    - - 当生态贡献达到此额度时才能提现 -
    -
    -
    - -
    -
    - - -
    -
    -
    -
    - -
    -
    - -
    -
    -
    - - - - - - -
    diff --git a/plugins/team-dividend/views/widget/profit/dealerCommission.js b/plugins/team-dividend/views/widget/profit/dealerCommission.js index f435d4cf..6acd432e 100644 --- a/plugins/team-dividend/views/widget/profit/dealerCommission.js +++ b/plugins/team-dividend/views/widget/profit/dealerCommission.js @@ -36,24 +36,21 @@ define({ - +
    经销商等级
    - -
    提成比例/经销商受益比例
    + +
    提成比例
    - -
    生态服务比例
    -
    - +
    额外奖励
    - +
    {{level.level_name}}
    - + @@ -61,12 +58,7 @@ define({ - - - - - - + @@ -185,17 +177,15 @@ define({ filterList (list=[]) { let ratesList = {}; let pricesList = {}; - let commissionList = {}; let extraList = {}; let gradeList = {}; list.forEach((item, index) => { let key = 'level_' + item.id; - let {has_dividend_rates, commission_rates, has_dividend_prices, has_dividend_extra, hierarchy, ratio} = item; + let {has_dividend_rates, has_dividend_prices, has_dividend_extra, hierarchy, ratio} = item; // 独立规则 if (this.has_dividend) { ratesList[key] = has_dividend_rates; pricesList[key] = has_dividend_prices; - commissionList[key] = commission_rates; } // 额外奖励 if (this.has_dividend && this.teamSet.is_extra_award == 1) { @@ -209,7 +199,7 @@ define({ } } }); - return {ratesList, commissionList, pricesList, extraList, gradeList} + return {ratesList, pricesList, extraList, gradeList} }, validate () { let aggregate = this.filterList(this.levelList); @@ -222,7 +212,6 @@ define({ // dividendLevel: this.filterList(this.levelList) has_dividend_rates: aggregate.ratesList, has_dividend_prices: aggregate.pricesList, - commission_rates: aggregate.commissionList, has_dividend_extra: aggregate.extraList, has_hierarchys: aggregate.gradeList } diff --git a/plugins/weight-value/src/PluginApplication.php b/plugins/weight-value/src/PluginApplication.php index 1bd2b5ae..43044567 100644 --- a/plugins/weight-value/src/PluginApplication.php +++ b/plugins/weight-value/src/PluginApplication.php @@ -6,6 +6,8 @@ namespace Yunshop\WeightValue; class PluginApplication extends \app\common\services\PluginApplication{ protected function setMenuConfig(){ + + return []; \app\backend\modules\menu\Menu::current()->setPluginMenu('weight-value', [ 'name' => '权重值管理', 'type' => 'marketing',