AtlasController.php 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/2/24
  6. * Time: 下午12:48
  7. */
  8. namespace backendApi\modules\v1\controllers;
  9. use backendApi\modules\v1\models\exportForms\AtlasExportForm;
  10. use backendApi\modules\v1\models\lists\atlas\EmpUserList;
  11. use backendApi\modules\v1\models\lists\atlas\NetworkLineList;
  12. use backendApi\modules\v1\models\lists\atlas\NetworkList;
  13. use backendApi\modules\v1\models\lists\atlas\RelationList;
  14. use common\helpers\Cache;
  15. use common\helpers\Form;
  16. use common\helpers\Level;
  17. use common\helpers\user\Perf;
  18. use common\helpers\user\Info;
  19. use common\models\CalcBonus;
  20. //use common\models\exportForms\AtlasRelationListExport;
  21. use common\models\PerfMonth;
  22. use common\models\Period;
  23. use common\models\DeclarationLevel;
  24. use common\models\EmployLevel;
  25. use common\models\UserInfo;
  26. use common\models\UserNetwork;
  27. use common\models\UserRelation;
  28. use Yii;
  29. use common\models\User;
  30. class AtlasController extends BaseController {
  31. public $modelClass = User::class;
  32. public function behaviors() {
  33. $behaviors = parent::behaviors();
  34. //$behaviors['contentNegotiator']['formats']['text/html'] = Response::FORMAT_JSON;
  35. return $behaviors;
  36. }
  37. /**
  38. * 开拓网络图
  39. * @return mixed
  40. * @throws \yii\base\Exception
  41. * @throws \yii\db\Exception
  42. * @throws \yii\web\HttpException
  43. */
  44. public function actionRelation() {
  45. $userId = Yii::$app->request->get('id', Yii::$app->params['mainUserId']);
  46. $deep = Yii::$app->request->get('deep', 2);
  47. $periodNum = Yii::$app->request->get('periodNum', null);
  48. if ($deep > 23) {
  49. return static::notice('Top 23 sub members of members can be viewed at most', 400);//最多查看会员的前23层子会员
  50. }
  51. $allData = UserRelation::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  52. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  53. }
  54. /**
  55. * 主点位信息
  56. * @return mixed
  57. * @throws \yii\base\Exception
  58. * @throws \yii\db\Exception
  59. * @throws \yii\web\HttpException
  60. */
  61. public function actionMainUserInfo() {
  62. $userName = Yii::$app->request->get('userName', '');
  63. $periodNum = Yii::$app->request->get('periodNum', null);
  64. $period = Period::instance();
  65. $yearMonth = $period->getYearMonth($periodNum);
  66. if ($userName !== '') {
  67. //$oneUser = Info::getUserByUserNameFromUserInfoTable($userName);
  68. if (!$userId = Info::getUserIdByUserName($userName)) {
  69. return static::notice('Member does not exist', 400); // 会员不存在
  70. }
  71. } else {
  72. $userId = Yii::$app->params['mainUserId'];
  73. }
  74. $baseInfo = Info::baseInfo($userId, $periodNum);
  75. // print_r($baseInfo);exit;
  76. $decLevelConfig = Cache::getDecLevelConfig();
  77. $empLevelConfig = Cache::getEmpLevelConfig();
  78. $crownLevelConfig = Cache::getStarCrownLevelConfig();
  79. return static::notice([
  80. [
  81. 'TOP_RELATION_DEEP' => $baseInfo['RELATION_DEEP'],
  82. 'TOP_NETWORK_DEEP' => $baseInfo['NETWORK_DEEP'],
  83. 'USER_ID' => $userId,
  84. 'USER_NAME' => $baseInfo['USER_NAME'],
  85. 'REAL_NAME' => $baseInfo['REAL_NAME'],
  86. 'PERIOD_AT' => $baseInfo['PERIOD_AT'],
  87. 'DEC_LV_NAME' => $decLevelConfig[$baseInfo['DEC_LV']]['LEVEL_NAME'],
  88. 'EMP_LV_NAME' => isset($empLevelConfig[$baseInfo['EMP_LV']])?$empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME']:'0-Star Director',
  89. 'CROWN_LV_NAME' => isset($crownLevelConfig[$baseInfo['CROWN_LV']])?$crownLevelConfig[$baseInfo['CROWN_LV']]['LEVEL_NAME']:'0-Star Crown',
  90. 'leaf' => false,
  91. 'icon' => 'el-icon-user-solid',
  92. 'children' => null,
  93. 'isExpanded' => false,
  94. 'displayNone' => 'display-none',
  95. 'className' => 'first-node',
  96. 'listPeriodNum' => $periodNum
  97. ],
  98. ]);
  99. }
  100. /**
  101. * 开拓网络列表
  102. * @return mixed
  103. * @throws \yii\base\Exception
  104. * @throws \yii\web\HttpException
  105. */
  106. public function actionRelationList() {
  107. $userName = Yii::$app->request->get('userName');
  108. $deep = Yii::$app->request->get('deep', 2);
  109. $periodNum = Yii::$app->request->get('periodNum', null);
  110. if (!$userName) {
  111. $userId = Yii::$app->params['mainUserId'];
  112. } else {
  113. if (!$userId = Info::getUserIdByUserName($userName)) {
  114. return static::notice('Member does not exist', 400);//会员不存在
  115. }
  116. }
  117. $listObj = new RelationList();
  118. $data = $listObj->getList(['condition' => '', 'params' => [], 'others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]);
  119. return static::notice($data);
  120. }
  121. /**
  122. * 开拓网络列表导出
  123. * @return mixed
  124. * @throws \yii\db\Exception
  125. * @throws \yii\web\HttpException
  126. */
  127. public function actionRelationListExport() {
  128. $filter = $this->filterCondition([]);
  129. $userName = Yii::$app->request->get('userName');
  130. $deep = Yii::$app->request->get('deep', 2);
  131. $periodNum = Yii::$app->request->get('periodNum', null);
  132. if (!$userName) {
  133. $userId = Yii::$app->params['mainUserId'];
  134. } else {
  135. if (!$userId = Info::getUserIdByUserName($userName)) {
  136. return static::notice('Member does not exist', 400); // 会员不存在
  137. }
  138. }
  139. $form = new AtlasExportForm();
  140. $result = $form->run(array_merge($filter, ['others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]), 'Sponsor_Network'); // 开拓网络列表
  141. if (!$result) {
  142. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  143. }
  144. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  145. }
  146. /**
  147. * 安置网络图
  148. * @return mixed
  149. * @throws \yii\web\HttpException
  150. */
  151. public function actionNetwork() {
  152. $userId = Yii::$app->request->get('id', Yii::$app->params['mainUserId']);
  153. $periodNum = Yii::$app->request->get('periodNum', null);
  154. $deep = Yii::$app->request->get('deep', 2);
  155. if ($deep > 20) {
  156. return static::notice('View the top 20 sub members of the member at most', 400);//最多查看会员的前20层子会员
  157. }
  158. $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  159. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  160. }
  161. /**
  162. * 安置网络列表
  163. * @return mixed
  164. * @throws \yii\base\Exception
  165. * @throws \yii\db\Exception
  166. * @throws \yii\web\HttpException
  167. */
  168. public function actionNetworkList() {
  169. $userName = Yii::$app->request->get('userName');
  170. $deep = Yii::$app->request->get('deep', 2);
  171. $periodNum = Yii::$app->request->get('periodNum', null);
  172. if (!$userName) {
  173. $userId = Yii::$app->params['mainUserId'];
  174. } else {
  175. if (!$userId = Info::getUserIdByUserName($userName)) {
  176. return static::notice('Member does not exist', 400);//会员不存在
  177. }
  178. }
  179. $listObj = new NetworkList();
  180. $data = $listObj->getList(['condition' => '', 'params' => [], 'others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]);
  181. return static::notice($data);
  182. }
  183. /**
  184. * 安置网络列表导出
  185. * @return mixed
  186. * @throws \yii\db\Exception
  187. * @throws \yii\web\HttpException
  188. */
  189. public function actionNetworkListExport() {
  190. $filter = $this->filterCondition([]);
  191. $userName = Yii::$app->request->get('userName');
  192. $deep = Yii::$app->request->get('deep', 2);
  193. $periodNum = Yii::$app->request->get('periodNum', null);
  194. if (!$userName) {
  195. $userId = Yii::$app->params['mainUserId'];
  196. } else {
  197. if (!$userId = Info::getUserIdByUserName($userName)) {
  198. return static::notice('Member does not exist', 400); // 会员不存在
  199. }
  200. }
  201. $form = new AtlasExportForm();
  202. $result = $form->run(array_merge($filter, ['others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]), 'Placement_Network'); // 安置网络列表
  203. if (!$result) {
  204. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  205. }
  206. return static::notice(Yii::t('ctx', 'startExporting')); // 导出开始,请到文件管理-导出文件查看
  207. }
  208. /**
  209. * 获取期数
  210. * @return mixed
  211. * @throws \yii\web\HttpException
  212. */
  213. public function getPeriod(){
  214. $period = Period::instance();
  215. $periodNum = $period->getNowPeriodNum();
  216. return static::notice([
  217. 'periodNum' => $periodNum,
  218. ]);
  219. }
  220. }