add customer payment info

master
kira 6 years ago
parent 076872abba
commit cdba32148d

@ -1,14 +1,13 @@
package au.com.royalpay.payment.manage.apps.events.listeners; package au.com.royalpay.payment.manage.apps.events.listeners;
import au.com.royalpay.payment.core.events.AfterPaymentFinishEvent; import au.com.royalpay.payment.core.events.AfterPaymentFinishEvent;
import au.com.royalpay.payment.manage.customers.core.CustomerPaymentInfoService;
import au.com.royalpay.payment.manage.mappers.system.SysCustomerPaymentInfoMapper; import au.com.royalpay.payment.manage.mappers.system.SysCustomerPaymentInfoMapper;
import au.com.royalpay.payment.tools.utils.id.IdUtil;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.ApplicationListener; import org.springframework.context.ApplicationListener;
import org.springframework.data.redis.core.BoundListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -18,33 +17,36 @@ import javax.annotation.Resource;
*/ */
@Service @Service
public class AfterPaymentFinishListener implements ApplicationListener<AfterPaymentFinishEvent> { public class AfterPaymentFinishListener implements ApplicationListener<AfterPaymentFinishEvent> {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource @Resource
private SysCustomerPaymentInfoMapper sysCustomerPaymentInfoMapper; private SysCustomerPaymentInfoMapper sysCustomerPaymentInfoMapper;
@Resource
private CustomerPaymentInfoService customerPaymentInfoService;
@Override @Override
public void onApplicationEvent(AfterPaymentFinishEvent event) { public void onApplicationEvent(AfterPaymentFinishEvent event) {
JSONObject order = event.getFinishedEvent().getOrder(); JSONObject order = event.getFinishedEvent().getOrder();
JSONObject lastOrderInfo = new JSONObject(); if(!"hf".equals(order.getString("channel"))){
return;
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression"); }
ops.rightPush(order.toJSONString()); if(StringUtils.isEmpty(order.getString("ext_params"))){
return;
lastOrderInfo.put("wechat_openid", order.getString("customer_id")); }
lastOrderInfo.put("idcard_name", order.getString("payer_name")); JSONObject extParam = JSONObject.parseObject(order.getString("ext_params"));
lastOrderInfo.put("idcard_no", order.getString("payer_identity_card"));
lastOrderInfo.put("bankcard", order.getString("card_number"));
lastOrderInfo.put("bank", order.getString("bankId"));
JSONObject orderInfo = sysCustomerPaymentInfoMapper.selectPaymentInfo(order.getString("customer_id")); JSONObject orderInfo = sysCustomerPaymentInfoMapper.selectPaymentInfo(order.getString("customer_id"));
if (orderInfo != null) { if (orderInfo != null) {
lastOrderInfo.put("id", orderInfo.getString("id")); orderInfo.put("idcard_name", extParam.getString("payer_name"));
sysCustomerPaymentInfoMapper.update(lastOrderInfo); orderInfo.put("idcard_no", extParam.getString("payer_identity_card"));
orderInfo.put("bankcard", extParam.getString("card_number"));
orderInfo.put("bank", extParam.getString("bankId"));
sysCustomerPaymentInfoMapper.update(orderInfo);
}else { }else {
lastOrderInfo.put("id", IdUtil.getId()); JSONObject lastOrderInfo = new JSONObject();
sysCustomerPaymentInfoMapper.save(lastOrderInfo); lastOrderInfo.put("wechat_openid", extParam.getString("customer_id"));
lastOrderInfo.put("idcard_name", extParam.getString("payer_name"));
lastOrderInfo.put("idcard_no", extParam.getString("payer_identity_card"));
lastOrderInfo.put("bankcard", extParam.getString("card_number"));
lastOrderInfo.put("bank", extParam.getString("bankId"));
customerPaymentInfoService.save(lastOrderInfo);
} }
} }

@ -4,9 +4,9 @@ import com.alibaba.fastjson.JSONObject;
public interface CustomerPaymentInfoService { public interface CustomerPaymentInfoService {
void saveCustomerPaymentInfo(JSONObject paymentInfo); void save(JSONObject paymentInfo);
void updateCustomerPaymentInfo(JSONObject paymentInfo); void update(JSONObject paymentInfo);
JSONObject selectPaymentInfoByOpenId(String open_id); JSONObject selectPaymentInfoByOpenId(String open_id);
} }

@ -15,7 +15,7 @@ public class CustomerPaymentInfoImpl implements CustomerPaymentInfoService {
private SysCustomerPaymentInfoMapper sysCustomerPaymentInfoMapper; private SysCustomerPaymentInfoMapper sysCustomerPaymentInfoMapper;
@Override @Override
public void saveCustomerPaymentInfo(JSONObject paymentInfo) { public void save(JSONObject paymentInfo) {
if (sysCustomerPaymentInfoMapper.selectPaymentInfo(paymentInfo.getString("wechat_openid")) != null) { if (sysCustomerPaymentInfoMapper.selectPaymentInfo(paymentInfo.getString("wechat_openid")) != null) {
throw new BadRequestException("openid already exists"); throw new BadRequestException("openid already exists");
} }
@ -25,7 +25,7 @@ public class CustomerPaymentInfoImpl implements CustomerPaymentInfoService {
} }
@Override @Override
public void updateCustomerPaymentInfo(JSONObject paymentInfo) { public void update(JSONObject paymentInfo) {
if (paymentInfo.getString("id") == null) { if (paymentInfo.getString("id") == null) {
throw new BadRequestException("ID is empty"); throw new BadRequestException("ID is empty");
} }

@ -15,12 +15,12 @@ public class CustomerPaymentInfoController {
@RequestMapping(value = "/update", method = RequestMethod.POST) @RequestMapping(value = "/update", method = RequestMethod.POST)
public void savePaymentInfo(@RequestBody JSONObject paymentInfo) { public void savePaymentInfo(@RequestBody JSONObject paymentInfo) {
customerPaymentInfoService.saveCustomerPaymentInfo(paymentInfo); customerPaymentInfoService.save(paymentInfo);
} }
@RequestMapping(value = "/update", method = RequestMethod.PUT) @RequestMapping(value = "/update", method = RequestMethod.PUT)
public void updatePaymentInfo(@RequestBody JSONObject paymentInfo) { public void updatePaymentInfo(@RequestBody JSONObject paymentInfo) {
customerPaymentInfoService.updateCustomerPaymentInfo(paymentInfo); customerPaymentInfoService.update(paymentInfo);
} }
@RequestMapping(value = "/{openid}/check", method = RequestMethod.GET) @RequestMapping(value = "/{openid}/check", method = RequestMethod.GET)

Loading…
Cancel
Save