package com.yeshi.fanli.util.factory;
|
|
import java.math.BigDecimal;
|
import java.text.MessageFormat;
|
import java.util.Map;
|
|
import com.yeshi.fanli.dto.HongBao;
|
import com.yeshi.fanli.entity.bus.user.AccountMessage;
|
import com.yeshi.fanli.entity.bus.user.Extract;
|
import com.yeshi.fanli.entity.bus.user.UserInfo;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.PropertiesUtil;
|
import com.yeshi.fanli.util.TimeUtil;
|
|
public class AccountMessageFactory {
|
|
/**
|
* 新人红包
|
*/
|
public static final int NEWUSER = 1;
|
|
/**
|
* 返利
|
*/
|
public static final int REBATE = 2;
|
|
/**
|
* 分销提成
|
*/
|
public static final int SALE = 3;
|
|
/**
|
* 分享赚
|
*/
|
public static final int SHARE = 4;
|
|
/**
|
* 售后订单扣款
|
*/
|
public static final int SERVICE = 5;
|
|
/**
|
* 提现申请
|
*/
|
public static final int EXTRACTAPPLY = 6;
|
|
/**
|
* 提现失败(被动)
|
*/
|
public static final int EXTRACTFAIL = 7;
|
|
/**
|
* 提现失败(被拒)
|
*/
|
public static final int EXTRACTFAIL2 = 9;
|
|
/**
|
* 新人红包扣除
|
*/
|
public static final int XINREN_DRAWBACK = 10;
|
|
/**
|
* 提现成功
|
*/
|
public static final int EXTRACTSUCCESS = 8;
|
|
private static final String FANTITLE = "fan_title";
|
|
private static final String FANCONTENT = "fan_content";
|
|
private static final String SALETITLE = "sale_title";
|
|
private static final String SALECONTENT = "sale_content";
|
|
private static final String USERTITLE = "user_title";
|
|
private static final String USERCONTENT = "user_content";
|
|
private static final String SERVICETITLE = "service_title";
|
|
private static final String SERVICECONTENT = "service_content";
|
|
private static final String EXTRACTAPPLYTITLE = "extract_apply_title";
|
|
private static final String EXTRACTAPPLYCONTENT = "extract_apply_content";
|
|
private static final String EXTRACTSUCCESSTITLE = "extract_success_title";
|
|
private static final String EXTRACTSUCCESSCONTENT = "extract_success_content";
|
|
private static final String EXTRACTFAILTITLE = "extract_fail_title";
|
|
private static final String EXTRACTFAILCONTENT1 = "extract_fail_content1";
|
private static final String EXTRACTFAILCONTENT2 = "extract_fail_content2";
|
|
public static AccountMessage create(UserInfo userInfo, String orderId, BigDecimal moeny, Extract extract,
|
int type) {
|
String wholeTime = TimeUtil.getWholeTime(extract.getExtractTime());
|
if (type == EXTRACTAPPLY) {
|
return create(userInfo, EXTRACTSUCCESSTITLE, EXTRACTSUCCESSCONTENT, wholeTime);
|
} else if (type == EXTRACTFAIL) {
|
return create(userInfo, EXTRACTFAILTITLE, EXTRACTFAILCONTENT1, wholeTime);
|
} else if (type == EXTRACTFAIL2) {
|
return create(userInfo, EXTRACTFAILTITLE, EXTRACTFAILCONTENT2, wholeTime);
|
} else if (type == EXTRACTSUCCESS) {
|
return create(userInfo, EXTRACTSUCCESSTITLE, EXTRACTSUCCESSCONTENT, wholeTime);
|
}
|
return null;
|
}
|
|
public static AccountMessage create(UserInfo userInfo, String orderId, BigDecimal moeny, int type) {
|
|
switch (type) {
|
case NEWUSER:
|
AccountMessage am = new AccountMessage();
|
am.setContent(Constant.znxConfig.getNewerHongbaoMsg());
|
am.setCreateTime(System.currentTimeMillis());
|
am.setIsOpen(false);
|
am.setTitle(Constant.znxConfig.getNewerHongbaoTitle());
|
am.setUserInfo(userInfo);
|
return am;
|
}
|
|
return null;
|
|
// if (type == REBATE) {
|
// return create(userInfo, FANTITLE, FANCONTENT, orderId, moeny);
|
// } else if (type == SALE) {
|
// return create(userInfo, SALETITLE, SALECONTENT, moeny);
|
// } else if (type == EXTRACTAPPLY) {
|
// return create(userInfo, EXTRACTAPPLYTITLE, EXTRACTAPPLYCONTENT);
|
// } else if (type == NEWUSER) {
|
// return create(userInfo, USERTITLE, USERCONTENT, moeny);
|
// } else if (type == SERVICE) {
|
// return create(userInfo, SERVICETITLE, SERVICECONTENT, orderId,
|
// moeny);
|
// }
|
// return null;
|
}
|
|
private static AccountMessage create(UserInfo userInfo, String titleKey, String contentKey, Object... objs) {
|
AccountMessage am = new AccountMessage();
|
Map<String, String> map = PropertiesUtil.getMap();
|
String title = map.get(titleKey);
|
String content = map.get(contentKey);
|
content = MessageFormat.format(content, objs);
|
am.setContent(content);
|
am.setCreateTime(System.currentTimeMillis());
|
am.setIsOpen(false);
|
am.setTitle(title);
|
am.setUserInfo(userInfo);
|
return am;
|
}
|
|
public static AccountMessage create(HongBao hb) {
|
int type = hb.getType();
|
if (type == Constant.TAOBAO) {
|
return create(hb.getUserInfo(), FANTITLE, FANCONTENT, hb.getOrder().getOrderId(), hb.getMoney());
|
} else if (type == Constant.ONESALE || type == Constant.TWOSALE) {
|
return create(hb.getUserInfo(), SALETITLE, SALECONTENT, hb.getOrder().getOrderId(), hb.getMoney());
|
} else if (type == Constant.HB_NEWUSER) {
|
return create(hb.getUserInfo(), USERTITLE, USERCONTENT, hb.getMoney());
|
}
|
return null;
|
}
|
|
}
|