wangmingchuan321@qq.com 11 months ago
commit 2cfe01b70d
  1. 53
      app/command/dayUserGrowth.php
  2. 7
      app/command/dayUserValue.php
  3. 131
      app/command/dayValue.php
  4. 43
      app/common/model/user/CommunityAccrue.php
  5. 2
      app/common/repositories/system/admin/PartnerRepository.php
  6. 9
      app/common/repositories/user/UserPartnerRepository.php
  7. 2
      app/controller/admin/user/User.php
  8. 2
      config/console.php
  9. 7
      config/partner.php
  10. 1
      crmeb/jobs/OrderPartnerJob.php

@ -0,0 +1,53 @@
<?php
declare (strict_types=1);
namespace app\command;
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 dayUserGrowth
class dayUserGrowth 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)
{
try {
$user = userModel::getDB()->where('status', 1)->select()->toArray();
foreach ($user as $k => $v) {
if ($v['all_value'] > 0) {
$growth_num = bcdiv($v['all_value'], $v['growth_rate'], 2);
userModel::getDB()
->where('uid', $v['uid'])
->update(['all_value' => 0, 'brokerage_price' => $growth_num]);
}
}
} catch (\Exception $e) {
print_r($e->getMessage());
}
echo 'ok';
}
}

@ -47,13 +47,18 @@ class dayUserValue extends Command
$days = $v['super_days'] + 1;
foreach ($resConfig as $rk => $rv) {
if ($days >= $rv['start'] && $rv['bili'] > 0) {
if (empty($v['growth_rate'])) {
$growth_rate = $rv['bili'];
} else {
$growth_rate = bcadd($v['growth_rate'], $rv['bili'], 2);
}
}
}
userModel::getDB()->where('uid', $v['uid'])->update(['super_days' => $days, 'growth_rate' => $growth_rate]);
}
} catch (\Exception $e) {
print_r($e->getMessage());
}
echo 'ok';

@ -4,16 +4,17 @@ declare (strict_types=1);
namespace app\command;
use app\common\model\community\Community;
use app\common\model\user\User;
use app\common\model\user\ValueContributionLog;
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 app\common\model\user\CommunityAccrue;
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;
@ -35,14 +36,124 @@ class dayValue extends Command
protected function execute(Input $input, Output $output)
{
$currentDate = date('Y-m-01'); // 获取当前月的第一天
//判断当月第一天
if (date('Y-m-d') === $currentDate) {
//获取上个月时间
list($start, $end) = $this->getLastMonth();
//根据社区等级分配贡献值
//重置社区等级
$yesterdayStart = date('Y-m-d H:i:s', strtotime('yesterday'));
$yesterdayEnd = date('Y-m-d H:i:s', strtotime('tomorrow') - 1);
$level = config('partner.community_level') ?? [];
$back_level = User::getDB()->where('community_level', '>', '0')->column('uid');
$userOrder = StoreOrderContribute::getDB()->field('uid,sum(order_profit) as user_profit')
->where('created_time', '>', $yesterdayStart)
->where('created_time', '<', $yesterdayEnd)
->whereNotIn('uid', $back_level)
->group('uid')->select()->toArray();
$newOrder = array_column($userOrder, null, 'uid');
$day_total = 0;
//查询社区分组,最高三级
foreach ($userOrder as $k => $v) {
$newOrder[$v['uid']]['child_user_profit'] = 0;
$day_total += $v['user_profit'];
//查询用户
$user = User::getDB()->where('uid', $v['uid'])->find();
if (!empty($user->spread_uid)) {
//查询二级
$f_user = User::getDB()->where('uid', $user->spread_uid)->find();
if (isset($newOrder[$user->spread_uid])) {
if (isset($newOrder[$user->spread_uid]['child_user_profit'])) {
$newOrder[$user->spread_uid]['child_user_profit'] += $v['user_profit'];
} else {
$newOrder[$user->spread_uid]['child_user_profit'] = $v['user_profit'];
}
} else {
$newOrder[$user->spread_uid] = [
'uid' => $user->spread_uid,
'user_profit' => 0,
'child_user_profit' => $v['user_profit']
];
}
if (!empty($f_user->spread_uid)) {
if (isset($newOrder[$f_user->spread_uid])) {
if (isset($newOrder[$f_user->spread_uid]['child_user_profit'])) {
$newOrder[$f_user->spread_uid]['child_user_profit'] += $v['user_profit'];
} else {
$newOrder[$f_user->spread_uid]['child_user_profit'] = $v['user_profit'];
}
} else {
$newOrder[$f_user->spread_uid] = [
'uid' => $f_user->spread_uid,
'user_profit' => 0,
'child_user_profit' => $v['user_profit']
];
}
}
}
}
try {
if (!empty($newOrder)) {
$user_log_data = [];
foreach ($newOrder as $ok => $ov) {
if ($ov['user_profit'] >= $ov['child_user_profit']) {
$use_value = $ov['user_profit'];
} else {
$use_value = $ov['child_user_profit'];
}
foreach ($level as $lk => $lv) {
if ($use_value >= $lv['min_price']) {
$level[$lk]['uid'][] = $ov['uid'];
continue 1;
}
}
}
foreach ($level as $nlk => $nlv) {
$temp_value = $order_value = bcmul((string)$day_total, $nlv['pay_community'], 2);
$old_value = Community::getDB()->where('community_id', $nlv['id'])->find();
if ($old_value && $old_value->value > 0) {
$temp_value = $temp_value + $old_value->value;
}
$back_uids = User::getDB()->where('community_level', $nlv['id'])->column('uid');
if (!empty($nlv['uid'])) {
$nlv['uid'] = array_merge($nlv['uid'], $back_uids);
} else {
$nlv['uid'] = $back_uids;
}
if (!empty($nlv['uid'])) {
$num = count($nlv['uid']);
$user_temp = bcdiv($temp_value, (string)$num, 2);
foreach ($nlv['uid'] as $uk => $uv) {
$user = User::getDB()->where('uid', $uv)->find();
$user->all_value = bcadd($user->all_value, $user_temp, 2);
$user->save();
$user_log_data[] = [
'type' => 8,
'types_of' => 1,
'num' => $user_temp,
'ctime' => date('Y-m-d H:i:s'),
'memo' => $nlv['alias'] . '贡献值',
'user_id' => $uv,
];
}
} else {
$has = Community::getDB()->where('community_id', $nlv['id'])->find();
if (!$has) {
$has = new Community();
$has->community_id = $nlv['id'];
$has->value = $order_value;
} else {
$has->value = $has->value + $order_value;
}
$has->save();
}
}
//批量增加用户贡献值日志
ValueContributionLog::getDB()->insertAll($user_log_data);
}
} catch (\Exception $e) {
print_r($e->getLine() . "-" . $e->getMessage());
}
echo '执行结束';
}
public function getLastMonth()

@ -0,0 +1,43 @@
<?php
// +----------------------------------------------------------------------
// | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016~2022 https://www.crmeb.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
// +----------------------------------------------------------------------
// | Author: CRMEB Team <admin@crmeb.com>
// +----------------------------------------------------------------------
namespace app\common\model\user;
use app\common\model\BaseModel;
class CommunityAccrue extends BaseModel
{
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tablePk(): string
{
return 'id';
}
/**
* @return string
* @author xaboy
* @day 2020-03-30
*/
public static function tableName(): string
{
return 'community_accrue';
}
}

@ -184,7 +184,7 @@ class PartnerRepository extends BaseRepository
public function roleExists(int $id)
{
return UserPartner::getDB()->where('id', '=', $id)->where('uid', '=', '')->find();
return UserPartner::getDB()->where('id', '=', $id)->where('uid', '>', 0)->find();
}

@ -73,14 +73,15 @@ class UserPartnerRepository extends BaseRepository
public function changePartnerForm($uid)
{
/** @var UserLabelRepository $make */
$list = UserPartner::getDB()->where('uid', $uid)->column('id') ?? [];
$ids_list = UserPartner::getDB()->where('uid', $uid)->column('id') ?? [];
$data = UserPartner::getDB()->select()->toArray();
$list = [];
foreach ($data as $value => $label) {
$name = (string)$label['id'];
$value = $label['partner_name'];
$name = $label['partner_name'];
$value = (int)$label['id'];
$options[] = compact('value', 'name');
}
$data = ['partner_id' => $list, 'uid' => $uid, 'option' => $options];
$data = ['partner_id' => $ids_list, 'uid' => $uid, 'option' => $options];
return $data;
}

@ -618,7 +618,7 @@ class User extends BaseController
return app('json')->fail('数据不存在');
foreach ($user_role_id as $k => $value) {
$user_role_ids[$k] = (int)$value;
if (!$partnerRepository->roleExists((int)$value))
if ($partnerRepository->roleExists((int)$value))
return app('json')->fail('该角色已分配,请重新选择');
}
$userPartnerRepository->editPartner($id, $user_role_id);

@ -43,5 +43,7 @@ return [
'dayValue' => 'app\command\dayValue',
//每日兑换率生成
'dayUserValue' => 'app\command\dayUserValue',
//每日贡献值转增值积分
'dayUserGrowth' => 'app\command\dayUserGrowth',
],
];

@ -18,40 +18,47 @@ return [
// 社区等级配置
'community_level' => [
[
'id' => 1,
'alias' => '七星社区服务商 ',
'level_name' => 'S7',
'min_price' => '100000000',
'pay_community' => '0.03',
], [
'id' => 2,
'alias' => '六星社区服务商 ',
'level_name' => 'S6',
'min_price' => '10000000',
'pay_community' => '0.03',
],
[
'id' => 3,
'alias' => '五星社区服务商 ',
'level_name' => 'S5',
'min_price' => '10000000',
'pay_community' => '0.03',
],
[
'id' => 4,
'alias' => '四星社区服务商 ',
'level_name' => 'S4',
'min_price' => '3000000',
'pay_community' => '0.03',
], [
'id' => 5,
'alias' => '三星社区服务商 ',
'level_name' => 'S3',
'min_price' => '100000',
'pay_community' => '0.03',
],
[
'id' => 6,
'alias' => '二星社区服务商 ',
'level_name' => 'S2',
'min_price' => '300000',
'pay_community' => '0.03',
],
[
'id' => 7,
'alias' => '一星社区服务商 ',
'level_name' => 'S1',
'min_price' => '30000',

@ -380,7 +380,6 @@ class OrderPartnerJob implements JobInterface
//批量增加用户贡献值日志
ValueContributionLog::getDB()->insertAll($user_log_data);
//社区等级判断
echo 'ok';
} catch (\Exception $e) {
Log::info('订单角色贡献值处理失败; error : ' . $e->getMessage());

Loading…
Cancel
Save