SystemGroupDataDao.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\dao\system\config;
  12. use app\dao\BaseDao;
  13. use app\model\system\config\SystemGroupData;
  14. /**
  15. * 组合数据
  16. * Class SystemGroupDataDao
  17. * @package app\dao\system\config
  18. */
  19. class SystemGroupDataDao extends BaseDao
  20. {
  21. /**
  22. * 设置模型
  23. * @return string
  24. */
  25. protected function setModel(): string
  26. {
  27. return SystemGroupData::class;
  28. }
  29. /**
  30. * 获取组合数据列表
  31. * @param array $where
  32. * @param int $page
  33. * @param int $limit
  34. * @throws \think\db\exception\DataNotFoundException
  35. * @throws \think\db\exception\DbException
  36. * @throws \think\db\exception\ModelNotFoundException
  37. */
  38. public function getGroupDataList(array $where, int $page, int $limit)
  39. {
  40. return $this->search($where)->when($page && $limit, function ($query) use ($page, $limit) {
  41. $query->page($page, $limit);
  42. })->order('sort desc,id DESC')->select()->toArray();
  43. }
  44. /**
  45. * 获取某个gid下的组合数据
  46. * @param int $gid
  47. * @param int $limit
  48. * @return array
  49. * @throws \think\db\exception\DataNotFoundException
  50. * @throws \think\db\exception\DbException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. */
  53. public function getGroupDate(int $gid, int $limit = 0)
  54. {
  55. return $this->search(['gid' => $gid, 'status' => 1])->when($limit, function ($query) use ($limit) {
  56. $query->limit($limit);
  57. })->field('value,id')->order('sort DESC,id DESC')->select()->toArray();
  58. }
  59. /**
  60. * 根据gid删除组合数据
  61. * @param int $gid
  62. * @return bool
  63. */
  64. public function delGroupDate(int $gid)
  65. {
  66. return $this->getModel()->where('gid', $gid)->delete();
  67. }
  68. /**
  69. * 批量保存
  70. * @param array $data
  71. * @return mixed|\think\Collection
  72. * @throws \Exception
  73. */
  74. public function saveAll(array $data)
  75. {
  76. return $this->getModel()->saveAll($data);
  77. }
  78. /**
  79. * 根据id获取秒杀数据
  80. * @param array $ids
  81. * @param string $field
  82. * @return array
  83. * @throws \think\db\exception\DataNotFoundException
  84. * @throws \think\db\exception\DbException
  85. * @throws \think\db\exception\ModelNotFoundException
  86. */
  87. public function idByGroupList(array $ids, string $field)
  88. {
  89. return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
  90. }
  91. }