UserController.php 6.6 KB

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