first commit
This commit is contained in:
147
app/common/command/InvestSettle.php
Normal file
147
app/common/command/InvestSettle.php
Normal 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user