فهرست منبع

导出BA订单列表Excel

kevin_zhangl 3 سال پیش
والد
کامیت
fb3dc4bdac

+ 3 - 2
backendApi/modules/v1/controllers/ShopController.php

@@ -8,6 +8,7 @@
 
 namespace backendApi\modules\v1\controllers;
 
+use backendApi\modules\v1\models\exportForms\BaShopExportForm;
 use backendApi\modules\v1\models\exportForms\ShopExportForm;
 use backendApi\modules\v1\models\lists\shop\DecOrderList;
 use backendApi\modules\v1\models\lists\shop\GoodsList;
@@ -782,7 +783,6 @@ class ShopController extends BaseController {
             'CREATED_AT'=> 'O.CREATED_AT',
             'ORDER_TYPE'=> 'O.ORDER_TYPE',
             'STATUS' => 'O.STATUS',
-            'IS_AUTO' => 'O.IS_AUTO'
         ]);
         $condition = ' 1=1 ' . $filter['condition'];
         $params = $filter['params'];
@@ -806,9 +806,10 @@ class ShopController extends BaseController {
             'MOBILE'=> 'O.MOBILE',
             'PERIOD_NUM'=> 'O.PERIOD_NUM',
             'CREATED_AT'=> 'O.CREATED_AT',
+            'STATUS' => 'O.STATUS',
         ]);
         $filter['condition'] = !$filter['condition'] ? '1=1 AND O.IS_DELETE=0' : ('O.IS_DELETE=0 ' . $filter['condition']);
-        $form = new ShopExportForm();
+        $form = new BaShopExportForm();
         $result = $form->run($filter, 'Ba_Order_List'); // 订单列表
         if (!$result) {
             return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);

+ 4 - 0
backendApi/modules/v1/controllers/UserController.php

@@ -2336,6 +2336,10 @@ class UserController extends BaseController
         return static::notice($data);
     }
 
+    /**
+     * @throws \yii\db\Exception
+     * @throws HttpException
+     */
     public function actionBaUserListExport() {
         $filter = $this->filterCondition([
             'USER_NAME' => 'U.USER_NAME',

+ 23 - 0
backendApi/modules/v1/models/exportForms/BaShopExportForm.php

@@ -0,0 +1,23 @@
+<?php
+namespace backendApi\modules\v1\models\exportForms;
+
+use common\libs\export\module\BaShopExport;
+use yii\db\Exception;
+
+class BaShopExportForm extends BaseExportForm
+{
+    /**
+     * 导出
+     * @param $filter
+     * @param $listName
+     * @param null $consoleRouter
+     * @return bool
+     * @throws Exception
+     */
+    public function run($filter, $listName, $consoleRouter = null){
+        $this->exportObj = BaShopExport::instance();
+        return $this->export($filter, $listName, $consoleRouter);
+    }
+
+
+}

+ 4 - 2
backendApi/modules/v1/models/exportForms/BaUserExportForm.php

@@ -2,6 +2,7 @@
 namespace backendApi\modules\v1\models\exportForms;
 
 use common\libs\export\module\BaUserExport;
+use yii\db\Exception;
 
 class BaUserExportForm extends BaseExportForm
 {
@@ -11,9 +12,10 @@ class BaUserExportForm extends BaseExportForm
      * @param $listName
      * @param null $consoleRouter
      * @return bool
-     * @throws \yii\db\Exception
+     * @throws Exception
      */
-    public function run($filter, $listName, $consoleRouter = null){
+    public function run($filter, $listName, $consoleRouter = null): bool
+    {
         $this->exportObj = BaUserExport::instance();
         return $this->export($filter, $listName, $consoleRouter);
     }

+ 8 - 46
backendApi/modules/v1/models/lists/shop/BaOrderList.php

@@ -70,10 +70,9 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
         ];
 
         foreach ($this->listData['list'] as $key => $value) {
-            $CREATE_USER_ID = Info::getUserIdByUserName($value['CREATE_USER']);
-            $this->listData['list'][$key]['DEC_USER_NAME'] = Info::getUserNameByUserId($value['DEC_ID']);
-            $this->listData['list'][$key]['CREATE_USER_NAME'] = Info::getUserRealNameByUserId($CREATE_USER_ID);
-//            $this->listData['list'][$key]['GOODS_NO'] = '';
+            $CREATE_USER_ID = Info::getBaUserIdByUserName($value['CREATE_USER']);
+            $this->listData['list'][$key]['DEC_USER_NAME'] = Info::getBaUserNameByUserId($value['DEC_ID']);
+            $this->listData['list'][$key]['CREATE_USER_NAME'] = Info::getBaUserRealNameByUserId($CREATE_USER_ID);
         }
     }
 
@@ -107,7 +106,6 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                     'header' => 'Order Code',//订单号
                     'headerOther' => ['width' => '200'],
                 ],
-//                'STATUS' => null,
                 'STATUS' => [
                     'header' => 'Status',//订单状态
                     'headerOther' => [
@@ -165,26 +163,6 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                         return $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
                     },
                 ],
-//                'AREA' => [
-//                    'header' => '地区',
-//                    // 用于导出
-//                    'value' => function($row) use($regionConfig) {
-//                        $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
-//                        $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
-//                        $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
-//                        return $province.$city.$county;
-//                    },
-//                    // 用于前台显示
-//                    'showValue' => function($row) {
-//                        $province = $regionConfig[$row['PROVINCE']]['REGION_NAME'] ?? '';
-//                        $city = $regionConfig[$row['CITY']]['REGION_NAME'] ?? '';
-//                        $county = $regionConfig[$row['COUNTY']]['REGION_NAME'] ?? '';
-//                        return '<div class="addr" title='.$province.$city.$county.'>'.$province.$city.$county.'</div>';
-//                    },
-//                    'headerOther' => [
-//                        'width' => '200'
-//                    ],
-//                ],
                 'ADDRESS' => [
                     'header' => 'Detailed Address',//详细地址
                     'headerOther' => [
@@ -204,11 +182,9 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                             case 'FX':
                                 return in_array($row['PAY_TYPE'], ['cash', 'pay_stack']) ? 'Reselling': 'Points'; //'重消' : '积分'
                         }
+                        return '';
                     },
                 ],
-//                'WAREHOUSE' => [
-//                    'header' => 'Delivery warehouse',//发货仓
-//                ],
                 'CREATED_AT' => [
                     'header' => 'Creation Time',//创建时间
                     'value' => function ($row) {
@@ -219,14 +195,14 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                     'headerOther' => ['width' => '190'],
                 ],
                 'PAY_TYPE' => [
-                    'header' => 'Pay type',// 支付方式
+                    'header' => 'Pay Type',// 支付方式
                     'value' => function ($row) {
                         return ShopGoods::payTypes()[$row['PAY_TYPE']]['name'] ?? ShopGoods::payTypes()['cash']['name'];
                     },
                     'headerOther' => ['width' => '190'],
                 ],
                 'PAY_AT' => [
-                    'header' => 'Payment time',//支付时间
+                    'header' => 'Payment Time',//支付时间
                     'value' => function ($row) {
                         return (new DateTime([
                             'value' => $row['PAY_AT'],
@@ -235,7 +211,7 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                     'headerOther' => ['width' => '190'],
                 ],
                 'DELIVERY_AT' => [
-                    'header' => 'Delivery time',//发货时间
+                    'header' => 'Delivery Time',//发货时间
                     'value' => function ($row) {
                         return (new DateTime([
                             'value' => $row['DELIVERY_AT'],
@@ -258,7 +234,7 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                     },
                 ],
                 'REAL_PV' => [
-                    'header' => 'Commodity amount',//商品金额
+                    'header' => 'Commodity Amount',//商品金额
                     'headerOther' => [
                         'width' => '150',
                     ],
@@ -350,12 +326,6 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                         return \Yii::$app->params['deliveryStatus'][$row['DELIVERY_STATUS']]['label'] ?? '';
                     },
                 ],
-                'IS_AUTO' => [
-                    'header' => 'Is Auto', // 是否自动
-                    'value' => function ($row) {
-                        return $row['IS_AUTO'] == 1 ? 'Yes' : 'No';
-                    },
-                ],
             ];
         }
         return $this->columns;
@@ -384,14 +354,6 @@ class BaOrderList extends \common\libs\dataList\DataList implements DataListInte
                         ['id' => \Yii::$app->params['orderStatus']['failPaid']['value'], 'name' => \Yii::$app->params['orderStatus']['failPaid']['label']]
                     ]
                 ],
-                'IS_AUTO' => [
-                    'name'=>'Is Auto',
-                    'other'=> 'select',
-                    'selectData'=> [
-                        ['id'=>1, 'name'=>'YES'],
-                        ['id'=>0, 'name'=>'NO'],
-                    ]
-                ]
             ];
         }
         return $this->filterTypes;

+ 16 - 24
backendApi/modules/v1/models/lists/user/BaUserList.php

@@ -3,20 +3,12 @@ namespace backendApi\modules\v1\models\lists\user;
 
 use common\helpers\Cache;
 use common\helpers\http\BackendToFrontendApi;
-use common\helpers\LoggerTool;
-use common\helpers\user\Info;
 use common\libs\dataList\DataListInterface;
 use common\models\BaUser;
 use common\models\BaUserInfo;
-use common\models\DecRole;
-use common\models\OpenBank;
-use common\models\Region;
 use common\models\User;
-use common\models\UserInfo;
 use common\libs\dataList\column\DateTime;
-use common\libs\dataList\column\YesNo;
 use common\models\UserNetwork;
-use common\models\UserSystem;
 use Yii;
 
 class BaUserList extends \common\libs\dataList\DataList implements DataListInterface
@@ -26,7 +18,7 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
      * @return string
      */
     public function getListName(){
-        return 'Brand Ambassador List';
+        return 'Brand_Ambassador_List';
     }
 
     /**
@@ -34,7 +26,7 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
      */
     public function dataHandle()
     {
-        $this->condition .= ' AND UN.USER_ID=UI.USER_ID AND UN.PARENT_UID=UI.CON_UID';
+//        $this->condition .= ' AND UN.USER_ID=UI.USER_ID AND UN.PARENT_UID=UI.CON_UID';
         $this->listData = BaUser::lists($this->condition, $this->params, [
             'select' => 'U.*,
                 UI.USER_ID, UI.ZC_PV, UI.CON_UID, UI.REC_UID, UI.CON_NUM, UI.REC_NUM, UI.NETWORK_DEEP, 
@@ -62,20 +54,20 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
             'pageSize' => $this->pageSize,
         ]);
 
-        foreach ($this->listData['list'] as $key => $value) {
-            // 后台访问前台的请求参数
-            if (!$this->isExport && Yii::$app->user->validateAdminAction('user', 'login-to-frontend')) {
-                $urlParams = BackendToFrontendApi::paramsFormat(['id' => $value['USER_ID']]);
-                $urlParamStr = '';
-                foreach ($urlParams as $pKey => $pValue) {
-                    $urlParamStr .= $pKey . '=' . $pValue . '&';
-                }
-                $urlParamStr = substr($urlParamStr, 0, -1);
-                $this->listData['list'][$key]['BTF_URL'] = $urlParamStr;
-            } else {
-                $this->listData['list'][$key]['BTF_URL'] = null;
-            }
-        }
+//        foreach ($this->listData['list'] as $key => $value) {
+//            // 后台访问前台的请求参数
+//            if (!$this->isExport && Yii::$app->user->validateAdminAction('user', 'login-to-frontend')) {
+//                $urlParams = BackendToFrontendApi::paramsFormat(['id' => $value['USER_ID']]);
+//                $urlParamStr = '';
+//                foreach ($urlParams as $pKey => $pValue) {
+//                    $urlParamStr .= $pKey . '=' . $pValue . '&';
+//                }
+//                $urlParamStr = substr($urlParamStr, 0, -1);
+//                $this->listData['list'][$key]['BTF_URL'] = $urlParamStr;
+//            } else {
+//                $this->listData['list'][$key]['BTF_URL'] = null;
+//            }
+//        }
     }
 
     /**

+ 129 - 4
common/libs/export/BaseExport.php

@@ -10,22 +10,24 @@ use common\helpers\http\RemoteUploadApi;
 use common\helpers\LoggerTool;
 use common\helpers\Tool;
 use common\helpers\user\Info;
-use common\libs\dataList\column\DateTime;
 use common\libs\dataList\DataList;
 use common\models\ApproachOrder;
 use common\models\ApproachOrderGoods;
+use common\models\BaApproachOrder;
+use common\models\BaApproachOrderGoods;
+use common\models\BaOrder;
+use common\models\BaOrderGoods;
+use common\models\BaUser;
 use common\models\Export;
 use common\models\Order;
 use common\models\OrderGoods;
 use common\models\Region;
 use common\models\ShopGoods;
 use common\models\User;
-use mysql_xdevapi\Result;
 use Yii;
 use yii\base\Exception;
 use yii\base\StaticInstanceTrait;
 use yii\base\Component;
-use yii\data\Pagination;
 use yii\db\Query;
 
 class BaseExport extends Component {
@@ -214,7 +216,6 @@ class BaseExport extends Component {
      * @throws \yii\httpclient\Exception
      */
     public function generate() {
-        //Logger::info(date('Y-m-d H:i:s'), 'export');
         $this->getParams();
         if (!$this->params) {
             throw new Exception('无法获取需要的参数');
@@ -263,9 +264,11 @@ class BaseExport extends Component {
         } else {
             throw new Exception($this->listModelClass.'的getList方法不存在');
         }
+        LoggerTool::info($list);
         if($page >= $list['totalPages']){
             return 'finish';
         }
+        LoggerTool::info($list['list']);
         if(!empty($list['list'])){
             foreach($list['list'] as $columnData){
                 fputcsv($this->_fp, Tool::arrTextConvert($columnData));
@@ -1089,4 +1092,126 @@ ORDER;
 
         return $list['list'];
     }
+
+    /**
+     * 生成
+     * @return bool
+     * @throws Exception
+     * @throws \yii\base\InvalidConfigException
+     * @throws \yii\httpclient\Exception
+     */
+    public function generateBaOrderExcel() {
+        $this->getParams();
+        if (!$this->params) {
+            throw new Exception('无法获取需要的参数');
+        }
+        $path = $this->getSaveBasePath() . __DS__ . $this->getSavePath();
+        $path = __DS__ . $path;
+        $realFile = $this->mkdir($path) . __DS__ . $this->getFileName();
+        $this->completed = false;
+        $this->getExportId();
+        $this->getUserId();
+        $this->_fp = fopen($realFile, 'w');
+        @exec('chown -R www:www /'.$realFile);
+        @exec('chmod -R 777 /'.$realFile);
+        // 获取列表数据及表头
+        $this->_listModel = new $this->listModelClass();
+        $this->_listModel->isExport = true;
+        if(method_exists($this->_listModel, 'getExportHeaders')){
+            if(method_exists($this->_listModel, 'exportPrepare')) {//导出数据提前设置参数
+                $this->_listModel->exportPrepare(['condition' => $this->params['condition'], 'params' => $this->params['params'], 'others' => $this->params['others'] ?? [], 'page' => 0, 'pageSize' => 100000, 'userId' => $this->userId]);
+            }
+            $headers = $this->_listModel->getExportHeaders($this->userId);
+            fputcsv($this->_fp, $headers);
+            unset($headers);
+            $this->_updateFirst($realFile, 1);
+        } else {
+            throw new Exception($this->listModelClass.'的getExportHeaders方法不存在');
+        }
+        $this->_loopWriteDataBaOrder();
+        $this->complete();
+        return true;
+    }
+
+    /**
+     * 循环写入数据
+     */
+    private function _loopWriteDataBaOrder()
+    {
+        $orderQuery = BaOrder::find()
+            ->alias('O')
+            ->where($this->params['condition'], $this->params['params'])
+            ->select('O.*,U.REAL_NAME,U.DEC_ID,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV')
+            ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
+            ->join('LEFT JOIN', BaOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
+            ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
+            ->orderBy('O.CREATED_AT DESC');
+
+        // 订单中间表只查询待支付和支付失败的订单
+        $this->params['params'][':NOT_PAID'] = \Yii::$app->params['orderStatus']['notPaid']['value'];   // 待支付
+        $this->params['params'][':FAIL_PAID'] = \Yii::$app->params['orderStatus']['failPaid']['value'];   // 支付失败
+        $orderStandardQuery = BaApproachOrder::find()
+            ->alias('O')
+            ->where($this->params['condition'] . ' AND (O.STATUS = :NOT_PAID OR O.STATUS = :FAIL_PAID)', $this->params['params'])
+            ->select('O.*,U.REAL_NAME,U.DEC_ID,SG.CATEGORY_TYPE,OG.REAL_PRICE,OG.TAX_RATE,OG.BUY_NUMS,OG.SKU_CODE,OG.GOODS_TITLE,OG.REAL_PV')
+            ->join('LEFT JOIN', BaUser::tableName() . ' AS U', 'U.ID=O.USER_ID')
+            ->join('LEFT JOIN', BaApproachOrderGoods::tableName() . ' AS OG', 'OG.ORDER_SN=O.SN')
+            ->join('LEFT JOIN', ShopGoods::tableName() . ' AS SG', 'SG.ID=OG.GOODS_ID')
+            ->orderBy('O.CREATED_AT DESC');
+
+        $queryAll = $orderQuery->union($orderStandardQuery, true);
+        $query = (new Query())->from(['Q' => $queryAll])->select('Q.*')->distinct()->orderBy(['CREATED_AT' => SORT_DESC]);
+        $lists = $query->all();
+
+        if(!empty($lists)){
+            $regionConfig = Cache::getRegionConfig();
+            foreach($lists as $columnData) {
+                $CREATE_USER_ID = Info::getBaUserIdByUserName($columnData['CREATE_USER']);
+                $createUserName = Info::getBaUserRealNameByUserId($CREATE_USER_ID);
+                $decUserName = Info::getBaUserNameByUserId($columnData['DEC_ID']);
+
+                $columnAccept = [
+                    'USER_NAME' => $columnData['USER_NAME'],
+                    'DEC_USER_NAME' => $decUserName,
+                    'CREATE_USER' => $columnData['CREATE_USER'],
+                    'CREATE_USER_NAME' => $createUserName,
+                    'SN' => $columnData['SN'],
+                    'STATUS' => \Yii::$app->params['orderStatus'][$columnData['STATUS']]['label'] ?? '',
+                    'SKU_CODE' => $columnData['SKU_CODE'],
+                    'GOODS_TITLE' => $columnData['GOODS_TITLE'],
+                    'BUY_NUMS' => $columnData['BUY_NUMS'],
+                    'CONSIGNEE' => $columnData['CONSIGNEE'],
+                    'MOBILE' => "\t{$columnData['MOBILE']}",
+                    'TEL' => "\t{$columnData['TEL']}",
+                    'PROVINCE' => $regionConfig[$columnData['PROVINCE']]['REGION_NAME'] ?? '',
+                    'CITY' => $regionConfig[$columnData['CITY']]['REGION_NAME'] ?? '',
+                    'COUNTY' => $regionConfig[$columnData['COUNTY']]['REGION_NAME'] ?? '',
+                    'ADDRESS' => $columnData['ADDRESS'],
+                    'PERIOD_NUM' => $columnData['PERIOD_NUM'],
+                    'ORDER_TYPE' => ($columnData['ORDER_TYPE'] == 'ZC') ? 'Welcome pack' : (in_array($columnData['PAY_TYPE'], ['cash', 'pay_stack']) ? 'Reselling': 'Points'),
+                    'CREATED_AT' => Date('Y-m-d H:i:s', $columnData['CREATED_AT']),
+                    'PAY_TYPE' => ShopGoods::payTypes()[$columnData['PAY_TYPE']]['name'] ?? ShopGoods::payTypes()['cash']['name'],
+                    'PAY_AT' => $columnData['PAY_AT'] > 0 ? Date('Y-m-d H:i:s', $columnData['PAY_AT']) : '',
+                    'DELIVERY_AT' => $columnData['DELIVERY_AT'] > 0 ? Date('Y-m-d H:i:s', $columnData['DELIVERY_AT']) : '',
+                    'REAL_PRICE' => $columnData['REAL_PRICE'] ?? 0,
+                    'REAL_PV' => $columnData['REAL_PV'] ?? 0,
+                    'PAY_FREIGHT' => $columnData['PAY_FREIGHT'] ?? 0,
+                    'TAX_RATE' => $columnData['TAX_RATE'],
+                    'TAX_AMOUNT' => Tool::calculateTax($columnData['REAL_PRICE'], $columnData['TAX_RATE'], $columnData['BUY_NUMS']),
+                    'EXPRESS_COMPANY' => $columnData['EXPRESS_COMPANY'],
+                    'ORDER_TRACK_NO' => $columnData['ORDER_TRACK_NO'],
+                    'EXPRESS_TYPE' => $columnData['EXPRESS_TYPE'] == 0 ? 'mailing ':' auto pick',
+                    'FRONT_REMARK' => $columnData['FRONT_REMARK'],
+                    'DELIVERY_STATUS_NAME' => \Yii::$app->params['deliveryStatus'][$columnData['DELIVERY_STATUS']]['label'] ?? '',
+                ];
+                
+                fputcsv($this->_fp, Tool::arrTextConvert($columnAccept));
+                unset($percent, $columnData, $columnAccept);
+            }
+            unset($list);
+        }
+
+        unset($list);
+        return 'finish';
+    }
 }

+ 10 - 0
common/libs/export/module/BaShopExport.php

@@ -0,0 +1,10 @@
+<?php
+namespace common\libs\export\module;
+
+use common\libs\export\BaseExport;
+
+class BaShopExport extends BaseExport
+{
+    public $moduleId = 'ba_shop';
+
+}

+ 1 - 1
composer.json

@@ -26,7 +26,7 @@
         "yiisoft/yii2-redis": "^2.0",
         "ext-pdo": "*",
         "ext-json": "*",
-        "monolog/monolog": "^2.4",
+        "monolog/monolog": "^2.8",
         "tecnickcom/tcpdf": "^6.4",
         "ext-curl": "*",
         "smladeoye/yii2-paystack": "^1.0"

+ 3 - 2
console/controllers/ShopController.php

@@ -11,6 +11,7 @@ use backendApi\modules\v1\models\lists\shop\DecOrderList;
 use backendApi\modules\v1\models\lists\shop\GoodsList;
 use backendApi\modules\v1\models\lists\shop\OrderList;
 use backendApi\modules\v1\models\lists\shop\BaOrderList;
+use common\libs\export\module\BaShopExport;
 use common\libs\export\module\ShopExport;
 use Yii;
 
@@ -138,10 +139,10 @@ class ShopController extends BaseController
      * @return bool
      */
     public function actionBaOrderListExport($taskId){
-        $factory = ShopExport::factory($taskId);
+        $factory = BaShopExport::factory($taskId);
         $factory->listModelClass = BaOrderList::class;
         try {
-            if ($factory->generateOrderExcel()) {
+            if ($factory->generateBaOrderExcel()) {
                 Yii::$app->swooleAsyncTimer->pushAsyncResultToAdmin($factory->getUserId(), 'BA订单列表导出成功');
             }
             unset($factory);

+ 27 - 2
console/controllers/UserController.php

@@ -19,6 +19,7 @@ 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;
@@ -188,7 +189,31 @@ class UserController extends BaseController
      * @param $taskId
      * @return bool
      */
-    public function actionBaUserListExport($taskId){
-        return $this->_export($taskId, BaUserList::class, 'Brand_Ambassador_List');
+    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;
     }
 }