package com.evt.mgr.handler;

import java.sql.SQLException;

import javax.xml.bind.annotation.XmlElementDecl.GLOBAL;

import com.data.bean.GroupBean;
import com.data.cache.GroupCache;
import com.data.cache.GroupMemberCache;
import com.data.util.ConsumeCode;
import com.data.util.CountUtil;
import com.data.util.Utility;
import com.evt.mgr.EventServer;
import com.evt.mgr.IHandler;
import com.taurus.core.entity.ITArray;
import com.taurus.core.entity.ITObject;
import com.taurus.core.entity.TArray;
import com.taurus.core.plugin.database.DataBase;
import com.taurus.core.plugin.redis.Redis;
import com.taurus.core.util.DateUtils;
import com.taurus.core.util.Logger;
import com.taurus.core.util.StringUtil;

import redis.clients.jedis.Jedis;
import redis.clients.jedis.Pipeline;

public class HandlerHpConsume implements IHandler {
	static Logger log = Logger.getLogger(HandlerHpConsume.class);
	final static String DB = "group1_db10";

	private static boolean hpConsume(int gid, int uid, int pid, int hp, int cur_hp, int reason, String roomid, int time,
			String desc) throws SQLException {
		String sql = String.format("{call sp_update_hp(%s,%s,%s,%s,%s,%s,'%s',%s,'%s')}", gid, uid, hp, cur_hp, reason,
				pid, roomid, time, desc);
		Utility.evtdb(gid, 2, sql);
		return false;
	}

	@Override
	public int process(int uid, ITObject param) throws Exception {
		return 0;
	}

	private void to_reward(Pipeline pipeline, int uid, String prs, int rewardType, int valueType, int real_pump,
			int pump, int groupId, int pid, String roomid, int time, int max_player) throws Exception {
		EventServer.log.info("to_reward begin:" + uid);
		EventServer.log.info("prs:" + prs);

		int useValue = 0;
		if (StringUtil.isNotEmpty(prs)) {

			int round = 100 / max_player;
			ITArray list = TArray.newFromJsonData(prs);

			for (int i = list.size() - 1; i >= 0; --i) {

				ITObject obj1 = list.getTObject(i);
				int parentId = obj1.getInt("p");
				int rewardPercent = 0;
				if (obj1.containsKey("r")) {
					rewardPercent = obj1.getInt("r");
				}
				int rv = 0;
				if (i > 0) {
					ITObject obj2 = list.getTObject(i - 1);
					if (!obj2.containsKey("r")) {
						rv = rewardPercent - 0;
					} else {
						rv = rewardPercent - obj2.getInt("r");
					}
				} else {

					rv = rewardPercent;
				}
				int reward_value = rv;
				EventServer.log.info("rewardType:" + rewardType);
				EventServer.log.info("valueType:" + valueType);
				EventServer.log.info("reward_value:" + reward_value);

				if (valueType == 1) {
//					EventServer.log.info("reward_value:" + reward_value);
					reward_value = Math.round(pump * (rv / 100f));
				} else {
					if (rewardType == 2) {
						reward_value = reward_value / max_player;
					}
				}
				EventServer.log.info("reward_value:" + reward_value);
				if (reward_value > 1000) {
					return;
				}
				if (reward_value < 0) {
					continue;
				}

				String key = String.format("g{%s}:m%s:reward_hp", groupId, parentId);
				Redis.use(DB).incrBy(key, reward_value);
				String rewardsql = String.format(
						"update group_member set reward_hp = %s where uid = %s AND groupId = %s",
						Redis.use(DB).get(key), parentId, groupId);
				Utility.evtdb(groupId, 1, rewardsql);
				// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
				// Redis.use(DB).incrBy(all_key, reward_value);
				useValue += reward_value;

				Jedis jedis9 = Redis.use("group1_db9").getJedis();
				try {
					String desc = "" + uid;
					long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s", groupId, parentId),
							reward_value, jedis9);
					EventServer.log.info("ConsumeCode.HP_PARTNER_REWARD:" + reward_value);

					String sql = String.format(
							"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round, info) "
									+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
							groupId, parentId, ConsumeCode.HP_PARTNER_REWARD, reward_value, cur_hp, pid, roomid, time,
							round, desc);
					DataBase.use().executeUpdate(sql);
				} finally {
					jedis9.close();
				}

				// 记录代理每天的推广奖励
				CountUtil.countLogByDay30(key, reward_value, pipeline);

				key = String.format("g{%s}:m%s:reward_log", groupId, parentId);
				CountUtil.countLogByDay30(key, reward_value, pipeline);

				key = String.format("g{%s}:m%s:p%s:reward_log", groupId, parentId, pid);
				CountUtil.countLogByDay30(key, reward_value, pipeline);

				// 记录每个人对上级的推广奖励是多少
				key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, uid, parentId);
				CountUtil.countLogByDay30(key, reward_value, pipeline);

				boolean add_uid = (uid == parentId || i == 0);
//				if (add_uid == true) {
				key = String.format("g{%s}:m%s:d_reward", groupId, parentId);
				CountUtil.countLogByDay30(key, obj1.getInt("r"), pipeline);
//				}

				if (i > 0) {

					for (int j = i - 1; j >= 0; j--) {

						ITObject obj2 = list.getTObject(j);
						int temp = obj2.getInt("p");
						if (temp != uid) {
							key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, temp, parentId);
							CountUtil.countLogByDay30(key, reward_value, pipeline);
						}
					}
				}

				// 某个玩法的抽水总值
				CountUtil.countLogByDay30(String.format("g%s:hp_cost:m%s:p%s", groupId, parentId, pid), pump, pipeline);

				CountUtil.countLogByDay30(String.format("g%s:hp_reward", groupId), reward_value, pipeline);
			}
		}

		GroupBean gb = GroupCache.getGroup(groupId);
		if (gb != null) {

			int round = 100 / max_player;
			int leftValue = real_pump - useValue;
			if (leftValue < 0) {
				return;
			}
			EventServer.log.info("群主抽水开始:" + leftValue);
			EventServer.log.info("群主抽水开始:" + real_pump + "-" + useValue);

			String key = String.format("g{%s}:m%s:reward_hp", groupId, gb.owner);
			Redis.use(DB).incrBy(key, leftValue);
			String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s",
					Redis.use(DB).get(key), gb.owner, groupId);
			Utility.evtdb(groupId, 1, rewardsql);
			// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
			// Redis.use(DB).incrBy(all_key, leftValue);
			// 记录代理每天的推广奖励
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			key = String.format("g{%s}:m%s:reward_log", groupId, gb.owner);
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			key = String.format("g{%s}:m%s:p%s:reward_log", groupId, gb.owner, pid);
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			// 记录每个人对上级的推广奖励是多少
			key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId, uid, gb.owner);
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			boolean add_uid = (uid == gb.owner);
			if (add_uid == true) {
				key = String.format("g{%s}:m%s:d_reward", groupId, gb.owner);
				CountUtil.countLogByDay30(key, leftValue, pipeline);
			}
			Jedis jedis9 = Redis.use("group1_db9").getJedis();
			EventServer.log.info("leftValue:" + leftValue);

			try {
				String desc = "" + uid;
				long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s", groupId, gb.owner), leftValue,
						jedis9);
				String sql = String.format(
						"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
								+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
						groupId, gb.owner, ConsumeCode.HP_PARTNER_REWARD, leftValue, cur_hp, pid, roomid, time, round,
						desc);

				DataBase.use().executeUpdate(sql);
				EventServer.log.info("群主抽水结束:" + leftValue);
				EventServer.log.info("群主抽水结束:" + real_pump + "-" + useValue);
				log.info("盟主分层后积分：" + Redis.use(DB).get(key));

			} finally {
				jedis9.close();
			}
		}
		EventServer.log.info("to_reward end:" + uid);

	}

	private void to_reward_base(Pipeline pipeline, int uid, String prs, int pump, int groupId, boolean isPumpBaseWin)
			throws Exception {
		EventServer.log.info("to_reward_base begin:" + uid);
		EventServer.log.info("prs:" + prs);
		EventServer.log.info("pump:" + pump);

		if (StringUtil.isNotEmpty(prs)) {

			ITArray list = TArray.newFromJsonData(prs);

			for (int i = list.size() - 1; i >= 0; --i) {

				ITObject obj1 = list.getTObject(i);
				int parentId = obj1.getInt("p");
				int rewardPercent = 0;
				if (obj1.containsKey("r")) {
					rewardPercent = obj1.getInt("r");
				}
				int rv = 0;
				if (i > 0) {
					ITObject obj2 = list.getTObject(i - 1);
					if (!obj2.containsKey("r")) {
						rv = rewardPercent - 0;
					} else {
						rv = rewardPercent - obj2.getInt("r");
					}
				} else {

					rv = rewardPercent;
				}

				// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
				// Redis.use(DB).incrBy(all_key, reward_value);
				if (!isPumpBaseWin) {
					String key = String.format("g{%s}:m%s:total_win", groupId, parentId);
					CountUtil.countLogByDay30(key, pump, pipeline);

				}

			}
		}
	}

	private void xipai_to_reward(Pipeline pipeline, int uid, String prs, int rewardType, int valueType, int real_pump,
			int pump, int groupId, int pid, String roomid, int time, int max_player) throws Exception {

		int useValue = 0;
		if (StringUtil.isNotEmpty(prs)) {

			ITArray list = TArray.newFromJsonData(prs);

			for (int i = list.size() - 1; i >= 0; --i) {

				ITObject obj1 = list.getTObject(i);
				int parentId = obj1.getInt("p");
				int rewardPercent = 0;
				if (obj1.containsKey("r")) {
					rewardPercent = obj1.getInt("r");
				}
				int rv = 0;
				if (i > 0) {
					ITObject obj2 = list.getTObject(i - 1);
					if (!obj2.containsKey("r")) {
						rv = rewardPercent - 0;
					} else {
						rv = rewardPercent - obj2.getInt("r");
					}
				} else {

					rv = rewardPercent;
				}

				// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,parentId);
				// Redis.use(DB).incrBy(all_key, reward_value);
					String key = String.format("g{%s}:m%s:total_win", groupId, parentId);
					CountUtil.countLogByDay30(key, -real_pump, pipeline);
			}
		}
		log.info("洗牌分给到盟主");
		GroupBean gb = GroupCache.getGroup(groupId);
		if (gb != null) {
			int round = 100 / 2;
			int leftValue = real_pump - useValue;
			String key = String.format("g{%s}:m%s:reward_hp", groupId, gb.owner);
			Redis.use(DB).incrBy(key, leftValue);
			String rewardsql = String.format(
					"update group_member set reward_hp=reward_hp+ %s where uid = %s AND groupId = %s", leftValue,
					gb.owner, groupId);

			Utility.evtdb(groupId, 1, rewardsql);

//			String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s",
//					Redis.use(DB).get(key), gb.owner, groupId);
//			Utility.evtdb(groupId, 1, rewardsql);
			log.info("盟主洗牌后积分：" + Redis.use(DB).get(key));

			// String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
			// Redis.use(DB).incrBy(all_key, leftValue);
			// 记录代理每天的推广奖励
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			key = String.format("g{%s}:m%s:xipai_reward_log", groupId, gb.owner);
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			key = String.format("g{%s}:m%s:p%s:xipai_reward_log", groupId, gb.owner, pid);
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			// 记录每个人对上级的推广奖励是多少
			key = String.format("g{%s}:m%s:xipai_reward_log_to:par%s", groupId, uid, gb.owner);
			CountUtil.countLogByDay30(key, leftValue, pipeline);

			boolean add_uid = (uid == gb.owner);
			if (add_uid == true) {
				key = String.format("g{%s}:m%s:d_xipai_reward", groupId, gb.owner);
				CountUtil.countLogByDay30(key, leftValue, pipeline);
			}
			Jedis jedis9 = Redis.use("group1_db9").getJedis();
			try {
				String desc = "" + uid;
				long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s", groupId, gb.owner), leftValue,
						jedis9);
				String sql = String.format(
						"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
								+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
						groupId, gb.owner, ConsumeCode.HP_PARTNER_XIPAI_REWARD, leftValue, cur_hp, pid, roomid, time,
						round, desc);
				DataBase.use().executeUpdate(sql);
			} finally {
				jedis9.close();
			}
		}
	}

//	private void to_mengzhu_reward(Pipeline pipeline, int uid, String prs,int rewardType, int valueType, int real_pump, int pump,int groupId,int pid,String roomid,int time,int max_player) throws Exception {
//		GroupBean gb = GroupCache.getGroup(groupId);
//		if (gb != null) {
//			int round = 100 / max_player;
//			int leftValue = real_pump;
//			String key = String.format("g{%s}:m%s:reward_hp", groupId,gb.owner);
//			Redis.use(DB).incrBy(key, leftValue);
//			String rewardsql = String.format("update group_member set reward_hp = %s where uid = %s AND groupId = %s", Redis.use(DB).get(key), gb.owner,groupId);
//			Utility.evtdb(groupId, 1, rewardsql);
//			//String all_key = String.format("g{%s}:m%s:all_reward_hp", groupId,gb.owner);
//			//Redis.use(DB).incrBy(all_key, leftValue);
//			// 记录代理每天的推广奖励
//			CountUtil.countLogByDay30(key, leftValue, pipeline);
//
//			key = String.format("g{%s}:m%s:reward_log", groupId,gb.owner);
//			CountUtil.countLogByDay30(key, leftValue, pipeline);
//
//			key = String.format("g{%s}:m%s:p%s:reward_log", groupId,gb.owner,pid);
//			CountUtil.countLogByDay30(key, leftValue, pipeline);
//
//			// 记录每个人对上级的推广奖励是多少
//			key = String.format("g{%s}:m%s:reward_log_to:par%s", groupId,uid, gb.owner);
//			CountUtil.countLogByDay30(key, leftValue, pipeline);
//
//			boolean add_uid = (uid == gb.owner);
//			if(add_uid == true) {
//				key = String.format("g{%s}:m%s:d_reward", groupId,gb.owner);
//				CountUtil.countLogByDay30(key, leftValue, pipeline);
//			}
//
//			Jedis jedis9 =  Redis.use("group1_db9").getJedis();
//			try {
//				String desc = "" + uid;
//				long cur_hp = CountUtil.countLogByDay3(String.format("g%s:hp_reward:m%s",groupId,gb.owner), leftValue, jedis9);
//				String sql = String.format("INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
//						+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)", groupId,gb.owner,ConsumeCode.HP_PARTNER_REWARD,leftValue,cur_hp,pid,roomid,time,round,desc);
//				DataBase.use().executeUpdate(sql);
//			}finally {
//				jedis9.close();
//			}
//		}
//	}

	@Override
	public int processGroup(int groupId, ITObject param) throws Exception {
		int uid = param.getInt("uid");
		EventServer.log.info("jiesuan processGroup begin:" + param);

		try {
			int hp = param.getInt("hp");
//			int cur_hp = param.getInt("cur_hp");
			//查询mysql的hp
			String hpSql = String.format(
					"SELECT hp FROM `group_member` WHERE uid=%s and groupId=%s",
					uid,groupId);

			ITArray arr = DataBase.use().executeQueryByTArray(hpSql);
			int cur_hp = arr.getTObject(0).getInt("hp").intValue();
			boolean is_pump = param.containsKey("pump");
			int pump = 0;// 分成抽水
			int pumpReal = 0;// 真实抽水
			int pumpBase = 0;// 保底抽水
			int pumpBaseWin = 0;// 大赢家保底抽水
			int hpReal = 0;// 大赢家保底抽水

			
			String roomid = param.getString("room");
			int pid = param.getInt("pid");
			int time = param.getInt("time");
			int reward_value = 0;
			int xipai_reward_value = 0;
			int max_player = 0;
			int rewardValueType = 0;
			int xipai_rewardValueType = 0;
			int rewardType = 1;
			int xipai_rewardType = 1;

			if (param.containsKey("hpReal")) {
				hpReal = param.getInt("hpReal");
			}

			boolean is_xipai = param.containsKey("xipai");
			int xipai = 0;
			pumpBase = param.getInt("pumpBase");
			if (param.containsKey("pumpBaseWin")) {
				pumpBaseWin = param.getInt("pumpBaseWin");
			}

			String prs = null;

			if (is_pump) {
				pump = param.getInt("pump");
				pumpReal = param.getInt("pumpReal");

				max_player = param.getInt("max_player");
				if (param.containsKey("reward_value")) {
					reward_value = param.getInt("reward_value");
					prs = param.getString("prs");
				}
				if (param.containsKey("reward_type")) {
					rewardType = param.getInt("reward_type");
				}
				if (param.containsKey("rewardValueType")) {
					rewardValueType = param.getInt("rewardValueType");
				}
			}

			if (is_xipai) {
				xipai = param.getInt("xipai");
				max_player = param.getInt("max_player");
				if (param.containsKey("xipai_reward_value")) {
					xipai_reward_value = param.getInt("xipai_reward_value");
					prs = param.getString("prs");
				}
				if (param.containsKey("xipai_reward_type")) {
					xipai_rewardType = param.getInt("xipai_reward_type");
				}
				if (param.containsKey("xipai_rewardValueType")) {
					xipai_rewardValueType = param.getInt("xipai_rewardValueType");
				}
			}

			if (param.containsKey("hp_than_max_value")) {
				int more_hp = param.getInt("hp_than_max_value");
				String gm_key = GroupMemberCache.genKey(groupId, uid);
				String bank_hp = Redis.use("group1_db10").hget(gm_key, "bank_hp");
				String sql = String.format("{call sp_bank_hp(%s,%s,%s,%s)}", groupId, uid, more_hp, cur_hp);
				Utility.evtdb(groupId, 2, sql);
				String sql2 = String.format("update group_member set bank_hp = %s where uid = %s AND groupId = %s",
						bank_hp, uid, groupId);
				Utility.evtdb(groupId, 1, sql2);
			}

			String desc = param.getString("desc");
			desc = StringUtil.isNotEmpty(desc) ? desc : StringUtil.Empty;

			if (hp != 0 && !is_xipai && pumpReal != 0 ) {
				log.info("结算到这里1:"+cur_hp);
				cur_hp = cur_hp+hp;
				if(hp<0) {
					hpConsume(groupId, uid, pid, hp, cur_hp, ConsumeCode.HP_CLEARING, roomid, time, desc);
				}else {
					cur_hp = cur_hp-pumpReal;
					hpConsume(groupId, uid, pid, hp, cur_hp-pumpReal, ConsumeCode.HP_CLEARING, roomid, time, desc);
					hpConsume(groupId, uid, pid, -pumpReal, cur_hp, ConsumeCode.HP_PUMP, roomid, time, desc);

				}
			} else if (hp > 0 && pumpBase != 0 && !is_xipai) {
				log.info("抽水到这里cur_hp:"+cur_hp);
				log.info("抽水到这里pumpBase:"+pumpBase);

				hpConsume(groupId, uid, pid, -pumpBase, cur_hp - pumpBase, ConsumeCode.HP_PUMP, roomid, time, desc);
			}

			Jedis jedis9 = Redis.use("group1_db9").getJedis();
			try {

				String key = String.format("g%s:m%s:consume_hp", groupId, uid);
				if (hp != 0) {
					CountUtil.countLogByDay(key, hp, jedis9, 691200);
				}

				if (pump > 0 && !is_xipai) {

					CountUtil.countLogByDay(key, -pumpReal, jedis9, 691200);
					time += 1;
//					if(hpReal > 0 ) {
//
//					}

					CountUtil.countLog(String.format("g%s:hp_cost", groupId), pump, jedis9);
					CountUtil.countLogByDay(String.format("g%s:hp_cost:p%s", groupId, pid), pumpReal, jedis9);
					CountUtil.countLogByDay(String.format("g%s:hp_cost:m%s", groupId, uid), pumpReal, jedis9);
				}

				if (xipai > 0) {
					CountUtil.countLogByDay(key, -xipai, jedis9, 691200);
					time += 1;
					hpConsume(groupId, uid, pid, -xipai, cur_hp-xipai, ConsumeCode.HP_XIPAI_PUMP, roomid, time, desc);

					CountUtil.countLog(String.format("g%s:hp_cost", groupId), xipai, jedis9);
					CountUtil.countLogByDay(String.format("g%s:hp_cost:p%s", groupId, pid), xipai, jedis9);
					CountUtil.countLogByDay(String.format("g%s:hp_cost:m%s", groupId, uid), xipai, jedis9);
				}

				Pipeline pipeline = jedis9.pipelined();
//				gid=618028, reward_value=0, reward_type=1, E=8, rewardType=1, hp=7000, pumpReal=0, pid=40,
//				room=328670, prs=[{"p":241662,"r":242},{"p":139302,"r":245}], uid=241662, cur_hp=256892,
//						xipai_rewardValueType=1, max_player=2, xipai_rewardType=3, time=1762344428, pump=0,
//						desc=放炮罚 328670, rewardValueType=2, pumpBase=100
				log.info("reward_value:" + reward_value);
				log.info("rewardValueType:" + rewardValueType);
				log.info("is_pump:" + is_pump);
				log.info("pumpBase:" + pumpBase);
				log.info("pumpBaseWin:" + pumpBaseWin);
				log.info("pumpReal:" + pumpReal);

				if ((reward_value > 0 || (rewardValueType == 2 && is_pump)) && pumpReal != 0 && pumpBaseWin == 0) {
					log.info("分层抽水");

					time += 1;
					to_reward(pipeline, uid, prs, rewardType, rewardValueType, pump, reward_value, groupId, pid, roomid,
							time, max_player);
				} else {
					// 平局则把保底分给到群主
					if (pumpBase > 0 && is_pump && pumpBaseWin != 0) {
						log.info("平局抽赢家保底分");
						hpConsume(groupId, uid, pid, -pumpBase, cur_hp - pumpBase, ConsumeCode.HP_PUMP, roomid, time, desc);

						GroupBean gb = GroupCache.getGroup(groupId);

						// 给到群主时要刷新mysql的hp值
						String rewardsql = String.format(
								"update group_member set bank_hp=bank_hp+ %s where uid = %s AND groupId = %s", pumpBase, gb.owner,
								groupId);

						Utility.evtdb(groupId, 1, rewardsql);
						long qunzhu_cur_hp = CountUtil.countLogByDay3(
								String.format("g%s:hp_reward:m%s", groupId, gb.owner), pumpBase, jedis9);

						String sql = String.format(
								"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
										+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,'" + "保底抽水" + "')",
								groupId, gb.owner, ConsumeCode.HP_PARTNER_REWARD, pumpBase, qunzhu_cur_hp, pid, roomid,
								time, 0);
						DataBase.use().executeUpdate(sql);
						to_reward_base(pipeline, uid, param.getString("prs"), -pumpBase, groupId, true);

					} else if (pumpBase > 0 && !is_xipai && is_pump && pumpBaseWin == 0) {
						log.info("平局抽双方保底分");
						hpConsume(groupId, uid, pid, -pumpBase, cur_hp - pumpBase, ConsumeCode.HP_PUMP, roomid, time, desc);

						GroupBean gb = GroupCache.getGroup(groupId);
						long qunzhu_cur_hp = CountUtil.countLogByDay3(
								String.format("g%s:hp_reward:m%s", groupId, gb.owner), pumpBase, jedis9);

						// 给到群主时要刷新mysql的hp值
						String rewardsql = String.format(
								"update group_member set bank_hp=bank_hp+ %s where uid = %s AND groupId = %s", pumpBase, gb.owner,
								groupId);

						Utility.evtdb(groupId, 1, rewardsql);
						String sqllog = String.format(
								"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
										+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,'" + "保底抽水" + "')",
								groupId, gb.owner, ConsumeCode.HP_PARTNER_REWARD, pumpBase, qunzhu_cur_hp, pid, roomid,
								time, 0);
						Utility.evtdb(groupId, 1, sqllog);
						// 记录被扣除保底分的用户

						String sqlUserlog = String.format(
								"INSERT INTO group_hp_log(gid,uid,reason,hp,cur_hp,pid,roomid,time,round,info) "
										+ "VALUES(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)",
								groupId, uid, ConsumeCode.HP_CLEARING, pumpBase, cur_hp, pid, roomid, time, 0, "扣除保底");
						Utility.evtdb(groupId, 1, sqlUserlog);

						to_reward_base(pipeline, uid, param.getString("prs"), -pumpBase, groupId, false);

					}
				}

				/*
				 * else { if (is_pump && pump > 0) {
				 * log.error("pump to_mengzhu_reward:"+pump+" uid:" + uid + " groupId:" +
				 * groupId); to_mengzhu_reward(pipeline,uid,prs,rewardType,rewardValueType,
				 * pump, reward_value ,groupId,pid,roomid,time,max_player); } }
				 */
				if (xipai_reward_value > 0 || (xipai_rewardValueType == 2 && is_xipai)) {

					time += 1;
					xipai_to_reward(pipeline, uid, prs, xipai_rewardType, xipai_rewardValueType, xipai,
							xipai_reward_value, groupId, pid, roomid, time, max_player);
				}

				/*
				 * else { if (is_xipai && xipai > 0) {
				 * log.error("xipai to_mengzhu_reward:"+pump+" uid:" + uid + " groupId:" +
				 * groupId);
				 * to_mengzhu_reward(pipeline,uid,prs,xipai_rewardType,xipai_rewardValueType,
				 * xipai, xipai_reward_value ,groupId,pid,roomid,time,max_player); } }
				 */
				pipeline.sync();

			} finally {
				jedis9.close();
			}
		} catch (Exception e) {
			EventServer.log.error("群主保底分sql异常:", e);
			e.printStackTrace();
		}

		return 0;
	}
}
