AtlasController.php 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  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 common\models\UserRelation;
  17. use Yii;
  18. use common\models\User;
  19. class AtlasController extends BaseController {
  20. public $modelClass = User::class;
  21. public function behaviors() {
  22. $behaviors = parent::behaviors();
  23. return $behaviors;
  24. }
  25. /**
  26. * 主点位信息
  27. * @return mixed
  28. * @throws \yii\base\Exception
  29. * @throws \yii\db\Exception
  30. * @throws \yii\web\HttpException
  31. */
  32. public function actionMainUserInfo() {
  33. $userName = Yii::$app->request->get('userName', '');
  34. $periodNum = Yii::$app->request->get('periodNum', null);
  35. if ($userName !== '') {
  36. if (!$userId = Info::getUserIdByUserName($userName)) {
  37. return static::notice('Member does not exist', 400); // 会员不存在
  38. }
  39. $topUid = \Yii::$app->user->id;
  40. $userNetInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS');
  41. $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']);
  42. if(!in_array($topUid,$parentUidsArr)){
  43. return static::notice('The member is not in the same placement network as the current user', 400); // 会员与当前用户不再同一安置网络内
  44. }
  45. } else {
  46. $userId = \Yii::$app->user->id;
  47. }
  48. $baseInfo = Info::baseInfo($userId, $periodNum);
  49. $decLevelConfig = Cache::getDecLevelConfig();
  50. $empLevelConfig = Cache::getEmpLevelConfig();
  51. $crownLevelConfig = Cache::getStarCrownLevelConfig();
  52. return static::notice([
  53. [
  54. 'TOP_RELATION_DEEP' => $baseInfo['RELATION_DEEP'],
  55. 'TOP_NETWORK_DEEP' => $baseInfo['NETWORK_DEEP'],
  56. 'USER_ID' => $userId,
  57. 'USER_NAME' => $baseInfo['USER_NAME'],
  58. 'REAL_NAME' => $baseInfo['REAL_NAME'],
  59. 'PERIOD_AT' => $baseInfo['PERIOD_AT'],
  60. 'DEC_LV_NAME' => $decLevelConfig[$baseInfo['DEC_LV']]['LEVEL_NAME'] ?? $decLevelConfig[DeclarationLevel::getDefaultLevelId()]['LEVEL_NAME'],
  61. 'EMP_LV_NAME' => $empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME'] ?? $empLevelConfig[EmployLevel::getDefaultLevelId()]['LEVEL_NAME'],
  62. 'CROWN_LV_NAME' => $crownLevelConfig[$baseInfo['CROWN_LV']]['LEVEL_NAME'] ?? $crownLevelConfig[StarCrownLevel::getDefaultLevelId()]['LEVEL_NAME'],
  63. 'leaf' => false,
  64. 'icon' => 'el-icon-user-solid',
  65. 'children' => null,
  66. 'isExpanded' => false,
  67. 'displayNone' => 'display-none',
  68. 'className' => 'first-node',
  69. 'listPeriodNum' => $periodNum
  70. ],
  71. ]);
  72. }
  73. /**
  74. * 安置网络图
  75. * @return mixed
  76. * @throws \yii\web\HttpException
  77. */
  78. public function actionNetwork() {
  79. $userId = Yii::$app->request->get('id', \Yii::$app->user->id);
  80. $periodNum = Yii::$app->request->get('periodNum', null);
  81. $deep = Yii::$app->request->get('deep', 5);
  82. if ($deep > 20) {
  83. return static::notice('View the top 20 sub members of the member at most', 400); // 最多查看会员的前20层子会员
  84. }
  85. $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  86. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  87. }
  88. /**
  89. * 安置网络列表
  90. * @return mixed
  91. * @throws \yii\base\Exception
  92. * @throws \yii\db\Exception
  93. * @throws \yii\web\HttpException
  94. */
  95. public function actionNetworkList() {
  96. $userName = Yii::$app->request->get('userName');
  97. $deep = Yii::$app->request->get('deep', 5);
  98. $periodNum = Yii::$app->request->get('periodNum', null);
  99. if (!$userName) {
  100. $userId = \Yii::$app->user->id;
  101. } else {
  102. if (!$userId = Info::getUserIdByUserName($userName)) {
  103. return static::notice('Member does not exist', 400); // 会员不存在
  104. }
  105. $topUid = \Yii::$app->user->id;
  106. $userNetInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS');
  107. $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']);
  108. if(!in_array($topUid,$parentUidsArr)){
  109. return static::notice('The member is not in the same placement network as the current user', 400); // 会员与当前用户不再同一安置网络内
  110. }
  111. }
  112. $period = Period::instance();
  113. $mainUserInfo = Info::baseInfo($userId, $periodNum);
  114. $decLevelConfig = Cache::getDecLevelConfig();
  115. $empLevelConfig = Cache::getEmpLevelConfig();
  116. $data = UserNetwork::getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum, 1 ? ['pageSize' => 10] : []);
  117. foreach($data['list'] as $key=>$value){
  118. $userBaseInfo = Info::baseInfo($value['USER_ID'], $periodNum);
  119. $data['list'][$key]['LIST_PERIOD_NUM'] = $periodNum?$periodNum:$period->getNowPeriodNum();
  120. $data['list'][$key]['COUNT_DEEP'] = (int)($userBaseInfo['NETWORK_DEEP']);
  121. $data['list'][$key]['USER_NAME'] = $userBaseInfo['USER_NAME'];
  122. $data['list'][$key]['SEE_USER_NAME'] = $userBaseInfo['USER_NAME'];
  123. $data['list'][$key]['REAL_NAME'] = $userBaseInfo['REAL_NAME'];
  124. $data['list'][$key]['PERIOD_AT'] = $userBaseInfo['PERIOD_AT'];
  125. $data['list'][$key]['DEC_LV_NAME'] = $decLevelConfig[$userBaseInfo['DEC_LV']]['LEVEL_NAME'];
  126. $data['list'][$key]['EMP_LV_NAME'] = $empLevelConfig[$userBaseInfo['EMP_LV']]['LEVEL_NAME'];
  127. }
  128. $data['periodNum'] = $periodNum;
  129. $data['listTopDeep'] = $mainUserInfo['NETWORK_DEEP'];
  130. return static::notice($data);
  131. }
  132. /**
  133. * 获取期数
  134. * @return mixed
  135. * @throws \yii\web\HttpException
  136. */
  137. public function getPeriod(){
  138. $period = Period::instance();
  139. $periodNum = $period->getNowPeriodNum();
  140. return static::notice([
  141. 'periodNum' => $periodNum,
  142. ]);
  143. }
  144. /**
  145. * 推荐网络图
  146. * @return mixed
  147. * @throws \yii\web\HttpException
  148. */
  149. public function actionRelation() {
  150. $userId = Yii::$app->request->get('id', \Yii::$app->user->id);
  151. $periodNum = Yii::$app->request->get('periodNum', null);
  152. $deep = Yii::$app->request->get('deep', 5);
  153. if ($deep > 20) {
  154. return static::notice('View the top 20 sub members of the member at most', 400); // 最多查看会员的前20层子会员
  155. }
  156. $allData = UserRelation::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  157. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  158. }
  159. /**
  160. * 推荐网络列表
  161. * @return mixed
  162. * @throws \yii\base\Exception
  163. * @throws \yii\db\Exception
  164. * @throws \yii\web\HttpException
  165. */
  166. public function actionRelationList() {
  167. $userName = Yii::$app->request->get('userName');
  168. $deep = Yii::$app->request->get('deep', 5);
  169. $periodNum = Yii::$app->request->get('periodNum', null);
  170. if (!$userName) {
  171. $userId = \Yii::$app->user->id;
  172. } else {
  173. if (!$userId = Info::getUserIdByUserName($userName)) {
  174. return static::notice('Member does not exist', 400); // 会员不存在
  175. }
  176. $topUid = \Yii::$app->user->id;
  177. $userNetInfo = UserRelation::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS');
  178. $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']);
  179. if(!in_array($topUid,$parentUidsArr)){
  180. return static::notice('会员与当前用户不再同一安置网络内', 400);
  181. }
  182. }
  183. $period = Period::instance();
  184. $mainUserInfo = Info::baseInfo($userId, $periodNum);
  185. $decLevelConfig = Cache::getDecLevelConfig();
  186. $empLevelConfig = Cache::getEmpLevelConfig();
  187. $data = UserNetwork::getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum, 1 ? ['pageSize' => 10] : []);
  188. foreach($data['list'] as $key=>$value){
  189. $userBaseInfo = Info::baseInfo($value['USER_ID'], $periodNum);
  190. $data['list'][$key]['LIST_PERIOD_NUM'] = $periodNum?$periodNum:$period->getNowPeriodNum();
  191. $data['list'][$key]['COUNT_DEEP'] = (int)($userBaseInfo['NETWORK_DEEP']);
  192. $data['list'][$key]['USER_NAME'] = $userBaseInfo['USER_NAME'];
  193. $data['list'][$key]['SEE_USER_NAME'] = $userBaseInfo['USER_NAME'];
  194. $data['list'][$key]['REAL_NAME'] = $userBaseInfo['REAL_NAME'];
  195. $data['list'][$key]['PERIOD_AT'] = $userBaseInfo['PERIOD_AT'];
  196. $data['list'][$key]['DEC_LV_NAME'] = $decLevelConfig[$userBaseInfo['DEC_LV']]['LEVEL_NAME'];
  197. $data['list'][$key]['EMP_LV_NAME'] = $empLevelConfig[$userBaseInfo['EMP_LV']]['LEVEL_NAME'];
  198. }
  199. $data['periodNum'] = $periodNum;
  200. $data['listTopDeep'] = $mainUserInfo['NETWORK_DEEP'];
  201. return static::notice($data);
  202. }
  203. }