AtlasController.php 9.9 KB

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