UserController.php 7.9 KB

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