Active.php 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace app\api\model\plus\assemble;
  3. use app\common\model\plus\assemble\Active as ActiveModel;
  4. /**
  5. * 拼团模型
  6. */
  7. class Active extends ActiveModel
  8. {
  9. /**
  10. * 参与记录列表
  11. */
  12. public function getList($param)
  13. {
  14. $model = $this;
  15. if (isset($param['status']) && $param['status'] > -1) {
  16. $model = $model->where('status', '=', $param['status']);
  17. }
  18. if (isset($param['title']) && !empty($param['title'])) {
  19. $model = $model->where('title', 'like', '%' . trim($param['title']) . '%');
  20. }
  21. $res = $model->with(['file'])
  22. ->order('create_time', 'desc')
  23. ->paginate($param);
  24. foreach ($res as $key => $val) {
  25. $res[$key]['start_time'] = format_time($val['start_time']);
  26. $res[$key]['end_time'] = format_time($val['end_time']);
  27. }
  28. return $res;
  29. }
  30. /**
  31. * 取最近要结束的一条记录
  32. */
  33. public static function getActive()
  34. {
  35. return (new static())->where('start_time', '<', time())
  36. ->where('end_time', '>', time())
  37. ->where('status', '=', 1)
  38. ->where('is_delete', '=', 0)
  39. ->order(['sort' => 'asc', 'create_time' => 'asc'])
  40. ->find();
  41. }
  42. /**
  43. * 获取拼团商品列表
  44. */
  45. public function activityList()
  46. {
  47. return $this->where('start_time', '<=', time())
  48. ->where('end_time', '>=', time())
  49. ->where('status', '=', 1)
  50. ->where('is_delete', '=', 0)
  51. ->order(['sort' => 'asc', 'create_time' => 'asc'])
  52. ->select();
  53. }
  54. }