ConfigServer.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. <?php
  2. namespace app\admin\server\index;
  3. use app\admin\model\SystemConfigClassify;
  4. use app\admin\model\SystemConfigValue;
  5. class ConfigServer
  6. {
  7. public static function getClassify()
  8. {
  9. $list = SystemConfigClassify::getClassifyList();
  10. return $list;
  11. }
  12. /**
  13. * Notes:新增设置分类
  14. * @param int $classify_pid
  15. * @param string $classify_name
  16. * @param string $classify_key
  17. * @param string $classify_info
  18. * @param int $classify_sort
  19. * @param int $classify_status
  20. * @param int $admin_id
  21. * @return bool
  22. * @throws \Exception
  23. * User: yym
  24. * Date: 2022/10/10
  25. */
  26. public static function insertClassify(int $classify_pid, string $classify_name, string $classify_key, string $classify_info, int $classify_sort, int $classify_status, int $admin_id)
  27. {
  28. try {
  29. $insert = array(
  30. 'classify_pid' => $classify_pid,
  31. 'classify_name' => $classify_name,
  32. 'classify_key' => $classify_key,
  33. 'classify_info' => $classify_info,
  34. 'classify_sort' => $classify_sort,
  35. 'classify_status' => $classify_status,
  36. 'classify_create_time' => date("Y-m-d H:i:s", time())
  37. );
  38. $result = SystemConfigClassify::insertData($insert);
  39. if($result)
  40. {
  41. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '添加设置分类: ' . $classify_name . $result;
  42. plog('system-config-create', '系统设置-配置-新增配置', $msg);
  43. return true;
  44. }
  45. throw new \Exception('新增失败!');
  46. }catch (\Exception $exception){
  47. throw new \Exception($exception->getMessage(), 500);
  48. }
  49. }
  50. /**
  51. * Notes:系统设置分类编辑
  52. * @param int $classify_id
  53. * @param int $classify_pid
  54. * @param string $classify_name
  55. * @param string $classify_key
  56. * @param string $classify_info
  57. * @param int $classify_sort
  58. * @param int $classify_status
  59. * @param int $admin_id
  60. * @return bool
  61. * @throws \Exception
  62. * User: yym
  63. * Date: 2022/10/10
  64. */
  65. public static function updateClassify(int $classify_id, int $classify_pid, string $classify_name, string $classify_key, string $classify_info, int $classify_sort, int $classify_status, int $admin_id)
  66. {
  67. try {
  68. //检测是否存在
  69. $info = SystemConfigClassify::getInfo($classify_id);
  70. if(empty($info))
  71. {
  72. throw new \Exception('查无此分类信息');
  73. }
  74. $update = array(
  75. 'classify_pid' => $classify_pid,
  76. 'classify_name' => $classify_name,
  77. 'classify_key' => $classify_key,
  78. 'classify_info' => $classify_info,
  79. 'classify_sort' => $classify_sort,
  80. 'classify_status' => $classify_status
  81. );
  82. $result = SystemConfigClassify::updateData($classify_id, $update);
  83. if($result !== false)
  84. {
  85. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '编辑设置分类: ' . $classify_name . $classify_id;
  86. plog('system-config-update', '系统设置-配置-修改配置', $msg);
  87. return true;
  88. }
  89. throw new \Exception('编辑失败!');
  90. }catch (\Exception $exception){
  91. throw new \Exception($exception->getMessage(), 500);
  92. }
  93. }
  94. /**
  95. * Notes:配置分类删除或修改状态
  96. * @param int $classify_id
  97. * @param int $type
  98. * @param int $status
  99. * @param int $admin_id
  100. * @return bool
  101. * @throws \Exception
  102. * User: yym
  103. * Date: 2022/10/10
  104. */
  105. public static function delUpClassify(int $classify_id, int $type, int $status, int $admin_id)
  106. {
  107. try {
  108. //删除
  109. if($type == 0)
  110. {
  111. //检测是否存在子集配置
  112. if(SystemConfigClassify::where(['classify_pid' => $classify_id])->exists())
  113. {
  114. throw new \Exception('该配置分类存在子集,请先删除子集分类');
  115. }
  116. if(SystemConfigValue::where(['value_classify_id' => $classify_id])->exists())
  117. {
  118. throw new \Exception('该配置分类存在配置内容,请先删除相关配置信息');
  119. }
  120. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '删除设置分类: ' . $classify_id;
  121. $result = SystemConfigClassify::where(['classify_id' => $classify_id])->delete();
  122. }else{
  123. $msg = '管理员:' . $admin_id . '在:' . date("Y-m-d H:i:s", time()) . '编辑设置分类: ' . $classify_id . '状态:' . $status;
  124. //修改状态
  125. $result = SystemConfigClassify::updateData($classify_id, ['classify_status' => $status]);
  126. }
  127. plog('system-config-update', '系统设置-配置-修改配置', $msg);
  128. if($result !== false)
  129. {
  130. return true;
  131. }
  132. throw new \Exception('操作失败');
  133. }catch (\Exception $exception){
  134. throw new \Exception($exception->getMessage(), 500);
  135. }
  136. }
  137. /**
  138. * Notes:获取单个配置信息
  139. * @param int $classify_id
  140. * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Model|object|null
  141. * User: yym
  142. * Date: 2022/10/10
  143. */
  144. public static function getClassifyInfo(int $classify_id)
  145. {
  146. return SystemConfigClassify::getInfo($classify_id);
  147. }
  148. }