StoreSeckillTimeDao.php 3.0 KB

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