SystemConfigGroupLogic.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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\model\system\SystemConfigGroup;
  9. use plugin\saiadmin\basic\BaseLogic;
  10. use plugin\saiadmin\exception\ApiException;
  11. use plugin\saiadmin\app\model\system\SystemConfig;
  12. use support\Cache;
  13. use think\facade\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)
  30. {
  31. $model = $this->model->where('id', $ids)->findOrEmpty();
  32. if ($model->isEmpty()) {
  33. throw new ApiException('配置数据未找到');
  34. }
  35. if (in_array(intval($ids), [1, 2, 3])) {
  36. throw new ApiException('系统默认分组,无法删除');
  37. }
  38. Db::startTrans();
  39. try {
  40. // 删除配置组
  41. $model->delete();
  42. // 删除配置组数据
  43. $typeIds = SystemConfig::where('group_id', $ids)->column('id');
  44. SystemConfig::destroy($typeIds);
  45. Cache::delete('cfg_' . $model->code);
  46. Db::commit();
  47. return true;
  48. } catch (\Exception $e) {
  49. Db::rollback();
  50. throw new ApiException('删除数据异常,请检查');
  51. }
  52. }
  53. }