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;
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.tools.utils.id.IdUtil;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
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 javax.annotation.Resource;
@ -18,33 +17,36 @@ import javax.annotation.Resource;
*/
@Service
public class AfterPaymentFinishListener implements ApplicationListener<AfterPaymentFinishEvent> {
@Resource
private StringRedisTemplate stringRedisTemplate;
@Resource
private SysCustomerPaymentInfoMapper sysCustomerPaymentInfoMapper;
@Resource
private CustomerPaymentInfoService customerPaymentInfoService;
@Override
public void onApplicationEvent(AfterPaymentFinishEvent event) {
JSONObject order = event.getFinishedEvent().getOrder();
JSONObject lastOrderInfo = new JSONObject();
BoundListOperations<String, String> ops = stringRedisTemplate.boundListOps("customer_impression");
ops.rightPush(order.toJSONString());
lastOrderInfo.put("wechat_openid", order.getString("customer_id"));
lastOrderInfo.put("idcard_name", order.getString("payer_name"));
lastOrderInfo.put("idcard_no", order.getString("payer_identity_card"));
lastOrderInfo.put("bankcard", order.getString("card_number"));
lastOrderInfo.put("bank", order.getString("bankId"));
if(!"hf".equals(order.getString("channel"))){
return;
}
if(StringUtils.isEmpty(order.getString("ext_params"))){
return;
}
JSONObject extParam = JSONObject.parseObject(order.getString("ext_params"));
JSONObject orderInfo = sysCustomerPaymentInfoMapper.selectPaymentInfo(order.getString("customer_id"));
if (orderInfo != null) {
lastOrderInfo.put("id", orderInfo.getString("id"));
sysCustomerPaymentInfoMapper.update(lastOrderInfo);
orderInfo.put("idcard_name", extParam.getString("payer_name"));
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 {
lastOrderInfo.put("id", IdUtil.getId());
sysCustomerPaymentInfoMapper.save(lastOrderInfo);
JSONObject lastOrderInfo = new JSONObject();
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 {
void saveCustomerPaymentInfo(JSONObject paymentInfo);
void save(JSONObject paymentInfo);
void updateCustomerPaymentInfo(JSONObject paymentInfo);
void update(JSONObject paymentInfo);
JSONObject selectPaymentInfoByOpenId(String open_id);
}

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

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

Loading…
Cancel
Save