$userID]); foreach ($list as $item) { //获取配置 $rebatePercent = floatval(GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_REBATE_LIST[$item->level])); if ($rebatePercent == 0) continue; $rate = GameConfigServices::getCommonNumByID(GameConfigServices::COMMON_GEM_EXCHANGE_GOLD_RATE); //计算返点金额 $rebateGold = intval($gold * ($rebatePercent / 100)); if ($rebateGold == 0) continue; $farmDbData = Farm::findOne(['user_id' => $item->parent_user_id]); //查找索引最大的农田 $maxLandPosition = Land::find() ->where(['farm_id' => $farmDbData->id]) ->max('position'); if($maxLandPosition<11){ continue; } //修改接受返点的用户金币 $log = SystemLogUtil::get($item->parent_user_id, SystemLogUtil::TYPE_GOLD, $rebateGold, 0, SystemLogUtil::FROM_TYPE_REBATE, []); $rs = UserService::checkAndModifyMoney($item->parent_user_id, true,$rebateGold, 0, $log); if ($rs != ResultStatusServices::RS_OPERATION_SUCCESS) throw new StatusException($rs); //保存返点记录 $rebateDbData = new Rebate(); $rebateDbData->from_user_id = $item->child_user_id; $rebateDbData->be_user_id = $item->parent_user_id; $rebateDbData->rebate_gold = $rebateGold; $rebateDbData->level = $item->level; $rebateDbData->type = $type; if (!$rebateDbData->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); } } /** * 创建推广关系 * @param $childUserID * @param $parentUserID * @throws StatusException */ public static function createUserRebates($childUserID, $parentUserID) { $childList = UserRebate::findAll(['child_user_id' => $parentUserID]); foreach ($childList as $item) { $level = $item->level + 1; if ($level > RebateUtil::MAX_LEVEL) continue; $userRebate = new UserRebate(); $userRebate->parent_user_id = $item->parent_user_id; $userRebate->child_user_id = $childUserID; $userRebate->level = $level; if (!$userRebate->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); } $userRebate = new UserRebate(); $userRebate->parent_user_id = $parentUserID; $userRebate->child_user_id = $childUserID; $userRebate->level = 1; if (!$userRebate->save()) throw new StatusException(ResultStatusServices::RS_SAVE_DB_ERROR); } // /** // * 迁移数据 // * @param $userID // */ // public static function createUserRebate($userID) // { // $findUserID = $userID; // // $userIDList = []; // // while (true) { // if (count($userIDList) >= self::MAX_LEVEL) break; // // $user = User::findById($findUserID, false); // if (empty($user)) break; // // $findUserID = $user->introduce_user_id; // if ($findUserID <= 0) break; // // array_push($userIDList, $findUserID); // } // // for ($i=0;$iparent_user_id=$userIDList[$i]; // $userRebate->child_user_id=$userID; // $userRebate->level=$i+1; // $userRebate->save(); // } // } }