Просмотр исходного кода

[B端账单][修改][账单支付]

release_toaliyun_real
gongbiao 7 лет назад
Родитель
Сommit
48eac8a49c
14 измененных файлов: 371 добавлений и 345 удалений
  1. +7
    -1
      mallinkAdmin/src/main/java/com/iformall/controller/WxPropertyContractController.java
  2. +5
    -3
      mallinkAdmin/src/main/java/com/iformall/controller/WxRentContractController.java
  3. +21
    -24
      mallinkBApi/src/main/java/com/iformall/controller/WxPayBillController.java
  4. +1
    -1
      mallinkService/src/main/java/com/iformall/service/WxBillAllService.java
  5. +4
    -9
      mallinkService/src/main/java/com/iformall/service/WxPayBillService.java
  6. +3
    -4
      mallinkService/src/main/java/com/iformall/service/WxPropertyContractService.java
  7. +1
    -1
      mallinkService/src/main/java/com/iformall/service/WxRentContractService.java
  8. +44
    -20
      mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java
  9. +188
    -246
      mallinkService/src/main/java/com/iformall/service/impl/WxPayBillServiceImpl.java
  10. +61
    -27
      mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java
  11. +20
    -5
      mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java
  12. +13
    -3
      mallinkService/src/main/resources/mapper/WxBillAllMapper.xml
  13. +1
    -1
      mallinkService/src/main/resources/mapper/WxPayBillMapper.xml
  14. +2
    -0
      mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml

+ 7
- 1
mallinkAdmin/src/main/java/com/iformall/controller/WxPropertyContractController.java Просмотреть файл

@@ -48,6 +48,7 @@ public class WxPropertyContractController extends BaseController

@PostMapping("update")
public ResultData update(@RequestBody WxPropertyContract wxPropertyContract) {
wxPropertyContract.setTenantId(getTenantId());
return wxPropertyContractService.saveOrUpdate(wxPropertyContract);
}

@@ -84,6 +85,11 @@ public class WxPropertyContractController extends BaseController
public ResultData getRentContractList() {
return new ResultData(Result.SUCCESS, "查询成功", wxPropertyContractService.getRentContractList(getTenantId()));
}

@GetMapping("/endPropertyContractByRentContractId")
@ApiImplicitParam(name = "rentContractId", value = "rentContractId", dataType = "Long", paramType = "query", required = true)
public ResultData endPropertyContractByRentContractId(Long rentContractId) {
return wxPropertyContractService.endPropertyContractByRentContractId(rentContractId);
}
}

+ 5
- 3
mallinkAdmin/src/main/java/com/iformall/controller/WxRentContractController.java Просмотреть файл

@@ -74,9 +74,11 @@ public class WxRentContractController extends BaseController {
}

@GetMapping("/endRentContract")
@ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true)
public ResultData endRentContract(Long id) {
return wxRentContractService.endRentContract(id);
@ApiImplicitParams({
@ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true),
@ApiImplicitParam(name = "status", value = "status", dataType = "int", paramType = "query", required = true)})
public ResultData endRentContract(Long id,Integer status) {
return wxRentContractService.endRentContract(id,status);
}

@PostMapping("updateMerchant")


+ 21
- 24
mallinkBApi/src/main/java/com/iformall/controller/WxPayBillController.java Просмотреть файл

@@ -43,7 +43,7 @@ public class WxPayBillController extends BaseController {
logger.info("/api/pay/create" + paramMap.toString());
//bill参数不能为空
String billIdStr = paramMap.get("billId");
if (StringUtils.isBlank(billIdStr)) {
if (StringUtils.isEmpty(billIdStr)) {
logger.info("billId不能为空: " + paramMap.toString());
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "billId不能为空");
}
@@ -57,7 +57,7 @@ public class WxPayBillController extends BaseController {

//b_user_id
String bUserIdStr = paramMap.get("bUserId");
if (StringUtils.isBlank(bUserIdStr)) {
if (StringUtils.isEmpty(bUserIdStr)) {
logger.info("bUserId不能为空: " + paramMap.toString());
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "bUserId不能为空");
}
@@ -80,6 +80,7 @@ public class WxPayBillController extends BaseController {
record.setBillId(billId);
record.setOpenId(openid);
record.setbUserId(bUserId);
record.setTenantId(appInfo.getTenantId());
try {
record.setIp(IPUtil.getIpAddr(request));
return wxPayBillService.createPayBill(payProperty.isReal(), appInfo, record, EnumPayWay.PAY_WAY_WECHAT);
@@ -96,47 +97,43 @@ public class WxPayBillController extends BaseController {
@PostMapping("/updatePayBill")
public ResultData updatePayBill(@RequestBody Map<String, Object> paramMap) {
logger.info("/api/pay/updatePayBill" + paramMap.toString());
String payBillIdStr = (String) paramMap.get("payBillId");
String billIdStr = (String) paramMap.get("billId");
String reasonStr = (String) paramMap.get("reason");
Integer status = (Integer) paramMap.get("status");
if (StringUtils.isBlank(billIdStr)) {
if (StringUtils.isEmpty(billIdStr)) {
logger.info("billId不能为空: " + paramMap.toString());
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "billId不能为空");
}
Long payBillId = 0L, billId = 0L;
Long billId = 0L;
try {
billId = Long.valueOf(billIdStr);
} catch (NumberFormatException e) {
logger.error("billId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage());
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "billId参数不正确");
}
if (!StringUtils.isBlank(payBillIdStr)) {
try {
payBillId = Long.valueOf(payBillIdStr);
} catch (NumberFormatException e) {
logger.error("payBillId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage());
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payBillId参数不正确");
}
}


WxPayBill payBill = new WxPayBill();
payBill.setId(payBillId);
payBill.setBillId(billId);
payBill.setPayBillStatus(status);
payBill.setFailReason(reasonStr);
payBill = wxPayBillService.queryPayBill(payBill);
if(payBill==null){
return new ResultData(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND);
}
try {
if(status.equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()) && !payBillIdStr.equals(EnumPayStatus.PAY_STATUS_WAIT.getCode())) {
// 有价券不走update, callback更新
payBill = wxPayBillService.getById(payBillId);
if(payBill.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) {
//前端返回状态成功时
if(status.equals(EnumPayStatus.PAY_WAY_SUCCESS.getCode())) {
//查询数据是否已经通过回调修改成功,成功什么也不做,因为已经通过回调修改了数据
if(payBill.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_SUCCESS.getCode())) {
return new ResultData(Result.SUCCESS, "支付状态更新成功");
} else {
return new ResultData(ErrorCode.PAY_ORDER_ERROR, "支付未状态,请等待!!");
}
} else {
wxPayBillService.handlePayBillStatusUpdate(payBill);
}
//前端返回状态失败时,修改数据状态为支付失败,
if(!billId.equals(payBill.getBillId())){
logger.info("传入的账单ID与数据表中账单ID不匹配");
}
payBill.setPayBillStatus(status);
payBill.setFailReason(reasonStr);
wxPayBillService.updatePayBillStatus(payBill);
return new ResultData(Result.SUCCESS, "支付状态更新成功");
} catch (MallinkException e) {
logger.error("支付状态更新失败2: " + payBill.toString() + ", e:" + e.getMessage());


+ 1
- 1
mallinkService/src/main/java/com/iformall/service/WxBillAllService.java Просмотреть файл

@@ -17,6 +17,6 @@ public interface WxBillAllService {

ResultData listBill(WxBillAll wxBillAll);

int updateBill(Map<String,Object> bill);
void updateBill(Map<String,Object> bill);

}

+ 4
- 9
mallinkService/src/main/java/com/iformall/service/WxPayBillService.java Просмотреть файл

@@ -59,16 +59,11 @@ public interface WxPayBillService {
*/
void handlePayBillStatusUpdate(WxPayBill record);

/**
* 页面回调
*
* @param paramMap 页面通知参数
* @param payWay 支付方式
* @return
*/
void callback(Map<String, String> paramMap, EnumPayWay payWay);


WxPayBill getById(Long payBillId);

void updatePayBillStatus(WxPayBill payBill);

WxPayBill queryPayBill(WxPayBill payBill);

}

+ 3
- 4
mallinkService/src/main/java/com/iformall/service/WxPropertyContractService.java Просмотреть файл

@@ -53,8 +53,7 @@ public interface WxPropertyContractService {

Object getRentContractList(String tenantId);


ResultData endPropertyContractByRentContractId(Long rentContractId);

}

+ 1
- 1
mallinkService/src/main/java/com/iformall/service/WxRentContractService.java Просмотреть файл

@@ -49,7 +49,7 @@ public interface WxRentContractService {

Object getRentContractStatusInfo(String tenantId);

ResultData endRentContract(Long id);
ResultData endRentContract(Long id, Integer status);

ResultData updateMerchant(WxRentContract wxRentContract);



+ 44
- 20
mallinkService/src/main/java/com/iformall/service/impl/WxBillAllServiceImpl.java Просмотреть файл

@@ -139,39 +139,58 @@ public class WxBillAllServiceImpl implements WxBillAllService {
}

@Override
public int updateBill(Map<String, Object> bill) {
if (bill == null) {
return 0;
}
Integer billTypeValue = (Integer) bill.get("billTypeValue");
if (billTypeValue.equals(EnumBillTypeParam.RENT.getCode())) {
public void updateBill(Map<String, Object> bill) {

int billTypeValue = ((Long) bill.get("billTypeValue")).intValue();
if (billTypeValue==EnumBillTypeParam.RENT.getCode().intValue()) {
//更新租金账单
return updateBillRent(bill);
} else if (billTypeValue.equals(EnumBillTypeParam.RENT_DEPOSIT.getCode())) {
WxBillRent billRent = wxBillRentMapper.selectByPrimaryKey(bill.get("id"));
if(billRent!=null && !billRent.getStatus().equals(EnumBillRentStatus.PAID.getCode())){
updateBillRent(bill);
}
} else if (billTypeValue==EnumBillTypeParam.RENT_DEPOSIT.getCode().intValue()) {
//更新租金押金账单
return updateBillRentDeposit(bill);
} else if (billTypeValue.equals(EnumBillTypeParam.PROPERTY.getCode())) {
WxBillDeposit billDeposit = wxBillDepositMapper.selectByPrimaryKey(bill.get("id"));
if(billDeposit!=null && !billDeposit.getStatus().equals(EnumBillRentStatus.PAID.getCode())){
updateBillRentDeposit(bill);
}
} else if (billTypeValue==EnumBillTypeParam.PROPERTY.getCode().intValue()) {
//更新物业账单
return updateBillProperty(bill);
} else if (billTypeValue.equals(EnumBillTypeParam.PROPERTY_DEPOSIT.getCode())) {
WxBillProperty property = wxBillPropertyMapper.selectByPrimaryKey(bill.get("id"));
if(property!=null && !property.getStatus().equals(EnumBillRentStatus.PAID.getCode())){
updateBillProperty(bill);
}
} else if (billTypeValue==EnumBillTypeParam.PROPERTY_DEPOSIT.getCode().intValue()) {
//更新物业押金账单
return updateBillPropertyDeposit(bill);
} else if (billTypeValue.equals(EnumBillTypeParam.WATER.getCode())) {
WxBillPropertyDeposit wxBillPropertyDeposit = wxBillPropertyDepositMapper.selectByPrimaryKey(bill.get("id"));
if(wxBillPropertyDeposit!=null && !wxBillPropertyDeposit.getStatus().equals(EnumBillRentStatus.PAID.getCode())){
updateBillPropertyDeposit(bill);
}
} else if (billTypeValue==EnumBillTypeParam.WATER.getCode().intValue()) {
//更新水费账单
return updateBillDaily(bill);
} else if (billTypeValue.equals(EnumBillTypeParam.POWER.getCode())) {
WxBillDaily wxBillDaily = wxBillDailyMapper.selectByPrimaryKey(bill.get("id"));
if(wxBillDaily!=null && !wxBillDaily.getStatus().equals(EnumBillRentStatus.PAID.getCode())){
updateBillDaily(bill);
}
} else if (billTypeValue==EnumBillTypeParam.POWER.getCode().intValue()) {
//更新电费账单
return updateBillDaily(bill);
} else if (billTypeValue.equals(EnumBillTypeParam.ROUTINE.getCode())) {
WxBillDaily wxBillDaily = wxBillDailyMapper.selectByPrimaryKey(bill.get("id"));
if(wxBillDaily!=null && !wxBillDaily.getStatus().equals(EnumBillRentStatus.PAID.getCode())){
updateBillDaily(bill);
}
} else if (billTypeValue==EnumBillTypeParam.ROUTINE.getCode().intValue()) {
//更新其他账单
return updateBillOther(bill);
WxBillOther wxBillOther = wxBillOtherMapper.selectByPrimaryKey(bill.get("id"));
if(wxBillOther!=null && !wxBillOther.getStatus().equals(EnumBillRentStatus.PAID.getCode())){
updateBillOther(bill);
}
} else {
logger.info("账单类型不存在");
return 0;
}
}

private int updateBillOther(Map<String, Object> bill) {
logger.info("updateBillOther params:"+bill.toString());
Object id = bill.get("id");
WxBillOther wxBillOther = wxBillOtherMapper.selectByPrimaryKey(id);
if(wxBillOther==null){
@@ -192,6 +211,7 @@ public class WxBillAllServiceImpl implements WxBillAllService {
}

private int updateBillDaily(Map<String, Object> bill) {
logger.info("updateBillDaily params:"+bill.toString());
Object id = bill.get("id");
WxBillDaily wxBillDaily = wxBillDailyMapper.selectByPrimaryKey(id);
if(wxBillDaily==null){
@@ -212,6 +232,7 @@ public class WxBillAllServiceImpl implements WxBillAllService {
}

private int updateBillPropertyDeposit(Map<String, Object> bill) {
logger.info("updateBillPropertyDeposit params:"+bill.toString());
Object id = bill.get("id");
WxBillPropertyDeposit wxBillPropertyDeposit = wxBillPropertyDepositMapper.selectByPrimaryKey(id);
if(wxBillPropertyDeposit==null){
@@ -232,6 +253,7 @@ public class WxBillAllServiceImpl implements WxBillAllService {
}

private int updateBillProperty(Map<String, Object> bill) {
logger.info("updateBillProperty params:"+bill.toString());
Object id = bill.get("id");
WxBillProperty property = wxBillPropertyMapper.selectByPrimaryKey(id);
if(property==null){
@@ -252,6 +274,7 @@ public class WxBillAllServiceImpl implements WxBillAllService {
}

private int updateBillRentDeposit(Map<String, Object> bill) {
logger.info("updateBillRentDeposit params:"+bill.toString());
Object id = bill.get("id");
WxBillDeposit wxBillDeposit = wxBillDepositMapper.selectByPrimaryKey(id);
if(wxBillDeposit==null){
@@ -272,6 +295,7 @@ public class WxBillAllServiceImpl implements WxBillAllService {
}

private int updateBillRent(Map<String, Object> bill) {
logger.info("updateBillRentDeposit params:"+bill.toString());
Object id = bill.get("id");
WxBillRent wxBillRent = wxBillRentMapper.selectByPrimaryKey(id);
if(wxBillRent==null){


+ 188
- 246
mallinkService/src/main/java/com/iformall/service/impl/WxPayBillServiceImpl.java Просмотреть файл

@@ -14,10 +14,7 @@ import com.iformall.mapper.*;
import com.iformall.pay.*;
import com.iformall.service.WxBillAllService;
import com.iformall.service.WxPayBillService;
import com.iformall.utils.BeanUtils;
import com.iformall.utils.MapUtil;
import com.iformall.utils.Utility;
import com.iformall.utils.XmlUtil;
import com.iformall.utils.*;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -88,213 +85,166 @@ public class WxPayBillServiceImpl implements WxPayBillService {
final IdWorker idworker = IdWorker.get();

EnumPayShare isShare = EnumPayShare.NO;

try {
// 1. check 订单
//查询账单是否存在
WxBillAll wxBillAll = new WxBillAll();
wxBillAll.setTenantId(appInfo.getTenantId());
wxBillAll.setId(record.getBillId());
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll);
if (bills == null) {
logger.error("pay bill, bill not allow, repaymentReq: " + record.toString() + ", payWay: " + payWay.toString());
if (bills.size()==0) {
logger.error("pay bill, bill not allow, repaymentReq: " + JSONObject.toJSONString(record) + ", payWay: " + payWay.toString());
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND);
}
Map<String, Object> bill;
//获取账单数据
if(bills.size()>0){
bill = bills.get(0);
}else{
logger.error("pay bill, bill not allow, repaymentReq: " + record.toString() + ", payWay: " + payWay.toString());
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND);
}

Map<String, Object> bill = bills.get(0);
//获取支付账户信息
WxPayAccountBill payAccount = wxPayAccountBillMapper.selectByPrimaryKey(appInfo.getPayBillId());

// 2. check 是否有支付订单
Date currentDate = new Date();
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode());
List<WxPayBill> list = wxPayBillMapper.findList(record);
String payBillNo;
List<WxPayBill> list = wxPayBillMapper.findList(record);
//数据库不存在已有订单,新建订单
if (list.size() <= 0) {
// 3. 创建支付订单
// 创建支付订单
Long id = idworker.nextId();
payBillNo = String.valueOf(id);
payBillNo = id+DateUtils.getSystemTime("yyMMddHHmmss");
record.setId(id);
record.setTenantId(appInfo.getTenantId());
record.setbUserId(record.getbUserId());
record.setCreateTime(currentDate);
record.setUpdateTime(currentDate);
record.setPayTimeStart(currentDate);
record.setPayTimeEnd(currentDate);
long endtime = currentDate.getTime() + 120 * 60 * 1000;
record.setPayTimeEnd(new Date(endtime));
// 支付单号
record.setPayBillNo(payBillNo);
record.setPayAmount((Integer) bill.get("owe"));
record.setPayVendor(EnumPayWay.PAY_WAY_WEAPP.getCode());
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode());
record.setPayBillStatus(EnumPayStatus.PAY_WAY_WAIT.getCode());
record.setShare(isShare.getCode());

int sqlRow = wxPayBillMapper.insertSelective(record);
if (sqlRow != 1) {
logger.error("pay bill insert error: " + record.toString());
logger.error("pay bill insert error: " + JSONObject.toJSONString(record));
throw new MallinkException(ErrorCode.DB_FAIL);
}
logger.info("创建支付订单:"+record.toString());
} else {
//数据库存在订单信息,更新支付中状态,返回之前的预支付信息
record = list.get(0);
record.setShare(isShare.getCode());
payBillNo = String.valueOf(record.getId());
}


if (isReal) {
// 微信实际支付
if (payAccount.getType().equals(EnumPayMode.MCH.getCode())) {
// 统一下单 普通商户模式
String noncestr = Utility.generate32UUID();
WxPayOrderP wxPayBillP = new WxPayOrderP();
wxPayBillP.setOpenid(record.getOpenId());
wxPayBillP.setAppid(appInfo.getAppId());
wxPayBillP.setMch_id(payAccount.getMchId());
wxPayBillP.setNonce_str(noncestr);
wxPayBillP.setBody(bill.get("billType").toString());
wxPayBillP.setOut_trade_no(record.getPayBillNo());
wxPayBillP.setTotal_fee((Integer) bill.get("owe"));
// 终端IP
wxPayBillP.setSpbill_create_ip(record.getIp());
wxPayBillP.setNotify_url(payAccount.getPayNotifyUrl());
// 终端类型
wxPayBillP.setTrade_type(WxPay.TradeType.JSAPI.name());
// 订单ID
wxPayBillP.setProduct_id(bill.get("id").toString());
wxPayBillP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate));
Date futureDate = new Date();
futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000);
// 15分钟后结束
wxPayBillP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate));
Map<String, String> payBillMap = BeanUtils.toStringMap(wxPayBillP);
wxPayBillP.setSign(WxPayment.createSign(payBillMap, payAccount.getApiKey()));
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayBillP));
logger.info("pay bill, wechat pushBill, " + wxPayBillP.toString() + ", response: " + response);
Map<String, String> returnMap = WxPayment.xmlToMap(response);
returnMap.put("payBillId", payBillNo);
String result_code = returnMap.get("result_code");
if ("SUCCESS".equals(result_code)) {
String prepay_id = returnMap.get("prepay_id");
// update payBill with prepay_id
record.setPrepayId(prepay_id);
record.setUpdateTime(new Date());
try {
wxPayBillMapper.updateByPrimaryKeySelective(record);
} catch (Exception e) {
logger.error("pay bill update error: " + record.toString());
throw new MallinkException(ErrorCode.DB_FAIL);
}

String timestamp = String.valueOf(Utility.getCurrentTimeStamp());
Map<String, String> sighMap = MapUtil.getOrderMap();
sighMap.put("appId", returnMap.get("appid"));
sighMap.put("timeStamp", timestamp);
sighMap.put("nonceStr", noncestr);
sighMap.put("package", "prepay_id=" + prepay_id);
sighMap.put("signType", "MD5");
String signAgent = WxPayment.createSign(sighMap, payAccount.getApiKey());
returnMap.put("timeStamp", timestamp);
returnMap.put("nonceStr", noncestr);
returnMap.put("package", "prepay_id=" + prepay_id);
returnMap.put("paySign", signAgent);
logger.info("back to UI: " + returnMap.toString());
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap);
} else {
return updatePayBill(record, returnMap, result_code);
}
} else {
// 统一下单 // 服务商模式
//更新订单状态为支付中
record.setPayBillStatus(EnumPayStatus.PAY_WAY_WAIT.getCode());
record.setUpdateTime(currentDate);
int sqlRow = wxPayBillMapper.updateByPrimaryKeySelective(record);
if (sqlRow != 1) {
logger.error("pay bill update error: " + record.toString());
throw new MallinkException(ErrorCode.DB_FAIL);
}
logger.info("数据库存在订单信息,更新支付中状态,返回之前的预支付信息:"+JSONObject.toJSONString(record));
//订单在120分钟之内没有失效,延用之前预支付订单号
if(record.getPayTimeEnd().after(new Date())){
String noncestr = Utility.generate32UUID();
WxPayOrderSP wxPayBillSP = new WxPayOrderSP();
wxPayBillSP.setSub_openid(record.getOpenId());
wxPayBillSP.setAppid(appInfo.getParentAppId());
wxPayBillSP.setMch_id(payAccount.getMchId());
wxPayBillSP.setSub_appid(appInfo.getAppId());
wxPayBillSP.setSub_mch_id(payAccount.getSubMchId());
wxPayBillSP.setNonce_str(noncestr);
wxPayBillSP.setBody(bill.get("billType").toString());
wxPayBillSP.setOut_trade_no(record.getPayBillNo());
wxPayBillSP.setTotal_fee((Integer) bill.get("owe"));
wxPayBillSP.setSpbill_create_ip(record.getIp()); // 终端IP
wxPayBillSP.setNotify_url(payAccount.getPayNotifyUrl());
wxPayBillSP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型
wxPayBillSP.setProduct_id(String.valueOf(bill.get("id").toString())); // 订单ID
wxPayBillSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate));
Date futureDate = new Date();
futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000);
wxPayBillSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束
wxPayBillSP.setSign_type("HMAC-SHA256");
wxPayBillSP.setProfit_sharing(null);
if (isShare == EnumPayShare.YES) {
wxPayBillSP.setProfit_sharing("Y");
}
Map<String, String> payBillMap = BeanUtils.toStringMap(wxPayBillSP);

wxPayBillSP.setSign(WxPayment.createSignHMAC(payBillMap, payAccount.getApiKey()));
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayBillSP));
logger.info("pay bill, wechat pushBill, " + wxPayBillSP.toString() + ", response: " + response.toString());
Map<String, String> returnMap = WxPayment.xmlToMap(response);
returnMap.put("payBillId", payBillNo);
String result_code = returnMap.get("result_code");
if ("SUCCESS".equals(result_code)) {
String prepay_id = returnMap.get("prepay_id");
// update payBill with prepay_id
record.setPrepayId(prepay_id);
record.setUpdateTime(new Date());
try {
wxPayBillMapper.updateByPrimaryKeySelective(record);
} catch (Exception e) {
logger.error("pay bill update error: " + record.toString());
throw new MallinkException(ErrorCode.DB_FAIL);
}
String timestamp = String.valueOf(Utility.getCurrentTimeStamp());
Map<String, String> sighMap = MapUtil.getOrderMap();
sighMap.put("appId", appInfo.getAppId());
sighMap.put("timeStamp", timestamp);
sighMap.put("nonceStr", noncestr);
sighMap.put("package", "prepay_id=" + record.getPrepayId());
sighMap.put("signType", "HMAC-SHA256");
String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey());
Map<String,String> returnMap=new HashMap<>();
returnMap.put("timeStamp", timestamp);
returnMap.put("nonceStr", noncestr);
returnMap.put("package", "prepay_id=" + record.getPrepayId());
returnMap.put("paySign", signAgent);
returnMap.put("signType", "HMAC-SHA256");
logger.info("订单在120分钟之内没有失效,延用之前预支付订单号:"+JSONObject.toJSONString(record));
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap);
}
//超过时间关闭订单
ResultData resultData = payBillClose(appInfo, record);
if(resultData.code!=Result.SUCCESS){
return new ResultData(ErrorCode.ORDER_IS_FAIL);
}
logger.info("超过时间关闭订单:"+record.toString());
record=wxPayBillMapper.selectByPrimaryKey(record.getId());
//创建新的订单号
payBillNo = record.getId()+DateUtils.getSystemTime("yyMMddHHmmss");
record.setPayTimeStart(currentDate);
long endtime = currentDate.getTime() + 120 * 60 * 1000;
record.setPayTimeEnd(new Date(endtime));
record.setPayBillNo(payBillNo);
record.setPayAmount((Integer) bill.get("owe"));
record.setUpdateTime(currentDate);
sqlRow = wxPayBillMapper.updateByPrimaryKeySelective(record);
if (sqlRow != 1) {
logger.error("pay bill update error: " + JSONObject.toJSONString(record));
throw new MallinkException(ErrorCode.DB_FAIL);
}
logger.info("新的订单数据:"+JSONObject.toJSONString(record));
}

String timestamp = String.valueOf(Utility.getCurrentTimeStamp());
Map<String, String> sighMap = MapUtil.getOrderMap();
sighMap.put("appId", appInfo.getAppId());
sighMap.put("timeStamp", timestamp);
sighMap.put("nonceStr", noncestr);
sighMap.put("package", "prepay_id=" + prepay_id);
sighMap.put("signType", "HMAC-SHA256");
String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey());
returnMap.put("timeStamp", timestamp);
returnMap.put("nonceStr", noncestr);
returnMap.put("package", "prepay_id=" + prepay_id);
returnMap.put("paySign", signAgent);
returnMap.put("signType", "HMAC-SHA256");
logger.info("back to UI: " + returnMap.toString());
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap);
} else {
return updatePayBill(record, returnMap, result_code);
}
// 统一下单 // 服务商模式
String noncestr = Utility.generate32UUID();
WxPayOrderSP wxPayBillSP = new WxPayOrderSP();
wxPayBillSP.setSub_openid(record.getOpenId());
wxPayBillSP.setAppid(appInfo.getParentAppId());
wxPayBillSP.setMch_id(payAccount.getMchId());
wxPayBillSP.setSub_appid(appInfo.getAppId());
wxPayBillSP.setSub_mch_id(payAccount.getSubMchId());
wxPayBillSP.setNonce_str(noncestr);
wxPayBillSP.setBody(bill.get("billType").toString());
wxPayBillSP.setOut_trade_no(record.getPayBillNo());
wxPayBillSP.setTotal_fee((Integer) bill.get("owe"));
// 终端IP
wxPayBillSP.setSpbill_create_ip(record.getIp());
wxPayBillSP.setNotify_url(payAccount.getPayNotifyUrl());
// 终端类型
wxPayBillSP.setTrade_type(WxPay.TradeType.JSAPI.name());
// 订单ID
wxPayBillSP.setProduct_id(String.valueOf(bill.get("id").toString()));
wxPayBillSP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate));
wxPayBillSP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(record.getPayTimeEnd()));
wxPayBillSP.setSign_type("HMAC-SHA256");
wxPayBillSP.setProfit_sharing(null);
if (isShare == EnumPayShare.YES) {
wxPayBillSP.setProfit_sharing("Y");
}
Map<String, String> payBillMap = BeanUtils.toStringMap(wxPayBillSP);
wxPayBillSP.setSign(WxPayment.createSignHMAC(payBillMap, payAccount.getApiKey()));
String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayBillSP));
logger.info("pay bill, wechat pushBill, " + wxPayBillSP.toString() + ", response: " + response);
Map<String, String> returnMap = WxPayment.xmlToMap(response);
returnMap.put("payBillId", record.getId().toString());
String result_code = returnMap.get("result_code");
if ("SUCCESS".equals(result_code)) {
String prepay_id = returnMap.get("prepay_id");
// update payBill with prepay_id
record.setPrepayId(prepay_id);
record.setUpdateTime(new Date());
try {
wxPayBillMapper.updateByPrimaryKeySelective(record);
} catch (Exception e) {
logger.error("pay bill update error: " + record.toString());
throw new MallinkException(ErrorCode.DB_FAIL);
}
} else {
// 虚拟支付
WxPayOrderP wxPayBillP = new WxPayOrderP();
wxPayBillP.setOpenid(record.getOpenId());
wxPayBillP.setAppid(appInfo.getAppId());
wxPayBillP.setMch_id(payAccount.getMchId());
wxPayBillP.setBody(bill.get("billType").toString());
wxPayBillP.setOut_trade_no(record.getPayBillNo());
wxPayBillP.setTotal_fee((Integer) bill.get("owe"));
// 终端IP
wxPayBillP.setSpbill_create_ip(record.getIp());
wxPayBillP.setNotify_url(payAccount.getPayNotifyUrl());
// 终端类型
wxPayBillP.setTrade_type(WxPay.TradeType.JSAPI.name());
// 订单ID
wxPayBillP.setProduct_id(bill.get("id").toString());
wxPayBillP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate));
Date futureDate = new Date();
futureDate.setTime(currentDate.getTime() + 15 * 60 * 1000);
// 15分钟后结束
wxPayBillP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate));
wxPayBillP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayBillP), payAccount.getApiKey()));
Map<String, String> returnMap = BeanUtils.toStringMap(wxPayBillP);
String timestamp = String.valueOf(Utility.getCurrentTimeStamp());
Map<String, String> sighMap = MapUtil.getOrderMap();
sighMap.put("appId", appInfo.getAppId());
sighMap.put("timeStamp", timestamp);
sighMap.put("nonceStr", noncestr);
sighMap.put("package", "prepay_id=" + prepay_id);
sighMap.put("signType", "HMAC-SHA256");
String signAgent = WxPayment.createSignHMAC(sighMap, payAccount.getApiKey());
returnMap.put("timeStamp", timestamp);
returnMap.put("nonceStr", noncestr);
returnMap.put("package", "prepay_id=" + prepay_id);
returnMap.put("paySign", signAgent);
returnMap.put("signType", "HMAC-SHA256");
logger.info("back to UI: " + returnMap.toString());
return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap);
}
return updatePayBill(record, returnMap, result_code);
} catch (RuntimeException e) {
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage());
} catch (Exception e) {
@@ -379,8 +329,8 @@ public class WxPayBillServiceImpl implements WxPayBillService {
@Override
public ResultData payBillQuery(WxAppinfo appInfo, WxPayBill record) {
try {
if (StringUtils.isBlank(record.getPayBillNo())){
record.setPayBillNo(String.valueOf(record.getId()));
if (StringUtils.isBlank(record.getPayBillNo())) {
record.setPayBillNo(record.getPayBillNo());
}

String response = wechatPayBillQuery(appInfo, record);
@@ -398,13 +348,13 @@ public class WxPayBillServiceImpl implements WxPayBillService {
//USERPAYING--用户支付中
//PAYERROR--支付失败(其他原因,如银行返回失败)
if ("SUCCESS".equals(trade_state)) {
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode());
record.setPayBillStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode());
handlePayBillStatusUpdate(record);
} else if ("USERPAYING".equals(trade_state)) {
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode());
record.setPayBillStatus(EnumPayStatus.PAY_WAY_WAIT.getCode());
handlePayBillStatusUpdate(record);
} else {
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_FAIL.getCode());
record.setPayBillStatus(EnumPayStatus.PAY_WAY_FAIL.getCode());
handlePayBillStatusUpdate(record);
}
return new ResultData(Result.SUCCESS, "订单查询成功", returnMap);
@@ -488,8 +438,13 @@ public class WxPayBillServiceImpl implements WxPayBillService {
Map<String, String> returnMap = WxPayment.xmlToMap(response);
String result_code = returnMap.get("result_code");
if ("SUCCESS".equals(result_code)) {
record.setPayBillStatus(EnumPayStatus.PAY_STATUS_CANCEL.getCode());
handlePayBillStatusUpdate(record);
try {
record.setPayBillStatus(EnumPayStatus.PAY_WAY_CANCEL.getCode());
wxPayBillMapper.updateByPrimaryKeySelective(record);
} catch (Exception e) {
logger.error("pay bill update error: " + record.toString());
throw new MallinkException(ErrorCode.DB_FAIL);
}
return new ResultData(Result.SUCCESS, "订单关闭成功", returnMap);
} else {
String errMsg = "";
@@ -527,11 +482,14 @@ public class WxPayBillServiceImpl implements WxPayBillService {
@Override
public String notify(Map<String, String> paramMap, EnumPayWay payWay) {
// how to get wechatAppId, wechatMchId, partnerKey
logger.info("-------------");
logger.info("微信回调返回值:" + JSONObject.toJSONString(paramMap));
logger.info("-------------");
String appId = paramMap.get("appid");
String subAppId = paramMap.get("sub_appid");
String mchId = paramMap.get("mch_id");
String subMchId = paramMap.get("sub_mch_id");
WxAppinfo appinfo = null;
WxAppinfo appinfo;
boolean isNormal = true;
if (StringUtils.isBlank(subAppId) && StringUtils.isBlank(subMchId)) {
// 普通商户号
@@ -583,7 +541,7 @@ public class WxPayBillServiceImpl implements WxPayBillService {

String payBillNo = paramMap.get("out_trade_no");
String timEndStr = paramMap.get("time_end");
Long payBillId = Long.valueOf(payBillNo);
Long payBillId = Long.valueOf(payBillNo.substring(0,payBillNo.length()-12));
WxPayBill payBill = wxPayBillMapper.selectByPrimaryKey(payBillId);
if (payBill == null) {
logger.warn("notify bill, wxpay check pay bill not exists, paramMap: " + paramMap.toString() + ", payWay:" + payWay.toString());
@@ -630,14 +588,30 @@ public class WxPayBillServiceImpl implements WxPayBillService {
return XmlUtil.getRequestXml(resultMap);
}


@Override
public void callback(Map<String, String> paramMap, EnumPayWay payWay) {
public WxPayBill getById(Long id) {
return wxPayBillMapper.selectByPrimaryKey(id);
}

@Override
public void updatePayBillStatus(WxPayBill payBill) {
try {
logger.info("更新支付订单");
wxPayBillMapper.selectByPrimaryKey(payBill);
}catch (MallinkException e){
logger.info("更新支付订单失败");
throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR);
}
}

@Override
public WxPayBill getById(Long id) {
return wxPayBillMapper.selectByPrimaryKey(id);
public WxPayBill queryPayBill(WxPayBill payBill) {
List<WxPayBill> select = wxPayBillMapper.select(payBill);
if(select.size()>0){
return select.get(0);
}
return null;
}

@Override
@@ -646,44 +620,41 @@ public class WxPayBillServiceImpl implements WxPayBillService {
Date currentDate = new Date();
EnumPayStatus payStatus = EnumPayStatus.getEnum(record.getPayBillStatus());
// 判断支付状态
if (payStatus == EnumPayStatus.PAY_STATUS_SUCCESS) {
if (payStatus == EnumPayStatus.PAY_WAY_SUCCESS) {
// 已经是成功状态,只更新transactionId
try {
record.setUpdateTime(currentDate);
record.setTransactionId(transactionId);
wxPayBillMapper.updateByPrimaryKeySelective(record);
WxBillAll wxBillAll = new WxBillAll();
wxBillAll.setId(record.getBillId());
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll);
if (bills.size() > 0) {
Map<String, Object> bill = bills.get(0);
wxBillAllService.updateBill(bill);
}
} catch (Exception e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL);
}
return;
}
if (payStatus != EnumPayStatus.PAY_STATUS_WAIT) {
logger.error("pay success handle, payBill " + record.getPayBillNo() +
"is paid success , billId : " + record.getBillId());
return;
}
WxBillAll wxBillAll = new WxBillAll();
wxBillAll.setId(record.getBillId());
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll);
if (bills == null) {
logger.error("pay success handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo());
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND);
}
Map<String, Object> bill=null;
if(bills.size()>0){
bill = bills.get(0);
}else{
if (bills.size()==0) {
logger.error("pay success handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo());
throw new MallinkException(ErrorCode.BILL_ROUTINE_IS_NOT_FOUND);
}
Map<String, Object> bill;
bill = bills.get(0);

// 修改支付订单状态
WxPayBill updateBill = new WxPayBill();
updateBill.setId(record.getId());
updateBill.setBillId(record.getBillId());
updateBill.setUpdateTime(currentDate);
updateBill.setPayBillStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode());
updateBill.setPayBillStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode());
updateBill.setTransactionId(transactionId);
try {
wxPayBillMapper.updateByPrimaryKeySelective(updateBill);
@@ -694,13 +665,10 @@ public class WxPayBillServiceImpl implements WxPayBillService {

//修改账单状态
try {
int _count = wxBillAllService.updateBill(bill);
if (_count > 1) {
throw new MallinkException(ErrorCode.BILL_UPDATE_FAILED);
}
wxBillAllService.updateBill(bill);
} catch (Exception e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "账单更新");
throw new MallinkException(ErrorCode.BILL_UPDATE_FAILED);
}

}
@@ -709,7 +677,7 @@ public class WxPayBillServiceImpl implements WxPayBillService {
@Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class})
public void handlePayBillStatusUpdate(WxPayBill record) {
// 判断支付状态
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_WAIT.getCode())) {
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_WAIT.getCode())) {
logger.error("pay handle, payBill " + record.getPayBillNo() +
"is complete, billId : " + record.getBillId());
return;
@@ -717,25 +685,11 @@ public class WxPayBillServiceImpl implements WxPayBillService {
WxBillAll wxBillAll = new WxBillAll();
wxBillAll.setId(record.getBillId());
List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll);
if (bills == null) {
logger.error("pay handle, bill " + record.getBillId() + " not found , payBillGid : " + record.getPayBillNo());
if (bills.size()==0) {
logger.error("pay handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo());
throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND);
}
WxMerchantBUser user = wxMerchantBUserMapper.selectByPrimaryKey(record.getbUserId());
if (user == null) {
logger.error("pay handle, bill " + record.getBillId() + " not found , payBillGid : " + record.getPayBillNo());
throw new MallinkException(ErrorCode.BUSER_NOT_IN_APP);
}
Map<String, Object> bill = bills.get(0);
Integer owe = (Integer) bill.get("owe");
if (owe > 0) {
// 订单金额不为0时, 支付订单未创建, 返回异常
if (!(record.getId() >0)) {
throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND);
}
}

Date currentDate = new Date();
if (record.getId() > 0) {
// 1. get appinfo
WxAppinfo appInfo = null;
@@ -747,13 +701,12 @@ public class WxPayBillServiceImpl implements WxPayBillService {
appInfo = appList.get(0);
}

WxPayBill updateBill = null;

// 检查支付订单状态
WxPayBill payBillQ = new WxPayBill();
payBillQ.setId(record.getId());
payBillQ.setTenantId(bill.get("tenantId").toString());
payBillQ.setBillId(record.getBillId());
WxPayBill updateBill;
try {
updateBill = wxPayBillMapper.selectOne(payBillQ);
} catch (Exception e) {
@@ -761,34 +714,34 @@ public class WxPayBillServiceImpl implements WxPayBillService {
throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND);
}

if (record.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_CANCEL.getCode())) {
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_FAIL.getCode())) {
// 支付订单取消
if (record.getPayAmount() > 0) {
if (updateBill.getPayAmount() > 0) {
payBillQ = new WxPayBill();
payBillQ.setTenantId(bill.get("tenantId").toString());
payBillQ.setBillId(record.getBillId());
payBillQ.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode());
List<WxPayBill> payBills = wxPayBillMapper.select(payBillQ);
for (WxPayBill payBill : payBills) {
payBillClose(appInfo, payBill);
if(payBill.getPayTimeEnd().before(new Date())){
payBillClose(appInfo, payBill);
}
}
}
} else {
// 支付订单成功?
if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) {
if (StringUtils.isBlank(updateBill.getTransactionId())) {
if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_SUCCESS.getCode())) {
if (!StringUtils.isBlank(updateBill.getTransactionId())) {
// 回调已设置成功
// 继续修改订单状态
} else {
// 回调异常
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "transactionId未获取");
}
} else if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_WAIT.getCode())) {
} else if (updateBill.getPayBillStatus().equals(EnumPayStatus.PAY_WAY_WAIT.getCode())) {
// 回调未返回,主动检查支付订单状态
try {
record.setPayBillNo(String.valueOf(record.getId()));
String response = wechatPayBillQuery(appInfo, record);

logger.info("pay bill query, " + record.toString() + ", response: " + response);
Map<String, String> returnMap = WxPayment.xmlToMap(response);
String result_code = returnMap.get("result_code");
@@ -804,6 +757,7 @@ public class WxPayBillServiceImpl implements WxPayBillService {
if ("SUCCESS".equals(trade_state)) {
// 查询支付订单 -- 已支付
// 继续更改状态
wxBillAllService.updateBill(bill);
} else {
// 支付订单未成功,返回异常
throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), "支付订单未成功");
@@ -820,18 +774,6 @@ public class WxPayBillServiceImpl implements WxPayBillService {
}
}

// 修改账单状态
if (record.getPayBillStatus().equals(EnumPayStatus.PAY_STATUS_SUCCESS.getCode())) {
try {
int _count = wxBillAllService.updateBill(bill);
if (_count > 1) {
throw new MallinkException(ErrorCode.ORDER_IS_FAIL);
}
} catch (Exception e) {
logger.error(e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "账单更新");
}
}
}




+ 61
- 27
mallinkService/src/main/java/com/iformall/service/impl/WxPropertyContractServiceImpl.java Просмотреть файл

@@ -51,6 +51,9 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
@Autowired
WxMerchantMapper wxMerchantMapper;

@Autowired
WxRentContractMapper wxRentContractMapper;

@Override
public Map<String, Object> listAsPage(WxPropertyContract record, Integer pageIndex, Integer pageSize) {
Object rentContractStatusInfo = getRentContractStatusInfo(record.getTenantId());
@@ -98,36 +101,47 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService

@Override
public ResultData saveOrUpdate(WxPropertyContract record) {
//保存物业合同信息
if (record.getId() == null) {

if(null==record.getMerchantId()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"merchantId不能为空");
}
WxMerchant merchant = wxMerchantMapper.selectByPrimaryKey(record.getMerchantId());
if(merchant==null){
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND);
}
if(null==record.getReceivePeriod()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"付款周期不能为空");
}
if(null==record.getLease()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"租期不能为空");
}
if(null==record.getPrice()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"物业费不能为空");
}
if(null==record.getDeposit()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"押金不能为空");
}
if(record.getPrice().intValue()<=0){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"物业费要大于0");
}
if(record.getDeposit().intValue()<=0){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"押金要大于0");
}
if(null==record.getShopId()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"shopId不能为空");
}

WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(record.getRentContractId());
if(wxRentContract!=null){
if(wxRentContract.getStatus().equals(EnumRentContractStatus.CONTRACT_TERMINATE.getCode()) ||
wxRentContract.getStatus().equals(EnumRentContractStatus.WAIT_SIGN.getCode()) ||
wxRentContract.getStatus().equals(EnumRentContractStatus.INVALID.getCode())){
return new ResultData(ErrorCode.RENT_CONTRACT_IS_TERMINATED);
}
}
if(null==record.getMerchantId()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"merchantId不能为空");
}
WxMerchant merchant = wxMerchantMapper.selectByPrimaryKey(record.getMerchantId());
if(merchant==null){
return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND);
}
if(null==record.getReceivePeriod()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"付款周期不能为空");
}
if(null==record.getLease()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"租期不能为空");
}
if(null==record.getPrice()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"物业费不能为空");
}
if(null==record.getDeposit()){
return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"押金不能为空");
}
if(record.getPrice().intValue()<=0){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"物业费要大于0");
}
if(record.getDeposit().intValue()<=0){
return new ResultData(ErrorCode.SYS_PARAMETER_ERROR,"押金要大于0");
}

//保存物业合同信息
if (record.getId() == null) {
final IdWorker idWorker = IdWorker.get();
record.setId(idWorker.nextId());
Calendar instance = Calendar.getInstance();
@@ -423,6 +437,26 @@ public class WxPropertyContractServiceImpl implements WxPropertyContractService
return wxPropertyContractMapper.getRentContractList(params);
}

@Override
public ResultData endPropertyContractByRentContractId(Long rentContractId) {
WxPropertyContract wxPropertyContractParam = new WxPropertyContract();
wxPropertyContractParam.setRentContractId(rentContractId);
List<Map<String, Object>> contractData = wxPropertyContractMapper.queryPropertyContractData(wxPropertyContractParam);
if(contractData.size()==0){
return new ResultData(ErrorCode.PROPERTY_CONTRACT_IS_NOT_FOUND);
}
Map<String, Object> contractMap = contractData.get(0);
WxPropertyContract wxPropertyContract = wxPropertyContractMapper.selectByPrimaryKey(contractMap.get("id"));
wxPropertyContract.setStatus(EnumRentContractStatus.CONTRACT_TERMINATE.getCode());
try {
wxPropertyContractMapper.updateByPrimaryKeySelective(wxPropertyContract);
} catch (MallinkException e) {
logger.info("终止合同失败:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());
}
return new ResultData(Result.SUCCESS, "操作成功");
}

public Map<String, Object> updateStatus(String tenantId) {
Map<String, Object> resultData = new HashMap();
WxPropertyContract wxRentContract = new WxPropertyContract();


+ 20
- 5
mallinkService/src/main/java/com/iformall/service/impl/WxRentContractServiceImpl.java Просмотреть файл

@@ -12,10 +12,7 @@ import com.iformall.enums.EnumDelStatus;
import com.iformall.enums.EnumRentContractStatus;
import com.iformall.enums.EnumShopStatus;
import com.iformall.exception.MallinkException;
import com.iformall.mapper.WxBillDepositMapper;
import com.iformall.mapper.WxBillRentMapper;
import com.iformall.mapper.WxRentContractMapper;
import com.iformall.mapper.WxShopMapper;
import com.iformall.mapper.*;
import com.iformall.service.WxMerchantService;
import com.iformall.service.WxRentContractService;
import com.iformall.utils.Constant;
@@ -55,6 +52,9 @@ public class WxRentContractServiceImpl implements WxRentContractService {
@Autowired
WxBillDepositMapper wxBillDepositMapper;

@Autowired
WxPropertyContractMapper wxPropertyContractMapper;

@Override
public Map<String, Object> listAsPage(WxRentContract record, Integer pageIndex, Integer pageSize) {
Object rentContractStatusInfo = getRentContractStatusInfo(record.getTenantId());
@@ -408,7 +408,7 @@ public class WxRentContractServiceImpl implements WxRentContractService {

@Transactional(rollbackFor = {Exception.class})
@Override
public ResultData endRentContract(Long id) {
public ResultData endRentContract(Long id, Integer status) {

WxRentContract wxRentContract = wxRentContractMapper.selectByPrimaryKey(id);
if (wxRentContract == null) {
@@ -419,6 +419,21 @@ public class WxRentContractServiceImpl implements WxRentContractService {
wxRentContractMapper.updateByPrimaryKeySelective(wxRentContract);
//停用商户
wxMerchantService.disable(wxRentContract.getMerchantId());
//物业合同终止
if(status.equals("1")){
WxPropertyContract wxPropertyContract = new WxPropertyContract();
wxPropertyContract.setRentContractId(id);
List<Map<String, Object>> contractData = wxPropertyContractMapper.queryPropertyContractData(wxPropertyContract);
if(contractData.size()>0){
Map<String, Object> propertyContract = contractData.get(0);
Long propertyContractId = (Long) propertyContract.get("id");
if(propertyContract!=null && propertyContractId!=null){
WxPropertyContract propertyContractUpdate = wxPropertyContractMapper.selectByPrimaryKey(propertyContractId);
propertyContractUpdate.setStatus(EnumRentContractStatus.CONTRACT_TERMINATE.getCode());
wxPropertyContractMapper.updateByPrimaryKeySelective(propertyContractUpdate);
}
}
}
} catch (MallinkException e) {
logger.info("终止合同失败:" + e.getMessage());
throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage());


+ 13
- 3
mallinkService/src/main/resources/mapper/WxBillAllMapper.xml Просмотреть файл

@@ -22,7 +22,10 @@
) bill
left join wx_merchant m on bill.merchant_id=m.id
left join wx_shop s on bill.shop_id=s.id
where date_format(bill.receive_date,'%Y-%m')=#{month} and bill.tenant_id=#{tenantId}
where date_format(bill.receive_date,'%Y-%m')=#{month}
<if test=" null != tenantId ">
and bill.tenant_id=#{tenantId}
</if>
<if test=" null != merchantName and ''!=merchantName ">and m.`name` like concat('%',#{merchantName},'%')</if>
<if test=" null != billTypeValue ">and bill.bill_type_value = #{billTypeValue}</if>
<if test=" null != status ">and bill.`status` = #{status}</if>
@@ -80,7 +83,8 @@
<select id="listData" resultType="hashmap" parameterType="com.iformall.domain.vo.WxBillAll">
select bill.id,bill.merchant_id merchantId,bill.shop_id shopId,bill.bill_type_value billTypeValue,bill.bill_type billType,bill.need_pay needPay,
bill.receive_pay receivePay,bill.pay,bill.owe,bill.receive_date receiveDate,bill.pay_date payDate,bill.expired_day expiredDay,bill.status,
bill.tenant_id tenantId,m.name merchantName,s.shop_number shopNumber,bill.starttime,bill.endtime,bill.name,pb.pay_bill_status payBillStatus from (
bill.tenant_id tenantId,m.name merchantName,s.shop_number shopNumber,bill.starttime,bill.endtime,bill.name,pb.pay_bill_status payBillStatus,
pb.pay_time_end tradeTime,pb.transaction_id transactionId,pb.pay_amount payAmount from (
select id,merchant_id,shop_id,tenant_id,'租金' name,1 bill_type_value,'租金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime from wx_bill_rent
union
select id,merchant_id,shop_id,tenant_id,'租赁押金' name,2 bill_type_value,'租赁押金' bill_type,need_pay,receive_pay,pay,owe,receive_date,pay_date,expired_day,status,starttime,endtime from wx_bill_rent_deposit
@@ -98,7 +102,13 @@
left join wx_merchant m on bill.merchant_id=m.id
left join wx_shop s on bill.shop_id=s.id
left join wx_pay_bill pb on bill.id=pb.bill_id
where bill.tenant_id=#{tenantId}
where 1=1
<if test=" null != id ">
and bill.id=#{id}
</if>
<if test=" null != tenantId ">
and bill.tenant_id=#{tenantId}
</if>
<if test=" null != merchantId ">
and bill.merchant_id=#{merchantId}
</if>


+ 1
- 1
mallinkService/src/main/resources/mapper/WxPayBillMapper.xml Просмотреть файл

@@ -50,7 +50,7 @@
and `bill_id` = #{billId}
</if>

<if test=" null != cUserId ">
<if test=" null != bUserId ">
and `b_user_id` = #{bUserId}
</if>



+ 2
- 0
mallinkService/src/main/resources/mapper/WxPropertyContractMapper.xml Просмотреть файл

@@ -100,6 +100,8 @@
<if test=" null != shopNumber and shopNumber!=''">and s.`shop_number` like concat('%',#{shopNumber},'%')
</if>
<if test=" null != status ">and rc.`status` = #{status}</if>
<if test=" null != rentContractId">and rc.`rent_contract_id` = #{rentContractId}</if>
<if test=" null != id">and rc.`id` = #{id}</if>
</where>
order by rc.id desc
</select>


Загрузка…
Отмена
Сохранить