123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220 |
- <?php
- // +----------------------------------------------------------------------
- // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
- // +----------------------------------------------------------------------
- // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
- // +----------------------------------------------------------------------
- // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
- // +----------------------------------------------------------------------
- // | Author: CRMEB Team <admin@crmeb.com>
- // +----------------------------------------------------------------------
- namespace app\admin\controller\ump;
- use app\admin\controller\AuthController;
- use service\JsonService as Json;
- use service\UploadService as Upload;
- use think\Request;
- use app\admin\model\ump\EventRegistration as EventRegistrationModel;
- use app\admin\model\ump\EventSignUp as EventSignUpModel;
- class EventRegistration extends AuthController
- {
- public function index(){
- return $this->fetch();
- }
- /**
- * 活动列表
- */
- public function event_registration_list(){
- $where = parent::getMore([
- ['title',''],
- ['page',1],
- ['limit',20],
- ],$this->request);
- return Json::successlayui(EventRegistrationModel::systemPage($where));
- }
- public function set_show($is_show = '', $id = '')
- {
- if ($is_show == '' || $id == '') return Json::fail('缺少参数');
- if (EventRegistrationModel::update(['is_show' => $is_show], ['id' => $id]))
- return Json::successful($is_show == 1 ? '显示成功' : '隐藏成功');
- else
- return Json::fail($is_show == 1 ? '显示失败' : '隐藏失败');
- }
- public function create(){
- $id = $this->request->param('id');
- $news = [];
- $news['image'] = '';
- $news['qrcode_img'] = '';
- $news['title'] = '';
- $news['start_time'] = '';
- $news['end_time'] = '';
- $news['signup_start_time'] = '';
- $news['signup_end_time'] = '';
- $news['province'] = '';
- $news['city'] = '';
- $news['district'] = '';
- $news['detail'] = '';
- $news['number'] = 0;
- $news['activity_rules'] = '';
- $news['content'] = '';
- $news['sort'] = 0;
- $news['restrictions'] = 0;
- $news['is_fill'] = 1;
- $news['is_show'] = 0;
- $news['pay_type'] = 0;
- $news['price'] = 0;
- $news['member_pay_type'] = 0;
- $news['member_price'] = 0;
- if($id){
- $news = EventRegistrationModel::where('id',$id)->find();
- $news['signup_start_time'] =date('Y-m-d H:i:s',$news['signup_start_time']);
- $news['signup_end_time'] =date('Y-m-d H:i:s',$news['signup_end_time']);
- $news['start_time'] =date('Y-m-d H:i:s',$news['start_time']);
- $news['end_time'] =date('Y-m-d H:i:s',$news['end_time']);
- $news['activity_rules'] = htmlspecialchars_decode($news['activity_rules']);
- $news['content'] = htmlspecialchars_decode($news['content']);
- if(!$news) return $this->failed('数据不存在!');
- }else{
- $id=0;
- }
- $this->assign('news',json_encode($news));
- $this->assign('id',$id);
- return $this->fetch();
- return $this->fetch();
- }
- /**
- * 删除活动
- * */
- public function delete($id)
- {
- $res = EventRegistrationModel::delArticleCategory($id);
- if(!$res)
- return Json::fail(EventRegistrationModel::getErrorInfo('删除失败,请稍候再试!'));
- else
- return Json::successful('删除成功!');
- }
- /**
- * 添加和修改活动
- */
- public function add_new(){
- $data = parent::postMore([
- ['id',0],
- 'title',
- 'image',
- 'qrcode_img',
- 'activity_rules',
- 'content',
- 'number',
- 'province',
- 'city',
- 'district',
- 'detail',
- 'signup_start_time',
- 'signup_end_time',
- 'start_time',
- 'end_time',
- ['sort',0],
- ['restrictions',0],
- ['pay_type',0],
- 'price',
- ['member_pay_type',0],
- 'member_price',
- ['is_fill',1],
- ['is_show',0],
- ]);
- $data['signup_start_time']=strtotime($data['signup_start_time']);
- $data['signup_end_time']=strtotime($data['signup_end_time']);
- $data['start_time']=strtotime($data['start_time']);
- $data['end_time']=strtotime($data['end_time']);
- if(bcsub($data['signup_end_time'],$data['signup_start_time'],0)<=0 || bcsub($data['start_time'],$data['signup_end_time'],0)<=0 || bcsub($data['end_time'],$data['start_time'],0)<=0) return Json::fail('活动时间有误');
- if(!$data['pay_type']){
- $data['price']=0;
- $data['member_pay_type']=0;
- $data['member_price']=0;
- }
- $data['content']=htmlspecialchars($data['content']);
- $data['activity_rules']=htmlspecialchars($data['activity_rules']);
- if(!$data['member_pay_type']) $data['member_price']=0;
- if($data['id']){
- $id = $data['id'];
- unset($data['id']);
- EventRegistrationModel::beginTrans();
- $res1 = EventRegistrationModel::edit($data,$id,'id');
- EventRegistrationModel::checkTrans($res1);
- if($res1){
- return Json::successful('修改活动成功!',$id);
- }else
- return Json::fail('修改活动失败,您并没有修改什么!',$id);
- }else{
- $data['add_time'] = time();
- EventRegistrationModel::beginTrans();
- $res2 = EventRegistrationModel::set($data);
- EventRegistrationModel::checkTrans($res2);
- if($res2)
- return Json::successful('添加活动成功!',$res2->id);
- else
- return Json::successful('添加活动失败!',$res2->id);
- }
- }
- /**
- * 查看报名人员
- */
- public function viewStaff($id){
- $activity = EventRegistrationModel::where('id',$id)->find();
- if(!$activity) return Json::fail('活动不存在!');
- $this->assign('aid',$id);
- return $this->fetch('view_staff');
- }
- /**
- * 查看活动报名订单列表
- */
- public function get_sign_up_list(){
- $id = $this->request->param('id');
- $where=parent::getMore([
- ['id',$id],
- ['page',1],
- ['limit',20],
- ['status',''],
- ['real_name',''],
- ['excel',0],
- ]);
- return Json::successlayui(EventSignUpModel::getUserSignUpAll($where));
- }
- /**
- * 统计
- */
- public function getBadge()
- {
- $id = $this->request->param('id');
- $where=parent::getMore([
- ['id',$id],
- ['status',''],
- ['real_name',''],
- ['excel',0],
- ]);
- return Json::successful(EventSignUpModel::getBadge($where));
- }
- /**用户活动核销
- * @param string $order_id
- * @param int $aid
- * @param string $code
- * @throws \think\db\exception\DataNotFoundException
- * @throws \think\db\exception\ModelNotFoundException
- * @throws \think\exception\DbException
- */
- public function scanCodeSignIn($id){
- if (!$id) $this->failed('参数有误!');
- $order=EventSignUpModel::where('id',$id)->find();
- if(!$order) $this->failed('订单不存在!');
- if($order['status']) $this->failed('订单已核销!');
- $res=EventSignUpModel::where('id',$id)->where('paid',1)->update(['status'=>1]);
- if($res) return Json::successful('ok');
- else return Json::fail('核销失败');
- }
- }
|