Active.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. <?php
  2. namespace app\api\model\plus\seckill;
  3. use app\common\model\plus\seckill\Active as ActiveModel;
  4. /**
  5. * 秒杀活动模型
  6. */
  7. class Active extends ActiveModel
  8. {
  9. public function checkOrderTime($data)
  10. {
  11. $result = ['code' => 0];
  12. if ($data['start_time'] > time()) {
  13. $result = ['code' => 10, 10 => '该活动未开始'];
  14. }
  15. if ($data['end_time'] < time()) {
  16. $result = ['code' => 20, 20 => '该活动已结束'];
  17. }
  18. $now_start_time = strtotime(date('Y-m-d') . ' ' . $data['day_start_time']);
  19. $now_end_time = strtotime(date('Y-m-d') . ' ' . $data['day_end_time']);
  20. if ($now_start_time > time()) {
  21. $result = ['code' => 30, 30 => '该活动今天未开始'];
  22. }
  23. if ($now_end_time < time()) {
  24. $result = ['code' => 40, 40 => '该活动今天已结束'];
  25. }
  26. return $result;
  27. }
  28. /**
  29. * 取最近要结束的一条记录
  30. */
  31. public static function getActive()
  32. {
  33. return (new static())->where('start_time', '<', time())
  34. ->where('end_time', '>', time())
  35. ->where('status', '=', 1)
  36. ->where('is_delete', '=', 0)
  37. ->order(['sort' => 'asc', 'create_time' => 'asc'])
  38. ->find();
  39. }
  40. /**
  41. * 获取秒杀活动
  42. */
  43. public function activityList()
  44. {
  45. return $this->where('start_time', '<=', time())
  46. ->where('end_time', '>', time())
  47. ->where('status', '=', 1)
  48. ->where('is_delete', '=', 0)
  49. ->select();
  50. }
  51. }