where($where)->order('sort DESC,add_time DESC')->page((int)$page, (int)$limit)->select(); $list = count($list) > 0 ? $list->toArray() : []; foreach ($list as &$v) { $v = self::singleActivity($v); $start_time = date('y/m/d H:i', $v['start_time']); $end_time = date('y/m/d H:i', $v['end_time']); $v['time'] = $start_time . '~' . $end_time; $v['baoming'] = $start_time . '~' . $end_time; $v['start'] = date('y/m/d H:i', $v['signup_start_time']) . '~' . date('y/m/d H:i', $v['signup_end_time']); $activity_status = 0; if ($v['start_time'] < time()) { $activity_status = 0; } elseif ($v['start_time'] > time() && $v['end_time'] > time()) { $activity_status = 1; } elseif ($v['end_time'] < time()) { $activity_status = 2; } $v['activity_status'] = $activity_status; $v['count'] = EventSignUp::signUpCount($v['id']); } return $list; } /*可以显示的活动数量 * @return int|string * @throws \think\Exception */ public static function homeCount() { return self::PreWhere()->count(); } /**获取单个活动 * @param int $id */ public static function oneActivitys($id = false) { $activity = self::PreWhere()->find($id ? $id : true); if ($activity) { $activity = self::singleActivity($activity->toArray()); $activity['count'] = EventSignUp::signUpCount($id); $activity['surplus'] = bcsub($activity['number'], $activity['count'], 0); $activity['surplus'] = $activity['surplus'] < 0 ? 0 : $activity['surplus']; if ($activity['surplus'] <= 0) { $activity['statu'] = 2; self::where('id', $activity['id'])->update(['statu' => 2]); } $activity['signup_start_time'] = date('Y-m-d H:i', $activity['signup_start_time']); $activity['signup_end_time'] = date('Y-m-d H:i', $activity['signup_end_time']); $activity['start_time'] = date('Y-m-d H:i', $activity['start_time']); $activity['end_time'] = date('Y-m-d H:i', $activity['end_time']); } return $activity; } /**活动过滤 * @return EventRegistration */ public static function PreWhere() { return self::where(['is_show' => 1, 'is_del' => 0, 'status' => 1]); } /**判断活动状态 * @param $activity * @return mixed */ public static function singleActivity($activity) { if (bcsub($activity['signup_start_time'], time(), 0) > 0) { $statu = 0;//报名尚未开始 } elseif (bcsub($activity['signup_start_time'], time(), 0) <= 0 && bcsub($activity['signup_end_time'], time(), 0) > 0) { $statu = 1;//报名开始 } elseif (bcsub($activity['signup_end_time'], time(), 0) <= 0 && bcsub($activity['start_time'], time(), 0) > 0) { $statu = 2;//报名结束 活动尚未开始 } elseif (bcsub($activity['start_time'], time(), 0) <= 0 && bcsub($activity['end_time'], time(), 0) > 0) { $statu = 3;//活动中 } elseif (bcsub($activity['end_time'], time(), 0) < 0) { $statu = 4;//活动结束 } else { $statu = -1; } if ($activity['statu'] != $statu) { $activity['statu'] = $statu; self::where('id', $activity['id'])->update(['statu' => $statu]); } return $activity; } /**讲师名下资料 * @param $mer_id * @param $page * @param $limit */ public static function getLecturerEventList($mer_id, $page, $limit,$institution = 0) { $list = []; if (!$mer_id) return $list; $model = self::PreWhere(); $model = $model->where('mer_id','in',$mer_id)->where('institution_id',$institution)->order('sort desc,id desc'); $list = $model->page($page, $limit)->select(); $list = count($list) ? $list->toArray() : []; foreach ($list as &$v) { $v = self::singleActivity($v); $start_time = date('y/m/d H:i', $v['start_time']); $end_time = date('y/m/d H:i', $v['end_time']); $v['time'] = $start_time . '~' . $end_time; $v['count'] = EventSignUp::signUpCount($v['id']); } return $list; } }