Active.php 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\api\model\plus\bargain;
  3. use app\common\model\plus\bargain\Active as ActiveModel;
  4. /**
  5. * 砍价模型
  6. */
  7. class Active extends ActiveModel
  8. {
  9. /**
  10. * 获取砍价活动详情
  11. */
  12. public function getDetail($activeId)
  13. {
  14. $model = static::detail($activeId, 'product.sku');
  15. if (empty($model) || $model['is_delete'] == true || $model['status'] == false) {
  16. $this->error = '很抱歉,该砍价商品不存在或已下架';
  17. return false;
  18. }
  19. return $model;
  20. }
  21. /**
  22. * 取最近要结束的一条记录
  23. */
  24. public static function getActive()
  25. {
  26. return (new static())->where('start_time', '<', time())
  27. ->where('end_time', '>', time())
  28. ->where('status', '=', 1)
  29. ->where('is_delete', '=', 0)
  30. ->order(['sort' => 'asc', 'create_time' => 'asc'])
  31. ->find();
  32. }
  33. /**
  34. * 获取砍价商品列表
  35. */
  36. public function activityList()
  37. {
  38. return $this->where('start_time', '<=', time())
  39. ->where('end_time', '>=', time())
  40. ->where('status', '=', 1)
  41. ->where('is_delete', '=', 0)
  42. ->order(['sort' => 'asc', 'create_time' => 'asc'])
  43. ->select();
  44. }
  45. }