belongsTo('app\\common\\model\\file\\UploadFile', 'image_id', 'file_id'); } public function getEndTimeAttr($value) { return date('Y-m-d H:i:s', $value); } public function getStartTimeAttr($value) { return date('Y-m-d H:i:s', $value); } /** * 获取活动详情 */ public static function detail($groupbuy_active_id,$with = ['file']) { return (new static())->with($with)->where('groupbuy_active_id', '=', $groupbuy_active_id)->find(); } /** * 获取有效的团购活动 */ public static function getValidActive() { return (new static()) ->where('start_time', '<=', time()) ->where('end_time', '>', time()) ->where('status', '=', 1) ->where('is_delete', '=', 0) ->order(['sort' => 'asc', 'create_time' => 'desc']) ->find(); } /** * 获取活动列表 */ public function getList($param) { $model = $this; if (isset($param['status']) && $param['status'] > -1) { $model = $model->where('status', '=', $param['status']); } if (isset($param['title']) && !empty($param['title'])) { $model = $model->where('active_name', 'like', '%' . trim($param['title']) . '%'); } $res = $model->with(['file']) ->order('create_time', 'desc') ->paginate($param); foreach ($res as $key => $val) { $res[$key]['start_time'] = format_time($val['start_time']); $res[$key]['end_time'] = format_time($val['end_time']); } return $res; } }