You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
crmeb_php/app/command/dayUserValue.php

84 lines
2.7 KiB

11 months ago
<?php
declare (strict_types=1);
namespace app\command;
use app\common\model\system\config\SystemConfig;
use app\common\model\system\config\SystemConfigValue;
11 months ago
use Swoole\Coroutine\MySQL\Exception;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
use app\common\model\user\User as userModel;
use think\console\Output;
use think\event\RouteLoaded;
use think\exception\ValidateException;
use think\facade\Cache;
use think\facade\Db;
use think\facade\Route;
use app\common\repositories\system\auth\MenuRepository;
// /www/server/php/74/bin/php /server/wwwroot/crmeb/think dayValue
class dayUserValue extends Command
{
protected function configure()
{
// 指令配置
$this->setName('dayUserValue')
->addArgument('dayValue', Argument::OPTIONAL, 'php think menu [1] / [2]')
->setDescription('用户每日兑换率生成');
}
protected function execute(Input $input, Output $output)
{
$config = systemConfig('brand_config');
11 months ago
$config_start = (int)systemConfig('brand_config') ?? 1;
$config_growth = systemConfig('brand_growth');
if (empty($config)) {
echo '无配置';
exit;
}
11 months ago
$resConfig = [];
foreach (explode('/', $config) as $k => $v) {
$newConfig = explode(',', $v);
$resConfig[$k]['start'] = $newConfig[0];
$resConfig[$k]['end'] = $newConfig[1];
$resConfig[$k]['bili'] = $newConfig[2];
}
try {
$growth_rate = 0;
$days = $config_start + 1;
foreach ($resConfig as $rk => $rv) {
if ($days >= $rv['start'] && $rv['bili'] > 0) {
11 months ago
if (empty($config_growth)) {
$growth_rate = $rv['bili'];
} else {
11 months ago
$growth_rate = bcadd($config_growth, $rv['bili'], 2);
11 months ago
}
11 months ago
}
}
$user = userModel::getDB()->where('status', 1)->select()->toArray();
foreach ($user as $k => $v) {
11 months ago
userModel::getDB()->where('uid', $v['uid'])->update(['super_days' => $days, 'growth_rate' => $growth_rate]);
}
$system_1 = SystemConfigValue::getDB()->where('config_key', 'brand_start')->find();
$system_1->value = $system_1->value + 1;
$system_1->save();
$system_2 = SystemConfigValue::getDB()->where('config_key', 'brand_growth')->find();
$system_2->value = $growth_rate;
$system_2->save();
11 months ago
} catch (\Exception $e) {
11 months ago
print_r($e->getMessage());
11 months ago
}
echo 'ok';
}
}