|
|
@@ -9,6 +9,7 @@ use app\common\controller\Api;
|
|
|
use app\common\model\UserWelfare;
|
|
|
use app\common\model\ProductPopular;
|
|
|
use app\common\model\ProductOrder;
|
|
|
+use app\common\model\UserModel;
|
|
|
use fast\Action;
|
|
|
use fast\Asset;
|
|
|
use fast\MembershipLevel;
|
|
|
@@ -24,234 +25,32 @@ use fast\Http;
|
|
|
class WelfareLoginc
|
|
|
{
|
|
|
|
|
|
+
|
|
|
/** 添加新人福利
|
|
|
* @param int $uid 用户id
|
|
|
* @param array $productId 产品ID
|
|
|
* @param int $num 数量
|
|
|
* @param int $lan 语言
|
|
|
*/
|
|
|
- public static function setUserWelfareLos($uid, int $productId, $num, $lan)
|
|
|
+ public static function setUserWelfareLos($uid, int $productId, $num, $lan, $typeId)
|
|
|
{
|
|
|
$tim = time();
|
|
|
- $result = ProductPopular::alias('a')->where('a.start_time', '<=', $tim)->where('a.end_time', '>=', $tim)
|
|
|
- ->join('product_list b', "a.product_id = b.id", "left")
|
|
|
- ->field('a.*,b.is_area,'.$lan.'_name as name')
|
|
|
- ->where('a.product_id', $productId)->find();
|
|
|
+ $result = ProductPopular::getPopularByTime($productId, $lan, $tim);
|
|
|
if(!$result || $num > $result->stock) throw new Exception(__('库存不足'));
|
|
|
if(empty($result->is_area)){
|
|
|
- ProductOrder::setPopularNoAreaOrder($num, $result->id, $result->price, $result->product_id, $uid, ProductOrder::Newbie);
|
|
|
+ ProductOrder::setPopularNoAreaOrder($num, $result->id, $result->price, $result->product_id, $uid, $typeId);
|
|
|
}else{
|
|
|
$areaArr = ProductArea::where('product_id', $productId)->where('status', ProductArea::NORMAL)->orderRaw('RAND()')->limit($num)->column('id');
|
|
|
- ProductOrder::setPopularAreaOrder($areaArr, $result->id, $result->price, $result->product_id, $uid, ProductOrder::Newbie);
|
|
|
+ ProductOrder::setPopularAreaOrder($areaArr, $result->id, $result->price, $result->product_id, $uid, $typeId);
|
|
|
}
|
|
|
return ['start_time'=>$tim, 'name'=>$result->name, 'num'=>$num];
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- /**
|
|
|
- * 计算理论收益
|
|
|
- * @var array
|
|
|
- */
|
|
|
- protected function calculateRewards($info, $team_level_config)
|
|
|
- {
|
|
|
- $user = DB::table('user')
|
|
|
- ->where('id', $info['user_id'])
|
|
|
- ->find();
|
|
|
- $level_info = [];
|
|
|
- foreach ($team_level_config as $level) {
|
|
|
- if ($user['team_power'] >= $level['compute_require']) {
|
|
|
- $level_info['id'] = $level['level_id'];
|
|
|
- $level_info['rate'] = $level['compute_incentive'];
|
|
|
- }
|
|
|
- }
|
|
|
- if(isset($level_info['id']) && $level_info['id'] > 0){
|
|
|
- //团队等级大于0,才发放收益
|
|
|
- $amount = $info['today_power'] * $level_info['rate'];
|
|
|
-
|
|
|
- DB::table('team_rewards')
|
|
|
- ->where('id', $info['id'])
|
|
|
- ->update([
|
|
|
- 'team_power' => $user['team_power'],
|
|
|
- 'level_id' => $level_info['id'],
|
|
|
- 'rate' => $level_info['rate'],
|
|
|
- 'commission' => $amount,
|
|
|
- 'update_time' => date('Y-m-d H:i:s')
|
|
|
- ]);
|
|
|
- //累计上级的团队收益
|
|
|
- DB::table('team_rewards')
|
|
|
- ->where('user_id', $user['parent_id'])
|
|
|
- ->where('date_time', $info['date_time'])
|
|
|
- ->update([
|
|
|
- 'team_commission' => DB::raw("team_commission + " . $amount),
|
|
|
- 'update_time' => date('Y-m-d H:i:s')
|
|
|
- ]);
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * 发放团队加权分红
|
|
|
- * 1.提取各个等级的会员列表
|
|
|
- * 2.再计算当日新增业绩
|
|
|
- * 3.根据每个等级现存的人数,按比例平分佣金
|
|
|
- */
|
|
|
- public function usdtRewards()
|
|
|
- {
|
|
|
- $date = $this->getExeDate($this->rewards_type['usdt']['type_id']);
|
|
|
-
|
|
|
- if(empty($date)){
|
|
|
- return "本次没有可用时间";
|
|
|
- }
|
|
|
-
|
|
|
- //创建定时任务执行日志
|
|
|
- $TimedTaskLog = new TimedTaskLogModel();
|
|
|
- $log_id = $TimedTaskLog->insertGetId([
|
|
|
- 'type_id' => $this->rewards_type['usdt']['type_id'],
|
|
|
- 'type_name' => $this->rewards_type['usdt']['type_name'],
|
|
|
- 'date_time' => $date,
|
|
|
- 'create_time' => date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
-
|
|
|
- $between_time = [strtotime($date), strtotime($date) + 86400];
|
|
|
-
|
|
|
- //读取当日新增数据,按用户分组统计
|
|
|
- $recharge_amount = DB::table('offline_recharge_record')
|
|
|
- ->whereBetween('create_time', $between_time)
|
|
|
- ->where('order_type', 1)
|
|
|
- ->where('status', 1)
|
|
|
- ->sum('amount');
|
|
|
-
|
|
|
- if($recharge_amount < 1){
|
|
|
- (new Output())->writeln("本次没有可用新增数据:" . $date);
|
|
|
- return $log_id;
|
|
|
- }
|
|
|
-
|
|
|
- //1.查找有等级的会员
|
|
|
- $level_user_list = DB::table('user')
|
|
|
- ->field('id,team_level_id')
|
|
|
- ->where('team_level_id', '>', 0)
|
|
|
- ->select();
|
|
|
- $levels_info = [];
|
|
|
- //整理数据格式,以team_level_id为键名,存放该等级下的会员id数组
|
|
|
- foreach ($level_user_list as $info) {
|
|
|
- $levels_info[$info['team_level_id']][] = $info['id'];
|
|
|
- }
|
|
|
- //读取团队等级配置
|
|
|
- $team_level_config = DB::table('team_level')
|
|
|
- ->field('level_id, weight_dividend')
|
|
|
- ->select();
|
|
|
- foreach ($team_level_config as $level) {
|
|
|
- if(isset($levels_info[$level['level_id']])){//存在当前等级的会员
|
|
|
- //计算当前等级平分佣金金额:当日新增业绩 * 分红比例 / 当前等级人数
|
|
|
- $amount = $recharge_amount * $level['weight_dividend'] / count($levels_info[$level['level_id']]);
|
|
|
- if($amount > 0){
|
|
|
- foreach ($levels_info[$level['level_id']] as $user_id){
|
|
|
- //发放佣金
|
|
|
- (new LedgerWalletModel)->changeWalletAccount($user_id, Asset::USDT, $amount, Action::UsdtWeightDividend);
|
|
|
- }
|
|
|
- }else{
|
|
|
- Log::info("分红等级" . $level['level_id'] . "在" . $date . "分红金额为0;当日新增业绩:" . $amount . ",分红比例:" . $level['weight_dividend']. ",分红人数" . dump($levels_info[$level['level_id']]));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return $log_id;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 发放社区长、系统领导人加权分红
|
|
|
- * 1.提取社区长等级的会员列表
|
|
|
- * 2.再计算当日新增业绩
|
|
|
- * 3.根据每个等级现存的人数,按比例平分佣金
|
|
|
- * 5.提取系统领导人等级的会员列表
|
|
|
- * 6.再计算当日新增业绩
|
|
|
- * 7.根据每个等级现存的人数,按比例平分佣金
|
|
|
- */
|
|
|
- public function marketRewards()
|
|
|
- {
|
|
|
- $date = $this->getExeDate($this->rewards_type['market']['type_id']);
|
|
|
-
|
|
|
- if(empty($date)){
|
|
|
- return "本次没有可用时间";
|
|
|
- }
|
|
|
-
|
|
|
- //创建定时任务执行日志
|
|
|
- $TimedTaskLog = new TimedTaskLogModel();
|
|
|
- $log_id = $TimedTaskLog->insertGetId([
|
|
|
- 'type_id' => $this->rewards_type['market']['type_id'],
|
|
|
- 'type_name' => $this->rewards_type['market']['type_name'],
|
|
|
- 'date_time' => $date,
|
|
|
- 'create_time' => date('Y-m-d H:i:s'),
|
|
|
- ]);
|
|
|
-
|
|
|
- $between_time = [strtotime($date), strtotime($date) + 86400];
|
|
|
-
|
|
|
- //读取当日新增数据
|
|
|
- $recharge_power = DB::table('offline_recharge_record')
|
|
|
- ->whereBetween('create_time', $between_time)
|
|
|
- ->where('status', 1)
|
|
|
- ->sum('power');
|
|
|
-
|
|
|
- if($recharge_power < 1){
|
|
|
- (new Output())->writeln("本次没有可用新增数据:" . $date);
|
|
|
- return $log_id;
|
|
|
- }
|
|
|
-
|
|
|
- //团队长分红
|
|
|
- //查找有团队长等级的会员
|
|
|
- $community_user_list = DB::table('user')
|
|
|
- ->field('id,market_level_id')
|
|
|
- ->where('market_level_id', MembershipLevel::CommunityLeader)
|
|
|
- ->select();
|
|
|
-
|
|
|
- $community_rewards = (new ParametersModel())->getValue('communityRewards'); //社区长分红参数 数据格式为:0.02:0.5:0.5
|
|
|
- $usdt_rate = (new ParametersModel())->getValue('usdtToPowerRate');
|
|
|
- $community_rewards_arr = explode(':', $community_rewards);
|
|
|
-
|
|
|
- $reward = $recharge_power * $community_rewards_arr[0] / count($community_user_list);//新增业绩 * 分红比例 / 人数
|
|
|
- if($reward > 0) {
|
|
|
- $reward_power = $reward * $community_rewards_arr[1];
|
|
|
- $reward_usdt = $reward * $community_rewards_arr[2] / $usdt_rate;//算力折算成U
|
|
|
-
|
|
|
- foreach ($community_user_list as $info) {
|
|
|
- //发放分红
|
|
|
- (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::POWER, $reward_power, Action::PowerBonusAward);
|
|
|
-
|
|
|
- (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::USDT, $reward_usdt, Action::UsdtWeightDividend);
|
|
|
- }
|
|
|
- }else {
|
|
|
- Log::info("社区长分红在" . $date . "分红金额为0;当日新增业绩:" . $recharge_power . ",分红比例:" . $community_rewards_arr[0] . ",分红人数" . count($community_user_list));
|
|
|
- }
|
|
|
-
|
|
|
- //领导人分红
|
|
|
- //查找有团队长等级的会员
|
|
|
- $sys_leader_user_list = DB::table('user')
|
|
|
- ->field('id,market_level_id')
|
|
|
- ->where('market_level_id', MembershipLevel::SystemLeader)
|
|
|
- ->select();
|
|
|
-
|
|
|
- $sys_leade_rewards = (new ParametersModel())->getValue('sysLeaderRewards'); //系统领导人分红参数 数据格式为:0.02:0.5:0.5
|
|
|
- $sys_leade_rewards_arr = explode(':', $sys_leade_rewards);
|
|
|
-
|
|
|
- $reward = $recharge_power * $sys_leade_rewards_arr[0] / count($sys_leader_user_list);//新增业绩 * 分红比例 / 人数
|
|
|
- if($reward > 0) {
|
|
|
- $reward_power = $reward * $sys_leade_rewards_arr[1];
|
|
|
- $reward_usdt = $reward * $sys_leade_rewards_arr[2] * 8;//算力折算成U
|
|
|
-
|
|
|
- foreach ($sys_leader_user_list as $info) {
|
|
|
- //发放分红
|
|
|
- (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::POWER, $reward_power, Action::PowerBonusAward);
|
|
|
+
|
|
|
|
|
|
- (new LedgerWalletModel)->changeWalletAccount($info['id'], Asset::USDT, $reward_usdt, Action::UsdtWeightDividend);
|
|
|
- }
|
|
|
- }else {
|
|
|
- Log::info("系统领导人分红在" . $date . "分红金额为0;当日新增业绩:" . $recharge_power . ",分红比例:" . $community_rewards_arr[0] . ",分红人数" . count($community_user_list));
|
|
|
- }
|
|
|
- return $log_id;
|
|
|
- }
|
|
|
+
|
|
|
|
|
|
|
|
|
/**
|