def query_player_items(request): ''' 查询用户物品 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) items = player.items.all().values() data = [] for item in items: meta = item.to_dict() meta["name"] = item.item and item.item.name or "" data.append(meta) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def delete_item(request): playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() itemType = request.REQUEST.get("itemType") count = request.REQUEST.get("itemCount") level = request.REQUEST.get("level", 0) player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" return HttpResponseJson(resdata) playeritem = player.items.get(int(itemType)) if not playeritem: #raise ErrorException(player, u"itemUse:playeritem(%s) no existed" % (playeritem_id)) resdata["success"] = False resdata["message"] = u"物品不存在!" return HttpResponseJson(resdata) playeritem.sub(int(count), u"GM删除物品") player.save() resdata["success"] = True resdata["message"] = "" return HttpResponseJson(resdata)
def query_player_soul(request): ''' 查询用户灵魂碎片 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) souls = player.souls.all().values() data = [] for soul in souls: meta = soul.to_dict() meta["name"] = soul.soul and soul.soul.name or "" data.append(meta) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_player_artifact(request): ''' 查询用户圣物 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) artifacts = player.artifacts.all().values() data = [] for artifact in artifacts: meta = artifact.to_dict() meta["name"] = artifact.artifact and artifact.artifact.name or "" data.append(meta) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_player_hero(request): ''' 查询用户英雄 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) heroes = player.heroes.all().values() data = [] for hero in heroes: meta = hero.to_dict() meta["name"] = hero.warrior and hero.warrior.name or "" data.append(meta) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_orders_by_plat_orderid(request): ''' 按订平台单号查询 ''' platOrderId = request.REQUEST.get("platOrderId", "").strip() order = PurchaseOrder.objects.get(plat_order_id=str(platOrderId)) if not order: data = {} data["success"] = False data["message"] = u"该订单不存在!" data["errorcode"] = ErrorCode.ERROR_PARAMETER_FORMAT return HttpResponseJson(data) return HttpResponseJson(order.to_dict())
def query_orders_by_time(request): ''' 按时间查询订单 ''' channel = request.REQUEST.get("channel", "").strip() startTimeStr = request.REQUEST.get("startTime", "").strip() # 格式:xxxx-xx-xx xx:xx:xx endTimeStr = request.REQUEST.get("endTime", "").strip() status = int(request.REQUEST.get("status", 2)) # 0 失败(未完成) 1 成功 2 全部 startTime = get_datetime(startTimeStr) endTime = get_datetime(endTimeStr) resdata = {} if (not startTime) or (not endTime) or (status not in range(3)) or ( startTime > endTime): resdata["success"] = False resdata["message"] = u"输入的参数有误!" resdata["data"] = [] return HttpResponseJson(resdata) orders = [] if status == 2: if not channel: orders = PurchaseOrder.objects.filter(updated_at__gte=startTime, updated_at__lte=endTime) else: orders = PurchaseOrder.objects.filter(channel=channel, updated_at__gte=startTime, updated_at__lte=endTime) else: if not channel: orders = PurchaseOrder.objects.filter(status=status, updated_at__gte=startTime, updated_at__lte=endTime) else: orders = PurchaseOrder.objects.filter(channel=channel, status=status, updated_at__gte=startTime, updated_at__lte=endTime) data = [] for order in orders: meta = {} meta = order.to_dict() data.append(meta) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_rank_by_price(request): ''' 充值排行 ''' channel = request.REQUEST.get("channel", "").strip() startTimeStr = request.REQUEST.get("startTime", "").strip() endTimeStr = request.REQUEST.get("endTime", "").strip() startTime = get_datetime(startTimeStr) endTime = get_datetime(endTimeStr) resdata = {} if startTime > endTime: meta = {} resdata["success"] = False resdata["message"] = u"输入的参数有误!" resdata["data"] = [] return HttpResponseJson(resdata) if not channel: orders = PurchaseOrder.objects.filter(status=1, updated_at__gte=startTime, updated_at__lte=endTime) else: orders = PurchaseOrder.objects.filter(channel=channel, status=1, updated_at__gte=startTime, updated_at__lte=endTime) rank_dic = {} for order in orders: if order.player_id in rank_dic: rank_dic[order.player_id] += order.price else: rank_dic[order.player_id] = order.price #data.items().sort(lambda x,y:cmp(y[1],x[1])) rank_list = sorted(rank_dic.items(), key=lambda item: item[1], reverse=True) data = [] i = 1 for rank in rank_list: meta = {} meta["rank"] = i meta["player_id"] = rank[0] meta["price"] = rank[1] data.append(meta) i += 1 resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def gag_player(request): ''' 禁言 ''' playerIdList_int = request.REQUEST.get("playerIdList", "").strip() # 逗号隔开的id字符串 gagAt = request.REQUEST.get("gagAt", "").strip() # 时间字符串 格式:xxxx-xx-xx xx:xx:xx serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() data = [] playerIds = [pk for pk in playerIdList_int.strip().split(",") if pk] for playerId in playerIds: player = get_player_by_id_or_str(playerId, int(serverId)) meta = {} meta["success"] = False meta["id"] = playerId if not player: meta["message"] = u"该玩家不存在!" meta["errorcode"] = ErrorCode.ERROR_PLAYER_IS_NONE data.append(meta) continue if not player.setGagAt(gagAt): meta["message"] = "禁言失败!" meta["errorcode"] = ErrorCode.ERROR_SET_FAILED data.append(meta) continue meta["success"] = True meta["message"] = "禁言成功!" data.append(meta) return HttpResponseJson(data)
def _handle(request): print "***", request.META ip = request.META.get("REMOTE_ADDR", "") print ip if ip not in WHITELIST: return HttpResponseJson({}) return view_func(request)
def send_mail(request): ''' 发送邮件 ''' playerIdList_int = request.REQUEST.get("playerIdList", "").strip() # 逗号隔开的id字符串 serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() title = request.REQUEST.get("title", "").strip() # "fytext_300723" attachments_str = request.REQUEST.get("attachments", "").strip() # t1000c1002,t1001c1003 content = request.REQUEST.get("content", "").strip() # "fytext_301064" paramList = request.REQUEST.get("paramList", "").strip() print title, "*****" if playerIdList_int == "all": players = get_all_player() else: players = [pk for pk in playerIdList_int.strip().split(",") if pk] rewards = [] attachments = [pk for pk in attachments_str.strip().split(",") if pk] for attachment in attachments: reward = get_commonreward(attachment) rewards.append({"type": reward.type, "count": reward.count}) contents = [] paramList = [pk for pk in paramList.strip().split(",") if pk] contents.append({"content": content, "paramList": paramList}) data = [] for player in players: if not isinstance(player, Player): _player = get_player_by_id_or_str(player, int(serverId)) else: _player = player meta = {} meta["success"] = False if not _player: meta["id"] = player meta["message"] = u"该玩家不存在!" meta["errorcode"] = ErrorCode.ERROR_PLAYER_IS_NONE data.append(meta) continue send_system_mail(player=_player, sender=None, title=title, contents=contents, rewards=rewards) meta["id"] = _player.id meta["success"] = True meta["message"] = "Send success!" data.append(meta) return HttpResponseJson(data)
def query_player_elementtower(request): ''' 查询用户元素之塔 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = {} return HttpResponseJson(resdata) data = player.elementTower.to_dict() resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_orders_by_orderid(request): ''' 按订单号查询 ''' orderId = request.REQUEST.get("orderId", "").strip() order = PurchaseOrder.objects.get(order_id=str(orderId)) resdata = {} if not order: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) data = [] data.append(order.to_dict()) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_player_mails(request): ''' 查询玩家邮件 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) mails = get_mails(player) data = [] for mail in mails: data.append(mail.to_dict()) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_player_raceinstance(request): ''' 查询用户活动副本 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} if not player: resdata["success"] = False resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) instances = player.raidinstances.all().values() data = [] for instance in instances: meta = instance.to_dict() data.append(meta) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_orders_by_playerid(request): ''' 按玩家ID查询订单 ''' playerId = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() startTimeStr = request.REQUEST.get("startTime", "").strip() # 格式:xxxx-xx-xx xx:xx:xx endTimeStr = request.REQUEST.get("endTime", "").strip() status = int(request.REQUEST.get("status", 2)) # 0 失败(未完成) 1 成功 2 全部 startTime = get_datetime(startTimeStr) endTime = get_datetime(endTimeStr) player = get_player_by_id_or_str(playerId, int(serverId)) resdata = {} # if (playerId == "") or (not startTime) or (not endTime) or (status not in range(3)) or (startTime > endTime): if not player: resdata["success"] = False #resdata["message"] = "The user is not exist!" resdata["message"] = u"该玩家不存在!" resdata["data"] = [] return HttpResponseJson(resdata) orders = [] if status == 2: if startTime and endTime: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), updated_at__gte=startTime, updated_at__lte=endTime) elif startTime: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), updated_at__gte=startTime) elif endTime: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), updated_at__lte=endTime) else: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), ) else: if startTime and endTime: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), status=status, updated_at__gte=startTime, updated_at__lte=endTime) elif startTime: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), status=status, updated_at__gte=startTime) elif endTime: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), status=status, updated_at__lte=endTime) else: orders = PurchaseOrder.objects.filter(player_id=get_playerId( playerId, serverId), status=status) data = [] for order in orders: meta = {} meta = order.to_dict() data.append(meta) resdata["success"] = True resdata["message"] = "" resdata["data"] = data return HttpResponseJson(resdata)
def query_player(request): ''' 查询用户 ''' playerIds = request.REQUEST.get("playerId", "").strip() serverId = request.REQUEST.get("serverId", str(settings.SERVERID)).strip() playerIds = [ playerId for playerId in playerIds.strip().split(",") if playerId ] print playerIds, "***" data = [] for playerId in playerIds: player = get_player_by_id_or_str(playerId, int(serverId)) if not player: meta = { "success": False, "message": u"该玩家不存在!", "player": { "id": playerId, } } data.append(meta) continue meta = { "player": { "id": player.id, "name": player.name, "level": player.level, "xp": player.xp, "gold": player.gold, "power": player.power, "stamina": player.stamina, "yuanbo": player.yuanbo, "wood": player.wood, "couragepoint": player.couragepoint, "gashaponInfos": { "gold": { "freeNumber": player.gashaponInfos["gold"]["freeNumber"], "last": player.gashaponInfos["gold"]["last"].strftime( "%Y-%m-%d %H:%M:%S") }, "yuanbo": { "last": player.gashaponInfos["yuanbo"]["last"].strftime( "%Y-%m-%d %H:%M:%S") } }, "lastInstance": player.lastInstance, "lastEliteInstance": player.lastEliteInstance, "dailyTasks": player.dailyTasks, "tasks": player.tasks, "sevenDaystasks": player.sevenDaystasks, "completeSevenTasks": player.completeSevenTasks, "tutorial": player.tutorial, "deviceId": player.deviceId, "week_card": { "status": player.week_card["status"], "ended_at": player.week_card["ended_at"] }, "month_card": { "status": player.month_card["status"], "ended_at": player.month_card["ended_at"] }, "castleLevel": player.castleLevel, "playerWarriorIds": player.playerWarriorIds, "isOpenSiege": player.isOpenSiege, "isOpenArena": player.isOpenArena, "halfBuyIds": player.halfBuyIds, "powerRank": player.powerRank, "towerGold": player.towerGold, "activityValue": player.activityValue, "banAt": player.banAt.strftime("%Y-%m-%d %H:%M:%S"), "gagAt": player.gagAt.strftime("%Y-%m-%d %H:%M:%S"), "vip": player.vip, "createTime": player.created_at.strftime("%Y-%m-%d %H:%M:%S"), "lastLoginTime": player.updated_at.strftime("%Y-%m-%d %H:%M:%S") }, "success": True } if player.week_card["ended_at"]: meta["player"]["week_card"]["ended_at"] = player.week_card[ "ended_at"].strftime("%Y-%m-%d %H:%M:%S") if player.month_card["ended_at"]: meta["player"]["month_card"]["ended_at"] = player.month_card[ "ended_at"].strftime("%Y-%m-%d %H:%M:%S") data.append(meta) return HttpResponseJson(data)
def purchase_callback(request): """ 支付回调 """ AppID = request.POST.get("AppID", "") OrderSerial = request.POST.get("OrderSerial", "") CooperatorOrderSerial = request.POST.get("CooperatorOrderSerial", "") Sign = request.POST.get("Sign", "") Content = request.POST.get("Content", "") secret_key = settings.CHANNELS["baidu"]["secret_key"] sign = hashlib.md5("%s%s%s%s%s" % (AppID, OrderSerial, CooperatorOrderSerial, Content, secret_key)).hexdigest() result = { "AppID": AppID, "ResultCode": 0, "resultMsg": "", "Sign": "", "Content": "" } if sign != Sign: result["resultMsg"] = u"Sign Error" else: contentStr = base64.b64decode(Content) #json解析 content = simplejson.loads(contentStr) order = get_order(CooperatorOrderSerial) if not order: result["ResultMsg"] = "No order" else: if not order.is_success: order.notify_data = simplejson.dumps(content) order.plat_order_id = OrderSerial yuanbo = get_yuanbo(order.yuanbo_id) #if yuanbo.price <= content["OrderMoney"] and content["OrderStatus"] == 1: if content["OrderStatus"] == 1: player = get_player(order.player_id) add_yuanbo, is_first = recharge_yuanbo( player, yuanbo, info="baidu recharge") order.yuanbo = add_yuanbo order.is_first = is_first order.success() player.update() else: order.failure() order.save() result["ResultCode"] = 1 result["Sign"] = hashlib.md5( "%s%s%s" % (result["AppID"], result["ResultCode"], secret_key)).hexdigest() return HttpResponseJson(result)