AtlasController.php 8.6 KB

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