控制台应用,yzncms本身基于tp5.1框架,里面的队列用不了,bug,坑
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Yzncms [ 御宅男工作室 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2007 http://yzncms.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
  8. // +----------------------------------------------------------------------
  9. // | Author: 御宅男 <530765310@qq.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\model;
  12. use think\Db;
  13. use think\Exception;
  14. use think\Model;
  15. /**
  16. * 用户组模型类
  17. * Class AuthGroupModel
  18. */
  19. class AuthGroup extends Model
  20. {
  21. protected static $roleList = [];
  22. public static function init()
  23. {
  24. self::beforeDelete(function ($row) {
  25. if ($row->id == 1) {
  26. throw new Exception("超级管理员角色不能被删除!");
  27. }
  28. $admin = Db::name('Admin')->where('roleid', $row->id)->find();
  29. if ($admin) {
  30. throw new Exception("该角色下有管理员!");
  31. }
  32. //子角色列表
  33. $child = explode(',', self::getArrchildid($row->id));
  34. if (count($child) > 1) {
  35. throw new Exception("该角色下有子角色,请删除子角色才可以删除!");
  36. }
  37. });
  38. }
  39. /**
  40. * 通过递归的方式获取该角色下的全部子角色
  41. * @param type $id
  42. * @return string
  43. */
  44. public static function getArrchildid($id)
  45. {
  46. if (empty(self::$roleList)) {
  47. self::$roleList = self::order(["id" => "desc"])->column('*', 'id');
  48. }
  49. $arrchildid = $id;
  50. if (is_array(self::$roleList)) {
  51. foreach (self::$roleList as $k => $cat) {
  52. if ($cat['parentid'] && $k != $id && $cat['parentid'] == $id) {
  53. $arrchildid .= ',' . self::getArrchildid($k);
  54. }
  55. }
  56. }
  57. return $arrchildid;
  58. }
  59. }