first commit

This commit is contained in:
Your Name
2026-01-19 14:19:22 +08:00
commit fe2d9c1868
4777 changed files with 665503 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
// +----------------------------------------------------------------------
// | likeadmin快速开发前后端分离管理后台PHP版
// +----------------------------------------------------------------------
// | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
// | 开源版本可自由商用可去除界面版权logo
// | gitee下载https://gitee.com/likeshop_gitee/likeadmin
// | github下载https://github.com/likeshop-github/likeadmin
// | 访问官网https://www.likeadmin.cn
// | likeadmin团队 版权所有 拥有最终解释权
// +----------------------------------------------------------------------
// | author: likeadminTeam
// +----------------------------------------------------------------------
namespace app\common\command;
use app\common\enum\CrontabEnum;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use Cron\CronExpression;
use think\facade\Console;
use app\common\model\Crontab as CrontabModel;
/**
* 定时任务
* Class Crontab
* @package app\command
*/
class Crontab extends Command
{
protected function configure()
{
$this->setName('crontab')
->setDescription('定时任务');
}
protected function execute(Input $input, Output $output)
{
$lists = CrontabModel::where('status', CrontabEnum::START)->select()->toArray();
if (empty($lists)) {
return false;
}
foreach ($lists as $item) {
$nextTime = (new CronExpression($item['expression']))
->getNextRunDate($item['last_time'])
->getTimestamp();
if ($nextTime > time()) {
// 未到时间,不执行
continue;
}
// 开始执行
self::start($item);
}
}
public static function start($item)
{
// 开始执行
$startTime = microtime(true);
try {
$params = explode(' ', $item['params']);
if (is_array($params) && !empty($item['params'])) {
Console::call($item['command'], $params);
} else {
Console::call($item['command']);
}
// 清除错误信息
CrontabModel::where('id', $item['id'])->update(['error' => '']);
} catch (\Exception $e) {
// 记录错误信息
CrontabModel::where('id', $item['id'])->update([
'error' => $e->getMessage(),
'status' => CrontabEnum::ERROR
]);
} finally {
$endTime = microtime(true);
// 本次执行时间
$useTime = round(($endTime - $startTime), 2);
// 最大执行时间
$maxTime = max($useTime, $item['max_time']);
// 更新最后执行时间
CrontabModel::where('id', $item['id'])->update([
'last_time' => time(),
'time' => $useTime,
'max_time' => $maxTime
]);
}
}
}

View File

@@ -0,0 +1,147 @@
<?php
namespace app\common\command;
use app\common\service\{UtilsService};
use app\common\model\finance\UserFinance;
use app\common\model\item\ItemRecord;
use think\console\{Command,Output,Input};
use think\facade\{Db,Log};
class InvestSettle extends Command
{
protected function configure()
{
$this->setName('invest_settle')
->setDescription('投资结算');
}
protected function execute(Input $input, Output $output)
{
Db::startTrans();
try {
$nowTime = time();
//每日/时付息,到期还本
$lists1 = ItemRecord::where(['status' => 1])
->where("type IN (1,4)")
->order(['create_time' => 'desc','id' => 'desc'])
->select()
->toArray();
foreach ($lists1 as &$item) {
//判断返还时间
$return_num = $item['wait_num'] - 1;
$return_time = $item['end_time'] - ($return_num * 24 * 60 * 60);
if($item['type'] == 4 ) $return_time = $item['end_time'] - ($return_num * 1 * 60 * 60);
if($return_time > $nowTime) continue;
$status = 1;
//最后一期,返还本金
if($return_num == 0){
$status = 2;//完成
//本金返回
//记录日志
UtilsService::user_finance_add(
$item['user_id'],
18,
1,
$item['money'],
$item['sn'],
''
);
//用户资金修改
UtilsService::user_money_change($item['user_id'], 1, $item['money'],'user_money');
}
ItemRecord::update([
'id' => $item['id'],
'wait_num' => $return_num,
'status' => $status //状态1进行中2已完成
]);
//利息返还
$money_rate = round($item['money'] * $item['rate'] / 100 , 2);
if($money_rate > 0.01){
//记录日志
UtilsService::user_finance_add(
$item['user_id'],
17,
1,
$money_rate,
$item['sn'],
''
);
//用户资金修改
UtilsService::user_money_change($item['user_id'], 1, $money_rate,'user_money');
UtilsService::user_money_change($item['user_id'], 1, $money_rate,'total_income_invest');
//团队收益奖励
UtilsService::team_reward_add($item['user_id'],$money_rate,2);
}
}
// //到期还本付息
// $lists2 = ItemRecord::where(['status' => 1])
// ->where("end_time <= $nowTime")
// ->where("type IN (2,3)")
// ->order(['create_time' => 'desc','id' => 'desc'])
// ->select()
// ->toArray();
// foreach ($lists2 as &$item) {
// ItemRecord::update([
// 'id' => $item['id'],
// 'wait_num' => 0,
// 'status' => 2 //状态1进行中2已完成
// ]);
// //本金返回
// //记录日志
// UtilsService::user_finance_add(
// $item['user_id'],
// 18,
// 1,
// $item['money'],
// $item['sn'],
// ''
// );
// //用户资金修改
// UtilsService::user_money_change($item['user_id'], 1, $item['money'],'user_money');
// //利息返还
// if($item['total_income'] > 0.01){
// //记录日志
// UtilsService::user_finance_add(
// $item['user_id'],
// 17,
// 1,
// $item['total_income'],
// $item['sn'],
// ''
// );
// //用户资金修改
// UtilsService::user_money_change($item['user_id'], 1, $item['total_income'],'user_money');
// UtilsService::user_money_change($item['user_id'], 1, $item['total_income'],'total_income_invest');
// //团队收益奖励
// UtilsService::team_reward_add($item['user_id'],$item['total_income'],2);
// }
// }
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::write('失败原因:' . $e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace app\common\command;
use app\common\model\item\Item;
use think\console\{Command,Output,Input};
use think\facade\{Db,Log};
class ItemProgress extends Command
{
protected function configure()
{
$this->setName('item_progress')
->setDescription('项目进度自增');
}
protected function execute(Input $input, Output $output)
{
Db::startTrans();
try {
$items = Item::where(['is_show' => 1])
->order(['create_time' => 'desc'])
->select()
->toArray();
foreach ($items as &$item) {
if($item['progress'] >= 100) continue;
$item['progress'] = $item['progress'] + $item['progress_auto'];
Item::update([
'id' => $item['id'],
'progress' => $item['progress'],
]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::write('失败原因:' . $e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,134 @@
<?php
namespace app\common\command;
use app\common\service\{ConfigService,UtilsService};
use app\common\model\user\{User,UserTron};
use app\common\model\finance\RechargeRecord;
use app\common\model\setting\RechargeMethod;
use think\console\{Command,Output,Input};
use think\facade\{Db,Log};
class TronOrder extends Command
{
protected function configure()
{
$this->setName('tron_order')
->setDescription('同步波场钱包余额');
}
protected function execute(Input $input, Output $output)
{
Db::startTrans();
try {
//为了性能只获取最后操作时间5分钟内的钱包
$now_5 = time() - 5 * 60;//5分钟前
$userTrons = UserTron::where("last_time > $now_5")
->order(['create_time' => 'desc'])
->select()
->toArray();
//查询余额
$data = [
'action' => 'infos',
];
$addrs = array();
foreach ($userTrons as $key=>$userTron) {
$addrs[$key] = $userTron['address'];
}
if(count($addrs) > 0){
$data['addrs'] = json_encode($addrs);
$response = UtilsService::usdt_request($data, 'POST');
$response = json_decode($response, true);
if($response['code'] == 200){
foreach ($response['data']['data'] as $res) {
UserTron::where(['address' => $res['addr']])
->update([
'money_trx' => $res['trx'],
'money_usdt' => $res['usdt'],
]);
//充值逻辑
foreach ($userTrons as $userTron) {
if($userTron['address'] == $res['addr']){
//金额相差超过0.01才生效
if(floatval($res['usdt']) - floatval($userTron['money_usdt']) >= 0.01){
$method = RechargeMethod::where(['id' => $userTron['method_id']])->findOrEmpty();
if(!$method->isEmpty()){
$money = $res['usdt'] - $userTron['money_usdt'];
$order_amount_act = round($money * $method['rate'] , 2);
//判断充值金额
$config = ConfigService::get('website', 'trade');
if ($order_amount_act >= $config['recharge_min']) {
$data = [
'sn' => generate_sn(RechargeRecord::class, 'sn'),
'user_id' => $userTron['user_id'],
'method_id' => $userTron['method_id'],
'amount' => $order_amount_act,
'amount_act' => round($money , $method['precision']),
'rate' => $method['rate'],
'symbol' => $method['symbol'],
'status' => 1,
];
$record = RechargeRecord::create($data);
//记录日志
UtilsService::user_finance_add(
$userTron['user_id'],
1,
1,
$data['amount'],
'',
'',
1//冻结
);
//用户资金修改
UtilsService::user_money_change($userTron['user_id'], 1, $data['amount'],'user_money');
//充值金额增加
UtilsService::user_money_change($userTron['user_id'], 1, $data['amount'],'total_recharge');
//充值活动奖励
UtilsService::activity_reward_add($userTron['user_id'],$data['amount']);
//更新充值记录用户余额
$user = User::where(['id' => $record['user_id']])->findOrEmpty();
if (!$user->isEmpty()) {
RechargeRecord::update([
'id' => $record['id'],
'user_money' => $user['user_money']
]);
//充值次数+1
User::update([
'id' => $user['id'],
'recharge_num' => $user['recharge_num'] + 1
]);
}
}
}
}
}
}
}
}
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::write('失败原因:' . $e->getMessage());
return false;
}
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace app\common\command;
use app\common\model\finance\UserFinance;
use think\console\{Command,Output,Input};
use think\facade\{Db,Log};
class UnfreezeFunds extends Command
{
protected function configure()
{
$this->setName('unfreeze_funds')
->setDescription('用户资金释放');
}
protected function execute(Input $input, Output $output)
{
Db::startTrans();
try {
$nowTime = time();
$lists = UserFinance::where(['frozen' => 1])
->where("thaw_time < $nowTime")
->order(['id' => 'desc'])
->select()
->toArray();
foreach ($lists as &$item) {
UserFinance::update([
'id' => $item['id'],
'frozen' => 0,
]);
}
Db::commit();
} catch (\Exception $e) {
Db::rollback();
Log::write('失败原因:' . $e->getMessage());
return false;
}
}
}