init commit
This commit is contained in:
496
application/api/controller/wdsxh/activity/Activity.php
Normal file
496
application/api/controller/wdsxh/activity/Activity.php
Normal file
@@ -0,0 +1,496 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller\wdsxh\activity;
|
||||
|
||||
use app\admin\model\wdsxh\activity\ActivityConfig;
|
||||
use app\api\model\wdsxh\activity\Order;
|
||||
use app\api\model\wdsxh\activity\Refund;
|
||||
use app\api\model\wdsxh\member\Member;
|
||||
use app\api\model\wdsxh\user\Wechat;
|
||||
use app\api\model\wdsxh\UserWechat;
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
/**
|
||||
* Class Activity
|
||||
* Desc 活动控制器
|
||||
* Create on 2024/3/11 16:24
|
||||
* Create by wangyafang
|
||||
*/
|
||||
class Activity extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['index','update_activity_state','details','activity_config'];
|
||||
protected $noNeedRight = ['*'];
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\api\model\wdsxh\activity\Activity();
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 活动列表
|
||||
* time: 2024-3-11 16:38
|
||||
* */
|
||||
public function index()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->get();
|
||||
$where = [];
|
||||
|
||||
$expired_activity_show = (new ActivityConfig())->value('expired_activity_show');
|
||||
if ($expired_activity_show == 1) {
|
||||
$where['state'] = array('in',['1','2','3']);
|
||||
} else {
|
||||
$where['state'] = array('in',['1','2']);
|
||||
}
|
||||
|
||||
$where['status'] = array('eq','normal');
|
||||
|
||||
if(isset($param['keywords']) && !empty($param['keywords'])) {
|
||||
$where['name'] = array('like','%'.$param['keywords'].'%');
|
||||
}
|
||||
if(isset($param['state']) && !empty($param['state'])) {
|
||||
$where['state'] = array('eq',$param['state']);
|
||||
}
|
||||
$page = isset($param['page']) ? $param['page'] : '';
|
||||
$limit = isset($param['limit']) ? $param['limit'] : 10;
|
||||
$count = $this->model->where($where)->count();
|
||||
$order = 'weigh desc,id desc';
|
||||
|
||||
$data = $this->model
|
||||
->where($where)
|
||||
->page($page,$limit)
|
||||
->field('id,name,start_time,address,images,organizing_method,activity_auth')
|
||||
->order($order)
|
||||
->select();
|
||||
|
||||
foreach ($data as $k=>&$v) {
|
||||
$v->week = $this->getTimeWeek($v['start_time']);
|
||||
$v->start_time = date('m/d H:i',$v->start_time);
|
||||
$images = explode(',',$v->images);
|
||||
$v->images = $images[0];
|
||||
}
|
||||
|
||||
$this->success('请求成功',['total'=>$count,'data'=>$data]);
|
||||
}
|
||||
|
||||
public function details()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->get('id');
|
||||
$data = $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')
|
||||
->find();
|
||||
if (!$data) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
if ($this->auth->isLogin()) {
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('activity_id',$id)
|
||||
->order('id desc')
|
||||
->find();
|
||||
if (!$activityApplyObj) {
|
||||
$data['pay_state'] = '1';
|
||||
$data['apply_id'] = '';
|
||||
$data['reject'] = '';
|
||||
} else {
|
||||
$data['pay_state'] = $activityApplyObj['state'];
|
||||
$data['apply_id'] = $activityApplyObj['id'];
|
||||
$activityRefundObj = (new Refund())
|
||||
->where('activity_id',$id)
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('state','3')
|
||||
->order('id desc')
|
||||
->find();
|
||||
$data['reject'] = $activityRefundObj ? $activityRefundObj['reject'] : '';
|
||||
}
|
||||
} else {
|
||||
$data['pay_state'] = '1';
|
||||
$data['apply_id'] = '';
|
||||
$data['reject'] = '';
|
||||
}
|
||||
|
||||
if ($data['points_status'] == 2) {
|
||||
unset($data['points']);
|
||||
}
|
||||
|
||||
$activityApplyModel = new \app\api\model\wdsxh\activity\ActivityApply();
|
||||
$data['apply_count'] = $activityApplyModel->where('activity_id', $id)->where('state',2)->count();
|
||||
$apply_list = $activityApplyModel->where('activity_id', $id)
|
||||
->where('state',2)
|
||||
->alias('apply')
|
||||
->order('apply.createtime desc')
|
||||
->join('wdsxh_member member', 'member.id = apply.member_id')
|
||||
->field('member.avatar member_avatar')
|
||||
->limit(10)
|
||||
->select();
|
||||
if (!empty($apply_list)) {
|
||||
foreach ($apply_list as &$v) {
|
||||
$v->member_avatar = wdsxh_full_url($v->member_avatar);
|
||||
}
|
||||
}
|
||||
$data['apply_list'] = $apply_list;
|
||||
|
||||
if ($this->auth->isLogin()) {
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('activity_id', $id)
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('state','2')
|
||||
->find();
|
||||
if ($activityApplyObj) {
|
||||
$apply_status = 1;
|
||||
} else {
|
||||
$apply_status = 2;
|
||||
}
|
||||
} else {
|
||||
$apply_status = 2;
|
||||
}
|
||||
$data['apply_status'] = $apply_status;
|
||||
|
||||
if ($this->auth->isLogin()) {
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('activity_id', $id)
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('state','1')
|
||||
->find();
|
||||
if ($activityApplyObj && !empty($activityApplyObj['field_data'])) {
|
||||
$apply_info_fill_state = 1;
|
||||
} else {
|
||||
$apply_info_fill_state = 2;
|
||||
}
|
||||
} else {
|
||||
$apply_info_fill_state = 2;
|
||||
}
|
||||
$data['apply_info_fill_state'] = $apply_info_fill_state;
|
||||
|
||||
if (!empty($data['apply_limit_number']) && $data['apply_limit_number'] > 0) {
|
||||
$apply_count = (new \app\api\model\wdsxh\activity\ActivityApply())->where('activity_id', $id)
|
||||
->where('state',2)
|
||||
->count();
|
||||
if ($data['apply_limit_number'] > $apply_count) {
|
||||
$data['apply_limit_number'] = $data['apply_limit_number'] - $apply_count;
|
||||
} else {
|
||||
$data['apply_limit_number'] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
$this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
public function getTimeWeek($time, $i = 0) {
|
||||
$weekarray = array("日","一", "二", "三", "四", "五", "六");
|
||||
$week = $weekarray[date("w",$time)];
|
||||
return "周".$week;
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 会员活动列表
|
||||
* time: 2024-3-11 17:38
|
||||
* */
|
||||
public function user_index()
|
||||
{
|
||||
$page=$this->request->param('page',1);
|
||||
$limit=$this->request->param('limit',10);
|
||||
$payState=$this->request->param('pay_state',0);//报名状态
|
||||
$activityState=$this->request->param('activity_state',0);
|
||||
try {
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$where=array(
|
||||
'ActivityApply.wechat_id'=>$wechat_id
|
||||
);
|
||||
if(!empty($payState)){
|
||||
$where['ActivityApply.state'] = $payState;
|
||||
}
|
||||
|
||||
$activityMap = array();
|
||||
if(!empty($activityState)){
|
||||
$activityMap['state']=$activityState;
|
||||
}
|
||||
$applyModel = new \app\api\model\wdsxh\activity\ActivityApply();
|
||||
$count = $applyModel->hasWhere('activity',$activityMap)->where($where)->count();
|
||||
$list = $applyModel->hasWhere('activity',$activityMap)->page($page,$limit)->where($where)->order('id desc')->select();
|
||||
$activityOrderModel = new Order();
|
||||
|
||||
foreach ($list as $k=>&$v) {
|
||||
$v->pay_state = $v->state;
|
||||
$activityObj = $this->model->get($v->activity_id);
|
||||
$orderObj = $activityOrderModel
|
||||
->where('activity_id',$v->activity_id)
|
||||
->where('apply_id',$v->id)
|
||||
->where('wechat_id',$v->wechat_id)
|
||||
->where('member_id',$v->member_id)
|
||||
->order('id desc')
|
||||
->limit(1)
|
||||
->find();
|
||||
$v->order_no = $orderObj ? $orderObj['order_no'] : '';
|
||||
$v->name = $activityObj['name'];
|
||||
$images = explode(',',$activityObj['images']);
|
||||
$v->images = $images[0];
|
||||
$v->week = $this->getTimeWeek($activityObj['start_time']);
|
||||
$v->start_time = date('m/d H:i',$activityObj['start_time']);
|
||||
$v->address = $activityObj->address;
|
||||
$v->fees = $orderObj ? $orderObj['pay_amount'] : '';
|
||||
$v->organizing_method = $activityObj['organizing_method'];
|
||||
$v->activity_state = $activityObj['state'];
|
||||
$v->refund = $activityObj['refund'];
|
||||
$v->url = $activityObj['url'];
|
||||
$v->is_verifying = $activityObj['is_verifying'];
|
||||
$v->verification_method = $activityObj['verification_method'];
|
||||
|
||||
$v->hidden(['wechat_id','member_id','createtime','state']);
|
||||
unset($orderObj);
|
||||
unset($activityObj);
|
||||
}
|
||||
$this->success('请求成功',['total'=>$count,'data'=>$list]);
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 申请退款
|
||||
* time: 2024-3-11 16:38
|
||||
* */
|
||||
public function apply_refund()
|
||||
{
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->post();
|
||||
$result = $this->validate($param,'app\api\validate\wdsxh\activity\Refund.apply_refund');
|
||||
if(true !== $result){
|
||||
// 验证失败 输出错误信息
|
||||
$this->error($result);
|
||||
}
|
||||
|
||||
$activityObj = $this->model->get($param['activity_id']);
|
||||
if(!$activityObj){
|
||||
$this->error('活动信息不存在');
|
||||
}
|
||||
if ($activityObj['refund'] == 0) {
|
||||
$this->error('此活动无法退款');
|
||||
}
|
||||
if ($activityObj && $activityObj['state'] == '2') {
|
||||
$this->error('活动进行中,无法退款');
|
||||
}
|
||||
if ($activityObj && $activityObj['state'] == '3') {
|
||||
$this->error('活动已结束,无法退款');
|
||||
}
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
|
||||
$refundModel = new Refund();
|
||||
$refundObj = $refundModel->where('activity_id',$param['activity_id'])
|
||||
->where('apply_id',$param['apply_id'])
|
||||
->find();
|
||||
if ($refundObj && $refundObj['wechat_id'] != $wechat_id) {
|
||||
$this->error('不是此用户下的活动,无法退款');
|
||||
}
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())->get($param['apply_id']);
|
||||
$orderObj = (new Order())->where('activity_id',$param['activity_id'])
|
||||
->where('apply_id',$param['apply_id'])
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('member_id',$activityApplyObj['member_id'])
|
||||
->where('paid','2')
|
||||
->order('id desc')
|
||||
->limit(1)
|
||||
->find();
|
||||
if (!$orderObj) {
|
||||
$this->error('订单支付信息不存在');
|
||||
}
|
||||
if($orderObj['pay_amount'] == 0.00){
|
||||
$this->error('订单0元,无法退款');
|
||||
}
|
||||
|
||||
if ($refundObj && $refundObj['state'] == '1') {
|
||||
$this->error('已申请退款,请勿重复提交');
|
||||
}
|
||||
$applyObj = (new \app\api\model\wdsxh\activity\ActivityApply())->get($param['apply_id']);
|
||||
|
||||
if ($refundObj) {
|
||||
Db::startTrans();
|
||||
try{
|
||||
$refundObj->state = '1';
|
||||
$refundObj->reject = '';
|
||||
$refundObj->save();
|
||||
$applyObj->state = '3';
|
||||
$applyObj->save();
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('提交成功');
|
||||
} else {
|
||||
Db::startTrans();
|
||||
try{
|
||||
$refund_data = array(
|
||||
'activity_id'=> $param['activity_id'],
|
||||
'apply_id'=> $param['apply_id'],
|
||||
'wechat_id' => $activityApplyObj['wechat_id'],
|
||||
'member_id'=>$activityApplyObj['member_id'],
|
||||
'order_id'=>$orderObj['id'],
|
||||
);
|
||||
$refundModel->data($refund_data);
|
||||
$refundModel->allowField(true)->save();
|
||||
$applyObj->state = '3';
|
||||
$applyObj->save();
|
||||
// 提交事务
|
||||
Db::commit();
|
||||
} catch (\Exception $e) {
|
||||
// 回滚事务
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('提交成功');
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 参会凭证
|
||||
* time: 2024-3-130 9:46
|
||||
* */
|
||||
public function attendance_voucher()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->get('activity_id');
|
||||
$activityObj = $this->model
|
||||
->where('id',$id)
|
||||
->field('id,name activity_name,
|
||||
address')
|
||||
->find();
|
||||
|
||||
if (!$activityObj) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityArray = $activityObj->toArray();
|
||||
$memberObj = (new Member())->where('wechat_id',$wechat_id)
|
||||
->field('name member_name,avatar member_avatar,mobile,
|
||||
type,member_level_name,type,company_name,organize_name')
|
||||
->find();
|
||||
if ($memberObj) {
|
||||
$memberObj->member_avatar = wdsxh_full_url($memberObj->member_avatar);
|
||||
$memberArray = $memberObj->toArray();
|
||||
$data = array_merge($activityArray,$memberArray);
|
||||
} else {
|
||||
$memberObj = (new UserWechat())->where('id',$wechat_id)
|
||||
->field('nickname member_name,avatar member_avatar,mobile')
|
||||
->find();
|
||||
|
||||
|
||||
$memberObj->member_avatar = wdsxh_full_url($memberObj->member_avatar);
|
||||
$memberObj['member_level_name'] = '普通用户';
|
||||
$memberObj['company_name'] = '';
|
||||
$memberObj['organize_name'] = '';
|
||||
$memberArray = $memberObj->toArray();
|
||||
$data = array_merge($activityArray,$memberArray);
|
||||
}
|
||||
|
||||
|
||||
$data['wechat_id'] = $wechat_id;
|
||||
|
||||
$this->success('请求成功',$data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 更新活动状态
|
||||
* Create on 2025/1/20 15:22
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function update_activity_state()
|
||||
{
|
||||
$now = time();
|
||||
// 更新为进行中状态
|
||||
$applyData = $this->model->where('state','1')->where('apply_time','elt',$now)->column('id');
|
||||
if (!empty($applyData)) {
|
||||
$this->model->where('id','in',$applyData)->update(['state'=>'2']);
|
||||
}
|
||||
// 更新为已结束状态(遍历更新以触发 afterUpdate 事件)
|
||||
$endList = $this->model
|
||||
->where('end_time','elt',$now)
|
||||
->where('state','<>','3')
|
||||
->select();
|
||||
if (!empty($endList)) {
|
||||
foreach ($endList as $activity) {
|
||||
$activity->state = '3';
|
||||
$activity->save();
|
||||
}
|
||||
}
|
||||
|
||||
$this->success('请求成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 接龙配置
|
||||
* Create on 2025/8/8 10:04
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function activity_config()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->get('id');
|
||||
if (empty($id)) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$activityObj = $this->model->get($id);
|
||||
if (!$activityObj) {
|
||||
$this->error('活动数据不存在');
|
||||
}
|
||||
$is_status = $activityObj['activity_auth'];
|
||||
|
||||
if ($is_status == 2){
|
||||
if ($this->auth->isLogin()) {
|
||||
$user_id = $this->auth->id;
|
||||
$wechat_id = (new Wechat())->where('user_id',$user_id)->value('id');
|
||||
$current_date = date('Y-m-d',time());
|
||||
$member = (new Member())->where('wechat_id',$wechat_id)->where('expire_time','>=',$current_date)->find();
|
||||
if ($member) {
|
||||
$is_status = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
$this->success('请求成功',['show_status'=>$is_status]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
536
application/api/controller/wdsxh/activity/ActivityApply.php
Normal file
536
application/api/controller/wdsxh/activity/ActivityApply.php
Normal file
@@ -0,0 +1,536 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
/**
|
||||
* Class ActivityApply
|
||||
* Desc 活动报名控制器
|
||||
* Create on 2024/3/11 17:57
|
||||
* Create by wangyafang
|
||||
*/
|
||||
|
||||
namespace app\api\controller\wdsxh\activity;
|
||||
|
||||
|
||||
use addons\wdsxh\library\Wxapp;
|
||||
use app\api\model\wdsxh\activity\ActivityApplyRecord;
|
||||
use app\api\model\wdsxh\activity\Order;
|
||||
use app\api\model\wdsxh\activity\Refund;
|
||||
use app\api\model\wdsxh\member\Member;
|
||||
use app\api\model\wdsxh\UserWechat;
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class ActivityApply extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['index','notify'];
|
||||
protected $noNeedRight = ['*'];
|
||||
protected $model = null;
|
||||
protected $configObj = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\api\model\wdsxh\activity\ActivityApply();
|
||||
$this->configObj = (new \app\admin\model\wdsxh\Config())->where('id',1)->find();
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 活动取消
|
||||
* time: 2023-3-30 10:20
|
||||
* */
|
||||
public function cancel()
|
||||
{
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->post('id');
|
||||
$where = array(
|
||||
'id'=>$id,
|
||||
);
|
||||
$activityApplyObj = $this->model->where($where)->find();
|
||||
if (!$activityApplyObj) {
|
||||
$this->error('活动已取消');
|
||||
}
|
||||
$activityObj = (new \app\api\model\wdsxh\activity\Activity())->where('id',$activityApplyObj['activity_id'])->find();
|
||||
if ($activityObj && $activityObj['state'] == '2') {
|
||||
$this->error('活动进行中,无法取消');
|
||||
}
|
||||
if ($activityObj && $activityObj['state'] == '3') {
|
||||
$this->error('活动已结束,无法取消');
|
||||
}
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
if ($wechat_id != $activityApplyObj['wechat_id']) {
|
||||
$this->error('不是本人,无法取消');
|
||||
}
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = $activityApplyObj->delete();
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if(false === $result){
|
||||
$this->error($activityApplyObj->getError());
|
||||
}
|
||||
|
||||
$this->success('取消成功');
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 活动提交
|
||||
* time: 2023-3-11 18:00
|
||||
* */
|
||||
public function submit()
|
||||
{
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->post();
|
||||
|
||||
$fixed_data = array();
|
||||
if (isset($_POST['data']) && !empty($_POST['data'])) {
|
||||
$custom_content = $_POST['data'];
|
||||
$param['data'] = json_decode($custom_content, true);
|
||||
$fixed_data = $this->handle_custom_data($param['data']);
|
||||
}
|
||||
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$result = $this->validate($param,'app\api\validate\wdsxh\activity\ActivityApply.apply');
|
||||
if(true !== $result){
|
||||
// 验证失败 输出错误信息
|
||||
$this->error($result);
|
||||
}
|
||||
$activityObj = (new \app\api\model\wdsxh\activity\Activity())->where('id',$param['activity_id'])->find();
|
||||
$current_date = date('Y-m-d',time());
|
||||
$memberObj = (new Member())->where('wechat_id',$wechat_id)
|
||||
->where('expire_time','>=',$current_date)
|
||||
->find();
|
||||
if ($activityObj['non_member_registration_status'] == '2' && !$memberObj) {
|
||||
$this->error('只有会员才能报名');
|
||||
}
|
||||
if (!$activityObj) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
if ($activityObj['apply_time'] < time()) {
|
||||
$this->error('活动报名时间已过,无法报名');
|
||||
}
|
||||
if ($activityObj['state'] == '2') {
|
||||
$this->error('活动进行中,无法报名');
|
||||
}
|
||||
if ($activityObj['state'] == '3') {
|
||||
$this->error('活动已结束,无法报名');
|
||||
}
|
||||
$applyObj = $this->model->where(array('wechat_id'=>$wechat_id,'activity_id'=>$param['activity_id']))
|
||||
->where('state','<>','4')
|
||||
->order('id desc')->find();
|
||||
if($applyObj && $applyObj['state'] == '2'){
|
||||
$this->error('你已报名过了,不能重复报名');
|
||||
}
|
||||
if($applyObj && $applyObj['state'] == '3'){
|
||||
$this->error('你的报名信息正在申请退款处理,暂时无法报名');
|
||||
}
|
||||
|
||||
if (!empty($activityObj['apply_limit_number']) && $activityObj['apply_limit_number'] > 0) {
|
||||
$apply_count = $this->model->where('activity_id', $param['activity_id'])
|
||||
->where('state',2)
|
||||
->count();
|
||||
if ($apply_count >= $activityObj['apply_limit_number']) {
|
||||
$this->error('活动报名人数已满,无法报名');
|
||||
}
|
||||
}
|
||||
|
||||
//is_verifying 活动是否核销:1=是,2=否
|
||||
//is_sign_in 签到:1=已签到,2=未签到,3=无需签到
|
||||
$is_sign_in = $activityObj['is_verifying'] == '1' ? '2' : '3';
|
||||
if ($applyObj && ($applyObj['state'] == 1 || $applyObj['state'] == 4)) {//已提交报名,但未付款
|
||||
if ($activityObj['apply_field_state'] == 1 && empty($applyObj['field_data'])) {
|
||||
$this->error('请填写报名信息');
|
||||
}
|
||||
$apply_id = $applyObj->id;
|
||||
} else {//第一次报名
|
||||
$apply_data = array(
|
||||
'activity_id'=> $param['activity_id'],
|
||||
'wechat_id' => $wechat_id,
|
||||
'member_id'=>$memberObj ? $memberObj->id : 0,
|
||||
'is_sign_in'=>$is_sign_in,
|
||||
);
|
||||
if ($activityObj['apply_field_state'] == 1
|
||||
&& (!isset($_POST['data']) || empty($_POST['data']))
|
||||
) {
|
||||
$this->error('请填写报名信息');
|
||||
}
|
||||
if (isset($_POST['data']) && !empty($_POST['data'])) {
|
||||
$apply_data['field_data'] = $_POST['data'];
|
||||
}
|
||||
$apply_data = array_merge($apply_data, $fixed_data);
|
||||
|
||||
$apply_data['state'] = $activityObj['fees'] == 0.00 ? 2 : 1;
|
||||
$this->model->data($apply_data);
|
||||
$applyObj = $this->model->allowField(true)->save();
|
||||
$apply_id = $this->model->id;
|
||||
}
|
||||
|
||||
if ($applyObj) {
|
||||
$orderModel = new Order();
|
||||
$activityOrderObj = $orderModel
|
||||
->where(array('wechat_id'=>$wechat_id,'activity_id'=>$param['activity_id']))
|
||||
->where('paid','1')
|
||||
->find();
|
||||
$channel = $this->request->header('channel');
|
||||
$paid = $activityObj['fees'] == 0.00 ? 2 : 1;
|
||||
if ($activityOrderObj) {
|
||||
$activityOrderObj->order_no = wdsxh_create_order();
|
||||
$activityOrderObj->pay_amount = $activityObj['fees'];
|
||||
$activityOrderObj->channel = $channel;
|
||||
$activityOrderObj->paid = $paid;
|
||||
if ($paid == 2) {
|
||||
$activityOrderObj->pay_time = time();
|
||||
$activityOrderObj->complete_time = date('Y-m-d H:i:s',time());
|
||||
}
|
||||
$activityOrderObj->save();
|
||||
} else {
|
||||
$order_data = array(
|
||||
'activity_id'=> $param['activity_id'],
|
||||
'apply_id'=> $apply_id,
|
||||
'wechat_id' => $wechat_id,
|
||||
'member_id'=>$memberObj ? $memberObj->id : 0,
|
||||
'order_no'=> wdsxh_create_order(),
|
||||
'pay_amount'=>$activityObj['fees'],
|
||||
'channel'=>$channel,
|
||||
'paid'=>$paid,
|
||||
);
|
||||
if ($paid == 2) {
|
||||
$order_data['pay_time'] = time();
|
||||
$order_data['complete_time'] = date('Y-m-d H:i:s',time());
|
||||
}
|
||||
$orderModel->data($order_data);
|
||||
$orderModel->allowField(true)->save();
|
||||
$activityOrderObj = $orderModel;
|
||||
}
|
||||
$applyObj = $this->model->get($apply_id);
|
||||
$applyObj->is_sign_in = $is_sign_in;
|
||||
$applyObj->save();
|
||||
if($paid == 2){//不付钱
|
||||
$avtivity_apply_record_data = array(
|
||||
'activity_id'=> $param['activity_id'],
|
||||
'wechat_id' => $wechat_id,
|
||||
'member_id'=>$memberObj ? $memberObj->id : 0,
|
||||
);
|
||||
$avtivityApplyRecordModel = new ActivityApplyRecord();
|
||||
$avtivityApplyRecordModel->data($avtivity_apply_record_data);
|
||||
$avtivityApplyRecordModel->allowField(true)->save();
|
||||
|
||||
$this->zero_pay($activityObj , $wechat_id , $channel);
|
||||
} else{//微信支付
|
||||
$this->wx_pay($activityOrderObj , $wechat_id , $channel);
|
||||
}
|
||||
} else {
|
||||
$this->error('创建订单失败');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
private function zero_pay($activityObj = [] , $wechat_id = '' ,$channel = 1)
|
||||
{
|
||||
$address = $activityObj['organizing_method'] == '1' ? $activityObj['url'] : $activityObj['address'];
|
||||
if ($channel == 1) {
|
||||
//活动报名成功通知
|
||||
try{
|
||||
$conf=$this->configObj;
|
||||
$data=[
|
||||
'thing1'=>[
|
||||
'value'=>$activityObj['name'],
|
||||
],
|
||||
'amount3'=>[
|
||||
'value'=>$activityObj['fees'],
|
||||
],
|
||||
'thing6'=>[
|
||||
'value'=>$address,
|
||||
],
|
||||
'date7'=>[
|
||||
'value'=>date('Y年m月d日 H:i',$activityObj['start_time']),
|
||||
],
|
||||
'phone_number8'=>[
|
||||
'value'=>$activityObj['mobile'],
|
||||
]
|
||||
];
|
||||
$result = Wxapp::subscribeMessage($conf['applet_activity_apply'],trim(wdsxh_get_openid($wechat_id,$channel)),'/pagesActivity/index/details?id='.$activityObj['id'],$data);
|
||||
}catch (\think\Exception $e){
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
} else {//todo公众号逻辑
|
||||
|
||||
}
|
||||
|
||||
$this->success('报名成功');
|
||||
}
|
||||
|
||||
private function wx_pay($activityOrderObj = [] , $wechat_id = '' ,$channel = 1)
|
||||
{
|
||||
if ($channel == 1) {//小程序支付
|
||||
try{
|
||||
$openid = wdsxh_get_openid($wechat_id,$channel);
|
||||
$conf=Wxapp::unify('商会活动报名',$activityOrderObj->order_no,$activityOrderObj->pay_amount,$openid,request()->domain().'/api/wdsxh/activity/activity_apply/notify');
|
||||
}catch (Exception $e){
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('报名成功',$conf);
|
||||
} else {//todo 公众号支付
|
||||
try{
|
||||
$openid = wdsxh_get_openid($wechat_id,$channel);
|
||||
$conf=Wxapp::unify_wxofficial('商会活动报名',$activityOrderObj->order_no,$activityOrderObj->pay_amount,$openid,request()->domain().'/api/wdsxh/activity/activity_apply/notify');
|
||||
}catch (Exception $e){
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$this->success('报名成功',$conf);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* desc: 活动支付回调处理
|
||||
* time: 2023-3-11 18:00
|
||||
* */
|
||||
public function notify()
|
||||
{
|
||||
$pay = Wxapp::getPay();
|
||||
$response = $pay->handlePaidNotify(function($message, $fail){
|
||||
$orderObj = Order::where('order_no',$message['out_trade_no'])->find();
|
||||
if (!$orderObj || $orderObj['paid'] == '2') {
|
||||
return true;
|
||||
}
|
||||
if ($message['return_code'] === 'SUCCESS') {
|
||||
if ($message['result_code'] === 'SUCCESS') {
|
||||
$avtivity_apply_record_data = array(
|
||||
'activity_id'=> $orderObj['activity_id'],
|
||||
'wechat_id' => $orderObj['wechat_id'],
|
||||
'member_id'=>$orderObj['member_id'],
|
||||
);
|
||||
$avtivityApplyRecordModel = new ActivityApplyRecord();
|
||||
Db::startTrans();
|
||||
try {
|
||||
$orderObj['pay_time'] = time();
|
||||
$orderObj['paid'] = '2';
|
||||
$orderObj->trade_no = $message['transaction_id'];
|
||||
$orderObj->save();
|
||||
//处理活动报名
|
||||
//todo 活动创建后,会员功能对外功能不可用,非会员无法报名 删除where条件
|
||||
$applyObj = $this->model->where(array('wechat_id'=>$orderObj['wechat_id'],'activity_id'=>$orderObj['activity_id']))
|
||||
->where('state','1')
|
||||
->find();
|
||||
$applyObj->state = '2';
|
||||
$applyObj->save();
|
||||
$avtivityApplyRecordModel->data($avtivity_apply_record_data);
|
||||
$avtivityApplyRecordModel->allowField(true)->save();
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
$activityObj = (new \app\api\model\wdsxh\activity\Activity())->get($orderObj['activity_id']);
|
||||
$address = $activityObj['organizing_method'] == '1' ? $activityObj['url'] : mb_substr($activityObj['address'],0,20);
|
||||
|
||||
|
||||
//活动报名成功通知
|
||||
try{
|
||||
$conf=$this->configObj;
|
||||
$data=[
|
||||
'thing1'=>[
|
||||
'value'=>mb_substr($activityObj['name'],0,20),
|
||||
],
|
||||
'amount3'=>[
|
||||
'value'=>$orderObj['pay_amount'],
|
||||
],
|
||||
'thing6'=>[
|
||||
'value'=>$address,
|
||||
],
|
||||
'date7'=>[
|
||||
'value'=>date('Y年m月d日 H:i',$activityObj['start_time']),
|
||||
],
|
||||
'phone_number8'=>[
|
||||
'value'=>$activityObj['mobile'],
|
||||
]
|
||||
];
|
||||
$result = Wxapp::subscribeMessage($conf['applet_activity_apply'],trim(wdsxh_get_openid($orderObj['wechat_id'],1)),'/pagesActivity/index/details?id='.$orderObj['activity_id'],$data);
|
||||
}catch (\think\Exception $e){
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
} else {
|
||||
return $fail('FAIL');
|
||||
}
|
||||
|
||||
return true;
|
||||
});
|
||||
|
||||
$response->send();
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 删除未支付订单
|
||||
* time: 2023-4-10 11:58
|
||||
* */
|
||||
public function del()
|
||||
{
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$id = $this->request->post('id');
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$where = array(
|
||||
'id'=>$id,
|
||||
'wechat_id'=>$wechat_id,
|
||||
);
|
||||
$activityApplyObj = $this->model->where($where)->find();
|
||||
if (!$activityApplyObj) {
|
||||
$this->error('未支付已取消');
|
||||
}
|
||||
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
if ($wechat_id != $activityApplyObj['wechat_id']) {
|
||||
$this->error('不是本人,无法取消');
|
||||
}
|
||||
|
||||
$activityOrderObj = (new Order())->where('activity_id',$activityApplyObj['activity_id'])
|
||||
->where('apply_id',$id)
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('paid','1')
|
||||
->find();
|
||||
if (!$activityOrderObj) {
|
||||
$this->error('未支付已取消');
|
||||
}
|
||||
$result = false;
|
||||
Db::startTrans();
|
||||
try {
|
||||
$result = $activityApplyObj->delete();
|
||||
$activityOrderObj->delete();
|
||||
Db::commit();
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
Db::rollback();
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
if(false === $result){
|
||||
$this->error($activityApplyObj->getError());
|
||||
}
|
||||
$this->success('删除成功');
|
||||
}
|
||||
|
||||
/*
|
||||
* desc: 报名活动详情
|
||||
* time: 2023-6-29 9:03
|
||||
* */
|
||||
public function details()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
try {
|
||||
$id = $this->request->get('id');
|
||||
$apply_id = $this->request->get('apply_id');
|
||||
$data = (new \app\api\model\wdsxh\activity\Activity())
|
||||
->where('id',$id)
|
||||
->field('id,images,start_time,end_time,name,fees,state activity_state,
|
||||
contacts,mobile,
|
||||
organizing_method,url,address,longitude,latitude,content,
|
||||
refund,
|
||||
apply_time,
|
||||
activity_auth,is_verifying,verification_method,points_status,points')
|
||||
->find();
|
||||
if (!$data) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
if ($data['points_status'] == 2) {
|
||||
unset($data['points']);
|
||||
}
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityObj = (new Order())->where('apply_id',$apply_id)->find();
|
||||
if (!$activityObj) {
|
||||
$this->error('活动订单不存在');
|
||||
}
|
||||
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('id',$activityObj['apply_id'])
|
||||
->where('activity_id',$id)
|
||||
->find();
|
||||
if (!$activityApplyObj) {
|
||||
$this->error('报名信息不存在');
|
||||
}
|
||||
$data['pay_state'] = $activityApplyObj['state'];
|
||||
$data['apply_id'] = $apply_id;
|
||||
$activityRefundObj = (new Refund())
|
||||
->where('apply_id',$activityObj['apply_id'])
|
||||
->where('activity_id',$id)
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('state','3')
|
||||
->order('id desc')
|
||||
->find();
|
||||
|
||||
$data['reject'] = $activityRefundObj ? $activityRefundObj['reject'] : '';
|
||||
|
||||
$activityApplyModel = new \app\api\model\wdsxh\activity\ActivityApply();
|
||||
$data['apply_count'] = $activityApplyModel->where('activity_id', $id)->where('state',2)->count();
|
||||
$apply_list = $activityApplyModel->where('activity_id', $id)
|
||||
->where('state',2)
|
||||
->alias('apply')
|
||||
->order('apply.createtime desc')
|
||||
->join('wdsxh_user_wechat member', 'member.id = apply.wechat_id')
|
||||
->field('member.avatar member_avatar')
|
||||
->limit(10)
|
||||
->select();
|
||||
if (!empty($apply_list)) {
|
||||
foreach ($apply_list as &$v) {
|
||||
$v->member_avatar = wdsxh_full_url($v->member_avatar);
|
||||
}
|
||||
}
|
||||
$data['apply_list'] = $apply_list;
|
||||
|
||||
|
||||
$applyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('id',$apply_id)
|
||||
->where('activity_id',$id)
|
||||
->where('wechat_id',$wechat_id)
|
||||
->find();
|
||||
$data['apply_status'] = $applyObj['state'] == 2 ? 1 : 2;
|
||||
|
||||
$data['is_sign_in'] = $applyObj['is_sign_in'];
|
||||
|
||||
$this->success('请求成功',$data);
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private function handle_custom_data($data)
|
||||
{
|
||||
$custom_field = array('name','mobile');
|
||||
|
||||
$result = array();
|
||||
foreach ($data as $v) {
|
||||
if (in_array($v['field'], $custom_field)) {
|
||||
$result[$v['field']] = $v['value'];
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力中小企业发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdadmin.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Wdadmin系统产品软件并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.wdadmin.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller\wdsxh\activity;
|
||||
|
||||
use app\api\model\wdsxh\UserWechat;
|
||||
use app\common\controller\Api;
|
||||
|
||||
class ActivityElectronicCertificate extends Api
|
||||
{
|
||||
protected $noNeedLogin = [''];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
protected $model = null;
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
$this->model = new \app\admin\model\wdsxh\activity\ActivityElectronicCertificate();
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 电子证书数据
|
||||
* Create on 2024/4/9 17:52
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function index(){
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$activity_id = $this->request->get('id');
|
||||
if (empty($activity_id)) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$activityObj = (new \app\api\model\wdsxh\activity\Activity())->get($activity_id);
|
||||
if (!$activityObj) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
if ($activityObj['end_time'] > time()) {
|
||||
$this->error('活动未结束');
|
||||
}
|
||||
if ($activityObj['state'] != '3') {
|
||||
$this->error('活动未结束');
|
||||
}
|
||||
$apply_id = $this->request->get('apply_id');
|
||||
if (empty($apply_id)) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('id',$apply_id)
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('activity_id',$activity_id)
|
||||
->find();
|
||||
if(!$activityApplyObj){
|
||||
$this->error('报名信息不存在');
|
||||
}
|
||||
|
||||
if ($activityObj['certificate_enabled'] == 1 && !empty($activityObj['certificate_data'])) {
|
||||
$data = $activityObj['certificate_data'];
|
||||
} else {
|
||||
$data = $this->model->where('id',1)->value('data');
|
||||
}
|
||||
|
||||
$data = json_decode($data,true);
|
||||
$data['bg']['img'] = wdsxh_full_url($data['bg']['img']);
|
||||
if (!empty($activityApplyObj['name'])) {
|
||||
$participant = $activityApplyObj['name'];
|
||||
} else {
|
||||
$participant = (new UserWechat())->where('id', $activityApplyObj['wechat_id'])->value('nickname');
|
||||
}
|
||||
|
||||
$result_data = array(
|
||||
'activity_name'=>$activityObj['name'],
|
||||
'participant'=>$participant,
|
||||
'time'=>date('Y年m月d日',$activityObj['start_time']),
|
||||
'data'=>$data,
|
||||
);
|
||||
|
||||
$this->success('请求成功',$result_data);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
namespace app\api\controller\wdsxh\activity;
|
||||
|
||||
use app\common\controller\Api;
|
||||
|
||||
/**
|
||||
* Class JoinConfig
|
||||
* Desc 入会申请控制器
|
||||
* Create on 2024/3/7 9:08
|
||||
* Create by wangyafang
|
||||
*/
|
||||
class ActivityFieldset extends Api
|
||||
{
|
||||
protected $noNeedLogin = ['*'];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
/**
|
||||
* Desc 报名字段
|
||||
* Create on 2025/8/11 下午5:00
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function field()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$activity_id = $this->request->get('id');
|
||||
if (empty($activity_id)) {
|
||||
$this->error('参数错误');
|
||||
}
|
||||
$activityFieldsetObj = (new \app\admin\model\wdsxh\activity\ActivityFieldset())
|
||||
->where('activity_id',$activity_id)
|
||||
->find();
|
||||
if ($activityFieldsetObj) {
|
||||
$fieldset = json_decode($activityFieldsetObj['json'],true);
|
||||
} else {
|
||||
$fieldset = array(
|
||||
0 =>
|
||||
array(
|
||||
'show' => '1',
|
||||
'required' => '1',
|
||||
'type' => 'text',
|
||||
'label' => '姓名',
|
||||
'field' => 'name',
|
||||
'option' => '请输入姓名',
|
||||
),
|
||||
1 =>
|
||||
array(
|
||||
'show' => '1',
|
||||
'required' => '1',
|
||||
'type' => 'number',
|
||||
'label' => '手机号',
|
||||
'field' => 'mobile',
|
||||
'option' => '请输入你的手机号',
|
||||
),
|
||||
);;
|
||||
}
|
||||
|
||||
foreach ($fieldset as $k=>$v) {
|
||||
$fieldset[$k]['value'] = '';
|
||||
}
|
||||
|
||||
$this->success('请求成功',$fieldset);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
318
application/api/controller/wdsxh/activity/Verifying.php
Normal file
318
application/api/controller/wdsxh/activity/Verifying.php
Normal file
@@ -0,0 +1,318 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | 麦沃德科技赋能开发者,助力商协会发展
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2017~2024 www.wdsxh.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | 沃德商协会系统并不是自由软件,不加密,并不代表开源,未经许可不可自由转售和商用
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: MY WORLD Team <bd@maiwd.cn> www.maiwd.cn
|
||||
// +----------------------------------------------------------------------
|
||||
/**
|
||||
* Class Verifying
|
||||
* Desc 活动核销
|
||||
* Create on 2024/3/15 16:27
|
||||
* Create by wangyafang
|
||||
*/
|
||||
|
||||
namespace app\api\controller\wdsxh\activity;
|
||||
|
||||
|
||||
use addons\wdsxh\library\Encryptor;
|
||||
use app\api\model\wdsxh\UserWechat;
|
||||
use app\common\controller\Api;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
use think\exception\PDOException;
|
||||
use think\exception\ValidateException;
|
||||
|
||||
class Verifying extends Api
|
||||
{
|
||||
protected $noNeedLogin = [''];
|
||||
protected $noNeedRight = ['*'];
|
||||
|
||||
public function _initialize()
|
||||
{
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 核销活动列表
|
||||
* Create on 2024/3/14 17:09
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function activity_list()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$where[] = ['exp',Db::raw("FIND_IN_SET($wechat_id,verifying_wechat_ids)")];
|
||||
|
||||
$activityModel = new \app\api\model\wdsxh\activity\Activity();
|
||||
|
||||
$page = isset($param['page']) ? $param['page'] : '';
|
||||
$limit = isset($param['limit']) ? $param['limit'] : 10;
|
||||
|
||||
$count = $activityModel->where($where)->count();
|
||||
|
||||
$data = $activityModel
|
||||
->where($where)
|
||||
->page($page,$limit)
|
||||
->field('id,name,start_time,address,images,organizing_method')
|
||||
->order('id desc')
|
||||
->select();
|
||||
|
||||
$activityController = new Activity();
|
||||
foreach ($data as $k=>&$v) {
|
||||
$v->week = $activityController->getTimeWeek($v['start_time']);
|
||||
$v->start_time = date('m/d H:i',$v->start_time);
|
||||
$images = explode(',',$v->images);
|
||||
$v->images = $images[0];
|
||||
}
|
||||
|
||||
$this->success('请求成功',['total'=>$count,'data'=>$data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 扫码核销
|
||||
* @author wangyafang
|
||||
* @date 2024/3/15 16:46
|
||||
*/
|
||||
public function verifying() {
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$wechat_id = $this->request->post('wechat_id');
|
||||
$activity_id = $this->request->post('activity_id');
|
||||
$activityObj = (new \app\api\model\wdsxh\activity\Activity())->get($activity_id);
|
||||
if (!$activityObj) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
|
||||
if ($activityObj['state'] == '3') {
|
||||
$this->error('活动已结束,无法核销');
|
||||
}
|
||||
|
||||
if ($activityObj['is_verifying'] == '1') {
|
||||
$user_id = $this->auth->id;
|
||||
$admin_wechat_id = (new UserWechat())->where('user_id',$user_id)->value('id');
|
||||
$verifying_wechat_ids_array = explode(',',$activityObj['verifying_wechat_ids']);
|
||||
if (!in_array($admin_wechat_id,$verifying_wechat_ids_array)) {
|
||||
$this->error('不是核销管理员,请在后台活动设置为核销管理员');
|
||||
}
|
||||
} else {
|
||||
$this->error('此活动不用核销');
|
||||
}
|
||||
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('activity_id',$activity_id)
|
||||
->where('state','2')
|
||||
->find();
|
||||
if (!$activityApplyObj) {
|
||||
$this->error('没有找到报名信息或者未付款,无法核销');
|
||||
}
|
||||
if ($activityApplyObj['is_sign_in'] == '1') {
|
||||
$this->error('已核销');
|
||||
}
|
||||
$activityApplyObj->is_sign_in = '1';
|
||||
$activityApplyObj->save();
|
||||
|
||||
|
||||
$this->success('核销成功');
|
||||
}
|
||||
|
||||
/**
|
||||
* @notes 核销会员列表
|
||||
* @author wangyafang
|
||||
* @date 2024/3/15 16:57
|
||||
*/
|
||||
public function verifying_member_list()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$param = $this->request->get();
|
||||
$where = [];
|
||||
$where['apply.activity_id'] = array('eq',$param['activity_id']);
|
||||
$where['apply.is_sign_in'] = array('eq',$param['is_sign_in']);
|
||||
|
||||
$activityApplyModel = new \app\api\model\wdsxh\activity\ActivityApply();
|
||||
$page = isset($param['page']) ? $param['page'] : '';
|
||||
$limit = isset($param['limit']) ? $param['limit'] : 10;
|
||||
$count = $activityApplyModel->alias('apply')->where($where)->count();
|
||||
$order = 'apply.id desc';
|
||||
|
||||
//todo 活动创建后,会员功能对外功能不可用,非会员无法报名
|
||||
$data = $activityApplyModel
|
||||
->alias('apply')
|
||||
->where($where)
|
||||
->page($page,$limit)
|
||||
->field('apply.is_sign_in,wechat.nickname,wechat.avatar')
|
||||
->join('wdsxh_user_wechat wechat','apply.wechat_id = wechat.id')
|
||||
->order($order)
|
||||
->select();
|
||||
foreach ($data as &$v) {
|
||||
$v->avatar = wdsxh_full_url($v->avatar);
|
||||
}
|
||||
|
||||
$this->success('请求成功',['total'=>$count,'data'=>$data]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 自动核销
|
||||
* Create on 2025/3/8 9:34
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function self_service_check_in()
|
||||
{
|
||||
if(!$this->request->isPost()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$validate_value = $this->request->post('validate_value');
|
||||
$activity_id = $this->request->post('activity_id');
|
||||
$from_lng = $this->request->post('lng');
|
||||
$from_lat = $this->request->post('lat');
|
||||
if (empty($validate_value)) {
|
||||
$this->error('validate_value参数不能为空');
|
||||
}
|
||||
if (empty($activity_id)) {
|
||||
$this->error('activity_id参数不能为空');
|
||||
}
|
||||
if (empty($from_lng)) {
|
||||
$this->error('纬度不能为空');
|
||||
}
|
||||
if (empty($from_lat)) {
|
||||
$this->error('经度不能为空');
|
||||
}
|
||||
|
||||
try {
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$activityObj = (new \app\api\model\wdsxh\activity\Activity())->get($activity_id);
|
||||
if (!$activityObj) {
|
||||
$this->error('活动不存在');
|
||||
}
|
||||
if ($activityObj['state'] == '3') {
|
||||
$this->error('活动已结束,无法核销');
|
||||
}
|
||||
|
||||
if ($activityObj['is_verifying'] == '2') {
|
||||
$this->error('此活动不用核销');
|
||||
}
|
||||
|
||||
if ($activityObj['verification_method'] != 1) {
|
||||
$this->error('核销方式不是自助签到,无法核销');
|
||||
}
|
||||
|
||||
$activityApplyObj = (new \app\api\model\wdsxh\activity\ActivityApply())
|
||||
->where('wechat_id',$wechat_id)
|
||||
->where('activity_id',$activity_id)
|
||||
->where('state','2')
|
||||
->find();
|
||||
if (!$activityApplyObj) {
|
||||
$this->error('没有找到报名信息或者未付款,无法核销');
|
||||
}
|
||||
if ($activityApplyObj['is_sign_in'] == '1') {
|
||||
$this->error('已核销');
|
||||
}
|
||||
$token_key = config('token.key');
|
||||
$encryptor = new Encryptor(substr($token_key,0,16),substr($token_key,16));
|
||||
if ($encryptor->encrypt($activity_id) != $validate_value) {// 验证失败,返回错误
|
||||
$this->error('签到失败,请检查签到二维码是否正确');
|
||||
}
|
||||
$distance = $this->calculateDistance($from_lat,$from_lng,$activityObj['latitude'],$activityObj['longitude']);
|
||||
if ($distance > 1000) {
|
||||
$this->error('请在1000米内核销');
|
||||
}
|
||||
$activityApplyObj->is_sign_in = '1';
|
||||
$activityApplyObj->save();
|
||||
|
||||
|
||||
$this->success('核销成功');
|
||||
} catch (ValidateException|PDOException|Exception $e) {
|
||||
$this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 计算距离
|
||||
* Create on 2025/3/8 9:55
|
||||
* Create by wangyafang
|
||||
*/
|
||||
private function calculateDistance($lat1, $lon1, $lat2, $lon2) {
|
||||
$lat1 = floatval($lat1);
|
||||
$lon1 = floatval($lon1);
|
||||
$lat2 = floatval($lat2);
|
||||
$lon2 = floatval($lon2);
|
||||
|
||||
// 验证经度和纬度是否在有效范围内
|
||||
if ($lon1 < -180 || $lon1 > 180) {
|
||||
$this->error('经度值不在有效范围内');
|
||||
}
|
||||
if ($lat1 < -90 || $lat1 > 90) {
|
||||
$this->error('纬度值不在有效范围内');
|
||||
}
|
||||
|
||||
if ($lon2 < -180 || $lon2 > 180) {
|
||||
$this->error('经度值不在有效范围内');
|
||||
}
|
||||
if ($lat2 < -90 || $lat2 > 90) {
|
||||
$this->error('纬度值不在有效范围内');
|
||||
}
|
||||
|
||||
// 地球半径(单位:米)
|
||||
$earthRadius = 6371000;
|
||||
|
||||
// 将纬度、经度从度转换为弧度
|
||||
$latFrom = deg2rad($lat1);
|
||||
$lonFrom = deg2rad($lon1);
|
||||
$latTo = deg2rad($lat2);
|
||||
$lonTo = deg2rad($lon2);
|
||||
|
||||
// 计算纬度和经度的差值
|
||||
$latDelta = $latTo - $latFrom;
|
||||
$lonDelta = $lonTo - $lonFrom;
|
||||
|
||||
// 使用 Haversine 公式计算距离
|
||||
$angle = 2 * asin(sqrt(
|
||||
pow(sin($latDelta / 2), 2) +
|
||||
cos($latFrom) * cos($latTo) * pow(sin($lonDelta / 2), 2)
|
||||
));
|
||||
$distance = $angle * $earthRadius;
|
||||
|
||||
return $distance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Desc 获取核销加密数据
|
||||
* Create on 2025/4/17 9:58
|
||||
* Create by wangyafang
|
||||
*/
|
||||
public function get_decrypt_data()
|
||||
{
|
||||
if(!$this->request->isGet()) {
|
||||
$this->error('请求类型错误');
|
||||
}
|
||||
$validate_value = $this->request->get('validate_value');
|
||||
|
||||
if (empty($validate_value)) {
|
||||
$this->error('validate_value参数不能为空');
|
||||
}
|
||||
$token_key = config('token.key');
|
||||
$encryptor = new Encryptor(substr($token_key,0,16),substr($token_key,16));
|
||||
$activity_id = $validate_value = $encryptor->decrypt($validate_value);
|
||||
|
||||
$wechat_id = (new UserWechat())->where('user_id',$this->auth->id)->value('id');
|
||||
$apply_id = (new \app\api\model\wdsxh\activity\ActivityApply())->where('activity_id',$activity_id)->where('wechat_id',$wechat_id)->value('id');
|
||||
if (!$apply_id) {
|
||||
$apply_id = '';
|
||||
}
|
||||
$this->success('请求成功',array('activity_id'=>$validate_value,'apply_id'=>$apply_id));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user