kevin_zhangl 3 лет назад
Родитель
Сommit
29e1eb7395

+ 1 - 1
backendApi/config/urlManagerRules.php

@@ -70,6 +70,7 @@ return [
             'GET flow-remain-pv' => 'flow-remain-pv',
             'GET ba-order-list' => 'ba-order-list',
             'GET ba-order-list-export' => 'ba-order-list-export',
+            'POST ba-delete-order' => 'ba-delete-order',
         ],
     ],
     [
@@ -171,7 +172,6 @@ return [
             'GET status-audit-export' => 'status-audit-export',
             'GET year-highest-emp-lv-export' => 'year-highest-emp-lv-export',
             'POST recharge-to-user' => 'recharge-to-user',
-
             'GET ba-user-list' => 'ba-user-list',
             'GET ba-user-list-export' => 'ba-user-list-export',
             'POST ba-modify-password' => 'ba-modify-password',

+ 47 - 27
backendApi/modules/v1/controllers/ShopController.php

@@ -23,6 +23,7 @@ use common\helpers\Cache;
 use common\helpers\Form;
 use common\models\DeclarationPackage;
 use common\models\DecOrder;
+use common\models\forms\BaOrderDeleteForm;
 use common\models\forms\DecPackageForm;
 use common\models\forms\ExcelOrderDecForm;
 use common\models\forms\ExcelOrderShopForm;
@@ -32,6 +33,7 @@ use common\models\forms\OrderForm;
 use common\models\forms\ShopGoodsForm;
 use common\models\forms\UploadForm;
 use common\models\ShopGoods;
+use yii\web\HttpException;
 use yii\web\UploadedFile;
 use yii\base\Exception;
 
@@ -48,7 +50,7 @@ class ShopController extends BaseController {
      * 商品列表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionIndex() {
         $filter = $this->filterCondition([
@@ -74,7 +76,7 @@ class ShopController extends BaseController {
      * 商品列表导出
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionGoodsListExport()
     {
@@ -101,7 +103,7 @@ class ShopController extends BaseController {
      * 添加商品
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionGoodsAdd() {
         if (\Yii::$app->request->isPost) {
@@ -125,7 +127,7 @@ class ShopController extends BaseController {
      * 编辑商品
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionGoodsEdit() {
         $id = \Yii::$app->request->get('id');
@@ -161,7 +163,7 @@ class ShopController extends BaseController {
      * @return mixed
      * @throws \yii\base\Exception
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionUpload(){
         if(\Yii::$app->request->isPost){
@@ -205,7 +207,7 @@ class ShopController extends BaseController {
      * 删除商品
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionGoodsDelete(){
         $result = static::delete(ShopGoods::class);
@@ -216,7 +218,7 @@ class ShopController extends BaseController {
      * 套餐列表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionPackage() {
         $filter = $this->filterCondition([
@@ -238,7 +240,7 @@ class ShopController extends BaseController {
     /**
      * 添加报单套餐
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionPackageAdd() {
         if (\Yii::$app->request->isPost) {
@@ -252,7 +254,7 @@ class ShopController extends BaseController {
     /**
      * 报单套餐获取
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionPackageGet() {
         $id = \Yii::$app->request->get('id');
@@ -288,7 +290,7 @@ class ShopController extends BaseController {
      * 删除套餐
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionPackageDelete(){
         $result = static::delete(DeclarationPackage::class);
@@ -300,7 +302,7 @@ class ShopController extends BaseController {
      * 报单表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionDecOrderList() {
         $filter = $this->filterCondition([
@@ -332,7 +334,7 @@ class ShopController extends BaseController {
      * 报单表导出
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionDecOrderListExport()
     {
@@ -373,7 +375,7 @@ class ShopController extends BaseController {
      * 订单表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderList() {
         $filter = $this->filterCondition([
@@ -398,7 +400,7 @@ class ShopController extends BaseController {
      * 订单表导出
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderListExport()
     {
@@ -422,7 +424,7 @@ class ShopController extends BaseController {
      * 外部商城订单列表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderShopList() {
         $filter = $this->filterCondition([
@@ -443,7 +445,7 @@ class ShopController extends BaseController {
      * 外部商城报单列表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderDecList() {
         $filter = $this->filterCondition([
@@ -501,7 +503,7 @@ class ShopController extends BaseController {
     /**
      * 导入完成标记
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionImportOrderShop() {
         //$periodNum = \Yii::$app->request->post('periodNum');
@@ -557,7 +559,7 @@ class ShopController extends BaseController {
     /**
      * 报单订单导入完成标记
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionImportOrderDec() {
         //$periodNum = \Yii::$app->request->post('periodNum');
@@ -576,7 +578,7 @@ class ShopController extends BaseController {
      * 见习达标订单列表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderStandardList() {
         $filter = $this->filterCondition([
@@ -596,7 +598,7 @@ class ShopController extends BaseController {
     /**
      * 分页导入excel文件到待导入数据的表中
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionImportOrderStandardToExcelTable()
     {
@@ -637,7 +639,7 @@ class ShopController extends BaseController {
     /**
      * 达标订单导入完成标记
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionImportOrderStandard() {
         $orderMonth = \Yii::$app->request->post('orderMonth');
@@ -653,7 +655,7 @@ class ShopController extends BaseController {
     /**
      * 管理员发货
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderDelivery() {
         if(\Yii::$app->request->isPost) {
@@ -666,7 +668,7 @@ class ShopController extends BaseController {
      * 报单表导出
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderListExportPdf()
     {
@@ -695,7 +697,7 @@ class ShopController extends BaseController {
      * 报单表导出
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionDecOrderListExportPdf()
     {
@@ -723,7 +725,7 @@ class ShopController extends BaseController {
     /**
      * 管理员订单退款
      * @return mixed
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionOrderRefund()
     {
@@ -769,7 +771,7 @@ class ShopController extends BaseController {
      * BA订单表
      * @return mixed
      * @throws Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionBaOrderList() {
         $filter = $this->filterCondition([
@@ -794,7 +796,7 @@ class ShopController extends BaseController {
      * BA订单表导出
      * @return mixed
      * @throws \yii\db\Exception
-     * @throws \yii\web\HttpException
+     * @throws HttpException
      */
     public function actionBaOrderListExport()
     {
@@ -813,4 +815,22 @@ class ShopController extends BaseController {
         }
         return static::notice('Starting exporting, please go to File Management - Export Files to view.'); // 导出开始,请到文件管理-导出文件查看
     }
+
+    /**
+     * 删除BA订单
+     * @return mixed|void
+     * @throws Exception
+     * @throws HttpException
+     */
+    public function actionBaDeleteOrder()
+    {
+        if (\Yii::$app->request->isPost) {
+            $formModel = new BaOrderDeleteForm();
+            if ($formModel->load(\Yii::$app->request->post(), '') && $formModel->returnOrder()) {
+                return static::notice('删除订单成功,请重新生成业绩单,计算奖金');
+            } else {
+                return static::notice(Form::formatErrorsForApi($formModel->getErrors()), 400);
+            }
+        }
+    }
 }

+ 1 - 10
backendApi/modules/v1/controllers/UserController.php

@@ -2259,19 +2259,10 @@ class UserController extends BaseController
         if (!$userInfo) {
             return static::notice('Data does not exist', 400);//数据不存在
         }
-//        $allNation = \Yii::$app->params['nation'];
-//        $allOpenBank = OpenBank::findAllAsArray('STATUS=1');
-//        $data['allNation'] = $allNation;
-//        $data['allOpenBank'] = $allOpenBank;
         $data['userInfo'] = [
             'userId' => $userInfo['ID'],
-//            'nation' => \Yii::$app->params['nation'][$userInfo['NATION']]['name']??'',
             'realName' => $userInfo['REAL_NAME'],
-//            'idCard' => $userInfo['ID_CARD'],
             'mobile' => $userInfo['MOBILE'],
-//            'openBank' => $userInfo['OPEN_BANK'],
-//            'bankAddress' => $userInfo['BANK_ADDRESS'],
-//            'bankNo' => $userInfo['BANK_NO'],
         ];
 
         return static::notice($data);
@@ -2368,7 +2359,7 @@ class UserController extends BaseController
             'ALLOW_TRANSFER' => 'UI.ALLOW_TRANSFER',
         ]);
         $form = new BaUserExportForm();
-        $result = $form->run($filter, 'Ba_User_List');
+        $result = $form->run($filter, 'Brand_Ambassador_List');
         if (!$result) {
             return static::notice(Form::formatErrorsForApi($form->getErrors()), 400);
         }

+ 14 - 220
backendApi/modules/v1/models/lists/user/BaUserList.php

@@ -3,8 +3,11 @@ 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;
@@ -23,7 +26,7 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
      * @return string
      */
     public function getListName(){
-        return '会员列表';
+        return 'Brand Ambassador List';
     }
 
     /**
@@ -32,7 +35,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->listData = User::lists($this->condition, $this->params, [
+        $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, 
                 UI.RELATION_DEEP, UI.SYSTEM_ID, UI.IS_GROUP_LEADER, UI.IS_SYSTEM_LEADER, UI.IS_TEAM, UI.IS_BIND, 
@@ -41,15 +44,15 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
                 UI.HIGHEST_EMP_LV, UI.CLOSE_LOGIN_AT, UI.PULLED_AT, 
                 UI.GROUP_LEADER_AT, UI.ALLOW_TRANSFER, UI.ALLOW_RECONSUME_SMS, UI.ALLOW_RECONSUME_SMS_TO, 
                 UI.HIGHEST_EMP_LV_PERIOD, UI.TRANSFER_PROP, UI.LOGIN_NUMS, UI.FAIL_NUMS, UI.LAST_LOGIN_IP, 
-                UI.LAST_LOGIN_AT, UI.SHOW_EMP_LV,UN.RELATIVE_LOCATION,
-                CU.USER_NAME CON_USER_NAME,CU.REAL_NAME CON_REAL_NAME,
-                RU.USER_NAME REC_USER_NAME,RU.REAL_NAME REC_REAL_NAME,
-                DU.USER_NAME DEC_USER_NAME
+                UI.LAST_LOGIN_AT, UI.SHOW_EMP_LV,UN.RELATIVE_LOCATION
                 ',
+//            CU.USER_NAME CON_USER_NAME,CU.REAL_NAME CON_REAL_NAME,
+//                RU.USER_NAME REC_USER_NAME,RU.REAL_NAME REC_REAL_NAME,
+//                DU.USER_NAME DEC_USER_NAME
             'orderBy' => 'UI.CREATED_AT DESC, UI.ID DESC',
-            'from' => User::tableName() . ' AS U',
+            'from' => BaUser::tableName() . ' AS U',
             'join' => [
-                ['LEFT JOIN', UserInfo::tableName() . ' AS UI', 'UI.USER_ID=U.ID'],
+                ['LEFT JOIN', BaUserInfo::tableName() . ' AS UI', 'UI.USER_ID=U.ID'],
                 ['LEFT JOIN', UserNetwork::tableName() . ' AS UN', 'UI.USER_ID=UN.USER_ID'],
                 ['LEFT JOIN', User::tableName() . ' AS CU', 'UI.CON_UID=CU.ID'],
                 ['LEFT JOIN', User::tableName() . ' AS RU', 'UI.REC_UID=RU.ID'],
@@ -58,6 +61,7 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
             'page' => $this->page,
             'pageSize' => $this->pageSize,
         ]);
+
         foreach ($this->listData['list'] as $key => $value) {
             // 后台访问前台的请求参数
             if (!$this->isExport && Yii::$app->user->validateAdminAction('user', 'login-to-frontend')) {
@@ -78,13 +82,8 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
      * 要展示和导出的所有字段
      * @return array
      */
-    public function getColumn(){
-        $decLevelConfig = Cache::getDecLevelConfig();
-        $empLevelConfig = Cache::getEmpLevelConfig();
-        $crownLevelConfig = Cache::getStarCrownLevelConfig();
-        $decRoleConfig = DecRole::getAllData();
-        $systemConfig = UserSystem::getAllSystems();
-        $openBankConfig = OpenBank::getAllOpenBank();
+    public function getColumn()
+    {
         $regionConfig = Cache::getRegionConfig();
         if(!$this->columns){
             $this->columns = [
@@ -131,65 +130,6 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
                     'header' => 'Joining Period', // 加入期数
                     'headerOther' => ['width' => '180'],
                 ],
-                'DEC_LV_NAME' => [
-                    'header' => 'Current Member Level', // 实时会员级别
-                    'headerOther' => ['width' => '160'],
-                    'value' => function($row) use($decLevelConfig) {
-                        return $decLevelConfig[$row['DEC_LV']]['LEVEL_NAME'];
-                    },
-                    'valueOther' => [
-                        'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
-                    ],
-                ],
-                'DEC_LV_UPDATED_AT' => [
-                    'header' => 'Current Adjustment Date', // 实时调整日期
-                    'value' => function($row) {
-                        return (new DateTime([
-                            'value' => $row['DEC_LV_UPDATED_AT'],
-                        ]))->result();
-                    },
-                    'headerOther' => ['width' => '180'],
-                ],
-                'LAST_DEC_LV_NAME' => [
-                    'header' => 'PC Member Level', // 结算时会员级别
-                    'headerOther' => [
-                        'width' => '140',
-                    ],
-                    'value' => function($row) use($decLevelConfig) {
-                        if (!$row['LAST_DEC_LV']) {
-                            return $decLevelConfig[$row['DEC_LV']]['LEVEL_NAME'];
-                        } else {
-                            return $decLevelConfig[$row['LAST_DEC_LV']]['LEVEL_NAME'];
-                        }
-                    },
-                    'valueOther' => [
-                        'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
-                    ],
-                ],
-                'EMP_LV_NAME' => [
-                    'header' => 'Current Director Rank', // 实时聘级
-                    'headerOther' => [
-                        'width' => '160',
-                    ],
-                    'value' => function($row) use($empLevelConfig) {
-                        return isset($empLevelConfig[$row['EMP_LV']])?$empLevelConfig[$row['EMP_LV']]['LEVEL_NAME']:'';
-                    },
-                    'valueOther' => [
-                        'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
-                    ],
-                ],
-                'CROWN_LV_NAME' => [
-                    'header' => 'Current Crown Rank', // 实时星级
-                    'headerOther' => [
-                        'width' => '150',
-                    ],
-                    'value' => function($row) use($crownLevelConfig) {
-                        return isset($crownLevelConfig[$row['CROWN_LV']])?$crownLevelConfig[$row['CROWN_LV']]['LEVEL_NAME']:'';
-                    },
-                    'valueOther' => [
-                        'tag'=>['type'=>'warning', 'size' => 'small', 'class'=>'no-border']
-                    ],
-                ],
                 'REC_USER_NAME' => [
                     'header' => 'Recommendation No', // 推荐编号
                     'headerOther' => ['width' => '160'],
@@ -198,18 +138,6 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
                     'header' => 'Recommended Name', // 推荐姓名
                     'headerOther' => ['width' => '160'],
                 ],
-                'CON_USER_NAME' => [
-                    'header' => 'Placement No', // 安置编号
-                    'headerOther' => ['width' => '140'],
-                ],
-                'CON_REAL_NAME' => [
-                    'header' => 'Placement Name', // 安置姓名
-                    'headerOther' => ['width' => '140'],
-                ],
-                'RELATIVE_LOCATION' => [
-                    'header' => 'Resettlement Area', // 安置区域
-                    'headerOther' => ['width' => '140'],
-                ],
                 'MOBILE' => [
                     'header' => 'Phone Number', // 手机号码
                     'value' => function($row) {
@@ -224,83 +152,6 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
                     },
                     'headerOther' => ['width' => '180'],
                 ],
-                'DEC_USER_NAME' => [
-                    'header' => 'Stockist Code', // 所属报单中心编号
-                    'headerOther' => ['width' => '150'],
-                ],
-                'IS_DEC' => [
-                    'header' => 'Whether Declaration Center', // 是否报单中心
-                    'value' => function($row) {
-                        return (new YesNo([
-                            'value' => $row['IS_DEC'],
-                        ]))->result();
-                    },
-                    'headerOther' => function($row) {
-                        return ['width' => '200'];
-                    },
-                    'valueOther' => function($row) {
-                        return [
-                            'tag'=>['type'=>(isset($row['IS_DEC']) && $row['IS_DEC'] )? 'success' : 'info', 'size' => 'small']
-                        ];
-                    },
-                ],
-                'IS_ATLAS' => [
-                    'header' => 'Wheter Atlas Display', // 是否显示图谱
-                    'value' => function($row) {
-                        return (new YesNo([
-                            'value' => $row['IS_ATLAS'],
-                        ]))->result();
-                    },
-                    'headerOther' => function($row) {
-                        return [
-                            'width' => '160',
-                        ];
-                    },
-                    'valueOther' => function($row) {
-                        return [
-                            'tag'=>['type'=>(isset($row['IS_ATLAS']) && $row['IS_ATLAS'] )? 'success' : 'info', 'size' => 'small']
-                        ];
-                    },
-                ],
-                'IS_RECHARGE' => [
-                    'header' => 'Wheter Recharge Display', // 是否显示充值
-                    'value' => function($row) {
-                        return (new YesNo([
-                            'value' => $row['IS_RECHARGE'],
-                        ]))->result();
-                    },
-                    'headerOther' => function($row) {
-                        return [
-                            'width' => '180',
-                        ];
-                    },
-                    'valueOther' => function($row) {
-                        return [
-                            'tag'=>['type'=>(isset($row['IS_RECHARGE']) && $row['IS_RECHARGE'] )? 'success' : 'info', 'size' => 'small']
-                        ];
-                    },
-                ],
-                'DEC_ROLE_NAME' => [
-                    'header' => 'Stockist Level', // 报单中心级别
-                    'headerOther' => ['width' => '110'],
-                    'value' => function($row) use($decRoleConfig) {
-                        return $decRoleConfig[$row['DEC_ROLE_ID']]['ROLE_NAME'] ?? '';
-                    },
-                ],
-                'OPEN_BANK_NAME' => [
-                    'header' => 'Bank Name', // 开户银行
-                    'headerOther' => ['width' => '110'],
-                    'value' => function($row) use($openBankConfig) {
-                        return $openBankConfig[$row['OPEN_BANK']]['BANK_NAME'] ?? '';
-                    },
-                ],
-                'BANK_NO' => [
-                    'header' => 'Bank Account Number', // 银行帐号
-                    'headerOther' => ['width' => '220'],
-                    'value' => function($row) {
-                        return "\t".$row['BANK_NO'];
-                    },
-                ],
                 'AREA' => [
                     'header' => 'Common Address', // 常用地址
                     'value' => function($row) use($regionConfig) {
@@ -319,22 +170,6 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
                         'width' => '200'
                     ],
                 ],
-                'ALLOW_TRANSFER' => [
-                    'header' => 'Enable "Transfer"', // 转账功能开启
-                    'value' => function($row) {
-                        return $row['ALLOW_TRANSFER'] == 1 ? 'On': 'Off'; // '开启' : '关闭'
-                    },
-                    'headerOther' => function($row) {
-                        return [
-                            'width' => '130',
-                        ];
-                    },
-                    'valueOther' => function($row) {
-                        return [
-                            'tag'=>['type'=>(isset($row['ALLOW_TRANSFER']) && $row['ALLOW_TRANSFER']) ? 'Success' : 'Info', 'size' => 'small']
-                        ];
-                    },
-                ],
             ];
         }
         return $this->columns;
@@ -350,53 +185,12 @@ class BaUserList extends \common\libs\dataList\DataList implements DataListInter
             $this->filterTypes = [
                 'USER_NAME'=> ['name'=> 'Member code'], // 会员编号
                 'REAL_NAME'=> ['name'=> 'Member name'], // 会员姓名
-//                'ALLOW_LOGIN'=> ['name'=> '允许登录', 'other'=> 'yesOrNo'],
                 'CREATED_AT'=> ['name'=> 'Joining Date', 'other'=> 'date'], // 加入日期
                 'PERIOD_AT'=> ['name'=> 'Joining Period'], // 加入期数
-                'DEC_LV_NAME'=> ['name'=> 'Real time membership level', 'other'=> 'decLevel'], // 实时会员级别
-//                'DEC_LV_UPDATED_AT'=> ['name'=> '实时调整日期', 'other'=> 'date'],
-//                'LAST_DEC_LV_NAME'=> ['name'=> '结算时会员级别', 'other'=> 'decLevel'],
-                'EMP_LV_NAME'=> ['name'=> 'Real time employment', 'other'=> 'empLevel'], // 实时聘级
-                'CROWN_LV_NAME'=> ['name'=> 'Real time Crown', 'other'=> 'crownLevel'], // 实时聘级
-//                'HIGHEST_EMP_LV_NAME'=> ['name'=> '历史最高聘级', 'other'=> 'empLevel'],
-//                'HIGHEST_EMP_LV_PERIOD'=> ['name'=> '首次达到历史最高聘级的期数'],
                 'REC_USER_NAME'=> ['name'=> 'Recommendation No'],//推荐编号
-                'CON_USER_NAME'=> ['name'=> 'Placement No'],//安置编号
-                //'ID_TYPE'=> ['name'=> '证件类型', 'other'=> 'select', 'selectData'=> [['id'=> 0, 'name'=> '身份证']]],
-                'ID_CARD'=> ['name'=> 'Identification Number'],//证件号码
-//                'SPOUSE_NAME'=> ['name'=> '配偶姓名'],
-//                'SPOUSE_IDCARD'=> ['name'=> '配偶身份证号'],
-//                'SYSTEM_NAME'=> ['name'=> '体系名称', 'other'=> 'systems'],
-//                'SUB_COM_NAME'=> ['name'=> '所属分公司', 'other'=> 'subCompany'],
                 'MOBILE'=> ['name'=> 'Phone Number'],//手机号码
-//                'TEL'=> ['name'=> '备用手机号码'],
-                'DEC_USER_NAME'=> ['name'=> 'Stockist Code'], // 所属报单中心编号
-                'IS_DEC'=> ['name'=> 'Declaration center or not', 'other'=> 'yesOrNo'],//是否报单中心
-                'IS_STUDIO'=> ['name'=> 'Studio or not', 'other'=> 'yesOrNo'],//是否工作室
-                'DEC_ROLE_NAME'=> ['name'=> 'Stockist Level', 'other'=> 'decRole'],//报单中心级别
-//                'OPEN_BANK_NAME'=> ['name'=> '开户银行', 'other'=> 'banks'],
-//                'BANK_AREA'=> ['name'=> '银行地区', 'other'=> 'area'],
-//                'BANK_ADDRESS'=> ['name'=> '开户地址'],
-//                'BANK_NO'=> ['name'=> '银行账号'],
-//                'SEX'=> ['name'=> '性别', 'other'=> 'sex'],
-//                'NATION_NAME'=> ['name'=> '民族', 'other'=> 'nations'],
                 'AREA'=> ['name'=> 'Common address', 'other'=> 'area'],//常用地址
                 'STATUS'=> ['name'=> 'Active status', 'other'=> 'select', 'selectData'=> [['id'=> 0, 'name'=> 'locking'],['id'=> 1, 'name'=> 'activation']]],
-//                'STATUS'=> ['name'=> '激活状态', 'other'=> 'select', 'selectData'=> [['id'=> 0, 'name'=> '锁定'],['id'=> 1, 'name'=> '激活']]],
-//                'ADDRESS'=> ['name'=> '身份证地址'],
-//                'IS_AUTO_WITHDRAW'=> [
-//                    'isUserTable'=> false,
-//                    'name'=> '提现方式',
-//                    'other'=> 'select',
-//                    'selectData'=> [['id'=> 0, 'name'=> '手动'], ['id'=> 1, 'name'=> '自动']]
-//                ],
-//                'VERIFIED'=> ['name'=> '实名认证', 'other'=> 'yesOrNo'],
-//                'VERIFIED_AT'=> ['name'=> '实名认证日期', 'other'=> 'date'],
-//                'IS_DIRECT_SELLER'=> ['name'=> '是否直销员', 'other'=> 'yesOrNo'],
-//                'IS_SYSTEM_LEADER'=> ['name'=> '是否体系领导人', 'other'=> 'yesOrNo'],
-//                'IS_GROUP_LEADER'=> ['name'=> '是否团队领导人', 'other'=> 'yesOrNo'],
-//                'ALLOW_TRANSFER'=> ['name'=> '转账功能开启', 'other'=> 'select', 'selectData'=> [['id'=> 0, 'name'=> '关闭'],['id'=> 1, 'name'=> '开启']]],
-//                'DEC_CLOSED'=> ['name'=> '是否关闭报单', 'other'=> 'yesOrNo'],
             ];
         }
         return $this->filterTypes;

+ 3 - 3
backendEle/src/router/index.js

@@ -180,12 +180,12 @@ export const constantRouterMap = [
       {
         path: '/shop/ba-order-list',
         component: _import('shop/ba-order-list'),
-        name: 'shop_ba-order-list',
+        name: 'ba-order-list',
         meta: {
-          title: 'Brand Ambassador Order', // 订单列表
+          title: 'Brand Ambassador Order', // BA订单列表
           breadcrumb: [
             {title: 'Dashboard', path: '/dashboard/index'}, // Dashboard
-            {title: 'Member management', path: '/user/index'} // 会员管理
+            {title: 'Shopping Mall', path: '/shop/index'} // 商城管理
           ]
         }
       }

+ 14 - 91
backendEle/src/views/shop/ba-order-list.vue

@@ -4,9 +4,7 @@
       <div class="filter-box">
         <filter-user :filter-types="filterTypes" @select-value="handleFilterUser"></filter-user>
       </div>
-      <el-table class="table-box" ref="multipleTable" :data="tableData" stripe style="width: 100%;"
-                @selection-change="handleSelectionChange"
-                :height="tool.getTableHeight()">
+      <el-table class="table-box" ref="multipleTable" :data="tableData" stripe style="width: 100%;" @selection-change="handleSelectionChange" :height="tool.getTableHeight()">
         <el-table-column type="selection" width="70" v-if="tableHeaders"></el-table-column>
         <el-table-column v-for="(tableHeader, key) in tableHeaders" :key="key" :label="tableHeader.header" :width="tableHeader.other.width ? tableHeader.other.width : ''" :prop="tableHeader.other.prop ? tableHeader.other.prop : null">
           <template slot-scope="scope">
@@ -25,10 +23,7 @@
                 Action<i class="el-icon-arrow-down el-icon--right"></i>
               </el-button>
               <el-dropdown-menu slot="dropdown">
-                <el-dropdown-item command="edit" @click.native="handleDel(scope.row)" v-if="permission.hasPermission(`shop/edit`)">Delete order</el-dropdown-item>
-                <!-- <el-dropdown-item command="edit" @click.native="handleEdit(scope.row)" v-if="permission.hasPermission(`shop/edit`)">Edit order&lt;!&ndash; 编辑订单 &ndash;&gt;</el-dropdown-item>
-                <el-dropdown-item command="delivery" @click.native="handleShowDeliveryDialog(scope.row)" v-if="permission.hasPermission(`shop/order-delivery`) && scope.row['STATUS'] === '1' && scope.row['DELIVERY_STATUS'] === '0' ">deliver goods&lt;!&ndash; 发货 &ndash;&gt;</el-dropdown-item>
-                <el-dropdown-item command="refund" @click.native="handleRefund(scope.row.SN)" v-if="permission.hasPermission(`shop/order-delivery`) && scope.row['PAY_TYPE'] === 'pay_stack' && scope.row['STATUS'] === '1' && scope.row['DELIVERY_STATUS'] === '0' ">Refund&lt;!&ndash; 退款 &ndash;&gt;</el-dropdown-item> -->
+                <el-dropdown-item command="edit" @click.native="handleDel(scope.row)" v-if="permission.hasPermission(`shop/ba-edit`)">Delete order</el-dropdown-item>
               </el-dropdown-menu>
             </el-dropdown>
           </template>
@@ -37,25 +32,9 @@
       <div class="white-box-footer">
         <el-button type="success" size="small" @click="handleExport" v-show="permission.hasPermission(`shop/ba-order-list-export`)">Export Excel</el-button>
         <el-button type="primary" size="small" @click="handleExportPDF" v-show="permission.hasPermission(`shop/ba-order-list-export`)">Export PDF</el-button>
-        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange"
-                    @current-change="handleCurrentChange"></pagination>
+        <pagination :total="totalCount" :page_size="pageSize" @size-change="handleSizeChange" @current-change="handleCurrentChange"></pagination>
       </div>
     </div>
-
-    <el-dialog title="deliver goods" :visible.sync="dialogDeliveryVisible"><!-- 发货 -->
-      <el-form :model="deliveryForm" label-width="150px" class="form-dialog">
-        <el-form-item label="Courier Services Company"><!-- 快递公司 -->
-          <el-input v-model="deliveryForm.expressCompany"></el-input>
-        </el-form-item>
-        <el-form-item label="courier number"><!-- 快递单号 -->
-          <el-input v-model="deliveryForm.orderTrackNo"></el-input>
-        </el-form-item>
-      </el-form>
-      <div slot="footer" class="dialog-footer">
-        <el-button @click="dialogDeliveryVisible = false">Cancel<!-- 取 消 --></el-button>
-        <el-button type="primary" @click.native="handleDelivery">deliver goods<!-- 发货 --></el-button>
-      </div>
-    </el-dialog>
   </div>
 </template>
 
@@ -69,7 +48,7 @@ import Pagination from '@/components/Pagination'
 import filterHelper from '@/utils/filterHelper'
 
 export default {
-  name: 'shop_order-list',
+  name: 'ba-order-list',
   components: {FilterUser, Pagination},
   mounted () {
     this.getData()
@@ -89,12 +68,6 @@ export default {
       permission: permission,
       filterTypes: null,
       filterModel: {},
-      dialogDeliveryVisible: false,
-      deliveryForm: {
-        sn: '',
-        expressCompany: '',
-        orderTrackNo: ''
-      }
     }
   },
   methods: {
@@ -119,8 +92,8 @@ export default {
     },
     handleExport () {
       this.$confirm(`Are you sure you want to export the current data?`, 'Hint', { // `确定要导出当前数据吗?`, '提示'
-        confirmButtonText: 'confirm', // 确定
-        cancelButtonText: 'cancel', // 取消
+        confirmButtonText: 'Confirm', // 确定
+        cancelButtonText: 'Cancel', // 取消
         type: 'warning'
       }).then(() => {
         return network.getData(`shop/ba-order-list-export`, this.filterModel)
@@ -155,8 +128,8 @@ export default {
       }
 
       this.$confirm(`Are you sure you want to export the current data?`, 'Hint', { // `确定要导出当前数据吗?`, '提示'
-        confirmButtonText: 'confirm', // 确定
-        cancelButtonText: 'cancel', // 取消
+        confirmButtonText: 'Confirm', // 确定
+        cancelButtonText: 'Cancel', // 取消
         type: 'info'
       }).then(() => {
         // 导出时只需要订单ID即可
@@ -174,22 +147,15 @@ export default {
         })
       })
     },
-    handleEdit () {
-      // 进入修改订单页面
-    },
     handleDel (row) {
       let orderSn = row.SN.value // order订单表的编号
-      this.$confirm(`确定要删除订单:${orderSn}吗?`, '提示', {
-        confirmButtonText: '确定',
-        cancelButtonText: '取消',
+      this.$confirm(`确定要删除订单:${orderSn}吗?`, 'Hint', {
+        confirmButtonText: 'Confirm', // 确定
+        cancelButtonText: 'Cancel', // 取消
         type: 'warning'
-      }).then(() => {
-        // 删除订单
-        let postData = {
-          orderSn
-        }
-        return network.postData('shop/delete-ba-order', postData).then(response => {
-          console.log(response)
+      }).then(_ => {
+        return network.postData('shop/ba-delete-order', { orderSn }).then(response => {
+          console.log(response);
           this.$message({
             message: response,
             type: 'success'
@@ -199,51 +165,8 @@ export default {
         }).catch(() => {
           this.submitButtonStat = false
         })
-      }).then(response => {
-
-      }).catch(response => {
-
       })
     },
-    // 显示发货对话框
-    handleShowDeliveryDialog (row) {
-      this.dialogDeliveryVisible = true
-      this.deliveryForm.sn = row['SN'].value
-    },
-    // 发货
-    handleDelivery () {
-      network.postData('shop/order-delivery', this.deliveryForm).then(response => {
-        this.$message({
-          message: response,
-          type: 'success'
-        })
-        this.dialogDeliveryVisible = false
-        this.getData(this.currentPage, this.pageSize)
-      }).catch(response => {
-        this.dialogDeliveryVisible = false
-      })
-    },
-    // 退款
-    handleRefund (orderSn) {
-      this.$confirm(`Are you sure you want to refund this order?`, 'Hint', { // `确定要将此订单退款吗?`, '提示',
-        confirmButtonText: 'confirm', // 确定
-        cancelButtonText: 'cancel', // 取消
-        type: 'warning'
-      }).then(() => {
-        return network.postData(`shop/order-refund`, { sn: orderSn.value })
-      }).then(response => {
-        this.$message({
-          message: response,
-          type: 'success'
-        })
-        this.getData(this.currentPage, this.pageSize)
-      }).catch(response => {
-        this.$message({
-          message: response,
-          type: 'error'
-        })
-      })
-    }
   }
 }
 

+ 373 - 0
common/models/forms/BaOrderDeleteForm.php

@@ -0,0 +1,373 @@
+<?php
+namespace common\models\forms;
+
+use common\helpers\Date;
+use common\components\Model;
+use common\helpers\snowflake\SnowFake;
+use common\models\ApproachDecOrder;
+use common\models\ApproachOrder;
+use common\models\BaApproachDecOrder;
+use common\models\BaApproachOrder;
+use common\models\BaDecOrder;
+use common\models\BaOrder;
+use common\models\BaUser;
+use common\models\DecOrder;
+use common\models\Order;
+use common\models\Period;
+use common\models\ReturnOrder;
+use common\models\User;
+use yii\base\Exception;
+
+/**
+ * 删除订单
+ */
+class BaOrderDeleteForm extends Model
+{
+    public $orderSn;
+
+    /**
+     * @var Order
+     */
+    private $_model;
+
+    /**
+     * @inheritdoc
+     */
+    public function rules()
+    {
+        return [
+            [['orderSn'], 'trim'],
+            [['orderSn'], 'required'],
+            [['orderSn'], 'checkOrderType'],
+        ];
+    }
+
+    public function attributeLabels()
+    {
+        return [
+            'orderSn' => '订单号',
+        ];
+    }
+
+    /**
+     * 指定校验场景
+     * @return array
+     */
+    public function scenarios()
+    {
+        $parentScenarios = parent::scenarios();
+        $customScenarios = [];
+        return array_merge($parentScenarios, $customScenarios);
+    }
+
+    /**
+     * @throws Exception
+     */
+    public function returnOrder()
+    {
+        if(!$this->validate()){
+            return null;
+        }
+        $sn = $this->orderSn;
+        // 获取订单详情
+        $orderInfo = BaOrder::findUseDbCalc()
+            ->select('ID,DEC_SN,SN,USER_ID,ORDER_TYPE,IS_DELETE,PAY_AMOUNT,PAY_TYPE,ORDER_AMOUNT,USER_NAME,PV,PAY_PV,PERIOD_NUM,PROVINCE,CITY,COUNTY,ADDRESS,STATUS,NOTE')
+            ->where("SN=:SN", [':SN' => $sn])
+            ->asArray()
+            ->one();
+
+        $approachOrderInfo = [];
+        // 如果是PayStack支付,订单是未支付状态,则去中间表查询,如果两个表都没有数据,订单不存在
+        if (!$orderInfo) {
+            $approachOrderInfo = BaApproachOrder::findUseDbCalc()
+                ->select('ID,DEC_SN,SN,USER_ID,ORDER_TYPE,IS_DELETE,PAY_AMOUNT,PAY_TYPE,ORDER_AMOUNT,USER_NAME,PV,PAY_PV,PERIOD_NUM,PROVINCE,CITY,COUNTY,ADDRESS,STATUS,NOTE')
+                ->where("SN=:SN", [':SN' => $sn])
+                ->asArray()
+                ->one();
+        }
+        if (!$orderInfo && !$approachOrderInfo) {
+            throw new Exception('Order does not exist');// 订单不存在
+        }
+
+        $orderInfo = $orderInfo ?: $approachOrderInfo;
+
+        // 如果会员已经是锁定状态了,删除订单的时候,是否还要退还金额
+        $db = \Yii::$app->db;
+        $transaction = $db->beginTransaction();
+        try {
+            $decInfo = [];
+            $isLock = 0 ; // 是否锁定会员单
+            // 如果是注册订单,则删除订单并退还金额,然后再冻结用户
+            if ($orderInfo['ORDER_TYPE'] == 'ZC') {
+                // 查询报单数据,因为如果是报单,则要退还给报单中心
+                if (!$approachOrderInfo) {
+                    $decInfo = BaDecOrder::findUseDbCalc()
+                        ->select('USER_ID,TO_USER_ID,DETAIL_TYPE,UPGRADE_TYPE,ORI_LV,UPGRADE_LV')
+                        ->where("ORDER_SN=:ORDER_SN", [':ORDER_SN' => $sn])
+                        ->asArray()
+                        ->one();
+                    // 删除报单
+                    $delDecOrder = BaDecOrder::updateAll(
+                        ['IS_DEL'=>1, 'DELETED_AT'=>Date::nowTime()],
+                        'ORDER_SN=:ORDER_SN',
+                        ['ORDER_SN'=>$sn]
+                    );
+                } else {
+                    $decInfo = BaApproachDecOrder::findUseDbCalc()
+                        ->select('USER_ID,TO_USER_ID,DETAIL_TYPE,UPGRADE_TYPE,ORI_LV,UPGRADE_LV')
+                        ->where("ORDER_SN=:ORDER_SN", [':ORDER_SN' => $sn])
+                        ->asArray()
+                        ->one();
+                    // 删除报单
+                    $delDecOrder = BaApproachDecOrder::updateAll(
+                        ['IS_DEL'=>1, 'DELETED_AT'=>Date::nowTime()],
+                        'ORDER_SN=:ORDER_SN',
+                        ['ORDER_SN'=>$sn]
+                    );
+                }
+
+                if (!$delDecOrder) {
+                    $transaction->rollBack();
+                    throw new Exception('删除报单失败,删除订单失败');
+                }
+
+                // 支付成功才需要处理
+                if ($orderInfo['STATUS'] == \Yii::$app->params['orderStatus']['paid']['value']) {
+                    // 如果删除的是升级单,则需要回退用户的级别
+                    if ($decInfo['DETAIL_TYPE'] == 2) {
+                        $oriLv = $decInfo['ORI_LV'];
+                        $userModel = BaUser::findOne(['ID' => $orderInfo['USER_ID']]);
+                        $userModel->DEC_LV = $oriLv;
+                        $userModel->UPDATED_AT = Date::nowTime();
+                        if(!$userModel->save(false)) {
+                            $transaction->rollBack();
+                            throw new Exception('回退会员级别失败,删除订单失败');
+                        }
+                    } else {
+                        // 锁定用户
+                        $userModel = User::findOne(['ID' => $orderInfo['USER_ID']]);
+                        $userModel->STATUS = 0;
+                        $userModel->STATUS_AT = Date::nowTime();
+                        if(!$userModel->save(false)) {
+                            $transaction->rollBack();
+                            throw new Exception('锁定会员失败,删除订单失败');
+                        }
+                        $isLock = 1;
+                    }
+                }
+            }
+
+            if (!$approachOrderInfo) {
+                // 公共的退钱,删除订单操作
+                $delOrder = Order::updateAll(
+                    ['IS_DELETE' => 1, 'DELETED_AT' => Date::nowTime()],
+                    'SN=:SN',
+                    ['SN' => $sn]
+                );
+            } else {
+                // 公共的退钱,删除订单操作
+                $delOrder = ApproachOrder::updateAll(
+                    ['IS_DELETE' => 1, 'DELETED_AT' => Date::nowTime()],
+                    'SN=:SN',
+                    ['SN' => $sn]
+                );
+            }
+            if (!$delOrder) {
+                $transaction->rollBack();
+                throw new Exception('删除订单失败');
+            }
+
+            // 如果是PayStack支付,只处理支付成功的
+            $upgradeType = 0; // 升级单类型
+            $returnLv = '';
+            $oriLvs = '';
+            if (!empty($decInfo)) {
+                $upgradeType = $decInfo['UPGRADE_TYPE'];
+                $returnLv = $decInfo['ORI_LV'];
+                $oriLvs = $decInfo['UPGRADE_LV'];
+            }
+
+            // 退款成功,记录数据信息
+            $periodObj = Period::instance();
+            $nowPeriodNum = $periodObj->getNowPeriodNum();
+            $returnOrderModel = new ReturnOrder();
+            $returnOrderModel->ID = SnowFake::instance()->generateId();
+            $returnOrderModel->SN = $sn;
+            $returnOrderModel->DEC_SN = $orderInfo['DEC_SN'];
+            $returnOrderModel->CREATE_AT = Date::nowTime();
+            $returnOrderModel->ORDER_TYPE = $orderInfo['ORDER_TYPE'];
+            $returnOrderModel->ORDER_AMOUNT = $orderInfo['ORDER_AMOUNT'];
+            $returnOrderModel->PV = $orderInfo['PV'];
+            $returnOrderModel->PAY_PV = $orderInfo['PAY_PV'];
+            $returnOrderModel->PAY_AMOUNT = $orderInfo['PAY_AMOUNT'];
+            $returnOrderModel->PAY_TYPE = $orderInfo['PAY_TYPE'];
+            $returnOrderModel->USER_ID = $orderInfo['USER_ID'];
+            $returnOrderModel->PERIOD_NUM = $nowPeriodNum;
+            $returnOrderModel->PAY_STATUS = $orderInfo['STATUS'];
+            $returnOrderModel->PAY_NOTE = $orderInfo['NOTE'];
+            $returnOrderModel->ORDER_PERIOD_NUM = $orderInfo['PERIOD_NUM'];
+            $returnOrderModel->UPGRADE_TYPE = $upgradeType;
+            $returnOrderModel->USER_NAME = $orderInfo['USER_NAME'];
+            $returnOrderModel->PROVINCE = $orderInfo['PROVINCE'];
+            $returnOrderModel->CITY = $orderInfo['CITY'] ?? 0;
+            $returnOrderModel->COUNTY = $orderInfo['COUNTY'] ?? 0;
+            $returnOrderModel->ADDRESS = $orderInfo['ADDRESS'] ?? '';
+            $returnOrderModel->ADMIN_ID = \Yii::$app->user->id;
+            $returnOrderModel->ORI_CASH = 0;
+            $returnOrderModel->ORI_BONUS = 0;
+            $returnOrderModel->ORI_EXCHANGE_POINTS = 0;
+            $returnOrderModel->ORI_RECONSUME_POINTS = 0;
+            $returnOrderModel->ORI_DEC_LV = $oriLvs;
+            $returnOrderModel->RETURN_DEC_LV = $returnLv;
+            $returnOrderModel->IS_LOCKING = $isLock;
+            if (!$returnOrderModel->save()) {
+                $transaction->rollBack();
+                $this->addErrors($returnOrderModel->getErrors());
+                return false;
+            }
+
+            $transaction->commit();
+        } catch(Exception $e) {
+            $transaction->rollBack();
+            $this->addError('add', $e->getMessage());
+            return null;
+        }
+
+        return true;
+    }
+
+    // 判断订单类型
+    public function checkOrderType($attribute) {
+        $sn = $this->orderSn;
+        $orderDetail = BaOrder::findUseDbCalc()
+        ->select('ID,DEC_SN,USER_ID,ORDER_TYPE,IS_DELETE,PERIOD_NUM')
+        ->where("SN=:SN", [':SN' => $sn])
+        ->asArray()
+        ->one();
+
+        $approachOrderDetail = [];
+        if (!$orderDetail) {
+            $orderDetail = $approachOrderDetail = BaApproachOrder::findUseDbCalc()
+                ->select('ID,DEC_SN,USER_ID,ORDER_TYPE,IS_DELETE,PERIOD_NUM')
+                ->where("SN=:SN", [':SN' => $sn])
+                ->asArray()
+                ->one();
+        }
+
+        if (empty($orderDetail)) {
+            $this->addError($attribute, '未找到订单信息,订单编号为:'.$this->orderSn);
+            return ;
+        }
+        if ($orderDetail['IS_DELETE'] == 1) {
+            $this->addError($attribute, '订单已被删除,订单编号为'.$this->orderSn);
+            return ;
+        }
+        // 已挂网或者挂网中的业绩期订单,不能进行删除操作
+        $periodNum = $orderDetail['PERIOD_NUM'];
+        $periodObj = Period::findOneAsArray(['PERIOD_NUM'=>$periodNum]);
+        if (empty($periodObj)) {
+            $this->addError($attribute, '订单对应业绩期不存在,订单编号为'.$this->orderSn.' 业绩期为:'.$periodNum);
+            return ;
+        }
+        if ($periodObj['IS_SENT'] == 1) {
+            $this->addError($attribute, '订单对应业绩期已挂网,订单编号为'.$this->orderSn.' 业绩期为:'.$periodNum);
+            return ;
+        }
+        if ($periodObj['IS_SENDING'] == 1) {
+            $this->addError($attribute, '订单对应业绩期正在挂网,订单编号为'.$this->orderSn.' 业绩期为:'.$periodNum);
+            return ;
+        }
+
+        if ($orderDetail['ORDER_TYPE'] == 'ZC') {
+            if (!$approachOrderDetail) {
+                $decDetail = DecOrder::findUseDbCalc()
+                    ->select('TO_USER_ID,DETAIL_TYPE,UPGRADE_TYPE,IS_DEL')
+                    ->where("ORDER_SN=:ORDER_SN", [':ORDER_SN' => $sn])
+                    ->asArray()
+                    ->one();
+            } else {
+                $decDetail = ApproachDecOrder::findUseDbCalc()
+                    ->select('TO_USER_ID,DETAIL_TYPE,UPGRADE_TYPE,IS_DEL')
+                    ->where("ORDER_SN=:ORDER_SN", [':ORDER_SN' => $sn])
+                    ->asArray()
+                    ->one();
+            }
+
+            if (empty($decDetail)) {
+                $this->addError($attribute, '未获取到对应报单信息,订单编号为:'.$this->orderSn);
+                return ;
+            }
+            if ($decDetail['IS_DEL'] == 1) {
+                $this->addError($attribute, '对应报单信息已被删除,订单编号为:'.$this->orderSn);
+                return ;
+            }
+
+            if ($decDetail['DETAIL_TYPE'] == 2) {
+                if (!$approachOrderDetail) {
+                    // 如果删除升级单,则此升级单必须是用户的最后一个升级单
+                    $lastUpgradeOrder = DecOrder::findUseDbCalc()
+                        ->select('ORDER_SN')
+                        ->where("TO_USER_ID=:TO_USER_ID AND IS_DEL=0 AND DETAIL_TYPE=2", [':TO_USER_ID' => $decDetail['TO_USER_ID']])
+                        ->orderBy('CREATED_AT DESC')
+                        ->asArray()
+                        ->one();
+                } else {
+                    // 如果删除升级单,则此升级单必须是用户的最后一个升级单
+                    $lastUpgradeOrder = ApproachDecOrder::findUseDbCalc()
+                        ->select('ORDER_SN')
+                        ->where("TO_USER_ID=:TO_USER_ID AND IS_DEL=0 AND DETAIL_TYPE=2", [':TO_USER_ID' => $decDetail['TO_USER_ID']])
+                        ->orderBy('CREATED_AT DESC')
+                        ->asArray()
+                        ->one();
+                }
+
+                $lastUpgradeSn = $lastUpgradeOrder['ORDER_SN'];
+                if ($sn != $lastUpgradeSn) {
+                    $this->addError($attribute, '有更晚的订单,此订单不能删除,订单编号为:'.$this->orderSn);
+                    return ;
+                }
+            } else {
+                // 如果是注册单,但是这个用户存在升级单,则也不能进行删除
+                if (!$approachOrderDetail) {
+                    $hasUpgradeOrder = DecOrder::findUseDbCalc()
+                        ->select('TO_USER_ID,DETAIL_TYPE,UPGRADE_TYPE,IS_DEL')
+                        ->where("TO_USER_ID=:TO_USER_ID AND IS_DEL=0 AND DETAIL_TYPE=2", [':TO_USER_ID' => $decDetail['TO_USER_ID']])
+                        ->asArray()
+                        ->one();
+                } else {
+                    $hasUpgradeOrder = ApproachDecOrder::findUseDbCalc()
+                        ->select('TO_USER_ID,DETAIL_TYPE,UPGRADE_TYPE,IS_DEL')
+                        ->where("TO_USER_ID=:TO_USER_ID AND IS_DEL=0 AND DETAIL_TYPE=2", [':TO_USER_ID' => $decDetail['TO_USER_ID']])
+                        ->asArray()
+                        ->one();
+                }
+
+                if (!empty($hasUpgradeOrder)) {
+                    $this->addError($attribute, '此注册报单,存在升级单,无法删除,订单编号为:'.$this->orderSn);
+                    return ;
+                }
+
+                if (!$approachOrderDetail) {
+                    // 删除注册单,判断是否有复消单,如果存在复消单,需要先删除复消单
+                    $hasFxOrder = Order::findUseDbCalc()
+                        ->select('SN')
+                        ->where("USER_ID=:USER_ID AND IS_DELETE=0 AND ORDER_TYPE='FX'", [':USER_ID' => $decDetail['TO_USER_ID']])
+                        ->asArray()
+                        ->one();
+                } else {
+                    // 删除注册单,判断是否有复消单,如果存在复消单,需要先删除复消单
+                    $hasFxOrder = ApproachOrder::findUseDbCalc()
+                        ->select('SN')
+                        ->where("USER_ID=:USER_ID AND IS_DELETE=0 AND ORDER_TYPE='FX'", [':USER_ID' => $decDetail['TO_USER_ID']])
+                        ->asArray()
+                        ->one();
+                }
+                if (!empty($hasFxOrder)) {
+                    $this->addError($attribute, '此注册报单,存在复消单,无法删除,订单编号为:'.$this->orderSn);
+                    return ;
+                }
+            }   
+        }
+        return true; 
+    }
+}

+ 1 - 1
console/controllers/UserController.php

@@ -189,6 +189,6 @@ class UserController extends BaseController
      * @return bool
      */
     public function actionBaUserListExport($taskId){
-        return $this->_export($taskId, BaUserList::class, 'Ba_Member_list');
+        return $this->_export($taskId, BaUserList::class, 'Brand_Ambassador_List');
     }
 }