首次提交 Laravel 專案

This commit is contained in:
2025-05-18 08:52:56 +07:00
commit 5e392ae581
264 changed files with 88756 additions and 0 deletions
@@ -0,0 +1,61 @@
<?php
namespace App\Services;
use App\Models\Ledger;
use App\Models\tg_comm;
use App\Models\TgGroupUsers;
use App\Models\UserAccount;
use Illuminate\Support\Facades\Storage;
class TgComm
{
public static function TgComm($msg){
$tg_comm = include Storage::disk('dataconfig')->path('TgComm.php');
foreach ($tg_comm as $v) {
if (str_starts_with($msg['message_text'], $v['command'])){
$res['ok']= true;
$res['id']= $v['id'];
$res['command']= $v['command'];
return $res; //有的话 返回指令ID
}
}
}
public static function comm_1($msg){
}
//@’指令的处理
public static function comm_2($msg){
$res = self::parseLedgerMessage($msg['message_text']); //
if ($res) {
$TgGroupUsers=TgGroupUsers::GetUsername($res['usernamer']);
if ($TgGroupUsers) {
$res=array_merge($res, ['user_id' => $TgGroupUsers->user_id,'chat_id'=>$msg['message_chat_id']]); //加入用户和群组ID
$Ledger=Ledger::AddIncome($res); //写入收支记录
//检查该user_id是否有账户资料,有的话处理余额,没有的话添加相关账户资料
$CheckUserId=UserAccount::CheckUserId($TgGroupUsers->user_id);
} else {
return $res['usernamer'].'-该用户不存在';
}
} else {
return false;
}
}
//拆解【@XXX +1000】字串
private static function parseLedgerMessage(string $text): ?array
{
if (preg_match('/@(\w+)\s*([+-])\s*(\d+(?:\.\d+)?)/', $text, $matches)) {
$usernamer = $matches[1];
$type = $matches[2] === '+' ? '0' : '1';
$amount = $matches[3];
return compact('usernamer', 'type', 'amount');
}
return false; // 格式不符
}
}