AtlasController.php 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace frontendApi\modules\v1\controllers;
  9. use common\helpers\Cache;
  10. use common\helpers\user\Info;
  11. use common\models\DeclarationLevel;
  12. use common\models\EmployLevel;
  13. use common\models\Period;
  14. use common\models\StarCrownLevel;
  15. use common\models\UserNetwork;
  16. use Yii;
  17. use common\models\User;
  18. class AtlasController extends BaseController {
  19. public $modelClass = User::class;
  20. public function behaviors() {
  21. $behaviors = parent::behaviors();
  22. return $behaviors;
  23. }
  24. /**
  25. * 主点位信息
  26. * @return mixed
  27. * @throws \yii\base\Exception
  28. * @throws \yii\db\Exception
  29. * @throws \yii\web\HttpException
  30. */
  31. public function actionMainUserInfo() {
  32. $userName = Yii::$app->request->get('userName', '');
  33. $periodNum = Yii::$app->request->get('periodNum', null);
  34. if ($userName !== '') {
  35. if (!$userId = Info::getUserIdByUserName($userName)) {
  36. return static::notice('Member does not exist', 400); // 会员不存在
  37. }
  38. $topUid = \Yii::$app->user->id;
  39. $userNetInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS');
  40. $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']);
  41. if(!in_array($topUid,$parentUidsArr)){
  42. return static::notice('会员与当前用户不再同一安置网络内', 400);
  43. }
  44. } else {
  45. $userId = \Yii::$app->user->id;
  46. }
  47. $baseInfo = Info::baseInfo($userId, $periodNum);
  48. $decLevelConfig = Cache::getDecLevelConfig();
  49. $empLevelConfig = Cache::getEmpLevelConfig();
  50. $crownLevelConfig = Cache::getStarCrownLevelConfig();
  51. return static::notice([
  52. [
  53. 'TOP_RELATION_DEEP' => $baseInfo['RELATION_DEEP'],
  54. 'TOP_NETWORK_DEEP' => $baseInfo['NETWORK_DEEP'],
  55. 'USER_ID' => $userId,
  56. 'USER_NAME' => $baseInfo['USER_NAME'],
  57. 'REAL_NAME' => $baseInfo['REAL_NAME'],
  58. 'PERIOD_AT' => $baseInfo['PERIOD_AT'],
  59. 'DEC_LV_NAME' => $decLevelConfig[$baseInfo['DEC_LV']]['LEVEL_NAME'] ?? $decLevelConfig[DeclarationLevel::getDefaultLevelId()]['LEVEL_NAME'],
  60. 'EMP_LV_NAME' => $empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME'] ?? $empLevelConfig[EmployLevel::getDefaultLevelId()]['LEVEL_NAME'],
  61. 'CROWN_LV_NAME' => $crownLevelConfig[$baseInfo['CROWN_LV']]['LEVEL_NAME'] ?? $crownLevelConfig[StarCrownLevel::getDefaultLevelId()]['LEVEL_NAME'],
  62. 'leaf' => false,
  63. 'icon' => 'el-icon-user-solid',
  64. 'children' => null,
  65. 'isExpanded' => false,
  66. 'displayNone' => 'display-none',
  67. 'className' => 'first-node',
  68. 'listPeriodNum' => $periodNum
  69. ],
  70. ]);
  71. }
  72. /**
  73. * 安置网络图
  74. * @return mixed
  75. * @throws \yii\web\HttpException
  76. */
  77. public function actionNetwork() {
  78. $userId = Yii::$app->request->get('id', \Yii::$app->user->id);
  79. $periodNum = Yii::$app->request->get('periodNum', null);
  80. $deep = Yii::$app->request->get('deep', 5);
  81. if ($deep > 20) {
  82. return static::notice('View the top 20 sub members of the member at most', 400); // 最多查看会员的前20层子会员
  83. }
  84. $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  85. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  86. }
  87. /**
  88. * 安置网络列表
  89. * @return mixed
  90. * @throws \yii\base\Exception
  91. * @throws \yii\db\Exception
  92. * @throws \yii\web\HttpException
  93. */
  94. public function actionNetworkList() {
  95. $userName = Yii::$app->request->get('userName');
  96. $deep = Yii::$app->request->get('deep', 5);
  97. $periodNum = Yii::$app->request->get('periodNum', null);
  98. if (!$userName) {
  99. $userId = \Yii::$app->user->id;
  100. } else {
  101. if (!$userId = Info::getUserIdByUserName($userName)) {
  102. return static::notice('Member does not exist', 400); // 会员不存在
  103. }
  104. $topUid = \Yii::$app->user->id;
  105. $userNetInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS');
  106. $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']);
  107. if(!in_array($topUid,$parentUidsArr)){
  108. return static::notice('会员与当前用户不再同一安置网络内', 400);
  109. }
  110. }
  111. $period = Period::instance();
  112. $mainUserInfo = Info::baseInfo($userId, $periodNum);
  113. $decLevelConfig = Cache::getDecLevelConfig();
  114. $empLevelConfig = Cache::getEmpLevelConfig();
  115. $data = UserNetwork::getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum, 1 ? ['pageSize' => 10] : []);
  116. foreach($data['list'] as $key=>$value){
  117. $userBaseInfo = Info::baseInfo($value['USER_ID'], $periodNum);
  118. $data['list'][$key]['LIST_PERIOD_NUM'] = $periodNum?$periodNum:$period->getNowPeriodNum();
  119. $data['list'][$key]['COUNT_DEEP'] = (int)($userBaseInfo['NETWORK_DEEP']);
  120. $data['list'][$key]['USER_NAME'] = $userBaseInfo['USER_NAME'];
  121. $data['list'][$key]['SEE_USER_NAME'] = $userBaseInfo['USER_NAME'];
  122. $data['list'][$key]['REAL_NAME'] = $userBaseInfo['REAL_NAME'];
  123. $data['list'][$key]['PERIOD_AT'] = $userBaseInfo['PERIOD_AT'];
  124. $data['list'][$key]['DEC_LV_NAME'] = $decLevelConfig[$userBaseInfo['DEC_LV']]['LEVEL_NAME'];
  125. $data['list'][$key]['EMP_LV_NAME'] = $empLevelConfig[$userBaseInfo['EMP_LV']]['LEVEL_NAME'];
  126. }
  127. $data['periodNum'] = $periodNum;
  128. $data['listTopDeep'] = $mainUserInfo['NETWORK_DEEP'];
  129. return static::notice($data);
  130. }
  131. /**
  132. * 获取期数
  133. * @return mixed
  134. * @throws \yii\web\HttpException
  135. */
  136. public function getPeriod(){
  137. $period = Period::instance();
  138. $periodNum = $period->getNowPeriodNum();
  139. return static::notice([
  140. 'periodNum' => $periodNum,
  141. ]);
  142. }
  143. }