find(); if (empty($seat)) { tip('提示','该活动不存在或已结束'); } session('mobile.seat.id', $id); $open_id = get_open_id(); $apply = SeatApplyModel::where('open_id', $open_id)->where('seat_id', $id)->find(); if (empty($apply)) { if ($seat['apply'] >= $seat['total']) { tip('提示', '座位已满'); } else { return redirect(url('seat/fillInfo')); } } else { tip('提示', '座位已满'); return redirect(url('seat/showSeat')); } } public function fillInfo() { $id = session('mobile.seat.id'); if (empty($id)) { tip('提示','该活动不存在或已结束'); } get_open_id(); return view(); } public function fillInfoPost() { $data = input('param.'); if (empty($data['name'])) { ajax_error('姓名不能为空'); } if (empty($data['mobile'])) { ajax_error('手机号不能为空'); } $id = session('mobile.seat.id'); $open_id = get_open_id(); Db::startTrans(); try { //是否还有座位 $seat = SeatModel::where('id', $id)->lock(true)->find(); if ($seat['apply'] >= $seat['total']) { throw new \Exception('座位已被选完'); } //报名人数+1 $seat->apply++; $seat->save(); //报名明细 $apply_info = [ 'seat_id' => $id, 'no' => $seat->apply, 'open_id' => $open_id, 'name' => $data['name'], 'mobile' => $data['mobile'], ]; $no = $seat->apply; $seat_info = ''; foreach ($seat['seat_list'] as $k => $v) { if ($no <= $v) { $seat_info = ($k + 1) . "排" . $no . '座'; break; } else { $no -= $v; } } $apply_info['seat'] = $seat_info; SeatApplyModel::create($apply_info); // 提交事务 Db::commit(); } catch (\Exception $e) { // 回滚事务 Db::rollback(); ajax_error('座位已满'); } ajax_success(); } public function showSeat() { $id = session('mobile.seat.id'); $open_id = get_open_id(); $seat = SeatApplyModel::where('seat_id', $id)->where('open_id',$open_id)->find(); return view('',['msg'=>$seat['seat']]); } public function login() { return redirect('https://www.jucai.gov.cn/api/auth/wechat_auth?url=' . urlencode(url('/mobile/seat/wechatBack'))); } /** * 微信回调 */ public function wechatBack() { $param = input('param.'); session('mobile.open_id',$param['openid']); return redirect(url('seat/apply')); } public function login1() { session('mobile.open_id','linwu'); return '登录成功'; } }