AtlasController.php 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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('会员不存在', 400);
  70. }
  71. } else {
  72. $userId = Yii::$app->params['mainUserId'];
  73. }
  74. $baseInfo = Info::baseInfo($userId, $periodNum);
  75. $decLevelConfig = Cache::getDecLevelConfig();
  76. $empLevelConfig = Cache::getEmpLevelConfig();
  77. return static::notice([
  78. [
  79. 'TOP_RELATION_DEEP' => $baseInfo['RELATION_DEEP'],
  80. 'TOP_NETWORK_DEEP' => $baseInfo['NETWORK_DEEP'],
  81. 'USER_ID' => $userId,
  82. 'USER_NAME' => $baseInfo['USER_NAME'],
  83. 'REAL_NAME' => $baseInfo['REAL_NAME'],
  84. 'PERIOD_AT' => $baseInfo['PERIOD_AT'],
  85. 'DEC_LV_NAME' => $decLevelConfig[$baseInfo['DEC_LV']]['LEVEL_NAME'],
  86. 'EMP_LV_NAME' => isset($empLevelConfig[$baseInfo['EMP_LV']])?$empLevelConfig[$baseInfo['EMP_LV']]['LEVEL_NAME']:'',
  87. 'leaf' => false,
  88. 'icon' => 'el-icon-user-solid',
  89. 'children' => null,
  90. 'isExpanded' => false,
  91. 'displayNone' => 'display-none',
  92. 'className' => 'first-node',
  93. 'listPeriodNum' => $periodNum
  94. ],
  95. ]);
  96. }
  97. /**
  98. * 开拓网络列表
  99. * @return mixed
  100. * @throws \yii\base\Exception
  101. * @throws \yii\web\HttpException
  102. */
  103. public function actionRelationList() {
  104. $userName = Yii::$app->request->get('userName');
  105. $deep = Yii::$app->request->get('deep', 2);
  106. $periodNum = Yii::$app->request->get('periodNum', null);
  107. if (!$userName) {
  108. $userId = Yii::$app->params['mainUserId'];
  109. } else {
  110. if (!$userId = Info::getUserIdByUserName($userName)) {
  111. return static::notice('Member does not exist', 400);//会员不存在
  112. }
  113. }
  114. $listObj = new RelationList();
  115. $data = $listObj->getList(['condition' => '', 'params' => [], 'others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]);
  116. return static::notice($data);
  117. }
  118. /**
  119. * 开拓网络列表导出
  120. * @return mixed
  121. * @throws \yii\db\Exception
  122. * @throws \yii\web\HttpException
  123. */
  124. public function actionRelationListExport() {
  125. $filter = $this->filterCondition([]);
  126. $userName = Yii::$app->request->get('userName');
  127. $deep = Yii::$app->request->get('deep', 2);
  128. $periodNum = Yii::$app->request->get('periodNum', null);
  129. if (!$userName) {
  130. $userId = Yii::$app->params['mainUserId'];
  131. } else {
  132. if (!$userId = Info::getUserIdByUserName($userName)) {
  133. return static::notice('会员不存在', 400);
  134. }
  135. }
  136. $form = new AtlasExportForm();
  137. $result = $form->run(array_merge($filter, ['others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]), '开拓网络列表');
  138. if (!$result) {
  139. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  140. }
  141. return static::notice('导出开始,请到文件管理-导出文件查看');
  142. }
  143. /**
  144. * 安置网络图
  145. * @return mixed
  146. * @throws \yii\web\HttpException
  147. */
  148. public function actionNetwork() {
  149. $userId = Yii::$app->request->get('id', Yii::$app->params['mainUserId']);
  150. $periodNum = Yii::$app->request->get('periodNum', null);
  151. $deep = Yii::$app->request->get('deep', 2);
  152. if ($deep > 20) {
  153. return static::notice('View the top 20 sub members of the member at most', 400);//最多查看会员的前20层子会员
  154. }
  155. $allData = UserNetwork::getChildrenWithDeepAndLayer($userId, $deep, 1, $periodNum);
  156. return static::notice(['allData' => $allData, 'periodNum' => $periodNum]);
  157. }
  158. /**
  159. * 安置网络列表
  160. * @return mixed
  161. * @throws \yii\base\Exception
  162. * @throws \yii\db\Exception
  163. * @throws \yii\web\HttpException
  164. */
  165. public function actionNetworkList() {
  166. $userName = Yii::$app->request->get('userName');
  167. $deep = Yii::$app->request->get('deep', 2);
  168. $periodNum = Yii::$app->request->get('periodNum', null);
  169. if (!$userName) {
  170. $userId = Yii::$app->params['mainUserId'];
  171. } else {
  172. if (!$userId = Info::getUserIdByUserName($userName)) {
  173. return static::notice('Member does not exist', 400);//会员不存在
  174. }
  175. }
  176. $listObj = new NetworkList();
  177. $data = $listObj->getList(['condition' => '', 'params' => [], 'others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]);
  178. return static::notice($data);
  179. }
  180. /**
  181. * 安置网络列表导出
  182. * @return mixed
  183. * @throws \yii\db\Exception
  184. * @throws \yii\web\HttpException
  185. */
  186. public function actionNetworkListExport() {
  187. $filter = $this->filterCondition([]);
  188. $userName = Yii::$app->request->get('userName');
  189. $deep = Yii::$app->request->get('deep', 2);
  190. $periodNum = Yii::$app->request->get('periodNum', null);
  191. if (!$userName) {
  192. $userId = Yii::$app->params['mainUserId'];
  193. } else {
  194. if (!$userId = Info::getUserIdByUserName($userName)) {
  195. return static::notice('会员不存在', 400);
  196. }
  197. }
  198. $form = new AtlasExportForm();
  199. $result = $form->run(array_merge($filter, ['others' => ['userId' => $userId, 'deep' => $deep, 'periodNum' => $periodNum]]), '安置网络列表');
  200. if (!$result) {
  201. return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
  202. }
  203. return static::notice('导出开始,请到文件管理-导出文件查看');
  204. }
  205. /**
  206. * 获取期数
  207. * @return mixed
  208. * @throws \yii\web\HttpException
  209. */
  210. public function getPeriod(){
  211. $period = Period::instance();
  212. $periodNum = $period->getNowPeriodNum();
  213. return static::notice([
  214. 'periodNum' => $periodNum,
  215. ]);
  216. }
  217. }