request->get('userName', ''); $periodNum = Yii::$app->request->get('periodNum', null); if ($userName !== '') { if (!$userId = Info::getUserIdByUserName($userName)) { return static::notice('会员不存在', 400); } $topUid = \Yii::$app->user->id; $userNetInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS'); $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']); if(!in_array($topUid,$parentUidsArr)){ return static::notice('会员与当前用户不再同一安置网络内', 400); } } else { $userId = \Yii::$app->user->id; } $baseInfo = Info::baseInfo($userId, $periodNum); $decLevelConfig = Cache::getDecLevelConfig(); $empLevelConfig = Cache::getEmpLevelConfig(); return static::notice([ [ 'TOP_RELATION_DEEP' => $baseInfo['RELATION_DEEP'], 'TOP_NETWORK_DEEP' => $baseInfo['NETWORK_DEEP'], 'USER_ID' => $userId, 'USER_NAME' => $baseInfo['USER_NAME'], 'REAL_NAME' => $baseInfo['REAL_NAME'], 'PERIOD_AT' => $baseInfo['PERIOD_AT'], 'DEC_LV_NAME' => $decLevelConfig[$baseInfo['DEC_LV']]['LEVEL_NAME'], 'EMP_LV_NAME' => $empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME'], 'leaf' => false, 'icon' => 'el-icon-user-solid', 'children' => null, 'isExpanded' => false, 'displayNone' => 'display-none', 'className' => 'first-node', 'listPeriodNum' => $periodNum ], ]); } /** * 安置网络图 * @return mixed * @throws \yii\web\HttpException */ public function actionNetwork() { $userId = Yii::$app->request->get('id', \Yii::$app->user->id); $periodNum = Yii::$app->request->get('periodNum', null); $deep = Yii::$app->request->get('deep', 5); $myUserId = \Yii::$app->user->id; $hiddenUser = UserNetworkHidden::fetchHiddenUser($myUserId); if ($deep > 20) { return static::notice('最多查看会员的前20层子会员', 400); } $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum, $hiddenUser); return static::notice(['allData' => $allData, 'periodNum' => $periodNum]); } /** * 安置网络列表 * @return mixed * @throws \yii\base\Exception * @throws \yii\db\Exception * @throws \yii\web\HttpException */ public function actionNetworkList() { $userName = Yii::$app->request->get('userName'); $deep = Yii::$app->request->get('deep', 5); $periodNum = Yii::$app->request->get('periodNum', null); if (!$userName) { $userId = \Yii::$app->user->id; } else { if (!$userId = Info::getUserIdByUserName($userName)) { return static::notice('会员不存在', 400); } $topUid = \Yii::$app->user->id; $userNetInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS'); $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']); if(!in_array($topUid,$parentUidsArr)){ return static::notice('会员与当前用户不再同一安置网络内', 400); } } $period = Period::instance(); $mainUserInfo = Info::baseInfo($userId, $periodNum); $decLevelConfig = Cache::getDecLevelConfig(); $empLevelConfig = Cache::getEmpLevelConfig(); $data = UserNetwork::getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum, 1 ? ['pageSize' => 10] : []); foreach($data['list'] as $key=>$value){ $userBaseInfo = Info::baseInfo($value['USER_ID'], $periodNum); $data['list'][$key]['LIST_PERIOD_NUM'] = $periodNum?$periodNum:$period->getNowPeriodNum(); $data['list'][$key]['COUNT_DEEP'] = (int)($userBaseInfo['NETWORK_DEEP']); $data['list'][$key]['USER_NAME'] = $userBaseInfo['USER_NAME']; $data['list'][$key]['SEE_USER_NAME'] = $userBaseInfo['USER_NAME']; $data['list'][$key]['REAL_NAME'] = $userBaseInfo['REAL_NAME']; $data['list'][$key]['PERIOD_AT'] = $userBaseInfo['PERIOD_AT']; $data['list'][$key]['DEC_LV_NAME'] = $decLevelConfig[$userBaseInfo['DEC_LV']]['LEVEL_NAME']; $data['list'][$key]['EMP_LV_NAME'] = $empLevelConfig[$userBaseInfo['EMP_LV']]['LEVEL_NAME']; } $data['periodNum'] = $periodNum; $data['listTopDeep'] = $mainUserInfo['NETWORK_DEEP']; return static::notice($data); } /** * 获取期数 * @return mixed * @throws \yii\web\HttpException */ public function getPeriod(){ $period = Period::instance(); $periodNum = $period->getNowPeriodNum(); return static::notice([ 'periodNum' => $periodNum, ]); } /** * 查询推荐网络的指定节点. * @return void * @throws HttpException * @throws \Exception */ public function actionScourRelation() { // 发起人 $initiator = Yii::$app->request->get('initiator'); // 接受者 $recipient = Yii::$app->request->get('recipient'); // 期数 $this->_periodNum = Period::instance()->getNowPeriodNum(); // 发起人 $initiatorInfo = Info::getBaseUserByUserName($initiator); if (!$initiatorInfo) { return static::notice('会员不存在', 400); } // 发起人是否报单中心 $initiatorIsDec = $initiatorInfo['IS_DEC'] == 1; $initiatorId = $initiatorInfo['ID']; // 接受者 $recipientInfo = Info::getBaseUserByUserName($recipient); if (!$recipientInfo) { return static::notice('会员不存在', 400); } // 发起人是否报单中心 $recipientIsDec = $recipientInfo['IS_DEC'] == 1; $recipientId = $recipientInfo['ID']; // 1. 如果发起人和接受者都是报单中心,则转账无限制 if (($initiatorIsDec == 1) && ($recipientIsDec == 1)) { return static::notice(['allowable' => true]); } // 2. 如果发起人是普通会员,则只能转给自己推荐网的上级某个节点 $relation = new Relation(); if (!$initiatorIsDec) { // 判断接受者是否是自己的推荐网上级某个节点 $allowable = $relation->loopRelationParentDo($initiatorId, function ($parent) use ($recipientId) { $parentUser = CalcCache::getUserInfo($parent['PARENT_UID'], $this->_periodNum); if ($parentUser['ID'] == $recipientId) { return self::LOOP_FINISH; } unset($parent); }); return static::notice(['allowable' => $allowable]); } // 3. 如果发起人是报单中心或者普通会员, 则可以转账给自己的推荐网下级 // 判断接受者是否是自己的推荐网上级某个节点 $allowable = $relation->loopRelationParentDo($recipientId, function ($parent) use ($initiatorId) { $parentUser = CalcCache::getUserInfo($parent['PARENT_UID'], $this->_periodNum); if ($parentUser['ID'] == $initiatorId) { return self::LOOP_FINISH; } unset($parent); }); return static::notice(['allowable' => $allowable]); } }