UserController.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: leo
  5. * Date: 2018/3/9
  6. * Time: 上午11:56
  7. */
  8. namespace console\controllers;
  9. use backendApi\modules\v1\models\lists\bonus\PerfOrderList;
  10. use backendApi\modules\v1\models\lists\user\BindList;
  11. use backendApi\modules\v1\models\lists\user\GroupList;
  12. use backendApi\modules\v1\models\lists\user\IndexList;
  13. use backendApi\modules\v1\models\lists\user\BaUserList;
  14. use backendApi\modules\v1\models\lists\user\MoveList;
  15. use backendApi\modules\v1\models\lists\user\StatusAuditList;
  16. use backendApi\modules\v1\models\lists\user\SystemList;
  17. use backendApi\modules\v1\models\lists\user\TeamworkList;
  18. use backendApi\modules\v1\models\lists\user\YearHighestEmpLvList;
  19. use common\helpers\Cache;
  20. use common\libs\export\BaseExport;
  21. use common\libs\export\module\BonusExport;
  22. use common\libs\export\module\UserExport;
  23. use common\models\forms\NetMoveForm;
  24. use common\helpers\Form;
  25. use Yii;
  26. use yii\db\Exception;
  27. class UserController extends BaseController
  28. {
  29. /**
  30. * 安置网络移网
  31. * @param $taskKey
  32. * @throws \Exception
  33. */
  34. public function actionMoveNetwork($taskKey){
  35. $params = Cache::getAsyncParams($taskKey);
  36. $formModel = new NetMoveForm();
  37. $formModel->scenario = 'async';
  38. $handleResult = false;
  39. if($formModel->load($params, '') && $formModel->moveAsync()){
  40. $handleResult = true;
  41. echo sprintf("时间:[%s]移网, 会员安置网络【%s】移网成功".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
  42. //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员安置网络{$params['moveUserName']}移网成功");
  43. } else {
  44. echo sprintf("时间:[%s]移网, 会员安置网络【%s】移网失败".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
  45. //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员安置网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()), false);
  46. }
  47. if(!$handleResult){
  48. // Log::async([
  49. // 'type' => LogAsync::TYPE_USER,
  50. // 'route' => 'user/move-network',
  51. // 'title' => "会员安置网络{$params['moveUserName']}移网失败",
  52. // 'detail' => "会员安置网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()),
  53. // 'status' => 0,
  54. // ]);
  55. }
  56. }
  57. /**
  58. * 移开拓网络
  59. * @param $taskKey
  60. * @throws Exception
  61. */
  62. public function actionMoveRelation($taskKey){
  63. $params = Cache::getAsyncParams($taskKey);
  64. $formModel = new NetMoveForm();
  65. $formModel->scenario = 'async';
  66. $handleResult = false;
  67. if($formModel->load($params, '') && $formModel->moveAsync()){
  68. $handleResult = true;
  69. echo sprintf("时间:[%s]移网, 会员开拓网络【%s】移网成功".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
  70. //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员开拓网络{$params['moveUserName']}移网成功");
  71. } else {
  72. echo sprintf("时间:[%s]移网, 会员开拓网络【%s】移网失败".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
  73. //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员开拓网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()), false);
  74. }
  75. if(!$handleResult){
  76. // Log::async([
  77. // 'type' => LogAsync::TYPE_USER,
  78. // 'route' => 'user/move-relation',
  79. // 'title' => "会员开拓网络{$params['moveUserName']}移网失败",
  80. // 'detail' => "会员开拓网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()),
  81. // 'status' => 0,
  82. // ]);
  83. }
  84. }
  85. /**
  86. * 会员列表导出
  87. * @param $taskId
  88. * @return bool
  89. */
  90. public function actionIndexExport($taskId){
  91. return $this->_export($taskId, IndexList::class, 'Member_list');
  92. }
  93. /**
  94. * 会员绑定列表导出
  95. * @param $taskId
  96. * @return bool
  97. */
  98. public function actionBindExport($taskId){
  99. return $this->_export($taskId, BindList::class, '会员绑定列表');
  100. }
  101. /**
  102. * 点位合作导出
  103. * @param $taskId
  104. * @return bool
  105. */
  106. public function actionTeamworkExport($taskId){
  107. return $this->_export($taskId, TeamworkList::class, '点位合作');
  108. }
  109. /**
  110. * 体系管理导出
  111. * @param $taskId
  112. * @return bool
  113. */
  114. public function actionSystemExport($taskId){
  115. return $this->_export($taskId, SystemList::class, '体系管理');
  116. }
  117. /**
  118. * 团队领导人列表导出
  119. * @param $taskId
  120. * @return bool
  121. */
  122. public function actionGroupExport($taskId){
  123. return $this->_export($taskId, GroupList::class, '团队领导人列表');
  124. }
  125. /**
  126. * 移网管理导出
  127. * @param $taskId
  128. * @return bool
  129. */
  130. public function actionMoveExport($taskId){
  131. return $this->_export($taskId, MoveList::class, '移网管理');
  132. }
  133. /**
  134. * 会员状态管理导出
  135. * @param $taskId
  136. * @return bool
  137. */
  138. public function actionStatusAuditExport($taskId){
  139. return $this->_export($taskId, StatusAuditList::class, '会员状态管理');
  140. }
  141. /**
  142. * 会员历史年度最高聘级表导出
  143. * @param $taskId
  144. * @return bool
  145. */
  146. public function actionYearHighestEmpLvExport($taskId){
  147. return $this->_export($taskId, YearHighestEmpLvList::class, '会员历史年度最高聘级表');
  148. }
  149. /**
  150. * 导出方法
  151. * @param $taskId
  152. * @param $className
  153. * @param $listName
  154. * @return bool
  155. */
  156. private function _export($taskId, $className, $listName){
  157. $factory = UserExport::factory($taskId);
  158. $factory->listModelClass = $className;
  159. try {
  160. if ($factory->generate()) {
  161. \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出成功');
  162. }
  163. unset($factory, $taskId, $className, $listName);
  164. return true;
  165. } catch (\Exception $e) {
  166. echo $listName.'导出失败。详情:' . $e->getMessage();
  167. \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出失败。详情:' . $e->getMessage(), false);
  168. }
  169. unset($factory, $taskId, $className, $listName);
  170. return false;
  171. }
  172. /**
  173. * BA会员列表导出
  174. * @param $taskId
  175. * @return bool
  176. */
  177. public function actionBaUserListExport($taskId){
  178. return $this->_export($taskId, BaUserList::class, 'Ba_Member_list');
  179. }
  180. }