AtlasController.php 10 KB

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