ShopAdminController.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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. $merchantName = $shop->merchantName ?? '';
  49. if (!empty($merchantName)) {
  50. SjClass::deleteByCondition(['name' => $merchantName]);
  51. }
  52. }
  53. }
  54. $sj = SjClass::getById($sjId, true);
  55. if (!empty($sj)) {
  56. $sj->delete();
  57. }
  58. $admin = AdminClass::getById($adminId, true);
  59. if (!empty($admin)) {
  60. $admin->delete();
  61. }
  62. $shopAdmin = ShopAdminClass::getById($id, true);
  63. if (!empty($shopAdmin)) {
  64. $shopAdmin->delete();
  65. }
  66. ShopAdminClass::deleteByCondition(['mainId' => $mainId]);
  67. $ghsList = GhsClass::getAllByCondition(['ownSjId' => $sjId], null, '*', null, true);
  68. if (!empty($ghsList)) {
  69. foreach ($ghsList as $ghs) {
  70. $customId = $ghs->customId;
  71. $ghs->delete();
  72. $current = CustomClass::getById($customId, true);
  73. if (!empty($current)) {
  74. $current->delete();
  75. }
  76. }
  77. }
  78. $customList = CustomClass::getAllByCondition(['ownSjId' => $sjId], null, '*', null, true);
  79. if (!empty($customList)) {
  80. foreach ($customList as $custom) {
  81. $ghsId = $custom->ghsId;
  82. $custom->delete();
  83. $current = GhsClass::getById($ghsId, true);
  84. if (!empty($current)) {
  85. $current->delete();
  86. }
  87. }
  88. }
  89. $transaction->commit();
  90. util::complete();
  91. } catch (Exception $exception) {
  92. $transaction->rollBack();
  93. util::fail("删除失败");
  94. }
  95. }
  96. }