370 lines
13 KiB
PHP
Executable File
370 lines
13 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Http\Controllers\Api\Customer;
|
||
|
||
use App\Model\Customer\Customer;
|
||
use App\Model\Lottery;
|
||
use App\Model\LotteryType;
|
||
use App\Model\Zq\BjdcSfggOdds;
|
||
use App\Service\BjdcSfggService;
|
||
use App\Utils\Helps;
|
||
use App\Utils\ThrowException;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Arr;
|
||
|
||
class BjdcSfggController extends BaseController
|
||
{
|
||
/**
|
||
* @api {GET} /api/customer/bjdc_sfgg/selling bjdc_sfgg-投注列表
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} lottery_type_id 彩票类型ID
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "play_types": [
|
||
* {
|
||
* "name": "胜负过关",
|
||
* "play_type": "sfgg_odds"
|
||
* }
|
||
* ],
|
||
* "competitions": [
|
||
* "全部",
|
||
* "韩足总杯",
|
||
* "J2联赛",
|
||
* "J1联赛",
|
||
* "芬甲",
|
||
* "欧洲U21 3",
|
||
* "挪威杯",
|
||
* "冰岛超",
|
||
* "解放者杯",
|
||
* "金杯赛",
|
||
* "南俱杯"
|
||
* ],
|
||
* "odds": [
|
||
* {
|
||
* "id": 22,
|
||
* "odds_id": 137260,
|
||
* "match_id": 451538,
|
||
* "issue_num": "23065",
|
||
* "play_num": 22,
|
||
* "bd_competition_name": "韩足总杯",
|
||
* "bd_competition_name_full": "韩足总杯",
|
||
* "bd_home_team_name": "仁川联",
|
||
* "bd_home_team_name_full": "仁川联",
|
||
* "bd_away_team_name": "水原三星蓝翼",
|
||
* "bd_away_team_name_full": "水原三星蓝翼",
|
||
* "sale_state": "selling",
|
||
* "is_reverse": 0,
|
||
* "close_time": "2023-06-28 17:35:00",
|
||
* "sfgg_odds": {
|
||
* "win": 2.4,
|
||
* "win_updown": 0,
|
||
* "loss": 1.71,
|
||
* "loss_updown": 0,
|
||
* "handicap": -0.5,
|
||
* "handicap_updown": 0
|
||
* },
|
||
* "created_at": "2023-06-28 10:17:28",
|
||
* "updated_at": "2023-06-28 10:19:31",
|
||
* "deleted_at": null,
|
||
* "real_close_str": "17:35截止"
|
||
* },
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function selling(Request $request, BjdcSfggService $service)
|
||
{
|
||
$lotteryTypeId = $request->input('lottery_type_id');
|
||
$odds = $service->saleLotteries($this->customer(), $lotteryTypeId);
|
||
return $this->jsonSuccess($odds);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {POST} /api/customer/bjdc_sfgg/compute bjdc_sfgg-计算奖金和投注金额
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} lottery_type_id 彩种类型id
|
||
* @apiParam {Int} bets_num 倍数
|
||
* @apiParam {Array} pass_mode_keys m串n的key
|
||
* @apiParam {Object} odds 组合投注信息
|
||
* @apiParam {String} play_type 玩法
|
||
* @apiParamExample {json} 请求示例
|
||
* {
|
||
* "lottery_type_id": 1, // 彩种类型id
|
||
* "playgames": {
|
||
* 1: { // 彩票赔率数据id
|
||
* "spf_odds": { // 玩法,如:spf,bf,bqc(胜平负,比分,半全场)等
|
||
* "win": 2.3 // 投注的值
|
||
* },
|
||
* "bf_odds": {
|
||
* "win": 2.3
|
||
* },
|
||
* ...
|
||
* },
|
||
* ...
|
||
* }
|
||
* }
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "money": 24, // 投注金额
|
||
* "prize_min": 200, // 最低中奖金额
|
||
* "prize_max": 400 // 最高中奖金额
|
||
* }
|
||
* }
|
||
*/
|
||
public function compute(Request $request, BjdcSfggService $service)
|
||
{
|
||
$odds = $request->input('odds');
|
||
$betsNum = $request->input('bets_num');
|
||
$passModeKeys = $request->input('pass_mode_keys'); // 例如['2.1']
|
||
$playType = $request->input('play_type');
|
||
if (!$odds) {
|
||
return $this->jsonFailed('请选择比赛');
|
||
}
|
||
$odds = $service->refreshOdds($odds);
|
||
$moneyInfo = $service->computePrizeInfo($odds, $betsNum, $passModeKeys);
|
||
return $this->jsonSuccess($moneyInfo);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/bjdc_sfgg/cart bjdc_sfgg-购入车信息
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} lottery_type_id 彩种类型id
|
||
* @apiParam {Int} bets_num 倍数
|
||
* @apiParam {Object} odds 组合投注信息
|
||
* @apiParamExample {json} 请求示例
|
||
* {
|
||
* "lottery_type_id": 1, // 彩种类型id
|
||
* "playgames": {
|
||
* 1: { // 彩票赔率数据id
|
||
* "spf_odds": { // 玩法,如:spf,bf,bqc(胜平负,比分,半全场)等
|
||
* "win": 2.3 // 投注的值
|
||
* },
|
||
* "bf_odds": {
|
||
* "win": 2.3
|
||
* },
|
||
* ...
|
||
* },
|
||
* ...
|
||
* }
|
||
* }
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code": 200,
|
||
* "message": "",
|
||
* "data": {
|
||
* "has_fadan": true,// 是否支持发单
|
||
* "has_union": false, // 是否支持合买
|
||
* "money": 12, // 投注金额
|
||
* "prize_min": 100, // 最低奖金
|
||
* "prize_max": 200, // 最高奖金
|
||
* "close_time_str": "3214:323 32:32:32截止,请尽快提交投注", // 提示信息
|
||
* "pass_mode":
|
||
* {
|
||
* "multi": [], // 多选
|
||
* "single": [ // 单选
|
||
* {
|
||
* "key": "2.1",
|
||
* "title": "2串1"
|
||
* }
|
||
* ]
|
||
* }
|
||
* ,
|
||
* "odds": [ // 购买界面所需信息,字段参考【bjdc_sfgg-投注列表】
|
||
* {
|
||
* "id": 3,
|
||
* "lottery_type_id": 1,
|
||
* "odds_id": 1,
|
||
* "match_id": 1,
|
||
* "issue_num": "2022-01-01/周一",
|
||
* "play_num": 21,
|
||
* "jc_competition_name": "adsf离开家",
|
||
* "jc_competition_name_full": "发三分大赛",
|
||
* "jc_home_team_name": "发顺丰",
|
||
* "jc_home_team_name_full": "发送",
|
||
* "jc_away_team_name": "fda",
|
||
* "jc_away_team_name_full": "fda",
|
||
* "sale_state": "selling",
|
||
* "is_reverse": 0,
|
||
* "real_close_time": "1969-12-31 23:50:00",
|
||
* "order_state": "selling",
|
||
* "spf_odds": {
|
||
* "win": 2.85,
|
||
* "loss": 2.25
|
||
* },
|
||
* "rq_odds": {
|
||
* "win": 2.85
|
||
* },
|
||
* "created_at": null,
|
||
* "updated_at": null,
|
||
* "deleted_at": null,
|
||
* "real_close_str": "23:50截止",
|
||
* "issue_num_week": "周一",
|
||
* "issue_num_day": "2022-01-01"
|
||
* },
|
||
* ...
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function cart(Request $request,
|
||
BjdcSfggService $service)
|
||
{
|
||
$typeId = $request->input('lottery_type_id');
|
||
$oddsData = $request->input('odds');
|
||
$betsNum = $request->input('bets_num');
|
||
$playType = $request->input('play_type');
|
||
|
||
if (!$oddsData) {
|
||
return $this->jsonFailed('请选择比赛');
|
||
}
|
||
$lott = Lottery::active()->shopAndType($this->customerShopId(), $typeId)->first();
|
||
|
||
ThrowException::isTrue(!$lott, '暂不支持该彩种');
|
||
ThrowException::isTrue($betsNum < 1, '请输入倍数');
|
||
|
||
$service->valid($lott, $playType, $oddsData);
|
||
|
||
$passMode = BjdcSfggService::generateZqPassModeInfo($oddsData, $playType);
|
||
|
||
$oddsData = $service->refreshOdds($oddsData);
|
||
$oddsNum = count($oddsData);
|
||
$moneyInfo = $service->computePrizeInfo($oddsData, $betsNum, [$oddsNum . '.1']);
|
||
|
||
$resultMatch = $service->getBjdcSfggOddsFromData($lott, $oddsData);
|
||
|
||
$earlyCloseTime = null;
|
||
foreach ($resultMatch as $match) {
|
||
if (!isset($earlyCloseTime)) {
|
||
$earlyCloseTime = $match->close_time;
|
||
}
|
||
if ($earlyCloseTime > $match->close_time) {
|
||
$earlyCloseTime = $match->real_close_time;
|
||
}
|
||
}
|
||
|
||
$data = [
|
||
'title' => '北京单场',
|
||
'money' => $moneyInfo['money'],
|
||
'prize_min' => $moneyInfo['prize_min'],
|
||
'prize_max' => $moneyInfo['prize_max'],
|
||
'close_time_str' => sprintf('%s截止,请尽快提交投注', $earlyCloseTime),
|
||
'pass_mode' => $passMode,
|
||
'odds' => $resultMatch,
|
||
'has_fadan' => true,
|
||
'has_union' => $lott->enableHemai(),
|
||
'prize_optimize' => $lott->enableOptimizePrize(),
|
||
];
|
||
|
||
return $this->jsonSuccess($data);
|
||
}
|
||
|
||
|
||
/**
|
||
* @api {POST} /api/customer/bjdc_sfgg/order/create bjdc_sfgg-创建订单/发单/合买
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} lottery_type_id 彩种类型id
|
||
* @apiParam {Int} bets_num 倍数
|
||
* @apiParam {String} pass_mode_keys 过关方式
|
||
* @apiParam {Int} type 1普通投注;2发单;3合买;4跟单
|
||
* @apiParam {String} [fadan_order_no] 跟单的订单no(只有在type=4的时候生效)
|
||
* @apiParam {Int} [type_mode] 1截止后公开,2公开;3认购可见
|
||
* @apiParam {String} [type_desc] 发单/合买描述,发单/合买时必填
|
||
* @apiParam {Int} [union_piece_total] 总份数,合买时必填
|
||
* @apiParam {Int} [union_piece_buy] 购买份数,合买时必填
|
||
* @apiParam {Int} [union_piece_keep] 保底份数,合买时必填
|
||
* @apiParam {Int} [union_keep] 是否全额保底:1是,0否,合买时必填
|
||
* @apiParam {Int} [union_brokerage] 佣金,合买时必填
|
||
* @apiParam {Object} odds 组合投注信息
|
||
* @apiParamExample {json} 请求示例
|
||
* {
|
||
* "lottery_type_id":9,
|
||
* "bets_num":1,
|
||
* "pass_mode_keys":["2.1","1.1"],
|
||
* "odds":{
|
||
* "69": {
|
||
* "bf_odds": {
|
||
* "wx":51.39
|
||
* },
|
||
* "bqc_odds": {
|
||
* "dd":51.39
|
||
* }
|
||
* },
|
||
* "68": {
|
||
* "bqc_odds": {
|
||
* "dd":51.39
|
||
* }
|
||
* }
|
||
* }
|
||
* }
|
||
*
|
||
* @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, BjdcSfggService $service)
|
||
{
|
||
$data = $request->all();
|
||
$lotteryTypeId = Arr::get($data, 'lottery_type_id');
|
||
$lotteryType = LotteryType::find($lotteryTypeId);
|
||
ThrowException::isTrue(!$lotteryType, '暂不支持该彩种');
|
||
|
||
/** @var Customer $customer */
|
||
$customer = Customer::find($this->customerId());
|
||
if (!$this->getPayTypes()) {
|
||
ThrowException::isTrue($customer->balanceActive() <= 0, '该店铺暂未开启支付');
|
||
}
|
||
|
||
$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()
|
||
]);
|
||
}
|
||
|
||
|
||
}
|