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

236 lines
7.2 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/13
* @author wild
* @copyright PhpStorm
*/
namespace App\Http\Controllers\Api\Customer;
use App\Enums\LottType;
use App\Model\Customer\Customer;
use App\Model\Lottery;
use App\Model\LotteryType;
use App\Model\Plw;
use App\Service\PlwService;
use App\Utils\Helps;
use App\Utils\ThrowException;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
class PlwController extends BaseController
{
/**
* @api {GET} /api/customer/plw/selling plw-selling
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
*
* @apiSuccessExample {json} 返回结果
* {
* "code": 200,
* "message": "",
* "data": {
* "result": [
* {
* "issue_num": "23064", // 期
* "result": [ // 结果
* "2",
* "6",
* "1",
* "5",
* "7",
* "7",
* "0"
* ]
* }
* ],
* "current": {
* "issue_num": "23067", // 期
* "close_time_str": "2023-06-13 20:40:00" // 截止时间
* }
* }
* }
*/
public function selling(Request $request, PlwService $service)
{
$lotteryTypeId = $request->input('lottery_type_id');
$result = $service->saleLotteries($this->customer(), $lotteryTypeId);
return $this->jsonSuccess($result);
}
/**
* @api {POST} /api/customer/plw/compute plw-compute
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
* @apiParam {Array} odds 数据
* @apiParamExample {json} 请求数据demo
* {
* "lottery_type_id":6,
* "odds":[
* {
* "play_type":"danshi", // danshi | fushi
* "play_odd":[[0,1,2,3],[1,6,7],[2],[3],[4]], // 选择的
* "bets_num":1 // 倍数
* },
*
* ]
* }
*
* @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, PlwService $service)
{
$data = $request->input('odds');
$lotteryTypeId = $request->input('lottery_type_id');
$lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryTypeId)->first();
ThrowException::isTrue(!$lott, '暂不支持该彩种');
$data = $service->refreshOdds($data);
$service->valid($lott,$data);
$computeInfo = $service->computePrizeInfo($data);
return $this->jsonSuccess($computeInfo);
}
/**
* @api {POST} /api/customer/plw/cart plw-cart
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
* @apiParam {Array} odds 数据
* @apiParamExample {json} 请求数据demo
* {
* "lottery_type_id":6,
* "odds":[
* {
* "play_type":"danshi", // danshi | fushi
* "play_odd":[[0,1,2,3],[1,6,7],[2],[3],[4]], // 选择的
* "bets_num":1 // 倍数
* },
*
* ]
* }
*
* @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 cart(Request $request, PlwService $service) {
$data = $request->input('odds');
$lotteryTypeId = $request->input('lottery_type_id');
/** @var Lottery $lott */
$lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryTypeId)->first();
ThrowException::isTrue(!$lott, '暂不支持该彩种');
$data = $service->refreshOdds($data);
$service->valid($lott,$data);
$moneyInfo = $service->computePrizeInfo($data);
/** @var Plw $plw */
$plw = $service->getSellingPlw();
$result = [
'title' => '排列五',
'money' => $moneyInfo['money'],
'prize_min' => $moneyInfo['prize_min'],
'prize_max' => $moneyInfo['prize_max'],
'close_time_str' => sprintf('%s截止请尽快提交投注', $plw->getCloseTime($lott->earlySecond())),
'odds' => $data,
'has_fadan' => false,
'has_union' => $lott->enableHemai(),
'prize_optimize' => $lott->enableOptimizePrize(),
];
return $this->jsonSuccess($result);
}
/**
* @api {POST} /api/customer/plw/order/create plw-order-create
* @apiVersion 0.1.0
* @apiGroup 客户端
*
* @apiParam {Int} lottery_type_id 类型ID
* @apiParam {Array} odds 数据
* @apiParamExample {json} 请求数据demo
* {
* "lottery_type_id":6,
* "odds":[
* {
* "play_type":"danshi", // danshi | fushi
* "play_odd":[[0,1,2,3],[1,6,7],[2],[3],[4]], // 选择的
* "bets_num":1 // 倍数
* },
*
* ]
* }
*
* @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, PlwService $service)
{
$data = $request->all();
$lotteryTypeId = Arr::get($data, 'lottery_type_id');
$lotteryType = LotteryType::find($lotteryTypeId);
ThrowException::isTrue(!$lotteryType || $lotteryType->type != LottType::PLW, '暂不支持该彩种');
/** @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()
]);
}
}