def handleAuditResultCoupon(userId, record, result): timestamp = pktimestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userId) if result == RESULT_AUDITSUCC: record.state = TYExchangeRecord.STATE_ACCEPT elif result == RESULT_REJECT: record.state = TYExchangeRecord.STATE_REJECT elif result == RESULT_REJECT_RETURN: record.state = TYExchangeRecord.STATE_REJECT_RETURN count = record.params.get('count', 0) userAssets.addAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH_BACK', count) # 历史提现记录对应减掉这个数额 userdata.incrAttr(userId, 'exchangedCoupon', -abs(count)) else: assert (0) if result in (RESULT_REJECT, RESULT_REJECT_RETURN): mail = '您申请提现%.2f元,审核未通过,抱歉。' % (record.params.get('amount', 0)) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') return record
def sendReward(userId, rewardConf, mailstr, eventId, eventParam): """ 通用发货 param: rewardConf 奖励配置 格式: { 'typeId': 'FixedContent', 'items': [{'itemId': 'user:chip', 'count': 100}] } param: mailstr 邮件内容文本字符串,其中包含子串\\${rewardContent} eventId: 哪个事件触发的 eventParam: 事件参数 return: list<(TYAssetKind, consumeCount, final)> """ rewardContent = TYContentRegister.decodeFromDict(rewardConf) userAssets = hallitem.itemSystem.loadUserAssets(userId) assetList = userAssets.sendContent(DIZHU_GAMEID, rewardContent, 1, True, pktimestamp.getCurrentTimestamp(), eventId, eventParam) changeNames = TYAssetUtils.getChangeDataNames(assetList) contents = TYAssetUtils.buildContentsString(assetList) if mailstr: mailstr = strutil.replaceParams(mailstr, {'rewardContent': contents}) message.send(DIZHU_GAMEID, message.MESSAGE_TYPE_SYSTEM, userId, mailstr) changeNames.add('message') datachangenotify.sendDataChangeNotify(DIZHU_GAMEID, userId, changeNames) return assetList
def handleShippingResultCoupon(userId, record, result): timestamp = pktimestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userId) if result == RESULT_OK: record.state = TYExchangeRecord.STATE_SHIPPING_SUCC elif result == RESULT_SHIPPINGFAIL_RETURN: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL_RETURN count = record.params.get('count', 0) userAssets.addAsset(HALL_GAMEID, hallitem.ASSET_COUPON_KIND_ID, count, timestamp, 'WX_GET_CASH_BACK', count) # 历史提现记录对应减掉这个数额 userdata.incrAttr(userId, 'exchangedCoupon', -abs(count)) elif result == RESULT_SHIPPINGFAIL: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL else: assert (0) amount = record.params.get('amount', 0) if result != RESULT_OK: mail = '您申请提现%.2f元,审核未通过,抱歉。' % (amount) else: mail = '您已成功提现%.2f元,请查收。' % (amount) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') return record
def get_award(self, uid): if not self.checkOperative(): return 'acitivity expired!' actkey = ACTIVITY_KEY.format(HALL_GAMEID, uid, self.getid()) weekcnt, daycnt = self._get_click_cnt(uid, actkey) if weekcnt >= self._clientConf['config'][ 'weeklimit'] or daycnt >= self._clientConf['config'][ 'daylimit']: return 'awardcnt:({},{}) expand limitcnt!'.format(weekcnt, daycnt) shareid = self._serverConf["share"] share = hallshare.findShare(shareid) if not share: return 'share:{} not exist!'.format(shareid) daobase.executeUserCmd(uid, 'HINCRBY', actkey, self.FIELD_DAY_CNT, 1) daobase.executeUserCmd(uid, 'HINCRBY', actkey, self.FIELD_WEEK_CNT, 1) daobase.executeUserCmd(uid, 'HINCRBY', actkey, self.FIELD_TOTAL_CNT, 1) hallshare.sendReward(HALL_GAMEID, uid, share, 'share_click') # 分享BI日志汇报 clientid = sessiondata.getClientId(uid) bireport.reportGameEvent('SHARE_CALLBACK', uid, HALL_GAMEID, shareid, 0, 0, 0, 0, 0, [], clientid) if share.mail: message.send(HALL_GAMEID, message.MESSAGE_TYPE_SYSTEM, uid, share.mail) return 'ok'
def sendMsgToUser(userId, gameId): """ 将中奖信息发给用户prize """ snatchConf = getSnatchConf() sendToMsg = snatchConf.get('rewardMsg', '') from poker.entity.biz.message import message message.send(gameId, message.MESSAGE_TYPE_SYSTEM, userId, sendToMsg)
def sendSingleUserPrize2(cls, gameId, userId, conf): prize = conf.get('prize', {}) prizeGet = {"CHIP": prize["CHIP"]} userchip.incrChip(userId, gameId, prize["CHIP"], daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'ACTIVITY_REWARD', 0, None) cls.updateNotify(gameId, userId, 'chip') message.send(gameId, message.MESSAGE_TYPE_SYSTEM, userId, cls.message(prizeGet)) return prizeGet
def handleExchangeAuditResult1(userId, exchangeId, result): ''' 处理审核结果 ''' if ftlog.is_debug(): ftlog.debug('userId=', userId, 'exchangeId=', exchangeId, 'result=', result) record = loadRecord(userId, exchangeId) if not record: raise TYUnknownExchangeOrder() if record.state != TYExchangeRecord.STATE_AUDIT: raise TYBadStateExchangeOrder() userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() item = userBag.findItem(record.itemId) if not isinstance(item, TYExchangeItem): raise TYBizException(-1, '系统错误') if item.state != TYExchangeItem.STATE_AUDIT: raise TYBizException(-1, '道具状态错误') timestamp = pktimestamp.getCurrentTimestamp() if result == RESULT_AUDITSUCC: item.state = TYExchangeItem.STATE_SHIPPING record.state = TYExchangeRecord.STATE_ACCEPT userBag.updateItem(HALL_GAMEID, item, timestamp) elif result == RESULT_REJECT: record.state = TYExchangeRecord.STATE_REJECT userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) elif result == RESULT_REJECT_RETURN: record.state = TYExchangeRecord.STATE_REJECT_RETURN item.state = TYExchangeItem.STATE_NORMAL userBag.updateItem(HALL_GAMEID, item, timestamp) else: raise TYBizException(-1, '错误的请求状态') itemDisPlayName = item.itemKind.displayName exchangeDesc = record.params.get('desc', '') if result == RESULT_REJECT or result == RESULT_REJECT_RETURN: mail = '您申请用%s兑换(领取)%s,审核未通过,抱歉。' % (itemDisPlayName, exchangeDesc) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) ftlog.info('hallexchange.handleExchangeAuditResult1', 'userId=', userId, 'exchangeId=', exchangeId, 'result=', result, 'itemId=', item.itemId, 'itemKindId=', item.kindId, 'orderState=', record.state) return record
def on_praise_friend(cls, gameId, uid, clientId, mo): code = mo.getResult('code', 0) # vip = mo.getResult('vip') if code == 0: friend_uid = int(mo.getResult('friend_uid')) nick_name = mo.getResult('nick_name') friend_nick_name = mo.getResult('friend_nick_name') my_add_charm = mo.getResult('my_add_charm') friend_add_charm = mo.getResult('friend_add_charm') my_charm = mo.getResult('my_charm') friend_charm = mo.getResult('friend_charm') msg1 = '给"' + friend_nick_name + '"点赞获得' + str(my_add_charm) + '个魅力值' msg2 = '"' + nick_name + '"给您点赞获得' + str(friend_add_charm) + '个魅力值' from poker.entity.biz.message import message message.send(gameId, message.MESSAGE_TYPE_SYSTEM, int(uid), msg1) message.send(gameId, message.MESSAGE_TYPE_SYSTEM, int(friend_uid), msg2) ftlog.debug('on praise friend.... ' + msg1) ftlog.debug('on praise friend.... ' + msg2) datachangenotify.sendDataChangeNotify(gameId, uid, 'charm') from hall.entity.hallranking import rankingSystem, TYRankingInputTypes timestamp = pktimestamp.getCurrentTimestamp() rankingSystem.setUserByInputType(gameId, TYRankingInputTypes.CHARM, uid, my_charm, timestamp) rankingSystem.setUserByInputType(gameId, TYRankingInputTypes.CHARM, friend_uid, friend_charm, timestamp) # 历史获赞次数 history_praised_num = gamedata.incrGameAttr(friend_uid, gameId, 'history_praised_num', 1) mo.setResult('friend_history_praised_num', history_praised_num) if code != 2: return from hall.entity.todotask import TodoTaskPayOrder, TodoTaskShowInfo from hall.entity.todotask import TodoTaskHelper from hall.entity import hallvip, hallitem user_vip = hallvip.userVipSystem.getUserVip(uid) delta_exp = user_vip.deltaExpToNextLevel() product, _ = hallstore.findProductByContains(gameId, uid, clientId, ['coin'], None, hallitem.ASSET_CHIP_KIND_ID, delta_exp * 1000) pay_order = TodoTaskPayOrder(product) if user_vip == 0: msg = '点赞次数已达今日上限,开通VIP可提高点赞次数上限获得更多福利哦~' btnTxt = '开通VIP' else: msg = '点赞次数已达今日上限,升级VIP等级可提高点赞次数上限获得更多福利哦~' btnTxt = '升级VIP' dialog_task = TodoTaskShowInfo(msg, True) dialog_task.setSubCmd(pay_order) dialog_task.setSubText(btnTxt) TodoTaskHelper.sendTodoTask(gameId, uid, [dialog_task])
def processEnterGame(cls, evt): # # 检查当前已结束赛季并发放赛季奖励, 只发放上一期的 if ftlog.is_debug(): ftlog.debug('============= processEnterGame userId=', evt.userId) _, intClientId = sessiondata.getClientIdNum(evt.userId) if intClientId == 24105: latestTwoIssues = SegmentMatchHelper.getIssueStateList()[-2:] for issuestate in reversed(latestTwoIssues): if issuestate['state'] == 0: continue # 判断用户有没有结算此赛季 userData = SegmentMatchHelper.getUserSegmentDataIssue( evt.userId, issuestate['issue']) or UserSegmentDataIssue() if userData and userData.segmentRewardsState == UserSegmentDataIssue.IDEAL: # 结算 发奖 settlementRanking(evt.userId, issuestate['issue']) segmentConf = getSegmentConf() if segmentConf.closed: return if evt.dayFirst: # 检查用户是否已经发送 if not gamedata.getGameAttrInt(evt.userId, DIZHU_GAMEID, 'wxNotice'): # 保存消息记录 gamedata.setGameAttr(evt.userId, DIZHU_GAMEID, 'wxNotice', 1) # 新用户发送一条额外消息 mailstr = '游戏公告#如有任何意见建议,欢迎加客服微信:Tuyoo_taozi,进入官方群反馈' message.send(DIZHU_GAMEID, message.MESSAGE_TYPE_SYSTEM, evt.userId, mailstr) # 同步钻石为用户道具 if not segmentdata.getSegmentAttr(evt.userId, DIZHU_GAMEID, 'diamondConvert'): segmentdata.setSegmentAttr(evt.userId, DIZHU_GAMEID, 'diamondConvert', 1) userDiamond = userdata.getAttr(evt.userId, 'diamond') if userDiamond: # count user_remote.consumeAssets(DIZHU_GAMEID, evt.userId, [{ 'itemId': 'user:diamond', 'count': userDiamond }], 'DIZHU_SEGMENT_DIAMOND_CONVERT', 0) contentItems = TYContentItem.decodeList([{ 'itemId': 'item:1311', 'count': userDiamond }]) from dizhu.entity import dizhu_util dizhu_util.sendRewardItems(evt.userId, contentItems, None, 'DIZHU_SEGMENT_DIAMOND_CONVERT', 0) ftlog.info('DizhuSegmentRewardsHelper diamondConvert userId=', evt.userId, 'userDiamond=', userDiamond)
def sendRewards(self, userId, gameId, clientId): bSend = True for cond in self.conditions: if not cond.check(gameId, userId, clientId, pktimestamp.getCurrentTimestamp()): bSend = False if bSend: from hall.entity import hallitem userAssets = hallitem.itemSystem.loadUserAssets(userId) assetList = userAssets.sendContent( gameId, self.items, 1, True, pktimestamp.getCurrentTimestamp(), 'LOGIN_REWARD', 0) if assetList: if ftlog.is_debug(): ftlog.debug('hall_login_reward.sendReward gameId=', gameId, 'userId=', userId, 'rewards=', [(atup[0].kindId, atup[1]) for atup in assetList]) # 记录登录奖励获取时间 gamedata.setGameAttr(userId, HALL_GAMEID, 'login_reward', pktimestamp.getCurrentTimestamp()) # 通知更新 changedDataNames = TYAssetUtils.getChangeDataNames(assetList) datachangenotify.sendDataChangeNotify(gameId, userId, changedDataNames) pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, self.mail) from poker.util import strutil _, cVer, _ = strutil.parseClientId(clientId) if cVer < 3.90: TodoTaskHelper.sendTodoTask( gameId, userId, TodoTaskShowInfo(self.mail, True)) else: rewardsList = [] for assetItemTuple in assetList: ''' 0 - assetItem 1 - count 2 - final ''' assetItem = assetItemTuple[0] reward = {} reward['name'] = assetItem.displayName reward['pic'] = assetItem.pic reward['count'] = assetItemTuple[1] rewardsList.append(reward) if ftlog.is_debug(): ftlog.debug( 'hall_login_reward.TodoTaskShowRewards rewardsList: ', rewardsList) TodoTaskHelper.sendTodoTask( gameId, userId, TodoTaskShowRewards(rewardsList))
def exchangeCouponItem(self, userId, couponId, **kwargs): couponItem = self.findCouponItem(couponId) if not couponItem: if ftlog.is_debug(): ftlog.debug('CouponService.exchangeCouponItem userId=', userId, 'couponId=', couponId, 'kwargs=', kwargs, 'gameId=', self.gameId, 'coupons=', self._couponItemMap.keys()) raise TYBizException(-1, 'Not found couponId %s' % (couponId)) if (couponItem.itemType == CouponItem.TYPE_PHONE_CARD and not kwargs.get('phone')): # 检查chargePhone参数 raise TYBizException(-1, 'Please input phone number') # 减奖券 trueDelta, final = pkuserchip.incrCoupon(userId, self.gameId, -couponItem.couponCount, pkdaoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 0, 0, 0) if -trueDelta < couponItem.couponCount: raise TYBizException(-1, 'Coupon not enough') if couponItem.itemType == CouponItem.TYPE_PHONE_CARD: phone = kwargs.get('phone') isCtyOk = sdkclient.couponCharge(self.gameId, userId, phone, '', '', couponItem.couponCount, couponItem.itemCount) if isCtyOk: mail = couponItem.mailOk else: mail = couponItem.mailFail if mail: mail = strutil.replaceParams(mail, { 'couponCount': str(couponItem.couponCount), 'itemCount': str(couponItem.itemCount), 'itemName': couponItem.itemName, 'phone': phone, 'qqGroup': self._qqGroup }) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') elif couponItem.itemType == CouponItem.TYPE_ID_CHIP: pkuserchip.incrChip(userId, self.gameId, couponItem.itemCount, pkdaoconst.CHIP_NOT_ENOUGH_OP_MODE_NONE, 0, 0, 0) mail = couponItem.mailOk if mail: mail = strutil.replaceParams(mail, { 'couponCount': str(couponItem.couponCount), 'itemCount': str(couponItem.itemCount), 'itemName': couponItem.itemName, 'qqGroup': self._qqGroup }) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') return trueDelta, final
def presentItemByUnitsCount(gameId, userId, fromUserId, kindId, count, receiveMail): itemKind = hallitem.itemSystem.findItemKind(kindId) if not itemKind: return False userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() userBag.addItemUnitsByKind(gameId, itemKind, count, pktimestamp.getCurrentTimestamp(), fromUserId, 'ACCEPT_PRESENT_ITEM', fromUserId) if receiveMail: pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, receiveMail) datachangenotify.sendDataChangeNotify(gameId, userId, 'item') return True
def doGetInviteReward(self, gameId, userId, inviteeId, clientId): """ 获取推荐人奖励 作为上线奖励 """ if (not inviteeId) or (inviteeId <= 0): TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo('请输入推荐人ID', True)) return try: status = hall_simple_invite.loadStatus(userId) inviteeInvitation = status.findInvitee(inviteeId) if not inviteeInvitation: TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo('没有推荐此人,请重新领取', True)) return if inviteeInvitation.inviterState == Invitation.STATE_REWARDED: TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo('已经领取推荐奖励', True)) return inviteeInvitation.inviterState = Invitation.STATE_REWARDED hall_simple_invite.saveStatus(status) ftlog.info('doGetInviteReward userId=', status.userId, 'invitee=', inviteeId) mo = MsgPack() mo.setCmd('invite_info') mo.setResult('action', 'get_invite_reward') mo.setResult('gameId', gameId) _, rCounts = self.getInviteesRewardInfo(status, Invitation.STATE_REWARDED, clientId) count = self.getTotalReward(status, userId, gameId, clientId) rObj = hall_simple_invite.getSimpleInviteRewardByIndex(userId, gameId, rCounts, clientId) if rObj: mo.setResult('totalReward', count) self.addUserItemByKindId(userId, gameId, clientId, rObj.assetKindId, rObj.count) userInfo = {} userInfo['userId'] = inviteeId userInfo['rewardState'] = inviteeInvitation.inviterState mo.setResult('updateInfo', userInfo) router.sendToUser(mo, userId) # 給userId补发一个系统消息 inviteeName, _ = self.getUserNameAndPic(inviteeId) inviteRewardDesc = hall_simple_invite.getSimpleInviteRewardDescByIndex(userId, gameId, rCounts, clientId) if inviteRewardDesc: pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, inviteeName + '通过您的分享登录斗地主游戏,您获得' + inviteRewardDesc) except TYBizException, e: TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskShowInfo(e.message, True))
def sendOldUserPrize(cls, userId, friendId, gameId, conf): prize = conf.get('prize', {}) prizeGet = {"CHIP": 0, "COUPON": 0} getprize = cls.getFriendListPrize(userId, friendId, gameId) if getprize == [0, 0]: return prizeGet cls.sendSingleOldUserPrize(userId, gameId, getprize[0] * prize["CHIP"], getprize[1] * prize["COUPON"]) prizeGet["CHIP"] = getprize[0] * prize["CHIP"] prizeGet["COUPON"] = getprize[1] * prize["COUPON"] message.send(gameId, message.MESSAGE_TYPE_SYSTEM, userId, cls.message(prizeGet)) return prizeGet
def sendBothUserPrize2(cls, gameId, userId, friendId, conf): prize = conf.get('prize', {}) friendnum = user_remote.addfriend(friendId, userId, gameId, prize) # rpc!!! prizeGet = {"CHIP": 0} if friendnum != -1: prizeGet = {"CHIP": prize["CHIP"]} userchip.incrChip(userId, gameId, prize["CHIP"], daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'ACTIVITY_REWARD', 0, None) cls.updateNotify(gameId, userId, 'chip') message.send(gameId, message.MESSAGE_TYPE_SYSTEM, userId, cls.message(prizeGet)) return prizeGet
def onUserLogin(self, event): if not self._mailWhenCanExchange: return _, clientVer, _ = strutil.parseClientId(event.clientId) if clientVer < 3.0: return if not event.dayFirst or event.gameId != HALL_GAMEID: return couponItem = self.findMinCouponItem([CouponItem.TYPE_PHONE_CARD]) if not couponItem: return userCouponCount = pkuserchip.getCoupon(event.userId) if userCouponCount >= couponItem.couponCount: pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, event.userId, self._mailWhenCanExchange) datachangenotify.sendDataChangeNotify(self.gameId, event.userId, 'message')
def handleExchangeAuditResult(userId, exchangeId, result): ''' 处理审核结果 ''' record = loadRecord(userId, exchangeId) if not record: raise TYUnknownExchangeOrder() if record.state != TYExchangeRecord.STATE_AUDIT: raise TYBadStateExchangeOrder() userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() item = userBag.findItem(record.itemId) if not isinstance(item, TYExchangeItem): raise TYBizException(-1, '系统错误') if item.state != TYExchangeItem.STATE_AUDIT: raise TYBizException(-1, '道具状态错误') ftlog.debug('hallexchange.handleExchangeAuditResult userId=', userId, 'exchangeId=', exchangeId, 'result=', result) timestamp = pktimestamp.getCurrentTimestamp() if result == RESULT_OK: record.state = TYExchangeRecord.STATE_ACCEPT userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) else: record.state = TYExchangeRecord.STATE_REJECT if result == RESULT_REJECT_RETURN: item.state = TYExchangeItem.STATE_NORMAL userBag.updateItem(HALL_GAMEID, item, timestamp) else: userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) itemDisPlayName = item.itemKind.displayName exchangeDesc = record.params.get("desc", '') if result == RESULT_OK: mail = "您申请用%s兑换(领取)%s,已成功为您办理,请查收。" % (itemDisPlayName, exchangeDesc) else: mail = "您申请用%s兑换(领取)%s,审核未通过,抱歉。" % (itemDisPlayName, exchangeDesc) ftlog.debug("handleExchangeAuditResult,mail:", mail) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) return record
def sendRewardItems(userId, items, mail, eventId, eventParam, **kwargs): userAssets = hallitem.itemSystem.loadUserAssets(userId) assetList = userAssets.sendContentItemList( DIZHU_GAMEID, items, 1, True, pktimestamp.getCurrentTimestamp(), eventId, eventParam) changeNames = TYAssetUtils.getChangeDataNames(assetList) contents = TYAssetUtils.buildContentsString(assetList) if mail: replaceDict = {'rewardContent': contents} replaceDict.update(kwargs) mailstr = strutil.replaceParams(mail, replaceDict) mailstr = mailstr.replace('红包券', '元红包') message.send(DIZHU_GAMEID, message.MESSAGE_TYPE_SYSTEM, userId, mailstr) changeNames.add('message') datachangenotify.sendDataChangeNotify(DIZHU_GAMEID, userId, changeNames) return assetList
def on_bind_inviter(userId, clientId, inviterCode): """处理玩家绑定代理邀请码的请求""" ftlog.debug("on_bind_inviter <<|userId, clientId, inviterCode:", userId, clientId, inviterCode) conf = _get_conf_by_client_id(clientId) card_type = conf['itemId'] url = conf['url'] ret_code, ret_msg = _http_bind(url, card_type, userId, inviterCode) ftlog.debug("on_bind_inviter |userId, clientId, inviterCode:", userId, clientId, inviterCode, "| ret_code, ret_msg:", ret_code, ret_msg) mo = MsgPack() mo.setCmd('bind_inviter') if ret_code == 1: # 绑定代理商邀请码后赠送房卡 giftTips = '' giftItemNum = conf.get('giftItemNumOnBind', 0) if giftItemNum > 0: from hall.entity import hallitem, datachangenotify assetKindId = 'item:%s' % card_type userAssets = hallitem.itemSystem.loadUserAssets(userId) userAssets.addAsset(HALL_GAMEID, assetKindId, giftItemNum, pktimestamp.getCurrentTimestamp(), 'BIND_AGENT_GIFT', 0) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'item') giftTips = ',并赠送给您%s张房卡' % giftItemNum tips = '您已成功绑定邀请码为%s的代理%s。' % (inviterCode, giftTips) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, tips, 0) gamedata.setGameAttr(HALL_GAMEID, userId, 'inviter_code', inviterCode) mo.setResult('bound', True) mo.setResult('tips', tips) router.sendToUser(mo, userId) _goto_shop(userId) else: mo.setResult('bound', False) mo.setResult('tips', ret_msg) router.sendToUser(mo, userId)
def dosendBindIDChipToUser(self, userId, gameId, clientId): # 添加绑定 nowBindID = gamedata.getGameAttr(userId, gameId, 'bindIDReward') if not nowBindID or nowBindID < 1: gamedata.setGameAttr(userId, gameId, 'bindIDReward', 1) else: from poker.entity.biz.exceptions import TYBizException raise TYBizException(-1, '重复绑定') ftlog.info('cmd game action bindIDCard userId =', userId) day2Kind = hallitem.itemSystem.findItemKind(hallitem.ITEM_HERO_KIND_ID) userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() timestamp = pktimestamp.getCurrentTimestamp() userBag.addItemUnitsByKind(gameId, day2Kind, 1, timestamp, 0, 'BIND_PHONE', 0) datachangenotify.sendDataChangeNotify(gameId, userId, 'item') # 消息推送 from poker.entity.biz.message import message msg = '恭喜您绑定身份证成功,赠送您1张英雄帖' message.send(gameId, message.MESSAGE_TYPE_PRIVATE, userId, msg)
def gainCheckinReward(self, gameId, userId, timestamp=None, actionType=0): if timestamp is None: timestamp = pktimestamp.getCurrentTimestamp() checkinOk, checkinDays = self.checkin(gameId, userId, timestamp) if ftlog.is_debug(): ftlog.debug( 'TYDailyCheckin.gainCheckinReward gameId=', gameId, 'userId=', userId, 'timestamp=', datetime.fromtimestamp(timestamp).strftime( '%Y-%m-%d %H:%M:%S'), 'checkinOk=', checkinOk, 'checkinDays=', checkinDays) if not checkinOk: return checkinOk, [], checkinDays # 发送奖励 rewardContent = self.getRewardContent(checkinDays) ebus = TGHall.getEventBus() ebus.publishEvent( TYDailyCheckinRewardEvent(gameId, userId, rewardContent, actionType)) if not rewardContent: return checkinOk, [], checkinDays userAssets = hallitem.itemSystem.loadUserAssets(userId) assetList = userAssets.sendContent(gameId, rewardContent, 1, True, timestamp, 'NSLOGIN_REWARD2', checkinDays) contents = TYAssetUtils.buildContentsString(assetList) if self._mail: mail = strutil.replaceParams(self._mail, {'rewardContent': contents}) pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(gameId, userId, 'message') ftlog.debug( 'TYDailyCheckin.gainCheckinReward gameId=', gameId, 'userId=', userId, 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'reward=', contents) return checkinOk, assetList, checkinDays
def presentItem(gameId, userId, fromUserId, itemDataDict, receiveMail): kindId = itemDataDict['itemKindId'] itemKind = hallitem.itemSystem.findItemKind(kindId) if not itemKind: return False itemData = itemKind.newItemData() itemData = itemData.fromDict(itemDataDict) item = hallitem.itemSystem.newItemFromItemData(itemData) if not item: return False item.fromUserId = fromUserId item.giftHandCount += 1 timestamp = pktimestamp.getCurrentTimestamp() userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() userBag.addItem(gameId, item, timestamp, 'ACCEPT_PRESENT_ITEM', fromUserId) if receiveMail: pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, receiveMail) datachangenotify.sendDataChangeNotify(gameId, userId, 'item') return True
def dosendChipToUser(self, userId, gameId, clientId): # 添加绑定 nowBindPone = gamedata.getGameAttr(userId, gameId, 'bindReward1') if not nowBindPone or nowBindPone < 1: gamedata.setGameAttr(userId, gameId, 'bindReward1', 1) else: from poker.entity.biz.exceptions import TYBizException raise TYBizException(-1, '重复绑定') # 发金币 ftlog.info('cmd game action bindPhone userId =', userId) from poker.entity.dao import userchip, daoconst userchip.incrChip(userId, gameId, 10000, daoconst.CHIP_NOT_ENOUGH_OP_MODE_CLEAR_ZERO, 'BIND_PHONE', 0, clientId) datachangenotify.sendDataChangeNotify(gameId, userId, 'chip') # 消息推送 from poker.entity.biz.message import message msg = '恭喜您绑定手机成功,赠送您10000金币' message.send(gameId, message.MESSAGE_TYPE_PRIVATE, userId, msg) # 更新小红点 datachangenotify.sendDataChangeNotify(gameId, userId, ['free', 'promotion_loc']) TGHall.getEventBus().publishEvent(UserBindPhoneEvent(userId, gameId))
def doGetFirstRechargeReward(self, gameId, userId, clientId): if not hallstore.isFirstRecharged(userId): mo = MsgPack() mo.setCmd('get_first_recharge') mo.setError(-1, '你还没有首充!') router.sendToUser(mo, userId) return if not hallstore.setFirstRechargeReward(userId): mo = MsgPack() mo.setCmd('get_first_recharge') mo.setError(-1, '您已经领取了!') router.sendToUser(mo, userId) return timestamp = pktimestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userId) itemKindId = hall_first_recharge.queryFirstRecharge( gameId, userId, clientId) assetKindId = hallitem.itemIdToAssetId(itemKindId) balance = userAssets.balance(gameId, assetKindId, timestamp) if balance <= 0: userAssets.addAsset(gameId, assetKindId, 1, timestamp, 'FIRST_RECHARGE', 0) ftlog.info('SotreTcpHandler.doGetFirstRechargeReward gameId=', gameId, 'userId=', userId, 'itemId=', itemKindId) userBag = userAssets.getUserBag() item = userBag.getItemByKindId(itemKindId) if item: try: userBag.doAction(gameId, item, 'open', timestamp) except: ftlog.error( 'SotreTcpHandler.doGetFirstRechargeReward gameId=', gameId, 'userId=', userId, 'itemId=', itemKindId) pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_PRIVATE, userId, '恭喜您获得首充豪华大礼包奖励!') datachangenotify.sendDataChangeNotify(gameId, userId, ['item', 'promotion_loc'])
def handleShippingResultItem(userId, record, result): userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() item = userBag.findItem(record.itemId) if not isinstance(item, TYExchangeItem): raise TYBizException(-1, '系统错误') if item.state != TYExchangeItem.STATE_SHIPPING: raise TYBizException(-1, '道具状态错误') timestamp = pktimestamp.getCurrentTimestamp() if result == RESULT_OK: record.state = TYExchangeRecord.STATE_SHIPPING_SUCC userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) elif result == RESULT_SHIPPINGFAIL_RETURN: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL_RETURN item.state = TYExchangeItem.STATE_NORMAL userBag.updateItem(HALL_GAMEID, item, timestamp) elif result == RESULT_SHIPPINGFAIL: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) else: assert (0) itemDisPlayName = item.itemKind.displayName exchangeDesc = record.params.get('desc', '') if result == RESULT_OK: mail = '您申请用%s兑换(领取)%s,已成功为您办理,请查收。' % (itemDisPlayName, exchangeDesc) else: mail = '您申请用%s兑换(领取)%s,审核未通过,抱歉。' % (itemDisPlayName, exchangeDesc) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') if result == RESULT_OK: sendShareForWXRedEnvelope(userId, record, item)
def doGetFirstRechargeReward(self, gameId, userId, clientId): if not hallstore.isFirstRecharged(userId): mo = MsgPack() mo.setCmd('get_first_recharge') mo.setError(-1, '你还没有首充!') router.sendToUser(mo, userId) return if not hallstore.setFirstRechargeReward(userId): mo = MsgPack() mo.setCmd('get_first_recharge') mo.setError(-1, '您已经领取了!') router.sendToUser(mo, userId) return timestamp = pktimestamp.getCurrentTimestamp() userAssets = hallitem.itemSystem.loadUserAssets(userId) itemKindId = hall_first_recharge.queryFirstRecharge(gameId, userId, clientId) assetKindId = hallitem.itemIdToAssetId(itemKindId) balance = userAssets.balance(gameId, assetKindId, timestamp) if balance <= 0: userAssets.addAsset(gameId, assetKindId, 1, timestamp, 'FIRST_RECHARGE', 0) ftlog.info('SotreTcpHandler.doGetFirstRechargeReward gameId=', gameId, 'userId=', userId, 'itemId=', itemKindId) userBag = userAssets.getUserBag() item = userBag.getItemByKindId(itemKindId) if item: try: userBag.doAction(gameId, item, 'open', timestamp) except: ftlog.error('SotreTcpHandler.doGetFirstRechargeReward gameId=', gameId, 'userId=', userId, 'itemId=', itemKindId) pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_PRIVATE, userId, '恭喜您获得首充豪华大礼包奖励!') datachangenotify.sendDataChangeNotify(gameId, userId, ['item', 'promotion_loc'])
def on_accept_friend(cls, gameId, uid, clientId, mo): code = mo.getResult('code', 0) if code != 0: return # red dot friend_uid = mo.getResult('friend_uid', None) if not friend_uid: return friend_uids = friend_uid.split(',') nick_name = mo.getResult('nick_name', '') is_agree = int(mo.getResult('is_agree', 0)) if is_agree == 0: return msg = '恭喜您和"' + nick_name + '"成为好友' ftlog.debug('on_accept_friend.... ' + msg) from poker.entity.biz.message import message message.send(gameId, message.MESSAGE_TYPE_SYSTEM, int(friend_uid), msg) from hall.entity import hallmoduletip ftlog.debug('on_accept_friend', friend_uids) for fid in friend_uids: hallmoduletip.sendModuleTipEvent(int(fid), gameId, "friends", 1)
def __getReward(self, rdskey, userId, gameId, actId, excode): config_ = daobase.executeMixCmd('HGET', 'excodeinfo:' + rdskey, 'rewards') try: config_ = json.loads(config_) except: return {} if not isinstance(config_, list): return {} rewards = {} items_ = config_ ftlog.debug('ExchangeCode.__getReward', 'items=', items_) from hall.entity.hallitem import itemSystem userAssets = itemSystem.loadUserAssets(userId) assetTupleList = [] for itemDict in items_: for assetKindId, count in itemDict.iteritems(): count = int(count) if assetKindId in self._rewardMap: assetKindId = self._rewardMap[assetKindId]['itemId'] assetTuple = userAssets.addAsset(gameId, assetKindId, count, int(time.time()), 'ACTIVITY_EXCHANGE', 0) rewards[assetKindId] = count assetTupleList.append(assetTuple) datachangenotify.sendDataChangeNotify(gameId, userId, TYAssetUtils.getChangeDataNames(assetTupleList)) ftlog.info('ExchangeCode->__statistics userid=', userId, 'excode=', excode, 'rewards=', rewards) msg = '兑换码兑换礼品成功,已自动加入到您的背包中,请查收。' message.send(9999, message.MESSAGE_TYPE_SYSTEM, userId, msg) result = TYAssetUtils.buildContentsString(assetTupleList) ftlog.debug('the last msg is result', result) return result
def get_award(self, uid): if not self.checkOperative(): return 'acitivity expired!' actkey = ACTIVITY_KEY.format(HALL_GAMEID, uid, self.getid()) weekcnt, daycnt = self._get_click_cnt(uid, actkey) if weekcnt >= self._clientConf['config']['weeklimit'] or daycnt >= self._clientConf['config']['daylimit']: return 'awardcnt:({},{}) expand limitcnt!'.format(weekcnt, daycnt) shareid = self._serverConf["share"] share = hallshare.findShare(shareid) if not share: return 'share:{} not exist!'.format(shareid) daobase.executeUserCmd(uid, 'HINCRBY', actkey, self.FIELD_DAY_CNT, 1) daobase.executeUserCmd(uid, 'HINCRBY', actkey, self.FIELD_WEEK_CNT, 1) daobase.executeUserCmd(uid, 'HINCRBY', actkey, self.FIELD_TOTAL_CNT, 1) hallshare.sendReward(HALL_GAMEID, uid, share, 'share_click') # 分享BI日志汇报 clientid = sessiondata.getClientId(uid) bireport.reportGameEvent('SHARE_CALLBACK', uid, HALL_GAMEID, shareid, 0, 0, 0, 0, 0, [], clientid) if share.mail: message.send(HALL_GAMEID, message.MESSAGE_TYPE_SYSTEM, uid, share.mail) return 'ok'
def gainCheckinReward(self, gameId, userId, timestamp=None, actionType=0): if timestamp is None: timestamp = pktimestamp.getCurrentTimestamp() checkinOk, checkinDays = self.checkin(gameId, userId, timestamp) if ftlog.is_debug(): ftlog.debug('TYDailyCheckin.gainCheckinReward gameId=', gameId, 'userId=', userId, 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'checkinOk=', checkinOk, 'checkinDays=', checkinDays) if not checkinOk: return checkinOk, [], checkinDays # 发送奖励 rewardContent = self.getRewardContent(checkinDays) ebus = TGHall.getEventBus() ebus.publishEvent(TYDailyCheckinRewardEvent(gameId, userId, rewardContent, actionType)) if not rewardContent: return checkinOk, [], checkinDays userAssets = hallitem.itemSystem.loadUserAssets(userId) assetList = userAssets.sendContent(gameId, rewardContent, 1, True, timestamp, 'NSLOGIN_REWARD2', checkinDays) contents = TYAssetUtils.buildContentsString(assetList) if self._mail: mail = strutil.replaceParams(self._mail, {'rewardContent': contents}) pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(gameId, userId, 'message') ftlog.debug('TYDailyCheckin.gainCheckinReward gameId=', gameId, 'userId=', userId, 'timestamp=', datetime.fromtimestamp(timestamp).strftime('%Y-%m-%d %H:%M:%S'), 'reward=', contents) return checkinOk, assetList, checkinDays
def _sendTaskReward(self, task, timestamp, eventId, intEventParam): if task.taskKind.rewardContent: userAssets = hallitem.itemSystem.loadUserAssets( task.userTaskUnit.userId) assetList = userAssets.sendContent(self.gameId, task.taskKind.rewardContent, 1, True, timestamp, eventId, intEventParam) changeNames = TYAssetUtils.getChangeDataNames(assetList) rewardMail = task.taskKind.rewardMail if rewardMail: contents = TYAssetUtils.buildContentsString(assetList) rewardMail = strutil.replaceParams( rewardMail, { 'rewardContent': contents, 'taskName': task.taskKind.name }) message.send(self.gameId, message.MESSAGE_TYPE_SYSTEM, task.userId, rewardMail) changeNames.add('message') datachangenotify.sendDataChangeNotify(self.gameId, task.userId, changeNames) return assetList return []
def handleAuditResultItem(userId, record, result): userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() item = userBag.findItem(record.itemId) timestamp = pktimestamp.getCurrentTimestamp() if not isinstance(item, TYExchangeItem): raise TYBizException(-1, '系统错误') if item.state != TYExchangeItem.STATE_AUDIT: raise TYBizException(-1, '道具状态错误') if result == RESULT_AUDITSUCC: item.state = TYExchangeItem.STATE_SHIPPING record.state = TYExchangeRecord.STATE_ACCEPT userBag.updateItem(HALL_GAMEID, item, timestamp) elif result == RESULT_REJECT: record.state = TYExchangeRecord.STATE_REJECT userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) elif result == RESULT_REJECT_RETURN: record.state = TYExchangeRecord.STATE_REJECT_RETURN item.state = TYExchangeItem.STATE_NORMAL userBag.updateItem(HALL_GAMEID, item, timestamp) else: assert (0) itemDisPlayName = item.itemKind.displayName exchangeDesc = record.params.get('desc', '') if result == RESULT_REJECT or result == RESULT_REJECT_RETURN: mail = '您申请用%s兑换(领取)%s,审核未通过,抱歉。' % (itemDisPlayName, exchangeDesc) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') return record
def send_todotask(gameid, typeid, clientid, userId, text, d, duration=0, fromuid=None, **todotask_kwarg): todo_task = hallpopwnd.decodeTodotaskFactoryByDict(d).newTodoTask(gameid, userId, clientid, **todotask_kwarg) attach = AttachmentTodoTask(todo_task, duration) message.send(gameid, typeid, userId, text, fromuid, attach)
def send_asset(gameid, typeid, userId, text, d, fromuid=None): attach = AttachmentAsset() attach.unmarshal(d) message.send(gameid, typeid, userId, text, fromuid, attach)
def send(gameid, typeid, userId, text, fromuid=None): message.send(gameid, typeid, userId, text, fromuid)
def on_praise_friend(cls, gameId, uid, clientId, mo): code = mo.getResult('code', 0) # vip = mo.getResult('vip') if code == 0: friend_uid = int(mo.getResult('friend_uid')) nick_name = mo.getResult('nick_name') friend_nick_name = mo.getResult('friend_nick_name') my_add_charm = mo.getResult('my_add_charm') friend_add_charm = mo.getResult('friend_add_charm') my_charm = mo.getResult('my_charm') friend_charm = mo.getResult('friend_charm') msg1 = '给"' + friend_nick_name + '"点赞获得' + str( my_add_charm) + '个魅力值' msg2 = '"' + nick_name + '"给您点赞获得' + str(friend_add_charm) + '个魅力值' from poker.entity.biz.message import message message.send(gameId, message.MESSAGE_TYPE_SYSTEM, int(uid), msg1) message.send(gameId, message.MESSAGE_TYPE_SYSTEM, int(friend_uid), msg2) ftlog.debug('on praise friend.... ' + msg1) ftlog.debug('on praise friend.... ' + msg2) datachangenotify.sendDataChangeNotify(gameId, uid, 'charm') from hall.entity.hallranking import rankingSystem, TYRankingInputTypes timestamp = pktimestamp.getCurrentTimestamp() rankingSystem.setUserByInputType(gameId, TYRankingInputTypes.CHARM, uid, my_charm, timestamp) rankingSystem.setUserByInputType(gameId, TYRankingInputTypes.CHARM, friend_uid, friend_charm, timestamp) # 历史获赞次数 history_praised_num = gamedata.incrGameAttr( friend_uid, gameId, 'history_praised_num', 1) mo.setResult('friend_history_praised_num', history_praised_num) if code != 2: return from hall.entity.todotask import TodoTaskPayOrder, TodoTaskShowInfo from hall.entity.todotask import TodoTaskHelper from hall.entity import hallvip, hallitem user_vip = hallvip.userVipSystem.getUserVip(uid) delta_exp = user_vip.deltaExpToNextLevel() product, _ = hallstore.findProductByContains( gameId, uid, clientId, ['coin'], None, hallitem.ASSET_CHIP_KIND_ID, delta_exp * 1000) pay_order = TodoTaskPayOrder(product) if user_vip == 0: msg = '点赞次数已达今日上限,开通VIP可提高点赞次数上限获得更多福利哦~' btnTxt = '开通VIP' else: msg = '点赞次数已达今日上限,升级VIP等级可提高点赞次数上限获得更多福利哦~' btnTxt = '升级VIP' dialog_task = TodoTaskShowInfo(msg, True) dialog_task.setSubCmd(pay_order) dialog_task.setSubText(btnTxt) TodoTaskHelper.sendTodoTask(gameId, uid, [dialog_task])
def _onOrderDelivery(event): from hall.entity import hallitem nowDT = datetime.now() order = event.orderDeliveryResult.order if ((_conf.startDT and nowDT < _conf.startDT) or (_conf.endDT and nowDT >= _conf.endDT)): if ftlog.is_debug(): ftlog.debug('buy_send_gift._onOrderDelivery outofTime userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'nowDT=', nowDT.strftime('%Y-%m-%d %H:%M:%S'), 'startDT=', _conf.startDT.strftime('%Y-%m-%d %H:%M:%S'), 'endDT=', _conf.endDT.strftime('%Y-%m-%d %H:%M:%S')) return giftConf = _conf.findGiftConf(order.productId) if not giftConf: if ftlog.is_debug(): ftlog.debug('buy_send_gift._onOrderDelivery noGiftConf userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'orderClientId=', order.clientId) return hallGameId = strutil.getGameIdFromHallClientId(order.clientId) if hallGameId not in giftConf.gameIds: if ftlog.is_debug(): ftlog.debug('buy_send_gift._onOrderDelivery notInGameIds userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'giftConf=', giftConf.conf, 'orderClientId=', order.clientId, 'hallGameId=', hallGameId, 'gameIds=', giftConf.gameIds) return count = 0 if giftConf.maxCount >= 0: limitD = gamedata.getGameAttrJson(order.userId, hallGameId, 'act.buy_send_gift', {}) count = limitD.get(order.productId, 0) if count + 1 > giftConf.maxCount: ftlog.info('buy_send_gift._onOrderDelivery overLimit userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'giftConf=', giftConf.conf if giftConf else None, 'orderClientId=', order.clientId, 'count=', count, 'maxCount=', giftConf.maxCount) return count += 1 limitD[order.productId] = count gamedata.setGameAttr(order.userId, hallGameId, 'act.buy_send_gift', strutil.dumps(limitD)) assetList = None if giftConf.giftContent: userAssets = hallitem.itemSystem.loadUserAssets(order.userId) # def sendContent(self, gameId, content, count, ignoreUnknown, timestamp, eventId, intEventParam): assetList = userAssets.sendContent(hallGameId, giftConf.giftContent, 1, True, pktimestamp.getCurrentTimestamp(), 'ACTIVITY_REWARD', 10043) changedDataNames = TYAssetUtils.getChangeDataNames(assetList) if assetList else set() contentStr = TYAssetUtils.buildContentsString(assetList) if assetList else '' if giftConf.mail: mail = strutil.replaceParams(giftConf.mail, {'gotContent': contentStr, 'price': order.product.price}) message.send(hallGameId, message.MESSAGE_TYPE_SYSTEM, order.userId, mail) changedDataNames.add('message') if changedDataNames: datachangenotify.sendDataChangeNotify(HALL_GAMEID, order.userId, changedDataNames) ftlog.info('buy_send_gift._onOrderDelivery sendGift userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'giftConf=', giftConf.conf if giftConf else None, 'orderClientId=', order.clientId, 'count=', count, 'maxCount=', giftConf.maxCount, 'assetList=', [(a[0].kindId, a[1]) for a in assetList] if assetList else None)
def _onOrderDelivery(event): from hall.entity import hallitem nowDT = datetime.now() order = event.orderDeliveryResult.order if ((_conf.startDT and nowDT < _conf.startDT) or (_conf.endDT and nowDT >= _conf.endDT)): if ftlog.is_debug(): ftlog.debug('buy_send_gift._onOrderDelivery outofTime userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'nowDT=', nowDT.strftime('%Y-%m-%d %H:%M:%S'), 'startDT=', _conf.startDT.strftime('%Y-%m-%d %H:%M:%S'), 'endDT=', _conf.endDT.strftime('%Y-%m-%d %H:%M:%S')) return giftConf = _conf.findGiftConf(order.productId) if not giftConf: if ftlog.is_debug(): ftlog.debug('buy_send_gift._onOrderDelivery noGiftConf userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'orderClientId=', order.clientId) return hallGameId = strutil.getGameIdFromHallClientId(order.clientId) if hallGameId not in giftConf.gameIds: if ftlog.is_debug(): ftlog.debug('buy_send_gift._onOrderDelivery notInGameIds userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'giftConf=', giftConf.conf, 'orderClientId=', order.clientId, 'hallGameId=', hallGameId, 'gameIds=', giftConf.gameIds) return count = 0 if giftConf.maxCount >= 0: limitD = gamedata.getGameAttrJson(order.userId, hallGameId, 'act.buy_send_gift', {}) count = limitD.get(order.productId, 0) if count + 1 > giftConf.maxCount: ftlog.info('buy_send_gift._onOrderDelivery overLimit userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'giftConf=', giftConf.conf if giftConf else None, 'orderClientId=', order.clientId, 'count=', count, 'maxCount=', giftConf.maxCount) return count += 1 limitD[order.productId] = count gamedata.setGameAttr(order.userId, hallGameId, 'act.buy_send_gift', strutil.dumps(limitD)) assetList = None if giftConf.giftContent: userAssets = hallitem.itemSystem.loadUserAssets(order.userId) #def sendContent(self, gameId, content, count, ignoreUnknown, timestamp, eventId, intEventParam): assetList = userAssets.sendContent(hallGameId, giftConf.giftContent, 1, True, pktimestamp.getCurrentTimestamp(), 'ACTIVITY_REWARD', 10043) changedDataNames = TYAssetUtils.getChangeDataNames( assetList) if assetList else set() contentStr = TYAssetUtils.buildContentsString( assetList) if assetList else '' if giftConf.mail: mail = strutil.replaceParams(giftConf.mail, { 'gotContent': contentStr, 'price': order.product.price }) message.send(hallGameId, message.MESSAGE_TYPE_SYSTEM, order.userId, mail) changedDataNames.add('message') if changedDataNames: datachangenotify.sendDataChangeNotify(HALL_GAMEID, order.userId, changedDataNames) ftlog.info('buy_send_gift._onOrderDelivery sendGift userId=', event.userId, 'orderId=', order.orderId, 'productId=', order.productId, 'giftConf=', giftConf.conf if giftConf else None, 'orderClientId=', order.clientId, 'count=', count, 'maxCount=', giftConf.maxCount, 'assetList=', [(a[0].kindId, a[1]) for a in assetList] if assetList else None)
def getShareReward(gameId, userId, share, shareLoc, timestamp): ''' 给用户发放分享奖励 ''' # 分享BI日志汇报 clientId = sessiondata.getClientId(userId) bireport.reportGameEvent('SHARE_CALLBACK', userId, gameId, share.shareId, 0, 0, 0, 0, 0, [], clientId) # 记录分享次数 gamedata.incrGameAttr(userId, HALL_GAMEID, 'shareCount', 1) TGHall.getEventBus().publishEvent(HallShareEvent(gameId, userId, share.shareId, shareLoc)) # 首先处理 分享相关的通知 notifyInfoStr = pkgamedata.getGameAttr(userId, HALL_GAMEID, 'shareInfo') newInfo = {} pkgamedata.setGameAttr(userId, HALL_GAMEID, 'shareInfo', json.dumps(newInfo)) if notifyInfoStr: notifyInfo = json.loads(notifyInfoStr) shareId = notifyInfo.get('shareId', 0) if shareId == share.shareId: # 通知 info = notifyInfo.get('info', '') module = notifyInfo.get('module', '') if module == hall_red_envelope.TYRedEnvelope.EVENTID: hall_red_envelope.TYRedEnvelopeMgr.changeRedEnvelopeState(info, hall_red_envelope.TYRedEnvelope.STATE_SHARED) from poker.entity.game.game import TYGame clientId = sessiondata.getClientId(userId) gameids = hallconf.getDaShiFenFilter(clientId) for gid in gameids: TYGame(gid).sendTuyooRedEnvelopeCallBack(userId, clientId, info) # 分享奖励 ok, rewardCount = incrRewardCount(userId, share, timestamp) if not ok: if ftlog.is_debug(): ftlog.debug('hallshare.getShareReward already no share, check update share promote ...') ftlog.debug('hallshare.getShareReward fail gameId=', gameId, 'userId=', userId, 'shareId=', share.shareId, 'shareLoc=', shareLoc, 'rewardCount=', rewardCount, 'maxRewardCount=', share.maxRewardCount) return False assetList = sendReward(gameId, userId, share, shareLoc) if assetList and share.mail: TodoTaskHelper.sendTodoTask(gameId, userId, TodoTaskGoldRain(share.mail)) ftlog.debug('hallshare.getShareReward ok gameId=', gameId, 'userId=', userId, 'shareId=', share.shareId, 'shareLoc=', shareLoc, 'rewardCount=', rewardCount, 'maxRewardCount=', share.maxRewardCount, 'reward=', [(at[0].kindId, at[1]) for at in assetList] if assetList else []) if share.mail: pkmessage.send(gameId, pkmessage.MESSAGE_TYPE_SYSTEM, userId, share.mail) # udpate free & promotion_loc datachangenotify.sendDataChangeNotify(gameId, userId, ['free', 'promotion_loc']) return True
def handleShippingResult1(userId, exchangeId, result): ''' 发货结果处理 ''' if ftlog.is_debug(): ftlog.debug('enter handleShippingResult(), userId:', userId, 'exchangeId:', exchangeId, 'result:', result) record = loadRecord(userId, exchangeId) if not record: raise TYUnknownExchangeOrder() if record.state != TYExchangeRecord.STATE_ACCEPT: raise TYBadStateExchangeOrder() userBag = hallitem.itemSystem.loadUserAssets(userId).getUserBag() item = userBag.findItem(record.itemId) if not isinstance(item, TYExchangeItem): raise TYBizException(-1, '系统错误') if item.state != TYExchangeItem.STATE_SHIPPING: raise TYBizException(-1, '道具状态错误') timestamp = pktimestamp.getCurrentTimestamp() if result == RESULT_OK: record.state = TYExchangeRecord.STATE_SHIPPING_SUCC userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) elif result == RESULT_SHIPPINGFAIL_RETURN: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL_RETURN item.state = TYExchangeItem.STATE_NORMAL userBag.updateItem(HALL_GAMEID, item, timestamp) elif result == RESULT_SHIPPINGFAIL: record.state = TYExchangeRecord.STATE_SHIPPING_FAIL userBag.removeItem(HALL_GAMEID, item, timestamp, 'EXCHANGE', item.kindId) else: raise TYBizException(-1, '错误的请求状态') itemDisPlayName = item.itemKind.displayName exchangeDesc = record.params.get('desc', '') if result == RESULT_OK: mail = '您申请用%s兑换(领取)%s,已成功为您办理,请查收。' % (itemDisPlayName, exchangeDesc) else: mail = '您申请用%s兑换(领取)%s,审核未通过,抱歉。' % (itemDisPlayName, exchangeDesc) pkmessage.send(HALL_GAMEID, pkmessage.MESSAGE_TYPE_SYSTEM, userId, mail) datachangenotify.sendDataChangeNotify(HALL_GAMEID, userId, 'message') if result == RESULT_OK: action = item.itemKind.findActionByName('exchange') from hall.entity.hallitem import TYItemActionExchange if isinstance( action, TYItemActionExchange) and action.isWechatRedPack(): # 微信红包 from poker.util import strutil from poker.entity.dao import sessiondata clientId = sessiondata.getClientId(userId) _, cVer, _ = strutil.parseClientId(clientId) if cVer >= 3.90: from hall.entity import hallshare gameId = strutil.getGameIdFromHallClientId(clientId) shareId = hallshare.getShareId('wxRedEnvelope', userId, gameId) share = hallshare.findShare(shareId) if share: todotask = share.buildTodotask(HALL_GAMEID, userId, 'wxRedEnvelope') if todotask: from hall.entity.todotask import TodoTaskHelper TodoTaskHelper.sendTodoTask(gameId, userId, todotask) jstr = json.dumps(record.toDict()) _saveRecordData(userId, exchangeId, jstr) ftlog.info('hallexchange.handleShippingResult1', 'userId=', userId, 'exchangeId=', exchangeId, 'result=', result, 'itemId=', item.itemId, 'itemKindId=', item.kindId, 'orderState=', record.state) return record