input('lottery_type_id'); $odds = $service->saleLotteries($this->customer(), $lotteryTypeId); return $this->jsonSuccess($odds); } /** * @api {POST} /api/customer/ctzq_sfc9/valid sfc9-校验信息 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} lottery_type_id 彩票类型ID * @apiParam {Object} odds 投注信息 * * @apiParamExample {json} 请求示例 * { * "lottery_type_id":11, * "bets_num":1, * "odds":{ * "43":{"3":1,"1":1}, * "44":{"3":1}, * "45":{"3":1}, * "46":{"3":1}, * "47":{"3":1}, * "48":{"3":1}, * "49":{"3":1}, * "50":{"3":1}, * "51":{"3":1}, * "52":{"3":1}, * "53":{"3":1}, * "54":{"3":1}, * "55":{"1":1}, * "56":{"0":1} * } * } */ public function valid(Request $request, CtzqSfc9Service $service) { $lotteryType = $this->getLotteryType($request); $lottery = Lottery::active()->where('shop_id', $this->customerShopId()) ->where('lottery_type_id', $lotteryType->id) ->first(); ThrowException::isTrue(!$lottery, '不支持该彩种'); $allData = $request->all(); $allData['odds'] = $service->getOddsFromRequestData($allData['odds']); $service->valid($lottery, $allData); return $this->jsonSuccess([]); } private function getLotteryType(Request $request) { $lotteryTypeId = $request->input('lottery_type_id'); $lotteryType = LotteryType::where('type', LottType::CTZQ_SFC9)->find($lotteryTypeId); ThrowException::isTrue(!$lotteryType, '无此彩种'); return $lotteryType; } /** * @api {POST} /api/customer/ctzq_sfc9/compute sfc9-计算金额 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} lottery_type_id 彩票类型ID * @apiParam {Object} odds 投注信息 * @apiParamExample {json} 请求示例 * { * "lottery_type_id":4, * "issue_num":20008, * "bets_num":5, * "odds":{ * "5":{ // odds id * "home_odds":[1,2], // 主队投注 * "away_odds":[1] // 客队投注 * }, * } * } * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "money": 111,// 价格 * } * } * } */ public function compute(Request $request, CtzqSfc9Service $service) { $oddsData = $request->input('odds'); $betsNum = intval($request->input('bets_num')); if (!$oddsData) { return $this->jsonFailed('请选择比赛'); } ThrowException::isTrue($betsNum < 1, '倍数不能小于1'); $lotteryType = $this->getLotteryType($request); $lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryType->id)->first(); ThrowException::isTrue(!$lott, '暂不支持该彩种'); $allData = $request->all(); $allData['odds'] = $service->getOddsFromRequestData($allData['odds']); $service->valid($lott, $allData); $moneyInfo = $service->computePrizeInfo( $allData['odds'], $betsNum); return $this->jsonSuccess($moneyInfo); } /** * @api {POST} /api/customer/ctzq_sfc9/cart sfc9-购入车信息/计算金额 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} lottery_type_id 彩票类型ID * @apiParam {Object} odds 投注信息 * @apiParamExample {json} 请求示例 * { * "lottery_type_id":4, * "issue_num":20008, * "bets_num":5, * "odds":{ * "5":{ // odds id * "home_odds":[1,2], // 主队投注 * "away_odds":[1] // 客队投注 * }, * } * } * @apiSuccessExample {json} 返回结果 * { * "code": 200, * "message": "", * "data": { * "has_fadan": true,// 是否支持发单 * "has_union": false, // 是否支持合买 * "money": 4, // 总投注金额 * "bets_num": 1, // 投注倍数 * "zhu_num": 1, // 投注数 * "odds": [{ * "id": 1, * "ret_id": 1, * "type": "ctzq_jqc", * "issue_num": "20007", * "state": "selling", * "start_time": "2023-04-26 23:20:10", * "end_time": "2023-04-27 23:20:10", * "prize_time": "2023-04-27 23:20:10", * "result_info": "", * "sales": "0.0000", * "jackpot": "0.0000", * "first_prize_num": 0, * "first_prize_value": 0, * "created_at": null, * "updated_at": null, * "deleted_at": null, * "competition_name": "xxxx", * "match_time_date": "2023-04-26", * "match_time_hour": "23:20开赛", * "close_time": "2023-04-27 23:00:10", * "close_time_str": "2023-04-27 23:00:10截止,请尽快提交投注", // 截止时间 * "matches": [ * { * "id": 1, * "ctzq_jqc_id": 1, * "no": 1, * "match_id": 2000, * "jc_home_team_name": "jc_home_team_name+0", // 主队 * "jc_home_team_name_full": "jc_home_team_name_full+0", * "jc_away_team_name": "jc_away_team_name+0", // 客队 * "jc_away_team_name_full": "jc_away_team_name_full+0", * "is_reverse": 0, * "result": -1, * "created_at": "2023-04-26T15:26:31.000000Z", * "updated_at": "2023-04-26T15:26:31.000000Z", * "deleted_at": null, * "home_odds_select": [ // 主队投注分数 * { * "score": "0", // 分数 * "select": false // 未选择 * }, * { * "score": "1", * "select": true // 已选择 * }, * { * "score": "2", * "select": true * }, * { * "score": "3+", * "select": false * } * ], * "away_odds_select": [ // 客队投注分数 * { * "score": "0", * "select": false * }, * { * "score": "1", * "select": true * }, * { * "score": "2", * "select": false * }, * { * "score": "3+", * "select": false * } * ] * }, * ... * ] * }] * } * } */ public function cart(Request $request, CtzqSfc9Service $service) { $oddsData = $request->input('odds'); $betsNum = intval($request->input('bets_num')); if (!$oddsData) { return $this->jsonFailed('请选择比赛'); } ThrowException::isTrue($betsNum < 1, '倍数不能小于1'); $lotteryType = $this->getLotteryType($request); $lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryType->id)->first(); ThrowException::isTrue(!$lott, '暂不支持该彩种'); $allData = $request->all(); $allData['odds'] = $service->getOddsFromRequestData($allData['odds']); $oddsData = $allData['odds']; $service->valid($lott, $allData); $moneyInfo = $service->computePrizeInfo($oddsData, $betsNum); $ctzqSfcMatchId = array_key_first($oddsData); $ctzqJqcMatch = CtzqSfcMatch::find($ctzqSfcMatchId); ThrowException::isTrue(!$ctzqJqcMatch, '无对应的比赛数据,无法投注'); $ctzq = CtzqSfc::where('id', $ctzqJqcMatch->ctzq_sfc_id)->where('state', SaleState::Selling)->first(); ThrowException::isTrue(!$ctzq, '比赛不存在'); $ctzq->match_time_date = date('Y-m-d', strtotime($ctzq->start_time)); $ctzq->match_time_hour = date('H:i', strtotime($ctzq->start_time)) . '开赛'; $ctzq->close_time = $ctzq->getCloseTime($lott->earlySecond()); $ctzq->close_time_str = sprintf('%s截止,请尽快提交投注', $ctzq->close_time); $matchList = $ctzq->matches()->whereIn('id', array_keys($oddsData))->get(); foreach ($matchList as $match) { $odds = []; $oddArr = Arr::get($oddsData, $match->id); foreach ($match->odds as $odd) { $odds[] = [ 'score' => $odd, 'select' => in_array($odd, $oddArr) ]; } $match->odds_select = $odds; } unset($ctzq->matchs); $ctzq->matches = $matchList; $data = [ 'title' => '任选9场', 'money' => $moneyInfo['money'], 'zhu_num' => $moneyInfo['zhu_num'], 'bets_num' => $betsNum, 'close_time_str' => $ctzq->close_time_str, 'odds' => [$ctzq], 'has_fadan' => false, 'has_union' => $lott->enableHemai(), 'prize_optimize' => $lott->enableOptimizePrize(), ]; return $this->jsonSuccess($data); } /** * @api {POST} /api/customer/ctzq_sfc9/order/create sfc9-创建订单/合买 * @apiVersion 0.1.0 * @apiGroup 客户端 * * @apiParam {Int} lottery_type_id 彩票类型ID * @apiParam {Object} odds 投注信息 * @apiParamExample {json} 请求示例 * { * "lottery_type_id":4, * "issue_num":20008, * "bets_num":5, * "odds":{ * "5":{ // odds id * "home_odds":[1,2], // 主队投注 * "away_odds":[1] // 客队投注 * }, * } * } * * @apiSuccessExample {json} 返回结果 * { * "code":200, * "message":"", * "data":{ * "order_sn":"P2023033000000010", // 订单号 * "balance":"0.00", // 余额 * "money":0, // 订单总金额 * "need_pay_money":0, // 需要支付的金额 * "username":"发达", // 用户名 * "lottery":"jc足球混合投注", // 投注彩票信息 * "pay_types":[ // 支付方式 * { * "pay_type":"alipay", * "name":"支付宝" * } * ] * } * } */ public function orderCreate(Request $request, CtzqSfc9Service $service) { $data = $request->all(); $lotteryType = $this->getLotteryType($request); ThrowException::isTrue(!$lotteryType, '暂不支持该彩种'); /** @var Customer $customer */ $customer = Customer::find($this->customerId()); if (!$this->getPayTypes()) { ThrowException::isTrue($customer->balanceActive()<=0, '该店铺暂未开启支付'); } $data['odds'] = $service->getOddsFromRequestData($data['odds']); $order = $service->createOrder($this->customer(), $data); $payMoney = $order->getPayMoney(); /** @var Customer $customer */ $customer = Customer::find($this->customerId()); $balance = $customer->balanceActive(); return $this->jsonSuccess([ 'order_sn' => $order->order_sn, 'balance' => $balance, 'money' => $payMoney, 'need_pay_money' => Helps::floatFormat($balance >= $payMoney ? 0 : $payMoney - $balance), 'username' => $this->customer()->name, 'lottery' => $order->lotteryName(), 'pay_types' => $this->getPayTypes() ]); } }