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.
 
 
 
 
 
 
zhishifufei_php/application/web/model/activity/EventRegistration.php

144 lines
5.6 KiB

<?php
// +----------------------------------------------------------------------
// | 天诚科技 [ 刘海东 17600099397赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2020 https://www.tczxkj.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 该系统并不是自由软件,未经许可不能去掉相关版权
// +----------------------------------------------------------------------
// | Author:甘肃天诚志信电子商务有限公司 刘海东 联系电话维系17600099397
// +----------------------------------------------------------------------
namespace app\web\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, $statu = '')
{
$list = self::PreWhere($statu)->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['count'] = EventSignUp::signUpCount($v['id']);
}
$count = self::PreWhere($statu)->count();
return compact('list', '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($statu)
{
$model = self::where(['is_show' => 1, 'is_del' => 0, 'status' => 1]);
if ($statu != '') $model = $model->where('statu', $statu);
return $model;
}
/**判断活动状态
* @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;
}
/**讲师名下活动
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public static function getLecturerEventList($mer_id = 0, $page = 1, $limit = 10)
{
$data = [];
$count = 0;
if (!$mer_id) return compact('data', 'count');
$model = self::PreWhere('');
$model = $model->where(['mer_id' => $mer_id])->order('sort desc,id desc');
$data = $model->page($page, $limit)->select();
$data = count($data) ? $data->toArray() : [];
foreach ($data 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']);
}
$count = self::PreWhere('')->where(['mer_id' => $mer_id])->count();
return compact('data', 'count');
}
/**
*相关活动
*/
public static function getRelatedActivitiesList($id, $page = 1, $limit = 10)
{
$model = self::PreWhere('')->order('sort desc,id desc');
$data = $model->where('id', '<>', $id)->page($page, $limit)->select();
$data = count($data) ? $data->toArray() : [];
foreach ($data as &$v) {
$v['count'] = EventSignUp::signUpCount($v['id']);
}
return $data;
}
}