SystemBase.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | ThinkAdmin
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2021 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: https://thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // | 免费声明 ( https://thinkadmin.top/disclaimer )
  11. // +----------------------------------------------------------------------
  12. // | gitee 代码仓库:https://gitee.com/zoujingli/ThinkAdmin
  13. // | github 代码仓库:https://github.com/zoujingli/ThinkAdmin
  14. // +----------------------------------------------------------------------
  15. namespace app\admin\model;
  16. use think\Model;
  17. /**
  18. * 数据字典数据模型
  19. * Class SystemBase
  20. * @package app\admin\model
  21. * @method \think\db\Query distinct(bool $true)
  22. */
  23. class SystemBase extends Model
  24. {
  25. /**
  26. * 获取指定数据列表
  27. * @param string $type 数据类型
  28. * @param array $data 外围数据
  29. * @param string $field 外链字段
  30. * @param string $bind 绑定字段
  31. * @return array
  32. */
  33. public function items(string $type, array &$data = [], string $field = 'base_code', string $bind = 'base_info'): array
  34. {
  35. $map = ['status' => 1, 'deleted' => 0, 'type' => $type];
  36. $bases = $this->where($map)->order('sort desc,id desc')->column('code,name,content', 'code');
  37. if (count($data) > 0) foreach ($data as &$vo) $vo[$bind] = $bases[$vo[$field]] ?? [];
  38. return $bases;
  39. }
  40. /**
  41. * 获取所有数据类型
  42. * @param boolean $simple
  43. * @return array
  44. */
  45. public function types(bool $simple = false): array
  46. {
  47. $types = $this->where(['deleted' => 0])->distinct(true)->column('type');
  48. if (empty($types) && empty($simple)) $types = ['身份权限'];
  49. return $types;
  50. }
  51. /**
  52. * 格式化创建时间
  53. * @param string $value
  54. * @return string
  55. */
  56. public function getCreateAtAttr(string $value): string
  57. {
  58. return format_datetime($value);
  59. }
  60. }