From e9f3486ab1bcd50af6377750938acc8e8c4406e3 Mon Sep 17 00:00:00 2001 From: limu Date: Tue, 26 Dec 2023 17:00:53 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E7=A4=BE=E5=8C=BA=E8=B4=A1=E7=8C=AE?= =?UTF-8?q?=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/dayUserValue.php | 9 +- app/command/dayValue.php | 132 ++++++++++++++++-- app/common/model/user/CommunityAccrue.php | 43 ++++++ .../system/admin/PartnerRepository.php | 2 +- .../user/UserPartnerRepository.php | 9 +- app/controller/admin/user/User.php | 2 +- config/partner.php | 7 + crmeb/jobs/OrderPartnerJob.php | 1 - 8 files changed, 186 insertions(+), 19 deletions(-) create mode 100644 app/common/model/user/CommunityAccrue.php diff --git a/app/command/dayUserValue.php b/app/command/dayUserValue.php index 034f9e6..9e450e1 100644 --- a/app/command/dayUserValue.php +++ b/app/command/dayUserValue.php @@ -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) { - $growth_rate = bcadd($v['growth_rate'], $rv['bili'], 2); + 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'; diff --git a/app/command/dayValue.php b/app/command/dayValue.php index eb55c62..7659f0d 100644 --- a/app/command/dayValue.php +++ b/app/command/dayValue.php @@ -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() diff --git a/app/common/model/user/CommunityAccrue.php b/app/common/model/user/CommunityAccrue.php new file mode 100644 index 0000000..9081eca --- /dev/null +++ b/app/common/model/user/CommunityAccrue.php @@ -0,0 +1,43 @@ + +// +---------------------------------------------------------------------- + + +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'; + } + + +} diff --git a/app/common/repositories/system/admin/PartnerRepository.php b/app/common/repositories/system/admin/PartnerRepository.php index df34796..1ffbabd 100644 --- a/app/common/repositories/system/admin/PartnerRepository.php +++ b/app/common/repositories/system/admin/PartnerRepository.php @@ -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(); } diff --git a/app/common/repositories/user/UserPartnerRepository.php b/app/common/repositories/user/UserPartnerRepository.php index de4e4b1..f757ca1 100644 --- a/app/common/repositories/user/UserPartnerRepository.php +++ b/app/common/repositories/user/UserPartnerRepository.php @@ -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; } diff --git a/app/controller/admin/user/User.php b/app/controller/admin/user/User.php index 255cef8..da9d8ca 100644 --- a/app/controller/admin/user/User.php +++ b/app/controller/admin/user/User.php @@ -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); diff --git a/config/partner.php b/config/partner.php index 2db7a0c..942072c 100644 --- a/config/partner.php +++ b/config/partner.php @@ -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', diff --git a/crmeb/jobs/OrderPartnerJob.php b/crmeb/jobs/OrderPartnerJob.php index 6704fa0..d2a709b 100644 --- a/crmeb/jobs/OrderPartnerJob.php +++ b/crmeb/jobs/OrderPartnerJob.php @@ -380,7 +380,6 @@ class OrderPartnerJob implements JobInterface //批量增加用户贡献值日志 ValueContributionLog::getDB()->insertAll($user_log_data); - //社区等级判断 echo 'ok'; } catch (\Exception $e) { Log::info('订单角色贡献值处理失败; error : ' . $e->getMessage()); From 7ebea57edd5862e25456afcf32ae6c9045c6ffc0 Mon Sep 17 00:00:00 2001 From: limu Date: Tue, 26 Dec 2023 17:11:43 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=AF=8F=E6=97=A5=E7=94=A8=E6=88=B7?= =?UTF-8?q?=E8=B4=A1=E7=8C=AE=E5=80=BC=E8=BD=AC=E5=A2=9E=E5=80=BC=E7=A7=AF?= =?UTF-8?q?=E5=88=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/dayUserGrowth.php | 53 +++++++++++++++++++++++++++++++++++ app/command/dayValue.php | 3 +- config/console.php | 2 ++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 app/command/dayUserGrowth.php diff --git a/app/command/dayUserGrowth.php b/app/command/dayUserGrowth.php new file mode 100644 index 0000000..a82ca87 --- /dev/null +++ b/app/command/dayUserGrowth.php @@ -0,0 +1,53 @@ +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'; + + } + + +} diff --git a/app/command/dayValue.php b/app/command/dayValue.php index 7659f0d..58e312c 100644 --- a/app/command/dayValue.php +++ b/app/command/dayValue.php @@ -38,8 +38,6 @@ class dayValue extends Command { $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') @@ -154,6 +152,7 @@ class dayValue extends Command } catch (\Exception $e) { print_r($e->getLine() . "-" . $e->getMessage()); } + echo '执行结束'; } diff --git a/config/console.php b/config/console.php index 9c6dbd3..47b478b 100644 --- a/config/console.php +++ b/config/console.php @@ -43,5 +43,7 @@ return [ 'dayValue' => 'app\command\dayValue', //每日兑换率生成 'dayUserValue' => 'app\command\dayUserValue', + //每日贡献值转增值积分 + 'dayUserGrowth' => 'app\command\dayUserGrowth', ], ];