fix encourage

master
eason 6 years ago
parent dbfa229946
commit 446f394428

@ -7,6 +7,7 @@ import java.util.List;
import javax.annotation.Resource; import javax.annotation.Resource;
import au.com.royalpay.payment.manage.mappers.system.ManagerCustomerRelationAlipayMapper;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.time.DateFormatUtils; import org.apache.commons.lang3.time.DateFormatUtils;
@ -62,6 +63,8 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
private ManagerMapper managerMapper; private ManagerMapper managerMapper;
@Resource @Resource
private OrderMapper orderMapper; private OrderMapper orderMapper;
@Resource
private ManagerCustomerRelationAlipayMapper managerCustomerRelationAlipayMapper;
@Override @Override
public int getOrder() { public int getOrder() {
@ -76,6 +79,7 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
@Override @Override
public JSONObject takeEncourageMoney(String orderId, String visitorOpenId) { public JSONObject takeEncourageMoney(String orderId, String visitorOpenId) {
logger.info("=====takeEncourageMoney+"+orderId);
JSONObject config = currentEncourageConfig(); JSONObject config = currentEncourageConfig();
if (config != null) { if (config != null) {
if (customerEncourageMoneyAccessLogMapper.findByOrderId(orderId) != null) { if (customerEncourageMoneyAccessLogMapper.findByOrderId(orderId) != null) {
@ -88,6 +92,7 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
return new JSONObject(); return new JSONObject();
} }
JSONObject order = orderMapper.find(orderId); JSONObject order = orderMapper.find(orderId);
String channel = order.getString("channel");
String openId = order.getString("customer_id"); String openId = order.getString("customer_id");
Date tradeDate = DateUtils.truncate(order.getDate("create_time"), Calendar.DATE); Date tradeDate = DateUtils.truncate(order.getDate("create_time"), Calendar.DATE);
if (tradeDate.before(config.getDate("from_date")) || !tradeDate.before(config.getDate("to_date"))) { if (tradeDate.before(config.getDate("from_date")) || !tradeDate.before(config.getDate("to_date"))) {
@ -102,9 +107,12 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
logger.debug("测试模式,不是管理员"); logger.debug("测试模式,不是管理员");
return new JSONObject(); return new JSONObject();
} }
JSONObject member = customerMembershipMapper.findByPaymentOpenId(openId); JSONObject member = customerMembershipMapper.findByPaymentOpenId(openId);
if (member == null) { if (member == null) {
member = new JSONObject(); member = new JSONObject();
if ("Wechat".equals(channel)){
JSONObject relation = customerMapper.findCustomerByOpenId(openId); JSONObject relation = customerMapper.findCustomerByOpenId(openId);
if (relation == null) { if (relation == null) {
logger.debug("用户关系不存在"); logger.debug("用户关系不存在");
@ -118,6 +126,22 @@ public class EncourageUseProcessor implements Ordered, EncourageService {
member.put("encourage_balance", 0); member.put("encourage_balance", 0);
customerMembershipMapper.saveMember(member); customerMembershipMapper.saveMember(member);
} }
if ("Alipay".equals(channel)){
JSONObject relation = managerCustomerRelationAlipayMapper.findCustomerByUserId(openId);
if (relation == null) {
logger.debug("用户关系不存在");
return new JSONObject();
}
member.put("payment_openid", openId);
member.put("kanga_openid", openId.concat("-kanga_openid"));
member.put("redpack_openid", openId.concat("-redpack_openid"));
member.put("attend_time", new Date());
member.put("member_point", -1);
member.put("encourage_balance", 0);
customerMembershipMapper.saveMember(member);
}
}
String memberId = member.getString("member_id"); String memberId = member.getString("member_id");
int usedOrders = customerEncourageMoneyAccessLogMapper.countOrders(memberId, new Date()); int usedOrders = customerEncourageMoneyAccessLogMapper.countOrders(memberId, new Date());
if (usedOrders >= config.getIntValue("max_count")) { if (usedOrders >= config.getIntValue("max_count")) {

@ -20,13 +20,34 @@ public class EncourageMoneyController {
private EncourageService encourageService; private EncourageService encourageService;
@RequestMapping(value = "/orders/{orderId}", method = RequestMethod.PUT) @RequestMapping(value = "/orders/{orderId}", method = RequestMethod.PUT)
public JSONObject takeEncourageMoney(@PathVariable String orderId, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser) { public String takeEncourageMoney(@PathVariable String orderId,@RequestHeader("User-Agent") String ua) {
ua = ua.toLowerCase();
if (ua.contains("micromessenger")) {
return "redirect:/act/encourage_money/orders/" + orderId + "/wechat";
}
if (ua.contains("alipayclient")) {
return "redirect:/act/encourage_money/orders/" + orderId + "/alipay";
}
return null;
}
@RequestMapping(value = "/orders/{orderId}/wechat", method = RequestMethod.PUT)
public JSONObject takeEncourageMoneyWeChat(@PathVariable String orderId, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser) {
if (wxUser == null) { if (wxUser == null) {
return new JSONObject(); return new JSONObject();
} }
return encourageService.takeEncourageMoney(orderId, wxUser.getString("openid")); return encourageService.takeEncourageMoney(orderId, wxUser.getString("openid"));
} }
@RequestMapping(value = "/orders/{orderId}/alipay", method = RequestMethod.PUT)
public JSONObject takeEncourageMoneyAlipay(@PathVariable String orderId, @ModelAttribute(CommonConsts.ALIUSER) JSONObject alipayInfo) {
if (alipayInfo == null) {
return new JSONObject();
}
return encourageService.takeEncourageMoney(orderId, alipayInfo.getString("user_id"));
}
@RequestMapping(value = "/orders/{orderId}/crit", method = RequestMethod.PUT) @RequestMapping(value = "/orders/{orderId}/crit", method = RequestMethod.PUT)
public JSONObject takeEncourageMoneyCrit(@PathVariable String orderId) { public JSONObject takeEncourageMoneyCrit(@PathVariable String orderId) {
return encourageService.doubleEncourageMoney(orderId); return encourageService.doubleEncourageMoney(orderId);

Loading…
Cancel
Save