init: 从宝塔同步到 Gitea
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class SettleCs extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('SettleCs')->setDescription('结算占股');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->settleCs($input, $output);
|
||||
}
|
||||
|
||||
// 结算占股
|
||||
private function settleCs($input, $output)
|
||||
{
|
||||
$settleTime = time() - 86400;
|
||||
$where = [];
|
||||
$where['c.is_checkout'] = 0;
|
||||
$where['c.create_time'] = array('<=',$settleTime);
|
||||
$where['u.agent_parent_id'] = array('>',0);
|
||||
$where['u.agent'] = 1;
|
||||
|
||||
$list = Db::name('cs')->alias('c')
|
||||
->join('cg_user u','u.id=c.user_id')
|
||||
->field('c.user_id,sum(c.share_amount) as share_amount, sum(c.share_maliang) as share_maliang')
|
||||
->where($where)
|
||||
->group('c.user_id')
|
||||
->select();
|
||||
foreach($list as $v){
|
||||
$userId = $v['user_id'];
|
||||
$shareAmount = $v['share_amount'];
|
||||
$shareMaliang = $v['share_maliang'];
|
||||
$amount = $shareAmount - $shareMaliang;
|
||||
|
||||
try{
|
||||
Db::startTrans();
|
||||
|
||||
// 用户信息 总代不结算
|
||||
$userInfo = Db::name('user')->where('id',$userId)->find();
|
||||
if($userInfo['agent_parent_id'] == 0){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 为总代");
|
||||
}
|
||||
if($userInfo['agent'] == 0){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 为会员");
|
||||
}
|
||||
// 上级信息
|
||||
$parentId = $userInfo['agent_parent_id'];
|
||||
$parent = Db::name('user')->where('id',$parentId)->lock(true)->find();
|
||||
if(empty($parent)){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 上级不存在");
|
||||
}
|
||||
// 下级余额判断
|
||||
$userMoney = $userInfo['money'] + $shareAmount - $shareMaliang;
|
||||
if(SETTLE_MONEY_EXCEED_PARENT_MONTY != 1 && $userMoney < 0){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 余额不足");
|
||||
}
|
||||
// 上级余额判断
|
||||
$parentMoney = $parent['money'] - $shareAmount + $shareMaliang;
|
||||
if(SETTLE_MONEY_EXCEED_PARENT_MONTY != 1 && $parentMoney < 0){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 上级余额不足");
|
||||
}
|
||||
|
||||
// 扣除上级余额
|
||||
$result = Db::name('user')->where(['id'=>$parent['id']])->update(['money'=>$parentMoney]);
|
||||
if(!$result){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 增加下级余额
|
||||
$result = Db::name('user')->where(['id'=>$userInfo['id']])->update(['money'=>$userMoney,'last_cs_time'=>time()]);
|
||||
if(!$result){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 更新洗码表状态
|
||||
$csWhere = [];
|
||||
$csWhere['is_checkout'] = 0;
|
||||
$csWhere['user_id'] = $userId;
|
||||
$csWhere['create_time'] = array('<=',$settleTime);
|
||||
$result = Db::name('cs')->where($csWhere)->update(['is_checkout'=>1,'checkout_time'=>time()]);
|
||||
if(!$result){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 结算占股记录
|
||||
$dataCs = array();
|
||||
$dataCs['user_id'] = $userInfo['id'];
|
||||
$dataCs['username'] = $userInfo['username'];
|
||||
$dataCs['admin_or_agent'] = 5;
|
||||
$dataCs['share_amount'] = $shareAmount;
|
||||
$dataCs['share_maliang'] = $shareMaliang;
|
||||
$dataCs['agent_cs'] = $userInfo['agent_cs'];
|
||||
$dataCs['create_time'] = time();
|
||||
$dataCs['old_money'] = $userInfo['money'];
|
||||
$dataCs['new_money'] = $userMoney;
|
||||
$dataCs['connection_old_money'] = $parent['money'];
|
||||
$dataCs['connection_new_money'] = $parentMoney;
|
||||
$dataCs['type'] = 1;
|
||||
$result = Db::name('cs_log')->insert($dataCs);
|
||||
if(!$result){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 上下分金额
|
||||
$scoreAmount = 0;
|
||||
if($shareAmount > 0){
|
||||
$mode = 1;
|
||||
$scoreAmount = $shareAmount - $shareMaliang;
|
||||
}elseif($shareAmount < 0){
|
||||
$mode = 2;
|
||||
$scoreAmount = to_number($shareAmount - $shareMaliang);
|
||||
}
|
||||
// 处理上分(下级)
|
||||
$dataRecharge = array();
|
||||
$dataRecharge['type'] = 3;
|
||||
$dataRecharge['amount'] = $scoreAmount;
|
||||
$dataRecharge['mode'] = $mode;
|
||||
$dataRecharge['agent_or_admin'] = 5;
|
||||
$dataRecharge['controller_type'] = '定时结算系统操作';
|
||||
$dataRecharge['user_id'] = $userInfo['id'];
|
||||
$dataRecharge['user_type'] = $userInfo['agent'];
|
||||
$dataRecharge['user_agent_level'] = $userInfo['agent_level'];
|
||||
$dataRecharge['username_for'] = $userInfo['username'];
|
||||
$dataRecharge['nickname_for'] = $userInfo['nickname'];
|
||||
$dataRecharge['user_parent_id'] = $userInfo['agent_parent_id'];
|
||||
$dataRecharge['create_time'] = time();
|
||||
$dataRecharge['old_money'] = $userInfo['money'];
|
||||
$dataRecharge['new_money'] = $userMoney;
|
||||
$dataRecharge['controller_old_money'] = $parent['money'];
|
||||
$dataRecharge['controller_new_money'] = $parentMoney;
|
||||
$dataRecharge['controller_system'] = 1;
|
||||
$dataRecharge['remake'] = '结算占股,超过24小时未结占股自动结算';
|
||||
$result = Db::name('recharge')->insert($dataRecharge);
|
||||
if(!$result){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 处理上分(上级)
|
||||
$dataRecharge = array();
|
||||
$dataRecharge['type'] = 3;
|
||||
$dataRecharge['amount'] = $scoreAmount;
|
||||
$dataRecharge['mode'] = $mode == 1 ? 2 : 1;
|
||||
$dataRecharge['agent_or_admin'] = 5;
|
||||
$dataRecharge['controller_type'] = '定时结算系统操作';
|
||||
$dataRecharge['user_id'] = $parent['id'];
|
||||
$dataRecharge['user_type'] = $parent['agent'];
|
||||
$dataRecharge['user_agent_level'] = $parent['agent_level'];
|
||||
$dataRecharge['username_for'] = $parent['username'];
|
||||
$dataRecharge['nickname_for'] = $parent['nickname'];
|
||||
$dataRecharge['user_parent_id'] = $parent['agent_parent_id'];
|
||||
$dataRecharge['create_time'] = time();
|
||||
$dataRecharge['old_money'] = $parent['money'];
|
||||
$dataRecharge['new_money'] = $parentMoney;
|
||||
$dataRecharge['controller_old_money'] = $parent['money'];
|
||||
$dataRecharge['controller_new_money'] = $parentMoney;
|
||||
$dataRecharge['controller_system'] = 1;
|
||||
$dataRecharge['remake'] = '下级结算占股,超过24小时未结占股自动结算';
|
||||
$result = Db::name('recharge')->insert($dataRecharge);
|
||||
if(!$result){
|
||||
throw new Exception("结算占股:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
$output->writeln("{$userInfo['username']} 成功结算占股:{$amount}元");
|
||||
}catch (Exception $e){
|
||||
$output->writeln($e->getMessage().',不参与自动结算');
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class SettleRebate extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('SettleRebate')->setDescription('结算返水');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->SettleRebate($input, $output);
|
||||
}
|
||||
|
||||
// 结算洗码
|
||||
private function settleRebate($input, $output)
|
||||
{
|
||||
$settleTime = time() - 86400;
|
||||
$where = [];
|
||||
$where['r.is_checkout'] = 0;
|
||||
$where['r.create_time'] = array('<=',$settleTime);
|
||||
$where['u.agent_parent_id'] = array('>',0);
|
||||
|
||||
$list = Db::name('rebate')->alias('r')
|
||||
->join('cg_user u','u.id=r.user_id')
|
||||
->field('r.user_id,sum(r.rebate_amount_actual) as rebate_amount, sum(r.amount) as amount')
|
||||
->where($where)
|
||||
->group('r.user_id')
|
||||
->select();
|
||||
foreach($list as $v){
|
||||
$userId = $v['user_id'];
|
||||
$amount = $v['amount'];
|
||||
$rebateAmount = $v['rebate_amount'];
|
||||
|
||||
try{
|
||||
Db::startTrans();
|
||||
|
||||
// 用户信息 总代不结算
|
||||
$userInfo = Db::name('user')->where('id',$userId)->find();
|
||||
if($userInfo['agent_parent_id'] == 0){
|
||||
throw new Exception("结算返水:{$userInfo['username']} 为总代");
|
||||
}
|
||||
|
||||
// 更新返水表状态
|
||||
$rebateWhere = [];
|
||||
$rebateWhere['is_checkout'] = 0;
|
||||
$rebateWhere['user_id'] = $userId;
|
||||
$rebateWhere['create_time'] = array('<=',$settleTime);
|
||||
$result = Db::name('rebate')->where($rebateWhere)->update(['is_checkout'=>1,'checkout_time'=>time()]);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 增加下级余额
|
||||
$userMoney = $userInfo['money'] + $amount;
|
||||
$result = Db::name('user')->where(['id'=>$userInfo['id']])->update(['money'=>$userMoney,'last_xima_time'=>time()]);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 返水记录
|
||||
$dataXima = array();
|
||||
$dataXima['user_id'] = $userInfo['id'];
|
||||
$dataXima['username'] = $userInfo['username'];
|
||||
$dataXima['admin_or_agent'] = 5;
|
||||
$dataXima['amount'] = $amount;
|
||||
$dataXima['rebate_amount'] = $rebateAmount;
|
||||
$dataXima['rebate_rate'] = $userInfo['rebate_rate'];
|
||||
$dataXima['create_time'] = time();
|
||||
$dataXima['old_money'] = $userInfo['money'];
|
||||
$dataXima['new_money'] = $userMoney;
|
||||
$dataXima['type'] = 1;
|
||||
$result = Db::name('rebate_log')->insert($dataXima);
|
||||
if(!$result){
|
||||
throw new Exception("结算返水:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 处理上分
|
||||
$dataRecharge = array();
|
||||
$dataRecharge['type'] = 2;
|
||||
$dataRecharge['money'] = $rebateAmount;
|
||||
$dataRecharge['user_id'] = $userInfo['id'];
|
||||
$dataRecharge['create_time'] = time();
|
||||
$dataRecharge['old_money'] = $userInfo['money'];
|
||||
$dataRecharge['new_money'] = $userMoney;
|
||||
$result = Db::name('user_recharge')->insert($dataRecharge);
|
||||
if(!$result){
|
||||
throw new Exception("结算返水:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
$output->writeln("{$userInfo['username']} 成功结算返水:{$amount}元",1);
|
||||
}catch (Exception $e){
|
||||
$output->writeln($e->getMessage().',行:'.$e->getLine(),1);
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,168 @@
|
||||
<?php
|
||||
|
||||
namespace app\command;
|
||||
|
||||
use think\console\Command;
|
||||
use think\console\Input;
|
||||
use think\console\Output;
|
||||
use think\Db;
|
||||
use think\Exception;
|
||||
|
||||
class SettleXima extends Command
|
||||
{
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('SettleXima')->setDescription('结算洗码');
|
||||
}
|
||||
|
||||
protected function execute(Input $input, Output $output)
|
||||
{
|
||||
$this->settleXima($input, $output);
|
||||
}
|
||||
|
||||
// 结算洗码
|
||||
private function settleXima($input, $output)
|
||||
{
|
||||
$settleTime = time() - 86400;
|
||||
$where = [];
|
||||
$where['x.is_checkout'] = 0;
|
||||
$where['x.create_time'] = array('<=',$settleTime);
|
||||
$where['u.agent_parent_id'] = array('>',0);
|
||||
|
||||
$list = Db::name('xima')->alias('x')
|
||||
->join('cg_user u','u.id=x.user_id')
|
||||
->field('x.user_id,sum(x.maliang) as amount, sum(x.ximaliang) as ximaliang')
|
||||
->where($where)
|
||||
->group('x.user_id')
|
||||
->select();
|
||||
foreach($list as $v){
|
||||
$userId = $v['user_id'];
|
||||
$amount = $v['amount'];
|
||||
$ximaliang = $v['ximaliang'];
|
||||
|
||||
try{
|
||||
Db::startTrans();
|
||||
|
||||
// 用户信息 总代不结算
|
||||
$userInfo = Db::name('user')->where('id',$userId)->find();
|
||||
if($userInfo['agent_parent_id'] == 0){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 为总代");
|
||||
}
|
||||
// 上级信息
|
||||
$parentId = $userInfo['agent_parent_id'];
|
||||
$parent = Db::name('user')->where('id',$parentId)->lock(true)->find();
|
||||
if(empty($parent)){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 上级不存在");
|
||||
}
|
||||
// 上级余额判断
|
||||
if(SETTLE_MONEY_EXCEED_PARENT_MONTY != 1 && $amount > $parent['money']){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 上级余额不足");
|
||||
}
|
||||
|
||||
// 更新洗码表状态
|
||||
$ximaWhere = [];
|
||||
$ximaWhere['is_checkout'] = 0;
|
||||
$ximaWhere['user_id'] = $userId;
|
||||
$ximaWhere['create_time'] = array('<=',$settleTime);
|
||||
$result = Db::name('xima')->where($ximaWhere)->update(['is_checkout'=>1,'checkout_time'=>time()]);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 扣除上级余额
|
||||
$parentMoney = $parent['money'] - $amount;
|
||||
$result = Db::name('user')->where(['id'=>$parent['id']])->update(['money'=>$parentMoney]);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 增加下级余额
|
||||
$userMoney = $userInfo['money'] + $amount;
|
||||
$result = Db::name('user')->where(['id'=>$userInfo['id']])->update(['money'=>$userMoney,'last_xima_time'=>time()]);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 洗码记录
|
||||
$dataXima = array();
|
||||
$dataXima['user_id'] = $userInfo['id'];
|
||||
$dataXima['username'] = $userInfo['username'];
|
||||
$dataXima['admin_or_agent'] = 5;
|
||||
$dataXima['ximaliang'] = $ximaliang;
|
||||
$dataXima['maliang'] = $amount;
|
||||
if($userInfo['type_xima'] == 1){
|
||||
$dataXima['agent_ximalv'] = $userInfo['agent_ximalv'].'/'.$userInfo['agent_ximalv_dt'].'/'.$userInfo['agent_ximalv_nn'];
|
||||
}else{
|
||||
$dataXima['agent_ximalv'] = '0/0/0';
|
||||
}
|
||||
$dataXima['create_time'] = time();
|
||||
$dataXima['old_money'] = $userInfo['money'];
|
||||
$dataXima['new_money'] = $userMoney;
|
||||
$dataXima['connection_old_money'] = $userInfo['money'];
|
||||
$dataXima['connection_new_money'] = $parentMoney;
|
||||
$dataXima['type'] = 1;
|
||||
$result = Db::name('xima_log')->insert($dataXima);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
|
||||
// 处理上分(下级)
|
||||
$dataRecharge = array();
|
||||
$dataRecharge['type'] = 2;
|
||||
$dataRecharge['amount'] = $amount;
|
||||
$dataRecharge['mode'] = 1;
|
||||
$dataRecharge['agent_or_admin'] = 5;
|
||||
$dataRecharge['controller_type'] = '定时结算系统操作';
|
||||
$dataRecharge['user_id'] = $userInfo['id'];
|
||||
$dataRecharge['user_type'] = $userInfo['agent'];
|
||||
$dataRecharge['user_agent_level'] = $userInfo['agent_level'];
|
||||
$dataRecharge['username_for'] = $userInfo['username'];
|
||||
$dataRecharge['nickname_for'] = $userInfo['nickname'];
|
||||
$dataRecharge['user_parent_id'] = $userInfo['agent_parent_id'];
|
||||
$dataRecharge['create_time'] = time();
|
||||
$dataRecharge['old_money'] = $userInfo['money'];
|
||||
$dataRecharge['new_money'] = $userMoney;
|
||||
$dataRecharge['controller_old_money'] = $parent['money'];
|
||||
$dataRecharge['controller_new_money'] = $parentMoney;
|
||||
$dataRecharge['controller_system'] = 1;
|
||||
$dataRecharge['remake'] = '洗码上分,超过24小时未接码费自动结算';
|
||||
$result = Db::name('recharge')->insert($dataRecharge);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
// 处理上分(上级)
|
||||
$dataRecharge = array();
|
||||
$dataRecharge['type'] = 2;
|
||||
$dataRecharge['amount'] = $amount;
|
||||
$dataRecharge['mode'] = 2;
|
||||
$dataRecharge['agent_or_admin'] = 5;
|
||||
$dataRecharge['controller_type'] = '定时结算系统操作';
|
||||
$dataRecharge['user_id'] = $parent['id'];
|
||||
$dataRecharge['user_type'] = $parent['agent'];
|
||||
$dataRecharge['user_agent_level'] = $parent['agent_level'];
|
||||
$dataRecharge['username_for'] = $parent['username'];
|
||||
$dataRecharge['nickname_for'] = $parent['nickname'];
|
||||
$dataRecharge['user_parent_id'] = $parent['agent_parent_id'];
|
||||
$dataRecharge['create_time'] = time();
|
||||
$dataRecharge['old_money'] = $parent['money'];
|
||||
$dataRecharge['new_money'] = $parentMoney;
|
||||
$dataRecharge['controller_old_money'] = $parent['money'];
|
||||
$dataRecharge['controller_new_money'] = $parentMoney;
|
||||
$dataRecharge['controller_system'] = 1;
|
||||
$dataRecharge['remake'] = '下级洗码上分,超过24小时未接码费自动结算';
|
||||
$result = Db::name('recharge')->insert($dataRecharge);
|
||||
if(!$result){
|
||||
throw new Exception("结算洗码:{$userInfo['username']} 操作失败");
|
||||
}
|
||||
|
||||
Db::commit();
|
||||
$output->writeln("{$userInfo['username']} 成功结算码费:{$amount}元",1);
|
||||
}catch (Exception $e){
|
||||
$output->writeln($e->getMessage().',行:'.$e->getLine(),1);
|
||||
Db::rollback();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user