AtlasController.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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\BaUser;
  12. use common\models\BaUserInfo;
  13. use common\models\DeclarationLevel;
  14. use common\models\EmployLevel;
  15. use common\models\Period;
  16. use common\models\UserNetwork;
  17. use common\models\UserRelation;
  18. use Yii;
  19. use common\models\User;
  20. class AtlasController extends BaseController {
  21. public $modelClass = User::class;
  22. public function behaviors() {
  23. return parent::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(Yii::t('app', 'memberDoesNotExist'), 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(Yii::t('app', 'memberDoesNotInSamePlacementNetwork'), 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. 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. 'leaf' => false,
  62. 'icon' => 'el-icon-user-solid',
  63. 'children' => null,
  64. 'isExpanded' => false,
  65. 'displayNone' => 'display-none',
  66. 'className' => 'first-node',
  67. 'listPeriodNum' => $periodNum
  68. ],
  69. ]);
  70. }
  71. /**
  72. * 安置网络图
  73. * @return mixed
  74. * @throws \yii\web\HttpException
  75. */
  76. public function actionNetwork() {
  77. $userId = Yii::$app->request->get('id', \Yii::$app->user->id);
  78. $periodNum = Yii::$app->request->get('periodNum', null);
  79. $deep = Yii::$app->request->get('deep', 5);
  80. if ($deep > 20) {
  81. return static::notice(Yii::t('app', 'viewSubMembersMost'), 400);
  82. }
  83. $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  84. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  85. }
  86. /**
  87. * 安置网络列表
  88. * @return mixed
  89. * @throws \yii\base\Exception
  90. * @throws \yii\db\Exception
  91. * @throws \yii\web\HttpException
  92. */
  93. public function actionNetworkList() {
  94. $userName = Yii::$app->request->get('userName');
  95. $deep = Yii::$app->request->get('deep', 5);
  96. $periodNum = Yii::$app->request->get('periodNum', null);
  97. if (!$userName) {
  98. $userId = \Yii::$app->user->id;
  99. } else {
  100. if (!$userId = Info::getUserIdByUserName($userName)) {
  101. return static::notice(Yii::t('app', 'memberDoesNotExist'), 400);
  102. }
  103. $topUid = \Yii::$app->user->id;
  104. $userNetInfo = UserNetwork::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS');
  105. $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']);
  106. if(!in_array($topUid,$parentUidsArr)){
  107. return static::notice(Yii::t('app', 'memberDoesNotInSamePlacementNetwork'), 400);
  108. }
  109. }
  110. $period = Period::instance();
  111. $mainUserInfo = Info::baseInfo($userId, $periodNum);
  112. $decLevelConfig = Cache::getDecLevelConfig();
  113. $empLevelConfig = Cache::getEmpLevelConfig();
  114. $data = UserNetwork::getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum, 1 ? ['pageSize' => 10] : []);
  115. foreach($data['list'] as $key=>$value){
  116. $userBaseInfo = Info::baseInfo($value['USER_ID'], $periodNum);
  117. $data['list'][$key]['LIST_PERIOD_NUM'] = $periodNum?$periodNum:$period->getNowPeriodNum();
  118. $data['list'][$key]['COUNT_DEEP'] = (int)($userBaseInfo['NETWORK_DEEP']);
  119. $data['list'][$key]['USER_NAME'] = $userBaseInfo['USER_NAME'];
  120. $data['list'][$key]['SEE_USER_NAME'] = $userBaseInfo['USER_NAME'];
  121. $data['list'][$key]['REAL_NAME'] = $userBaseInfo['REAL_NAME'];
  122. $data['list'][$key]['PERIOD_AT'] = $userBaseInfo['PERIOD_AT'];
  123. $data['list'][$key]['DEC_LV_NAME'] = $decLevelConfig[$userBaseInfo['DEC_LV']]['LEVEL_NAME'];
  124. $data['list'][$key]['EMP_LV_NAME'] = $empLevelConfig[$userBaseInfo['EMP_LV']]['LEVEL_NAME'];
  125. }
  126. $data['periodNum'] = $periodNum;
  127. $data['listTopDeep'] = $mainUserInfo['NETWORK_DEEP'];
  128. return static::notice($data);
  129. }
  130. /**
  131. * 获取期数
  132. * @return mixed
  133. * @throws \yii\web\HttpException
  134. */
  135. public function getPeriod(){
  136. $period = Period::instance();
  137. $periodNum = $period->getNowPeriodNum();
  138. return static::notice([
  139. 'periodNum' => $periodNum,
  140. ]);
  141. }
  142. /**
  143. * 推荐网络图
  144. * @return mixed
  145. * @throws \yii\web\HttpException
  146. */
  147. public function actionRelation() {
  148. $userId = Yii::$app->request->get('id', \Yii::$app->user->id);
  149. $periodNum = Yii::$app->request->get('periodNum', null);
  150. $deep = Yii::$app->request->get('deep', 5);
  151. if ($deep > 20) {
  152. return static::notice(Yii::t('app', 'viewSubMembersMost'), 400);
  153. }
  154. $allData = UserRelation::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  155. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  156. }
  157. /**
  158. * 推荐网络列表
  159. * @return mixed
  160. * @throws \yii\base\Exception
  161. * @throws \yii\db\Exception
  162. * @throws \yii\web\HttpException
  163. */
  164. public function actionRelationList() {
  165. $userName = Yii::$app->request->get('userName');
  166. $deep = Yii::$app->request->get('deep', 5);
  167. $periodNum = Yii::$app->request->get('periodNum', null);
  168. if (!$userName) {
  169. $userId = \Yii::$app->user->id;
  170. } else {
  171. if (!$userId = Info::getUserIdByUserName($userName)) {
  172. return static::notice(Yii::t('app', 'memberDoesNotExist'), 400);
  173. }
  174. $topUid = \Yii::$app->user->id;
  175. $userNetInfo = UserRelation::findOneAsArray('USER_ID=:USER_ID', [':USER_ID' => $userId], 'PARENT_UIDS');
  176. $parentUidsArr = explode(',', $userNetInfo['PARENT_UIDS']);
  177. if(!in_array($topUid,$parentUidsArr)){
  178. return static::notice(Yii::t('app', 'memberDoesNotInSamePlacementNetwork'), 400);
  179. }
  180. }
  181. $period = Period::instance();
  182. $mainUserInfo = Info::baseInfo($userId, $periodNum);
  183. $decLevelConfig = Cache::getDecLevelConfig();
  184. $empLevelConfig = Cache::getEmpLevelConfig();
  185. $data = UserNetwork::getChildrenInDeepFromPeriodWithPage($userId, $deep, $periodNum, 1 ? ['pageSize' => 10] : []);
  186. foreach($data['list'] as $key=>$value){
  187. $userBaseInfo = Info::baseInfo($value['USER_ID'], $periodNum);
  188. $data['list'][$key]['LIST_PERIOD_NUM'] = $periodNum?$periodNum:$period->getNowPeriodNum();
  189. $data['list'][$key]['COUNT_DEEP'] = (int)($userBaseInfo['NETWORK_DEEP']);
  190. $data['list'][$key]['USER_NAME'] = $userBaseInfo['USER_NAME'];
  191. $data['list'][$key]['SEE_USER_NAME'] = $userBaseInfo['USER_NAME'];
  192. $data['list'][$key]['REAL_NAME'] = $userBaseInfo['REAL_NAME'];
  193. $data['list'][$key]['PERIOD_AT'] = $userBaseInfo['PERIOD_AT'];
  194. $data['list'][$key]['DEC_LV_NAME'] = $decLevelConfig[$userBaseInfo['DEC_LV']]['LEVEL_NAME'];
  195. $data['list'][$key]['EMP_LV_NAME'] = $empLevelConfig[$userBaseInfo['EMP_LV']]['LEVEL_NAME'];
  196. }
  197. $data['periodNum'] = $periodNum;
  198. $data['listTopDeep'] = $mainUserInfo['NETWORK_DEEP'];
  199. return static::notice($data);
  200. }
  201. /**
  202. * 会员推荐的BA会员
  203. * @return mixed
  204. * @throws \yii\web\HttpException
  205. */
  206. public function actionBrandAmbassadorList()
  207. {
  208. $condition = ' AND I.REC_UID = :REC_UID ';
  209. $params[':REC_UID'] = \Yii::$app->user->id;
  210. $data = BaUserInfo::lists($condition, $params, [
  211. 'select' => 'I.USER_ID, I.USER_NAME, U.REAL_NAME, U.PERIOD_AT, U.WHETHER_UPGRADE, U.BA_UPGRADE_AT',
  212. 'from' => BaUserInfo::tableName().' AS I',
  213. 'join' => [
  214. ['INNER JOIN', BaUser::tableName().' AS U', 'I.USER_ID = U.ID'],
  215. ],
  216. 'orderBy' => 'I.CREATED_AT DESC',
  217. ]);
  218. return static::notice($data);
  219. }
  220. }