ShopAdminController.php 3.7 KB

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