214 lines
6.7 KiB
PHP
Executable File
214 lines
6.7 KiB
PHP
Executable File
<?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\Service\DltService;
|
||
use App\Utils\Helps;
|
||
use App\Utils\ThrowException;
|
||
use Illuminate\Http\Request;
|
||
use Illuminate\Support\Arr;
|
||
|
||
class DltController 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/dlt/selling dlt-selling
|
||
* @apiVersion 0.1.0
|
||
* @apiGroup 客户端
|
||
*
|
||
* @apiParam {Int} lottery_type_id 类型ID
|
||
*
|
||
* @apiSuccessExample {json} 返回结果
|
||
* {
|
||
* "code":200,
|
||
* "message":"",
|
||
* "data":{
|
||
* "play_type":[ // 玩法
|
||
* {
|
||
* "name":"单式",
|
||
* "play_type":"danshi"
|
||
* },
|
||
* ],
|
||
* "result":[ // 结果
|
||
* {
|
||
* "issue_num":"20222", // 期号
|
||
* "result_qian":[ // 前区
|
||
* 1,
|
||
* 2,
|
||
* 3,
|
||
* 4,
|
||
* 5
|
||
* ],
|
||
* "result_hou":[ // 后区
|
||
* 1,
|
||
* 2
|
||
* ]
|
||
* }
|
||
* ]
|
||
* }
|
||
* }
|
||
*/
|
||
public function selling(Request $request, DltService $service)
|
||
{
|
||
$lotteryTypeId = $request->input('lottery_type_id');
|
||
$result = $service->saleLotteries($this->customer(), $lotteryTypeId);
|
||
return $this->jsonSuccess($result);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/dlt/compute dlt-compute
|
||
* @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 compute(Request $request, DltService $service)
|
||
{
|
||
$data = $request->input('odds');
|
||
$enableAdd = $request->input('enable_add');
|
||
$lotteryTypeId = $request->input('lottery_type_id');
|
||
$lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryTypeId)->first();
|
||
ThrowException::isTrue(!$lott, '暂不支持该彩种');
|
||
|
||
$data = $service->refreshOdds($data);
|
||
$data = $service->refreshOddsForCreateOrder($data, $enableAdd);
|
||
$service->valid($lott,$data);
|
||
$computeInfo = $service->computePrizeInfo($data);
|
||
|
||
return $this->jsonSuccess($computeInfo);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/dlt/cart dlt-cart
|
||
* @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 cart(Request $request, DltService $service) {
|
||
$data = $request->input('odds');
|
||
$enableAdd = $request->input('enable_add');
|
||
$lotteryTypeId = $request->input('lottery_type_id');
|
||
/** @var Lottery $lott */
|
||
$lott = Lottery::active()->shopAndType($this->customerShopId(), $lotteryTypeId)->first();
|
||
ThrowException::isTrue(!$lott, '暂不支持该彩种');
|
||
$data = $service->refreshOdds($data);
|
||
$data = $service->refreshOddsForCreateOrder($data, $enableAdd);
|
||
$service->valid($lott,$data);
|
||
$moneyInfo = $service->computePrizeInfo($data);
|
||
|
||
/** @var Dlt $dlt */
|
||
$dlt = $service->getSellingDlt();
|
||
$data = [
|
||
'title' => '大乐透',
|
||
'money' => $moneyInfo['money'],
|
||
'prize_min' => $moneyInfo['prize_min'],
|
||
'prize_max' => $moneyInfo['prize_max'],
|
||
'close_time_str' => sprintf('%s截止,请尽快提交投注', $dlt->getCloseTime($lott->earlySecond())),
|
||
'odds' => $data,
|
||
'has_fadan' => false,
|
||
'has_union' => $lott->enableHemai(),
|
||
'prize_optimize' => $lott->enableOptimizePrize(),
|
||
];
|
||
|
||
return $this->jsonSuccess($data);
|
||
}
|
||
|
||
/**
|
||
* @api {POST} /api/customer/dlt/order/create dlt-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, DltService $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()
|
||
]);
|
||
}
|
||
}
|