EventRegistration.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2016~2020 https://www.crmeb.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  8. // +----------------------------------------------------------------------
  9. // | Author: CRMEB Team <admin@crmeb.com>
  10. // +----------------------------------------------------------------------
  11. namespace app\admin\controller\ump;
  12. use app\admin\controller\AuthController;
  13. use service\JsonService as Json;
  14. use service\UploadService as Upload;
  15. use think\Request;
  16. use app\admin\model\ump\EventRegistration as EventRegistrationModel;
  17. use app\admin\model\ump\EventSignUp as EventSignUpModel;
  18. class EventRegistration extends AuthController
  19. {
  20. public function index(){
  21. return $this->fetch();
  22. }
  23. /**
  24. * 活动列表
  25. */
  26. public function event_registration_list(){
  27. $where = parent::getMore([
  28. ['title',''],
  29. ['page',1],
  30. ['limit',20],
  31. ],$this->request);
  32. return Json::successlayui(EventRegistrationModel::systemPage($where));
  33. }
  34. public function set_show($is_show = '', $id = '')
  35. {
  36. if ($is_show == '' || $id == '') return Json::fail('缺少参数');
  37. if (EventRegistrationModel::update(['is_show' => $is_show], ['id' => $id]))
  38. return Json::successful($is_show == 1 ? '显示成功' : '隐藏成功');
  39. else
  40. return Json::fail($is_show == 1 ? '显示失败' : '隐藏失败');
  41. }
  42. public function create(){
  43. $id = $this->request->param('id');
  44. $news = [];
  45. $news['image'] = '';
  46. $news['qrcode_img'] = '';
  47. $news['title'] = '';
  48. $news['start_time'] = '';
  49. $news['end_time'] = '';
  50. $news['signup_start_time'] = '';
  51. $news['signup_end_time'] = '';
  52. $news['province'] = '';
  53. $news['city'] = '';
  54. $news['district'] = '';
  55. $news['detail'] = '';
  56. $news['number'] = 0;
  57. $news['activity_rules'] = '';
  58. $news['content'] = '';
  59. $news['sort'] = 0;
  60. $news['restrictions'] = 0;
  61. $news['is_fill'] = 1;
  62. $news['is_show'] = 0;
  63. $news['pay_type'] = 0;
  64. $news['price'] = 0;
  65. $news['member_pay_type'] = 0;
  66. $news['member_price'] = 0;
  67. if($id){
  68. $news = EventRegistrationModel::where('id',$id)->find();
  69. $news['signup_start_time'] =date('Y-m-d H:i:s',$news['signup_start_time']);
  70. $news['signup_end_time'] =date('Y-m-d H:i:s',$news['signup_end_time']);
  71. $news['start_time'] =date('Y-m-d H:i:s',$news['start_time']);
  72. $news['end_time'] =date('Y-m-d H:i:s',$news['end_time']);
  73. $news['activity_rules'] = htmlspecialchars_decode($news['activity_rules']);
  74. $news['content'] = htmlspecialchars_decode($news['content']);
  75. if(!$news) return $this->failed('数据不存在!');
  76. }else{
  77. $id=0;
  78. }
  79. $this->assign('news',json_encode($news));
  80. $this->assign('id',$id);
  81. return $this->fetch();
  82. return $this->fetch();
  83. }
  84. /**
  85. * 删除活动
  86. * */
  87. public function delete($id)
  88. {
  89. $res = EventRegistrationModel::delArticleCategory($id);
  90. if(!$res)
  91. return Json::fail(EventRegistrationModel::getErrorInfo('删除失败,请稍候再试!'));
  92. else
  93. return Json::successful('删除成功!');
  94. }
  95. /**
  96. * 添加和修改活动
  97. */
  98. public function add_new(){
  99. $data = parent::postMore([
  100. ['id',0],
  101. 'title',
  102. 'image',
  103. 'qrcode_img',
  104. 'activity_rules',
  105. 'content',
  106. 'number',
  107. 'province',
  108. 'city',
  109. 'district',
  110. 'detail',
  111. 'signup_start_time',
  112. 'signup_end_time',
  113. 'start_time',
  114. 'end_time',
  115. ['sort',0],
  116. ['restrictions',0],
  117. ['pay_type',0],
  118. 'price',
  119. ['member_pay_type',0],
  120. 'member_price',
  121. ['is_fill',1],
  122. ['is_show',0],
  123. ]);
  124. $data['signup_start_time']=strtotime($data['signup_start_time']);
  125. $data['signup_end_time']=strtotime($data['signup_end_time']);
  126. $data['start_time']=strtotime($data['start_time']);
  127. $data['end_time']=strtotime($data['end_time']);
  128. 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('活动时间有误');
  129. if(!$data['pay_type']){
  130. $data['price']=0;
  131. $data['member_pay_type']=0;
  132. $data['member_price']=0;
  133. }
  134. $data['content']=htmlspecialchars($data['content']);
  135. $data['activity_rules']=htmlspecialchars($data['activity_rules']);
  136. if(!$data['member_pay_type']) $data['member_price']=0;
  137. if($data['id']){
  138. $id = $data['id'];
  139. unset($data['id']);
  140. EventRegistrationModel::beginTrans();
  141. $res1 = EventRegistrationModel::edit($data,$id,'id');
  142. EventRegistrationModel::checkTrans($res1);
  143. if($res1){
  144. return Json::successful('修改活动成功!',$id);
  145. }else
  146. return Json::fail('修改活动失败,您并没有修改什么!',$id);
  147. }else{
  148. $data['add_time'] = time();
  149. EventRegistrationModel::beginTrans();
  150. $res2 = EventRegistrationModel::set($data);
  151. EventRegistrationModel::checkTrans($res2);
  152. if($res2)
  153. return Json::successful('添加活动成功!',$res2->id);
  154. else
  155. return Json::successful('添加活动失败!',$res2->id);
  156. }
  157. }
  158. /**
  159. * 查看报名人员
  160. */
  161. public function viewStaff($id){
  162. $activity = EventRegistrationModel::where('id',$id)->find();
  163. if(!$activity) return Json::fail('活动不存在!');
  164. $this->assign('aid',$id);
  165. return $this->fetch('view_staff');
  166. }
  167. /**
  168. * 查看活动报名订单列表
  169. */
  170. public function get_sign_up_list(){
  171. $id = $this->request->param('id');
  172. $where=parent::getMore([
  173. ['id',$id],
  174. ['page',1],
  175. ['limit',20],
  176. ['status',''],
  177. ['real_name',''],
  178. ['excel',0],
  179. ]);
  180. return Json::successlayui(EventSignUpModel::getUserSignUpAll($where));
  181. }
  182. /**
  183. * 统计
  184. */
  185. public function getBadge()
  186. {
  187. $id = $this->request->param('id');
  188. $where=parent::getMore([
  189. ['id',$id],
  190. ['status',''],
  191. ['real_name',''],
  192. ['excel',0],
  193. ]);
  194. return Json::successful(EventSignUpModel::getBadge($where));
  195. }
  196. /**用户活动核销
  197. * @param string $order_id
  198. * @param int $aid
  199. * @param string $code
  200. * @throws \think\db\exception\DataNotFoundException
  201. * @throws \think\db\exception\ModelNotFoundException
  202. * @throws \think\exception\DbException
  203. */
  204. public function scanCodeSignIn($id){
  205. if (!$id) $this->failed('参数有误!');
  206. $order=EventSignUpModel::where('id',$id)->find();
  207. if(!$order) $this->failed('订单不存在!');
  208. if($order['status']) $this->failed('订单已核销!');
  209. $res=EventSignUpModel::where('id',$id)->where('paid',1)->update(['status'=>1]);
  210. if($res) return Json::successful('ok');
  211. else return Json::fail('核销失败');
  212. }
  213. }