You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
155 lines
5.8 KiB
155 lines
5.8 KiB
<?php
|
|
// +----------------------------------------------------------------------
|
|
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
|
|
// +----------------------------------------------------------------------
|
|
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
|
|
// +----------------------------------------------------------------------
|
|
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
|
|
// +----------------------------------------------------------------------
|
|
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
|
|
// +----------------------------------------------------------------------
|
|
|
|
namespace app\wap\model\activity;
|
|
|
|
use traits\ModelTrait;
|
|
use basic\ModelBasic;
|
|
use think\Db;
|
|
|
|
/**活动 model
|
|
* Class EventRegistration
|
|
* @package app\wap\model\activity
|
|
*/
|
|
class EventRegistration extends ModelBasic
|
|
{
|
|
use ModelTrait;
|
|
|
|
/**活动列表
|
|
* @param int $page
|
|
* @param int $limit
|
|
* @return array
|
|
*/
|
|
public static function eventRegistrationList($page = 1, $limit = 10, $city = "", $subject_id = 0, $type = "")
|
|
{
|
|
$where = [];
|
|
if ($city) {
|
|
$where['city'] = ['like',"%".$city."%"];
|
|
}
|
|
if ($subject_id) {
|
|
$where['subject_id'] = $subject_id;
|
|
}
|
|
if ($type !== "") {
|
|
$where['type'] = $type;
|
|
}
|
|
$list = self::PreWhere()->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;
|
|
}
|
|
|
|
}
|
|
|