StoreAdvanceDao.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. declare (strict_types = 1);
  12. namespace app\dao\activity\advance;
  13. use app\dao\BaseDao;
  14. use app\model\activity\advance\StoreAdvance;
  15. /**
  16. * 预售商品
  17. * Class StoreAdvanceDao
  18. * @package app\dao\activity
  19. */
  20. class StoreAdvanceDao extends BaseDao
  21. {
  22. /**
  23. * 设置模型
  24. * @return string
  25. */
  26. protected function setModel(): string
  27. {
  28. return StoreAdvance::class;
  29. }
  30. /**
  31. * @param array $where
  32. * @param int $page
  33. * @param int $limit
  34. * @return array
  35. * @throws \think\db\exception\DataNotFoundException
  36. * @throws \think\db\exception\DbException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. */
  39. public function getList(array $where, int $page = 0, int $limit = 0)
  40. {
  41. return $this->search($where)
  42. ->when($where['time_type'], function ($query) use ($where) {
  43. if ($where['time_type'] == 1) $query->whereTime('start_time', '>', time());
  44. if ($where['time_type'] == 2) $query->whereTime('start_time', '<=', time())->whereTime('stop_time', '>=', time());
  45. if ($where['time_type'] == 3) $query->whereTime('stop_time', '<', time());
  46. })
  47. ->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
  48. $query->page($page, $limit);
  49. })->with(['product'])->order('sort desc,id desc')->select()->toArray();
  50. }
  51. /**
  52. * @param array $where
  53. * @return int
  54. */
  55. public function getCount(array $where)
  56. {
  57. return $this->search($where)
  58. ->when($where['time_type'], function ($query) use ($where) {
  59. if ($where['time_type'] == 1) $query->whereTime('start_time', '>', time());
  60. if ($where['time_type'] == 2) $query->whereTime('start_time', '<=', time())->whereTime('stop_time', '>=', time());
  61. if ($where['time_type'] == 3) $query->whereTime('stop_time', '<', time());
  62. })->count();
  63. }
  64. /**
  65. * 获取预售商品是否开启
  66. * @param array $ids
  67. * @return int
  68. */
  69. public function getAdvanceStatus(array $ids)
  70. {
  71. return $this->getModel()->whereIn('product_id', $ids)->where('is_del', 0)->where('status', 1)->count();
  72. }
  73. }