StoreSeckillTimeDao.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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\common\dao\store;
  12. use app\common\model\store\StoreSeckillTime;
  13. use app\common\dao\BaseDao;
  14. class StoreSeckillTimeDao extends BaseDao
  15. {
  16. /**
  17. * TODO
  18. * @return string
  19. * @author Qinii
  20. * @day 2020-07-30
  21. */
  22. protected function getModel(): string
  23. {
  24. return StoreSeckillTime::class;
  25. }
  26. public function getTime($status)
  27. {
  28. foreach (StoreSeckillTime::ISTIME as $k => $item){
  29. if($status && $k !== 24){
  30. $time [] = ['value' => $k, 'label' => $item];
  31. }
  32. if(!$status && $k !== 0){
  33. $time [] = ['value' => $k, 'label' => $item];
  34. }
  35. }
  36. return $time;
  37. }
  38. public function search(array $where)
  39. {
  40. $query = $this->getModel()::getDB()
  41. ->when(isset($where['status']) && $where['status'] !== '',function($query) use($where){
  42. $query->where('status',$where['status']);
  43. })
  44. ->when(isset($where['title']) && $where['title'] !== '',function($query) use($where){
  45. $query->where('title','like','%'.$where['title'].'%');
  46. })
  47. ->when(isset($where['start_time']) && $where['start_time'] !== '',function($query) use($where){
  48. $query->whereTime('start_time','<=',intval($where['start_time']));
  49. })
  50. ->when(isset($where['end_time']) && $where['end_time'] !== '',function($query) use($where){
  51. $query->whereTime('end_time','>=',intval($where['end_time']));
  52. });
  53. $query->order('start_time ASC');
  54. return $query;
  55. }
  56. /**
  57. * TODO 开始时间 在别的时间段中
  58. * @param $time
  59. * @return mixed
  60. * @author Qinii
  61. * @day 2020-07-31
  62. */
  63. public function valStartTime($time,$id)
  64. {
  65. return $this->getModel()::getDB()
  66. ->when($id,function ($query)use($id){
  67. $query->where($this->getPk(),'<>',$id);
  68. })->where('start_time','<=',$time)->where('end_time','>',$time)->count();
  69. }
  70. /**
  71. * TODO 结束时间在别的时间段中
  72. * @param $time
  73. * @param $id
  74. * @return mixed
  75. * @author Qinii
  76. * @day 2020-07-31
  77. */
  78. public function valEndTime($time,$id)
  79. {
  80. return $this->getModel()::getDB()
  81. ->when($id,function ($query)use($id){
  82. $query->where($this->getPk(),'<>',$id);
  83. })->where('start_time','<',$time)->where('end_time','>=',$time)->count();
  84. }
  85. /**
  86. * TODO 时间段包含了别的时间段
  87. * @param array $data
  88. * @param $id
  89. * @return mixed
  90. * @author Qinii
  91. * @day 2020-07-31
  92. */
  93. public function valAllTime(array $data,$id)
  94. {
  95. return $this->getModel()::getDB()
  96. ->when($id,function ($query)use($id){
  97. $query->where($this->getPk(),'<>',$id);
  98. })->where('start_time','>',$data['start_time'])->where('end_time','<=',$data['end_time'])->count();
  99. }
  100. }