作者 杨育虎

online push

要显示太多修改。

为保证性能只显示 5 of 5+ 个文件。

<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 11:30
*/
namespace api\index\controller;
use api\index\model\ActivityModel;
use api\index\model\ActivityNewsModel;
use api\index\model\ActivityType;
use api\index\model\ActivityTypeModel;
use api\index\model\JoinModel;
use api\index\model\PositionProvinceModel;
use api\index\model\SlideItemModel;
use api\index\model\UserModel;
use api\index\model\VolunteerModel;
use cmf\controller\RestBaseController;
use Dompdf\Frame\Factory;
use EasyWeChatComposer\EasyWeChat;
use Hooklife\ThinkphpWechat\Wechat;
use Magicfier\Image;
use think\Url;
use traits\think\Instance;
use wxapp\Code;
/**
* @title 首页
* @description 首页
*/
class IndexController extends RestBaseController
{
public function _initialize()
{
$user_id = $this->getUserId();
$userModel = new UserModel();
$user = $userModel->where(array('id'=>$user_id))->find();
if($user['user_status'] == 0){
$this->error(['code'=>40005,'msg'=>'您已被列入黑名单,请联系管理员!']);
}
}
/**
* @title 首页
* @description 首页
* @author Xiaogang Wang
* @url /index/index/index
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:volunteer_page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:volunteer_pageNum type:int require:0 other: desc:活动显示数量(默认3)
* @param name:activity_page type:int require:0 other: desc:活动当前页(0为第一页)(默认0)
* @param name:activity_pageNum type:int require:0 other: desc:活动显示数量(默认4)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 level:星级 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
* @return news:活动新闻@
* @news id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
* @return volunteer_page:志愿者下一页
* @return activity_page:活动下一页
*/
public function index(){
$param = $this->request->param();
$volunteer_page = $param['volunteer_page'] ? $param['volunteer_page'] : 0;//当前页数下标
$volunteer_pageNum = $param['volunteer_pageNum'] ? $param['volunteer_pageNum'] : 3;//每页显示几条数据
$activity_page = $param['activity_page'] ? $param['activity_page'] : 0;//当前页数下标
$activity_pageNum = $param['activity_pageNum'] ? $param['activity_pageNum'] : 4;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
$volunteer = $volunteerModel->selectData($volunteer_page,$volunteer_pageNum,array('status'=>2));
//活动
$activityModel = new ActivityModel();
$activity = $activityModel->selectData(0,2);
// $beginAtOnce = $activityModel->beginAtOnce($activity_page,$activity_pageNum);
//新闻
$activityNewsModel = new ActivityNewsModel();
$news = $activityNewsModel->selectData($activity_page,$activity_pageNum);
//幻灯片
$slideItemModel = new SlideItemModel();
$slide = $slideItemModel->selectData(array('slide_id'=>1));
$data['slide'] = $slide;
$data['volunteer'] = $volunteer;
$data['activity'] = $activity;
$data['news'] = $news;
$data['volunteer_page'] = $volunteer_page+1;
$data['activity_page'] = $activity_page+1;
$this->success('获取成功!',$data);
}
/**
* @title 更多志愿者
* @description 更多志愿者
* @author Xiaogang Wang
* @url /index/index/volunteer
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 level:星级 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*/
public function volunteer(){
$param = $this->request->param();
$page = $param['page'] ? $param['page'] : 0;//当前页数下标
$pageNum = $param['pageNum'] ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>2));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 获取更多即将开始的活动
* @description
* @author Xiaogang Wang
* @url /index/index/activityAtOnce
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
* @return page:活动下一页
*/
public function activityAtOnce(){
$param = $this->request->param();
$page = $param['page'] ? $param['page'] : 0;//当前页数下标
$pageNum = $param['pageNum'] ? $param['pageNum'] : 10;//每页显示几条数据
$Activity=new ActivityModel();
$activity=$Activity->beginAtOnce($page,$pageNum);
$data['activity'] = $activity;
$data['page'] =$page+1;
$this->success('获取成功!',$data);
}
/**
* @title 志愿者详情
* @description 志愿者详情
* @author Xiaogang Wang
* @url /index/index/volunteer_info
* @method GET
*
* @param name:id type:int require:1 other: desc:志愿者id
*
* @return id:id
* @return name:姓名
* @return sex:性别
* @return birthday:生日
* @return nation:民族
* @return politics:政治面貌
* @return education:学历
* @return unit:工作单位
* @return duty:职务
* @return addr:通讯地址
* @return postcode:邮编
* @return school:毕业院校
* @return card_number:身份证号
* @return fixed_phone:固定电话
* @return move_phone:移动电话
* @return email:email
* @return urgency_phone:紧急联系电话
* @return qq:qq
* @return province:省
* @return city:市
* @return county:区/县
* @return address:详细地址
* @return type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者)
* @return record:个人履历@
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return front_card:身份证正面照
* @return reverse_card:身份证背面照
* @return photo:照片
* @return status:状态(1审核中,2审核成功,3审核失败)
* @return user_id:用户id
*/
public function volunteer_info(){
$id = $this->request->param('id');
//获取志愿者
$volunteerModel = new VolunteerModel();
$volunteer = $volunteerModel->findData(array('id'=>$id));
$this->success('获取成功!',$volunteer);
}
/**
* @title 活动详情
* @description 活动详情
* @author Xiaogang Wang
* @url /index/index/activity_info
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
* @return id:id
* @return activity_name:活动名称
* @return abstract:摘要
* @return thumbnail:缩略图
* @return time:时间
* @return content:内容
* @return admin:是否为管理员1是管理员
* @return button_title:按钮标题
* @return join:参加用户@
* @join photo:照片 name:名称 level:星级 duty:岗位
* @return button_status:按钮状态7.用户被拒绝重新申请客户6.用户是志愿者,但是未报名参加活动5.已结束(活动过期)4.已提交工作汇报(用户是志愿者,已报名活动,已通过审核,已签到)3.提交工作汇报(用户是志愿者,已报名活动,选择线下或线上+线下,已通过审核,按钮变为签到但不可点击,活动有效时间内,变为可点击状态)2.待审核(用户是志愿者,已报名活动,但是未通过审核)1.报名 (用户是志愿者,但是未报名参加活动)
*/
public function activity_info(){
$id = $this->request->param('id');
//活动
$activityModel = new ActivityModel();
$userId=$this->getUserId();
$activity = $activityModel->findData(array('id'=>$id));
/*获取状态*/
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$userId));
/*是否为志愿者*/
$Volunteer=new VolunteerModel();
$volunteerMap['user_id']=$userId;
$volunteerMap['status']=2;
$volunteerMap['delete_time']=0;
$volunteer=$Volunteer->findData($volunteerMap);
if (empty($volunteer)){
$is_volunteer=0;
}else{
$is_volunteer=1;
}
/*是否活动结束*/
$Activity=new ActivityModel();
$activityMap['id']=$id;
$activity=$Activity->findData($activityMap);
if($activity['end_time']<time()){
$is_end=1;
}else{
$is_end=0;
}
if($user['type'] == 2){
$activity['admin']=1;
}else{
$activity['admin']=0;
}
/*是否报名活动*/
$Join=new JoinModel();
$where['activity_id']=$id;
$where['user_id']=$userId;
$where['delete_time']=0;
$join=$Join->findData($where);
if (empty($join)){
$is_join=0;
}else{
$is_join=1;
}
/*是否报名通过*/
if (empty($join['status']) || $join['status']==2){
$is_pass=0;
$is_book=0;
}elseif($join['status']=='3'){
$is_book=1;
$is_pass=1;
}elseif($join['status']=='1'){
$is_book=0;
$is_pass=1;
}elseif($join['status']==0){
$is_book=1;
$is_pass=0;
}
$check=0;
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==1 && $is_book==0){
$status=3;
$title='工作汇报';
$check=1;
}
if ($is_volunteer==0 && $check==0) {
$status=6;
$check=1;
$title='成为志愿者';
}
if ($is_end==1 && $check==0){
$status=5;
$title='已结束';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_pass==1 && $is_book==1){
$status=4;
$title='已签到';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==1 && $is_book==0){
$status=3;
$title='工作汇报';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $join['status']=='2'){
$status=7;
$title='报名';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==0){
$status=2;
$title='待审核';
$check=0;
}
if ($is_volunteer==1 && $check==0 && $is_join==0){
$status=1;
$title='报名';
$check=0;
}
$activity['button_title']=$title;
$activity['button_status']=$status;
$people=$Join->getJoinData($id);
$join1=[];
foreach ($people as $k=>$v){
$join1[$k]['photo']=$v['photo'];
$join1[$k]['name']=$v['name'];
$join1[$k]['level']=$v['level'];
$join1[$k]['duty']=$v['duty'];
}
$activity['join']=$join1;
$this->success('获取成功!',$activity);
}
/**
* @title 新闻详情
* @description 新闻详情
* @author Xiaogang Wang
* @url /index/index/news_info
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
* @return id:id
* @return activity_name:活动名称
* @return abstract:摘要
* @return thumbnail:缩略图
* @return time:时间
* @return content:内容
* @return button_title:按钮标题
* @return join:参加用户@
* @join photo:照片 name:名称 level:星级
* @return button_status:按钮状态6.用户是志愿者,但是未报名参加活动5.已结束(活动过期)4.已提交工作汇报(用户是志愿者,已报名活动,已通过审核,已签到)3.提交工作汇报(用户是志愿者,已报名活动,选择线下或线上+线下,已通过审核,按钮变为签到但不可点击,活动有效时间内,变为可点击状态)2.待审核(用户是志愿者,已报名活动,但是未通过审核)1.报名 (用户是志愿者,但是未报名参加活动)
*/
public function news_info(){
$id = $this->request->param('id');
//活动
$activityModel = new ActivityNewsModel();
$userId=$this->getUserId();
$activity = $activityModel->findData(array('id'=>$id));
/*获取状态*/
/*是否为志愿者*/
$Volunteer=new VolunteerModel();
$volunteerMap['user_id']=$userId;
$volunteerMap['status']=2;
$volunteerMap['delete_time']=0;
$volunteer=$Volunteer->findData($volunteerMap);
if (empty($volunteer)){
$is_volunteer=0;
}else{
$is_volunteer=1;
}
/*是否活动结束*/
$Activity=new ActivityModel();
$activityMap['id']=$id;
$activity_news=$Activity->findData($activityMap);
if($activity_news['end_time']>time()){
$is_end=1;
}else{
$is_end=0;
}
/*是否报名活动*/
$Join=new JoinModel();
$where['activity_id']=$id;
$where['user_id']=$userId;
$where['delete_time']=0;
$join=$Join->findData($where);
if (empty($join)){
$is_join=0;
}else{
$is_join=1;
}
/*是否报名通过*/
if (empty($join['status']) || $join['status']==2){
$is_pass=0;
$is_book=0;
}elseif($join['status']=='3'){
$is_book=1;
$is_pass=1;
}elseif($join['status']=='1'){
$is_book=0;
$is_pass=1;
}
$check=0;
if ($is_volunteer==0 && $check==0) {
$status=6;
$check=1;
$title='成为志愿者';
}
if ($is_end==1 && $check==0){
$status=5;
$title='已结束';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_pass==1 && $is_book==1){
$status=4;
$title='已提交工作汇报';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==1 && $is_book==0){
$status=3;
$title='提交工作汇报';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==0){
$status=2;
$title='待审核';
$check=0;
}
if ($is_volunteer==1 && $check==0 && $is_join==0){
$status=1;
$title='报名';
$check=0;
}
$activity['button_title']=$title;
$activity['button_status']=$status;
$people=$Join->getJoinData($id);
$join1=[];
foreach ($people as $k=>$v){
$join1[$k]['photo']=$v['photo'];
$join1[$k]['name']=$v['name'];
$join1[$k]['level']=$v['level'];
}
$activity['join']=$join1;
$this->success('获取成功!',$activity);
}
/**
* @title 签到(提交工作汇报)(new)
* @description 活动签到
* @author Xiaogang Wang
* @url /index/index/sginIn
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:work_report type:int require:1 other: desc:感想汇报
* @param name:work_pic type:int require:1 other: desc:图片
*
*/
public function sginIn(){
$userId=$this->getUserId();
$activity_id=input('id');
$Join=new JoinModel();
$where['user_id']=$userId;
$where['activity_id']=$activity_id;
$where['delete_time']=0;
$join=$Join->findData($where);
if (empty($join)){
$this->error('您还未报名此活动');
}
if ($join['status']==3){
$this->error('您已经提交过了');
}
if ($join['status']==2||$join['status']==0){
$this->error('还没有通过审核');
}
if ($join['status']==1){
$data['sgin_time']=time();
$data['status']=3;
$data['work_report']=input('work_report');
$data['work_pic']=html_entity_decode(htmlspecialchars_decode(input('work_pic')));
$result=db('join')->where($where)->update($data);
if ($result==0){
$this->error('提交失败');
}
}
$this->success('提交成功!');
}
/**
* @title 申请活动(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/applyJoin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:form_id type:int require:1 other: desc:表单id
* @param name:type type:int require:1 other: desc:活动类型1:线上2:线下3:线上+线下
* @param name:start_time type:int require:1 other: desc:开始时间
* @param name:end_time type:int require:1 other: desc:结束时间
* @param name:work_content type:int require:1 other: desc:工作内容
* @param name:select_time type:int require:1 other: desc:选择日期[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
* @param name:apply_stay type:int require:1 other: desc:申请入住[{"date":"2018-01-02","idcard":"123456"},{"date":"2018-01-02","idcard":"123456"}]
* @param name:apply_food type:int require:1 other: desc:申请用餐[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
*
*/
public function applyJoin(){
$userId=$this->getUserId();
$type=input('type');
$start_time=strtotime(input('start_time'));
$end_time=strtotime(input('end_time'));
$activity_id=input('id');
$form_id=input('form_id');
$this->saveFormId($userId,$form_id);
/*三期增加字段*/
$work_content=input('work_content');
$select_time=html_entity_decode(htmlspecialchars_decode(input('select_time')));
$apply_stay=html_entity_decode(htmlspecialchars_decode(input('apply_stay')));
$apply_food=html_entity_decode(htmlspecialchars_decode(input('apply_food')));
/*判断是否未志愿者*/
$Volunteer=new VolunteerModel();
$where['user_id']=$userId;
$volunter=$Volunteer->findData($where);
if (empty($volunter)){
$this->error('请先成为志愿者!');
}
/*判断是否参加了活动*/
$Join=new JoinModel();
$map['user_id']=$userId;
$map['activity_id']=$activity_id;
$map['delete_time']=0;
$join=$Join->findData($map);
if ($join){
// $this->error('已经报名参加过该活动!');
}
$data['user_id']=$userId;
$data['activity_id']=$activity_id;
$data['type']=$type;
$data['start_time']=$start_time;
$data['end_time']=$end_time;
$data['add_time']=time();
/*三期功能字段*/
$data['work_content']=$work_content;
$data['select_time']=html_entity_decode(htmlspecialchars_decode(input('select_time')));
$data['apply_stay']=html_entity_decode(htmlspecialchars_decode(input('apply_stay')));
$data['apply_food']=html_entity_decode(htmlspecialchars_decode(input('apply_food')));
$result=$Join->insert($data);
if ($result>0){
$this->success('报名成功,请等待审核!');
}
$this->error('报名失败');
}
/**
* @title 编辑参加活动信息(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/editApply
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:form_id type:int require:1 other: desc:表单id
* @param name:type type:int require:1 other: desc:活动类型1:线上2:线下3:线上+线下
* @param name:start_time type:int require:1 other: desc:开始时间
* @param name:end_time type:int require:1 other: desc:结束时间
* @param name:work_content type:int require:1 other: desc:工作内容
* @param name:select_time type:int require:1 other: desc:选择日期[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
* @param name:apply_stay type:int require:1 other: desc:申请入住[{"date":"2018-01-02","idcard":"123456"},{"date":"2018-01-02","idcard":"123456"}]
* @param name:apply_food type:int require:1 other: desc:申请用餐[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
*
*/
public function editApply(){
$userId=$this->getUserId();
$activity_id=input('id');
$map['activity_id']=$activity_id;
$map['user_id']=$userId;
$map['delete_time']=0;
$form_id=input('form_id');
$this->saveFormId($userId,$form_id);
$join=db('join')->where($map)->find();
if (empty($join)){
$this->error('不存在相关信息');
}
$type=input('type');
$start_time=strtotime(input('start_time'));
$end_time=strtotime(input('end_time'));
/*三期增加字段*/
$work_content=input('work_content');
$select_time=html_entity_decode(htmlspecialchars_decode(input('select_time')));
$apply_stay=html_entity_decode(htmlspecialchars_decode(input('apply_stay')));
$apply_food=html_entity_decode(htmlspecialchars_decode(input('apply_food')));
$data['user_id']=$userId;
$data['activity_id']=$activity_id;
$data['type']=$type;
$data['start_time']=$start_time;
$data['end_time']=$end_time;
/*三期功能字段*/
$data['work_content']=$work_content;
$data['select_time']=$select_time;
$data['apply_stay']=$apply_stay;
$data['apply_food']=$apply_food;
$Join=new JoinModel();
$result=$Join->where($map)->Update($data);
/*echo $Join->getLastSql();
dump($result);
exit();*/
if ($result>0){
$this->success('修改成功,请等待审核!');
}
$this->error('修改失败');
}
/**
* @title 获取申请活动填写信息(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/getApplyInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:user_id type:int require:1 other: desc:用户id
*
* @return name:姓名
* @return birthday:生日
* @return sex:性别
* @return tel:手机号
* @return work_type:工作类型
* @return work_content:工作内容
* @return select_time:选择日期
* @return apply_stay:申请入住
* @return apply_food:申请用餐
*
*/
public function getApplyInfo(){
$userId=$this->getUserId();
$activity_id=input('id');
$user_id=input('user_id');
if (!empty($user_id)){
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$userId));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$userId=$user_id;
}
$map['user_id']=$userId;
$map['activity_id']=$activity_id;
$map['delete_time']=0;
/*获取*/
$activity=db('activity')->field('start_time,end_time')->where('id',$activity_id)->order('id','desc')->find();
$time=$activity['end_time'];
$now=time();
while ($time>$now){
$return['time'][]=date('Y-m-d',$time);
$time=$time-60*60*24;
}
if (!empty($return['time'])){
$return['time']= array_reverse($return['time']);
}
$info=db('join')->field('sgin_time,id,type,user_id,activity_id,select_time,apply_stay,apply_food,work_content')->where($map)->find();
$user=db('volunteer')->field('sex,name,birthday,move_phone')->where('user_id',$userId)->find();
if (!empty($user)){
$return['name']=$user['name'];
$return['birthday']=$user['birthday'];
$return['sex']=$user['sex']==1?'男':'女';
$return['tel']=$user['move_phone'];
}
if (!empty($info)){
$return['work_content']=db('work')->where('id',$info['work_content'])->value('name');
$return['work_content']=$info['work_content'];
$return['select_time']=json_decode($info['select_time'],true);
$return['apply_stay']=json_decode($info['apply_stay'],true);
$return['apply_food']=json_decode($info['apply_food'],true);
$return['id']=$info['id'];
$return['work_type']=$info['type'];
$return['is_complete']=$info['sgin_time']==0?'0':'1';
/* switch ($info['type']){
case 1:
$return['work_type']='线上';
break;
case 2:
$return['work_type']='线下';
break;
case 3:
$return['work_type']='线上及线下';
break;
}*/
}
$this->success('',$return);
}
/**
* @title 退出活动(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/quitActivity
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
*/
public function quitActivity(){
$userId=$this->getUserId();
$activity_id=input('id');
$map['user_id']=$userId;
$map['activity_id']=$activity_id;
$data['delete_time']=time();
$result=db('join')->where($map)->update($data);
if ($result>0){
$this->success('退出成功!');
}else{
$this->error('退出失败!');
}
}
/**
* @title 工作汇报表信息(new)
* @description 获取工作汇报表信息
* @author Xiaogang Wang
* @url /index/index/workReportInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:user_id type:int require:1 other: desc:用户id
*
* @return work_content:工作内容
* @return date:参加日期
* @return time:参加时间
* @return name:姓名
*/
public function workReportInfo(){
$userId=$this->getUserId();
$activity_id=input('id');
if (!empty($user_id)){
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$userId));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$userId=$user_id;
}
$map['user_id']=input('user_id');
$map['activity_id']=$activity_id;
$map['status']=['in','1,3'];
$map['delete_time']=0;
$result=db('join')->where($map)->find();
// echo db('join')->getLastSql();
if (empty($result)){
$this->error('没有相关信息');
}
$return['work_content']=db('work')->where('id',$result['work_content'])->value('name');
/* $return['date']=date('Y-m-d',$result['add_time']);
$return['time']=date('H:i:s',$result['add_time']);*/
$return['time']=json_decode($result['select_time'],true);
$return['name']=db('volunteer')->where('user_id',$result['user_id'])->value('name');
$return['pic']=json_decode($result['work_pic'],true);
$this->success('',$return);
}
/**
* @title 获取城市列表
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/cityList
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:城市id
* @param name:province_name type:int require:1 other: desc:城市名称
*
*/
public function cityList(){
$Pro=new PositionProvinceModel();
$pro=$Pro->selectData();
foreach ($pro as $k=>$v){
$return['city'][$k]=$v['province_name'];
$return['id'][$k]=$v['id'];
}
$this->success('',$return);
}
/**
* @title 通过城市获取活动
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/cityGetActivity
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:city_id type:int require:1 other: desc:城市id
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
*/
public function cityGetActivity(){
$city_id=input('city_id');
$Activity=new ActivityModel();
$activity=$Activity->selectCityData($city_id);
$this->success('',$activity);
}
/**
* @title 获取活动类型列表
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/activityType
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:id
* @param name:type_name type:int require:1 other: desc:活动类型
*
*/
public function activityType(){
$Type=new ActivityTypeModel();
$type=$Type->selectData();
foreach ($type as $k=>$v){
$return['type_name'][$k]=$v['type_name'];
$return['id'][$k]=$v['id'];
}
$this->success('',$return);
}
/**
* @title 通过类型获取活动
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/typeGetActivity
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:type n_id type:int require:1 other: desc:类型id
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
*/
public function typeGetActivity(){
$type_id=input('type');
$Activity=new ActivityModel();
$activity=$Activity->selectTypeData($type_id);
$this->success('',$activity);
}
/**
* @title 生成分享图片地址(new);
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/makePic
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id n_id type:int require:1 other: desc:活动id
*/
public function makePic(){
$id=input('id');
$activity=db('activity')->where('id',$id)->find();
$text=$activity['activity_name'];
$headimg='../upload/'.$activity['thumbnail'];
$scene=$id;
$name='1-'.$id;
$Code=new Code();
$path='../upload/qrcode/';
$name1=$Code->code($scene,'pages/img_txt/img_txt',280,$name);
$Image = new Image($path.$name1);
$circle=$Image->circle();
$Image->save('../upload/qrcode/1-'.$id.'.png','png',5);
/*生成图片*/
$image1=\think\Image::open($headimg);
$image1->thumb(595,545,\think\Image::THUMB_CENTER)->save('../upload/qrcode/2-'.$id.'.png');
$image = \think\Image::open('../static/images/background.png');
// $text='这个是一个活动名称啊啊啊';
$num=mb_strlen($text);
$cha=$num-8;
$locate[]=188-$cha*13;
$locate[]=680;
$font='../static/font-awesome/fonts/PingFang Medium.ttf';
$result=$image->water('../upload/qrcode/2-'.$id.'.png',\think\Image::WATER_NORTHWEST)->water('../static/images/bottom.png',9)
->water('../upload/qrcode/1-'.$id.'.png',5)->text($text,$font,20,'#000000',$locate)->save($path.$id.'.png');
/*清除产生的图片*/
unlink($path.'1-'.$id.'.jpg');
unlink($path.'1-'.$id.'.png');
unlink($path.'2-'.$id.'.png');
$return['url']=cmf_get_image_url('/upload/qrcode/'.$id.'.png');
$this->success('',$return);
/*
$Head=new Image('../static/images/qr.jpg');
$Head->thumb('595');
$Head->save('../upload/qrcode/2-'.$id.'.jpg');
$path2='../upload/qrcode/2-'.$id.'.jpg';
$background =new Image('../static/images/background.png');
$background->mergeImage($path2,'jpg',595,'400',0,0);
echo 111;
//$background->mergeImage('../static/images/bottom.png','jpg',595,536,'425',0);
$background->save('../upload/qrcode/3-'.$id.'.png');
echo 222;
$last=new Image('../upload/qrcode/3-'.$id.'.png');
$last->mergeImage('../static/images/bottom.png','png',595,536,425,0);
$last->mergeImage('../upload/qrcode/1-'.$id.'.png','png',595,536,477,160);
$last->save('../upload/qrcode/4-'.$id.'.png');
dump($circle);
dump($Image->get());*/
}
/**
* 添加formid
* @param $userId
* @param $formId
*/
protected function saveFormId($userId,$formId){
if ($formId=='undefined'){
return;
}
$data['user_id']=$userId;
$data['add_time']=time();
$data['value']=$formId;
$data['expire_time']=time()+604800;
db('form_id')->insert($data);
}
public function test(){
$config = [
'app_id' => 'wx3cf0f39249eb0exx',
'secret' => 'f1c242f4f28f735d4687abb469072axx',
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
'response_type' => 'array'
];
$app = Factory::officialAccount($config);
}
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 11:30
*/
namespace api\index\controller;
use api\index\model\ActivityModel;
use api\index\model\ActivityNewsModel;
use api\index\model\ActivityType;
use api\index\model\ActivityTypeModel;
use api\index\model\JoinModel;
use api\index\model\PositionProvinceModel;
use api\index\model\SlideItemModel;
use api\index\model\UserModel;
use api\index\model\VolunteerModel;
use cmf\controller\RestBaseController;
use Dompdf\Frame\Factory;
use EasyWeChatComposer\EasyWeChat;
use Hooklife\ThinkphpWechat\Wechat;
use Magicfier\Image;
use think\Url;
use traits\think\Instance;
use wxapp\Code;
/**
* @title 首页
* @description 首页
*/
class IndexController extends RestBaseController
{
public function _initialize()
{
$user_id = $this->getUserId();
$userModel = new UserModel();
$user = $userModel->where(array('id'=>$user_id))->find();
if($user['user_status'] == 0){
$this->error(['code'=>40005,'msg'=>'您已被列入黑名单,请联系管理员!']);
}
}
/**
* @title 首页
* @description 首页
* @author Xiaogang Wang
* @url /index/index/index
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:volunteer_page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:volunteer_pageNum type:int require:0 other: desc:活动显示数量(默认3)
* @param name:activity_page type:int require:0 other: desc:活动当前页(0为第一页)(默认0)
* @param name:activity_pageNum type:int require:0 other: desc:活动显示数量(默认4)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 level:星级 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
* @return news:活动新闻@
* @news id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
* @return volunteer_page:志愿者下一页
* @return activity_page:活动下一页
*/
public function index(){
$param = $this->request->param();
$volunteer_page = $param['volunteer_page'] ? $param['volunteer_page'] : 0;//当前页数下标
$volunteer_pageNum = $param['volunteer_pageNum'] ? $param['volunteer_pageNum'] : 3;//每页显示几条数据
$activity_page = $param['activity_page'] ? $param['activity_page'] : 0;//当前页数下标
$activity_pageNum = $param['activity_pageNum'] ? $param['activity_pageNum'] : 4;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
$volunteer = $volunteerModel->selectData($volunteer_page,$volunteer_pageNum,array('status'=>2));
//活动
$activityModel = new ActivityModel();
$activity = $activityModel->selectDataByTime(0,2);
foreach ($activity as $k=>$v){
$activity[$k]['start_time']=date('Y-m-d',$v['start_time']);
}
// $beginAtOnce = $activityModel->beginAtOnce($activity_page,$activity_pageNum);
//新闻
$activityNewsModel = new ActivityNewsModel();
$news = $activityModel->selectDataByTime($activity_page,$activity_pageNum,1);
//幻灯片
$slideItemModel = new SlideItemModel();
$slide = $slideItemModel->selectData(array('slide_id'=>1));
$data['slide'] = $slide;
$data['volunteer'] = $volunteer;
$data['activity'] = $activity;
$data['news'] = $news;
$data['volunteer_page'] = $volunteer_page+1;
$data['activity_page'] = $activity_page+1;
$this->success('获取成功!',$data);
}
/**
* @title 更多志愿者
* @description 更多志愿者
* @author Xiaogang Wang
* @url /index/index/volunteer
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 level:星级 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*/
public function volunteer(){
$param = $this->request->param();
$page = $param['page'] ? $param['page'] : 0;//当前页数下标
$pageNum = $param['pageNum'] ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>2));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 获取更多即将开始的活动
* @description
* @author Xiaogang Wang
* @url /index/index/activityAtOnce
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
* @return page:活动下一页
*/
public function activityAtOnce(){
$param = $this->request->param();
$page = $param['page'] ? $param['page'] : 0;//当前页数下标
$pageNum = $param['pageNum'] ? $param['pageNum'] : 10;//每页显示几条数据
$Activity=new ActivityModel();
$activity=$Activity->beginAtOnce($page,$pageNum);
$data['activity'] = $activity;
$data['page'] =$page+1;
$this->success('获取成功!',$data);
}
/**
* @title 志愿者详情
* @description 志愿者详情
* @author Xiaogang Wang
* @url /index/index/volunteer_info
* @method GET
*
* @param name:id type:int require:1 other: desc:志愿者id
*
* @return id:id
* @return name:姓名
* @return sex:性别
* @return birthday:生日
* @return nation:民族
* @return politics:政治面貌
* @return education:学历
* @return unit:工作单位
* @return duty:职务
* @return addr:通讯地址
* @return postcode:邮编
* @return school:毕业院校
* @return card_number:身份证号
* @return fixed_phone:固定电话
* @return move_phone:移动电话
* @return email:email
* @return urgency_phone:紧急联系电话
* @return qq:qq
* @return province:省
* @return city:市
* @return county:区/县
* @return address:详细地址
* @return type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者)
* @return record:个人履历@
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return front_card:身份证正面照
* @return reverse_card:身份证背面照
* @return photo:照片
* @return status:状态(1审核中,2审核成功,3审核失败)
* @return user_id:用户id
*/
public function volunteer_info(){
$id = $this->request->param('id');
//获取志愿者
$volunteerModel = new VolunteerModel();
$volunteer = $volunteerModel->findData(array('id'=>$id));
$this->success('获取成功!',$volunteer);
}
/**
* @title 活动详情
* @description 活动详情
* @author Xiaogang Wang
* @url /index/index/activity_info
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
* @return id:id
* @return activity_name:活动名称
* @return abstract:摘要
* @return thumbnail:缩略图
* @return time:时间
* @return content:内容
* @return admin:是否为管理员1是管理员
* @return button_title:按钮标题
* @return join:参加用户@
* @join photo:照片 name:名称 level:星级 duty:岗位
* @return button_status:按钮状态8.报名通过活动未结束,不能填写报告7.用户被拒绝重新申请客户6.用户是志愿者,但是未报名参加活动5.已结束(活动过期)4.已提交工作汇报(用户是志愿者,已报名活动,已通过审核,已签到)3.提交工作汇报(用户是志愿者,已报名活动,选择线下或线上+线下,已通过审核,按钮变为签到但不可点击,活动有效时间内,变为可点击状态)2.待审核(用户是志愿者,已报名活动,但是未通过审核)1.报名 (用户是志愿者,但是未报名参加活动)
* @return activity_stage:0.未开始1.进行中2.已结束
* @return status:0.未审核1.已通过2.已拒绝3.已提交工作汇报
* @return is_join:0.未参加1.已参加
*/
public function activity_info(){
$id = $this->request->param('id');
//活动
$activityModel = new ActivityModel();
$userId=$this->getUserId();
$activity = $activityModel->findData(array('id'=>$id));
/*获取状态*/
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$userId));
/*是否为志愿者*/
$Volunteer=new VolunteerModel();
$volunteerMap['user_id']=$userId;
$volunteerMap['status']=2;
$volunteerMap['delete_time']=0;
$volunteer=$Volunteer->findData($volunteerMap);
if (empty($volunteer)){
$is_volunteer=0;
}else{
$is_volunteer=1;
}
/*是否活动结束*/
$Activity=new ActivityModel();
$activityMap['id']=$id;
$activity=$Activity->findData($activityMap);
if($activity['end_time']<time()){
$is_end=1;
}else{
$is_end=0;
}
if ($is_end==0){
if ($activity['start_time']>time()){
$activity['activity_stage']=0;
}else{
$activity['activity_stage']=1;
}
}else{
$activity['activity_stage']=2;
}
if($user['type'] == 2){
$activity['admin']=1;
}else{
$activity['admin']=0;
}
/*是否报名活动*/
$Join=new JoinModel();
$where['activity_id']=$id;
$where['user_id']=$userId;
$where['delete_time']=0;
$join=$Join->findData($where);
if (empty($join)){
$is_join=0;
}else{
$is_join=1;
}
/*是否报名通过*/
if (empty($join['status']) || $join['status']==2){
$is_pass=0;
$is_book=0;
}elseif($join['status']=='3'){
$is_book=1;
$is_pass=1;
}elseif($join['status']=='1'){
$is_book=0;
$is_pass=1;
}elseif($join['status']==0){
$is_book=1;
$is_pass=0;
}
$check=0;
/*添加状态 活动没有开始时不能提交报告*/
if ($is_volunteer==1 && $check==0 && $is_pass==1 && $is_end==0){
$status=8;
$title='暂不能提交工作汇报';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==1 && $is_book==0){
$status=3;
$title='工作汇报';
$check=1;
}
if ($is_end==1 && $check==0){
$status=5;
$title='已结束';
$check=1;
}
if ($is_volunteer==0 && $check==0) {
$status=6;
$check=1;
$title='成为志愿者';
}
if ($is_volunteer==1 && $check==0 && $is_pass==1 && $is_book==1){
$status=4;
$title='已签到';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==1 && $is_book==0){
$status=3;
$title='工作汇报';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $join['status']=='2'){
$status=7;
$title='报名';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==0){
$status=2;
$title='待审核';
$check=0;
}
if ($is_volunteer==1 && $check==0 && $is_join==0){
$status=1;
$title='报名';
$check=0;
}
$activity['button_title']=$title;
$activity['button_status']=$status;
/*活动参与状态*/
$activity['is_join']=$is_join;
$people=$Join->getJoinData($id);
$map1=[];
$sub_map['j.activity_id']=$id;
$sub_map['j.status']=['in','1,3'];
$sub_map['j.delete_time']=0;
$subQuery = db('join')->alias('j')
->field('max(j.id)')
->join('volunteer v','v.user_id=j.user_id')
->where($sub_map)
->group('j.user_id')
->select()
->toArray();
if (!empty($subQuery)){
foreach ($subQuery as $k=>$v){
$new_map[]=$v["max(j.id)"];
}
$map1['j.id']=['in',implode(',',$new_map)];
}
$map1['j.activity_id']=$id;
$map1['j.status']=['in','1,3'];
$map1['j.delete_time']=0;
$people=db('join')->alias('j')
->group('j.user_id')
->field('v.name,v.photo,v.level,j.work_content')
->join('volunteer v','v.user_id=j.user_id')
->where($map1)
->order('j.id','asc')
->select()
->toArray();
$join1=[];
$work_content=db('work')->column('name');
// dump($people);
foreach ($people as $k=>$v){
$join1[$k]['photo']=$v['photo'];
$join1[$k]['name']=$v['name'];
$join1[$k]['level']=$v['level'];
$join1[$k]['duty']=$work_content[$v['work_content']-1]??'';
}
$activity['join']=$join1;
$this->success('获取成功!',$activity);
}
/**
* @title 新闻详情
* @description 新闻详情
* @author Xiaogang Wang
* @url /index/index/news_info
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
* @return id:id
* @return activity_name:活动名称
* @return abstract:摘要
* @return thumbnail:缩略图
* @return time:时间
* @return content:内容
* @return button_title:按钮标题
* @return join:参加用户@
* @join photo:照片 name:名称 level:星级
* @return button_status:按钮状态6.用户是志愿者,但是未报名参加活动5.已结束(活动过期)4.已提交工作汇报(用户是志愿者,已报名活动,已通过审核,已签到)3.提交工作汇报(用户是志愿者,已报名活动,选择线下或线上+线下,已通过审核,按钮变为签到但不可点击,活动有效时间内,变为可点击状态)2.待审核(用户是志愿者,已报名活动,但是未通过审核)1.报名 (用户是志愿者,但是未报名参加活动)
*/
public function news_info(){
$id = $this->request->param('id');
//活动
$activityModel = new ActivityNewsModel();
$userId=$this->getUserId();
$activity = $activityModel->findData(array('id'=>$id));
/*获取状态*/
/*是否为志愿者*/
$Volunteer=new VolunteerModel();
$volunteerMap['user_id']=$userId;
$volunteerMap['status']=2;
$volunteerMap['delete_time']=0;
$volunteer=$Volunteer->findData($volunteerMap);
if (empty($volunteer)){
$is_volunteer=0;
}else{
$is_volunteer=1;
}
/*是否活动结束*/
$Activity=new ActivityModel();
$activityMap['id']=$id;
$activity_news=$Activity->findData($activityMap);
if($activity_news['end_time']>time()){
$is_end=1;
}else{
$is_end=0;
}
/*是否报名活动*/
$Join=new JoinModel();
$where['activity_id']=$id;
$where['user_id']=$userId;
$where['delete_time']=0;
$join=$Join->findData($where);
if (empty($join)){
$is_join=0;
}else{
$is_join=1;
}
/*是否报名通过*/
if (empty($join['status']) || $join['status']==2){
$is_pass=0;
$is_book=0;
}elseif($join['status']=='3'){
$is_book=1;
$is_pass=1;
}elseif($join['status']=='1'){
$is_book=0;
$is_pass=1;
}
$check=0;
if ($is_volunteer==0 && $check==0) {
$status=6;
$check=1;
$title='成为志愿者';
}
if ($is_end==1 && $check==0){
$status=5;
$title='已结束';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_pass==1 && $is_book==1){
$status=4;
$title='已提交工作汇报';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==1 && $is_book==0){
$status=3;
$title='提交工作汇报';
$check=1;
}
if ($is_volunteer==1 && $check==0 && $is_join==1 && $is_pass==0){
$status=2;
$title='待审核';
$check=0;
}
if ($is_volunteer==1 && $check==0 && $is_join==0){
$status=1;
$title='报名';
$check=0;
}
$activity['button_title']=$title;
$activity['button_status']=$status;
$people=$Join->getJoinData($id);
$join1=[];
foreach ($people as $k=>$v){
$join1[$k]['photo']=$v['photo'];
$join1[$k]['name']=$v['name'];
$join1[$k]['level']=$v['level'];
}
$activity['join']=$join1;
$this->success('获取成功!',$activity);
}
/**
* @title 签到(提交工作汇报)(new)
* @description 活动签到
* @author Xiaogang Wang
* @url /index/index/sginIn
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:work_report type:int require:1 other: desc:感想汇报
* @param name:work_pic type:int require:1 other: desc:图片
*
*/
public function sginIn(){
$userId=$this->getUserId();
$activity_id=input('id');
$Join=new JoinModel();
$where['user_id']=$userId;
$where['activity_id']=$activity_id;
$where['status']=1;
$where['delete_time']=0;
$join=$Join->findData($where);
if (empty($join)){
$this->error('您还未报名此活动');
}
if ($join['status']==3){
$this->error('您已经提交过了');
}
if ($join['status']==2||$join['status']==0){
$this->error('还没有通过审核');
}
if ($join['status']==1){
$data['sgin_time']=time();
$data['status']=3;
$data['work_report']=input('work_report');
$data['work_pic']=html_entity_decode(htmlspecialchars_decode(input('work_pic')));
$result=db('join')->where($where)->update($data);
if ($result==0){
$this->error('提交失败');
}
}
$this->success('提交成功!');
}
/**
* @title 申请活动(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/applyJoin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:form_id type:int require:1 other: desc:表单id
* @param name:card_number type:int require:1 other: desc:身份证号
* @param name:type type:int require:1 other: desc:活动类型1:线上2:线下3:线上+线下
* @param name:start_time type:int require:1 other: desc:开始时间
* @param name:end_time type:int require:1 other: desc:结束时间
* @param name:work_content type:int require:1 other: desc:工作内容
* @param name:select_time type:int require:1 other: desc:选择日期[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
* @param name:apply_stay type:int require:1 other: desc:申请入住[{"date":"2018-01-02","idcard":"123456"},{"date":"2018-01-02","idcard":"123456"}]
* @param name:apply_food type:int require:1 other: desc:申请用餐[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
*
*/
public function applyJoin(){
$userId=$this->getUserId();
$type=input('type');
$start_time=strtotime(input('start_time'));
$end_time=strtotime(input('end_time'));
$activity_id=input('id');
$form_id=input('form_id');
$card_number=input('card_number');
$this->saveFormId($userId,$form_id);
/*三期增加字段*/
$work_content=input('work_content');
$select_time=html_entity_decode(htmlspecialchars_decode(input('select_time')));
$apply_stay=html_entity_decode(htmlspecialchars_decode(input('apply_stay')));
$apply_food=html_entity_decode(htmlspecialchars_decode(input('apply_food')));
/*判断是否未志愿者*/
$Volunteer=new VolunteerModel();
$where['user_id']=$userId;
$volunter=$Volunteer->findData($where);
if (empty($volunter)){
$this->error('请先成为志愿者!');
}
/*判断是否参加了活动*/
$Join=new JoinModel();
$map['user_id']=$userId;
$map['activity_id']=$activity_id;
$map['delete_time']=0;
$map['status']=0;
$join=$Join->findData($map);
if ($join){
$this->error('已经报名参加过该活动!');
}
$data['user_id']=$userId;
$data['card_number']=$card_number;
$data['activity_id']=$activity_id;
$data['type']=$type;
$data['start_time']=$start_time;
$data['end_time']=$end_time;
$data['add_time']=time();
/*三期功能字段*/
$data['work_content']=$work_content;
$data['select_time']=html_entity_decode(htmlspecialchars_decode(input('select_time')));
$data['apply_stay']=html_entity_decode(htmlspecialchars_decode(input('apply_stay')));
$data['apply_food']=html_entity_decode(htmlspecialchars_decode(input('apply_food')));
$result=$Join->insert($data);
if ($result>0){
$this->success('报名成功,请等待审核!');
}
$this->error('报名失败');
}
/**
* @title 编辑参加活动信息(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/editApply
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:form_id type:int require:1 other: desc:表单id
* @param name:type type:int require:1 other: desc:活动类型1:线上2:线下3:线上+线下
* @param name:start_time type:int require:1 other: desc:开始时间
* @param name:end_time type:int require:1 other: desc:结束时间
* @param name:work_content type:int require:1 other: desc:工作内容
* @param name:select_time type:int require:1 other: desc:选择日期[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
* @param name:apply_stay type:int require:1 other: desc:申请入住[{"date":"2018-01-02","idcard":"123456"},{"date":"2018-01-02","idcard":"123456"}]
* @param name:apply_food type:int require:1 other: desc:申请用餐[{"date":"2018-01-02","time":"18:01"},{"date":"2018-01-02","time":"18:01"}]
*
*/
public function editApply(){
$userId=$this->getUserId();
$activity_id=input('id');
$map['activity_id']=$activity_id;
$map['user_id']=$userId;
$map['delete_time']=0;
$form_id=input('form_id');
$this->saveFormId($userId,$form_id);
$join=db('join')->where($map)->find();
if (empty($join)){
$this->error('不存在相关信息');
}
$type=input('type');
$start_time=strtotime(input('start_time'));
$end_time=strtotime(input('end_time'));
/*三期增加字段*/
$work_content=input('work_content');
$select_time=html_entity_decode(htmlspecialchars_decode(input('select_time')));
$apply_stay=html_entity_decode(htmlspecialchars_decode(input('apply_stay')));
$apply_food=html_entity_decode(htmlspecialchars_decode(input('apply_food')));
$data['user_id']=$userId;
$data['activity_id']=$activity_id;
$data['type']=$type;
$data['start_time']=$start_time;
$data['end_time']=$end_time;
/*三期功能字段*/
$data['work_content']=$work_content;
$data['select_time']=$select_time;
$data['apply_stay']=$apply_stay;
$data['apply_food']=$apply_food;
$data['card_number']=input('card_number');
$data['status']=0;//需要重新进行审核
$Join=new JoinModel();
$result=$Join->where($map)->Update($data);
/*echo $Join->getLastSql();
dump($result);
exit();*/
if ($result>0){
$this->success('修改成功,请等待审核!');
}
$this->error('修改失败');
}
/**
* @title 获取申请活动填写信息(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/getApplyInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:user_id type:int require:1 other: desc:用户id
*
* @return name:姓名
* @return birthday:生日
* @return sex:性别
* @return tel:手机号
* @return card_number:身份证号
* @return work_type:工作类型
* @return work_content:工作内容
* @return select_time:选择日期
* @return apply_stay:申请入住
* @return apply_food:申请用餐
*
*
*/
public function getApplyInfo(){
$userId=$this->getUserId();
$activity_id=input('id');
$user_id=input('user_id');
if (!empty($user_id)){
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$userId));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$userId=$user_id;
}
$map['user_id']=$userId;
$map['activity_id']=$activity_id;
$map['delete_time']=0;
/*获取*/
$activity=db('activity')->field('start_time,end_time')->where('id',$activity_id)->order('id','desc')->find();
$time=$activity['end_time'];
$now=time();
while ($time>$now){
$return['time'][]=date('Y-m-d',$time);
$time=$time-60*60*24;
}
if (!empty($return['time'])){
$return['time']= array_reverse($return['time']);
}
$info=db('join')->field('sgin_time,id,type,user_id,activity_id,select_time,apply_stay,apply_food,work_content')->where($map)->find();
$user=db('volunteer')->field('card_number,sex,name,birthday,move_phone')->where('user_id',$userId)->find();
if (!empty($user)){
$return['name']=$user['name'];
$return['birthday']=$user['birthday'];
$return['sex']=$user['sex']==1?'男':'女';
$return['tel']=$user['move_phone'];
$return['card_number']=$user['card_number'];
}
if (!empty($info)){
$return['work_content']=db('work')->where('id',$info['work_content'])->value('name');
$return['work_content']=$info['work_content'];
$return['select_time']=json_decode($info['select_time'],true);
$return['apply_stay']=json_decode($info['apply_stay'],true);
$return['apply_food']=json_decode($info['apply_food'],true);
$return['id']=$info['id'];
$return['work_type']=$info['type'];
$return['is_complete']=$info['sgin_time']==0?'0':'1';
/* switch ($info['type']){
case 1:
$return['work_type']='线上';
break;
case 2:
$return['work_type']='线下';
break;
case 3:
$return['work_type']='线上及线下';
break;
}*/
}
$this->success('',$return);
}
/**
* @title 退出活动(new)
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/quitActivity
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
*/
public function quitActivity(){
$userId=$this->getUserId();
$activity_id=input('id');
$map['user_id']=$userId;
$map['activity_id']=$activity_id;
$data['delete_time']=time();
$result=db('join')->where($map)->update($data);
if ($result>0){
$this->success('退出成功!');
}else{
$this->error('退出失败!');
}
}
/**
* @title 工作汇报表信息(new)
* @description 获取工作汇报表信息
* @author Xiaogang Wang
* @url /index/index/workReportInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
* @param name:user_id type:int require:1 other: desc:用户id
*
* @return work_content:工作内容
* @return date:参加日期
* @return time:参加时间
* @return name:姓名
*/
public function workReportInfo(){
$userId=$this->getUserId();
$activity_id=input('id');
if (!empty($user_id)){
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$userId));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$userId=$user_id;
}
$map['user_id']=input('user_id');
if (empty($map['user_id'])){
$map['user_id']=$userId;
}
$map['activity_id']=$activity_id;
$map['status']=['in','1,3'];
$map['delete_time']=0;
$result=db('join')->where($map)->order('id','desc')->find();
if (empty($result)){
$this->error('没有相关信息');
}
$return['work_content']=db('work')->where('id',$result['work_content'])->value('name');
$return['work_report']=$result['work_report'];
/* $return['date']=date('Y-m-d',$result['add_time']);
$return['time']=date('H:i:s',$result['add_time']);*/
$return['time']=json_decode($result['select_time'],true);
$return['name']=db('volunteer')->where('user_id',$result['user_id'])->value('name');
$return['pic']=json_decode($result['work_pic'],true);
$this->success('',$return);
}
/**
* @title 获取城市列表
* @description 活动申请
* @author Xiaogang Wang
* @url /index/index/cityList
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:城市id
* @param name:province_name type:int require:1 other: desc:城市名称
*
*/
public function cityList(){
$Pro=new PositionProvinceModel();
$pro=$Pro->selectData();
foreach ($pro as $k=>$v){
$return['city'][$k]=$v['province_name'];
$return['id'][$k]=$v['id'];
}
$this->success('',$return);
}
/**
* @title 通过城市获取活动
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/cityGetActivity
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:city_id type:int require:1 other: desc:城市id
* @param name:end type:int require:1 other: desc:0,未结束1,已结束
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
*/
public function cityGetActivity(){
$city_id=input('city_id');
$end=input('end');
if (empty($end)||$end==0){
$type='>=';
}else{
$type='<';
}
$Activity=new ActivityModel();
$activity=$Activity->selectCityData($city_id,$type);
$this->success('',$activity);
}
/**
* @title 获取活动类型列表
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/activityType
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:id
* @param name:type_name type:int require:1 other: desc:活动类型
*
*/
public function activityType(){
$Type=new ActivityTypeModel();
$type=$Type->selectData();
foreach ($type as $k=>$v){
$return['type_name'][$k]=$v['type_name'];
$return['id'][$k]=$v['id'];
}
$this->success('',$return);
}
/**
* @title 通过类型获取活动
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/typeGetActivity
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:type n_id type:int require:1 other: desc:类型id
* @param name:end type:int require:1 other: desc:0,未结束1,已结束
* @return activity:活动@
* @activity id:id activity_name:活动名称 abstract:摘要 thumbnail:缩略图 time:时间 content:内容 province_name:省市地区
*/
public function typeGetActivity(){
$type_id=input('type');
$end=input('end');
if (empty($end)||$end==0){
$type='>=';
}else{
$type='<';
}
$Activity=new ActivityModel();
$activity=$Activity->selectTypeData($type_id,$type);
$this->success('',$activity);
}
/**
* @title 生成分享图片地址(new);
* @description 活动类型
* @author Xiaogang Wang
* @url /index/index/makePic
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id n_id type:int require:1 other: desc:活动id
*/
public function makePic(){
$id=input('id');
$activity=db('activity')->where('id',$id)->find();
$text=$activity['activity_name'];
$headimg='../upload/'.$activity['thumbnail'];
$scene=$id;
$name='1-'.$id;
$Code=new Code();
$path='../upload/qrcode/';
$name1=$Code->code($scene,'pages/img_txt/img_txt',280,$name);
$Image = new Image($path.$name1);
$circle=$Image->circle();
$Image->save('../upload/qrcode/1-'.$id.'.png','png',5);
/*生成图片*/
$image1=\think\Image::open($headimg);
$image1->thumb(595,545,\think\Image::THUMB_CENTER)->save('../upload/qrcode/2-'.$id.'.png');
$image = \think\Image::open('../static/images/background.png');
// $text='这个是一个活动名称啊啊啊';
$num=mb_strlen($text);
$cha=$num-8;
$locate[]=188-$cha*13;
$locate[]=680;
$font='../static/font-awesome/fonts/PingFang Medium.ttf';
$result=$image->water('../upload/qrcode/2-'.$id.'.png',\think\Image::WATER_NORTHWEST)->water('../static/images/bottom.png',9)
->water('../upload/qrcode/1-'.$id.'.png',5)->text($text,$font,20,'#000000',$locate)->save($path.$id.'.png');
/*清除产生的图片*/
unlink($path.'1-'.$id.'.jpg');
unlink($path.'1-'.$id.'.png');
unlink($path.'2-'.$id.'.png');
$return['url']=cmf_get_image_url('/upload/qrcode/'.$id.'.png');
$this->success('',$return);
/*
$Head=new Image('../static/images/qr.jpg');
$Head->thumb('595');
$Head->save('../upload/qrcode/2-'.$id.'.jpg');
$path2='../upload/qrcode/2-'.$id.'.jpg';
$background =new Image('../static/images/background.png');
$background->mergeImage($path2,'jpg',595,'400',0,0);
echo 111;
//$background->mergeImage('../static/images/bottom.png','jpg',595,536,'425',0);
$background->save('../upload/qrcode/3-'.$id.'.png');
echo 222;
$last=new Image('../upload/qrcode/3-'.$id.'.png');
$last->mergeImage('../static/images/bottom.png','png',595,536,425,0);
$last->mergeImage('../upload/qrcode/1-'.$id.'.png','png',595,536,477,160);
$last->save('../upload/qrcode/4-'.$id.'.png');
dump($circle);
dump($Image->get());*/
}
/**
* 添加formid
* @param $userId
* @param $formId
*/
protected function saveFormId($userId,$formId){
if ($formId=='undefined'){
return;
}
$data['user_id']=$userId;
$data['add_time']=time();
$data['value']=$formId;
$data['expire_time']=time()+604800;
db('form_id')->insert($data);
}
public function test(){
$config = [
'app_id' => 'wx3cf0f39249eb0exx',
'secret' => 'f1c242f4f28f735d4687abb469072axx',
// 指定 API 调用返回结果的类型:array(default)/collection/object/raw/自定义类名
'response_type' => 'array'
];
$app = Factory::officialAccount($config);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 15:35
*/
namespace api\index\controller;
use api\index\model\AboutModel;
use api\index\model\ContactModel;
use api\index\model\JoinModel;
use api\index\model\VolunteerModel;
use api\index\model\UserModel;
use cmf\controller\RestBaseController;
use EasyWeChat\Foundation\Application;
use think\Validate;
/**
* @title 个人中心
* @description 个人中心
*/
class MemberCenterController extends RestBaseController
{
public function _initialize()
{
$user_id = $this->getUserId();
$userModel = new UserModel();
$user = $userModel->where(array('id'=>$user_id))->find();
if($user['user_status'] == 0){
$this->error(['code'=>40005,'msg'=>'您已被列入黑名单,请联系管理员!']);
}
}
/**
* @title 个人中心
* @description 个人中心
* @author XiaoGang Wang
* @url /index/member_center/index
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return user_nickname:用户昵称
* @return level:用户星级
* @return work_time:工作时长
* @return avatar:头像
* @return type:类型(1为普通,2为管理员)
* @return is_submit:0为未提交过,1为已提交过
*/
public function index(){
$user_id = $this->getUserId();
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if(empty($result)){
$is_submit = 0;
}else {
$is_submit = 1;
}
if (empty($result['level'])){
$result['level']=0;
}
if (empty($result['work_time'])){
$result['work_time']=0;
}
$user['level']=$result['level'];
$user['work_time']=$result['work_time'];
$user['is_submit'] = $is_submit;
$this->success('获取成功!',$user);
}
/**
* @title 判断是否为管理员是否提交过申请
* @description 判断是否为管理员是否提交过申请
* @author XiaoGang Wang
* @url /index/member_center/is_submit_admin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return user_nickname:用户昵称
* @return avatar:头像
* @return type:类型(1为普通,2为管理员)
* @return is_submit:0为未提交过,1为已提交过
*/
public function is_submit_admin(){
$user_id = $this->getUserId();
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
if(empty($result)){
$is_submit = 0;
}else{
$is_submit = 1;
}
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$is_admin = 0;
}else{
$is_admin = 1;
}
$data['is_submit'] = $is_submit;
$data['is_admin'] = $is_admin;
$this->success('获取成功!',$data);
}
/**
* @title 提交审核
* @description 提交审核
* @author XiaoGang Wang
* @url /index/member_center/submit_form
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:form_id type:str require:1 other: desc:表单id
* @param name:name type:str require:1 other: desc:姓名
* @param name:sex type:str require:1 other: desc:性别(1男,2女)
* @param name:birthday type:str require:1 other: desc:生日
* @param name:nation type:str require:1 other: desc:民族
* @param name:politics type:str require:1 other: desc:政治面貌
* @param name:education type:str require:1 other: desc:学历
* @param name:unit type:str require:1 other: desc:工作单位
* @param name:duty type:str require:1 other: desc:职务
* @param name:addr type:str require:1 other: desc:通讯地址
* @param name:postcode type:str require:1 other: desc:邮编
* @param name:school type:str require:1 other: desc:毕业院校
* @param name:card_number type:str require:1 other: desc:身份证号码
* @param name:fixed_phone type:str require:1 other: desc:固定电话
* @param name:move_phone type:str require:1 other: desc:移动电话
* @param name:email type:str require:1 other: desc:email
* @param name:urgency_phone type:str require:1 other: desc:紧急联系人电话
* @param name:qq type:str require:1 other: desc:qq
* @param name:province type:str require:1 other: desc:省
* @param name:city type:str require:1 other: desc:市
* @param name:county type:str require:1 other: desc:区/县
* @param name:address type:str require:1 other: desc:详细地址
* @param name:type type:int require:1 other: desc:1医院志愿者,2社会志愿者,3办事处志愿者
* @param name:record_start_time type:str require:1 other: desc:开始时间
* @param name:record_end_time type:str require:1 other: desc:结束时间
* @param name:record_unit type:str require:1 other: desc:单位
* @param name:record_duty type:str require:1 other: desc:职务
* @param name:record_name type:str require:1 other: desc:证明人
* @param name:record_phone type:str require:1 other: desc:证明人电话
* @param name:front_card type:str require:1 other: desc:身份证正面照
* @param name:reverse_card type:str require:1 other: desc:身份证背面照
* @param name:photo type:str require:1 other: desc:照片
*/
public function submit_form(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'name' => 'require',
'sex' => 'require',
'birthday' => 'require',
'nation' => 'require',
'politics' => 'require',
'education' => 'require',
'unit' => 'require',
'duty' => 'require',
'addr' => 'require',
'postcode' => 'require',
'school' => 'require',
'card_number' => 'require',
// 'fixed_phone' => 'require',
'move_phone' => 'require',
'email' => 'require',
'urgency_phone' => 'require',
'qq' => 'require',
'province' => 'require',
'city' => 'require',
// 'county' => 'require',
'address' => 'require',
'record_start_time' => 'require',
'record_end_time' => 'require',
'record_unit' => 'require',
'record_duty' => 'require',
'record_name' => 'require',
'record_phone' => 'require',
'front_card' => 'require',
'reverse_card' => 'require',
'photo' => 'require',
]);
$validate->message([
'name' => '缺少参数name',
'sex' => '缺少参数sex',
'birthday' => '缺少参数birthday',
'nation' => '缺少参数nation',
'politics' => '缺少参数politics',
'education' => '缺少参数education',
'unit' => '缺少参数unit',
'duty' => '缺少参数duty',
'addr' => '缺少参数addr',
'postcode' => '缺少参数postcode',
'school' => '缺少参数school',
'card_number' => '缺少参数card_number',
// 'fixed_phone' => '缺少参数fixed_phone',
'move_phone' => '缺少参数move_phone',
'email' => '缺少参数email',
'urgency_phone' => '缺少参数urgency_phone',
'qq' => '缺少参数qq',
'province' => '缺少参数province',
'city' => '缺少参数city',
// 'county' => '缺少参数county',
'address' => '缺少参数address',
'record_start_time' => '缺少参数record_start_time',
'record_end_time' => '缺少参数record_end_time',
'record_unit' => '缺少参数record_unit',
'record_duty' => '缺少参数record_duty',
'record_name' => '缺少参数record_name',
'record_phone' => '缺少参数record_phone',
'front_card' => '缺少参数front_card',
'reverse_card' => '缺少参数reverse_card',
'photo' => '缺少参数photo',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$record_start_time = explode(',',$param['record_start_time']);
$record_end_time = explode(',',$param['record_end_time']);
$record_unit = explode(',',$param['record_unit']);
$record_duty = explode(',',$param['record_duty']);
$record_name = explode(',',$param['record_name']);
$record_phone = explode(',',$param['record_phone']);
$record = [];
foreach($record_start_time as $key => $r_s_t){
$record[$key]['record_start_time'] = !empty($r_s_t) ? $r_s_t : '';
$record[$key]['record_end_time'] = !empty($record_end_time[$key]) ? $record_end_time[$key] : '';
$record[$key]['record_unit'] = !empty($record_unit[$key]) ? $record_unit[$key] :'';
$record[$key]['record_duty'] = !empty($record_duty[$key]) ? $record_duty[$key] :'';
$record[$key]['record_name'] = !empty($record_name[$key]) ? $record_name[$key] :'';
$record[$key]['record_phone'] = !empty($record_phone[$key]) ? $record_phone[$key] :'';
}
if(!empty($record)){
$record = json_encode($record);
}else{
$record = null;
}
$data = [
'name' => $param['name'],
'sex' => $param['sex'],
'birthday' => $param['birthday'],
'nation' => $param['nation'],
'politics' => $param['politics'],
'education' => $param['education'],
'unit' => $param['unit'],
'duty' => $param['duty'],
'addr' => $param['addr'],
'postcode' => $param['postcode'],
'school' => $param['school'],
'card_number' => $param['card_number'],
'fixed_phone' => $param['fixed_phone'],
'move_phone' => $param['move_phone'],
'email' => $param['email'],
'urgency_phone' => $param['urgency_phone'],
'qq' => $param['qq'],
'province' => $param['province'],
'city' => $param['city'],
'county' => !empty($param['county'])?$param['county']:null,
'address' => $param['address'],
/* 'type' => $param['type'],*/
'record' => $record,
'front_card' => $param['front_card'],
'reverse_card' => $param['reverse_card'],
'photo' => $param['photo'],
'status' => 1,
'user_id' => $user_id,
];
$form_id=input('form_id');
if (empty($form_id)){
$this->saveFormId($user_id,$form_id);
}
$volunteerModel = new VolunteerModel();
$result1 = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
//判断该用户是否提交过
if(!empty($result1)){
$data['update_time'] = time();
$volunteerModel->updateData(array('id'=>$result1['id']),$data);
}else{
$data['create_time'] = time();
$volunteerModel->insertData($data);
}
$this->success('提交成功!');
}
/**
* @title 进入修改页面
* @description 进入修改页面
* @author XiaoGang Wang
* @url /index/member_center/edit
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return name:姓名
* @return sex:性别(1男,2女)
* @return birthday:生日
* @return nation:民族
* @return politics:政治面貌
* @return education:学历
* @return unit:工作单位
* @return duty:职务
* @return addr:通讯地址
* @return postcode:邮编
* @return school: desc:毕业院校
* @return card_number :身份证号码
* @return fixed_phone:固定电话
* @return move_phone:移动电话
* @return email:email
* @return urgency_phone:紧急联系人电话
* @return qq:qq
* @return province:省
* @return city:市
* @return county:区/县
* @return address:详细地址
* @return type:1医院志愿者,2社会志愿者,3办事处志愿者
* @return record_start_time:开始时间
* @return record_end_time:结束时间
* @return record_unit:单位
* @return record_duty:职务
* @return record_name:证明人
* @return record_phone:证明人电话
* @return front_card type:str require:1 other: desc:身份证正面照
* @return reverse_card:身份证背面照
* @return photo:照片
*/
public function edit(){
// $user_id = $this->getUserId();
$user_id = $this->request->param('id');
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
$this->success('获取成功!',$result);
}
/**
* @title 查看审核状态
* @description 查看审核状态
* @author XiaoGang Wang
* @url /index/member_center/status
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return status:状态(1审核中,2审核成功,3审核失败)
*/
public function status(){
$user_id = $this->getUserId();
$volunteerModel = new VolunteerModel();
$data = $volunteerModel->findData(array('user_id'=>$user_id));
if(empty($data)){
$this->success(['code'=>40001,'msg'=>'您还没有提交过申请!']);
}
$this->success('获取成功!',$data);
}
/**
* @title 管理员审核
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/admin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*/
public function admin(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$param = $this->request->param();
$page = !empty($param['page']) ? $param['page'] : 0;//当前页数下标
$pageNum = !empty($param['pageNum']) ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
// $volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>['in','1,2']));
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>'1'));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 工时管理列表(new)
* @description
* @author XiaoGang Wang
* @url /index/member_center/addTimeList
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*
*/
public function addTimeList(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$param = $this->request->param();
$page = !empty($param['page']) ? $param['page'] : 0;//当前页数下标
$pageNum = !empty($param['pageNum']) ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
// $volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>['in','1,2']));
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>'2'));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 管理员添加时间(new)
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/addTime
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:add_time type:int require:0 other: desc:添加时间
* @param name:user_id type:int require:0 other: desc:用户id
*
*/
public function addTime(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$map['user_id']=input('user_id');
$time=input('add_time');
// $data['add_time']=['exp','work_time'+$time];
$result=db('volunteer')->where($map)->setInc('work_time',$time);
// echo db('volunteer')->getLastSql();
if ($result>0){
$this->success('修改成功!');
}else{
$this->error('此人不是审核通过的志愿者!');
}
}
/**
* @title 管理员查看活动申请详情
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/adminGetApplyInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:join_id type:int require:0 other: desc:报名id
*
*/
public function adminGetApplyInfo(){
$map['id']=input('join_id');
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
/*获取*/
if (!empty($return['time'])){
$return['time']= array_reverse($return['time']);
}
$info=db('join')->field('sgin_time,id,type,user_id,activity_id,select_time,apply_stay,apply_food,work_content')->where($map)->find();
$user=db('volunteer')->field('sex,name,birthday,move_phone')->where('user_id',$info['user_id'])->find();
if (!empty($user)){
$return['name']=$user['name'];
$return['birthday']=$user['birthday'];
$return['sex']=$user['sex']==1?'男':'女';
$return['tel']=$user['move_phone'];
}
if (!empty($info)){
$return['work_content']=db('work')->where('id',$info['work_content'])->value('name');
$return['work_content']=$info['work_content'];
$return['select_time']=json_decode($info['select_time'],true);
$return['apply_stay']=json_decode($info['apply_stay'],true);
$return['apply_food']=json_decode($info['apply_food'],true);
$return['id']=$info['id'];
$return['work_type']=$info['type'];
$return['is_complete']=$info['sgin_time']==0?'0':'1';
/* switch ($info['type']){
case 1:
$return['work_type']='线上';
break;
case 2:
$return['work_type']='线下';
break;
case 3:
$return['work_type']='线上及线下';
break;
}*/
}
$this->success('',$return);
}
/**
* @title 管理员更新状态
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/update_status
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:志愿者id
* @param name:status type:int require:1 other: desc:状态(点击审核通过传2,点击审核失败传3)
* @param name:refund_reason type:int require:1 other: desc:审核不通过原因
*/
public function update_status(){
$user_id = $this->getUserId();
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少参数id');
}
$status = $this->request->param('status');
if(empty($status)){
$this->error('缺少参数status');
}
if($status != 2 && $status != 3){
$this->error('status参数错误!');
}
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
//获取志愿者
$volunteerModel = new VolunteerModel();
$data['status']=input('status');
if ($data['status']==2){
$keyword='审核通过';
}else{
$keyword='审核未通过';
}
$data['refund_reason']=input('refund_reason')??'';
$result = $volunteerModel->updateData(array('id'=>$id),$data);
if(empty($result)){
$this->success(['code'=>40002,'msg'=>'当前申请可能已被其他管理员审核,请刷新页面!']);
}
$userMap['user_id']=$id;
$openid=db('third_party_user')->where($userMap)->value('openid');
$volunteer=db('volunteer')->where('id',$id)->find();
$formMap['user_id']=$id;
$formMap['use_time']=0;
$formMap['expire_time']=['>',time()];
$form_id=\db('form_id')->where($formMap)->find();
$data['keyword1']= $volunteer['name'];
$data['keyword2']='志愿者审核';
$data['keyword3']=$keyword;
$data['keyword4']='志愿者审核';
$message = [
'touser' => $openid,
'template_id' => '1FYkLuMK8LNKO4_nxJ_DuNQhgIjaaJQlAukgt92C-uw',
'page' => 'pages/index/index',
'form_id' => $form_id['value'],
'data' => $data,
'emphasis_keyword' =>$data['keyword3']='状态',
];
$this->wxappNotice($message);
$this->success(['code'=>20000,'msg'=>'更新成功!']);
}
/**
* @title 获取人员参与状态
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/getJoinPerson
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
* @return photo:摄影(设备自带)
* @return camera:摄像(设备自带)
* @return motorcade:爱心车队
* @return service:现场服务(签到、指引、礼仪等)
* @return question:线上答疑
* @return ill:门诊服务
* @return name:status0,未审核1,已通过2,未通过3,已填写工作汇报(已通过)
*/
public function getJoinPerson(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
//活动id
$id=input('id');
$map['activity_id']=$id;
$map['j.delete_time']=0;
$info=db('join')->alias('j')
->group('j.user_id')
->field('v.*,j.*,j.id as join_id,j.status as status')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->order('j.id','desc')
->select()
->toArray();
$return=[];
$i0=0;
$i1=0;
$i2=0;
$i3=0;
$i4=0;
$i5=0;
foreach($info as $k=>$v){
switch ($v['work_content']){
case 1:
$return[0]['title']='摄影(设备自带)';
$return[0]['arr'][$i0]['id']=$v['join_id'];
$return[0]['arr'][$i0]['photo']=$v['photo'];
$return[0]['arr'][$i0]['name']=$v['name'];
$return[0]['arr'][$i0]['user_id']=$v['user_id'];
$return[0]['arr'][$i0]['status']=$this->switchStatus($v['status']);
$i0++;
break;
case 2:
$return[1]['title']='摄像(设备自带)';
$return[1]['arr'][$i1]['id']=$v['join_id'];
$return[1]['arr'][$i1]['photo']=$v['photo'];
$return[1]['arr'][$i1]['name']=$v['name'];
$return[1]['arr'][$i1]['user_id']=$v['user_id'];
$return[1]['arr'][$i1]['status']=$this->switchStatus($v['status']);
$i1++;
break;
case 3:
$return[2]['title']='爱心车队';
$return[2]['arr'][$i2]['id']=$v['join_id'];
$return[2]['arr'][$i2]['photo']=$v['photo'];
$return[2]['arr'][$i2]['name']=$v['name'];
$return[2]['arr'][$i2]['user_id']=$v['user_id'];
$return[2]['arr'][$i2]['status']=$this->switchStatus($v['status']);
$i2++;
break;
case 4:
$return[3]['title']='现场服务(签到、指引、礼仪等)';
$return[3]['arr'][$i3]['id']=$v['join_id'];
$return[3]['arr'][$i3]['photo']=$v['photo'];
$return[3]['arr'][$i3]['name']=$v['name'];
$return[3]['arr'][$i3]['user_id']=$v['user_id'];
$return[3]['arr'][$i3]['status']=$this->switchStatus($v['status']);
$i3++;
break;
case 5:
$return[4]['title']='线上答疑';
$return[4]['arr'][$i4]['id']=$v['join_id'];
$return[4]['arr'][$i4]['photo']=$v['photo'];
$return[4]['arr'][$i4]['name']=$v['name'];
$return[4]['arr'][$i4]['user_id']=$v['user_id'];
$return[4]['arr'][$i4]['status']=$this->switchStatus($v['status']);
$i4++;
break;
case 6:
$return[5]['title']='门诊服务';
/*判断是否有user_id*/
$return[5]['arr'][$i5]['id']=$v['join_id'];
$return[5]['arr'][$i5]['photo']=$v['photo'];
$return[5]['arr'][$i5]['name']=$v['name'];
$return[5]['arr'][$i5]['user_id']=$v['user_id'];
$return[5]['arr'][$i5]['status']=$this->switchStatus($v['status']);
$i5++;
break;
}
}
foreach ($return as $k=>$v){
foreach($return[$k] as $k1=>$v1){
}
}
$this->success('',$return);
}
/**
* @title 管理员审核活动申请是否通过(new)
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/adminApprove
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:参加id
* @param name:status type:int require:1 other: desc:1通过2.拒绝
* @param name:refund_reason type:int require:1 other: desc:拒绝理由
*
*
*/
public function adminApprove(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$map['id']=input('id');
$data['status']=input('status');
$refund_reason=input('refund_reason');
if (!empty($refund_reason)){
$data['refund_reason']=input('refund_reason');
}
$result=db('join')->where($map)->update($data);
if ($result>0){
$join=\db('join')->where($map)->find();
$activity=\db('activity')->where('id',$join['activity_id'])->find();
$userMap['user_id']=$join['user_id'];
$openid=db('third_party_user')->where($userMap)->value('openid');
$volunteer=\db('volunteer')->where('user_id',$join['user_id'])->find();
$formMap['user_id']=$join['user_id'];
$formMap['use_time']=0;
$formMap['expire_time']=['>',time()];
$form_id=\db('form_id')->where($formMap)->find();
if ($data['status']==1){
if (!empty($form_id)){
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>time()]);
$data['keyword1']= $volunteer['name'];
$data['keyword2']='活动审核';
$data['keyword3']='通过';
$data['keyword4']=$activity['activity_name'];
$message = [
'touser' => $openid,
'template_id' => '1FYkLuMK8LNKO4_nxJ_DuNQhgIjaaJQlAukgt92C-uw',
'page' => 'pages/index/index',
'form_id' => $form_id['value'],
'data' => $data,
'emphasis_keyword' =>$data['keyword3'],
];
$this->wxappNotice($message);
}
}else{
if (!empty($form_id)){
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>time()]);
$data['keyword1']= $volunteer['name'];
$data['keyword2']='活动审核';
$data['keyword3']='未通过';
$data['keyword4']=$activity['activity_name'];
$message = [
'touser' => $openid,
'template_id' => '1FYkLuMK8LNKO4_nxJ_DuNQhgIjaaJQlAukgt92C-uw',
'page' => 'pages/index/index',
'form_id' => $form_id['value'],
'data' => $data,
'emphasis_keyword' =>$data['keyword3'],
];
$this->wxappNotice($message);
}
}
$this->success('更新成功!');
}else{
$this->error('操作失败!');
}
}
protected function wxappNotice($message){
$appId = 'wx7a3bf4e0796c070a';
$secret = '755478f064e09a8301345e0c427c6cf3';
$config = [
'app_id' => $appId,
'secret' => $secret,
];
$wechat=new Application($config);
$notice=$wechat->mini_program->notice;
try{
$result= $notice->send($message);
}catch(Exception $e){
$e->getMessage();
}
return $result;
}
protected function switchStatus($status){
switch ($status){
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
}
}
/**
* @title 关于我们
* @description 关于我们
* @author XiaoGang Wang
* @url /index/member_center/about
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function about(){
$aboutModel = new AboutModel();
$data = $aboutModel->findData(array('id'=>1));
$this->success('获取成功!',$data);
}
/**
* @title 联系我们
* @description 联系我们
* @author XiaoGang Wang
* @url /index/member_center/contact
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function contact(){
$contactModel = new ContactModel();
$data = $contactModel->findData(array('id'=>1));
$this->success('获取成功!',$data);
}
/**
* @title 我参加的活动
* @description 参加过的活动
* @author XiaoGang Wang
* @url /index/member_center/joined
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function joined(){
$userId=$this->getUserId();
$Join=new JoinModel();
$join=$Join->getUserJoin($userId);
foreach ($join as $k=>$v){
$join[$k]['thumbnail']=cmf_get_image_url($v['thumbnail']);
$join[$k]['create_time']=date('Y-m-d',$v['create_time']);
}
$this->success('',$join);
}
protected function saveFormId($userId,$formId){
if ($formId=='undefined'){
return;
}
$data['user_id']=$userId;
$data['add_time']=time();
$data['value']=$formId;
$data['expire_time']=time()+604800;
db('form_id')->insert($data);
}
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 15:35
*/
namespace api\index\controller;
use api\index\model\AboutModel;
use api\index\model\ContactModel;
use api\index\model\JoinModel;
use api\index\model\VolunteerModel;
use api\index\model\UserModel;
use cmf\controller\RestBaseController;
use EasyWeChat\Foundation\Application;
use think\Db;
use think\Validate;
/**
* @title 个人中心
* @description 个人中心
*/
class MemberCenterController extends RestBaseController
{
public function _initialize()
{
$user_id = $this->getUserId();
$userModel = new UserModel();
$user = $userModel->where(array('id'=>$user_id))->find();
if($user['user_status'] == 0){
$this->error(['code'=>40005,'msg'=>'您已被列入黑名单,请联系管理员!']);
}
}
/**
* @title 个人中心
* @description 个人中心
* @author XiaoGang Wang
* @url /index/member_center/index
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return user_nickname:用户昵称
* @return level:用户星级
* @return work_time:工作时长
* @return avatar:头像
* @return type:类型(1为普通,2为管理员)
* @return is_submit:0为未提交过,1为已提交过
*/
public function index(){
$user_id = $this->getUserId();
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
// dump($result->toArray());
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if(empty($result)){
$is_submit = 0;
}else {
$user['avatar']=$result['photo'];
$user['user_nickname']=$result['name'];
$is_submit = 1;
}
if (empty($result['level'])){
$result['level']=0;
}
if (empty($result['work_time'])){
$result['work_time']=0;
}
$user['level']=$result['level'];
$user['work_time']=$result['work_time'];
$user['is_submit'] = $is_submit;
$this->success('获取成功!',$user);
}
/**
* @title 判断是否为管理员是否提交过申请
* @description 判断是否为管理员是否提交过申请
* @author XiaoGang Wang
* @url /index/member_center/is_submit_admin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return user_nickname:用户昵称
* @return avatar:头像
* @return type:类型(1为普通,2为管理员)
* @return is_submit:0为未提交过,1为已提交过
*/
public function is_submit_admin(){
$user_id = $this->getUserId();
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
if(empty($result)){
$is_submit = 0;
}else{
$is_submit = 1;
}
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$is_admin = 0;
}else{
$is_admin = 1;
}
$data['is_submit'] = $is_submit;
$data['is_admin'] = $is_admin;
$this->success('获取成功!',$data);
}
/**
* @title 提交审核
* @description 提交审核
* @author XiaoGang Wang
* @url /index/member_center/submit_form
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:form_id type:str require:1 other: desc:表单id
* @param name:name type:str require:1 other: desc:姓名
* @param name:sex type:str require:1 other: desc:性别(1男,2女)
* @param name:birthday type:str require:1 other: desc:生日
* @param name:nation type:str require:1 other: desc:民族
* @param name:politics type:str require:1 other: desc:政治面貌
* @param name:education type:str require:1 other: desc:学历
* @param name:unit type:str require:1 other: desc:工作单位
* @param name:duty type:str require:1 other: desc:职务
* @param name:addr type:str require:1 other: desc:通讯地址
* @param name:postcode type:str require:1 other: desc:邮编
* @param name:school type:str require:1 other: desc:毕业院校
* @param name:card_number type:str require:1 other: desc:身份证号码
* @param name:fixed_phone type:str require:1 other: desc:固定电话
* @param name:move_phone type:str require:1 other: desc:移动电话
* @param name:email type:str require:1 other: desc:email
* @param name:urgency_phone type:str require:1 other: desc:紧急联系人电话
* @param name:qq type:str require:1 other: desc:qq
* @param name:province type:str require:1 other: desc:省
* @param name:city type:str require:1 other: desc:市
* @param name:county type:str require:1 other: desc:区/县
* @param name:address type:str require:1 other: desc:详细地址
* @param name:type type:int require:1 other: desc:1医院志愿者,2社会志愿者,3办事处志愿者
* @param name:record_start_time type:str require:1 other: desc:开始时间
* @param name:record_end_time type:str require:1 other: desc:结束时间
* @param name:record_unit type:str require:1 other: desc:单位
* @param name:record_duty type:str require:1 other: desc:职务
* @param name:record_name type:str require:1 other: desc:证明人
* @param name:record_phone type:str require:1 other: desc:证明人电话
* @param name:front_card type:str require:1 other: desc:身份证正面照
* @param name:reverse_card type:str require:1 other: desc:身份证背面照
* @param name:photo type:str require:1 other: desc:照片
*/
public function submit_form(){
$user_id = $this->getUserId();
$param = $this->request->param();
$validate = new Validate([
'name' => 'require',
'sex' => 'require',
'birthday' => 'require',
'nation' => 'require',
'politics' => 'require',
'education' => 'require',
'unit' => 'require',
'duty' => 'require',
'addr' => 'require',
'postcode' => 'require',
'school' => 'require',
'card_number' => 'require',
// 'fixed_phone' => 'require',
'move_phone' => 'require',
'email' => 'require',
'urgency_phone' => 'require',
'qq' => 'require',
'province' => 'require',
'city' => 'require',
// 'county' => 'require',
'address' => 'require',
'record_start_time' => 'require',
'record_end_time' => 'require',
'record_unit' => 'require',
'record_duty' => 'require',
'record_name' => 'require',
'record_phone' => 'require',
'front_card' => 'require',
'reverse_card' => 'require',
'photo' => 'require',
]);
$validate->message([
'name' => '缺少参数name',
'sex' => '缺少参数sex',
'birthday' => '缺少参数birthday',
'nation' => '缺少参数nation',
'politics' => '缺少参数politics',
'education' => '缺少参数education',
'unit' => '缺少参数unit',
'duty' => '缺少参数duty',
'addr' => '缺少参数addr',
'postcode' => '缺少参数postcode',
'school' => '缺少参数school',
'card_number' => '缺少参数card_number',
// 'fixed_phone' => '缺少参数fixed_phone',
'move_phone' => '缺少参数move_phone',
'email' => '缺少参数email',
'urgency_phone' => '缺少参数urgency_phone',
'qq' => '缺少参数qq',
'province' => '缺少参数province',
'city' => '缺少参数city',
// 'county' => '缺少参数county',
'address' => '缺少参数address',
'record_start_time' => '缺少参数record_start_time',
'record_end_time' => '缺少参数record_end_time',
'record_unit' => '缺少参数record_unit',
'record_duty' => '缺少参数record_duty',
'record_name' => '缺少参数record_name',
'record_phone' => '缺少参数record_phone',
'front_card' => '缺少参数front_card',
'reverse_card' => '缺少参数reverse_card',
'photo' => '缺少参数photo',
]);
if (!$validate->check($param)) {
$this->error($validate->getError());
}
$record_start_time = explode(',',$param['record_start_time']);
$record_end_time = explode(',',$param['record_end_time']);
$record_unit = explode(',',$param['record_unit']);
$record_duty = explode(',',$param['record_duty']);
$record_name = explode(',',$param['record_name']);
$record_phone = explode(',',$param['record_phone']);
$record = [];
foreach($record_start_time as $key => $r_s_t){
$record[$key]['record_start_time'] = !empty($r_s_t) ? $r_s_t : '';
$record[$key]['record_end_time'] = !empty($record_end_time[$key]) ? $record_end_time[$key] : '';
$record[$key]['record_unit'] = !empty($record_unit[$key]) ? $record_unit[$key] :'';
$record[$key]['record_duty'] = !empty($record_duty[$key]) ? $record_duty[$key] :'';
$record[$key]['record_name'] = !empty($record_name[$key]) ? $record_name[$key] :'';
$record[$key]['record_phone'] = !empty($record_phone[$key]) ? $record_phone[$key] :'';
}
if(!empty($record)){
$record = json_encode($record);
}else{
$record = null;
}
$data = [
'name' => $param['name'],
'sex' => $param['sex'],
'birthday' => $param['birthday'],
'nation' => $param['nation'],
'politics' => $param['politics'],
'education' => $param['education'],
'unit' => $param['unit'],
'duty' => $param['duty'],
'addr' => $param['addr'],
'postcode' => $param['postcode'],
'school' => $param['school'],
'card_number' => $param['card_number'],
'fixed_phone' => $param['fixed_phone'],
'move_phone' => $param['move_phone'],
'email' => $param['email'],
'urgency_phone' => $param['urgency_phone'],
'qq' => $param['qq'],
'province' => $param['province'],
'city' => $param['city'],
'county' => !empty($param['county'])?$param['county']:null,
'address' => $param['address'],
/* 'type' => $param['type'],*/
'record' => $record,
'front_card' => $param['front_card'],
'reverse_card' => $param['reverse_card'],
'photo' => $param['photo'],
'status' => 1,
'user_id' => $user_id,
];
$form_id=input('form_id');
if (!empty($form_id)){
$this->saveFormId($user_id,$form_id);
}
$volunteerModel = new VolunteerModel();
$result1 = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
//判断该用户是否提交过
if(!empty($result1)){
$data['update_time'] = time();
$volunteerModel->updateData(array('id'=>$result1['id']),$data);
}else{
$data['create_time'] = time();
$volunteerModel->insertData($data);
}
$this->success('提交成功!');
}
/**
* @title 进入修改页面
* @description 进入修改页面
* @author XiaoGang Wang
* @url /index/member_center/edit
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return name:姓名
* @return sex:性别(1男,2女)
* @return birthday:生日
* @return nation:民族
* @return politics:政治面貌
* @return education:学历
* @return unit:工作单位
* @return duty:职务
* @return addr:通讯地址
* @return postcode:邮编
* @return school: desc:毕业院校
* @return card_number :身份证号码
* @return fixed_phone:固定电话
* @return move_phone:移动电话
* @return email:email
* @return urgency_phone:紧急联系人电话
* @return qq:qq
* @return province:省
* @return city:市
* @return county:区/县
* @return address:详细地址
* @return type:1医院志愿者,2社会志愿者,3办事处志愿者
* @return record_start_time:开始时间
* @return record_end_time:结束时间
* @return record_unit:单位
* @return record_duty:职务
* @return record_name:证明人
* @return record_phone:证明人电话
* @return front_card type:str require:1 other: desc:身份证正面照
* @return reverse_card:身份证背面照
* @return photo:照片
*/
public function edit(){
// $user_id = $this->getUserId();
$user_id = $this->request->param('id');
//判断当前用户是否提交过
$volunteerModel = new VolunteerModel();
$result = $volunteerModel->findData(array('user_id'=>$user_id,'delete_time'=>0));
$this->success('获取成功!',$result);
}
/**
* @title 查看审核状态
* @description 查看审核状态
* @author XiaoGang Wang
* @url /index/member_center/status
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @return id:id
* @return status:状态(1审核中,2审核成功,3审核失败)
*/
public function status(){
$user_id = $this->getUserId();
$volunteerModel = new VolunteerModel();
$data = $volunteerModel->findData(array('user_id'=>$user_id));
if(empty($data)){
$this->success(['code'=>40001,'msg'=>'您还没有提交过申请!']);
}
$this->success('获取成功!',$data);
}
/**
* @title 管理员审核
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/admin
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*/
public function admin(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$param = $this->request->param();
$page = !empty($param['page']) ? $param['page'] : 0;//当前页数下标
$pageNum = !empty($param['pageNum']) ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
// $volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>['in','1,2']));
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>'1'));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 工时管理列表(new)
* @description
* @author XiaoGang Wang
* @url /index/member_center/addTimeList
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:page type:int require:0 other: desc:志愿者当前页(0为第一页)(默认0)
* @param name:pageNum type:int require:0 other: desc:活动显示数量(默认10)
*
* @return volunteer:志愿者@
* @volunteer id:id name:姓名 sex:性别 birthday:生日 nation:民族 politics:政治面貌 education:学历 unit:工作单位 duty:职务 addr:通讯地址 postcode:邮编 school:毕业院校 card_number:身份证号 fixed_phone:固定电话 move_phone:移动电话 email:email urgency_phone:紧急联系电话 qq:qq province:省 city:市 county:区/县 address:详细地址 type:志愿者类型(0医院志愿者,2社会志愿者,3办事处志愿者) record:个人履历@ front_card:身份证正面照 reverse_card:身份证背面照 photo:照片 status:状态(1审核中,2审核成功,3审核失败) user_id:用户id
* @record record_start_time:开始时间 record_end_time:结束时间 record_unit:单位 record_duty:职务 record_name:证明人 record_phone:证明人电话
* @return page:志愿者下一页
* @return page:活动下一页
*
*/
public function addTimeList(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$param = $this->request->param();
$page = !empty($param['page']) ? $param['page'] : 0;//当前页数下标
$pageNum = !empty($param['pageNum']) ? $param['pageNum'] : 10;//每页显示几条数据
//获取志愿者
$volunteerModel = new VolunteerModel();
// $volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>['in','1,2']));
$volunteer = $volunteerModel->selectData($page,$pageNum,array('status'=>'2'));
$data['volunteer'] = $volunteer;
$data['page'] = $page+1;
$this->success('获取成功!',$data);
}
/**
* @title 管理员添加时间(new)
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/addTime
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:join_id type:int require:0 other: desc:参加id
*
*/
public function addTime(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$map['id']=input('join_id');
$time=input('add_time');
$user_id1=input('user_id');
if (empty($user_id1)){
$join=\db('join')->where($map)->find();
if (empty($join)){
$this->error('参数错误');
}
$joinUpdate['work_time']=$time;
\db('join')->where($map)->update($joinUpdate);
if ($time>$join['work_time']){
$add_time=$time-$join['work_time'];
$volunteerUpdate['work_time']=$add_time;
\db('volunteer')->where('user_id',$join['user_id'])->setInc('work_time',$add_time);
}else{
$add_time=$join['work_time']-$time;
\db('volunteer')->where('user_id',$join['user_id'])->setDec('work_time',$add_time);
}
}else{
\db('volunteer')->where('user_id',$user_id1)->setInc('work_time',$time);
}
$result=1;
/* // $data['add_time']=['exp','work_time'+$time];
$result=db('volunteer')->where($map)->setInc('work_time',$time);
// echo db('volunteer')->getLastSql();*/
if ($result>0){
$this->success('修改成功!');
}else{
$this->error('此人不是审核通过的志愿者!');
}
}
/**
* @title 管理员查看活动申请详情
* @description 管理员审核
* @author XiaoGang Wang
* @url /index/member_center/adminGetApplyInfo
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:join_id type:int require:0 other: desc:报名id
*
*/
public function adminGetApplyInfo(){
$map['id']=input('join_id');
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
/*获取*/
if (!empty($return['time'])){
$return['time']= array_reverse($return['time']);
}
$info=db('join')->field('card_number,sgin_time,id,type,user_id,activity_id,select_time,apply_stay,apply_food,work_content')->where($map)->find();
$user=db('volunteer')->field('card_number,sex,name,birthday,move_phone')->where('user_id',$info['user_id'])->find();
if (!empty($user)){
$return['name']=$user['name'];
$return['birthday']=$user['birthday'];
$return['sex']=$user['sex']==1?'男':'女';
$return['tel']=$user['move_phone'];
}
if (!empty($info)){
$return['work_content']=db('work')->where('id',$info['work_content'])->value('name');
$return['work_content']=$info['work_content'];
$return['select_time']=json_decode($info['select_time'],true);
$return['apply_stay']=json_decode($info['apply_stay'],true);
$return['apply_food']=json_decode($info['apply_food'],true);
$return['id']=$info['id'];
$return['work_type']=$info['type'];
$return['card_number']=$user['card_number'];
$return['is_complete']=$info['sgin_time']==0?'0':'1';
/* switch ($info['type']){
case 1:
$return['work_type']='线上';
break;
case 2:
$return['work_type']='线下';
break;
case 3:
$return['work_type']='线上及线下';
break;
}*/
}
$this->success('',$return);
}
/**
* @title 管理员更新状态
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/update_status
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:志愿者id
* @param name:status type:int require:1 other: desc:状态(点击审核通过传2,点击审核失败传3)
* @param name:refund_reason type:int require:1 other: desc:审核不通过原因
*/
public function update_status(){
$user_id = $this->getUserId();
$id = $this->request->param('id');
if(empty($id)){
$this->error('缺少参数id');
}
$data['refund_reason']=input('refund_reason')??'';
$status = $this->request->param('status');
if(empty($status)){
$this->error('缺少参数status');
}
if($status != 2 && $status != 3){
$this->error('status参数错误!');
}
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
//获取志愿者
$volunteerModel = new VolunteerModel();
$data['status']=input('status');
if ($data['status']==2){
$keyword='审核通过';
}else{
$keyword="审核未通过 原因:$data[refund_reason]";
}
$result = $volunteerModel->updateData(array('id'=>$id),$data);
if(empty($result)){
$this->success(['code'=>40002,'msg'=>'当前申请可能已被其他管理员审核,请刷新页面!']);
}
$volunteer=db('volunteer')->where('id',$id)->find();
$userMap['user_id']=$volunteer['user_id'];
$openid=db('third_party_user')->where($userMap)->value('openid');
$formMap['user_id']=$volunteer['user_id'];
$formMap['use_time']=0;
$formMap['expire_time']=['>',time()];
$form_id=\db('form_id')->where($formMap)->find();
$now=time();
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>$now]);
if (!empty($form_id)){
$data['keyword1']= $volunteer['name'];
$data['keyword2']='志愿者审核';
$data['keyword3']=$keyword;
$data['keyword4']='志愿者审核';
$message = [
'touser' => $openid,
'template_id' => '1FYkLuMK8LNKO4_nxJ_DuNQhgIjaaJQlAukgt92C-uw',
'page' => 'pages/index/index',
'form_id' => $form_id['value'],
'data' => $data,
'emphasis_keyword' =>$data['keyword3']='状态',
];
$this->wxappNotice($message);
}
$this->success(['code'=>20000,'msg'=>'更新成功!']);
}
/**
* @title 获取人员参与状态
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/getJoinPerson
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:活动id
*
* @return photo:摄影(设备自带)
* @return camera:摄像(设备自带)
* @return motorcade:爱心车队
* @return service:现场服务(签到、指引、礼仪等)
* @return question:线上答疑
* @return ill:门诊服务
* @return name:status0,未审核1,已通过2,未通过3,已填写工作汇报(已通过)
*/
public function getJoinPerson(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
//活动id
$id=input('id');
$map['activity_id']=$id;
$map['j.delete_time']=0;
/* $info=db('join')->alias('j')
->group('j.user_id')
->field('v.*,j.*,j.id as join_id,j.status as status')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->order('j.id','asc')
->select()
->toArray();*/
/* $subQuery = db('join')->alias('j')
->field('j.user_id,v.name,v.photo,j.id as join_id,j.status as status,j.delete_time,j.activity_id,j.work_content')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->order('j.id','desc')
->buildSql();
dump($subQuery);
$info= Db::table($subQuery.'a')
->group('a.user_id')
->select()
->toArray();*/
$new_map=[];
$subQuery = db('join')->alias('j')
->field('max(j.id)')
->join('volunteer v','v.user_id=j.user_id')
->where($map)
->group('j.user_id')
->select()
->toArray();
if (!empty($subQuery)){
foreach ($subQuery as $k=>$v){
$new_map[]=$v["max(j.id)"];
}
}
$map1['j.id']=['in',implode(',',$new_map)];
$info=db('join')->alias('j')
->group('j.user_id')
->field('v.*,j.*,j.id as join_id,j.status as status')
->join('volunteer v','v.user_id=j.user_id')
->where($map1)
->order('j.id','asc')
->select()
->toArray();
/*$info=db('join_view')
->group('user_id')
->where($map)
->select()
->toArray();*/
// echo db('join')->getLastSql();
$return=[];
$i0=0;
$i1=0;
$i2=0;
$i3=0;
$i4=0;
$i5=0;
foreach($info as $k=>$v){
switch ($v['work_content']){
case 1:
$return[0]['title']='摄影(设备自带)';
$return[0]['arr'][$i0]['id']=$v['join_id'];
$return[0]['arr'][$i0]['photo']=$v['photo'];
$return[0]['arr'][$i0]['name']=$v['name'];
$return[0]['arr'][$i0]['user_id']=$v['user_id'];
$return[0]['arr'][$i0]['status']=$this->switchStatus($v['status']);
$i0++;
break;
case 2:
$return[1]['title']='摄像(设备自带)';
$return[1]['arr'][$i1]['id']=$v['join_id'];
$return[1]['arr'][$i1]['photo']=$v['photo'];
$return[1]['arr'][$i1]['name']=$v['name'];
$return[1]['arr'][$i1]['user_id']=$v['user_id'];
$return[1]['arr'][$i1]['status']=$this->switchStatus($v['status']);
$i1++;
break;
case 3:
$return[2]['title']='爱心车队';
$return[2]['arr'][$i2]['id']=$v['join_id'];
$return[2]['arr'][$i2]['photo']=$v['photo'];
$return[2]['arr'][$i2]['name']=$v['name'];
$return[2]['arr'][$i2]['user_id']=$v['user_id'];
$return[2]['arr'][$i2]['status']=$this->switchStatus($v['status']);
$i2++;
break;
case 4:
$return[3]['title']='现场服务(签到、指引、礼仪等)';
$return[3]['arr'][$i3]['id']=$v['join_id'];
$return[3]['arr'][$i3]['photo']=$v['photo'];
$return[3]['arr'][$i3]['name']=$v['name'];
$return[3]['arr'][$i3]['user_id']=$v['user_id'];
$return[3]['arr'][$i3]['status']=$this->switchStatus($v['status']);
$i3++;
break;
case 5:
$return[4]['title']='线上答疑';
$return[4]['arr'][$i4]['id']=$v['join_id'];
$return[4]['arr'][$i4]['photo']=$v['photo'];
$return[4]['arr'][$i4]['name']=$v['name'];
$return[4]['arr'][$i4]['user_id']=$v['user_id'];
$return[4]['arr'][$i4]['status']=$this->switchStatus($v['status']);
$i4++;
break;
case 6:
$return[5]['title']='门诊服务';
/*判断是否有user_id*/
$return[5]['arr'][$i5]['id']=$v['join_id'];
$return[5]['arr'][$i5]['photo']=$v['photo'];
$return[5]['arr'][$i5]['name']=$v['name'];
$return[5]['arr'][$i5]['user_id']=$v['user_id'];
$return[5]['arr'][$i5]['status']=$this->switchStatus($v['status']);
$i5++;
break;
}
}
foreach ($return as $k=>$v){
foreach($return[$k] as $k1=>$v1){
}
}
$this->success('',$return);
}
/**
* @title 管理员审核活动申请是否通过(new)
* @description 管理员更新状态
* @author XiaoGang Wang
* @url /index/member_center/adminApprove
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*
* @param name:id type:int require:1 other: desc:参加id
* @param name:status type:int require:1 other: desc:1通过2.拒绝
* @param name:refund_reason type:int require:1 other: desc:拒绝理由
*
*
*/
public function adminApprove(){
$user_id = $this->getUserId();
//判断这个用户是不是管理员
$userModel = new UserModel();
$user = $userModel->findData(array('id'=>$user_id));
if($user['type'] != 2){
$this->success(['code'=>40001,'msg'=>'查无此人!']);
}
$map['id']=input('id');
$data['status']=input('status');
$refund_reason=input('refund_reason');
if (!empty($refund_reason)){
$data['refund_reason']=input('refund_reason');
}
$result=db('join')->where($map)->update($data);
if ($result>0){
$join=\db('join')->where($map)->find();
$activity=\db('activity')->where('id',$join['activity_id'])->find();
$userMap['user_id']=$join['user_id'];
$openid=db('third_party_user')->where($userMap)->value('openid');
$volunteer=\db('volunteer')->where('user_id',$join['user_id'])->find();
$formMap['user_id']=$join['user_id'];
$formMap['use_time']=0;
$formMap['expire_time']=['>',time()];
$form_id=\db('form_id')->where($formMap)->find();
$now=time();
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>$now]);
if ($data['status']==1){
if (!empty($form_id)){
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>time()]);
$data['keyword1']= $volunteer['name'];
$data['keyword2']='活动审核';
$data['keyword3']='通过';
$data['keyword4']=$activity['activity_name'];
$message = [
'touser' => $openid,
'template_id' => '1FYkLuMK8LNKO4_nxJ_DuNQhgIjaaJQlAukgt92C-uw',
'page' => 'pages/index/index',
'form_id' => $form_id['value'],
'data' => $data,
'emphasis_keyword' =>$data['keyword3'],
];
$this->wxappNotice($message);
}
}else{
if (!empty($form_id)){
\db('form_id')->where('form_id',$form_id['form_id'])->update(['use_time'=>time()]);
$data['keyword1']= $volunteer['name'];
$data['keyword2']='活动审核';
$data['keyword3']='未通过 原因:'.$refund_reason;
$data['keyword4']=$activity['activity_name'];
$message = [
'touser' => $openid,
'template_id' => '1FYkLuMK8LNKO4_nxJ_DuNQhgIjaaJQlAukgt92C-uw',
'page' => 'pages/index/index',
'form_id' => $form_id['value'],
'data' => $data,
'emphasis_keyword' =>$data['keyword3'],
];
$this->wxappNotice($message);
}
}
$this->success('更新成功!');
}else{
$this->error('操作失败!');
}
}
protected function wxappNotice($message){
$appId = 'wx7a3bf4e0796c070a';
$secret = '755478f064e09a8301345e0c427c6cf3';
$config = [
'app_id' => $appId,
'secret' => $secret,
];
$wechat=new Application($config);
$notice=$wechat->mini_program->notice;
try{
$result= $notice->send($message);
}catch(Exception $e){
// $e->getMessage();
}
return $result;
}
protected function switchStatus($status){
switch ($status){
case 0:
return '0';
case 1:
return '1';
case 2:
return '2';
case 3:
return '3';
}
}
/**
* @title 关于我们
* @description 关于我们
* @author XiaoGang Wang
* @url /index/member_center/about
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function about(){
$aboutModel = new AboutModel();
$data = $aboutModel->findData(array('id'=>1));
$this->success('获取成功!',$data);
}
/**
* @title 联系我们
* @description 联系我们
* @author XiaoGang Wang
* @url /index/member_center/contact
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function contact(){
$contactModel = new ContactModel();
$data = $contactModel->findData(array('id'=>1));
$this->success('获取成功!',$data);
}
/**
* @title 我参加的活动
* @description 参加过的活动
* @author XiaoGang Wang
* @url /index/member_center/joined
* @method GET
*
* @header name:XX-Token require:1 default: desc:token
*/
public function joined(){
$userId=$this->getUserId();
$Join=new JoinModel();
$join=$Join->getUserJoin($userId);
foreach ($join as $k=>$v){
$join[$k]['thumbnail']=cmf_get_image_url($v['thumbnail']);
$join[$k]['create_time']=date('Y-m-d',$v['create_time']);
}
$this->success('',$join);
}
protected function saveFormId($userId,$formId){
if ($formId=='undefined'){
return;
}
$data['user_id']=$userId;
$data['add_time']=time();
$data['value']=$formId;
$data['expire_time']=time()+604800;
db('form_id')->insert($data);
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 13:47
*/
namespace api\index\model;
use think\Model;
class ActivityModel extends Model
{
/**
* thumbnail 自动转化
* @param $value
* @return array
*/
public function getThumbnailAttr($value)
{
return cmf_get_image_url($value);
}
/**
* time 自动转化
* @param $value
* @return array
*/
public function getTimeAttr($value)
{
return date('Y-m-d',$value);
}
/**
* content 自动转化
* @param $value
* @return array
*/
public function getContentAttr($value)
{
return cmf_replace_content_file_url(htmlspecialchars_decode($value));
}
public function selectData($page,$pageNum){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['is_up'] = ['eq',1];
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->limit(($page * $pageNum),$pageNum)
->order($order)
->select()
->toArray();
return $data;
}
public function selectCityData($city_id){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['a.is_up']=1;
if (!empty($city_id)){
$where['a.position_id'] = $city_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
return $data;
}
public function selectTypeData($type_id){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['a.is_up']=1;
if (!empty($type_id)){
$where['a.activity_type'] = $type_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
/**
* 即将开始的活动
* @param $page
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function beginAtOnce($page,$pageNum){
$now=time();
$map['a.create_time']=['<',$now];
$map['a.delete_time'] = ['eq',0];
if ($page<=0){
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit('2')
->select()->toArray();
}else{
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit(($page * $pageNum),$pageNum)
->select()->toArray();
}
return $data;
}
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 2018/12/31
* Time: 13:47
*/
namespace api\index\model;
use think\Model;
class ActivityModel extends Model
{
/**
* thumbnail 自动转化
* @param $value
* @return array
*/
public function getThumbnailAttr($value)
{
return cmf_get_image_url($value);
}
/**
* time 自动转化
* @param $value
* @return array
*/
public function getTimeAttr($value)
{
return date('Y-m-d',$value);
}
/**
* content 自动转化
* @param $value
* @return array
*/
public function getContentAttr($value)
{
return cmf_replace_content_file_url(htmlspecialchars_decode($value));
}
public function selectData($page,$pageNum){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['is_up'] = ['eq',1];
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->limit(($page * $pageNum),$pageNum)
->order($order)
->select()
->toArray();
return $data;
}
public function selectDataByTime($page,$pageNum,$type=0){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
if ($type==0){
$where['a.end_time']=['>',time()];
}else{
$where['a.end_time']=['<',time()];
}
$where['is_up'] = ['eq',1];
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->limit(($page * $pageNum),$pageNum)
->order($order)
->select()
->toArray();
return $data;
}
public function selectCityData($city_id,$type=">="){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['a.is_up']=1;
$where['a.end_time']=[$type,time()];
if (!empty($city_id)){
$where['a.position_id'] = $city_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
// echo $this->getLastSql();
return $data;
}
public function selectTypeData($type_id,$type="<="){
$order = "create_time desc";
$where['a.delete_time'] = ['eq',0];
$where['a.is_up']=1;
$where['a.end_time']=[$type,time()];
if (!empty($type_id)){
$where['a.activity_type'] = $type_id;
}
$data = $this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($where)
->order($order)
->select()
->toArray();
return $data;
}
public function findData($where){
$data = $this->where($where)->find();
return $data;
}
/**
* 即将开始的活动
* @param $page
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function beginAtOnce($page,$pageNum){
$now=time();
$map['a.create_time']=['<',$now];
$map['a.delete_time'] = ['eq',0];
if ($page<=0){
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit('2')
->select()->toArray();
}else{
$data=$this->alias('a')
->field('a.*,p.province_name,act.type_name')
->join('activity_type act','act.id=a.activity_type','LEFT')
->join('position_province p','p.id=a.position_id','LEFT')
->where($map)
->order("create_time desc")
->limit(($page * $pageNum),$pageNum)
->select()->toArray();
}
return $data;
}
}
\ No newline at end of file
... ...
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2019/2/28
* Time: 18:29
*/
namespace api\index\model;
use think\Model;
class JoinModel extends Model
{
public function findData($where){
$data=$this->where($where)->order('id','desc')->find();
return $data;
}
/**
* 查询多条
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectData($where){
$data=$this->where($where)->select()->toArray();
return $data;
}
public function getJoinData($activity_id){
$where['j.activity_id']=$activity_id;
$where['j.status']=['in','1,3'];
$where['j.delete_time']=0;
$info=$this->alias('j')
->join('cmf_volunteer v','v.user_id=j.user_id')
->where($where)
//->fetchSql()
->select()
->toArray();
//->toArray();
//dump($info);
return $info;
}
/**
* @param $userId 用户参加活动id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserJoin($userId){
$where['j.user_id']=$userId;
$where['j.status']=['>',1];
$info=$this->alias('j')
->field('a.*,at.type_name,pp.*,a.id as id')
->join('cmf_activity a','a.id=j.activity_id')
->join('cmf_activity_type at','a.activity_type=at.id')
->join('cmf_position_province pp','a.position_id=pp.id')
->where($where)
->select()
->toArray();
return $info;
}
<?php
/**
* Created by PhpStorm.
* auther: sgj
* Date: 2019/2/28
* Time: 18:29
*/
namespace api\index\model;
use think\Model;
class JoinModel extends Model
{
public function findData($where){
$data=$this->where($where)->order('id','desc')->find();
return $data;
}
/**
* 查询多条
* @param $where
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function selectData($where){
$data=$this->where($where)->select()->toArray();
return $data;
}
public function getJoinData($activity_id){
$where['j.activity_id']=$activity_id;
$where['j.status']=['in','1,3'];
$where['j.delete_time']=0;
$info=$this->alias('j')
->join('cmf_volunteer v','v.user_id=j.user_id')
->where($where)
//->fetchSql()
->select()
->toArray();
//->toArray();
//dump($info);
return $info;
}
/**
* @param $userId 用户参加活动id
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\ModelNotFoundException
* @throws \think\exception\DbException
*/
public function getUserJoin($userId){
$where['j.user_id']=$userId;
$where['j.status']=['in','1,3'];
$where['j.delete_time']=0;
$info=$this->alias('j')
->field('a.*,at.type_name,pp.*,a.id as id')
->join('cmf_activity a','a.id=j.activity_id')
->join('cmf_activity_type at','a.activity_type=at.id','LEFT')
->join('cmf_position_province pp','a.position_id=pp.id','LEFT')
->where($where)
->order('a.start_time','desc')
->group('a.id')
->select()
->toArray();
// echo $this->getLastSql();
return $info;
}
}
\ No newline at end of file
... ...
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace api\wxapp\controller;
use think\Db;
use cmf\controller\RestBaseController;
use wxapp\aes\WXBizDataCrypt;
use think\Validate;
/**
* @title 公共模块
* @description 公共模块
* @package api\wxapp\controller
*/
class PublicController extends RestBaseController
{
/**
* @title 获取sessionKey和openid
* @description 小程序登录注册
* @author Tiger Yang
* @url /wxapp/public/getSessionKey
* @method POST
*
* @param name:code type:string require:1 other: desc:code
*
* @return session_key:session_key
* @return openid:openid
*/
public function getSessionKey(){
$validate = new Validate([
'code' => 'require',
]);
$validate->message([
'code.require' => '缺少参数code!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$code = $data['code'];
$appId = config('app_id');
$appSecret = config('app_secret');
$response = cmf_curl_get("https://api.weixin.qq.com/sns/jscode2session?appid=$appId&secret=$appSecret&js_code=$code&grant_type=authorization_code");
$response = json_decode($response, true);
if (!empty($response['errcode'])) {
$this->error(['code'=>'41001','msg'=>'操作失败:'.$response['errcode']]);
}
$this->success('获取成功',$response);
}
/**
* @title 小程序登录注册
* @description 小程序登录注册
* @author Tiger Yang
* @url /wxapp/public/login
* @method POST
*
* @param name:openid type:string require:1 other: desc:openid
* @param name:session_key type:string require:1 other: desc:session_key
* @param name:encrypted_data type:string require:1 other: desc:encrypted_data
* @param name:iv type:string require:1 other: desc:iv
*
* @return token:登录唯一标识
*/
public function login()
{
$validate = new Validate([
'openid' => 'require',
'session_key' => 'require',
'encrypted_data' => 'require',
'iv' => 'require',
]);
$validate->message([
'openid.require' => '缺少参数openid!',
'session_key.require' => '缺少参数session_key!',
'encrypted_data.require' => '缺少参数encrypted_data!',
'iv.require' => '缺少参数iv!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$appId = config('app_id');
$openid = $data['openid'];
$sessionKey = $data['session_key'];
$pc = new WXBizDataCrypt($appId, $sessionKey);
$errCode = $pc->decryptData($data['encrypted_data'], $data['iv'], $wxUserData);
if ($errCode != 0) {
$this->error(['code'=>'41002','msg'=>'检验数据失败!'],['errCode'=>$errCode,'param'=>$data]);
}
$findThirdPartyUser = Db::name("third_party_user")
->where('openid', $openid)
->where('app_id', $appId)
->find();
$currentTime = time();
$ip = $this->request->ip(0, true);
$wxUserData['sessionKey'] = $sessionKey;
unset($wxUserData['watermark']);
if ($findThirdPartyUser) {
$token = cmf_generate_user_token($findThirdPartyUser['user_id'], 'wxapp');
$userData = [
'last_login_ip' => $ip,
'last_login_time' => $currentTime,
'login_times' => ['exp', 'login_times+1'],
'more' => json_encode($wxUserData)
];
if (isset($wxUserData['unionId'])) {
$userData['union_id'] = $wxUserData['unionId'];
}
Db::name("third_party_user")
->where('openid', $openid)
->where('app_id', $appId)
->update($userData);
$this->success("登录成功!", ['token' => $token]);
} else {
Db::startTrans();
$userId = Db::name("user")->insertGetId([
'create_time' => $currentTime,
'user_status' => 1,
'user_type' => 2,
'sex' => $wxUserData['gender'],
'user_nickname' => $wxUserData['nickName'],
'avatar' => $wxUserData['avatarUrl'],
'last_login_ip' => $ip,
'last_login_time' => $currentTime
]);
$row=Db::name("third_party_user")->insert([
'openid' => $openid,
'user_id' => $userId,
'third_party' => 'wxapp',
'app_id' => $appId,
'last_login_ip' => $ip,
'union_id' => isset($wxUserData['unionId']) ? $wxUserData['unionId'] : '',
'last_login_time' => $currentTime,
'create_time' => $currentTime,
'login_times' => 1,
'status' => 1,
'more' => json_encode($wxUserData)
]);
if($userId && $row){
Db::commit();
$token = cmf_generate_user_token($userId, 'wxapp');
$this->success("登录成功!", ['token' => $token]);
}else{
Db::rollback();
$this->error(['code'=>'40004','msg'=>'登录失败']);
}
}
}
/**
* @title 获取token
* @description 获取token
* @author Tiger Yang
* @url /wxapp/public/get_token
* @method POST
*
* @param name:openid type:string require:1 other: desc:openid
*
* @return token:登录唯一标识
*/
public function get_token(){
$openid = $this->request->param('openid');
$third_party_user = Db::name('third_party_user')->where(array('openid'=>$openid))->find();
if(empty($third_party_user)){
$this->success('查无此人!',['code'=>20000,'msg'=>'查无此人!']);
}
$data = Db::name('user_token')->where(array('user_id'=>$third_party_user['user_id']))->find();
if($data['expire_time']<time()){
$this->success('token过期了',['code'=>20000,'msg'=>'token过期了']);
}else{
$this->success('ok',['code'=>20000,'msg'=>'ok','data'=>$data['token']]);
}
}
}
<?php
// +----------------------------------------------------------------------
// | bronet [ 以客户为中心 以奋斗者为本 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.bronet.cn All rights reserved.
// +----------------------------------------------------------------------
namespace api\wxapp\controller;
use think\Db;
use cmf\controller\RestBaseController;
use wxapp\aes\WXBizDataCrypt;
use think\Validate;
/**
* @title 公共模块
* @description 公共模块
* @package api\wxapp\controller
*/
class PublicController extends RestBaseController
{
/**
* @title 获取sessionKey和openid
* @description 小程序登录注册
* @author Tiger Yang
* @url /wxapp/public/getSessionKey
* @method POST
*
* @param name:code type:string require:1 other: desc:code
*
* @return session_key:session_key
* @return openid:openid
*/
public function getSessionKey(){
$validate = new Validate([
'code' => 'require',
]);
$validate->message([
'code.require' => '缺少参数code!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$code = $data['code'];
$appId = config('app_id');
$appSecret = config('app_secret');
$response = cmf_curl_get("https://api.weixin.qq.com/sns/jscode2session?appid=$appId&secret=$appSecret&js_code=$code&grant_type=authorization_code");
$response = json_decode($response, true);
if (!empty($response['errcode'])) {
$this->error(['code'=>'41001','msg'=>'操作失败:'.$response['errcode']]);
}
$this->success('获取成功',$response);
}
/**
* @title 小程序登录注册
* @description 小程序登录注册
* @author Tiger Yang
* @url /wxapp/public/login
* @method POST
*
* @param name:openid type:string require:1 other: desc:openid
* @param name:session_key type:string require:1 other: desc:session_key
* @param name:encrypted_data type:string require:1 other: desc:encrypted_data
* @param name:iv type:string require:1 other: desc:iv
*
* @return token:登录唯一标识
*/
public function login()
{
$validate = new Validate([
'openid' => 'require',
'session_key' => 'require',
'encrypted_data' => 'require',
'iv' => 'require',
]);
$validate->message([
'openid.require' => '缺少参数openid!',
'session_key.require' => '缺少参数session_key!',
'encrypted_data.require' => '缺少参数encrypted_data!',
'iv.require' => '缺少参数iv!',
]);
$data = $this->request->param();
if (!$validate->check($data)) {
$this->error(['code'=>'40003','msg'=>$validate->getError()]);
}
$appId = config('app_id');
$openid = $data['openid'];
$sessionKey = $data['session_key'];
$pc = new WXBizDataCrypt($appId, $sessionKey);
$errCode = $pc->decryptData($data['encrypted_data'], $data['iv'], $wxUserData);
if ($errCode != 0) {
$this->error(['code'=>'41002','msg'=>'检验数据失败!'],['errCode'=>$errCode,'param'=>$data]);
}
$findThirdPartyUser = Db::name("third_party_user")
->where('openid', $openid)
->where('app_id', $appId)
->find();
$currentTime = time();
$ip = $this->request->ip(0, true);
$wxUserData['sessionKey'] = $sessionKey;
unset($wxUserData['watermark']);
if ($findThirdPartyUser) {
$token = cmf_generate_user_token($findThirdPartyUser['user_id'], 'wxapp');
$userData = [
'last_login_ip' => $ip,
'last_login_time' => $currentTime,
'login_times' => ['exp', 'login_times+1'],
'more' => json_encode($wxUserData)
];
if (isset($wxUserData['unionId'])) {
$userData['union_id'] = $wxUserData['unionId'];
}
Db::name("third_party_user")
->where('openid', $openid)
->where('app_id', $appId)
->update($userData);
$this->success("登录成功!", ['token' => $token]);
} else {
Db::startTrans();
$userId = Db::name("user")->insertGetId([
'create_time' => $currentTime,
'user_status' => 1,
'user_type' => 2,
'sex' => $wxUserData['gender'],
'user_nickname' => $wxUserData['nickName'],
'avatar' => $wxUserData['avatarUrl'],
'last_login_ip' => $ip,
'last_login_time' => $currentTime
]);
$row=Db::name("third_party_user")->insert([
'openid' => $openid,
'user_id' => $userId,
'third_party' => 'wxapp',
'app_id' => $appId,
'last_login_ip' => $ip,
'union_id' => isset($wxUserData['unionId']) ? $wxUserData['unionId'] : '',
'last_login_time' => $currentTime,
'create_time' => $currentTime,
'login_times' => 1,
'status' => 1,
'more' => json_encode($wxUserData)
]);
if($userId && $row){
Db::commit();
$token = cmf_generate_user_token($userId, 'wxapp');
$this->success("登录成功!", ['token' => $token]);
}else{
Db::rollback();
$this->error(['code'=>'40004','msg'=>'登录失败']);
}
}
}
/**
* @title 获取token
* @description 获取token
* @author Tiger Yang
* @url /wxapp/public/get_token
* @method POST
*
* @param name:openid type:string require:1 other: desc:openid
*
* @return token:登录唯一标识
*/
public function get_token(){
$openid = $this->request->param('openid');
$third_party_user = Db::name('third_party_user')->where(array('openid'=>$openid))->find();
if(empty($third_party_user)){
/*没有相关用户 添加用户到数据库 分配token*/
$ip = $this->request->ip(0, true);
$currentTime=time();
Db::startTrans();
$appId = config('app_id');
$userId = Db::name("user")->insertGetId([
'create_time' => $currentTime,
'user_status' => 1,
'user_type' => 2,
'sex' => 0,
'user_nickname' => '用户',
'avatar' => '',
'last_login_ip' => $ip,
'last_login_time' => $currentTime
]);
$row=Db::name("third_party_user")->insert([
'openid' => $openid,
'user_id' => $userId,
'third_party' => 'wxapp',
'app_id' => $appId,
'last_login_ip' => $ip,
'union_id' => '',
'last_login_time' => $currentTime,
'create_time' => $currentTime,
'login_times' => 1,
'status' => 1
]);
if($userId && $row){
Db::commit();
$token = cmf_generate_user_token($userId, 'wxapp');
$this->success("登录成功!", ['token' => $token]);
}else{
Db::rollback();
$this->error(['code'=>'40004','msg'=>'登录失败']);
}
// $this->success('查无此人!',['code'=>20000,'msg'=>'查无此人!']);
}
$data = Db::name('user_token')->where(array('user_id'=>$third_party_user['user_id']))->find();
if($data['expire_time']<time()){
$token = cmf_generate_user_token($third_party_user['user_id'], 'wxapp');
$this->success('ok',['code'=>20000,'msg'=>'ok','token'=>$token]);
}else{
$this->success('ok',['code'=>20000,'msg'=>'ok','token'=>$data['token']]);
}
}
}
... ...