123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171 |
- <?php
- namespace App\Services;
- use App\Services\BaseService;
- use App\Models\Bet;
- use App\Models\Config;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Collection;
- use Illuminate\Support\Facades\Cache;
- use Illuminate\Support\Facades\Log;
- use App\Services\GameplayRuleService;
- use App\Services\WalletService;
- use App\Services\IssueService;
- /**
- * 投注
- */
- class BetService extends BaseService
- {
- /**
- * @description: 模型
- * @return {string}
- */
- public static function model() :string
- {
- return Bet::class;
- }
- /**
- * @description: 枚举
- * @return {*}
- */
- public static function enum() :string
- {
- return '';
- }
- /**
- * @description: 获取查询条件
- * @param {array} $search 查询内容
- * @return {array}
- */
- public static function getWhere(array $search = []) :array
- {
- $where = [];
- if(isset($search['issue_no']) && !empty($search['issue_no'])){
- $where[] = ['issue_no', '=', $search['issue_no']];
- }
- if(isset($search['member_id']) && !empty($search['member_id'])){
- $where[] = ['member_id', '=', $search['member_id']];
- }
- if(isset($search['issue_id']) && !empty($search['issue_id'])){
- $where[] = ['issue_id', '=', $search['issue_id']];
- }
- if(isset($search['id']) && !empty($search['id'])){
- $where[] = ['id', '=', $search['id']];
- }
- if(isset($search['user_id']) && !empty($search['user_id'])){
- $where[] = ['user_id', '=', $search['user_id']];
- }
- if(isset($search['status']) && !empty($search['status'])){
- $where[] = ['status', '=', $search['status']];
- }
- return $where;
- }
- /**
- * @description: 查询单条数据
- * @param array $search
- * @return \App\Models\Coin|null
- */
- public static function findOne(array $search): ?Bet
- {
- return self::model()::where(self::getWhere($search))->first();
- }
- /**
- * @description: 查询所有数据
- * @param array $search
- * @return \Illuminate\Database\Eloquent\Collection
- */
- public static function findAll(array $search = [])
- {
- return self::model()::where(self::getWhere($search))->get();
- }
- /**
- * @description: 分页查询
- * @param array $search
- * @return \Illuminate\Contracts\Pagination\LengthAwarePaginator
- */
- public static function paginate(array $search = [])
- {
- $limit = isset($search['limit'])?$search['limit']:15;
- $paginator = self::model()::where(self::getWhere($search))->paginate($limit);
- return ['total' => $paginator->total(), 'data' => $paginator->items()];
- }
- /**
- * @description: 投注操作
- * @param {string} $memberId
- * @param {string} $input
- * @return {*}
- */
- public static function bet(string $memberId,string $input ,$messageId = 0)
- {
- $msg = [];
- $msg['chat_id'] = $memberId;
- // 钱包生成
- // $walletInfo = WalletService::getUserWallet($memberId);
-
- // 分解投注的内容
- $betResult = GameplayRuleService::bettingRuleVerify($input);
- $serviceAccount = Config::where('field', 'service_account')->first()->val;
- if($betResult == null){
- $text = "消息格式错误!\n";
- $text .= "任何疑问都可以联系唯一财务:@{$serviceAccount}";
- $msg['text'] = $text;
- if($memberId){
- $msg['message_id'] = $messageId;
- }
- return $msg;
- }
- $keywords = $betResult['rule']; // 玩法
- $amount = $betResult['amount']; // 投注金额
- $GameplayRuleInfo = GameplayRuleService::getGameplayRules($keywords);
- if($GameplayRuleInfo == null){
- $text = "玩法未配置!\n";
- $text .= "任何疑问都可以联系唯一财务:@{$serviceAccount}";
- $msg['text'] = $text;
- if($memberId){
- $msg['message_id'] = $messageId;
- }
- return $msg;
- }
- if(!is_numeric($amount) || $amount <= 0){
- $text = "投注金额格式不正确!\n";
- $text .= "任何疑问都可以联系唯一财务:@{$serviceAccount}";
- $msg['text'] = $text;
- if($memberId){
- $msg['message_id'] = $messageId;
- }
- return $msg;
- }
- // 获取用户余额
- $walletInfo = WalletService::findOne(['member_id' => $memberId]);
- $balance = $walletInfo['available_balance'];
- // 余额计算
- if($balance < $amount){
- $text = "余额不足,本次下注无效!\n";
- $msg['text'] = $text;
- if($memberId){
- $msg['message_id'] = $messageId;
- }
- return $msg;
- }
- }
- }
|