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/brand.php

132 lines
4.9 KiB

12 months ago
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
declare (strict_types=1);
namespace app\command;
use Swoole\Coroutine\MySQL\Exception;
use think\console\Command;
use app\common\model\store\order\StoreOrderContribute;
12 months ago
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
12 months ago
use app\common\model\user\User as userModel;
use app\common\model\user\ValueContributionLog;
use app\common\model\store\product\Spu;
use app\common\model\store\order\StoreOrder;
12 months ago
use think\console\Output;
use think\event\RouteLoaded;
12 months ago
use think\exception\ValidateException;
12 months ago
use think\facade\Cache;
12 months ago
use think\facade\Db;
12 months ago
use think\facade\Route;
use app\common\repositories\system\auth\MenuRepository;
// /www/server/php/74/bin/php /server/wwwroot/crmeb/think brand
class brand extends Command
{
protected function configure()
{
// 指令配置
$this->setName('clearCache')
12 months ago
->addArgument('cacheType', Argument::OPTIONAL, 'php think menu [1] / [2]')
12 months ago
->setDescription('各种积分转换');
}
/**
* TODO
* @param Input $input
* @param Output $output
* @return int|void|null
* @author Qinii
* @day 4/24/22
*/
protected function execute(Input $input, Output $output)
{
12 months ago
//获取所有用户
$userList = userModel::getDB()->where('status', 1)->select()->toArray();
12 months ago
$start = date('Y-m-d', strtotime("-1 day")).' 00:00:00';
$end = date('Y-m-d', strtotime("-1 day")).' 23:59:59';
12 months ago
//全网报单区流水昨日24小时的
$baodanall = StoreOrderContribute::getDB()
->where('bao_price','>',0)
->where('created_time', '>=',$start)
->where('created_time', '<=',$end)
->sum('baodan_liushui');
12 months ago
//全网品宣贡献值之和
$allBrandValue = userModel::getDB()->where('status', 1)->sum('brand_integral');
Db::startTrans();
foreach ($userList as $k => $v) {
try {
//用户的品宣贡献值=本人当前品宣积分÷全网品宣积分之和×全网报单流水×1%
$brandGongxian = round($v['brand_integral']/$allBrandValue*$baodanall/100,2);
//加到log日志
ValueContributionLog::getDB()->insert([
'type' => 7,
'types_of' => 1,
'num' => $brandGongxian,
'ctime' => date('Y-m-d H:i:s'),
'memo' => '品宣积分'.$v['brand_integral'].'自动转换为品宣贡献值'.$brandGongxian,
'user_id' => $v['uid'],
]);
//用户总贡献值 = 当前总贡献值+昨日的品宣贡献值
$all_value = $brandGongxian+$v['all_value'];
//贡献值自动转换为超级积分 暂定1:1
$superBrand = $all_value;
11 months ago
//超级积分自动转换为增值积分 按照每天的比例 这个是重点
$brandAdd = $superBrand;
$user = userModel::getDB()->where('uid', $v['uid'])->find();
//品宣积分清0
$user->brand_integral = 0;
//总贡献清0
$user->all_value = 0;
//超级积分清0
$user->super_brand = 0;
//更新增值积分
$user->brand_add += $brandAdd;
//天数+1
$user->super_days += 1;
$user->save();
12 months ago
Db::commit();
} catch (\Exception $exception) {
echo $exception->getMessage();
12 months ago
Db::rollback();
}
}
echo date('Y-m-d H:i:s').'完成';
12 months ago
}
}