package com.iamberry.wechat.tools;

import com.iamberry.wechat.tools.NameUtils;
import com.iamberry.wechat.tools.ResultInfo;
import com.iamberry.wechat.tools.WeixinUtil;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
/**
 * @company	深圳爱贝源科技有限公司
 * @website www.iamberry.com
 * @author 	献
 * @tel		18271840547
 * @date	2016年11月3日
 * @explain	发送消息通知工具类类
 */
@Component
public class SendMessageUtil {

		//快递公司列表
		public static HashMap<String, String> hashmap = new HashMap<String, String>();
		//正式环境
		{
			hashmap.put("sto", "申通快递");
			hashmap.put("yto", "圆通快递");
			hashmap.put("sf", "顺丰快递");
			hashmap.put("longbanwuliu", "龙邦快递");
			hashmap.put("ems", "邮政EMS");
			hashmap.put("zto", "中通快递");
			hashmap.put("zjs", "宅急送");
			hashmap.put("yunda", "韵达快递");
			hashmap.put("cces", "cces快递");
			hashmap.put("pick", "上门提货");
			hashmap.put("htky", "汇通快递");
			hashmap.put("ttkdex", "天天快递");
			hashmap.put("stars", "邮政EMS");
			hashmap.put("jd", "星晨急便");
			hashmap.put("01", "其他");
			hashmap.put("02", "上门送货");
		}


	/**
	 *  获取快递名称
	 * @param firm
	 * @return
	 */
		public static String getHashMap(String firm){
			String escapeFirm = firm;
			try{
				escapeFirm = hashmap.get(firm);;
			}catch (Exception e){}
			return escapeFirm;
		}
		
		/**
		 * 发送模板通知给用户
		 * @param date data 日期
		 * @param openId 接受的用户id
		 * @param url  点击打开的url
		 * @param type 发送类型 1，收益成功通知 2，发货提醒通知 3、收入提醒通知,4、订单未支付通知
		 * @return
		 */
		public boolean sendTemplateMessageToOpenid(String date,String openId, String url,Integer type) {
			boolean result =false;
			switch (type) {
			case 1:  //1，收益成功通知
				WeixinUtil.sendTemplateMessage(NameUtils.appId, NameUtils.appSecret, openId,ResultInfo.rewards_template_id, date, url);
				break;
			case 2:  // 2，发货提醒通知 
				WeixinUtil.sendTemplateMessage(NameUtils.appId, NameUtils.appSecret, openId, ResultInfo.Shipment_template_id, date, url);
				break;
			case 3:  //3、收入提醒通知
				WeixinUtil.sendTemplateMessage(NameUtils.appId, NameUtils.appSecret, openId, ResultInfo.Income_template_id, date, url);
				break;
			case 4:  //4、订单未支付通知
				WeixinUtil.sendTemplateMessage(NameUtils.appId, NameUtils.appSecret, openId, ResultInfo.Order_template_id, date, url);
				break;
			case 5:  //5、支付成功
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.probation_pay_success, date, url);
				break;
			case 6:  //6、用户申请退款提醒
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.order_apply_refund, date, url);
				break;
			case 7:  //7、用户 申请退货 提醒
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.order_apply_return, date, url);
				break;
			case 8:  //8、用户 申请换货 提醒
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.order_apply_barter, date, url);
				break;
			case 9:  //9、发货后 提醒
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.order_send_success, date, url);
				break;
//			case 10:  //10、退款申请通知
//				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.order_refund_msg, date, url);
//				break;
			case 11:  //11、推送模板
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.service_push, date, url);
				break;
			case 12:
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.member_activation, date, url);
				break;
			case 13:	//推荐用户注册会员
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.register_member, date, url);
				break;
			case 14:	//推荐用户使用优惠券
				WeixinUtil.sendTemplateMessage(NameUtils.getConfig("appId"), NameUtils.getConfig("appSecret"), openId, ResultInfo.recommend_use_coupon, date, url);
				break;
			default:
				break;
			}
			result = true;
			return result;
		}

	public static void main(String[] args) {

	}

	/**
	 * 支付成功
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param keyword3
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void probationPaySuccess(String first,String keyword1,String keyword2,String keyword3,String keyword4,String remark,String openId,String url){
		String temp = ResultInfo.PROBATIONPAYSUCCESS;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("keyword3Value",keyword3)
				.replaceFirst("keyword4Value",keyword4)
				.replaceFirst("colorValue","#1C86EE")
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,5);
	}


	/**
	 * 用户申请退款提醒
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param keyword3
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void orderApplyRefund(String first,String keyword1,String keyword2,String keyword3,String keyword4,String remark,String openId,String url){
		String temp = ResultInfo.APPLYREFUND;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("keyword3Value",keyword3)
				.replaceFirst("keyword4Value",keyword4)
				.replaceFirst("colorValue","#1C86EE")
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,6);
	}

	/**
	 * 退款申请通知
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param keyword3
	 * @param remark
	 * @param openId
	 * @param url
	 */
//	public void orderRefundMsg(String first,String keyword1,String keyword2,String keyword3,String remark,String openId,String url){
//		String temp = ResultInfo.ORDERREFUNDMSG;
//		temp = temp.replaceFirst("firstValueIamberry", first)
//				.replaceFirst("keyword1Value",keyword1)
//				.replaceFirst("keyword2Value",keyword2)
//				.replaceFirst("keyword3Value",keyword3)
//				.replaceFirst("colorValue","#1C86EE")
//				.replaceFirst("remarkValue",remark);
//		sendTemplateMessageToOpenid(temp, openId, url,10);
//	}

	/**
	 * 退货
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param keyword3
	 * @param keyword4
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void orderApplyReturn(String first,String keyword1,String keyword2,String keyword3,String keyword4,String keyword5,String remark,String openId,String url){
		String temp = ResultInfo.APPLYRETURN;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("keyword3Value",keyword3)
				.replaceFirst("keyword4Value",keyword4)
				.replaceFirst("keyword5Value",keyword5)
				.replaceFirst("colorValue","#1C86EE")
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,7);
	}

	/**
	 * 申请换货
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void orderApplyBarter(String first,String keyword1,String keyword2,String remark,String openId,String url){
		String temp = ResultInfo.APPLYBARTER;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("colorValue","#1C86EE")
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,8);
	}

	/**
	 * 发货后提醒
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param keyword3
	 * @param keyword4
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void orderSendSuccess(String first,String keyword1,String keyword2,String keyword3,String keyword4,String remark,String openId,String url){
		String temp = ResultInfo.SENDSUCCESS;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("keyword3Value",keyword3)
				.replaceFirst("keyword4Value",keyword4)
				.replaceFirst("colorValue","#1C86EE")
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,9);
	}

	/**
	 * 服务推送
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void servicePush(String first,String keyword1,String keyword2,String remark,String openId,String url){
		String temp = ResultInfo.SERVICEPUSH;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,11);
	}


	/**
	 * 会员激活-生日提醒
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void memberActivation(String first,String keyword1,String keyword2,String remark,String openId,String url){
		String temp = ResultInfo.MEMBERACTIVATION;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,12);
	}

	/**
	 * 注册成为会员
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void registerMember(String first,String keyword1,String keyword2,String remark,String openId,String url){
		String temp = ResultInfo.REGISTERMEMBER;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,13);
	}

	/**
	 * 推荐用户使用优惠券
	 * @param first
	 * @param keyword1
	 * @param keyword2
	 * @param remark
	 * @param openId
	 * @param url
	 */
	public void recommendUseCoupon(String first,String keyword1,String keyword2,String remark,String openId,String url){
		String temp = ResultInfo.RECOMMENDUSECOUPON;
		temp = temp.replaceFirst("firstValueIamberry", first)
				.replaceFirst("keyword1Value",keyword1)
				.replaceFirst("keyword2Value",keyword2)
				.replaceFirst("remarkValue",remark);
		sendTemplateMessageToOpenid(temp, openId, url,14);
	}


}
