123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120 |
- <?php
- namespace App\Http\Controllers\Gteam;
- use App\Http\Controllers\Miniprogram\Auth;
- use App\Http\Resources\Gteam\EnterResource;
- use App\Models\Gteam\EnterModel;
- use App\Services\Gteam\EnterService;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- class EnterController extends Controller
- {
- private $type = [
- "wz" => ["wz_wx", "wz_qq"],
- "cj" => ["cj_wx", "cj_qq"],
- ];
- public function store(Request $request)
- {
- $this->validate($request, [
- 'activity_id' => 'required',
- 'type' => 'required',
- ]);
- $uid = Auth::auth();
- $activity_id = $request->activity_id;
- $rank_type = $request->input('rank_type', 4);
- $game_type = $request->type;
- $sex = $request->input('sex', 0);
- \DB::beginTransaction();
- try {
- $enterService = new EnterService();
- $ack = $enterService->enter($uid, $activity_id, $game_type, $sex, $rank_type);
- $enterService->push($ack);
- \DB::commit();
- return response()->json([
- 'code' => 200,
- 'message' => 'OK',
- 'data' => [
- 'id' => $ack
- ]
- ]);
- } catch (\Exception $e) {
- app('sentry')->captureException($e);
- \DB::rollBack();
- throw $e;
- }
- }
- /**
- * 预约的列表
- * @param Request $request
- * @return \Illuminate\Http\JsonResponse
- * @throws \Tymon\JWTAuth\Exceptions\JWTException
- */
- public function index(Request $request)
- {
- $uid = Auth::auth();
- $this->validate($request, [
- 'type' => 'in:wz,cj',
- ]);
- $builder = EnterModel::where('uid', $uid)->when($request->filled('type'), function ($query) use ($request) {
- return $query->whereIn('type', $this->type[$request->type]);
- })->where('activity_id', '>', 0);
- $enters = $builder->orderBy('created_at', 'desc')->paginate($request->get('per_page', 20));
- foreach ($enters as $enter) {
- $enter->activity;
- }
- return response()->json([
- 'code' => 200,
- 'data' => $enters
- ]);
- }
- public function show(Request $request, $id)
- {
- $uid = Auth::auth();
- $enter = EnterModel::findOrFail($id);
- $enter->room;
- $enter->activity;
- return new EnterResource($enter);
- }
- /**
- * 活动男女数量
- * @param int $activity_id
- * @return array
- */
- public function sexproportion(int $activity_id)
- {
- $es = new EnterService();
- $data = $es->sexproportion($activity_id);
- return array(
- 'code' => 200,
- 'message' => 'success',
- 'data' => $data
- );
- }
- /**
- * 取消报名
- * @param Request $request
- * @param $enter_id
- * @return \Illuminate\Http\JsonResponse
- */
- public function destroy(Request $request, $enter_id)
- {
- $service = new EnterService();
- $service->unenter($enter_id);
- return response()->json([
- "code" => 200,
- "message" => "OK"
- ]);
- }
- }
|