ShopAdminController.php 2.9 KB

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