ShopAdminController.php 3.7 KB

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