ShopAdminController.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <?php
  2. namespace pt\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\ghs\classes\GhsClass;
  5. use biz\shop\classes\ShopAdminClass;
  6. use biz\shop\classes\ShopClass;
  7. use biz\sj\classes\SjClass;
  8. use bizGhs\custom\classes\CustomClass;
  9. use bizHd\admin\services\ShopAdminService;
  10. use bizHd\saas\classes\ApplyClass;
  11. use common\components\util;
  12. use Yii;
  13. class ShopAdminController extends BaseController
  14. {
  15. //员工列表 ssh 2019.12.8
  16. public function actionList()
  17. {
  18. $where = [];
  19. $where['delStatus'] = 0;
  20. $list = ShopAdminService::getAdminList($where);
  21. util::success($list);
  22. }
  23. //删除员工、商家、和申请信息 ssh
  24. public function actionDelete()
  25. {
  26. $id = Yii::$app->request->get('id');
  27. $shopAdmin = ShopAdminClass::getAdminInfo($id);
  28. if (empty($shopAdmin)) {
  29. util::fail('没有找到员工');
  30. }
  31. if (getenv('YII_ENV', 'local') == 'production') {
  32. util::fail('生产环境不能执行删除操作');
  33. }
  34. $connection = Yii::$app->db;
  35. $transaction = $connection->beginTransaction();
  36. try {
  37. $adminId = $shopAdmin['adminId'] ?? 0;
  38. $sjId = $shopAdmin['sjId'] ?? 0;
  39. $mainId = $shopAdmin['mainId'] ?? 0;
  40. $shopList = ShopClass::getAllByCondition(['mainId' => $mainId], null, '*', null, true);
  41. if (!empty($shopList)) {
  42. foreach ($shopList as $shop) {
  43. $mobile = $shop->mobile ?? '';
  44. if (!empty($mobile)) {
  45. ApplyClass::deleteByCondition(['mobile' => $mobile]);
  46. }
  47. $shop->delete();
  48. }
  49. }
  50. $sj = SjClass::getById($sjId, true);
  51. if (!empty($sj)) {
  52. $sj->delete();
  53. }
  54. $admin = AdminClass::getById($adminId, true);
  55. if (!empty($admin)) {
  56. $admin->delete();
  57. }
  58. $shopAdmin = ShopAdminClass::getById($id, true);
  59. if (!empty($shopAdmin)) {
  60. $shopAdmin->delete();
  61. }
  62. ShopAdminClass::deleteByCondition(['mainId' => $mainId]);
  63. $ghsList = GhsClass::getAllByCondition(['ownSjId' => $sjId], null, '*', null, true);
  64. if (!empty($ghsList)) {
  65. foreach ($ghsList as $ghs) {
  66. $customId = $ghs->customId;
  67. $ghs->delete();
  68. $current = CustomClass::getById($customId, true);
  69. if (!empty($current)) {
  70. $current->delete();
  71. }
  72. }
  73. }
  74. $customList = CustomClass::getAllByCondition(['ownSjId' => $sjId], null, '*', null, true);
  75. if (!empty($customList)) {
  76. foreach ($customList as $custom) {
  77. $ghsId = $custom->ghsId;
  78. $custom->delete();
  79. $current = GhsClass::getById($ghsId, true);
  80. if (!empty($current)) {
  81. $current->delete();
  82. }
  83. }
  84. }
  85. $transaction->commit();
  86. util::complete();
  87. } catch (Exception $exception) {
  88. $transaction->rollBack();
  89. util::fail("删除失败");
  90. }
  91. }
  92. }