调整
This commit is contained in:
106
application/command/Yebeveryday.php
Normal file
106
application/command/Yebeveryday.php
Normal file
@ -0,0 +1,106 @@
|
|||||||
|
<?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 . '条');
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -27,5 +27,5 @@ return [
|
|||||||
'DEFAULT_TIMEZONE' => 'America/Sao_Paulo',
|
'DEFAULT_TIMEZONE' => 'America/Sao_Paulo',
|
||||||
'default_lang' => 'zh-cn', // 设置默认语言
|
'default_lang' => 'zh-cn', // 设置默认语言
|
||||||
'lang_switch_on' => true, // 开启多语言切换
|
'lang_switch_on' => true, // 开启多语言切换
|
||||||
'deny_module_list' => ['akszadmin']
|
'deny_module_list' => ['akszadmin','command','lang']
|
||||||
];
|
];
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user