|
|
|
<?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;
|
|
|
|
use think\console\Input;
|
|
|
|
use think\console\input\Argument;
|
|
|
|
use think\console\input\Option;
|
|
|
|
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;
|
|
|
|
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 brand
|
|
|
|
class brand extends Command
|
|
|
|
{
|
|
|
|
protected function configure()
|
|
|
|
{
|
|
|
|
// 指令配置
|
|
|
|
$this->setName('clearCache')
|
|
|
|
->addArgument('cacheType', Argument::OPTIONAL, 'php think menu [1] / [2]')
|
|
|
|
->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)
|
|
|
|
{
|
|
|
|
//获取所有用户
|
|
|
|
$userList = userModel::getDB()->where('status', 1)->select()->toArray();
|
|
|
|
|
|
|
|
$start = date('Y-m-d', strtotime("-1 day")).' 00:00:00';
|
|
|
|
$end = date('Y-m-d', strtotime("-1 day")).' 23:59:59';
|
|
|
|
|
|
|
|
//全网报单区流水昨日24小时的
|
|
|
|
$baodanall = StoreOrderContribute::getDB()
|
|
|
|
->where('bao_price','>',0)
|
|
|
|
->where('created_time', '>=',$start)
|
|
|
|
->where('created_time', '<=',$end)
|
|
|
|
->sum('baodan_liushui');
|
|
|
|
|
|
|
|
//全网品宣贡献值之和
|
|
|
|
$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;
|
|
|
|
//超级积分自动转换为增值积分 按照每天的比例 这个是重点
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$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();
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
echo $exception->getMessage();
|
|
|
|
Db::rollback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo date('Y-m-d H:i:s').'完成';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|