ShopAdminController.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. namespace pt\controllers;
  3. use biz\admin\classes\AdminClass;
  4. use biz\shop\classes\ShopAdminClass;
  5. use biz\sj\classes\SjClass;
  6. use bizHd\admin\services\ShopAdminService;
  7. use bizHd\saas\classes\ApplyClass;
  8. use common\components\util;
  9. use Yii;
  10. class ShopAdminController extends BaseController
  11. {
  12. //员工列表 ssh 2019.12.8
  13. public function actionList()
  14. {
  15. $where = [];
  16. $where['delStatus'] = 0;
  17. $list = ShopAdminService::getAdminList($where);
  18. util::success($list);
  19. }
  20. //删除员工、商家、和申请信息 shish
  21. public function actionDelete()
  22. {
  23. $id = Yii::$app->request->get('id');
  24. $shopAdmin = ShopAdminClass::getAdminInfo($id);
  25. if (empty($shopAdmin)) {
  26. util::fail('没有找到员工');
  27. }
  28. if (getenv('YII_ENV', 'local') == 'production') {
  29. util::fail('生产环境不能执行删除操作');
  30. }
  31. $connection = Yii::$app->db;
  32. $transaction = $connection->beginTransaction();
  33. try {
  34. $adminId = $shopAdmin['adminId'] ?? 0;
  35. $sjId = $shopAdmin['merchantId'] ?? 0;
  36. $sj = SjClass::getById($sjId, true);
  37. if (!empty($sj)) {
  38. $sj->delete();
  39. }
  40. $apply = ApplyClass::getByCondition(['sjId' => $sjId], true);
  41. if (!empty($apply)) {
  42. $apply->delete();
  43. }
  44. $admin = AdminClass::getById($adminId, true);
  45. if (!empty($admin)) {
  46. $admin->delete();
  47. }
  48. $shopAdmin = ShopAdminClass::getById($id, true);
  49. if (!empty($shopAdmin)) {
  50. $shopAdmin->delete();
  51. }
  52. util::complete();
  53. } catch (Exception $exception) {
  54. $transaction->rollBack();
  55. util::fail("删除失败");
  56. }
  57. }
  58. }