StoreAdvanceDao.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 \ReflectionException
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\DbException
  38. * @throws \think\db\exception\ModelNotFoundException
  39. * @author 吴汐
  40. * @email 442384644@qq.com
  41. * @date 2023/03/20
  42. */
  43. public function getList(array $where, int $page = 0, int $limit = 0)
  44. {
  45. return $this->search($where, false)
  46. ->when($where['time_type'], function ($query) use ($where) {
  47. if ($where['time_type'] == 1) $query->whereTime('start_time', '>', time());
  48. if ($where['time_type'] == 2) $query->whereTime('start_time', '<=', time())->whereTime('stop_time', '>=', time());
  49. if ($where['time_type'] == 3) $query->whereTime('stop_time', '<', time());
  50. })
  51. ->when($page != 0 && $limit != 0, function ($query) use ($page, $limit) {
  52. $query->page($page, $limit);
  53. })->with(['product'])->order('sort desc,id desc')->select()->toArray();
  54. }
  55. /**
  56. * @param array $where
  57. * @return int
  58. * @throws \ReflectionException
  59. */
  60. public function getCount(array $where)
  61. {
  62. return $this->search($where, false)
  63. ->when($where['time_type'], function ($query) use ($where) {
  64. if ($where['time_type'] == 1) $query->whereTime('start_time', '>', time());
  65. if ($where['time_type'] == 2) $query->whereTime('start_time', '<=', time())->whereTime('stop_time', '>=', time());
  66. if ($where['time_type'] == 3) $query->whereTime('stop_time', '<', time());
  67. })->count();
  68. }
  69. /**
  70. * 获取预售商品是否开启
  71. * @param array $ids
  72. * @return int
  73. */
  74. public function getAdvanceStatus(array $ids)
  75. {
  76. return $this->getModel()->whereIn('product_id', $ids)->where('is_del', 0)->where('status', 1)->count();
  77. }
  78. }