| @@ -218,6 +218,7 @@ public class WxBillAllController extends BaseController { | |||
| wxBillAll.setEndtime(wxBillAll.getEndtime() + " 23:59:59"); | |||
| } | |||
| wxBillAll.updateTenantInfo(getTenantInfo()); | |||
| wxBillAllService.exportOweBill(wxBillAll, request, response); | |||
| } | |||
| @@ -1028,4 +1028,6 @@ CREATE TABLE `wx_bill_settle_schedule` ( | |||
| PRIMARY KEY (`id`) | |||
| ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC COMMENT='结算单'; | |||
| ALTER TABLE `wx_pay_bill` ADD COLUMN `bill_type_value` int(1) NOT NULL DEFAULT 0 COMMENT '账单类型' ; | |||
| @@ -87,7 +87,7 @@ public class WxBillController extends BaseController { | |||
| logger.info("开始时间和结束时间要同时存在或不存在"); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(),"starttime和endtime要同时存在或不存在"); | |||
| } | |||
| return wxBillAllService.listBill(wxBillAll,wxMerchant); | |||
| return wxBillAllService.pageListBill(wxBillAll,wxMerchant,true,true,true); | |||
| } | |||
| @@ -33,7 +33,7 @@ public class WxPayBillController extends BaseController { | |||
| @Autowired | |||
| private WxPayBillService wxPayBillService; | |||
| @ApiOperation(value = "发起微信小程序支付订单", notes = "{\"billId\":\"string\",\"appId\":\"string\",\"openId\":\"string\",\"bUserId\":\"string\"}") | |||
| @ApiOperation(value = "发起微信小程序支付订单", notes = "{\"billTypeValue\":\"string\",\"billId\":\"string\",\"appId\":\"string\",\"openId\":\"string\",\"bUserId\":\"string\"}") | |||
| @RequestMapping(value = "/create", method = RequestMethod.POST) | |||
| public ResultData _create(@RequestBody Map<String, String> paramMap, HttpServletRequest request) throws Exception { | |||
| logger.info("/api/pay/create" + paramMap.toString()); | |||
| @@ -50,6 +50,19 @@ public class WxPayBillController extends BaseController { | |||
| } catch (NumberFormatException e) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "billId参数不正确"); | |||
| } | |||
| String billTypeValueStr = paramMap.get("billTypeValue"); | |||
| if (StringUtils.isEmpty(billTypeValueStr)) { | |||
| logger.info("billId不能为空: " + paramMap.toString()); | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "billTypeValue不能为空"); | |||
| } | |||
| Integer billTypeValue = null; | |||
| try { | |||
| billTypeValue = Integer.parseInt(billTypeValueStr); | |||
| } catch (NumberFormatException e) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "billTypeValue参数不正确"); | |||
| } | |||
| //b_user_id | |||
| String bUserIdStr = paramMap.get("bUserId"); | |||
| @@ -79,7 +92,7 @@ public class WxPayBillController extends BaseController { | |||
| record.updateTenantInfo(getTenantInfo()); | |||
| try { | |||
| record.setIp(IPUtil.getIpAddr(request)); | |||
| return wxPayBillService.createPayBill(appInfo, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| return wxPayBillService.createPayBill(billTypeValue,appInfo, record, EnumPayWay.PAY_WAY_WECHAT); | |||
| } catch (MallinkException e) { | |||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| @@ -2,6 +2,7 @@ package com.iformall.schedule; | |||
| import com.iformall.domain.vo.WxBillAll; | |||
| import com.iformall.mapper.WxBillAllMapper; | |||
| import com.iformall.mapper.WxBillSettleScheduleMapper; | |||
| import com.iformall.service.WxBillAllService; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| @@ -17,11 +18,11 @@ public class BillSchedule { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private WxBillAllMapper wxBillAllMapper; | |||
| @Autowired | |||
| WxBillAllService wxBillAllService; | |||
| @Autowired | |||
| WxBillSettleScheduleMapper wxBillSettleScheduleMapper; | |||
| /** | |||
| * 每天1点执行 | |||
| @@ -32,7 +33,7 @@ public class BillSchedule { | |||
| public void settleBill() { | |||
| WxBillAll wxBillAll = new WxBillAll(); | |||
| //wxBillAll.updateTenantInfo(wxBillAll); | |||
| List<Long> settleBillIdList = wxBillAllMapper.listToSettleBillIdList(wxBillAll); | |||
| List<Long> settleBillIdList = wxBillSettleScheduleMapper.listToSettleBillIdList(wxBillAll); | |||
| if (null != settleBillIdList && settleBillIdList.size() > 0 ) { | |||
| for (int i = 0 ; i < settleBillIdList.size(); i ++) { | |||
| Long settleId = settleBillIdList.get(i); | |||
| @@ -53,6 +53,9 @@ public class WxPayBill extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="openId",name="openId") | |||
| private String openId; | |||
| @io.swagger.annotations.ApiModelProperty(value="billTypeValue",name="billTypeValue") | |||
| private Integer billTypeValue; | |||
| public Long getbUserId() { | |||
| @@ -17,6 +17,14 @@ public enum EnumBillQueryType { | |||
| SETTLE(10, "结算单") | |||
| ; | |||
| public static Integer getRealType(Integer type) { | |||
| //查询的列表数据中 5:水费 6:电费 9:空调费 | |||
| if (type == 5 || type == 6 || type == 9) { | |||
| return WATER_POWER_AIR.getCode(); | |||
| } | |||
| return type; | |||
| } | |||
| public static EnumBillQueryType getEnum(Integer code) { | |||
| for (EnumBillQueryType value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| @@ -26,7 +26,8 @@ public interface WxBillAllService { | |||
| //List<Map<String, Object>> listBillOweAndWaitPay(WxBillAll wxBillAll); | |||
| ResultData listBill(WxBillAll wxBillAll,WxMerchant wxMerchant); | |||
| ResultData pageListBill(WxBillAll wxBillAll,WxMerchant wxMerchant,boolean hasShop,boolean hasPayBill,boolean hasReceivePay); | |||
| List<Map<String, Object>> listBill(WxBillAll wxBillAll,WxMerchant wxMerchant,boolean hasShop,boolean hasPayBill,boolean hasReceivePay); | |||
| void updateBill(Map<String, Object> bill); | |||
| @@ -19,7 +19,7 @@ public interface WxPayBillService { | |||
| * @param payWay | |||
| * @return | |||
| */ | |||
| ResultData createPayBill(WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay); | |||
| ResultData createPayBill(Integer billTypeValue,WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay); | |||
| /** | |||
| * 微信支付订单查询 | |||
| @@ -215,13 +215,20 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||
| // } | |||
| @Override | |||
| public ResultData listBill(WxBillAll wxBillAll,WxMerchant wxMerchant) { | |||
| public ResultData pageListBill(WxBillAll wxBillAll,WxMerchant wxMerchant,boolean hasShop,boolean hasPayBill,boolean hasReceivePay) { | |||
| //更新各账单状态 | |||
| //updateBillStatus(wxBillAll); | |||
| PageHelper.startPage(wxBillAll.getPageIndex(), wxBillAll.getPageSize()); | |||
| PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(listBill(wxBillAll, wxMerchant, hasShop, hasPayBill, hasReceivePay)); | |||
| return new ResultData(pageInfo); | |||
| } | |||
| @Override | |||
| public List<Map<String, Object>> listBill(WxBillAll wxBillAll,WxMerchant wxMerchant,boolean hasShop,boolean hasPayBill,boolean hasReceivePay){ | |||
| List<Map<String, Object>> maps = null; | |||
| //账单类型 | |||
| if (wxBillAll.getBillTypeValue() != null) { | |||
| wxBillAll.setBillTypeValue(EnumBillQueryType.getRealType(wxBillAll.getBillTypeValue())); | |||
| if (wxBillAll.getBillTypeValue().equals(EnumBillQueryType.RENT.getCode())) { | |||
| wxBillAll.setBillTypeValue(EnumBillQueryType.RENT.getCode()); | |||
| maps = wxBillAllMapper.listRentBillData(wxBillAll); | |||
| @@ -257,37 +264,42 @@ public class WxBillAllServiceImpl implements WxBillAllService { | |||
| Long id = (Long) map.get("id"); | |||
| WxBillSettle settle = wxBillSettleService.getById(id, EnumFilterSettle.YES.getCode()); | |||
| map.put("owe", settle.getBalance()); | |||
| settle = wxBillSettleService.getById(id, EnumFilterSettle.NO.getCode()); | |||
| map.put("receivePay", settle.getBalance()); | |||
| if (hasReceivePay) { | |||
| settle = wxBillSettleService.getById(id, EnumFilterSettle.NO.getCode()); | |||
| map.put("receivePay", settle.getBalance()); | |||
| } | |||
| } | |||
| if (null != wxMerchant) { | |||
| map.put("merchantName", wxMerchant.getName()); | |||
| } | |||
| map.put("merchantName", wxMerchant.getName()); | |||
| Long shopId = (Long) map.get("shopId"); | |||
| if (null != shopId) { | |||
| Map param = new HashMap(); | |||
| param.put("id", shopId); | |||
| Map<String, Object> shopResult = wxShopMapper.getMerchantShopByShopId(param); | |||
| if (null != shopResult) { | |||
| map.put("shopNumber", shopResult.get("shopNumber")); | |||
| } | |||
| if (hasShop) { | |||
| Long shopId = (Long) map.get("shopId"); | |||
| if (null != shopId) { | |||
| Map param = new HashMap(); | |||
| param.put("id", shopId); | |||
| Map<String, Object> shopResult = wxShopMapper.getMerchantShopByShopId(param); | |||
| if (null != shopResult) { | |||
| map.put("shopNumber", shopResult.get("shopNumber")); | |||
| } | |||
| } | |||
| } | |||
| Long billId = (Long) map.get("id"); | |||
| WxPayBill wxPayBill = new WxPayBill(); | |||
| wxPayBill.updateTenantInfo(wxMerchant); | |||
| wxPayBill.setBillId(billId); | |||
| List<WxPayBill> payBillList = wxPayBillMapper.findList(wxPayBill); | |||
| if (null != payBillList && payBillList.size() > 0 ) { | |||
| WxPayBill pb = payBillList.get(0); | |||
| map.put("payBillStatus", pb.getPayBillStatus()); | |||
| map.put("tradeTime", pb.getPayTimeEnd()); | |||
| map.put("transactionId", pb.getTransactionId()); | |||
| map.put("payAmount", pb.getPayAmount()); | |||
| if (hasPayBill) { | |||
| Long billId = (Long) map.get("id"); | |||
| WxPayBill wxPayBill = new WxPayBill(); | |||
| wxPayBill.updateTenantInfo(wxMerchant); | |||
| wxPayBill.setBillId(billId); | |||
| List<WxPayBill> payBillList = wxPayBillMapper.findList(wxPayBill); | |||
| if (null != payBillList && payBillList.size() > 0 ) { | |||
| WxPayBill pb = payBillList.get(0); | |||
| map.put("payBillStatus", pb.getPayBillStatus()); | |||
| map.put("tradeTime", pb.getPayTimeEnd()); | |||
| map.put("transactionId", pb.getTransactionId()); | |||
| map.put("payAmount", pb.getPayAmount()); | |||
| } | |||
| } | |||
| } | |||
| } | |||
| PageInfo<Map<String, Object>> pageInfo = new PageInfo<>(maps); | |||
| return new ResultData(pageInfo); | |||
| return maps; | |||
| } | |||
| @@ -24,6 +24,7 @@ import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.context.annotation.Lazy; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| @@ -50,12 +51,14 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| @Autowired | |||
| WxBillAllMapper wxBillAllMapper; | |||
| @Lazy | |||
| @Autowired | |||
| WxBillAllService wxBillAllService; | |||
| @Autowired | |||
| WxMerchantBUserMapper wxMerchantBUserMapper; | |||
| @Lazy | |||
| @Autowired | |||
| private WxBillSettleService wxBillSettleService; | |||
| @@ -89,7 +92,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| "\"XML_FORMAT_ERROR\":{\"detail\":\"XML格式错误\t\",\"reason\":\"XML格式错误\",\"reason\":\"请检查XML参数格式是否正确\"}}"); | |||
| @Override | |||
| public ResultData createPayBill(WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay) { | |||
| public ResultData createPayBill(Integer billTypeValue,WxAppinfo appInfo, WxPayBill record, EnumPayWay payWay) { | |||
| final IdWorker idworker = IdWorker.get(); | |||
| EnumPayShare isShare = EnumPayShare.NO; | |||
| @@ -98,7 +101,8 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| WxBillAll wxBillAll = new WxBillAll(); | |||
| wxBillAll.updateTenantInfo(record); | |||
| wxBillAll.setId(record.getBillId()); | |||
| List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); | |||
| wxBillAll.setBillTypeValue(billTypeValue); | |||
| List<Map<String, Object>> bills = wxBillAllService.listBill(wxBillAll,null,false,false,false); | |||
| 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); | |||
| @@ -106,14 +110,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| //获取账单数据 | |||
| Map<String, Object> bill = bills.get(0); | |||
| Long owe = (Long) bill.get("owe"); | |||
| Integer billTypeValue = ((Long) bill.get("billTypeValue")).intValue(); | |||
| if(EnumBillType.SETTLE.getCode().equals(billTypeValue)){ | |||
| WxBillSettle wxBillSettle = wxBillSettleService.getById(record.getBillId(), EnumFilterSettle.YES.getCode()); | |||
| owe = wxBillSettle.getBalance(); | |||
| bill.put("owe",owe); | |||
| logger.info("wxBillSettle.balance:{}",owe); | |||
| } | |||
| if (owe.longValue() <= 0) { | |||
| logger.info("账单欠缴为0"); | |||
| return new ResultData(ErrorCode.BILL_OWE_ZERO); | |||
| @@ -144,7 +141,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| record.setPayVendor(payWay.getCode()); | |||
| record.setPayBillStatus(EnumPayStatus.PAY_STATUS_WAIT.getCode()); | |||
| record.setShare(isShare.getCode()); | |||
| record.setBillTypeValue(billTypeValue); | |||
| int sqlRow = wxPayBillMapper.insert(record); | |||
| if (sqlRow != 1) { | |||
| logger.error("pay bill insert error: " + JSONObject.toJSONString(record)); | |||
| @@ -711,7 +708,8 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| wxPayBillMapper.updateById(record); | |||
| WxBillAll wxBillAll = new WxBillAll(); | |||
| wxBillAll.setId(record.getBillId()); | |||
| List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); | |||
| wxBillAll.setBillTypeValue(record.getBillTypeValue()); | |||
| List<Map<String, Object>> bills = wxBillAllService.listBill(wxBillAll, null, false, false, false); | |||
| if (bills.size() > 0) { | |||
| Map<String, Object> bill = bills.get(0); | |||
| bill.put("userId", record.getbUserId()); | |||
| @@ -726,7 +724,7 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| WxBillAll wxBillAll = new WxBillAll(); | |||
| wxBillAll.setId(record.getBillId()); | |||
| wxBillAll.updateTenantInfo(record); | |||
| List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); | |||
| List<Map<String, Object>> bills = wxBillAllService.listBill(wxBillAll, null, false, false, false); | |||
| 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); | |||
| @@ -769,7 +767,8 @@ public class WxPayBillServiceImpl implements WxPayBillService { | |||
| } | |||
| WxBillAll wxBillAll = new WxBillAll(); | |||
| wxBillAll.setId(record.getBillId()); | |||
| List<Map<String, Object>> bills = wxBillAllMapper.listData(wxBillAll); | |||
| wxBillAll.setBillTypeValue(record.getBillTypeValue()); | |||
| List<Map<String, Object>> bills = wxBillAllService.listBill(wxBillAll, null, false, false, false); | |||
| if (bills.size()==0) { | |||
| logger.error("pay handle, bill " + record.getBillId() + " not found , payBillNo : " + record.getPayBillNo()); | |||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | |||
| @@ -22,10 +22,12 @@ | |||
| <result column="share_amount" jdbcType="INTEGER" property="shareAmount"/> | |||
| <result column="fail_reason" jdbcType="VARCHAR" property="failReason"/> | |||
| <result column="open_id" jdbcType="VARCHAR" property="openId"/> | |||
| <result column="bill_type_value" jdbcType="VARCHAR" property="billTypeValue"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`create_time`,`update_time`,`bill_id`,`b_user_id`,`ip`,`pay_amount`,`pay_time_start`,`pay_time_end`,`prepay_id`,`transaction_id`,`pay_vendor`,`pay_bill_no`,`pay_bill_status`,`share`,`share_amount`,`fail_reason`,`open_id` | |||
| `id`,`tenant_id`,`parent_tenant_id`,`create_time`,`update_time`,`bill_id`,`b_user_id`,`ip`,`pay_amount`,`pay_time_start`,`pay_time_end`,`prepay_id`,`transaction_id`,`pay_vendor`, | |||
| `pay_bill_no`,`pay_bill_status`,`share`,`share_amount`,`fail_reason`,`open_id`,`bill_type_value` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -85,6 +87,10 @@ | |||
| <if test=" null != payVendor "> | |||
| and `pay_vendor` = #{payVendor} | |||
| </if> | |||
| <if test=" null != billTypeValue "> | |||
| and `bill_type_value` = #{billTypeValue} | |||
| </if> | |||
| <if test=" null != payBillNo "> | |||
| and `pay_bill_no` like concat('%', #{payBillNo},'%') | |||