package com.iamberry.rent.service.pay;

import java.net.InetAddress;
import java.util.regex.Pattern;

import com.iamberry.rent.face.order.RentOrderService;
import com.iamberry.rent.face.pay.RentPayService;
import com.iamberry.wechat.core.entity.rent.AccountLogsInfo;
import com.iamberry.wechat.tools.*;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.iamberry.wechat.core.entity.pay.PayResult;
import com.iamberry.wechat.face.pay.PayService;

/**
 * @author LJK Class Description: 微信支付service实现 Create Date:2017年5月8日15:17:19
 *         
 */
@Service
public class RentPayServiceImpl implements RentPayService {

	@Autowired
	private RentOrderService rentOrderService;

	@Override
	public ResponseJson payTransfer(String openid, String orderid, Integer amount, Integer accountType, String dese) {
		ResponseJson responseJson = PayUtil.transferPay(openid,orderid,amount,dese);
		if(responseJson.getReturnCode() == 200){
			//新增转账记录
			AccountLogsInfo accountLogsInfo = new AccountLogsInfo();
			accountLogsInfo.setAccountMoney(Integer.valueOf(amount));
			accountLogsInfo.setAccountOpenId(openid);
			accountLogsInfo.setAccountOrderId(orderid);
			accountLogsInfo.setAccountType(accountType);
			accountLogsInfo.setAccountRemark(dese);
			accountLogsInfo.setTransferOrderNo((String)responseJson.getReturnMsg().get("partner_trade_no"));
			rentOrderService.addTransferRecord(accountLogsInfo);
		}
		return responseJson;
	}

}
