SystemConfigGroupLogic.php 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | saiadmin [ saiadmin快速开发框架 ]
  4. // +----------------------------------------------------------------------
  5. // | Author: sai <1430792918@qq.com>
  6. // +----------------------------------------------------------------------
  7. namespace plugin\saiadmin\app\logic\system;
  8. use plugin\saiadmin\app\cache\ConfigCache;
  9. use plugin\saiadmin\app\model\system\SystemConfigGroup;
  10. use plugin\saiadmin\basic\think\BaseLogic;
  11. use plugin\saiadmin\exception\ApiException;
  12. use plugin\saiadmin\app\model\system\SystemConfig;
  13. use support\think\Db;
  14. /**
  15. * 参数配置分组逻辑层
  16. */
  17. class SystemConfigGroupLogic extends BaseLogic
  18. {
  19. /**
  20. * 构造函数
  21. */
  22. public function __construct()
  23. {
  24. $this->model = new SystemConfigGroup();
  25. }
  26. /**
  27. * 删除配置信息
  28. */
  29. public function destroy($ids): bool
  30. {
  31. $id = $ids[0];
  32. $model = $this->model->where('id', $id)->findOrEmpty();
  33. if ($model->isEmpty()) {
  34. throw new ApiException('配置数据未找到');
  35. }
  36. if (in_array(intval($id), [1, 2, 3])) {
  37. throw new ApiException('系统默认分组,无法删除');
  38. }
  39. Db::startTrans();
  40. try {
  41. // 删除配置组
  42. $model->delete();
  43. // 删除配置组数据
  44. $typeIds = SystemConfig::where('group_id', $id)->column('id');
  45. SystemConfig::destroy($typeIds);
  46. ConfigCache::clearConfig($model->code);
  47. Db::commit();
  48. return true;
  49. } catch (\Exception $e) {
  50. Db::rollback();
  51. throw new ApiException('删除数据异常,请检查');
  52. }
  53. }
  54. }