|
|
@@ -1,6 +1,7 @@
|
|
|
<?php
|
|
|
|
|
|
namespace App\Services;
|
|
|
+
|
|
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
|
|
use Endroid\QrCode\Builder\Builder;
|
|
|
use Endroid\QrCode\Writer\PngWriter;
|
|
|
@@ -15,6 +16,7 @@ class BaseService
|
|
|
{
|
|
|
const YES = 1;
|
|
|
const NOT = 0;
|
|
|
+
|
|
|
/**
|
|
|
* @description: 生成充值二维码
|
|
|
* @param {*} $address 充值地址
|
|
|
@@ -60,7 +62,7 @@ class BaseService
|
|
|
imagestring($image, $font, $x, $y, $content, $black);
|
|
|
|
|
|
// 生成文件名
|
|
|
- $filename = $address. '.png';
|
|
|
+ $filename = $address . '.png';
|
|
|
$relativePath = 'recharge/' . $filename;
|
|
|
$storagePath = storage_path('app/public/' . $relativePath);
|
|
|
|
|
|
@@ -75,7 +77,7 @@ class BaseService
|
|
|
imagedestroy($image);
|
|
|
|
|
|
// 返回 public 存储路径(可用于 URL)
|
|
|
- return 'storage/'.$relativePath; // 或返回 Storage::url($relativePath);
|
|
|
+ return 'storage/' . $relativePath; // 或返回 Storage::url($relativePath);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -90,8 +92,8 @@ class BaseService
|
|
|
$relativePath = 'recharge/' . $filename;
|
|
|
$storagePath = storage_path('app/public/' . $relativePath);
|
|
|
$path = '';
|
|
|
- if(file_exists($storagePath)){
|
|
|
- $path = 'storage/'.$relativePath;
|
|
|
+ if (file_exists($storagePath)) {
|
|
|
+ $path = 'storage/' . $relativePath;
|
|
|
}
|
|
|
return $path;
|
|
|
}
|
|
|
@@ -106,15 +108,15 @@ class BaseService
|
|
|
* @param {*} $id_name 主键id 名称
|
|
|
* @return {*}
|
|
|
*/
|
|
|
- public static function toTree($list,$pid=0,$level=0,$pid_name='pid',$id_name='id')
|
|
|
+ public static function toTree($list, $pid = 0, $level = 0, $pid_name = 'pid', $id_name = 'id')
|
|
|
{
|
|
|
- $arr=[];
|
|
|
+ $arr = [];
|
|
|
$level++;
|
|
|
- foreach($list as $k => $v){
|
|
|
- if($pid==$v[$pid_name]){
|
|
|
- $v['level']=$level;
|
|
|
- $v['children']=self::toTree($list,$v[$id_name],$level,$pid_name,$id_name);
|
|
|
- $arr[]=$v;
|
|
|
+ foreach ($list as $k => $v) {
|
|
|
+ if ($pid == $v[$pid_name]) {
|
|
|
+ $v['level'] = $level;
|
|
|
+ $v['children'] = self::toTree($list, $v[$id_name], $level, $pid_name, $id_name);
|
|
|
+ $arr[] = $v;
|
|
|
}
|
|
|
}
|
|
|
return $arr;
|
|
|
@@ -193,7 +195,7 @@ class BaseService
|
|
|
* @param {*string} $image 图片
|
|
|
* @return {*}
|
|
|
*/
|
|
|
- public static function bettingGroupNotice($text ,$keyboard = [], $image = '' ,$isTop = false)
|
|
|
+ public static function bettingGroupNotice($text, $keyboard = [], $image = '', $isTop = false): void
|
|
|
{
|
|
|
$bettingGroup = Config::where('field', 'betting_group')->first()->val;
|
|
|
|
|
|
@@ -201,19 +203,19 @@ class BaseService
|
|
|
'chat_id' => "@{$bettingGroup}",
|
|
|
'text' => $text
|
|
|
];
|
|
|
- if(count($keyboard)>0){
|
|
|
+ if (count($keyboard) > 0) {
|
|
|
$botMsg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
|
|
|
}
|
|
|
- if(!empty($image)){
|
|
|
+ if (!empty($image)) {
|
|
|
$botMsg['photo'] = InputFile::create($image);
|
|
|
$botMsg['caption'] = $text;
|
|
|
$botMsg['protect_content'] = true; // 防止转发
|
|
|
$response = self::telegram()->sendPhoto($botMsg);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$response = self::telegram()->sendMessage($botMsg);
|
|
|
}
|
|
|
|
|
|
- if($isTop == true){
|
|
|
+ if ($isTop == true) {
|
|
|
// 获取消息ID
|
|
|
$messageId = $response->get('message_id');
|
|
|
// 置顶消息
|
|
|
@@ -232,9 +234,9 @@ class BaseService
|
|
|
* @param {*string} $image 图片
|
|
|
* @return {*}
|
|
|
*/
|
|
|
- public static function asyncBettingGroupNotice($text ,$keyboard = [], $image = '' ,$isTop = false)
|
|
|
+ public static function asyncBettingGroupNotice($text, $keyboard = [], $image = '', $isTop = false)
|
|
|
{
|
|
|
- SendTelegramGroupMessageJob::dispatch($text ,$keyboard ,$image ,$isTop);
|
|
|
+ SendTelegramGroupMessageJob::dispatch($text, $keyboard, $image, $isTop);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -245,20 +247,20 @@ class BaseService
|
|
|
* @param {*string} $image 图片
|
|
|
* @return {*}
|
|
|
*/
|
|
|
- public static function sendMessage($chatId ,$text ,$keyboard = [] ,$image = '')
|
|
|
+ public static function sendMessage($chatId, $text, $keyboard = [], $image = '')
|
|
|
{
|
|
|
$botMsg = [
|
|
|
'chat_id' => $chatId,
|
|
|
];
|
|
|
- if(count($keyboard)>0){
|
|
|
+ if (count($keyboard) > 0) {
|
|
|
$botMsg['reply_markup'] = json_encode(['inline_keyboard' => $keyboard]);
|
|
|
}
|
|
|
- if($image != ''){
|
|
|
+ if ($image != '') {
|
|
|
$botMsg['photo'] = InputFile::create($image);
|
|
|
$botMsg['caption'] = $text;
|
|
|
$botMsg['protect_content'] = true; // 防止转发
|
|
|
self::telegram()->sendPhoto($botMsg);
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$botMsg['text'] = $text;
|
|
|
self::telegram()->sendMessage($botMsg);
|
|
|
}
|
|
|
@@ -272,9 +274,9 @@ class BaseService
|
|
|
* @param {*string} $image 图片
|
|
|
* @return {*}
|
|
|
*/
|
|
|
- public static function asyncSendMessage($chatId ,$text ,$keyboard = [] ,$image = '')
|
|
|
+ public static function asyncSendMessage($chatId, $text, $keyboard = [], $image = '')
|
|
|
{
|
|
|
- SendTelegramMessageJob::dispatch($chatId ,$text ,$keyboard ,$image);
|
|
|
+ SendTelegramMessageJob::dispatch($chatId, $text, $keyboard, $image);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -283,7 +285,7 @@ class BaseService
|
|
|
* @param {*} $address
|
|
|
* @return {*}
|
|
|
*/
|
|
|
- public static function alertNotice($callbackId ,$text)
|
|
|
+ public static function alertNotice($callbackId, $text)
|
|
|
{
|
|
|
self::telegram()->answerCallbackQuery([
|
|
|
'callback_query_id' => $callbackId,
|
|
|
@@ -306,16 +308,16 @@ class BaseService
|
|
|
|
|
|
$replyInfo = KeyboardService::findOne(['button' => '投注菜单']);
|
|
|
|
|
|
- if($replyInfo && $replyInfo->buttons){
|
|
|
+ if ($replyInfo && $replyInfo->buttons) {
|
|
|
$buttons = json_decode($replyInfo->buttons, true);
|
|
|
|
|
|
- foreach ($buttons as $row) {
|
|
|
+ foreach ($buttons as $row) {
|
|
|
$inlineButton[] = [];
|
|
|
foreach ($row as $button) {
|
|
|
$btn = ['text' => $button['text']];
|
|
|
- if(strpos($button['url'], 'http') === 0){
|
|
|
+ if (strpos($button['url'], 'http') === 0) {
|
|
|
$btn['url'] = $button['url'];
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
$btn['callback_data'] = $button['url'];
|
|
|
}
|
|
|
$inlineButton[count($inlineButton) - 1][] = $btn;
|
|
|
@@ -358,14 +360,15 @@ class BaseService
|
|
|
}
|
|
|
|
|
|
// 获取字符串最后几个字符
|
|
|
- public static function getLastChar($str,$num = 1)
|
|
|
+ public static function getLastChar($str, $num = 1)
|
|
|
{
|
|
|
$length = mb_strlen($str, 'UTF-8');
|
|
|
$lastChar = mb_substr($str, $length - 1, $num, 'UTF-8');
|
|
|
return $lastChar;
|
|
|
}
|
|
|
|
|
|
- public static function generateRandomString($length = 8) {
|
|
|
+ public static function generateRandomString($length = 8)
|
|
|
+ {
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
|
$randomString = '';
|
|
|
|
|
|
@@ -376,7 +379,8 @@ class BaseService
|
|
|
return $randomString;
|
|
|
}
|
|
|
|
|
|
- public static function generateRandomNumber($length = 8) {
|
|
|
+ public static function generateRandomNumber($length = 8)
|
|
|
+ {
|
|
|
$characters = '0123456789';
|
|
|
$randomString = '';
|
|
|
|
|
|
@@ -387,7 +391,8 @@ class BaseService
|
|
|
return $randomString;
|
|
|
}
|
|
|
|
|
|
- public static function hideMiddleDigits($number, $hideCount = 4) {
|
|
|
+ public static function hideMiddleDigits($number, $hideCount = 4)
|
|
|
+ {
|
|
|
$length = strlen($number);
|
|
|
|
|
|
if ($length <= $hideCount) {
|
|
|
@@ -406,9 +411,9 @@ class BaseService
|
|
|
}
|
|
|
|
|
|
// 生成订单号
|
|
|
- public static function createOrderNo($prefix = 'pc28_',$memberId = null)
|
|
|
+ public static function createOrderNo($prefix = 'pc28_', $memberId = null)
|
|
|
{
|
|
|
- // 处理会员ID,获取后四位
|
|
|
+ // 处理会员ID,获取后四位
|
|
|
if ($memberId) {
|
|
|
$memberSuffix = str_pad(substr($memberId, -4), 4, '0', STR_PAD_LEFT);
|
|
|
} else {
|
|
|
@@ -470,10 +475,10 @@ class BaseService
|
|
|
$y = $qrSize + $padding + 5;
|
|
|
imagestring($image, $font, $x, $y, $content, $black);
|
|
|
|
|
|
- $address_name = self::generateRandomString(20).time();
|
|
|
+ $address_name = self::generateRandomString(20) . time();
|
|
|
|
|
|
// 生成文件名
|
|
|
- $filename = $address_name. '.png';
|
|
|
+ $filename = $address_name . '.png';
|
|
|
$relativePath = 'payment/' . $filename;
|
|
|
$storagePath = storage_path('app/public/' . $relativePath);
|
|
|
|
|
|
@@ -488,7 +493,7 @@ class BaseService
|
|
|
imagedestroy($image);
|
|
|
|
|
|
// 返回 public 存储路径(可用于 URL)
|
|
|
- return 'storage/'.$relativePath; // 或返回 Storage::url($relativePath);
|
|
|
+ return 'storage/' . $relativePath; // 或返回 Storage::url($relativePath);
|
|
|
}
|
|
|
|
|
|
}
|