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

246 lines
8.6 KiB
PHP
Executable File
Raw Permalink 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/6/05
* @author wild
* @copyright PhpStorm
*/
namespace App\Http\Controllers\Api\Customer;
use App\Model\Customer\Customer;
use App\Model\Dlt;
use App\Model\Lottery;
use App\Model\LotteryType;
use App\Model\Zq\JczqGuan;
use App\Model\Zq\JczqGuanYaOdds;
use App\Service\GuanYaService;
use App\Utils\Helps;
use App\Utils\ThrowException;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
class GuanYaController extends BaseController
{
//Route::get('jclq/selling', 'JclqController@selling');
//Route::post('jclq/valid', 'JclqController@valid');
//Route::post('jclq/cart', 'JclqController@cart');
//Route::post('jclq/compute', 'JclqController@compute');
//Route::post('jclq/order/create', 'JclqController@orderCreate');
/**
* @api {GET} /api/customer/guan_ya/selling 冠亚军selling
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "id": 1,
* "type": "guanya",
* "guanya_id": 3,
* "competition": 21,
* "competition_name": "世界杯",
* "season": "2022",
* "sales_state": "selling", // 销售状态selling: 销售中, stopSelling: 停售)
* "lott_state": "hasLottery", // 开奖状态noLottery: 未开奖,hasLottery: 已开奖)
* "close_time": "2022-12-18 23:00:00", // 截止投注时间
* "odds": [
* {
* "id": 75,
* "odds": 2.6, // 赔率
* "teamId": 301, //
* "teamName": "巴西", // 球队
* "optionNum": 1, // 序号
* "showState": "out", // 竞彩官方显示状态empty: “”, out: 出局, invalid: 无效选项, selling: 已开售, stopSelling: 已停售, win: 胜出)
* "orderState": "stopSelling", // 竞彩官方销售状态selling: 销售中, stopSelling: 停售)
* "salesState": "stopSelling" //实际销售状态selling: 销售中, stopSelling: 停售)
* }
* ],
* "created_at": "2024-06-05 11:07:46",
* "updated_at": "2024-06-05 11:13:17",
* "deleted_at": null
* }
* }
*/
public function selling(Request $request, GuanYaService $service)
{
$lotteryTypeId = $request->input('lottery_type_id');
$result = $service->saleLotteries($this->customer(), $lotteryTypeId);
return $this->jsonSuccess($result);
}
/**
* @api {POST} /api/customer/guan_ya/compute 冠亚军compute
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
* @apiParam {Object} odds 数据
* {
* "lottery_type_id":13,
* "bets_num":1, 倍数
* "odds":{ id => 赔率
* "1":11,
* "2":22
* }
* }
*
* @apiSuccessExample {json} 返回结果
* {
* "code":200,
* "message":"",
* "data":{
* "zhu_num":5,
* "bets_num":2,
* "expect_bets":0,
* "money":10, // 总金额
* "prize_min":0,
* "prize_max":0
* }
* }
*/
public function compute(Request $request, GuanYaService $service)
{
$odds = $request->input('odds');
$lotteryTypeId = $request->input('lottery_type_id');
$betsNum = $request->input('bets_num');
$lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryTypeId)->first();
ThrowException::isTrue(!$lott, '暂不支持该彩种');
$odds = $service->refreshOdds($odds);
$computeInfo = $service->computePrizeInfo($odds, $betsNum);
return $this->jsonSuccess($computeInfo);
}
/**
* @api {POST} /api/customer/guan_ya/cart 冠亚军cart
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
* @apiParam {Object} odds 数据 参考compute的odds
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "title": "冠亚军",
* "money": 4,
* "prize_min": 10.4,
* "prize_max": 10.4,
* "close_time_str": "1970-01-01 07:50:00截止请尽快提交投注",
* "odds": [ // 这个地方如果格式不对,给我说
* {
* "id": 2,
* "jczq_guanya_id": 1,
* "odds_id": 76,
* "team_id": 305,
* "team_name": "法国",
* "option_num": 2,
* "odds": "1.76",
* "season": "",
* "sales_state": "stopSelling",
* "show_state": "out",
* "order_state": "stopSelling",
* "created_at": "2024-06-05 11:10:14",
* "updated_at": "2024-06-05 11:13:17",
* "deleted_at": null
* }
* ],
* "has_fadan": false,
* "has_union": true,
* "prize_optimize": false
* }
* }
*/
public function cart(Request $request, GuanYaService $service) {
$odds = $request->input('odds');
$betsNum = $request->input('bets_num');
$lotteryTypeId = $request->input('lottery_type_id');
/** @var JczqGuan $guanya */
$guanya = $service->getSellingGuan();
/** @var Lottery $lott */
$lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryTypeId)->first();
ThrowException::isTrue(!$lott, '暂不支持该彩种');
$odds = $service->refreshOdds($odds);
$moneyInfo = $service->computePrizeInfo($odds, $betsNum);
$odds = JczqGuanYaOdds::whereIn('id', array_keys($odds))->orderBy('option_num', 'asc')->get();
$data = [
'title' => '冠亚军',
'money' => $moneyInfo['money'],
'prize_min' => $moneyInfo['prize_min'],
'prize_max' => $moneyInfo['prize_max'],
'zhu_num' => $moneyInfo['zhu_num'],
'close_time_str' => sprintf('%s截止请尽快提交投注', $guanya->getCloseTime($lott->earlySecond())),
'odds' => $odds,
'has_fadan' => false,
'has_union' => $lott->enableHemai(),
'prize_optimize' => $lott->enableOptimizePrize(),
];
return $this->jsonSuccess($data);
}
/**
* @api {POST} /api/customer/guan_ya/order/create 冠亚军-order-create
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
* @apiParam {Object} odds 数据
*
* @apiSuccessExample {json} 返回结果
* {
* "code":200,
* "message":"",
* "data":{
* "zhu_num":5,
* "bets_num":2,
* "expect_bets":0,
* "money":10, // 总金额
* "prize_min":0,
* "prize_max":0
* }
* }
*/
public function orderCreate(Request $request, GuanYaService $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()
]);
}
}