| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219 |
- <?php
- /**
- * Created by PhpStorm.
- * User: leo
- * Date: 2018/3/9
- * Time: 上午11:56
- */
- namespace console\controllers;
- use backendApi\modules\v1\models\lists\bonus\PerfOrderList;
- use backendApi\modules\v1\models\lists\user\BindList;
- use backendApi\modules\v1\models\lists\user\GroupList;
- use backendApi\modules\v1\models\lists\user\IndexList;
- use backendApi\modules\v1\models\lists\user\BaUserList;
- use backendApi\modules\v1\models\lists\user\MoveList;
- use backendApi\modules\v1\models\lists\user\StatusAuditList;
- use backendApi\modules\v1\models\lists\user\SystemList;
- use backendApi\modules\v1\models\lists\user\TeamworkList;
- use backendApi\modules\v1\models\lists\user\YearHighestEmpLvList;
- use common\helpers\Cache;
- use common\libs\export\BaseExport;
- use common\libs\export\module\BaUserExport;
- use common\libs\export\module\BonusExport;
- use common\libs\export\module\UserExport;
- use common\models\forms\NetMoveForm;
- use common\helpers\Form;
- use Yii;
- use yii\db\Exception;
- class UserController extends BaseController
- {
- /**
- * 安置网络移网
- * @param $taskKey
- * @throws \Exception
- */
- public function actionMoveNetwork($taskKey){
- $params = Cache::getAsyncParams($taskKey);
- $formModel = new NetMoveForm();
- $formModel->scenario = 'async';
- $handleResult = false;
- if($formModel->load($params, '') && $formModel->moveAsync()){
- $handleResult = true;
- echo sprintf("时间:[%s]移网, 会员安置网络【%s】移网成功".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
- //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员安置网络{$params['moveUserName']}移网成功");
- } else {
- echo sprintf("时间:[%s]移网, 会员安置网络【%s】移网失败".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
- //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员安置网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()), false);
- }
- if(!$handleResult){
- // Log::async([
- // 'type' => LogAsync::TYPE_USER,
- // 'route' => 'user/move-network',
- // 'title' => "会员安置网络{$params['moveUserName']}移网失败",
- // 'detail' => "会员安置网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()),
- // 'status' => 0,
- // ]);
- }
- }
- /**
- * 移开拓网络
- * @param $taskKey
- * @throws Exception
- */
- public function actionMoveRelation($taskKey){
- $params = Cache::getAsyncParams($taskKey);
- $formModel = new NetMoveForm();
- $formModel->scenario = 'async';
- $handleResult = false;
- if($formModel->load($params, '') && $formModel->moveAsync()){
- $handleResult = true;
- echo sprintf("时间:[%s]移网, 会员开拓网络【%s】移网成功".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
- //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员开拓网络{$params['moveUserName']}移网成功");
- } else {
- echo sprintf("时间:[%s]移网, 会员开拓网络【%s】移网失败".PHP_EOL, date('Y-m-d H:i:s', time()), $params['moveUserName']);
- //\Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($params['handleUserId'], "会员开拓网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()), false);
- }
- if(!$handleResult){
- // Log::async([
- // 'type' => LogAsync::TYPE_USER,
- // 'route' => 'user/move-relation',
- // 'title' => "会员开拓网络{$params['moveUserName']}移网失败",
- // 'detail' => "会员开拓网络{$params['moveUserName']}移网失败,原因:".Form::formatErrorsForApi($formModel->getErrors()),
- // 'status' => 0,
- // ]);
- }
- }
- /**
- * 会员列表导出
- * @param $taskId
- * @return bool
- */
- public function actionIndexExport($taskId){
- return $this->_export($taskId, IndexList::class, 'Member_list');
- }
- /**
- * 会员绑定列表导出
- * @param $taskId
- * @return bool
- */
- public function actionBindExport($taskId){
- return $this->_export($taskId, BindList::class, '会员绑定列表');
- }
- /**
- * 点位合作导出
- * @param $taskId
- * @return bool
- */
- public function actionTeamworkExport($taskId){
- return $this->_export($taskId, TeamworkList::class, '点位合作');
- }
- /**
- * 体系管理导出
- * @param $taskId
- * @return bool
- */
- public function actionSystemExport($taskId){
- return $this->_export($taskId, SystemList::class, '体系管理');
- }
- /**
- * 团队领导人列表导出
- * @param $taskId
- * @return bool
- */
- public function actionGroupExport($taskId){
- return $this->_export($taskId, GroupList::class, '团队领导人列表');
- }
- /**
- * 移网管理导出
- * @param $taskId
- * @return bool
- */
- public function actionMoveExport($taskId){
- return $this->_export($taskId, MoveList::class, '移网管理');
- }
- /**
- * 会员状态管理导出
- * @param $taskId
- * @return bool
- */
- public function actionStatusAuditExport($taskId){
- return $this->_export($taskId, StatusAuditList::class, '会员状态管理');
- }
- /**
- * 会员历史年度最高聘级表导出
- * @param $taskId
- * @return bool
- */
- public function actionYearHighestEmpLvExport($taskId){
- return $this->_export($taskId, YearHighestEmpLvList::class, '会员历史年度最高聘级表');
- }
- /**
- * 导出方法
- * @param $taskId
- * @param $className
- * @param $listName
- * @return bool
- */
- private function _export($taskId, $className, $listName){
- $factory = UserExport::factory($taskId);
- $factory->listModelClass = $className;
- try {
- if ($factory->generate()) {
- \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出成功');
- }
- unset($factory, $taskId, $className, $listName);
- return true;
- } catch (\Exception $e) {
- echo $listName.'导出失败。详情:' . $e->getMessage();
- \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出失败。详情:' . $e->getMessage(), false);
- }
- unset($factory, $taskId, $className, $listName);
- return false;
- }
- /**
- * BA会员列表导出
- * @param $taskId
- * @return bool
- */
- public function actionBaUserListExport($taskId) {
- return $this->_exportBA($taskId, BaUserList::class, 'Brand_Ambassador_List');
- }
- /**
- * 导出方法
- * @param $taskId
- * @param $className
- * @param $listName
- * @return bool
- */
- private function _exportBA($taskId, $className, $listName){
- $factory = BaUserExport::factory($taskId);
- $factory->listModelClass = $className;
- try {
- if ($factory->generate()) {
- \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出成功');
- }
- unset($factory, $taskId, $className, $listName);
- return true;
- } catch (\Exception $e) {
- echo $listName.'导出失败。详情:' . $e->getMessage();
- \Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), $listName.'导出失败。详情:' . $e->getMessage(), false);
- }
- unset($factory, $taskId, $className, $listName);
- return false;
- }
- }
|