Files
weipan02_server/application/command/Yebeveryday.php
2025-08-15 11:02:14 +08:00

107 lines
4.6 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace app\command;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
class InterestTreasure extends Command
{
protected $outputInfo;
protected function configure()
{
// 指令配置
$this->setName('InterestTreasure');
// 设置参数
}
protected function execute(Input $input, Output $output)
{
// 指令执行
$this->outputInfo = $output;
}
public function closeAccount()
{
$this->outputInfo->writeln('开始结算');
$this->yebeveryday();
$this->outputInfo->writeln('结算完成');
}
public function yebeveryday()
{
$nowtime = time();
$keepnum = 0;
$closenum = 0;
$getdoings = Db::table('lc_yuebao_lists')->where('status=1 and profit_time<=' . (time() - 86400))->select();
foreach ($getdoings as $getdoing) {
try {
$new_profit_time = $nowtime;
if ($new_profit_time >= $getdoing['end_time']) {
$new_profit_time = $getdoing['end_time'];
}
$second_time = $new_profit_time - $getdoing['profit_time'];
$nowprift = ($getdoing['money'] * $getdoing['lily'] / 100) * floor($second_time / 86400);
if ($nowprift > 0) {
Db::table('lc_yuebao_lists')->where('id='. $getdoing['id'])
->update([
'profit_time' => $getdoing['profit_time'] + $second_time,
'nowprofit' => $getdoing['nowprofit'] + $nowprift,
'profit' => $getdoing['profit'] + floor(($nowtime - $getdoing['start_time']) / 86400)
]);
$keepnum = $keepnum + 1;
//获取用户余额;
addFinance($getdoing['uid'], $nowprift, 1, "余额宝利息返利");
$getuserinfo = Db::table('lc_user')->where('id=' . $getdoing['uid'])->find();
//记录日志!
$id = $getdoing['id'];
unset($getdoing['id']);
unset($getdoing['profit_time']);
unset($getdoing['profit']);
$getdoing['status'] = 2;
$getdoing['end_time'] = time();
$getdoing['nowprofit'] = $nowprift;
$getdoing['balance'] = $getuserinfo['money'];
$getdoing['closetime'] = time();
$getdoing['remarks'] = "自动结算";
Db::table('lc_yuebao_log')->insert($getdoing);
//更新用户余额
$newbalance = $getuserinfo['money'] + $nowprift;
Db::table('lc_user')->where('id=' . $getdoing['uid'])->update(['money' => $newbalance]);
}
//第二步,已到期待结算
if ($new_profit_time >= $getdoing['end_time']) {
//更新参保状态。
Db::table('lc_yuebao_lists')->where('id=' . $id)
->update(['status' => 2, 'end_time' => $nowtime]);
//获取用户余额;
addFinance($getdoing['uid'], $getdoing['money'], 1, "余额宝返还本金");
$getuserinfo = Db::table('lc_user')->where('id=' . $getdoing['uid'])->find();
//更新用户余额
$newbalance = $getuserinfo['money'] + $getdoing['money'];
Db::table('lc_user')->where('id=' . $getdoing['uid'])->update(['money' => $newbalance]);
$getuc = Db::table('lc_yuebao_uc')->where('uid=' . $getdoing['uid'])->find();
Db::table('lc_yuebao_uc')->where('uid=' . $getdoing['uid'])->update(['balance' => $getuc['balance'] - $getdoing['money']]);
$saveuclog = array(
'uid' => $getdoing['uid'],
'balance' => $getuc['balance'],
'money' => "-" . $getdoing['money'],
'addtime' => time(),
'remarks' => $getdoing['yebtitle'] . "到期结算"
);
Db::table('lc_yuebao_uclog')->insert($saveuclog);
$closenum = $closenum + 1;
}
}catch (\Exception $e){
$this->outputInfo->error("结算失败ID: " . $getdoing['id'] . " 错误信息: " . $e->getMessage());
}
}
$this->outputInfo->writeln('结算成功:' . $keepnum . '条,结算失败:' . $closenum . '条');
}
}