| @@ -10,6 +10,8 @@ import com.iformall.exception.MallinkException; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.IPUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| import org.slf4j.Logger; | |||
| @@ -211,4 +213,13 @@ public class WxMicroPayController extends BaseController { | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| @ApiOperation("某日期扫码支付总流水") | |||
| @GetMapping("getMicroPayAmountOnDate") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "date", value = "日期yyyy-MM-dd", dataType = "string", paramType = "query")}) | |||
| public ResultData getUnverifiedAmountOnDate(String date) { | |||
| //return wxCouponOrderService.listOnDateAsPage(getUser().getId(), date, null, null, false); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -8,7 +8,7 @@ public enum EnumPayStatus { | |||
| PAY_STATUS_UNKNOWN(-1, "未知"), | |||
| PAY_STATUS_WAIT(0, "支付中"), | |||
| PAY_STATUS_SUCCESS(1, "支付成功"), | |||
| PAY_STATUS_ERR(2, "支付错误"), | |||
| PAY_STATUS_FAIL(2, "支付错误"), | |||
| PAY_STATUS_CANCEL(3, "取消支付"), | |||
| PAY_STATUS_CANCEL_FAIL(4,"取消支付失败"), | |||
| PAY_STATUS_CLOSE(5, "关闭支付订单"), | |||
| @@ -63,6 +63,13 @@ public interface WxOrderService { | |||
| */ | |||
| int orderSuccess(WxOrder updateOrder); | |||
| /** | |||
| * microPayOrderSuccess 刷卡支付成功 | |||
| * @param updateOrder | |||
| * @return | |||
| */ | |||
| int microPayOrderSuccess(WxOrder updateOrder); | |||
| /** | |||
| * updateOrderStatus 更新订单状态, 只针对已取消及已退款 | |||
| * @param updateOrder | |||
| @@ -68,6 +68,14 @@ public interface WxPayOrderService { | |||
| */ | |||
| void handleOrderPaySuccess(WxPayOrder record, String transactionId); | |||
| /** | |||
| * 刷卡支付成功处理 | |||
| * | |||
| * @param record | |||
| * @param transactionId | |||
| */ | |||
| void handleMicroOrderPaySuccess(WxPayOrder record, String transactionId, String openId, String isSubscribe); | |||
| /** | |||
| * 支付状态处理 | |||
| * | |||
| @@ -21,6 +21,8 @@ import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.math.BigDecimal; | |||
| import java.text.ParseException; | |||
| import java.text.SimpleDateFormat; | |||
| import java.util.*; | |||
| @Service | |||
| @@ -61,6 +63,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Autowired | |||
| WxPayOrderMapper wxPayOrderMapper; | |||
| @Autowired | |||
| WxMerchantBUserMapper wxMerchantBUserMapper; | |||
| @Autowired | |||
| WxPayOrderService wxPayOrderService; | |||
| @@ -599,12 +604,42 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| logger.error("订单更新失败:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
| } | |||
| // 创建couponOrder | |||
| // 创建couponOrder | |||
| try { | |||
| createCouponOrder(user, updateOrder, coupon); | |||
| } catch (Exception e) { | |||
| logger.error("保存订单:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| } | |||
| // 成长值 计算 | |||
| try { | |||
| createCouponOrder(user, updateOrder, coupon); | |||
| wxScoreRulesService.addScore(EnumScoreType.CONSUMPTION,updateOrder); | |||
| } catch (Exception e) { | |||
| logger.error("保存订单:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.COUPON_ORDER_SAVE_ERR); | |||
| logger.error("成长值:" + e.getMessage()); | |||
| } | |||
| return ret; | |||
| } | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public int microPayOrderSuccess(WxOrder updateOrder) { | |||
| Date currentDate = new Date(); | |||
| WxCUser user = wxCUserMapper.selectByPrimaryKey(updateOrder.getCUserId()); | |||
| if (user == null) { | |||
| logger.error("用户不存在, userId: " + updateOrder.getCUserId()); | |||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||
| } | |||
| // 已支付,更新支付时间 | |||
| updateOrder.setPaymentTime(currentDate); | |||
| updateOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||
| updateOrder.setUpdateDate(currentDate); | |||
| int ret = 0; | |||
| try { | |||
| ret = wxOrderMapper.updateByPrimaryKey(updateOrder); | |||
| } catch (Exception e) { | |||
| logger.error("订单更新失败:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.ORDER_UPDATE_ERR); | |||
| } | |||
| // 成长值 计算 | |||
| @@ -613,6 +648,8 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } catch (Exception e) { | |||
| logger.error("成长值:" + e.getMessage()); | |||
| } | |||
| //// TODO 支付发券 | |||
| return ret; | |||
| } | |||
| @@ -712,4 +749,69 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| return wxOrderMapper.selectDetailOfCUser(record); | |||
| } | |||
| /* | |||
| @Override | |||
| public ResultData microPayListOnDateAsPage(Long bUserId, String date, Integer pageIndex, Integer pageSize) { | |||
| WxMerchantBUser wxMerchantBUser = wxMerchantBUserMapper.selectByPrimaryKey(bUserId.longValue()); | |||
| if (wxMerchantBUser == null) { | |||
| logger.error("B端用户不存在:" + bUserId); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||
| } | |||
| WxMerchant wxMerchant = wxMerchantMapper.selectByPrimaryKey(wxMerchantBUser.getMerchantId()); | |||
| if (wxMerchant == null) { | |||
| logger.error("商户不存在:" + bUserId); | |||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||
| } | |||
| SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); | |||
| String dateString; | |||
| Date startDate; | |||
| Date endDate; | |||
| if (date == null) { | |||
| endDate = new Date(); | |||
| dateString = fmt.format(new Date()); | |||
| try { | |||
| startDate = fmt.parse(dateString); | |||
| } catch (ParseException e) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||
| } | |||
| } else { | |||
| try { | |||
| startDate = fmt.parse(date); | |||
| } catch (ParseException e) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR); | |||
| } | |||
| Calendar cal = Calendar.getInstance(); | |||
| cal.setTime(startDate); | |||
| cal.add(Calendar.DATE, 1); | |||
| endDate = cal.getTime(); | |||
| } | |||
| Map dateMap = new HashMap(); | |||
| dateMap.put("startDate", startDate); | |||
| dateMap.put("endDate", endDate); | |||
| dateMap.put("merchantID", wxMerchant.getId()); | |||
| Map resultMap = new HashMap(); | |||
| if (pageIndex == null || pageSize == null) { | |||
| List<WxCouponOrder> list; | |||
| list = wxOrderMapper.findListOfOrderedByDate(dateMap); | |||
| logger.info("find " + list.size() + " coupon order from " + startDate + " to " + new Date()); | |||
| int total_price = 0; | |||
| for (WxCouponOrder couponOrder : list) { | |||
| total_price = total_price + couponOrder.getCouponPrice(); | |||
| } | |||
| resultMap.put("amount", total_price); | |||
| } else { | |||
| resultMap.put("list", PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponOrderMapper.findListOfOrderedByDateForBUser(dateMap))); | |||
| } | |||
| return new ResultData(resultMap); | |||
| } | |||
| */ | |||
| } | |||
| @@ -461,22 +461,11 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| String openId = returnMap.get("openid"); | |||
| String isSubscribe = returnMap.get("is_subscribe"); | |||
| String transactionId = returnMap.get("transaction_id"); | |||
| String err_code = returnMap.get("err_code"); | |||
| String errMsg = returnMap.get("err_code_des"); | |||
| if(errMsg.length() <= 0) { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| record.setTransactionId(transactionId); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return new ResultData(Result.SUCCESS, errMsg, returnMap); | |||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||
| } else { | |||
| String err_code = returnMap.get("err_code"); | |||
| String errMsg = returnMap.get("err_code_des"); | |||
| @@ -544,23 +533,11 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| String openId = returnMap.get("openid"); | |||
| String isSubscribe = returnMap.get("is_subscribe"); | |||
| String transactionId = returnMap.get("transaction_id"); | |||
| String err_code = returnMap.get("err_code"); | |||
| String errMsg = returnMap.get("err_code_des"); | |||
| if(errMsg.length() <= 0) { | |||
| errMsg = returnMap.get("return_msg"); | |||
| } | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| record.setTransactionId(transactionId); | |||
| record.setUpdateTime(new Date()); | |||
| try { | |||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||
| } catch (Exception e) { | |||
| logger.error("pay order update error: " + record.toString()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| // TODO update order | |||
| return new ResultData(Result.SUCCESS, errMsg, returnMap); | |||
| handleMicroOrderPaySuccess(record, transactionId, openId, isSubscribe); | |||
| return new ResultData(Result.SUCCESS, "刷卡支付成功", returnMap); | |||
| } else { | |||
| String err_code = returnMap.get("err_code"); | |||
| String errMsg = returnMap.get("err_code_des"); | |||
| @@ -717,7 +694,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| // handlePayOrderStatusUpdate(record); | |||
| return new ResultData(ErrorCode.PAY_ORDER_PAYING, returnMap); | |||
| } else { | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_ERR.getCode()); | |||
| record.setPayOrderStatus(EnumPayStatus.PAY_STATUS_FAIL.getCode()); | |||
| // handlePayOrderStatusUpdate(record); | |||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, returnMap); | |||
| } | |||
| @@ -1179,6 +1156,92 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| */ | |||
| } | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void handleMicroOrderPaySuccess(WxPayOrder record, String transactionId, String openId, String isSubscribe) { | |||
| Date currentDate = new Date(); | |||
| EnumPayStatus payStatus = EnumPayStatus.getEnum(record.getPayOrderStatus()); | |||
| // 判断支付状态 | |||
| if (payStatus == EnumPayStatus.PAY_STATUS_SUCCESS) { | |||
| // 已经是成功状态,只更新transactionId | |||
| try { | |||
| record.setUpdateTime(currentDate); | |||
| record.setTransactionId(transactionId); | |||
| wxPayOrderMapper.updateByPrimaryKeySelective(record); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| return; | |||
| } | |||
| if (payStatus != EnumPayStatus.PAY_STATUS_WAIT) { | |||
| logger.info("pay success handle, payOrder " + record.getPayOrderNo() + | |||
| "is paid success , orderId : " + record.getOrderId()); | |||
| return; | |||
| } | |||
| // add c_user | |||
| Date curDate = new Date(); | |||
| WxCUser userQ = new WxCUser(); | |||
| userQ.setOpenId(openId); | |||
| userQ.setCreateDate(curDate); | |||
| userQ.setUpdateDate(curDate); | |||
| WxCUser user1 = wxCUserMapper.findByOpenId(userQ); | |||
| if(user1 == null) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| userQ.setId(idWorker.nextId()); | |||
| wxCUserMapper.insertSelective(userQ); | |||
| } else { | |||
| userQ.setId(user1.getId()); | |||
| } | |||
| WxOrder order = wxOrderMapper.selectByPrimaryKey(record.getOrderId()); | |||
| if (order == null) { | |||
| logger.error("pay success handle, order " + record.getOrderId() + " not found , payOrderid : " + record.getPayOrderNo()); | |||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | |||
| } | |||
| // 修改支付订单状态 | |||
| WxPayOrder updateOrder = new WxPayOrder(); | |||
| updateOrder.setId(record.getId()); | |||
| updateOrder.setOrderId(record.getOrderId()); | |||
| updateOrder.setUpdateTime(currentDate); | |||
| updateOrder.setPayOrderStatus(EnumPayStatus.PAY_STATUS_SUCCESS.getCode()); | |||
| updateOrder.setTransactionId(transactionId); | |||
| try { | |||
| wxPayOrderMapper.updateByPrimaryKeySelective(updateOrder); | |||
| } catch (Exception e) { | |||
| logger.error("支付订单数据库更新失败: " + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "支付订单数据库更新失败: " + e.getMessage()); | |||
| } | |||
| // 修改订单状态 | |||
| order.setCUserId(user1.getId()); | |||
| try { | |||
| int _count = wxOrderService.microPayOrderSuccess(order); | |||
| if (_count > 1) { | |||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||
| } | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | |||
| } | |||
| /* | |||
| Map<String, String> msgMap = new HashMap<>(); | |||
| try { | |||
| msgMap.put("name", String.valueOf(order.getCouponId())); | |||
| msgMap.put("orderNo", String.valueOf(order.getId())); | |||
| msgMap.put("createTime", Utility.getDataFormatString3(order.getCreateDate())); | |||
| msgMap.put("standingTime", order.getCreateDate() + "-" + currentDate ); | |||
| // 短信 通知 商户 | |||
| //smsSenderHandler.sendSms("SMS_18195394", order.getMobile(), msgMap); | |||
| } catch (Exception e) { | |||
| logger.error("pay success handle, sms send exception, payOrderi: " + updatePayOrder+ ", msgMap: " + msgMap.toString() + ", e: " + e.getMessage()); | |||
| } | |||
| */ | |||
| } | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public void handlePayOrderStatusUpdate(WxPayOrder record) { | |||
| @@ -1241,8 +1304,8 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| throw new MallinkException(ErrorCode.PAY_ORDER_NOT_FOUND); | |||
| } | |||
| if (record.getPayOrderStatus() == EnumPayStatus.PAY_STATUS_CANCEL.getCode()) { | |||
| // 支付订单取消 | |||
| if (record.getPayOrderStatus() == EnumPayStatus.PAY_STATUS_FAIL.getCode()) { | |||
| // 支付订单失败,取消此订单 | |||
| if (record.getPayAmount() > 0) { | |||
| payOrderQ = new WxPayOrder(); | |||
| payOrderQ.setTenantId(order.getTenantId()); | |||
| @@ -238,5 +238,23 @@ | |||
| </select> | |||
| <select id="dayMicroPayAmountList" parameterType="com.iformall.domain.po.WxOrder" resultType="java.lang.Integer"> | |||
| select count(*) from wx_order | |||
| where 1=1 | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != cUserId "> | |||
| and `c_user_id` = #{cUserId} | |||
| </if> | |||
| <if test=" null != couponId "> | |||
| and `coupon_id` = #{couponId} | |||
| </if> | |||
| <if test=" null != orderStatus "> | |||
| and `order_status` = #{orderStatus} | |||
| </if> | |||
| and `create_date` between date_sub(now(),interval 1 day) and now() | |||
| </select> | |||
| </mapper> | |||