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

121 lines
4.6 KiB

1 year 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;
1 year ago
use think\console\Input;
use think\console\input\Argument;
use think\console\input\Option;
1 year 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;
1 year ago
use think\console\Output;
use think\event\RouteLoaded;
1 year ago
use think\exception\ValidateException;
1 year ago
use think\facade\Cache;
1 year ago
use think\facade\Db;
1 year 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')
1 year ago
->addArgument('cacheType', Argument::OPTIONAL, 'php think menu [1] / [2]')
12 months ago
->setDescription('增值积分自动转增值贡献值');
1 year ago
}
/**
* TODO
* @param Input $input
* @param Output $output
* @return int|void|null
* @author Qinii
* @day 4/24/22
*/
protected function execute(Input $input, Output $output)
{
1 year ago
//获取所有用户
$userList = userModel::getDB()->where('status', 1)->select()->toArray();
1 year ago
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';
1 year ago
//全网报单区流水昨日24小时的
$baodanall = StoreOrderContribute::getDB()
12 months ago
->where('bao_price', '>', 0)
->where('created_time', '>=', $start)
->where('created_time', '<=', $end)
->sum('baodan_liushui');
1 year ago
//全网品宣贡献值之和
$allBrandValue = userModel::getDB()->where('status', 1)->sum('brand_integral');
12 months ago
if ($allBrandValue <= 0) {
die;
}
1 year ago
Db::startTrans();
foreach ($userList as $k => $v) {
try {
//用户的品宣贡献值=本人当前品宣积分÷全网品宣积分之和×全网报单流水×1%
12 months ago
$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'),
12 months ago
'memo' => '品宣积分' . $v['brand_integral'] . '自动转换为品宣贡献值' . $brandGongxian,
'user_id' => $v['uid'],
]);
//用户总贡献值 = 当前总贡献值+昨日的品宣贡献值
12 months ago
$all_value = $brandGongxian + $v['all_value'];
12 months ago
$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
]);
1 year ago
Db::commit();
} catch (\Exception $exception) {
echo $exception->getMessage();
1 year ago
Db::rollback();
}
}
12 months ago
echo date('Y-m-d H:i:s') . '完成';
1 year ago
}
}