ActiveTime.php 2.3 KB

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