|
|
|
@ -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,125 @@ 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); |
|
|
|
|
$yesterdayStart = '2023-12-18 00:00:00'; |
|
|
|
|
$yesterdayEnd = '2023-12-20 00:00:00'; |
|
|
|
|
$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()); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
public function getLastMonth() |
|
|
|
|