| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/2/24
- * Time: 下午12:48
- */
- namespace backendApi\modules\v1\controllers;
- use backendApi\modules\v1\models\exportForms\AtlasExportForm;
- use backendApi\modules\v1\models\lists\atlas\EmpUserList;
- use backendApi\modules\v1\models\lists\atlas\NetworkLineList;
- use backendApi\modules\v1\models\lists\atlas\NetworkList;
- use backendApi\modules\v1\models\lists\atlas\RelationList;
- use common\helpers\Cache;
- use common\helpers\Form;
- use common\helpers\Level;
- use common\helpers\user\Perf;
- use common\helpers\user\Info;
- use common\models\CalcBonus;
- //use common\models\exportForms\AtlasRelationListExport;
- use common\models\PerfMonth;
- use common\models\Period;
- use common\models\DeclarationLevel;
- use common\models\EmployLevel;
- use common\models\UserInfo;
- use common\models\UserNetwork;
- use common\models\UserRelation;
- use Yii;
- use common\models\User;
- class AtlasController extends BaseController {
- public $modelClass = User::class;
- public function behaviors() {
- $behaviors = parent::behaviors();
- //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
- return $behaviors;
- }
- /**
- * 开拓网络图
- * @return mixed
- * @throws \yii\base\Exception
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionRelation() {
- $userId = Yii::$app->request->get('id', Yii::$app->params['mainUserId']);
- $deep = Yii::$app->request->get('deep', 2);
- $periodNum = Yii::$app->request->get('periodNum', null);
- if ($deep > 23) {
- return static::notice('Top 23 sub members of members can be viewed at most', 400);//最多查看会员的前23层子会员
- }
- $allData = UserRelation::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
- return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
- }
- /**
- * 主点位信息
- * @return mixed
- * @throws \yii\base\Exception
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionMainUserInfo() {
- $userName = Yii::$app->request->get('userName', '');
- $periodNum = Yii::$app->request->get('periodNum', null);
- $period = Period::instance();
- $yearMonth = $period->getYearMonth($periodNum);
- if ($userName !== '') {
- //$oneUser = Info::getUserByUserNameFromUserInfoTable($userName);
- if (!$userId = Info::getUserIdByUserName($userName)) {
- return static::notice('Member does not exist', 400); // 会员不存在
- }
- } else {
- $userId = Yii::$app->params['mainUserId'];
- }
- $baseInfo = Info::baseInfo($userId, $periodNum);
- // print_r($baseInfo);exit;
- $decLevelConfig = Cache::getDecLevelConfig();
- $empLevelConfig = Cache::getEmpLevelConfig();
- $crownLevelConfig = Cache::getStarCrownLevelConfig();
- 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' => isset($empLevelConfig[$baseInfo['EMP_LV']])?$empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME']:'0-Star Director',
- 'CROWN_LV_NAME' => isset($crownLevelConfig[$baseInfo['CROWN_LV']])?$crownLevelConfig[$baseInfo['CROWN_LV']]['LEVEL_NAME']:'0-Star Crown',
- 'leaf' => false,
- 'icon' => 'el-icon-user-solid',
- 'children' => null,
- 'isExpanded' => false,
- 'displayNone' => 'display-none',
- 'className' => 'first-node',
- 'listPeriodNum' => $periodNum
- ],
- ]);
- }
- /**
- * 开拓网络列表
- * @return mixed
- * @throws \yii\base\Exception
- * @throws \yii\web\HttpException
- */
- public function actionRelationList() {
- $userName = Yii::$app->request->get('userName');
- $deep = Yii::$app->request->get('deep', 2);
- $periodNum = Yii::$app->request->get('periodNum', null);
- if (!$userName) {
- $userId = Yii::$app->params['mainUserId'];
- } else {
- if (!$userId = Info::getUserIdByUserName($userName)) {
- return static::notice('Member does not exist', 400);//会员不存在
- }
- }
- $listObj = new RelationList();
- $data = $listObj->getList(['condition' => '', 'params' => [], 'others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]);
- return static::notice($data);
- }
- /**
- * 开拓网络列表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionRelationListExport() {
- $filter = $this->filterCondition([]);
- $userName = Yii::$app->request->get('userName');
- $deep = Yii::$app->request->get('deep', 2);
- $periodNum = Yii::$app->request->get('periodNum', null);
- if (!$userName) {
- $userId = Yii::$app->params['mainUserId'];
- } else {
- if (!$userId = Info::getUserIdByUserName($userName)) {
- return static::notice('Member does not exist', 400); // 会员不存在
- }
- }
- $form = new AtlasExportForm();
- $result = $form->run(array_merge($filter, ['others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]), 'Sponsor_Network'); // 开拓网络列表
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- /**
- * 安置网络图
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function actionNetwork() {
- $userId = Yii::$app->request->get('id', Yii::$app->params['mainUserId']);
- $periodNum = Yii::$app->request->get('periodNum', null);
- $deep = Yii::$app->request->get('deep', 2);
- if ($deep > 20) {
- return static::notice('View the top 20 sub members of the member at most', 400);//最多查看会员的前20层子会员
- }
- $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
- 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', 2);
- $periodNum = Yii::$app->request->get('periodNum', null);
- if (!$userName) {
- $userId = Yii::$app->params['mainUserId'];
- } else {
- if (!$userId = Info::getUserIdByUserName($userName)) {
- return static::notice('Member does not exist', 400);//会员不存在
- }
- }
- $listObj = new NetworkList();
- $data = $listObj->getList(['condition' => '', 'params' => [], 'others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]);
- return static::notice($data);
- }
- /**
- * 安置网络列表导出
- * @return mixed
- * @throws \yii\db\Exception
- * @throws \yii\web\HttpException
- */
- public function actionNetworkListExport() {
- $filter = $this->filterCondition([]);
- $userName = Yii::$app->request->get('userName');
- $deep = Yii::$app->request->get('deep', 2);
- $periodNum = Yii::$app->request->get('periodNum', null);
- if (!$userName) {
- $userId = Yii::$app->params['mainUserId'];
- } else {
- if (!$userId = Info::getUserIdByUserName($userName)) {
- return static::notice('Member does not exist', 400); // 会员不存在
- }
- }
- $form = new AtlasExportForm();
- $result = $form->run(array_merge($filter, ['others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]), 'Placement_Network'); // 安置网络列表
- if (!$result) {
- return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
- }
- return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
- }
- /**
- * 获取期数
- * @return mixed
- * @throws \yii\web\HttpException
- */
- public function getPeriod(){
- $period = Period::instance();
- $periodNum = $period->getNowPeriodNum();
- return static::notice([
- 'periodNum' => $periodNum,
- ]);
- }
- }
|