feat: 扫码签到功能

This commit is contained in:
2026-03-19 17:41:23 +08:00
parent e2c8ae752d
commit 1156b2f4e2
9 changed files with 457 additions and 349 deletions

View File

@@ -53,6 +53,7 @@ return [
'Verification_method 1' => '自助签到(范围1000米)', 'Verification_method 1' => '自助签到(范围1000米)',
'Verification_method 2' => '管理员核销', 'Verification_method 2' => '管理员核销',
'Applet_activity_qrcode_path' => '活动小程序码', 'Applet_activity_qrcode_path' => '活动小程序码',
'Checked_in_qrcode' => '签到二维码',
'Points_status' => '设置是否获得积分', 'Points_status' => '设置是否获得积分',
'Points_status 1' => '是', 'Points_status 1' => '是',
'Points_status 2' => '否', 'Points_status 2' => '否',

View File

@@ -20,6 +20,9 @@ return [
'State 3' => '退款中', 'State 3' => '退款中',
'State 4' => '已退款', 'State 4' => '已退款',
'State 5' => '已驳回', 'State 5' => '已驳回',
'check_in_status' => '签到状态',
'checked_in' => '已签到',
'unchecked_in' => '未签到',
'Is_sign_in' => '核销状态', 'Is_sign_in' => '核销状态',
'Is_sign_in 1' => '已核销', 'Is_sign_in 1' => '已核销',
'Is_sign_in 2' => '未核销', 'Is_sign_in 2' => '未核销',

View File

@@ -42,7 +42,8 @@ class Activity extends Model
'state_text', 'state_text',
'is_verifying_text', 'is_verifying_text',
'status_text', 'status_text',
'applet_activity_qrcode_path' 'applet_activity_qrcode_path',
'checked_in_qrcode'
]; ];
@@ -186,6 +187,7 @@ class Activity extends Model
$response = $app->app_code->getUnlimit($ids, [ $response = $app->app_code->getUnlimit($ids, [
'page' => $path, 'page' => $path,
'check_path' => false, 'check_path' => false,
'env_version' => 'develop',
]); ]);
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) { if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
@@ -202,6 +204,48 @@ class Activity extends Model
return $value; return $value;
} }
public function getCheckedInQrcodeAttr($value, $data)
{
$row = $data;
$row['createtime'] = self::where('id',$row['id'])->value('createtime');
$save_path = '/uploads/wdsxh/check_in_qrcode/'.$row['id'].'/'.$row['createtime'].'.png';
if (is_file(ROOT_PATH."public".$save_path)) {
$value = $save_path;
} else {
if(isset($row['id'])) {
$configObj = (new \app\admin\model\wdsxh\Config())->where('id',1)->find();
if (!empty($configObj['applet_appid']) && !empty($configObj['applet_secret'])) {
$path = 'pagesActivity/index/details';
$config = [
'app_id' => $configObj['applet_appid'],
'secret' => $configObj['applet_secret'],
'response_type' => 'array',
'log' => [
'level' => 'debug',
],
];
$app = Factory::miniProgram($config);
$scene = http_build_query(['id' => $row['id'], 'op' => 'checked_in']);
$response = $app->app_code->getUnlimit($scene, [
'page' => $path,
'check_path' => false,
'env_version' => 'develop',
]);
if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
$response->saveAs('uploads/wdsxh/check_in_qrcode/'.$row['id'], $row['createtime'].'.png');
$value = $save_path;
}
}
}
}
if (!empty($value)) {
$value = request()->domain().$value;
}
return $value;
}
public function getPointsStatusList() public function getPointsStatusList()
{ {
return ['2' => __('Points_status 2'), '1' => __('Points_status 1')]; return ['2' => __('Points_status 2'), '1' => __('Points_status 1')];
@@ -216,6 +260,4 @@ class Activity extends Model
{ {
return ['1' => __('启用单独证书'), '2' => __('使用统一证书')]; return ['1' => __('启用单独证书'), '2' => __('使用统一证书')];
} }
} }

View File

@@ -9,11 +9,6 @@
<a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a> <a href="javascript:;" class="btn btn-primary btn-refresh" title="{:__('Refresh')}" ><i class="fa fa-refresh"></i> </a>
<a href="javascript:;" class="btn btn-success btn-add {:$auth->check('wdsxh/activity/activity_apply/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a> <a href="javascript:;" class="btn btn-success btn-add {:$auth->check('wdsxh/activity/activity_apply/add')?'':'hide'}" title="{:__('Add')}" ><i class="fa fa-plus"></i> {:__('Add')}</a>
<!-- <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('wdsxh/activity/activity_apply/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>--> <!-- <a href="javascript:;" class="btn btn-danger btn-del btn-disabled disabled {:$auth->check('wdsxh/activity/activity_apply/del')?'':'hide'}" title="{:__('Delete')}" ><i class="fa fa-trash"></i> {:__('Delete')}</a>-->
</div> </div>
<table id="table" class="table table-striped table-bordered table-hover table-nowrap" <table id="table" class="table table-striped table-bordered table-hover table-nowrap"
data-operate-edit="{:$auth->check('wdsxh/activity/activity_apply/edit')}" data-operate-edit="{:$auth->check('wdsxh/activity/activity_apply/edit')}"

View File

@@ -95,22 +95,48 @@ class Activity extends Api
$this->error('请求类型错误'); $this->error('请求类型错误');
} }
$id = $this->request->get('id'); $id = $this->request->get('id');
$data = $this->model $activity = $this->model
->where('id',$id) ->where('id',$id)
->field('id,images,start_time,end_time,name,fees,state activity_state, ->field([
contacts,mobile, 'id', 'images', 'start_time', 'end_time', 'name', 'fees',
organizing_method,url,address,longitude,latitude,content, 'state' => 'activity_state', 'contacts', 'mobile',
is_verifying,refund, 'organizing_method', 'url', 'address', 'longitude',
apply_time, 'latitude', 'content', 'is_verifying', 'refund',
activity_auth, 'apply_time', 'activity_auth', 'points_status', 'points',
points_status,points, 'apply_field_state', 'apply_limit_number', 'non_member_registration_status'
apply_field_state, ])
apply_limit_number,
non_member_registration_status')
->find(); ->find();
if (!$data) { if (!$activity) {
$this->error('活动不存在'); $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()) { if ($this->auth->isLogin()) {
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id'); $wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply()) $activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
@@ -123,6 +149,7 @@ class Activity extends Api
$data['apply_id'] = ''; $data['apply_id'] = '';
$data['reject'] = ''; $data['reject'] = '';
} else { } else {
$data['check_in_status'] = $activityApplyObj['check_in_status'];
$data['pay_state'] = $activityApplyObj['state']; $data['pay_state'] = $activityApplyObj['state'];
$data['apply_id'] = $activityApplyObj['id']; $data['apply_id'] = $activityApplyObj['id'];
$activityRefundObj = (new Refund()) $activityRefundObj = (new Refund())
@@ -490,7 +517,3 @@ class Activity extends Api
$this->success('请求成功',['show_status'=>$is_status]); $this->success('请求成功',['show_status'=>$is_status]);
} }
} }

View File

@@ -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) private function handle_custom_data($data)
{ {
$custom_field = array('name','mobile'); $custom_field = array('name','mobile');
@@ -530,7 +579,3 @@ class ActivityApply extends Api
return $result; return $result;
} }
} }

View File

@@ -65,7 +65,3 @@ class Activity extends Base
}); });
} }
} }

View File

@@ -43,6 +43,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'weigh', title: __('Weigh'), operate: false}, {field: 'weigh', title: __('Weigh'), operate: false},
{field: 'status', title: __('Status'), searchList: {"normal":__('Status normal'),"hidden":__('Status hidden')}, formatter: Table.api.formatter.status}, {field: 'status', title: __('Status'), searchList: {"normal":__('Status normal'),"hidden":__('Status hidden')}, formatter: Table.api.formatter.status},
{field: 'applet_activity_qrcode_path', title: __('Applet_activity_qrcode_path'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image}, {field: 'applet_activity_qrcode_path', title: __('Applet_activity_qrcode_path'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'checked_in_qrcode', title: __('Checked_in_qrcode'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
{field: 'points_status', title: __('Points_status'), searchList: { "1": __('Points_status 1'), "2": __('Points_status 2'), "3": __('Points_status 3') }, formatter: Table.api.formatter.normal}, {field: 'points_status', title: __('Points_status'), searchList: { "1": __('Points_status 1'), "2": __('Points_status 2'), "3": __('Points_status 3') }, formatter: Table.api.formatter.normal},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons:[ buttons:[
@@ -87,11 +88,12 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
extend: 'data-area=["40%","60%"]', extend: 'data-area=["40%","60%"]',
url: 'wdsxh/activity/activity/verification_applet_code', url: 'wdsxh/activity/activity/verification_applet_code',
visible: function (row) { visible: function (row) {
if(Config.applet_appid !== null && Config.applet_appid !== undefined && Config.applet_appid !== '' && row.is_verifying == '1' && row.verification_method == 1 && row.state != '3'){
return true;
}else{
return false; return false;
} // if(Config.applet_appid !== null && Config.applet_appid !== undefined && Config.applet_appid !== '' && row.is_verifying == '1' && row.verification_method == 1 && row.state != '3'){
// return true;
// }else{
// return false;
// }
}, },
}, },
{ {

View File

@@ -35,6 +35,7 @@ define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefin
{field: 'state', title: __('State'), searchList: {"1":__('State 1'),"2":__('State 2'),"3":__('State 3'),"4":__('State 4'),"5":__('State 5')}, formatter: Table.api.formatter.normal}, {field: 'state', title: __('State'), searchList: {"1":__('State 1'),"2":__('State 2'),"3":__('State 3'),"4":__('State 4'),"5":__('State 5')}, formatter: Table.api.formatter.normal},
{field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime}, {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
{field: 'pay_time', title: __('付款时间'), operate:false}, {field: 'pay_time', title: __('付款时间'), operate:false},
{field: 'check_in_status', title: __('check_in_status'), searchList: {"checked_in":__('checked_in'),"unchecked_in":__('unchecked_in')}, formatter: Table.api.formatter.normal},
{field: 'is_sign_in', title: __('Is_sign_in'), searchList: {"1":__('Is_sign_in 1'),"2":__('Is_sign_in 2'),"3":__('Is_sign_in 3')}, formatter: Table.api.formatter.normal}, {field: 'is_sign_in', title: __('Is_sign_in'), searchList: {"1":__('Is_sign_in 1'),"2":__('Is_sign_in 2'),"3":__('Is_sign_in 3')}, formatter: Table.api.formatter.normal},
{field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate, {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate,
buttons: [ buttons: [