| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147 |
- <?php
- namespace app\mobile\controller;
- use app\common\model\SeatApplyModel;
- use app\common\model\SeatModel;
- use app\mobile\MobileBaseController;
- use think\facade\Db;
- class Seat extends MobileBaseController
- {
- public function apply()
- {
- $id = input('id', 0);
- if (empty($id)) {
- $id = session('mobile.seat.id');
- if (empty($id)) {
- tip('提示','该活动不存在或已结束');
- }
- } else {
- session('mobile.seat.id', $id);
- }
- $seat = SeatModel::where('id', $id)->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 '登录成功';
- }
- }
|