StoreSeckillTimeDao.php 3.0 KB

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