input('issue_no'); $member_id = $request->input('member_id'); $keywords = $request->input('keywords'); $amount = floatval($request->input('amount', 0)); $fake_time = $request->input('fake_time'); $game = $request->input('game', 'pc28'); $gameTypeMap = ['pc28' => 6, 'ca28' => 5]; if (!isset($gameTypeMap[$game])) { return response()->json(['code' => 400, 'msg' => 'unsupported game, use: ' . implode(',', array_keys($gameTypeMap))]); } $type = $gameTypeMap[$game]; if (!$issue_no || !$member_id || !$keywords || $amount <= 0) { return response()->json(['code' => 400, 'msg' => 'missing params']); } $issue = PcIssue::where('issue_no', $issue_no)->first(); if (!$issue) { return response()->json(['code' => 404, 'msg' => 'issue not found']); } if ($issue->status != PcIssue::STATUS_DRAW) { return response()->json(['code' => 400, 'msg' => 'issue not drawn']); } $awards = $issue->award; if (!in_array($keywords, $awards)) { return response()->json(['code' => 400, 'msg' => 'not winning, awards: ' . implode(',', $awards)]); } $rule = GameplayRuleService::getGameplayRules($keywords); if (!$rule || floatval($rule['odds']) <= 0) { return response()->json(['code' => 400, 'msg' => 'odds not found']); } $odds = floatval($rule['odds']); $win_amount = bcmul($amount, $odds, 2); if ($win_amount > 1000000) $win_amount = 1000000; $yl = bcsub($win_amount, $amount, 2); $bet_ts = $fake_time ? strtotime($fake_time) : (strtotime($issue->end_time) - rand(60, 300)); DB::beginTransaction(); try { $order = LhcOrder::create([ 'amount' => $amount, 'number' => $keywords, 'member_id' => $member_id, 'issue' => $issue_no, 'lhc_number_id' => $issue->id, 'odds' => $odds, 'type' => $type, 'lottery_status' => LhcOrder::STATUS_WIN, 'win_amount' => $win_amount, 'profit_and_loss' => $yl, 'total_amount' => $amount, 'created_at' => $bet_ts, 'updated_at' => $bet_ts, ]); LhcOrderItem::create([ 'ordernum' => $order->ordernum, 'number' => $keywords, 'member_id' => $member_id, 'lottery_status' => LhcOrder::STATUS_WIN, 'win_amount' => $win_amount, 'profit_and_loss' => $yl, 'created_at' => $bet_ts, 'updated_at' => $bet_ts, ]); $walletInfo = WalletService::findOne(['member_id' => $member_id]); if (!$walletInfo) { DB::rollBack(); return response()->json(['code' => 404, 'msg' => 'wallet not found']); } $balance = floatval($walletInfo['available_balance']); WalletService::updateBalance($member_id, $win_amount); BalanceLogService::addLog( $member_id, $win_amount, $balance, bcadd($balance, $win_amount, 2), '中奖', $order->id, "盈利:{$yl}" ); DB::commit(); return response()->json([ 'code' => 200, 'issue_no' => $issue_no, 'keywords' => $keywords, 'awards' => $awards, 'amount' => $amount, 'odds' => $odds, 'win_amount' => $win_amount, 'profit' => $yl, 'balance_before' => $balance, 'balance_after' => bcadd($balance, $win_amount, 2), 'order_id' => $order->id, 'bet_time' => date('Y-m-d H:i:s', $bet_ts), ]); } catch (\Exception $e) { DB::rollBack(); Log::error('settle_inject: ' . $e->getMessage()); return response()->json(['code' => 500, 'msg' => $e->getMessage()]); } } }