get($cacheKey)){ sr_throw('请不要频繁操作'); } **/ $box_info = Db::name('box')->where('id', $params['box_id'])->find(); if (!$box_info){ sr_throw('参数错误'); } //$redis->set($cacheKey, json_encode(['uid'=> $userId,'box'=> $box_info], 256), rand(1,2)); //if ($box_info['open_status']!=1 && $user_info['id'] != 5344517){ if ($box_info['open_status']!=1){ sr_throw('预约未开启'); } if ($params['buy_count'] > 20){ sr_throw('最多可预约20个'); } if ($params['buy_count'] < 5){ $count = Db::name('box_record')->where('uid', $uid)->where('box_id', $params['box_id'])->where('status', 1)->where('num', '<', 5)->count('id'); if ( $count >= 4){ sr_throw('每一场数量小于5最多只能预约4次'); } } if (Db::name('box_record')->where('uid', $uid)->where('status', 1)->sum('num') > 100){ sr_throw('每一场最多可预约100次'); } $times = explode('|', $box_info['time_set']); $cur_timeday = sr_getcurtime(time(), 'Y-m-d'); $time = time(); $lun = 1; $day_before = 0; $day_end = 0; $can_buy = false; foreach ($times as $key=>$val){ $timesarr = explode('-', $val); $begin_time = strtotime($cur_timeday.' '.$timesarr[0]); $end_time=strtotime($cur_timeday.' '.$timesarr[1]); if ($time > $begin_time && $time < $end_time){ $can_buy = true; $lun = $key+1; } } //if (!$can_buy && $user_info['id'] != 5344517){ if (!$can_buy){ sr_throw('预约失败,还未开始预约、或预约已结束'); } $total_pay = $params['buy_count'] * env('boxsetting.one_box_price'); $user_model = new UserModel(); // $userinfo = $user_model->where('id', $uid)->find(); // 修改 by wes at 2023-02-19 16点 $user_info = $user_model->where(['id'=> $uid])->field('id,score,money,has_fd')->find(); // end if ($params['pay_type'] == 1){ if ($user_info['score'] < $total_pay){ sr_throw('积分不足,预约失败'); } edit_user_score(1, $uid, $total_pay); } if ($params['pay_type'] == 2){ if ($user_info['money'] < $total_pay){ sr_throw('余额不足,预约失败'); } edit_user_money(1, $uid, $total_pay); } Db::name('box_record')->insert([ 'box_id'=>$params['box_id'], 'num'=>$params['buy_count'], 'lun_count'=>$lun, 'uid'=>$uid, 'create_time'=>sr_getcurtime($time), 'box_img'=>$box_info['box_img'], 'box_title'=>$box_info['box_title'], 'qi_count'=>$box_info['qi_count'], 'pay_type'=>$params['pay_type'] ]); // 设置用户已经预约福袋 Db::name('user')->where('id', $uid)->inc('total_appoint_count', $params['buy_count'])->update(); if ($user_info['has_fd']==0){ Db::name('user')->where('id', $uid)->save([ 'has_fd'=>1 ]); } } }