ShopAdminController.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. $ghs->delete();
  58. }
  59. }
  60. $customList = CustomClass::getAllByCondition(['ownSjId' => $sjId], null, '*', null, true);
  61. if (!empty($customList)) {
  62. foreach ($customList as $custom) {
  63. $custom->delete();
  64. }
  65. }
  66. $transaction->commit();
  67. util::complete();
  68. } catch (Exception $exception) {
  69. $transaction->rollBack();
  70. util::fail("删除失败");
  71. }
  72. }
  73. }