SystemGroupServices.php 3.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 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. * @mixin SystemGroupDao
  19. */
  20. class SystemGroupServices extends BaseServices
  21. {
  22. /**
  23. * SystemGroupServices constructor.
  24. * @param SystemGroupDao $dao
  25. */
  26. public function __construct(SystemGroupDao $dao)
  27. {
  28. $this->dao = $dao;
  29. }
  30. /**
  31. * 获取组合数据列表
  32. * @param array $where
  33. * @return array
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function getGroupList(array $where, array $field = ['*'])
  39. {
  40. [$page, $limit] = $this->getPageValue();
  41. $list = $this->dao->getGroupList($where, $field, $page, $limit);
  42. $count = $this->dao->count($where);
  43. foreach ($list as $key => $value) {
  44. if (isset($value['fields'])) {
  45. $list[$key]['typelist'] = $value['fields'];
  46. unset($list[$key]['fields']);
  47. }
  48. }
  49. return compact('list', 'count');
  50. }
  51. /**
  52. * 获取组合数据tab下的header头部
  53. * @param int $id
  54. * @return array
  55. */
  56. public function getGroupDataTabHeader(int $id)
  57. {
  58. $data = $this->getValueFields($id);
  59. $header = [];
  60. foreach ($data as $key => $item) {
  61. if ($item['type'] == 'upload' || $item['type'] == 'uploads') {
  62. $header[$key]['key'] = $item['title'];
  63. $header[$key]['minWidth'] = 60;
  64. $header[$key]['type'] = 'img';
  65. } elseif ($item['title'] == 'url' || $item['title'] == 'wap_url' || $item['title'] == 'link' || $item['title'] == 'wap_link') {
  66. $header[$key]['key'] = $item['title'];
  67. $header[$key]['minWidth'] = 200;
  68. } else {
  69. $header[$key]['key'] = $item['title'];
  70. $header[$key]['minWidth'] = 100;
  71. }
  72. $header[$key]['title'] = $item['name'];
  73. }
  74. array_unshift($header, ['key' => 'id', 'title' => '编号', 'width' => 55]);
  75. array_push($header, ['slot' => 'status', 'title' => '是否可用', 'minWidth' => 80], ['key' => 'sort', 'title' => '排序', 'minWidth' => 80], ['slot' => 'action', 'fixed' => 'right', 'title' => '操作', 'minWidth' => 120]);
  76. return compact('header');
  77. }
  78. /**
  79. * 获取组合数据fields字段
  80. * @param int $id
  81. * @return array|mixed
  82. */
  83. public function getValueFields(int $id)
  84. {
  85. return json_decode($this->dao->value(['id' => $id], 'fields'), true) ?: [];
  86. }
  87. }