| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- <?php
- namespace pt\controllers;
- use biz\admin\classes\AdminClass;
- use biz\ghs\classes\GhsClass;
- use biz\shop\classes\ShopAdminClass;
- use biz\shop\classes\ShopClass;
- use biz\sj\classes\SjClass;
- use bizGhs\custom\classes\CustomClass;
- use bizHd\admin\services\ShopAdminService;
- use bizHd\saas\classes\ApplyClass;
- use common\components\util;
- use Yii;
- class ShopAdminController extends BaseController
- {
- //员工列表 ssh 2019.12.8
- public function actionList()
- {
- $where = [];
- $where['delStatus'] = 0;
- $list = ShopAdminService::getAdminList($where);
- util::success($list);
- }
- //删除员工、商家、和申请信息 ssh
- public function actionDelete()
- {
- $id = Yii::$app->request->get('id');
- $shopAdmin = ShopAdminClass::getAdminInfo($id);
- if (empty($shopAdmin)) {
- util::fail('没有找到员工');
- }
- if (getenv('YII_ENV', 'local') == 'production') {
- util::fail('生产环境不能执行删除操作');
- }
- $connection = Yii::$app->db;
- $transaction = $connection->beginTransaction();
- try {
- $adminId = $shopAdmin['adminId'] ?? 0;
- $sjId = $shopAdmin['sjId'] ?? 0;
- $mainId = $shopAdmin['mainId'] ?? 0;
- $shopList = ShopClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
- if (!empty($shopList)) {
- foreach ($shopList as $shop) {
- $mobile = $shop->mobile ?? '';
- if (!empty($mobile)) {
- ApplyClass::deleteByCondition(['mobile' => $mobile]);
- }
- $shop->delete();
- $merchantName = $shop->merchantName ?? '';
- if (!empty($merchantName)) {
- SjClass::deleteByCondition(['name' => $merchantName]);
- }
- }
- }
- $sj = SjClass::getById($sjId, true);
- if (!empty($sj)) {
- $sj->delete();
- }
- $admin = AdminClass::getById($adminId, true);
- if (!empty($admin)) {
- $admin->delete();
- }
- $shopAdmin = ShopAdminClass::getById($id, true);
- if (!empty($shopAdmin)) {
- $shopAdmin->delete();
- }
- ShopAdminClass::deleteByCondition(['mainId' => $mainId]);
- $ghsList = GhsClass::getAllByCondition(['ownSjId' => $sjId], null, '*', null, true);
- if (!empty($ghsList)) {
- foreach ($ghsList as $ghs) {
- $customId = $ghs->customId;
- $ghs->delete();
- $current = CustomClass::getById($customId, true);
- if (!empty($current)) {
- $current->delete();
- }
- }
- }
- $customList = CustomClass::getAllByCondition(['ownSjId' => $sjId], null, '*', null, true);
- if (!empty($customList)) {
- foreach ($customList as $custom) {
- $ghsId = $custom->ghsId;
- $custom->delete();
- $current = GhsClass::getById($ghsId, true);
- if (!empty($current)) {
- $current->delete();
- }
- }
- }
- $transaction->commit();
- util::complete();
- } catch (Exception $exception) {
- $transaction->rollBack();
- util::fail("删除失败");
- }
- }
- }
|