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($messageId){ $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($messageId){ $msg['message_id'] = $messageId; } return $msg; } // 期数验证 $issueInfo = IssueService::model()::where('status',IssueService::model()::STATUS_BETTING)->orderBy('id','desc')->first(); if(empty($issueInfo)){ $issueCloseInfo = IssueService::model()::where('status',IssueService::model()::STATUS_CLOSE)->orderBy('id','desc')->first(); if(empty($issueCloseInfo)){ $text = "暂无可下注期数,本次下注无效!\n"; $msg['text'] = $text; if($messageId){ $msg['message_id'] = $messageId; } return $msg; }else{ $text = "封盘中,本次下注无效!\n"; $msg['text'] = $text; if($messageId){ $msg['message_id'] = $messageId; } return $msg; } } if(!is_numeric($amount) || $amount <= 0){ $text = "投注金额格式不正确!\n"; $text .= "任何疑问都可以联系唯一财务:@{$serviceAccount}"; $msg['text'] = $text; if($messageId){ $msg['message_id'] = $messageId; } return $msg; } // 投注限制校验 if($amount < $gameplayRuleInfo['mininum']){ $text = "下注失败,最小金额限制{$gameplayRuleInfo['mininum']}\n"; $msg['text'] = $text; if($messageId){ $msg['message_id'] = $messageId; } return $msg; } // 投注限制校验 if($amount > $gameplayRuleInfo['maxinum']){ $text = "下注失败,最大金额限制{$gameplayRuleInfo['maxinum']}\n"; $msg['text'] = $text; if($messageId){ $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($messageId){ $msg['message_id'] = $messageId; } return $msg; } $userInfo = UserService::findOne(['member_id' => $memberId]); $data = []; $data['amount'] = $amount; // 分数 $data['keywords'] = $keywords; // 玩法 $data['member_id'] = $memberId; $data['user_id'] = $userInfo->id; $data['issue_no'] = $issueInfo->issue_no; $data['issue_id'] = $issueInfo->id; $data['odds'] = $gameplayRuleInfo['odds']; $newBet = self::model()::create($data); WalletService::updateBalance($memberId,-$amount); BalanceLogService::addLog($memberId,-$amount,$balance,($balance-$amount),'投注',$newBet->id,''); $text = "下注期数:{$issueInfo->issue_no}\n"; $text .= "下注内容\n"; $text .= "--------\n"; $text .= "{$input}\n"; $text .= "--------\n"; $text .= "下注成功\n"; $msg['text'] = $text; return $msg; } }