jingcai-php/app/Http/Controllers/Api/Customer/JclqController.php

477 lines
18 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
/**
* @createtime 2023/4/26
* @author wild
* @copyright PhpStorm
*/
namespace App\Http\Controllers\Api\Customer;
use App\Enums\BoolEnum;
use App\Enums\PayType;
use App\Model\Customer\Customer;
use App\Model\Lottery;
use App\Model\LotteryType;
use App\Model\Lq\JclqOdds;
use App\Service\JclqService;
use App\Utils\Helps;
use App\Utils\ThrowException;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
class JclqController extends BaseController
{
/**
* @api {GET} /api/customer/jclq/selling 竞彩篮球-投注列表
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 彩票类型ID
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "play_types": [ // 玩法
* {
* "name": "混合投注",
* "play_type": "mixed"
* },
* {
* "name": "胜负(让)",
* "play_type": "sf_rf_odds"
* },
* {
* "name": "大小分",
* "play_type": "dxf_odds"
* },
* {
* "name": "胜分差",
* "play_type": "sfc_odds"
* }
* ],
* "competitions": [ // 赛事
* "全部",
* "111"
* ],
* "odds": [
* {
* "id": 1,
* "odds_id": 1,
* "match_id": 11,
* "issue_num": "期号", // 期号
* "play_num": "场次", // 场次
* "jc_competition_name": "", // 竞彩网赛事名
* "jc_competition_name_full": "1111", // 赛事全称
* "jc_home_team_name": "1111", // 主队名
* "jc_home_team_name_full": "1111", // 主队全名
* "jc_away_team_name": "2222", // 客队
* "jc_away_team_name_full": "2222",
* "sale_state": "selling", // 销售状态selling: 销售中, stopSelling: 停售)
* "is_reverse": 0,
* "close_time": "2023-04-27 21:26:30", // 截止时间
* "order_state": "selling",
* "sf_odds": { // 胜负赔率
* "win": 1.45, // 主胜
* "win_updown": 0,
* "loss": 2.07, // 客负
* "loss_updown": -1,
* "single": 0, // 单关标识, 0: 串关, 1: 单关
* "single_updown": 0
* },
* "rf_odds": { // 让分胜负
* "win": 1.7, // 主胜
* "win_updown": 0,
* "loss": 1.7, // 客胜
* "loss_updown": 0,
* "single": 0,
* "single_updown": 0,
* "handicap": -1.5, // 让分
* "handicap_updown": 0
* },
* "sfc_odds": { // 胜分差
* "l1": 4.15, // //客胜1-5分赔率
* "l1_updown": 0,
* "l2": 3.9, //客胜6-10分赔率
* "l2_updown": 0,
* "l3": 6.4, //客胜11-15分赔率
* "l3_updown": 0,
* "l4": 10, //客胜16-20分赔率
* "l4_updown": 0,
* "l5": 21, //客胜16-20分赔率
* "l5_updown": 0,
* "l6": 22, //客胜16-20分赔率
* "l6_updown": 0,
* "w1": 4.6, //客胜16-20分赔率
* "w1_updown": 0,
* "w2": 5.2, //主胜6-10分赔率
* "w2_updown": 0,
* "w3": 10, //主胜6-10分赔率
* "w3_updown": 0,
* "w4": 21, //主胜6-10分赔率
* "w4_updown": 0,
* "w5": 36, //主胜6-10分赔率
* "w5_updown": 0,
* "w6": 49, //主胜6-10分赔率
* "w6_updown": 0,
* "single": 1,
* "single_updown": 0
* },
* "dxf_odds": { // 大小分
* "big": 1.75, //大分赔率
* "big_updown": 0,
* "small": 1.66, //大分赔率
* "small_updown": 0,
* "single": 1,
* "single_updown": 0,
* "totalScore": 233.5, //大分赔率
* "totalScore_updown": 0
* },
* "created_at": null,
* "updated_at": null,
* "deleted_at": null,
* "real_close_time": "1969-12-31 23:40:00",
* "real_close_str": "23:40截止", // 截止时间
* "issue_num_week": null, // 星期
* "issue_num_day": "期号" // 日期
* }
* ]
* }
* }
*/
public function selling(Request $request, JclqService $service)
{
$lotteryTypeId = $request->input('lottery_type_id');
$odds = $service->saleLotteries($this->customer(), $lotteryTypeId);
return $this->jsonSuccess($odds);
}
/**
* @api {POST} /api/customer/jclq/valid 竞彩篮球-验证组合方案是否可用
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 彩种类型id
* @apiParam {String} play_type 玩法
* @apiParam {Object} odds 组合投注信息
* @apiParamExample {json} 请求示例
* {
* "lottery_type_id": 1, // 彩种类型id
* "playgames": {
* 1: { // 彩票赔率数据id
* "rf_odds": { // 玩法sf_odds,sf_odds,sfc_odds
* "win": 2.3 // 投注的值
* },
* "sf_odds": {
* "win": 2.3
* },
* ...
* },
* ...
* }
* }
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 410,
* "message": "不允许组合方案", // 验证结果信息只要code不是200就是未通过验证
* "data": null
* }
*/
public function valid(Request $request, JclqService $service)
{
$lotteryTypeId = $request->input('lottery_type_id');
$playType = $request->input('play_type');
$data = $request->input('odds');
$lotteryType = LotteryType::find($lotteryTypeId);
if (!$lotteryType) {
return $this->jsonFailed('非法数据');
}
$lottery = Lottery::active()->where('shop_id', $this->customerShopId())
->where('lottery_type_id', $lotteryTypeId)
->first();
ThrowException::isTrue(!$lottery, '该店铺不支持此彩');
$service->valid($lottery, $playType, $data);
return $this->jsonSuccess([]);
}
/**
* @api {POST} /api/customer/jclq/compute 竞彩蓝球-计算奖金和投注金额
* @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
* "rf_odds": { // 玩法sf_odds,sf_odds,sfc_odds
* "win": 2.3 // 投注的值
* },
* "sf_odds": {
* "win": 2.3
* },
* ...
* },
* ...
* }
* }
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "money": 24, // 投注金额
* "prize_min": 200, // 最低中奖金额
* "prize_max": 400 // 最高中奖金额
* }
* }
*/
public function compute(Request $request, JclqService $service)
{
$odds = $request->input('odds');
$betsNum = $request->input('bets_num');
$passModeKeys = $request->input('pass_mode_keys'); // 例如['2.1']
if (!$odds) {
return $this->jsonFailed('');
}
$oddsInfo = $service->refreshOdds($odds);
$odds = $oddsInfo['odds'];
$moneyInfo = $service->computePrizeInfo($odds, $betsNum, $passModeKeys);
return $this->jsonSuccess($moneyInfo);
}
/**
* @api {POST} /api/customer/jclq/cart 竞彩蓝球-购物车信息
* @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
* "rf_odds": { // 玩法sf_odds,sf_odds,sfc_odds
* "win": 2.3 // 投注的值
* },
* "sf_odds": {
* "win": 2.3
* },
* ...
* },
* ...
* }
* }
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "has_fadan": true,// 是否支持发单
* "has_union": false, // 是否支持合买
* "title": "",
* "money": 8,
* "prize_min": 9.18, // 最小中奖金额
* "prize_max": 48.28, // 最大中间金额
* "close_time_str": "1970-01-01 07:20:00截止请尽快提交", // 截止时间
* "pass_mode": [ // m串n
* {
* "key": "2.1",
* "title": "2串1"
* }
* ],
* "odds": [
* {
* "id": 1,
* "odds_id": 5131,
* "match_id": 97880,
* "issue_num": "2023-05-05/周五",
* "play_num": "302", // 场次
* "jc_competition_name": "欧篮联", // 赛事
* "jc_competition_name_full": "欧洲篮球联赛",
* "jc_home_team_name": "费内巴切", // 主队
* "jc_home_team_name_full": "费内巴切",
* "jc_away_team_name": "奥林匹亚", // 客队
* "jc_away_team_name_full": "奥林匹亚科斯",
* "sale_state": "selling",
* "is_reverse": 0,
* "close_time": "2023-05-05 22:00:00", // 比赛截止时间
* "order_state": "selling",
* "sf_odds": { // 下注信息
* "win": 1.76,
* "loss": 1.64
* },
* "created_at": "2023-05-05 20:35:37",
* "updated_at": "2023-05-05 20:35:37",
* "deleted_at": null,
* "real_close_time": "1970-01-01 07:40:00", // 下注截止时间
* "real_close_str": "07:40截止", // 截止时间
* "issue_num_week": "周五", // 星期n
* "issue_num_day": "2023-05-05" // 日期
* }
* ]
* }
* }
*/
public function cart(Request $request, JclqService $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, '暂不支持该彩种');
$service->valid($lott,$playType, $oddsData);
$oddsNum = count($oddsData);
$passMode = JclqService::generateLqPassModeInfo($oddsData, $playType);
if ($lott->mn == BoolEnum::NO) {
$passMode['single'] = [];
}
$oddsDataInfo = $service->refreshOdds($oddsData);
$oddsData = $oddsDataInfo['odds'];
$moneyInfo = $service->computePrizeInfo($oddsData, $betsNum, [$oddsNum .'.1']);
$resultMatch = $service->getJczqOddsFromData($lott, $oddsData);
$earlyCloseTime = null;
foreach ($resultMatch as $match) {
if (!isset($earlyCloseTime)) {
$earlyCloseTime = $match->real_close_time;
}
if ($earlyCloseTime > $match->real_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' => Helps::genDanEnable(),
'has_union' => $lott->enableHemai(),
'prize_optimize' => $lott->enableOptimizePrize(),
];
return $this->jsonSuccess($data);
}
/**
* @api {POST} /api/customer/jclq/order/create 竞彩篮球-创建订单/发单/合买
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 彩种类型id
* @apiParam {Int} bets_num 倍数
* @apiParam {String} play_type 玩法
* @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":1, // 彩种
* "bets_num":2, // 倍数
* "play_type":"all", // 玩法
* "pass_mode_keys":["2.1"], // 过关方式
* "odds":{ // 赔率/组合投注信息
* "1":{ // 彩票赔率数据id
* "spf_odds":{
* "win":2.3,
* "loss":3.1
* },
* "rq_odds":{
* "win":1.2
* }
* },
* ...
* }
* }
*
* @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, JclqService $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()
]);
}
}