Active.php 1.9 KB

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