SystemGroupServices.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2023 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\services\system\config;
  12. use app\dao\system\config\SystemGroupDao;
  13. use app\services\BaseServices;
  14. /**
  15. * 组合数据
  16. * Class SystemGroupServices
  17. * @package app\services\system\config
  18. * @method getConfigNameId(string $configName) 获取配置id
  19. * @method save(array $data) 新增数据
  20. * @method get(int $id, ?array $field = []) 获取一条数据
  21. * @method count(array $where = []): int 根据条件获取条数
  22. * @method update($id, array $data, ?string $key = null) 修改数据
  23. * @method delete($id, ?string $key = null) 删除数据
  24. * @method value(array $where, ?string $field = '') 获取某个值
  25. */
  26. class SystemGroupServices extends BaseServices
  27. {
  28. /**
  29. * SystemGroupServices constructor.
  30. * @param SystemGroupDao $dao
  31. */
  32. public function __construct(SystemGroupDao $dao)
  33. {
  34. $this->dao = $dao;
  35. }
  36. /**
  37. * 获取组合数据列表
  38. * @param array $where
  39. * @return array
  40. * @throws \think\db\exception\DataNotFoundException
  41. * @throws \think\db\exception\DbException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. */
  44. public function getGroupList(array $where, array $field = ['*'])
  45. {
  46. [$page, $limit] = $this->getPageValue();
  47. $list = $this->dao->getGroupList($where, $field, $page, $limit);
  48. $count = $this->dao->count($where);
  49. foreach ($list as $key => $value) {
  50. if (isset($value['fields'])) {
  51. $list[$key]['typelist'] = $value['fields'];
  52. unset($list[$key]['fields']);
  53. }
  54. }
  55. return compact('list', 'count');
  56. }
  57. /**
  58. * 获取组合数据tab下的header头部
  59. * @param int $id
  60. * @return array
  61. */
  62. public function getGroupDataTabHeader(int $id)
  63. {
  64. $data = $this->getValueFields($id);
  65. $header = [];
  66. foreach ($data as $key => $item) {
  67. if ($item['type'] == 'upload' || $item['type'] == 'uploads') {
  68. $header[$key]['key'] = $item['title'];
  69. $header[$key]['minWidth'] = 60;
  70. $header[$key]['type'] = 'img';
  71. } elseif ($item['title'] == 'url' || $item['title'] == 'wap_url' || $item['title'] == 'link' || $item['title'] == 'wap_link') {
  72. $header[$key]['key'] = $item['title'];
  73. $header[$key]['minWidth'] = 200;
  74. } else {
  75. $header[$key]['key'] = $item['title'];
  76. $header[$key]['minWidth'] = 100;
  77. }
  78. $header[$key]['title'] = $item['name'];
  79. }
  80. array_unshift($header, ['key' => 'id', 'title' => '编号', 'minWidth' => 60]);
  81. array_push($header, ['slot' => 'status', 'title' => '是否可用', 'minWidth' => 80], ['key' => 'sort', 'title' => '排序', 'minWidth' => 80], ['slot' => 'action', 'fixed' => 'right', 'title' => '操作', 'minWidth' => 120]);
  82. return compact('header');
  83. }
  84. /**
  85. * 获取组合数据fields字段
  86. * @param int $id
  87. * @return array|mixed
  88. */
  89. public function getValueFields(int $id)
  90. {
  91. return json_decode($this->dao->value(['id' => $id], 'fields'), true) ?: [];
  92. }
  93. }