Active.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <?php
  2. namespace app\api\model\sharp;
  3. use app\common\model\sharp\Active as ActiveModel;
  4. /**
  5. * 整点秒杀-活动会场模型
  6. * Class Active
  7. * @package app\api\model\sharp
  8. */
  9. class Active extends ActiveModel
  10. {
  11. /**
  12. * 隐藏字段
  13. * @var array
  14. */
  15. protected $hidden = [
  16. 'is_delete',
  17. 'wxapp_id',
  18. 'create_time',
  19. 'update_time',
  20. ];
  21. /**
  22. * 获取当天的活动
  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 getNowActive()
  29. {
  30. $todayTime = strtotime(date('Y-m-d'));
  31. return $this->getActiveByDate($todayTime, '=');
  32. }
  33. /**
  34. * 获取当天的活动
  35. * @return array|false|\PDOStatement|string|\think\Model
  36. * @throws \think\db\exception\DataNotFoundException
  37. * @throws \think\db\exception\ModelNotFoundException
  38. * @throws \think\exception\DbException
  39. */
  40. public function getNextActive()
  41. {
  42. $todayTime = strtotime(date('Y-m-d'));
  43. return $this->getActiveByDate($todayTime, '>');
  44. }
  45. /**
  46. * 根据日期获取活动
  47. * @param $date
  48. * @param string $op
  49. * @return array|false|\PDOStatement|string|\think\Model
  50. * @throws \think\db\exception\DataNotFoundException
  51. * @throws \think\db\exception\ModelNotFoundException
  52. * @throws \think\exception\DbException
  53. */
  54. private function getActiveByDate($date, $op = '=')
  55. {
  56. return $this->where('active_date', $op, $date)
  57. ->where('status', '=', 1)
  58. ->where('is_delete', '=', 0)
  59. ->find();
  60. }
  61. }