SystemGroupDataDao.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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\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)->page($page, $limit)->order('sort desc,id DESC')->select()->toArray();
  41. }
  42. /**
  43. * 获取某个gid下的组合数据
  44. * @param int $gid
  45. * @param int $limit
  46. * @return array
  47. * @throws \think\db\exception\DataNotFoundException
  48. * @throws \think\db\exception\DbException
  49. * @throws \think\db\exception\ModelNotFoundException
  50. */
  51. public function getGroupDate(int $gid, int $limit = 0)
  52. {
  53. return $this->search(['gid' => $gid, 'status' => 1])->when($limit, function ($query) use ($limit) {
  54. $query->limit($limit);
  55. })->field('value,id')->order('sort DESC,id DESC')->select()->toArray();
  56. }
  57. /**
  58. * 根据id获取秒杀数据
  59. * @param array $ids
  60. * @param string $field
  61. * @return array
  62. * @throws \think\db\exception\DataNotFoundException
  63. * @throws \think\db\exception\DbException
  64. * @throws \think\db\exception\ModelNotFoundException
  65. */
  66. public function idByGroupList(array $ids, string $field)
  67. {
  68. return $this->getModel()->whereIn('id', $ids)->field($field)->select()->toArray();
  69. }
  70. /**
  71. * 根据gid删除组合数据
  72. * @param int $gid
  73. * @return bool
  74. */
  75. public function delGroupDate(int $gid)
  76. {
  77. return $this->getModel()->where('gid', $gid)->delete();
  78. }
  79. /**
  80. * 批量保存
  81. * @param array $data
  82. * @return mixed|\think\Collection
  83. * @throws \Exception
  84. */
  85. public function saveAll(array $data)
  86. {
  87. return $this->getModel()->saveAll($data);
  88. }
  89. }