|
|
|
<?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');
|
|
|
|
if ($allBrandValue <= 0) {
|
|
|
|
die;
|
|
|
|
}
|
|
|
|
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'];
|
|
|
|
|
|
|
|
$growth_num = bcdiv($all_value, $v['growth_rate'], 2);
|
|
|
|
userModel::getDB()
|
|
|
|
->where('uid', $v['uid'])
|
|
|
|
->update([
|
|
|
|
'brand_integral' => 0,
|
|
|
|
'all_value' => 0,
|
|
|
|
'brokerage_price' => $growth_num
|
|
|
|
]);
|
|
|
|
|
|
|
|
Db::commit();
|
|
|
|
} catch (\Exception $exception) {
|
|
|
|
echo $exception->getMessage();
|
|
|
|
Db::rollback();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
echo date('Y-m-d H:i:s') . '完成';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|