feat: 扫码签到功能
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -94,23 +94,49 @@ class Activity extends Api
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->get('id');
|
||||
$data = $this->model
|
||||
$id = $this->request->get('id');
|
||||
$activity = $this->model
|
||||
->where('id',$id)
|
||||
->field('id,images,start_time,end_time,name,fees,state activity_state,
|
||||
contacts,mobile,
|
||||
organizing_method,url,address,longitude,latitude,content,
|
||||
is_verifying,refund,
|
||||
apply_time,
|
||||
activity_auth,
|
||||
points_status,points,
|
||||
apply_field_state,
|
||||
apply_limit_number,
|
||||
non_member_registration_status')
|
||||
->field([
|
||||
'id', 'images', 'start_time', 'end_time', 'name', 'fees',
|
||||
'state' => 'activity_state', 'contacts', 'mobile',
|
||||
'organizing_method', 'url', 'address', 'longitude',
|
||||
'latitude', 'content', 'is_verifying', 'refund',
|
||||
'apply_time', 'activity_auth', 'points_status', 'points',
|
||||
'apply_field_state', 'apply_limit_number', 'non_member_registration_status'
|
||||
])
|
||||
->find();
|
||||
if (!$data) {
|
||||
if (!$activity) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
|
||||
$data = $activity->toArray();
|
||||
// 如果活动未结束,则根据当前时间校验活动状态并更新状态
|
||||
if ($data['activity_state'] < 3) {
|
||||
$now = time();
|
||||
// 当前时间小于报名截止时间,状态流转处于:报名中
|
||||
if ($now < $data['apply_time']) $data['actitity_state_trans'] = 1;
|
||||
// 当前时间大于等于报名截止时间小于开始时间,状态流转处于:未开始
|
||||
if ($now >= $data['apply_time'] && $now < $data['start_time']) $data['actitity_state_trans'] = 2;
|
||||
// 当前时间大于等于开始时间小于等于结束时间,状态流转处于:进行中
|
||||
if ($now >= $data['start_time'] && $now <= $data['end_time']) {
|
||||
$data['actitity_state_trans'] = 3;
|
||||
// 如果活动未结束,则根据当前时间校验活动状态并更新状态
|
||||
$activity->state = $data['activity_state'] = 2;
|
||||
$activity->save();
|
||||
}
|
||||
// 当前时间大于结束时间,状态流转处于:已结束
|
||||
if ($now > $data['end_time']) {
|
||||
$data['actitity_state_trans'] = 4;
|
||||
// 如果活动已结束,则根据当前时间更新状态
|
||||
$activity->state = $data['activity_state'] = 3;
|
||||
$activity->save();
|
||||
}
|
||||
} else {
|
||||
// 活动结束,状态流转就一直处理:已结束
|
||||
$data['actitity_state_trans'] = 4;
|
||||
}
|
||||
|
||||
if ($this->auth->isLogin()) {
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
@@ -123,6 +149,7 @@ class Activity extends Api
|
||||
$data['apply_id'] = '';
|
||||
$data['reject'] = '';
|
||||
} else {
|
||||
$data['check_in_status'] = $activityApplyObj['check_in_status'];
|
||||
$data['pay_state'] = $activityApplyObj['state'];
|
||||
$data['apply_id'] = $activityApplyObj['id'];
|
||||
$activityRefundObj = (new Refund())
|
||||
@@ -490,7 +517,3 @@ class Activity extends Api
|
||||
$this->success('请求成功',['show_status'=>$is_status]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
@@ -516,6 +516,55 @@ class ActivityApply extends Api
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 签到(单纯签到功能不涉核销)
|
||||
*
|
||||
* @param type $param
|
||||
* @return type
|
||||
* Created by jsasg
|
||||
*/
|
||||
public function checked_in()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
|
||||
if (!$this->auth->isLogin()) {
|
||||
$this->error('请先登录');
|
||||
}
|
||||
|
||||
// 活动id
|
||||
$id = $this->request->get('id');
|
||||
$activity = (new \app\api\model\wdsxh\activity\Activity())->where('id',$id)->find();
|
||||
if (empty($activity)) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
if (3 == $activity['state'] || time() > $activity['end_time']) {
|
||||
$this->error('活动已结束');
|
||||
}
|
||||
|
||||
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activity_apply = $this->model->where('activity_id',$id)->where('wechat_id',$wechat_id)->find();
|
||||
// 如果用户未报名,不能签到
|
||||
if(empty($activity_apply)) {
|
||||
$this->error('您还未报名该活动');
|
||||
}
|
||||
// 如果已签到,不能再次签到
|
||||
if ('checked_in' == $activity_apply['check_in_status']) {
|
||||
$this->error('您已签到');
|
||||
}
|
||||
|
||||
// 设置已签到
|
||||
$activity_apply->check_in_status = 'checked_in';
|
||||
$activity_apply->checked_in_at = time();
|
||||
if ($activity_apply->save()) {
|
||||
$this->success('签到成功');
|
||||
}
|
||||
|
||||
$this->error('签到失败');
|
||||
}
|
||||
|
||||
private function handle_custom_data($data)
|
||||
{
|
||||
$custom_field = array('name','mobile');
|
||||
@@ -530,7 +579,3 @@ class ActivityApply extends Api
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user