ActiveTime.php 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. namespace app\api\model\sharp;
  3. use app\common\model\sharp\ActiveTime as ActiveTimeModel;
  4. /**
  5. * 整点秒杀-活动会场场次模型
  6. * Class ActiveTime
  7. * @package app\api\model\sharp
  8. */
  9. class ActiveTime extends ActiveTimeModel
  10. {
  11. /**
  12. * 隐藏字段
  13. * @var array
  14. */
  15. protected $hidden = [
  16. 'wxapp_id',
  17. 'create_time',
  18. 'update_time',
  19. ];
  20. /**
  21. * 获取当前进行中的活动场次
  22. * @param $activeId
  23. * @return array|false|\PDOStatement|string|\think\Model
  24. * @throws \think\db\exception\DataNotFoundException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. * @throws \think\exception\DbException
  27. */
  28. public function getNowActiveTime($activeId)
  29. {
  30. // 当前的时间点
  31. $nowTime = date('H');
  32. return $this->where('active_id', '=', $activeId)
  33. ->where('active_time', '=', $nowTime)
  34. ->where('status', '=', 1)
  35. ->find();
  36. }
  37. /**
  38. * 获取下一场活动场次
  39. * @param $activeId
  40. * @return false|\PDOStatement|string|\think\Collection
  41. * @throws \think\db\exception\DataNotFoundException
  42. * @throws \think\db\exception\ModelNotFoundException
  43. * @throws \think\exception\DbException
  44. */
  45. public function getNextActiveTimes($activeId)
  46. {
  47. // 当前的时间点
  48. $nowTime = date('H');
  49. return $this->where('active_id', '=', $activeId)
  50. ->where('active_time', '>', $nowTime)
  51. ->where('status', '=', 1)
  52. ->order(['active_time' => 'asc'])
  53. ->select();
  54. }
  55. /**
  56. * 获取指定日期最近的活动场次
  57. * @param $activeId
  58. * @return array|false|\PDOStatement|string|\think\Model
  59. * @throws \think\db\exception\DataNotFoundException
  60. * @throws \think\db\exception\ModelNotFoundException
  61. * @throws \think\exception\DbException
  62. */
  63. public function getRecentActiveTime($activeId)
  64. {
  65. return $this->where('active_id', '=', $activeId)
  66. ->where('status', '=', 1)
  67. ->order(['active_time' => 'asc'])
  68. ->find();
  69. }
  70. }