| @@ -0,0 +1,24 @@ | |||||
| package com.simple.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -22,10 +22,14 @@ import com.simple.domain.dto.WxCuerBasicInfoDto; | |||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| import com.simple.domain.po.WxCUserBasicInfo; | import com.simple.domain.po.WxCUserBasicInfo; | ||||
| import com.simple.domain.po.WxCUserTags; | import com.simple.domain.po.WxCUserTags; | ||||
| import com.simple.domain.po.WxCoupon; | |||||
| import com.simple.domain.po.WxCouponOrder; | |||||
| import com.simple.domain.po.WxTags; | import com.simple.domain.po.WxTags; | ||||
| import com.simple.service.WxCUserBasicInfoService; | import com.simple.service.WxCUserBasicInfoService; | ||||
| import com.simple.service.WxCUserService; | import com.simple.service.WxCUserService; | ||||
| import com.simple.service.WxCUserTagsService; | import com.simple.service.WxCUserTagsService; | ||||
| import com.simple.service.WxCouponOrderService; | |||||
| import com.simple.service.WxCouponService; | |||||
| import com.simple.service.WxTagsService; | import com.simple.service.WxTagsService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| @@ -49,6 +53,12 @@ public class WxCUserBasicInfoController extends BaseController | |||||
| @Autowired | @Autowired | ||||
| private WxCUserService wxCUserService; | private WxCUserService wxCUserService; | ||||
| @Autowired | |||||
| private WxCouponOrderService wxCouponOrderService; | |||||
| @Autowired | |||||
| private WxCouponService wxCouponService; | |||||
| private Logger logger = Logger.getLogger(WxCUserBasicInfoController.class); | private Logger logger = Logger.getLogger(WxCUserBasicInfoController.class); | ||||
| @@ -100,17 +110,18 @@ public class WxCUserBasicInfoController extends BaseController | |||||
| @ApiOperation("根据id更新接口") | @ApiOperation("根据id更新接口") | ||||
| @PostMapping("update") | @PostMapping("update") | ||||
| public ResultData update(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) { | public ResultData update(@RequestBody WxCUserBasicInfo wxCUserBasicInfo) { | ||||
| WxCUserBasicInfo info = wxCUserBasicInfoService.getById(wxCUserBasicInfo.getId()); | |||||
| wxCUserBasicInfo.setTenantId(getTenantId()); | wxCUserBasicInfo.setTenantId(getTenantId()); | ||||
| if(StringUtils.isNotBlank(wxCUserBasicInfo.getTags())) { | |||||
| if(StringUtils.isNotBlank(wxCUserBasicInfo.getTagIds())) { | |||||
| WxCUserTags record =new WxCUserTags(); | WxCUserTags record =new WxCUserTags(); | ||||
| record.setUserId(wxCUserBasicInfo.getCUserId()); | |||||
| record.setUserId(info.getCUserId()); | |||||
| record.setTenantId(getTenantId()); | record.setTenantId(getTenantId()); | ||||
| PageInfo<WxCUserTags> page = wxCUserTagsService.listAsPage(record, 1, 1); | PageInfo<WxCUserTags> page = wxCUserTagsService.listAsPage(record, 1, 1); | ||||
| if(page.getSize()>0) { | if(page.getSize()>0) { | ||||
| WxCUserTags t = page.getList().get(0); | WxCUserTags t = page.getList().get(0); | ||||
| record.setId(t.getId()); | record.setId(t.getId()); | ||||
| } | } | ||||
| String tags = wxCUserBasicInfo.getTags(); | |||||
| String tags = wxCUserBasicInfo.getTagIds(); | |||||
| List<Long> tagIdList = new ArrayList<>(); | List<Long> tagIdList = new ArrayList<>(); | ||||
| for(String t:tags.split(",")) { | for(String t:tags.split(",")) { | ||||
| tagIdList.add(Long.valueOf(t)); | tagIdList.add(Long.valueOf(t)); | ||||
| @@ -143,13 +154,43 @@ public class WxCUserBasicInfoController extends BaseController | |||||
| WxTags wxTags =new WxTags(); | WxTags wxTags =new WxTags(); | ||||
| wxTags.setIds(ids); | wxTags.setIds(ids); | ||||
| PageInfo<WxTags> page = wxTagsService.listAsPage(wxTags, 1, 5000); | PageInfo<WxTags> page = wxTagsService.listAsPage(wxTags, 1, 5000); | ||||
| if(page.getSize()>0) { | |||||
| info.setTagList(page.getList()); | |||||
| String tagNames=""; | |||||
| String tagIds=""; | |||||
| List<Long> tagIdList = new ArrayList<>(); | |||||
| for(WxTags wt:page.getList()) { | |||||
| tagNames+=wt.getName()+"/"; | |||||
| tagIds+=wt.getId()+","; | |||||
| tagIdList.add(wt.getId()); | |||||
| } | |||||
| if(StringUtils.isNotBlank(tagNames)) { | |||||
| info.setTagNames(tagNames.substring(0,tagNames.length()-1)); | |||||
| } | } | ||||
| if(StringUtils.isNoneBlank(tagIds)) { | |||||
| info.setTagIds(tagIds.substring(0,tagIds.length()-1)); | |||||
| } | |||||
| long count = wxCUserTagsService.findCountByTag(tagIdList); | |||||
| info.setCount(count); | |||||
| } | } | ||||
| } | } | ||||
| return new ResultData(Result.SUCCESS,"查询成功",info); | return new ResultData(Result.SUCCESS,"查询成功",info); | ||||
| } | } | ||||
| @ApiOperation("根据userId查询交易记录接口") | |||||
| @GetMapping("/findOrderCouponByUserId") | |||||
| @ApiImplicitParam(name="userId",value="userId",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData findOrderCouponByUserId(Long userId,Integer pageNum, Integer pageSize) { | |||||
| WxCouponOrder corder = new WxCouponOrder(); | |||||
| corder.setCUserId(userId); | |||||
| corder.setTenantId(getTenantId()); | |||||
| PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(corder, pageNum, pageSize); | |||||
| if(page.getSize()>0) { | |||||
| List<WxCouponOrder> list = page.getList(); | |||||
| for(WxCouponOrder c:list) { | |||||
| WxCoupon coupon = wxCouponService.getById(c.getCouponId()); | |||||
| c.setCouponName(coupon.getTitle()); | |||||
| c.setSalePrice(coupon.getPrice()); | |||||
| } | |||||
| } | |||||
| return new ResultData(Result.SUCCESS,"查询成功",page); | |||||
| } | |||||
| } | } | ||||
| @@ -70,6 +70,12 @@ public class WxMallBuildingController extends BaseController | |||||
| return wxMallBuildingService.getbuildinglist(getTenantId()); | return wxMallBuildingService.getbuildinglist(getTenantId()); | ||||
| } | } | ||||
| @ApiOperation("获取楼层楼座数据") | |||||
| @GetMapping("getbuildingfloorlist") | |||||
| public ResultData getbuildingfloorlist() { | |||||
| return wxMallBuildingService.getbuildingfloorlist(getTenantId()); | |||||
| } | |||||
| } | } | ||||
| @@ -37,3 +37,6 @@ pagehelper: | |||||
| mapper: | mapper: | ||||
| mappers: | mappers: | ||||
| - com.simple.common.CommonMapper | - com.simple.common.CommonMapper | ||||
| pay: | |||||
| real: false | |||||
| @@ -0,0 +1,24 @@ | |||||
| package com.simple.config; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -39,24 +39,32 @@ public class WxDateAmountRecordController extends BaseController | |||||
| public ResultData getRecord() { | public ResultData getRecord() { | ||||
| Calendar c =Calendar.getInstance(); | Calendar c =Calendar.getInstance(); | ||||
| int weekOfYear =c.get(Calendar.WEEK_OF_YEAR); | int weekOfYear =c.get(Calendar.WEEK_OF_YEAR); | ||||
| int day =c.get(Calendar.DAY_OF_WEEK); | |||||
| WxDateAmountRecord temp = new WxDateAmountRecord(); | WxDateAmountRecord temp = new WxDateAmountRecord(); | ||||
| temp.setDayOfWeek(weekOfYear); | |||||
| temp.setWeekOfYear(weekOfYear); | |||||
| WxMerchantBUser u = getUser(); | WxMerchantBUser u = getUser(); | ||||
| temp.setTenantId(u.getTenantId()); | temp.setTenantId(u.getTenantId()); | ||||
| temp.setMerchantId(u.getMerchantId()); | temp.setMerchantId(u.getMerchantId()); | ||||
| AmountRecordVo vo = new AmountRecordVo(); | AmountRecordVo vo = new AmountRecordVo(); | ||||
| vo.setOrderAmountList(getAmountRecord(temp, 0)); | |||||
| vo.setVerifyAmountList(getAmountRecord(temp, 0)); | |||||
| vo.setOrderAmountList(getAmountRecord(temp, day,0,vo)); | |||||
| vo.setVerifyAmountList(getAmountRecord(temp,day, 1,vo)); | |||||
| return new ResultData(Result.SUCCESS,"ok",vo); | return new ResultData(Result.SUCCESS,"ok",vo); | ||||
| } | } | ||||
| private List<WxDateAmountRecord> getAmountRecord( WxDateAmountRecord temp,int type){ | |||||
| private List<WxDateAmountRecord> getAmountRecord( WxDateAmountRecord temp,int day ,int type,AmountRecordVo vo){ | |||||
| temp.setType(type); | temp.setType(type); | ||||
| List<WxDateAmountRecord> list =new ArrayList<>(); | List<WxDateAmountRecord> list =new ArrayList<>(); | ||||
| for(int i=1;i<=7;i++) {//周日是1 | for(int i=1;i<=7;i++) {//周日是1 | ||||
| temp.setDayOfWeek(i); | temp.setDayOfWeek(i); | ||||
| PageInfo<WxDateAmountRecord> page = wxDateAmountRecordService.listAsPage(temp, 1, 1); | PageInfo<WxDateAmountRecord> page = wxDateAmountRecordService.listAsPage(temp, 1, 1); | ||||
| if(page.getSize()>0) { | if(page.getSize()>0) { | ||||
| if(i==day ) { | |||||
| if(type==0) { | |||||
| vo.setOrderAmount(page.getList().get(0).getPayPrice()); | |||||
| }else { | |||||
| vo.setVerifyAmount(page.getList().get(0).getPayPrice()); | |||||
| } | |||||
| } | |||||
| list.add(page.getList().get(0)); | list.add(page.getList().get(0)); | ||||
| } | } | ||||
| } | } | ||||
| @@ -1,7 +1,12 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxMerchant; | |||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| import com.simple.domain.po.WxMsgValidationcode; | import com.simple.domain.po.WxMsgValidationcode; | ||||
| import com.simple.service.WxMerchantBUserService; | |||||
| import com.simple.service.WxMerchantService; | |||||
| import com.simple.service.WxMsgValidationcodeService; | import com.simple.service.WxMsgValidationcodeService; | ||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| @@ -21,6 +26,14 @@ public class WxMsgValidationcodeController extends BaseController { | |||||
| @Autowired | @Autowired | ||||
| private WxMsgValidationcodeService wxMsgValidationcodeService; | private WxMsgValidationcodeService wxMsgValidationcodeService; | ||||
| @Autowired | |||||
| private WxMerchantBUserService wxMerchantBUserService; | |||||
| @Autowired | |||||
| private WxMerchantService wxMerchantService; | |||||
| @GetMapping("sendvalidationcode") | @GetMapping("sendvalidationcode") | ||||
| @ApiImplicitParams({ | @ApiImplicitParams({ | ||||
| @ApiImplicitParam(name = "tenantId", value = "租户ID", dataType = "String", paramType = "query"), | @ApiImplicitParam(name = "tenantId", value = "租户ID", dataType = "String", paramType = "query"), | ||||
| @@ -28,6 +41,29 @@ public class WxMsgValidationcodeController extends BaseController { | |||||
| @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true), | @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true), | ||||
| @ApiImplicitParam(name = "appid", value = "appid", dataType = "String", paramType = "query", required = true)}) | @ApiImplicitParam(name = "appid", value = "appid", dataType = "String", paramType = "query", required = true)}) | ||||
| public ResultData sendvalidationcode(String tenantId, String phone, Integer type, String appid) { | public ResultData sendvalidationcode(String tenantId, String phone, Integer type, String appid) { | ||||
| WxMerchantBUser user = new WxMerchantBUser(); | |||||
| user.setAppId(appid); | |||||
| user.setPhone(phone); | |||||
| WxMerchantBUser buser=wxMerchantBUserService.getBUserByAppId(user); | |||||
| if (buser==null) { | |||||
| logger.error("B端用户不存在, phone: " + phone); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| WxMerchant merchant = wxMerchantService.getById(user.getMerchantId()); | |||||
| if (merchant==null) { | |||||
| logger.error("B端所在商户不存在, id: " + user.getMerchantId()); | |||||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||||
| } | |||||
| if(merchant.getStatus()==0){ | |||||
| logger.error("B端所在商户已停用, id: " + merchant.getId()); | |||||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_VALID); | |||||
| } | |||||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | ||||
| wxMsgValidationcode.setTenantId(tenantId); | wxMsgValidationcode.setTenantId(tenantId); | ||||
| wxMsgValidationcode.setPhone(phone); | wxMsgValidationcode.setPhone(phone); | ||||
| @@ -101,8 +101,17 @@ public class WxOrderController extends BaseController { | |||||
| orderId = Long.valueOf(orderIdStr); | orderId = Long.valueOf(orderIdStr); | ||||
| } catch (NumberFormatException e) { | } catch (NumberFormatException e) { | ||||
| logger.error("orderId " + orderIdStr + ", e:" + e.getMessage()); | logger.error("orderId " + orderIdStr + ", e:" + e.getMessage()); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID转换异常"); | |||||
| } | } | ||||
| wxOrderService.updateOrderStatus(orderId, EnumOrderStatus.ORDER_STATUS_PENDING_REFUND); | |||||
| try { | |||||
| WxOrder order = wxOrderService.getById(orderId); | |||||
| if (order != null) { | |||||
| wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_PENDING_REFUND); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error("orderId " + orderIdStr + ", e:" + e.getMessage()); | |||||
| } | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| } | } | ||||
| @@ -4,12 +4,12 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.common.Result; | import com.simple.common.Result; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxAppinfo; | |||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| import com.simple.domain.po.WxRefundOrder; | |||||
| import com.simple.config.PayProperty; | |||||
| import com.simple.domain.po.*; | |||||
| import com.simple.enums.EnumPayStatus; | |||||
| import com.simple.enums.EnumPayWay; | import com.simple.enums.EnumPayWay; | ||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.service.WxRefundOrderService; | |||||
| import com.simple.service.*; | |||||
| import io.swagger.annotations.Api; | import io.swagger.annotations.Api; | ||||
| import io.swagger.annotations.ApiImplicitParam; | import io.swagger.annotations.ApiImplicitParam; | ||||
| import io.swagger.annotations.ApiImplicitParams; | import io.swagger.annotations.ApiImplicitParams; | ||||
| @@ -27,25 +27,33 @@ import java.util.Map; | |||||
| public class WxRefundOrderController extends BaseController { | public class WxRefundOrderController extends BaseController { | ||||
| private Logger logger = Logger.getLogger(WxRefundOrderController.class); | private Logger logger = Logger.getLogger(WxRefundOrderController.class); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | |||||
| private WxCouponOrderService wxCouponOrderService; | |||||
| @Autowired | |||||
| private WxOrderService wxOrderService; | |||||
| @Autowired | |||||
| private WxPayOrderService wxPayOrderService; | |||||
| @Autowired | @Autowired | ||||
| private WxRefundOrderService wxRefundOrderService; | private WxRefundOrderService wxRefundOrderService; | ||||
| @ApiOperation(value = "发起退款", notes = "{\"orderId\":,\"string\", \"payOrderId\":\"string\"}") | |||||
| @ApiOperation(value = "发起退款", notes = "{\"orderId\":\"string\"}") | |||||
| @PostMapping("/create") | @PostMapping("/create") | ||||
| public ResultData create(@RequestBody Map<String, String> paramMap) { | public ResultData create(@RequestBody Map<String, String> paramMap) { | ||||
| // couponOrder发起退款 | |||||
| logger.info("/api/refund/create" + paramMap.toString()); | logger.info("/api/refund/create" + paramMap.toString()); | ||||
| //Assert.notNull(wxRefundOrder.getName(), "角色名不能为空"); | //Assert.notNull(wxRefundOrder.getName(), "角色名不能为空"); | ||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | ||||
| String orderIdStr = paramMap.get("orderId"); | String orderIdStr = paramMap.get("orderId"); | ||||
| String payOrderIdStr = paramMap.get("payOrderId"); | |||||
| if (StringUtils.isBlank(orderIdStr)) { | if (StringUtils.isBlank(orderIdStr)) { | ||||
| logger.error("orderId不能为空: " + paramMap.toString()); | logger.error("orderId不能为空: " + paramMap.toString()); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| } | } | ||||
| if (StringUtils.isBlank(payOrderIdStr)) { | |||||
| logger.error("payOrderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | |||||
| } | |||||
| Long orderId = 0L; | Long orderId = 0L; | ||||
| try { | try { | ||||
| orderId = Long.valueOf(orderIdStr); | orderId = Long.valueOf(orderIdStr); | ||||
| @@ -53,14 +61,49 @@ public class WxRefundOrderController extends BaseController { | |||||
| logger.error("orderId参数不正确: " + paramMap.toString()); | logger.error("orderId参数不正确: " + paramMap.toString()); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL); | ||||
| } | } | ||||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||||
| refundOrder.setPayOrderNo(payOrderIdStr); | |||||
| refundOrder.setOrderId(orderId); | |||||
| WxOrder order = null; | |||||
| try { | |||||
| order = wxOrderService.getById(orderId); | |||||
| } catch (Exception e) { | |||||
| logger.error("订单不存在: " + orderIdStr); | |||||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "订单不存在: " + orderIdStr); | |||||
| } | |||||
| if (order == null) { | |||||
| logger.error("订单不存在: " + orderIdStr); | |||||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND.getCode(), "订单不存在: " + orderIdStr); | |||||
| } | |||||
| if (order.getPayment() <= 0) { | |||||
| logger.error("订单支付金额小于等于0: " + order.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_PAY_ORDER_IS_ZERO); | |||||
| } | |||||
| WxPayOrder payOrderQ = new WxPayOrder(); | |||||
| payOrderQ.setCUserId(order.getCUserId()); | |||||
| payOrderQ.setOrderId(orderId); | |||||
| payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | |||||
| WxPayOrder payOrder = null; | |||||
| try { | |||||
| payOrder = wxPayOrderService.getByObj(payOrderQ); | |||||
| } catch (Exception e) { | |||||
| logger.error("payOrder不存在"); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOT_FOUND.getCode(), "支付订单不存在,无法退款"); | |||||
| } | |||||
| if (payOrder == null) { | |||||
| logger.error("payOrder不存在"); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_NOT_FOUND.getCode(), "支付订单不存在,无法退款"); | |||||
| } | |||||
| WxRefundOrder refundOrderQ = new WxRefundOrder(); | |||||
| refundOrderQ.setPayOrderNo(String.valueOf(payOrder.getId())); | |||||
| refundOrderQ.setOrderId(orderId); | |||||
| WxMerchantBUser bUser = getUser(); | WxMerchantBUser bUser = getUser(); | ||||
| WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | WxAppinfo appinfo = getAppInfo(bUser.getAppId()); | ||||
| try { | try { | ||||
| wxRefundOrderService.createRefundOrder(appinfo, refundOrder, EnumPayWay.PAY_WAY_WEAPP); | |||||
| wxRefundOrderService.createRefundOrder(payProperty.isReal(), appinfo, refundOrderQ, payOrder, EnumPayWay.PAY_WAY_WEAPP); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -37,3 +37,6 @@ pagehelper: | |||||
| mapper: | mapper: | ||||
| mappers: | mappers: | ||||
| - com.simple.common.CommonMapper | - com.simple.common.CommonMapper | ||||
| pay: | |||||
| real: false | |||||
| @@ -0,0 +1,26 @@ | |||||
| package com.simple.config; | |||||
| import org.apache.commons.lang3.builder.ToStringBuilder; | |||||
| import org.apache.commons.lang3.builder.ToStringStyle; | |||||
| import org.springframework.boot.context.properties.ConfigurationProperties; | |||||
| import org.springframework.stereotype.Component; | |||||
| /** | |||||
| * @author Stormeye | |||||
| */ | |||||
| @Component | |||||
| @ConfigurationProperties(prefix = "pay") | |||||
| public class PayProperty { | |||||
| /** | |||||
| * 真实支付 | |||||
| */ | |||||
| private boolean real; | |||||
| public boolean isReal() { | |||||
| return real; | |||||
| } | |||||
| public void setReal(boolean real) { | |||||
| this.real = real; | |||||
| } | |||||
| } | |||||
| @@ -1,5 +1,6 @@ | |||||
| package com.simple.controller; | package com.simple.controller; | ||||
| import com.simple.domain.vo.WxCouponChannelVo; | |||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.util.Assert; | import org.springframework.util.Assert; | ||||
| @@ -16,13 +17,15 @@ import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @RestController | @RestController | ||||
| @RequestMapping("wxCouponChannel") | |||||
| @RequestMapping("/api/wxCouponChannel") | |||||
| public class WxCouponChannelController extends BaseController | public class WxCouponChannelController extends BaseController | ||||
| { | { | ||||
| private Logger logger = Logger.getLogger(WxCouponChannelController.class); | |||||
| @Autowired | @Autowired | ||||
| private WxCouponChannelService wxCouponChannelService; | private WxCouponChannelService wxCouponChannelService; | ||||
| private Logger logger = Logger.getLogger(WxCouponChannelController.class); | |||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @GetMapping("list") | @GetMapping("list") | ||||
| @@ -31,33 +34,11 @@ public class WxCouponChannelController extends BaseController | |||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | ||||
| public ResultData list(@ModelAttribute WxCouponChannel wxCouponChannel,Integer pageNum, Integer pageSize) { | public ResultData list(@ModelAttribute WxCouponChannel wxCouponChannel,Integer pageNum, Integer pageSize) { | ||||
| if (null == wxCouponChannel) wxCouponChannel = new WxCouponChannel(); | if (null == wxCouponChannel) wxCouponChannel = new WxCouponChannel(); | ||||
| final PageInfo<WxCouponChannel> page = wxCouponChannelService.listAsPage(wxCouponChannel, pageNum, pageSize); | |||||
| wxCouponChannel.setTenantId(getTenantId()); | |||||
| final PageInfo<WxCouponChannelVo> page = wxCouponChannelService.listPageCAPI(wxCouponChannel, pageNum, pageSize); | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxCouponChannel wxCouponChannel) { | |||||
| //Assert.notNull(wxCouponChannel.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxCouponChannelService.saveOrUpdate(wxCouponChannel); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxCouponChannel wxCouponChannel) { | |||||
| wxCouponChannelService.saveOrUpdate(wxCouponChannel); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxCouponChannelService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | @ApiOperation("根据id查询接口") | ||||
| @GetMapping("/findById") | @GetMapping("/findById") | ||||
| @@ -16,7 +16,7 @@ import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | import io.swagger.annotations.ApiOperation; | ||||
| @RestController | @RestController | ||||
| @RequestMapping("wxCoupon") | |||||
| @RequestMapping("/api/wxCoupon") | |||||
| public class WxCouponController extends BaseController { | public class WxCouponController extends BaseController { | ||||
| private Logger logger = Logger.getLogger(WxCouponController.class); | private Logger logger = Logger.getLogger(WxCouponController.class); | ||||
| @@ -30,6 +30,7 @@ public class WxCouponController extends BaseController { | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | ||||
| public ResultData list(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | public ResultData list(@ModelAttribute WxCoupon wxCoupon, Integer pageNum, Integer pageSize) { | ||||
| if (null == wxCoupon) wxCoupon = new WxCoupon(); | if (null == wxCoupon) wxCoupon = new WxCoupon(); | ||||
| wxCoupon.setTenantId(getTenantId()); | |||||
| final PageInfo<WxCoupon> page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize); | final PageInfo<WxCoupon> page = wxCouponService.listAsPage(wxCoupon, pageNum, pageSize); | ||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @@ -31,33 +31,11 @@ public class WxCouponSendController extends BaseController | |||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | ||||
| public ResultData list(@ModelAttribute WxCouponSend wxCouponSend,Integer pageNum, Integer pageSize) { | public ResultData list(@ModelAttribute WxCouponSend wxCouponSend,Integer pageNum, Integer pageSize) { | ||||
| if (null == wxCouponSend) wxCouponSend = new WxCouponSend(); | if (null == wxCouponSend) wxCouponSend = new WxCouponSend(); | ||||
| wxCouponSend.setTenantId(getTenantId()); | |||||
| final PageInfo<WxCouponSend> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize); | final PageInfo<WxCouponSend> page = wxCouponSendService.listAsPage(wxCouponSend, pageNum, pageSize); | ||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxCouponSend wxCouponSend) { | |||||
| //Assert.notNull(wxCouponSend.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxCouponSendService.saveOrUpdate(wxCouponSend); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxCouponSend wxCouponSend) { | |||||
| wxCouponSendService.saveOrUpdate(wxCouponSend); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxCouponSendService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | @ApiOperation("根据id查询接口") | ||||
| @GetMapping("/findById") | @GetMapping("/findById") | ||||
| @@ -0,0 +1,68 @@ | |||||
| package com.simple.controller; | |||||
| import com.simple.common.ResultData; | |||||
| import com.simple.domain.po.WxMsgValidationcode; | |||||
| import com.simple.service.WxMerchantBUserService; | |||||
| import com.simple.service.WxMerchantService; | |||||
| import com.simple.service.WxMsgValidationcodeService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import org.apache.log4j.Logger; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.GetMapping; | |||||
| import org.springframework.web.bind.annotation.RequestMapping; | |||||
| import org.springframework.web.bind.annotation.RestController; | |||||
| @RestController | |||||
| @RequestMapping("/api/wxMsgValidationcode") | |||||
| @Api(description="短信验证相关接口") | |||||
| public class WxMsgValidationcodeController extends BaseController { | |||||
| private Logger logger = Logger.getLogger(WxMsgValidationcodeController.class); | |||||
| @Autowired | |||||
| private WxMsgValidationcodeService wxMsgValidationcodeService; | |||||
| @Autowired | |||||
| private WxMerchantBUserService wxMerchantBUserService; | |||||
| @Autowired | |||||
| private WxMerchantService wxMerchantService; | |||||
| @GetMapping("sendvalidationcode") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "tenantId", value = "租户ID", dataType = "String", paramType = "query"), | |||||
| @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "appid", value = "appid", dataType = "String", paramType = "query", required = true)}) | |||||
| public ResultData sendvalidationcode(String tenantId, String phone, Integer type, String appid) { | |||||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||||
| wxMsgValidationcode.setTenantId(tenantId); | |||||
| wxMsgValidationcode.setPhone(phone); | |||||
| wxMsgValidationcode.setType(type); | |||||
| wxMsgValidationcode.setAppid(appid); | |||||
| return wxMsgValidationcodeService.sendvalidationcode(wxMsgValidationcode); | |||||
| } | |||||
| @GetMapping("hasvalidationcode") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "tenantId", value = "租户ID", dataType = "String", paramType = "query"), | |||||
| @ApiImplicitParam(name = "phone", value = "手机号", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "type", value = "场景", dataType = "Integer", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "code", value = "验证码", dataType = "String", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "appid", value = "appid", dataType = "String", paramType = "query", required = true)}) | |||||
| public ResultData hasvalidationcode(String tenantId, String phone, Integer type, String code, String appid) { | |||||
| WxMsgValidationcode wxMsgValidationcode = new WxMsgValidationcode(); | |||||
| wxMsgValidationcode.setTenantId(tenantId); | |||||
| wxMsgValidationcode.setPhone(phone); | |||||
| wxMsgValidationcode.setType(type); | |||||
| wxMsgValidationcode.setCode(code); | |||||
| wxMsgValidationcode.setAppid(appid); | |||||
| return wxMsgValidationcodeService.hasvalidationcode(wxMsgValidationcode); | |||||
| } | |||||
| } | |||||
| @@ -46,10 +46,12 @@ public class WxOrderController extends BaseController { | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponId: " + couponIdStr + ", e:" + e.getMessage()); | return new ResultData(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "couponId: " + couponIdStr + ", e:" + e.getMessage()); | ||||
| } | } | ||||
| Long cUserId = getUserId(); | |||||
| WxCUser user = getUser(); | |||||
| WxOrder order = null; | |||||
| try { | try { | ||||
| WxOrder order = wxOrderService.sendUserFreeCoupon(cUserId, couponId); | |||||
| order = wxOrderService.sendUserFreeCoupon(user.getId(), couponId); | |||||
| return new ResultData(order); | return new ResultData(order); | ||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -107,7 +109,16 @@ public class WxOrderController extends BaseController { | |||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "orderId: " + orderIdStr + ", e: " + e.getMessage()); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL, "orderId: " + orderIdStr + ", e: " + e.getMessage()); | ||||
| } | } | ||||
| wxOrderService.updateOrderStatus(orderId, EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL); | |||||
| try { | |||||
| WxOrder order = wxOrderService.getById(orderId); | |||||
| if (order != null) { | |||||
| wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error("取消订单失败: " + e.getMessage()); | |||||
| return new ResultData(ErrorCode.ORDER_IS_FAIL.getCode(), "取消订单失败: " + e.getMessage()); | |||||
| } | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -118,7 +129,7 @@ public class WxOrderController extends BaseController { | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | ||||
| String orderIdStr = paramMap.get("orderId"); | String orderIdStr = paramMap.get("orderId"); | ||||
| if (StringUtils.isBlank(orderIdStr)) { | if (StringUtils.isBlank(orderIdStr)) { | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "退款订单ID不能为空"); | |||||
| } | } | ||||
| Long orderId = 0L; | Long orderId = 0L; | ||||
| WxCUser user = getUser(); | WxCUser user = getUser(); | ||||
| @@ -126,8 +137,17 @@ public class WxOrderController extends BaseController { | |||||
| orderId = Long.valueOf(orderIdStr); | orderId = Long.valueOf(orderIdStr); | ||||
| } catch (NumberFormatException e) { | } catch (NumberFormatException e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "退款订单ID转换失败"); | |||||
| } | |||||
| try { | |||||
| WxOrder order = wxOrderService.getById(orderId); | |||||
| if (order != null) { | |||||
| wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error("更新退款订单状态失败:" + e.getMessage()); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR.getCode(), "更新退款订单状态失败:" + e.getMessage()); | |||||
| } | } | ||||
| wxOrderService.updateOrderStatus(orderId, EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS); | |||||
| return new ResultData(); | return new ResultData(); | ||||
| } | } | ||||
| @@ -160,8 +180,20 @@ public class WxOrderController extends BaseController { | |||||
| orderId = Long.valueOf(orderIdStr); | orderId = Long.valueOf(orderIdStr); | ||||
| } catch (NumberFormatException e) { | } catch (NumberFormatException e) { | ||||
| logger.error("parse orderId failed"); | logger.error("parse orderId failed"); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "订单ID转换异常"); | |||||
| } | |||||
| WxOrder order = null; | |||||
| try { | |||||
| order = wxOrderService.getById(orderId); | |||||
| if (order != null) { | |||||
| return new ResultData(Result.SUCCESS, "查询成功", order); | |||||
| } else { | |||||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error("parse orderId failed"); | |||||
| return new ResultData(ErrorCode.DB_FAIL.getCode(), "订单查询未成功,e:" + e.getMessage()); | |||||
| } | } | ||||
| return new ResultData(Result.SUCCESS, "查询成功", wxOrderService.getById(orderId)); | |||||
| } | } | ||||
| @@ -3,6 +3,7 @@ package com.simple.controller; | |||||
| import cn.binarywang.wx.miniapp.api.WxMaService; | import cn.binarywang.wx.miniapp.api.WxMaService; | ||||
| import com.simple.annotation.AuthIgnore; | import com.simple.annotation.AuthIgnore; | ||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.config.PayProperty; | |||||
| import com.simple.domain.po.WxAppinfo; | import com.simple.domain.po.WxAppinfo; | ||||
| import com.simple.domain.po.WxCUser; | import com.simple.domain.po.WxCUser; | ||||
| import com.simple.enums.EnumPayStatus; | import com.simple.enums.EnumPayStatus; | ||||
| @@ -39,6 +40,9 @@ public class WxPayOrderController extends BaseController { | |||||
| private Logger logger = Logger.getLogger(WxPayOrderController.class); | private Logger logger = Logger.getLogger(WxPayOrderController.class); | ||||
| @Autowired | |||||
| private PayProperty payProperty; | |||||
| @Autowired | @Autowired | ||||
| private WxPayOrderService wxPayOrderService; | private WxPayOrderService wxPayOrderService; | ||||
| @@ -66,7 +70,7 @@ public class WxPayOrderController extends BaseController { | |||||
| try { | try { | ||||
| record.setIp(IPUtil.getIpAddr(request)); | record.setIp(IPUtil.getIpAddr(request)); | ||||
| return wxPayOrderService.createPayOrder(appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| return wxPayOrderService.createPayOrder(payProperty.isReal(), appInfo, user, record, EnumPayWay.PAY_WAY_WECHAT); | |||||
| } catch (MallinkException e) { | } catch (MallinkException e) { | ||||
| logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | logger.error("payment wechat, order create error, req 2: " + record.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| @@ -92,7 +96,6 @@ public class WxPayOrderController extends BaseController { | |||||
| try { | try { | ||||
| orderId = Long.valueOf(orderIdStr); | orderId = Long.valueOf(orderIdStr); | ||||
| } catch (NumberFormatException e) { | } catch (NumberFormatException e) { | ||||
| orderId = 0L; | |||||
| logger.error("orderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | logger.error("orderId参数不正确: " + paramMap.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | ||||
| } | } | ||||
| @@ -118,8 +121,8 @@ public class WxPayOrderController extends BaseController { | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | return new ResultData(e.getErrorCode(), e.getMessage()); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | logger.error("支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | ||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR, "支付状态更新失败3: " + payOrder.toString() + ", e:" + e.getMessage()); | |||||
| } | } | ||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR); | |||||
| } | } | ||||
| @ApiOperation("分页列表接口") | @ApiOperation("分页列表接口") | ||||
| @@ -1,94 +0,0 @@ | |||||
| package com.simple.controller; | |||||
| import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.ErrorCode; | |||||
| import com.simple.common.Result; | |||||
| import com.simple.common.ResultData; | |||||
| import com.simple.domain.po.WxAppinfo; | |||||
| import com.simple.domain.po.WxCUser; | |||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| import com.simple.domain.po.WxRefundOrder; | |||||
| import com.simple.enums.EnumPayWay; | |||||
| import com.simple.exception.MallinkException; | |||||
| import com.simple.service.WxRefundOrderService; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.log4j.Logger; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("/api/refund") | |||||
| public class WxRefundOrderController extends BaseController | |||||
| { | |||||
| private Logger logger = Logger.getLogger(WxRefundOrderController.class); | |||||
| @Autowired | |||||
| private WxRefundOrderService wxRefundOrderService; | |||||
| @ApiOperation(value = "发起退款", notes = "{\"orderId\":,\"string\", \"payOrderId\":\"string\"}") | |||||
| @PostMapping("/create") | |||||
| public ResultData create(@RequestBody Map<String, String> paramMap) { | |||||
| logger.info("/api/refund/create" + paramMap.toString()); | |||||
| //Assert.notNull(wxRefundOrder.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| String orderIdStr = paramMap.get("orderId"); | |||||
| String payOrderIdStr = paramMap.get("payOrderId"); | |||||
| if (StringUtils.isBlank(orderIdStr)) { | |||||
| logger.error("orderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(payOrderIdStr)) { | |||||
| logger.error("payOrderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "payOrderId不能为空"); | |||||
| } | |||||
| Long orderId = 0L; | |||||
| try { | |||||
| orderId = Long.valueOf(orderIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| logger.error("orderId参数不正确: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | |||||
| } | |||||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||||
| refundOrder.setPayOrderNo(payOrderIdStr); | |||||
| refundOrder.setOrderId(orderId); | |||||
| WxCUser cUser = getUser(); | |||||
| WxAppinfo appinfo = getAppInfo(cUser.getAppId()); | |||||
| try { | |||||
| wxRefundOrderService.createRefundOrder(appinfo, refundOrder, EnumPayWay.PAY_WAY_WEAPP); | |||||
| return new ResultData(); | |||||
| } catch (MallinkException e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||||
| } catch (Exception e) { | |||||
| logger.error(e.getMessage()); | |||||
| return new ResultData(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } | |||||
| @ApiOperation("分页列表接口") | |||||
| @GetMapping("list") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name="pageNum",value="页数",dataType="int", paramType = "query",required=true), | |||||
| @ApiImplicitParam(name="pageSize",value="每页条数",dataType="int", paramType = "query",required=true)}) | |||||
| public ResultData list(@ModelAttribute WxRefundOrder wxRefundOrder,Integer pageNum, Integer pageSize) { | |||||
| if (null == wxRefundOrder) wxRefundOrder = new WxRefundOrder(); | |||||
| final PageInfo<WxRefundOrder> page = wxRefundOrderService.listAsPage(wxRefundOrder, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("根据id查询接口") | |||||
| @GetMapping("/findById") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData findById(Long id) { | |||||
| return new ResultData(Result.SUCCESS,"查询成功",wxRefundOrderService.getById(id)); | |||||
| } | |||||
| } | |||||
| @@ -237,7 +237,7 @@ public class WxUserGrantController extends BaseController { | |||||
| * 检查用户状态 | * 检查用户状态 | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| @GetMapping("/checkUserStatus") | |||||
| @PostMapping("/checkUserStatus") | |||||
| @ApiOperation(value = "判断是否是老用户", notes="") | @ApiOperation(value = "判断是否是老用户", notes="") | ||||
| public ResultData checkUserStatus() { | public ResultData checkUserStatus() { | ||||
| Map resultMap = new HashMap(); | Map resultMap = new HashMap(); | ||||
| @@ -245,13 +245,25 @@ public class WxUserGrantController extends BaseController { | |||||
| if (!StringUtils.isBlank(user.getUnionId())) { | if (!StringUtils.isBlank(user.getUnionId())) { | ||||
| resultMap.put("unionId", user.getUnionId()); | resultMap.put("unionId", user.getUnionId()); | ||||
| } | } | ||||
| //if (StringUtils.isBlank(user.getUnionId())) { | |||||
| // logger.warn("用户昵称未授权,跳转到用户授权页!"); | |||||
| // return new ResultData(ErrorCode.NICK_NAME_NOT_FOUND.getCode(), "用户昵称未授权,请跳转到用户昵称授权页!", resultMap); | |||||
| //} | |||||
| return new ResultData(Result.SUCCESS, "是老用户,已完成所有授权", resultMap); | |||||
| } | |||||
| /** | |||||
| * 检查用户状态 | |||||
| * @return | |||||
| */ | |||||
| @PostMapping("/checkPhoneStatus") | |||||
| @ApiOperation(value = "判断是否是老用户", notes="") | |||||
| public ResultData checkPhoneStatus() { | |||||
| Map resultMap = new HashMap(); | |||||
| WxCUser user = getUser(); | |||||
| if (!StringUtils.isBlank(user.getPhone())) { | if (!StringUtils.isBlank(user.getPhone())) { | ||||
| resultMap.put("phone", user.getPhone()); | resultMap.put("phone", user.getPhone()); | ||||
| } | } | ||||
| if (StringUtils.isBlank(user.getUnionId())) { | |||||
| logger.warn("用户昵称未授权,跳转到用户授权页!"); | |||||
| return new ResultData(ErrorCode.NICK_NAME_NOT_FOUND.getCode(), "用户昵称未授权,请跳转到用户昵称授权页!", resultMap); | |||||
| } | |||||
| if (StringUtils.isBlank(user.getPhone())) { | if (StringUtils.isBlank(user.getPhone())) { | ||||
| logger.warn("用户手机号未授权,跳转到授权手机号页!"); | logger.warn("用户手机号未授权,跳转到授权手机号页!"); | ||||
| return new ResultData(ErrorCode.PHONE_NOT_FOUND.getCode(), "用户手机号未授权,请跳转到授权手机号页!", resultMap); | return new ResultData(ErrorCode.PHONE_NOT_FOUND.getCode(), "用户手机号未授权,请跳转到授权手机号页!", resultMap); | ||||
| @@ -37,3 +37,6 @@ pagehelper: | |||||
| mapper: | mapper: | ||||
| mappers: | mappers: | ||||
| - com.simple.common.CommonMapper | - com.simple.common.CommonMapper | ||||
| pay: | |||||
| real: false | |||||
| @@ -121,6 +121,7 @@ public enum ErrorCode{ | |||||
| /** | /** | ||||
| * 支付 | * 支付 | ||||
| */ | */ | ||||
| PAY_ORDER_NOT_FOUND(12000, "支付订单不存在"), | |||||
| PAY_ORDER_EXIST(12001, "支付订单已存在"), | PAY_ORDER_EXIST(12001, "支付订单已存在"), | ||||
| PAY_ORDER_ERROR(12002, "支付订单异常"), | PAY_ORDER_ERROR(12002, "支付订单异常"), | ||||
| PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR(12003 , "支付验签失败"), | PAY_ORDER_NOTIFY_CHECK_SIGN_ERROR(12003 , "支付验签失败"), | ||||
| @@ -83,25 +83,35 @@ public class WxCUserBasicInfo implements Serializable { | |||||
| @io.swagger.annotations.ApiModelProperty(value="用户姓名",name="name") | @io.swagger.annotations.ApiModelProperty(value="用户姓名",name="name") | ||||
| private String name; | private String name; | ||||
| @Transient | @Transient | ||||
| private String tags; | |||||
| private String tagIds; | |||||
| @Transient | @Transient | ||||
| private List<WxTags> tagList; | |||||
| private String tagNames; | |||||
| @Transient | |||||
| private long count; | |||||
| public long getCount() { | |||||
| return count; | |||||
| } | |||||
| public List<WxTags> getTagList() { | |||||
| return tagList; | |||||
| public void setCount(long count) { | |||||
| this.count = count; | |||||
| } | } | ||||
| public void setTagList(List<WxTags> tagList) { | |||||
| this.tagList = tagList; | |||||
| public String getTagNames() { | |||||
| return tagNames; | |||||
| } | } | ||||
| public String getTags() { | |||||
| return tags; | |||||
| public void setTagNames(String tagNames) { | |||||
| this.tagNames = tagNames; | |||||
| } | |||||
| public String getTagIds() { | |||||
| return tagIds; | |||||
| } | } | ||||
| public void setTags(String tags) { | |||||
| this.tags = tags; | |||||
| public void setTagIds(String tagIds) { | |||||
| this.tagIds = tagIds; | |||||
| } | } | ||||
| public String getPhone() { | public String getPhone() { | ||||
| @@ -39,9 +39,20 @@ public class WxCouponChannel implements Serializable { | |||||
| public void setIds(List<String> ids) { | public void setIds(List<String> ids) { | ||||
| this.ids = ids; | this.ids = ids; | ||||
| } | } | ||||
| /***/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="business") | |||||
| private String business; | |||||
| public String getBusiness() { | |||||
| return business; | |||||
| } | |||||
| public void setBusiness(String business) { | |||||
| this.business = business; | |||||
| } | |||||
| /*租户ID**/ | /*租户ID**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | ||||
| private String tenantId; | private String tenantId; | ||||
| @@ -1,12 +1,13 @@ | |||||
| package com.simple.domain.po; | package com.simple.domain.po; | ||||
| import javax.persistence.*; | |||||
| import java.util.*; | |||||
| import java.math.*; | |||||
| import javax.persistence.Transient; | |||||
| import java.io.Serializable; | |||||
| import java.text.DecimalFormat; | |||||
| import java.util.Date; | |||||
| import java.util.List; | import java.util.List; | ||||
| import javax.persistence.Id; | import javax.persistence.Id; | ||||
| import java.io.Serializable; | |||||
| import javax.persistence.Table; | |||||
| import javax.persistence.Transient; | |||||
| @Table(name = "wx_coupon_order") | @Table(name = "wx_coupon_order") | ||||
| public class WxCouponOrder implements Serializable { | public class WxCouponOrder implements Serializable { | ||||
| @@ -71,8 +72,58 @@ public class WxCouponOrder implements Serializable { | |||||
| /*单券实际购买价格**/ | /*单券实际购买价格**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value = "单券实际购买价格", name = "couponPrice") | @io.swagger.annotations.ApiModelProperty(value = "单券实际购买价格", name = "couponPrice") | ||||
| private Integer couponPrice; | private Integer couponPrice; | ||||
| public String getTenantId() { | |||||
| @Transient | |||||
| private String couponName; | |||||
| @Transient | |||||
| private String couponPriceStr; | |||||
| @Transient | |||||
| private String salePriceStr; | |||||
| @Transient | |||||
| private Integer salePrice; | |||||
| public String getCouponPriceStr() { | |||||
| if(couponPrice!=null) { | |||||
| DecimalFormat df=new DecimalFormat("0.00"); | |||||
| couponPriceStr = df.format((float)couponPrice/100); | |||||
| } | |||||
| return couponPriceStr; | |||||
| } | |||||
| public void setCouponPriceStr(String couponPriceStr) { | |||||
| this.couponPriceStr = couponPriceStr; | |||||
| } | |||||
| public String getSalePriceStr() { | |||||
| if(salePrice!=null) { | |||||
| DecimalFormat df=new DecimalFormat("0.00"); | |||||
| salePriceStr = df.format((float)salePrice/100); | |||||
| } | |||||
| return salePriceStr; | |||||
| } | |||||
| public void setSalePriceStr(String salePriceStr) { | |||||
| this.salePriceStr = salePriceStr; | |||||
| } | |||||
| public Integer getSalePrice() { | |||||
| return salePrice; | |||||
| } | |||||
| public void setSalePrice(Integer salePrice) { | |||||
| this.salePrice = salePrice; | |||||
| } | |||||
| public String getCouponName() { | |||||
| return couponName; | |||||
| } | |||||
| public void setCouponName(String couponName) { | |||||
| this.couponName = couponName; | |||||
| } | |||||
| public String getTenantId() { | |||||
| return tenantId; | return tenantId; | ||||
| } | } | ||||
| @@ -1,12 +1,11 @@ | |||||
| package com.simple.domain.po; | package com.simple.domain.po; | ||||
| import javax.persistence.*; | |||||
| import java.util.*; | |||||
| import java.math.*; | |||||
| import javax.persistence.Transient; | |||||
| import java.util.List; | |||||
| import javax.persistence.Id; | import javax.persistence.Id; | ||||
| import javax.persistence.Table; | |||||
| import javax.persistence.Transient; | |||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| import java.util.Date; | |||||
| import java.util.List; | |||||
| @Table(name = "wx_mall_building") | @Table(name = "wx_mall_building") | ||||
| public class WxMallBuilding implements Serializable { | public class WxMallBuilding implements Serializable { | ||||
| @@ -38,9 +37,11 @@ public class WxMallBuilding implements Serializable { | |||||
| public void setIds(List<String> ids) { | public void setIds(List<String> ids) { | ||||
| this.ids = ids; | this.ids = ids; | ||||
| } | } | ||||
| @Transient | |||||
| protected List<WxMallFloor> floors; | |||||
| /*租户ID**/ | /*租户ID**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | @io.swagger.annotations.ApiModelProperty(value="租户ID",name="tenantId") | ||||
| private String tenantId; | private String tenantId; | ||||
| @@ -96,7 +97,13 @@ public class WxMallBuilding implements Serializable { | |||||
| updateDate = _updateDate; | updateDate = _updateDate; | ||||
| } | } | ||||
| public List<WxMallFloor> getFloors() { | |||||
| return floors; | |||||
| } | |||||
| public void setFloors(List<WxMallFloor> floors) { | |||||
| this.floors = floors; | |||||
| } | |||||
| public static enum Field | public static enum Field | ||||
| { | { | ||||
| @@ -77,6 +77,10 @@ public class WxMerchantBUser implements Serializable { | |||||
| @io.swagger.annotations.ApiModelProperty(value="name",name="name") | @io.swagger.annotations.ApiModelProperty(value="name",name="name") | ||||
| private String name; | private String name; | ||||
| @io.swagger.annotations.ApiModelProperty(value="删除状态1删除0未删除",name="status") | |||||
| private Integer status; | |||||
| public String getTenantId() { | public String getTenantId() { | ||||
| return tenantId; | return tenantId; | ||||
| } | } | ||||
| @@ -146,6 +150,14 @@ public class WxMerchantBUser implements Serializable { | |||||
| this.name = _name; | this.name = _name; | ||||
| } | } | ||||
| public Integer getStatus() { | |||||
| return status; | |||||
| } | |||||
| public void setStatus(Integer status) { | |||||
| this.status = status; | |||||
| } | |||||
| public static enum Field | public static enum Field | ||||
| { | { | ||||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | ||||
| @@ -160,6 +172,7 @@ public class WxMerchantBUser implements Serializable { | |||||
| ,Token_ASC("`token` ASC"),Token_DESC("`token` DESC") | ,Token_ASC("`token` ASC"),Token_DESC("`token` DESC") | ||||
| ,ExpireTime_ASC("`expireTime` ASC"),ExpireTime_DESC("`expireTime` DESC") | ,ExpireTime_ASC("`expireTime` ASC"),ExpireTime_DESC("`expireTime` DESC") | ||||
| ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | ,Name_ASC("`name` ASC"),Name_DESC("`name` DESC") | ||||
| ,Status_ASC("`status` ASC"),Status_DESC("`status` DESC") | |||||
| ; | ; | ||||
| private String value; | private String value; | ||||
| @@ -57,6 +57,9 @@ public class WxOrder implements Serializable { | |||||
| /*操作券B端小程序用户ID**/ | /*操作券B端小程序用户ID**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="操作券B端小程序用户ID",name="bUserId") | @io.swagger.annotations.ApiModelProperty(value="操作券B端小程序用户ID",name="bUserId") | ||||
| private Long bUserId; | private Long bUserId; | ||||
| /*券ID-产品ID将来的产品都会放在coupon表里**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="券ID",name="couponId") | |||||
| private Long couponId; | |||||
| /*0: 付款 1: 退款**/ | /*0: 付款 1: 退款**/ | ||||
| @io.swagger.annotations.ApiModelProperty(value="0: 付款 1: 退款",name="paymentType") | @io.swagger.annotations.ApiModelProperty(value="0: 付款 1: 退款",name="paymentType") | ||||
| private Integer paymentType; | private Integer paymentType; | ||||
| @@ -108,6 +111,14 @@ public class WxOrder implements Serializable { | |||||
| public void setBUserId(Long _bUserId) { | public void setBUserId(Long _bUserId) { | ||||
| bUserId = _bUserId; | bUserId = _bUserId; | ||||
| } | } | ||||
| public Long getCouponId() { | |||||
| return couponId; | |||||
| } | |||||
| public void setCouponId(Long _couponId) { | |||||
| this.couponId = _couponId; | |||||
| } | |||||
| public Integer getPaymentType() { | public Integer getPaymentType() { | ||||
| return paymentType; | return paymentType; | ||||
| } | } | ||||
| @@ -161,6 +172,7 @@ public class WxOrder implements Serializable { | |||||
| ,CUserId_ASC("`cUserId` ASC"),CUserId_DESC("`cUserId` DESC") | ,CUserId_ASC("`cUserId` ASC"),CUserId_DESC("`cUserId` DESC") | ||||
| ,MerchantId_ASC("`merchantId` ASC"),MerchantId_DESC("`merchantId` DESC") | ,MerchantId_ASC("`merchantId` ASC"),MerchantId_DESC("`merchantId` DESC") | ||||
| ,BUserId_ASC("`bUserId` ASC"),BUserId_DESC("`bUserId` DESC") | ,BUserId_ASC("`bUserId` ASC"),BUserId_DESC("`bUserId` DESC") | ||||
| ,CouponId_ASC("`couponId` ASC"),CouponId_DESC("`couponId` DESC") | |||||
| ,PaymentType_ASC("`paymentType` ASC"),PaymentType_DESC("`paymentType` DESC") | ,PaymentType_ASC("`paymentType` ASC"),PaymentType_DESC("`paymentType` DESC") | ||||
| ,Payment_ASC("`payment` ASC"),Payment_DESC("`payment` DESC") | ,Payment_ASC("`payment` ASC"),Payment_DESC("`payment` DESC") | ||||
| ,PaymentTime_ASC("`paymentTime` ASC"),PaymentTime_DESC("`paymentTime` DESC") | ,PaymentTime_ASC("`paymentTime` ASC"),PaymentTime_DESC("`paymentTime` DESC") | ||||
| @@ -1,6 +1,7 @@ | |||||
| package com.simple.domain.vo; | package com.simple.domain.vo; | ||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| import java.text.DecimalFormat; | |||||
| /** | /** | ||||
| * 交易记录核销记录Vo | * 交易记录核销记录Vo | ||||
| * @author jinguo | * @author jinguo | ||||
| @@ -15,10 +16,61 @@ public class AmountRecordVo implements Serializable{ | |||||
| * | * | ||||
| */ | */ | ||||
| private static final long serialVersionUID = 4494858079134918638L; | private static final long serialVersionUID = 4494858079134918638L; | ||||
| List<WxDateAmountRecord> orderAmountList; | |||||
| //交易金额记录 | |||||
| private List<WxDateAmountRecord> orderAmountList; | |||||
| //核销金额记录 | |||||
| private List<WxDateAmountRecord> verifyAmountList; | |||||
| private Integer orderAmount; | |||||
| private String orderAmountStr; | |||||
| List<WxDateAmountRecord> verifyAmountList; | |||||
| private Integer verifyAmount; | |||||
| private String verifyAmountStr; | |||||
| public String getOrderAmountStr() { | |||||
| if(orderAmount!=null) { | |||||
| DecimalFormat df=new DecimalFormat("0.00"); | |||||
| orderAmountStr = df.format((float)orderAmount/100); | |||||
| } | |||||
| return orderAmountStr; | |||||
| } | |||||
| public String getVerifyAmountStr() { | |||||
| if(verifyAmount!=null) { | |||||
| DecimalFormat df=new DecimalFormat("0.00"); | |||||
| verifyAmountStr = df.format((float)verifyAmount/100); | |||||
| } | |||||
| return verifyAmountStr; | |||||
| } | |||||
| public Integer getOrderAmount() { | |||||
| return orderAmount; | |||||
| } | |||||
| public void setOrderAmount(Integer orderAmount) { | |||||
| this.orderAmount = orderAmount; | |||||
| } | |||||
| public Integer getVerifyAmount() { | |||||
| return verifyAmount; | |||||
| } | |||||
| public void setVerifyAmount(Integer verifyAmount) { | |||||
| this.verifyAmount = verifyAmount; | |||||
| } | |||||
| public void setOrderAmountStr(String orderAmountStr) { | |||||
| this.orderAmountStr = orderAmountStr; | |||||
| } | |||||
| public void setVerifyAmountStr(String verifyAmountStr) { | |||||
| this.verifyAmountStr = verifyAmountStr; | |||||
| } | |||||
| public List<WxDateAmountRecord> getOrderAmountList() { | public List<WxDateAmountRecord> getOrderAmountList() { | ||||
| return orderAmountList; | return orderAmountList; | ||||
| @@ -0,0 +1,162 @@ | |||||
| package com.simple.domain.vo; | |||||
| import com.simple.domain.po.WxCoupon; | |||||
| import com.simple.domain.po.WxCouponChannel; | |||||
| import javax.persistence.Transient; | |||||
| import java.io.Serializable; | |||||
| import java.text.DecimalFormat; | |||||
| import java.util.Date; | |||||
| /** | |||||
| * Created by syf on 2018/8/22. | |||||
| */ | |||||
| public class WxCouponChannelVo extends WxCouponChannel implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| @io.swagger.annotations.ApiModelProperty(value="剩余库存",name="remainInventory") | |||||
| private Integer remainInventory; | |||||
| @io.swagger.annotations.ApiModelProperty(value="封面图",name="coverImg") | |||||
| private String coverImg; | |||||
| /*副标题**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="副标题",name="subTitle") | |||||
| private String subTitle; | |||||
| /*售价(适用于类型2,3,4,5)**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="售价(适用于类型2,3,4,5)",name="salePrice") | |||||
| private Integer salePrice; | |||||
| /*使用条件金额(适用于类型1,2,3,4)**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="使用条件金额(适用于类型1,2,3,4)",name="usePrice") | |||||
| private Integer usePrice; | |||||
| @Transient | |||||
| private String salePriceStr; | |||||
| @Transient | |||||
| private String usePriceStr; | |||||
| /*限领张数**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="限领张数",name="useLimitQuantity") | |||||
| private Integer useLimitQuantity; | |||||
| /*1.主动领取2.定向投放**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="1.主动领取2.定向投放",name="sendType") | |||||
| private Integer sendType; | |||||
| /*发放开始时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="发放开始时间",name="sendStartDate") | |||||
| private Date sendStartDate; | |||||
| /*发放结束时间**/ | |||||
| @io.swagger.annotations.ApiModelProperty(value="发放结束时间",name="sendEndDate") | |||||
| private Date sendEndDate; | |||||
| public Integer getRemainInventory() { | |||||
| return remainInventory; | |||||
| } | |||||
| public void setRemainInventory(Integer remainInventory) { | |||||
| this.remainInventory = remainInventory; | |||||
| } | |||||
| public String getCoverImg() { | |||||
| return coverImg; | |||||
| } | |||||
| public void setCoverImg(String coverImg) { | |||||
| this.coverImg = coverImg; | |||||
| } | |||||
| public String getSubTitle() { | |||||
| return subTitle; | |||||
| } | |||||
| public void setSubTitle(String subTitle) { | |||||
| this.subTitle = subTitle; | |||||
| } | |||||
| public Integer getSalePrice() { | |||||
| return salePrice; | |||||
| } | |||||
| public void setSalePrice(Integer salePrice) { | |||||
| this.salePrice = salePrice; | |||||
| } | |||||
| public Integer getUsePrice() { | |||||
| return usePrice; | |||||
| } | |||||
| public void setUsePrice(Integer usePrice) { | |||||
| this.usePrice = usePrice; | |||||
| } | |||||
| public Integer getUseLimitQuantity() { | |||||
| return useLimitQuantity; | |||||
| } | |||||
| public void setUseLimitQuantity(Integer useLimitQuantity) { | |||||
| this.useLimitQuantity = useLimitQuantity; | |||||
| } | |||||
| public Integer getSendType() { | |||||
| return sendType; | |||||
| } | |||||
| public void setSendType(Integer sendType) { | |||||
| this.sendType = sendType; | |||||
| } | |||||
| public Date getSendStartDate() { | |||||
| return sendStartDate; | |||||
| } | |||||
| public void setSendStartDate(Date sendStartDate) { | |||||
| this.sendStartDate = sendStartDate; | |||||
| } | |||||
| public Date getSendEndDate() { | |||||
| return sendEndDate; | |||||
| } | |||||
| public void setSendEndDate(Date sendEndDate) { | |||||
| this.sendEndDate = sendEndDate; | |||||
| } | |||||
| public String getSalePriceStr() { | |||||
| if(salePrice!=null) { | |||||
| DecimalFormat df=new DecimalFormat("0.00"); | |||||
| salePriceStr = df.format((float)salePrice/100); | |||||
| } | |||||
| return salePriceStr; | |||||
| } | |||||
| public void setSalePriceStr(String salePriceStr) { | |||||
| this.salePriceStr = salePriceStr; | |||||
| } | |||||
| public String getUsePriceStr() { | |||||
| if(usePrice!=null) { | |||||
| DecimalFormat df=new DecimalFormat("0.00"); | |||||
| usePriceStr = df.format((float)usePrice/100); | |||||
| } | |||||
| return usePriceStr; | |||||
| } | |||||
| public void setUsePriceStr(String usePriceStr) { | |||||
| this.usePriceStr = usePriceStr; | |||||
| } | |||||
| public WxCouponChannelVo(){} | |||||
| public WxCouponChannelVo setWxCoupon (WxCoupon wxCoupon){ | |||||
| this.coverImg=wxCoupon.getCoverImg(); | |||||
| this.remainInventory=wxCoupon.getRemainInventory(); | |||||
| this.salePrice=wxCoupon.getSalePrice(); | |||||
| this.sendStartDate=wxCoupon.getSendStartDate(); | |||||
| this.sendEndDate=wxCoupon.getSendEndDate(); | |||||
| this.sendType=wxCoupon.getSendType(); | |||||
| this.useLimitQuantity=wxCoupon.getUseLimitQuantity(); | |||||
| this.usePrice=wxCoupon.getUsePrice(); | |||||
| this.subTitle=wxCoupon.getSubTitle(); | |||||
| return this; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,14 @@ | |||||
| package com.simple.domain.vo; | |||||
| import com.simple.domain.po.WxCouponOrder; | |||||
| public class WxUserCouponVo extends WxCouponOrder{ | |||||
| /** | |||||
| * | |||||
| */ | |||||
| private static final long serialVersionUID = 6687954932922444531L; | |||||
| } | |||||
| @@ -5,15 +5,11 @@ package com.simple.enums; | |||||
| */ | */ | ||||
| public enum EnumCouponStatus { | public enum EnumCouponStatus { | ||||
| // 0-草稿/待生效;1-已生效/已发布/已投放;2-已下架;3-已领取/已购买/未核销/未使用,4:已核销/已使用,5:已过期,6:已退券 | |||||
| // 0-草稿/待生效;1-已生效/已发布/已投放;2-已下架; | |||||
| COUPON_STATUS_DRAFT(0, "草稿"), | COUPON_STATUS_DRAFT(0, "草稿"), | ||||
| COUPON_STATUS_THROW_IN(1, "已投放"), | COUPON_STATUS_THROW_IN(1, "已投放"), | ||||
| COUPON_STATUS_TAKE_OFFF(2, "已下架"), | COUPON_STATUS_TAKE_OFFF(2, "已下架"), | ||||
| COUPON_STATUS_NOT_USED(3, "未使用"), | |||||
| COUPON_STATUS_USED(4,"已使用"), | |||||
| COUPON_STATUS_OVER_TIME(5, "已过期"), | |||||
| COUPON_STATUS_BACKED(6, "已退券") | |||||
| ; | ; | ||||
| public static EnumCouponStatus getEnum(Integer code) { | public static EnumCouponStatus getEnum(Integer code) { | ||||
| @@ -2,12 +2,15 @@ package com.simple.mapper; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.simple.common.CommonMapper; | import com.simple.common.CommonMapper; | ||||
| import com.simple.domain.vo.WxCouponChannelVo; | |||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import com.simple.domain.po.WxCouponChannel; | import com.simple.domain.po.WxCouponChannel; | ||||
| public interface WxCouponChannelMapper extends CommonMapper<WxCouponChannel, String> { | public interface WxCouponChannelMapper extends CommonMapper<WxCouponChannel, String> { | ||||
| List<WxCouponChannel> findList(WxCouponChannel wxCouponChannel); | List<WxCouponChannel> findList(WxCouponChannel wxCouponChannel); | ||||
| List<WxCouponChannelVo> findVoList(WxCouponChannel wxCouponChannel); | |||||
| @@ -2,6 +2,7 @@ package com.simple.mapper; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.simple.common.CommonMapper; | import com.simple.common.CommonMapper; | ||||
| import com.simple.domain.po.WxCouponOrder; | |||||
| import com.simple.domain.vo.OrderVo; | import com.simple.domain.vo.OrderVo; | ||||
| import org.apache.ibatis.annotations.Param; | import org.apache.ibatis.annotations.Param; | ||||
| import com.simple.domain.po.WxOrder; | import com.simple.domain.po.WxOrder; | ||||
| @@ -14,4 +15,5 @@ public interface WxOrderMapper extends CommonMapper<WxOrder, Long> { | |||||
| Map<String,Object> queryObject(OrderVo orderVo); | Map<String,Object> queryObject(OrderVo orderVo); | ||||
| List<WxOrder> findListOfUnpaidOrderByDate(Map dateMap); | |||||
| } | } | ||||
| @@ -1,6 +1,8 @@ | |||||
| package com.simple.schedule; | package com.simple.schedule; | ||||
| import com.simple.common.IdWorker; | |||||
| import com.simple.domain.po.WxCouponOrder; | import com.simple.domain.po.WxCouponOrder; | ||||
| import com.simple.domain.po.WxDateAmountRecord; | |||||
| import com.simple.domain.po.WxMall; | import com.simple.domain.po.WxMall; | ||||
| import com.simple.domain.po.WxMerchant; | import com.simple.domain.po.WxMerchant; | ||||
| import com.simple.mapper.*; | import com.simple.mapper.*; | ||||
| @@ -64,42 +66,72 @@ public class DaliyAmountSchedule { | |||||
| for (int j=0; j < merchantList.size(); j++) { | for (int j=0; j < merchantList.size(); j++) { | ||||
| merchant = merchantList.get(j); | merchant = merchantList.get(j); | ||||
| HashMap dateMap = new HashMap(); | |||||
| Map dateMap = new HashMap(); | |||||
| SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); | SimpleDateFormat fmt = new SimpleDateFormat("yyyy-MM-dd"); | ||||
| String dateString = fmt.format(new Date()); | String dateString = fmt.format(new Date()); | ||||
| Date startDate = null; | |||||
| try { | try { | ||||
| Date startDate = fmt.parse(dateString); | |||||
| dateMap.put("startDate", startDate); | |||||
| dateMap.put("endDate", new Date()); | |||||
| dateMap.put("merchantID",merchant.getId()); | |||||
| List<WxCouponOrder> list = wxCouponOrderMapper.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(); | |||||
| } | |||||
| logger.info("\nFound " + list.size() + " coupon orders \n" + | |||||
| "for " + merchant.getId() + "\n" + | |||||
| "from " + startDate + " to " + new Date() +"\n" + | |||||
| "TOTAL ORDER=" + total_price); | |||||
| list= wxCouponOrderMapper.findListOfVerifiedByDate(dateMap); | |||||
| logger.info("find " + list.size() + " coupon order from " + startDate + " to " + new Date()); | |||||
| total_price = 0; | |||||
| for(WxCouponOrder couponOrder : list) { | |||||
| total_price = total_price + couponOrder.getCouponPrice(); | |||||
| } | |||||
| logger.info("\nFound " + list.size() + " coupon orders \n" + | |||||
| "for " + merchant.getId() + "\n" + | |||||
| "from " + startDate + " to " + new Date() +"\n" + | |||||
| "TOTAL VERIFIED=" + total_price); | |||||
| //daliy amount 落表 | |||||
| startDate = fmt.parse(dateString); | |||||
| } catch (ParseException e) { | } catch (ParseException e) { | ||||
| logger.error("Parse date string failed"); | logger.error("Parse date string failed"); | ||||
| continue; | |||||
| } | |||||
| dateMap.put("startDate", startDate); | |||||
| dateMap.put("endDate", new Date()); | |||||
| dateMap.put("merchantID",merchant.getId()); | |||||
| List<WxCouponOrder> list = wxCouponOrderMapper.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(); | |||||
| } | |||||
| logger.info("\nFound " + list.size() + " coupon orders \n" + | |||||
| "for " + merchant.getId() + "\n" + | |||||
| "from " + startDate + " to " + new Date() +"\n" + | |||||
| "TOTAL ORDER=" + total_price); | |||||
| Date now = new Date(); | |||||
| Calendar cal = Calendar.getInstance(); | |||||
| cal.setTime(now); // 将时分秒,毫秒域清零 | |||||
| cal.set(Calendar.HOUR_OF_DAY, 0); | |||||
| cal.set(Calendar.MINUTE, 0); | |||||
| cal.set(Calendar.SECOND, 0); | |||||
| cal.set(Calendar.MILLISECOND, 0); | |||||
| now = cal.getTime(); | |||||
| WxDateAmountRecord dateAmountRecord = new WxDateAmountRecord(); | |||||
| dateAmountRecord.setId(IdWorker.get().nextId()); | |||||
| dateAmountRecord.setCreateDate(new Date()); | |||||
| dateAmountRecord.setUpdateDate(new Date()); | |||||
| dateAmountRecord.setPayPrice(total_price); | |||||
| dateAmountRecord.setMerchantId(merchant.getId()); | |||||
| dateAmountRecord.setTenantId(merchant.getTenantId()); | |||||
| dateAmountRecord.setType(0); | |||||
| dateAmountRecord.setDate(now); | |||||
| dateAmountRecord.setDayOfWeek(cal.get(Calendar.DAY_OF_WEEK)); | |||||
| dateAmountRecord.setMonth(cal.get(Calendar.MONTH)); | |||||
| dateAmountRecord.setWeekOfYear(cal.get(Calendar.WEEK_OF_YEAR)); | |||||
| wxDateAmountRecordService.saveDaliyAmount(dateAmountRecord); | |||||
| list= wxCouponOrderMapper.findListOfVerifiedByDate(dateMap); | |||||
| logger.info("find " + list.size() + " coupon order from " + startDate + " to " + new Date()); | |||||
| total_price = 0; | |||||
| for(WxCouponOrder couponOrder : list) { | |||||
| total_price = total_price + couponOrder.getCouponPrice(); | |||||
| } | } | ||||
| logger.info("\nFound " + list.size() + " coupon orders \n" + | |||||
| "for " + merchant.getId() + "\n" + | |||||
| "from " + startDate + " to " + new Date() +"\n" + | |||||
| "TOTAL VERIFIED=" + total_price); | |||||
| dateAmountRecord.setId(IdWorker.get().nextId()); | |||||
| dateAmountRecord.setPayPrice(total_price); | |||||
| dateAmountRecord.setType(1); | |||||
| wxDateAmountRecordService.saveDaliyAmount(dateAmountRecord); | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| @@ -77,8 +77,8 @@ public class MsgSendingSchedule { | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | ||||
| message.put("sign", sign.toUpperCase()); | message.put("sign", sign.toUpperCase()); | ||||
| String str32 = "198b02e8fd704e96198b02e8fd704e96"; | |||||
| String iv = "198b02e8fd704e96"; | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | Map<String, String> params = new HashMap<>(); | ||||
| params.put("iv", iv); | params.put("iv", iv); | ||||
| @@ -0,0 +1,59 @@ | |||||
| package com.simple.schedule; | |||||
| import com.simple.domain.po.WxCouponOrder; | |||||
| import com.simple.domain.po.WxMall; | |||||
| import com.simple.domain.po.WxMerchant; | |||||
| import com.simple.domain.po.WxOrder; | |||||
| import com.simple.enums.EnumOrderStatus; | |||||
| import com.simple.mapper.WxCouponOrderMapper; | |||||
| import com.simple.mapper.WxMallMapper; | |||||
| import com.simple.mapper.WxMerchantMapper; | |||||
| import com.simple.mapper.WxOrderMapper; | |||||
| import com.simple.service.WxDateAmountRecordService; | |||||
| import org.apache.log4j.Logger; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.scheduling.annotation.Scheduled; | |||||
| import org.springframework.stereotype.Component; | |||||
| import org.springframework.transaction.annotation.Propagation; | |||||
| import org.springframework.transaction.annotation.Transactional; | |||||
| import java.text.ParseException; | |||||
| import java.text.SimpleDateFormat; | |||||
| import java.util.Date; | |||||
| import java.util.HashMap; | |||||
| import java.util.List; | |||||
| import java.util.Map; | |||||
| @Component | |||||
| public class OrderExpireSchedule { | |||||
| private final Logger logger = Logger.getLogger(OrderExpireSchedule.class); | |||||
| private final int TIME_OUT_VALUE = 15 * 60 * 1000; //15分钟 | |||||
| @Autowired | |||||
| WxOrderMapper wxOrderMapper; | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| @Scheduled(cron = "0 */5 * * * *?") // 每5分钟检查一次 | |||||
| //@Scheduled(cron = "*/10 * * * * ?") // 测试10秒中一次 | |||||
| public void orderExpireSchedule() { | |||||
| Map dateMap = new HashMap(); | |||||
| Date curDate = new Date(); | |||||
| //dateMap.put("startDate",new Date(curDate.getTime() - 2*TIME_OUT_VALUE)); | |||||
| dateMap.put("endDate", new Date(curDate.getTime() - TIME_OUT_VALUE )); | |||||
| List<WxOrder> wxOrderList = wxOrderMapper.findListOfUnpaidOrderByDate(dateMap); | |||||
| for(WxOrder wxOrder: wxOrderList){ | |||||
| wxOrder.setUpdateDate(new Date()); | |||||
| wxOrder.setOrderStatus(EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL.getCode()); | |||||
| wxOrderMapper.updateByPrimaryKeySelective(wxOrder); | |||||
| logger.info("\nFound " + wxOrder.getId() + "\n" | |||||
| + " create at " + wxOrder.getCreateDate() +"\n" | |||||
| + " expired at " + new Date()); | |||||
| } | |||||
| } | |||||
| } | |||||
| @@ -1,8 +1,8 @@ | |||||
| package com.simple.service; | package com.simple.service; | ||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.po.WxCouponChannel; | import com.simple.domain.po.WxCouponChannel; | ||||
| import com.simple.domain.vo.WxCouponChannelVo; | |||||
| public interface WxCouponChannelService { | public interface WxCouponChannelService { | ||||
| @@ -15,6 +15,8 @@ public interface WxCouponChannelService { | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| PageInfo<WxCouponChannel> listAsPage(WxCouponChannel record, Integer pageIndex, Integer pageSize); | PageInfo<WxCouponChannel> listAsPage(WxCouponChannel record, Integer pageIndex, Integer pageSize); | ||||
| PageInfo<WxCouponChannelVo> listPageCAPI(WxCouponChannel record, Integer pageIndex, Integer pageSize); | |||||
| /** | /** | ||||
| * 根据Id获得实体 | * 根据Id获得实体 | ||||
| @@ -49,8 +49,10 @@ public interface WxDateAmountRecordService { | |||||
| int updateAmount(String tenantId,Long merchantId | int updateAmount(String tenantId,Long merchantId | ||||
| ,Integer type,Integer payPrice); | ,Integer type,Integer payPrice); | ||||
| /** | |||||
| * 记录每日交易核销总额 | |||||
| */ | |||||
| void saveDaliyAmount(WxDateAmountRecord amount); | |||||
| } | } | ||||
| @@ -42,4 +42,6 @@ public interface WxMallBuildingService { | |||||
| ResultData getbuildinglist(String tenantId); | ResultData getbuildinglist(String tenantId); | ||||
| ResultData getbuildingfloorlist(String tenantId); | |||||
| } | } | ||||
| @@ -53,11 +53,18 @@ public interface WxOrderService { | |||||
| WxOrder sendUserFreeCoupon(Long userId, Long couponId); | WxOrder sendUserFreeCoupon(Long userId, Long couponId); | ||||
| /** | /** | ||||
| * 更新订单状态 | |||||
| * @param orderId | |||||
| * orderSuccess 订单已支付 | |||||
| * @param updateOrder | |||||
| * @return | |||||
| */ | |||||
| int orderSuccess(WxOrder updateOrder); | |||||
| /** | |||||
| * updateOrderStatus 更新订单状态, 只针对已取消及已退款 | |||||
| * @param updateOrder | |||||
| * @param enumOrderStatus | * @param enumOrderStatus | ||||
| */ | */ | ||||
| int updateOrderStatus(Long orderId, EnumOrderStatus enumOrderStatus); | |||||
| int updateOrderStatus(WxOrder updateOrder, EnumOrderStatus enumOrderStatus); | |||||
| /** | /** | ||||
| * 根据Id获得实体 | * 根据Id获得实体 | ||||
| @@ -18,7 +18,7 @@ public interface WxPayOrderService { | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 异步通知 | * 异步通知 | ||||
| @@ -78,6 +78,14 @@ public interface WxPayOrderService { | |||||
| */ | */ | ||||
| WxPayOrder getById(Long id); | WxPayOrder getById(Long id); | ||||
| /** | |||||
| * 根据obj获得实体 | |||||
| * | |||||
| * @param payOrder | |||||
| * @return | |||||
| */ | |||||
| WxPayOrder getByObj(WxPayOrder payOrder); | |||||
| /** | /** | ||||
| @@ -4,6 +4,7 @@ import java.util.*; | |||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxAppinfo; | import com.simple.domain.po.WxAppinfo; | ||||
| import com.simple.domain.po.WxPayOrder; | |||||
| import com.simple.domain.po.WxRefundOrder; | import com.simple.domain.po.WxRefundOrder; | ||||
| import com.simple.enums.EnumPayWay; | import com.simple.enums.EnumPayWay; | ||||
| @@ -11,12 +12,14 @@ public interface WxRefundOrderService { | |||||
| /** | /** | ||||
| * 创建退款订单 | * 创建退款订单 | ||||
| * @param isReal | |||||
| * @param appInfo | * @param appInfo | ||||
| * @param record 退款订单请求 | * @param record 退款订单请求 | ||||
| * @param payOrder 支付订单 | |||||
| * @param payWay | * @param payWay | ||||
| * @return | * @return | ||||
| */ | */ | ||||
| ResultData createRefundOrder(WxAppinfo appInfo, WxRefundOrder record, EnumPayWay payWay); | |||||
| ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, WxRefundOrder record, WxPayOrder payOrder, EnumPayWay payWay); | |||||
| /** | /** | ||||
| * 退款订单查询 | * 退款订单查询 | ||||
| @@ -1,10 +1,13 @@ | |||||
| package com.simple.service.impl; | package com.simple.service.impl; | ||||
| import java.util.*; | import java.util.*; | ||||
| import java.util.stream.Collectors; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.domain.po.WxCoupon; | import com.simple.domain.po.WxCoupon; | ||||
| import com.simple.domain.po.WxCouponChannel; | import com.simple.domain.po.WxCouponChannel; | ||||
| import com.simple.domain.vo.WxCouponChannelVo; | |||||
| import com.simple.mapper.WxCouponChannelMapper; | import com.simple.mapper.WxCouponChannelMapper; | ||||
| import com.simple.service.WxCouponChannelService; | import com.simple.service.WxCouponChannelService; | ||||
| import com.simple.service.WxCouponService; | import com.simple.service.WxCouponService; | ||||
| @@ -22,6 +25,13 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { | |||||
| WxCouponService wxCouponService; | WxCouponService wxCouponService; | ||||
| /** | |||||
| * B端业务端 | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| @Override | @Override | ||||
| public PageInfo<WxCouponChannel> listAsPage(WxCouponChannel record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxCouponChannel> listAsPage(WxCouponChannel record, Integer pageIndex, Integer pageSize) { | ||||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponChannelMapper.findList(record)); | return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxCouponChannelMapper.findList(record)); | ||||
| @@ -64,11 +74,13 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { | |||||
| } | } | ||||
| @Transactional | |||||
| public void addCuponChannel(Long couponid,Integer channelId,String tanantId){ | public void addCuponChannel(Long couponid,Integer channelId,String tanantId){ | ||||
| WxCoupon wxCouponUP = new WxCoupon(); | |||||
| wxCouponUP.setId(couponid); | |||||
| wxCouponUP.setStatus(1); | |||||
| wxCouponService.saveOrUpdate(wxCouponUP); | |||||
| WxCoupon wxCoupon = wxCouponService.getById(couponid); | |||||
| if(wxCoupon.getStatus()!=1) { | |||||
| wxCoupon.setStatus(1); | |||||
| wxCouponService.saveOrUpdate(wxCoupon); | |||||
| } | |||||
| WxCouponChannel wxCouponChannel = new WxCouponChannel(); | WxCouponChannel wxCouponChannel = new WxCouponChannel(); | ||||
| wxCouponChannel.setCouponId(couponid); | wxCouponChannel.setCouponId(couponid); | ||||
| wxCouponChannel.setCouponStatus(1); | wxCouponChannel.setCouponStatus(1); | ||||
| @@ -77,5 +89,33 @@ public class WxCouponChannelServiceImpl implements WxCouponChannelService { | |||||
| saveOrUpdate(wxCouponChannel); | saveOrUpdate(wxCouponChannel); | ||||
| } | } | ||||
| /** | |||||
| * C端api使用,关联查找的券时已生效 | |||||
| * @param record | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | |||||
| */ | |||||
| @Override | |||||
| public PageInfo<WxCouponChannelVo> listPageCAPI(WxCouponChannel record, Integer pageIndex, Integer pageSize) { | |||||
| List<WxCouponChannelVo> wxCouponChannelVoList = new ArrayList<>(); | |||||
| PageHelper.startPage(pageIndex, pageSize); | |||||
| wxCouponChannelVoList = wxCouponChannelMapper.findVoList(record); | |||||
| if(wxCouponChannelVoList.isEmpty()){ | |||||
| return new PageInfo<>(wxCouponChannelVoList); | |||||
| } | |||||
| List<Long> couponIds = wxCouponChannelVoList.stream().map(p->p.getCouponId()).distinct().collect(Collectors.toList()); | |||||
| WxCoupon wxCoupon = new WxCoupon(); | |||||
| wxCoupon.setIds(couponIds); | |||||
| List<WxCoupon> wxCoupons = wxCouponService.findList(wxCoupon); | |||||
| Map<Long,WxCoupon> couponNamesMap = wxCoupons.stream().collect(Collectors.toMap(WxCoupon::getId,p->p)); | |||||
| for (WxCouponChannelVo wxcouponVo:wxCouponChannelVoList) { | |||||
| if(couponNamesMap.get(wxcouponVo.getCouponId())!=null){ | |||||
| wxcouponVo.setWxCoupon(couponNamesMap.get(wxcouponVo.getCouponId())); | |||||
| } | |||||
| } | |||||
| return new PageInfo<>(wxCouponChannelVoList); | |||||
| } | |||||
| } | } | ||||
| @@ -59,8 +59,34 @@ public class WxDateAmountRecordServiceImpl implements WxDateAmountRecordService | |||||
| r.setTenantId(tenantId); | r.setTenantId(tenantId); | ||||
| r.setMerchantId(merchantId); | r.setMerchantId(merchantId); | ||||
| r.setType(type); | r.setType(type); | ||||
| List<WxDateAmountRecord> list = wxDateAmountRecordMapper.findList(r); | |||||
| r.setPayPrice(payPrice); | r.setPayPrice(payPrice); | ||||
| if(!list.isEmpty()) {//今天没数据就新增一条 | |||||
| r.setDayOfWeek(cal1.get(Calendar.DAY_OF_WEEK)); | |||||
| r.setMonth(cal1.get(Calendar.MONTH)); | |||||
| r.setWeekOfYear(cal1.get(Calendar.WEEK_OF_YEAR)); | |||||
| return wxDateAmountRecordMapper.insertSelective(r); | |||||
| } | |||||
| return wxDateAmountRecordMapper.updateAmount(r); | return wxDateAmountRecordMapper.updateAmount(r); | ||||
| } | } | ||||
| @Override | |||||
| public void saveDaliyAmount(WxDateAmountRecord amount) { | |||||
| WxDateAmountRecord record = new WxDateAmountRecord(); | |||||
| record.setDate(amount.getDate()); | |||||
| record.setTenantId(amount.getTenantId()); | |||||
| record.setMerchantId(amount.getMerchantId()); | |||||
| record.setType(amount.getType()); | |||||
| List<WxDateAmountRecord> list = wxDateAmountRecordMapper.findList(record); | |||||
| if (list.size() > 0){ | |||||
| list.get(0).setPayPrice(amount.getPayPrice()); | |||||
| list.get(0).setUpdateDate(new Date()); | |||||
| wxDateAmountRecordMapper.updateByPrimaryKeySelective(list.get(0)); | |||||
| }else{ | |||||
| wxDateAmountRecordMapper.insertSelective(amount); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| @@ -1,15 +1,19 @@ | |||||
| package com.simple.service.impl; | package com.simple.service.impl; | ||||
| import java.util.*; | |||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| import com.github.pagehelper.PageInfo; | import com.github.pagehelper.PageInfo; | ||||
| import com.simple.common.IdWorker; | |||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.WxMallBuilding; | import com.simple.domain.po.WxMallBuilding; | ||||
| import com.simple.domain.po.WxMallFloor; | |||||
| import com.simple.mapper.WxMallBuildingMapper; | import com.simple.mapper.WxMallBuildingMapper; | ||||
| import com.simple.mapper.WxMallFloorMapper; | |||||
| import com.simple.service.WxMallBuildingService; | import com.simple.service.WxMallBuildingService; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import com.simple.common.IdWorker; | |||||
| import java.util.List; | |||||
| import java.util.stream.Collectors; | |||||
| @Service | @Service | ||||
| public class WxMallBuildingServiceImpl implements WxMallBuildingService { | public class WxMallBuildingServiceImpl implements WxMallBuildingService { | ||||
| @@ -17,6 +21,8 @@ public class WxMallBuildingServiceImpl implements WxMallBuildingService { | |||||
| @Autowired | @Autowired | ||||
| WxMallBuildingMapper wxMallBuildingMapper; | WxMallBuildingMapper wxMallBuildingMapper; | ||||
| @Autowired | |||||
| WxMallFloorMapper wxMallFloorMapper; | |||||
| @Override | @Override | ||||
| public PageInfo<WxMallBuilding> listAsPage(WxMallBuilding record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxMallBuilding> listAsPage(WxMallBuilding record, Integer pageIndex, Integer pageSize) { | ||||
| @@ -53,5 +59,33 @@ public class WxMallBuildingServiceImpl implements WxMallBuildingService { | |||||
| return new ResultData(list); | return new ResultData(list); | ||||
| } | } | ||||
| @Override | |||||
| public ResultData getbuildingfloorlist(String tenantId) { | |||||
| WxMallBuilding wxMallBuilding = new WxMallBuilding(); | |||||
| wxMallBuilding.setTenantId(tenantId); | |||||
| List<WxMallBuilding> buildings = wxMallBuildingMapper.findList(wxMallBuilding); | |||||
| List<WxMallBuilding> wxMallBuildings = buildings.stream().map(b -> { | |||||
| WxMallBuilding tempb = new WxMallBuilding(); | |||||
| tempb.setId(b.getId()); | |||||
| tempb.setName(b.getName()); | |||||
| return tempb; | |||||
| }).collect(Collectors.toList()); | |||||
| for(WxMallBuilding building:wxMallBuildings){ | |||||
| WxMallFloor wxMallFloor = new WxMallFloor(); | |||||
| wxMallFloor.setBuildingId(building.getId()); | |||||
| List<WxMallFloor> wxMallFloors = wxMallFloorMapper.findList(wxMallFloor).stream().map(f -> { | |||||
| WxMallFloor tempf = new WxMallFloor(); | |||||
| tempf.setId(f.getId()); | |||||
| tempf.setFloorName(f.getFloorName()); | |||||
| return tempf; | |||||
| }).collect(Collectors.toList()); | |||||
| building.setFloors(wxMallFloors); | |||||
| } | |||||
| return new ResultData(wxMallBuildings); | |||||
| } | |||||
| } | } | ||||
| @@ -84,6 +84,7 @@ public class WxMerchantBUserServiceImpl implements WxMerchantBUserService { | |||||
| public boolean hasphone(String phone) { | public boolean hasphone(String phone) { | ||||
| WxMerchantBUser bUser = new WxMerchantBUser(); | WxMerchantBUser bUser = new WxMerchantBUser(); | ||||
| bUser.setPhone(phone); | bUser.setPhone(phone); | ||||
| bUser.setStatus(0); | |||||
| List<WxMerchantBUser> list = wxMerchantBUserMapper.findList(bUser); | List<WxMerchantBUser> list = wxMerchantBUserMapper.findList(bUser); | ||||
| return list.size()>=1?true:false; | return list.size()>=1?true:false; | ||||
| } | } | ||||
| @@ -62,6 +62,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| WxMerchantBUser wxMerchantBUser = new WxMerchantBUser(); | WxMerchantBUser wxMerchantBUser = new WxMerchantBUser(); | ||||
| wxMerchantBUser.setMerchantId(wxMerchant.getId()); | wxMerchantBUser.setMerchantId(wxMerchant.getId()); | ||||
| wxMerchantBUser.setStatus(0); | |||||
| List<WxMerchantBUser> bUserList = wxMerchantBUserMapper.findList(wxMerchantBUser); | List<WxMerchantBUser> bUserList = wxMerchantBUserMapper.findList(wxMerchantBUser); | ||||
| wxMerchant.setbUsers(bUserList); | wxMerchant.setbUsers(bUserList); | ||||
| return wxMerchant; | return wxMerchant; | ||||
| @@ -122,13 +123,8 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| WxShopMapper.updateByPrimaryKeySelective(wxShop); | WxShopMapper.updateByPrimaryKeySelective(wxShop); | ||||
| } | } | ||||
| //删除之前的关联用户 | |||||
| List<WxMerchantBUser> bUsers = wxMerchant.getbUsers(); | List<WxMerchantBUser> bUsers = wxMerchant.getbUsers(); | ||||
| for(WxMerchantBUser user:bUsers){ | |||||
| wxMerchantBUserMapper.deleteByPrimaryKey(user.getId()); | |||||
| } | |||||
| //保存商户关联用户 | //保存商户关联用户 | ||||
| for(WxMerchantBUser user:bUsers){ | for(WxMerchantBUser user:bUsers){ | ||||
| long id = idWorker.nextId(); | long id = idWorker.nextId(); | ||||
| @@ -140,6 +136,7 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| date = new Date(); | date = new Date(); | ||||
| user.setCreateDate(date); | user.setCreateDate(date); | ||||
| user.setUpdateDate(date); | user.setUpdateDate(date); | ||||
| user.setStatus(0); | |||||
| wxMerchantBUserMapper.insertSelective(user); | wxMerchantBUserMapper.insertSelective(user); | ||||
| } | } | ||||
| @@ -188,25 +185,43 @@ public class WxMerchantServiceImpl implements WxMerchantService { | |||||
| WxShopMapper.updateByPrimaryKeySelective(wxShop); | WxShopMapper.updateByPrimaryKeySelective(wxShop); | ||||
| } | } | ||||
| //删除之前的关联用户 | |||||
| List<WxMerchantBUser> bUsers = wxMerchant.getbUsers(); | List<WxMerchantBUser> bUsers = wxMerchant.getbUsers(); | ||||
| for(WxMerchantBUser user:bUsers){ | |||||
| wxMerchantBUserMapper.deleteByPrimaryKey(user.getId()); | |||||
| //删除之前的关联用户 | |||||
| WxMerchantBUser bUser = new WxMerchantBUser(); | |||||
| bUser.setMerchantId(wxMerchant.getId()); | |||||
| List<WxMerchantBUser> wxMerchantBUserMapperList = wxMerchantBUserMapper.findList(bUser); | |||||
| for(WxMerchantBUser wxMerchantBUser:wxMerchantBUserMapperList){ | |||||
| wxMerchantBUser.setStatus(1); | |||||
| wxMerchantBUserMapper.updateByPrimaryKeySelective(wxMerchantBUser); | |||||
| } | } | ||||
| //保存商户关联用户 | //保存商户关联用户 | ||||
| for(WxMerchantBUser user:bUsers){ | for(WxMerchantBUser user:bUsers){ | ||||
| long id = idWorker.nextId(); | |||||
| user.setId(id); | |||||
| user.setBUserId(id); | |||||
| user.setMerchantId(wxMerchant.getId()); | |||||
| user.setTenantId(wxMerchant.getTenantId()); | |||||
| user.setAppId(wxAppinfo.getAppId()); | |||||
| date = new Date(); | |||||
| user.setCreateDate(date); | |||||
| user.setUpdateDate(date); | |||||
| wxMerchantBUserMapper.insertSelective(user); | |||||
| if(user.getId()==null){//没有id的新增 | |||||
| long id = idWorker.nextId(); | |||||
| user.setId(id); | |||||
| user.setBUserId(id); | |||||
| user.setMerchantId(wxMerchant.getId()); | |||||
| user.setTenantId(wxMerchant.getTenantId()); | |||||
| user.setAppId(wxAppinfo.getAppId()); | |||||
| date = new Date(); | |||||
| user.setCreateDate(date); | |||||
| user.setUpdateDate(date); | |||||
| user.setStatus(0); | |||||
| wxMerchantBUserMapper.insertSelective(user); | |||||
| }else{//有id的更新 | |||||
| user.setBUserId(user.getId()); | |||||
| user.setMerchantId(wxMerchant.getId()); | |||||
| user.setTenantId(wxMerchant.getTenantId()); | |||||
| user.setAppId(wxAppinfo.getAppId()); | |||||
| date = new Date(); | |||||
| user.setUpdateDate(date); | |||||
| user.setStatus(0); | |||||
| wxMerchantBUserMapper.updateByPrimaryKeySelective(user); | |||||
| } | |||||
| } | } | ||||
| @@ -81,8 +81,8 @@ public class WxMsgModelServiceImpl implements WxMsgModelService { | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | ||||
| message.put("sign", sign.toUpperCase()); | message.put("sign", sign.toUpperCase()); | ||||
| String str32 = "198b02e8fd704e96198b02e8fd704e96"; | |||||
| String iv = "198b02e8fd704e96"; | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | Map<String, String> params = new HashMap<>(); | ||||
| params.put("iv", iv); | params.put("iv", iv); | ||||
| @@ -155,8 +155,8 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | ||||
| message.put("sign", sign.toUpperCase()); | message.put("sign", sign.toUpperCase()); | ||||
| String str32 = "198b02e8fd704e96198b02e8fd704e96"; | |||||
| String iv = "198b02e8fd704e96"; | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | Map<String, String> params = new HashMap<>(); | ||||
| params.put("iv", iv); | params.put("iv", iv); | ||||
| @@ -84,8 +84,8 @@ public class WxMsgValidationcodeModelServiceImpl implements WxMsgValidationcodeM | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | ||||
| message.put("sign", sign.toUpperCase()); | message.put("sign", sign.toUpperCase()); | ||||
| String str32 = "198b02e8fd704e96198b02e8fd704e96"; | |||||
| String iv = "198b02e8fd704e96"; | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | Map<String, String> params = new HashMap<>(); | ||||
| params.put("iv", iv); | params.put("iv", iv); | ||||
| @@ -78,29 +78,6 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
| @Override | @Override | ||||
| public ResultData sendvalidationcode(WxMsgValidationcode wxMsgValidationcode) { | public ResultData sendvalidationcode(WxMsgValidationcode wxMsgValidationcode) { | ||||
| WxMerchantBUser user = new WxMerchantBUser(); | |||||
| user.setAppId(wxMsgValidationcode.getAppid()); | |||||
| user.setPhone(wxMsgValidationcode.getPhone()); | |||||
| List<WxMerchantBUser> userList = wxMerchantBUserMapper.findList(user); | |||||
| if (userList.size()==0) { | |||||
| logger.error("B端用户不存在, phone: " + wxMsgValidationcode.getPhone()); | |||||
| return new ResultData(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| WxMerchant wxMerchant = new WxMerchant(); | |||||
| wxMerchant.setId(userList.get(0).getId()); | |||||
| List<WxMerchant> merchantList = wxMerchantMapper.findList(wxMerchant); | |||||
| if (merchantList.size()==0) { | |||||
| logger.error("B端所在商户不存在, id: " + userList.get(0).getId()); | |||||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||||
| } | |||||
| wxMerchant = merchantList.get(0); | |||||
| if(wxMerchant.getStatus()==0){ | |||||
| logger.error("B端所在商户已停用, id: " + userList.get(0).getId()); | |||||
| return new ResultData(ErrorCode.MERCHANT_INFO_NOT_VALID); | |||||
| } | |||||
| //1、查看是否存在未过期的短信,有返回成功 没有继续 | //1、查看是否存在未过期的短信,有返回成功 没有继续 | ||||
| List<WxMsgValidationcode> wxmsgvalidationcodelist = wxMsgValidationcodeMapper.findList(wxMsgValidationcode); | List<WxMsgValidationcode> wxmsgvalidationcodelist = wxMsgValidationcodeMapper.findList(wxMsgValidationcode); | ||||
| @@ -160,8 +137,8 @@ public class WxMsgValidationcodeServiceImpl implements WxMsgValidationcodeServic | |||||
| String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | String sign = HMACSHA256.sha256_HMAC(sb.toString(), secret); | ||||
| message.put("sign", sign.toUpperCase()); | message.put("sign", sign.toUpperCase()); | ||||
| String str32 = "198b02e8fd704e96198b02e8fd704e96"; | |||||
| String iv = "198b02e8fd704e96"; | |||||
| String str32 = HMACSHA256.STR2; | |||||
| String iv = HMACSHA256.IV; | |||||
| Map<String, String> params = new HashMap<>(); | Map<String, String> params = new HashMap<>(); | ||||
| params.put("iv", iv); | params.put("iv", iv); | ||||
| @@ -1,6 +1,5 @@ | |||||
| package com.simple.service.impl; | package com.simple.service.impl; | ||||
| import java.math.BigDecimal; | |||||
| import java.util.*; | import java.util.*; | ||||
| import com.github.pagehelper.PageHelper; | import com.github.pagehelper.PageHelper; | ||||
| @@ -8,14 +7,10 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.ErrorCode; | import com.simple.common.ErrorCode; | ||||
| import com.simple.domain.po.*; | import com.simple.domain.po.*; | ||||
| import com.simple.domain.vo.OrderVo; | import com.simple.domain.vo.OrderVo; | ||||
| import com.simple.enums.EnumCouponOrderStatus; | |||||
| import com.simple.enums.EnumOrderStatus; | |||||
| import com.simple.enums.EnumPayType; | |||||
| import com.simple.enums.EnumValidStatus; | |||||
| import com.simple.enums.*; | |||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.mapper.*; | import com.simple.mapper.*; | ||||
| import com.simple.service.WxOrderService; | import com.simple.service.WxOrderService; | ||||
| import com.simple.service.WxPayAccountService; | |||||
| import com.simple.utils.RedisLock; | import com.simple.utils.RedisLock; | ||||
| import org.apache.log4j.Logger; | import org.apache.log4j.Logger; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -71,29 +66,45 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| return wxOrderMapper.queryObject(orderVo); | return wxOrderMapper.queryObject(orderVo); | ||||
| } | } | ||||
| @Override | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public WxOrder saveOrder(WxCUser user, Long couponId) { | |||||
| String couponIdStr = String.valueOf(couponId); | |||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId); | |||||
| if (coupon == null) { | |||||
| logger.error("券不存在, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||||
| private int getUserCouponOrderCount(WxCUser user, WxCoupon counpon) { | |||||
| // 用户购买的券包数量 | |||||
| // + Order 待支付 | |||||
| // + couponOrder 待使用 | |||||
| int countOrder = 0, countCouponOrder = 0; | |||||
| WxOrder orderQ = new WxOrder(); | |||||
| orderQ.setCouponId(counpon.getId()); | |||||
| orderQ.setCUserId(user.getId()); | |||||
| orderQ.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||||
| try { | |||||
| countOrder = wxOrderMapper.selectCount(orderQ); | |||||
| }catch (Exception e) { | |||||
| logger.error("购买是否超限-DB, couponId: " + counpon.getId() + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| } | } | ||||
| //加锁 | |||||
| WxCouponOrder couponOrderQ = new WxCouponOrder(); | |||||
| couponOrderQ.setCouponId(counpon.getId()); | |||||
| couponOrderQ.setCUserId(user.getId()); | |||||
| couponOrderQ.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||||
| try { | |||||
| countCouponOrder = wxCouponOrderMapper.selectCount(couponOrderQ); | |||||
| }catch (Exception e) { | |||||
| logger.error("购买是否超限-DB, couponId: " + counpon.getId() + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| } | |||||
| return countOrder + countCouponOrder; | |||||
| } | |||||
| private void stockReduce(WxCUser user, WxCoupon coupon, String couponIdStr) { | |||||
| long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | ||||
| String timeStr = String.valueOf(time); | String timeStr = String.valueOf(time); | ||||
| // 库存加锁 | |||||
| if(!redisLock.lock(couponIdStr, timeStr)) { | if(!redisLock.lock(couponIdStr, timeStr)) { | ||||
| logger.error("此券被锁定, couponId: " + couponIdStr); | logger.error("此券被锁定, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | ||||
| } | } | ||||
| int payPrice = 0; | |||||
| int payment = 0; | |||||
| Date curr = new Date(); | |||||
| Date valid_date = null; | |||||
| // 检查 优惠券 库存 | // 检查 优惠券 库存 | ||||
| if (coupon.getRemainInventory() <= 0) { | if (coupon.getRemainInventory() <= 0) { | ||||
| //解锁 | //解锁 | ||||
| @@ -105,17 +116,13 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| // check 购买是否超限 | // check 购买是否超限 | ||||
| int count = 0; | int count = 0; | ||||
| try { | try { | ||||
| WxCouponOrder query = new WxCouponOrder(); | |||||
| query.setCouponId(couponId); | |||||
| query.setCUserId(user.getId()); | |||||
| query.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||||
| count = wxCouponOrderMapper.selectCount(query); | |||||
| }catch (Exception e) { | |||||
| count = getUserCouponOrderCount(user, coupon); | |||||
| } catch (Exception e) { | |||||
| //解锁 | //解锁 | ||||
| redisLock.unlock(couponIdStr, timeStr); | redisLock.unlock(couponIdStr, timeStr); | ||||
| logger.error("购买是否超限-DB, couponId: " + couponIdStr + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | } | ||||
| if (count > coupon.getUseLimitQuantity()) { | if (count > coupon.getUseLimitQuantity()) { | ||||
| //解锁 | //解锁 | ||||
| redisLock.unlock(couponIdStr, timeStr); | redisLock.unlock(couponIdStr, timeStr); | ||||
| @@ -135,69 +142,146 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| logger.error("此券减库存失败, couponId: " + couponIdStr); | logger.error("此券减库存失败, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| } | |||||
| payPrice = coupon.getSalePrice(); | |||||
| payment = coupon.getSalePrice(); | |||||
| private void stockBack(WxOrder updateOrder) { | |||||
| // 已取消/已退款,库存加1 | |||||
| // 获取订单相关coupon | |||||
| Long couponId = updateOrder.getCouponId(); | |||||
| String couponIdStr = "" + couponId; | |||||
| //加锁 | |||||
| long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | |||||
| String timeStr = String.valueOf(time); | |||||
| valid_date = (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode())? | |||||
| coupon.getValidEndDate(): | |||||
| new Date((curr.getTime()/1000+coupon.getValidDays()*24*60*60)*1000); | |||||
| if(!redisLock.lock(couponIdStr, timeStr)) { | |||||
| logger.error("此券被锁定, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | |||||
| } | |||||
| try { | |||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId); | |||||
| coupon.setRemainInventory(coupon.getRemainInventory() + 1); | |||||
| wxCouponMapper.updateByPrimaryKeySelective(coupon); | |||||
| } catch (Exception e) { | |||||
| logger.error("库存+1失败, e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "库存+1失败, e:" + e.getMessage()); | |||||
| } finally { | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| } | |||||
| } | |||||
| @Override | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public WxOrder saveOrder(WxCUser user, Long couponId) { | |||||
| // 检查用户 | |||||
| if (user == null) { | |||||
| logger.error("用户不存在"); | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| // 获取券信息 | |||||
| String couponIdStr = String.valueOf(couponId); | |||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId); | |||||
| if (coupon == null) { | |||||
| logger.error("券不存在, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| if (coupon.getStatus() == EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()) { | |||||
| logger.error("券已下架, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); | |||||
| } | |||||
| /* | |||||
| WxMerchant wxMerchant = wxMerchantMapper.selectByPrimaryKey(coupon.getMerchantId()); | |||||
| if (wxMerchant == null) { | |||||
| logger.error("商户不存在, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_FOUND); | |||||
| } | |||||
| if (wxMerchant.getStatus() == EnumMerchantStatus.NOT_VALID.getCode()) { | |||||
| logger.error("商户已禁用, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.MERCHANT_INFO_NOT_VALID); | |||||
| } | |||||
| */ | |||||
| // 减库存操作 | |||||
| try { | |||||
| stockReduce(user, coupon, couponIdStr); | |||||
| } catch (Exception e) { | |||||
| logger.error("减库存失败, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(), "减库存失败, couponId: " + couponIdStr); | |||||
| } | |||||
| Date curr = new Date(); | |||||
| int payment = coupon.getSalePrice(); | |||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| Long orderNumber = idWorker.nextId(); | Long orderNumber = idWorker.nextId(); | ||||
| // body | // body | ||||
| // tenant_id + merchant_id + title + subtitle | // tenant_id + merchant_id + title + subtitle | ||||
| String bodyStr = coupon.getTitle() + "/" + coupon.getSubTitle(); | |||||
| String bodyStr = coupon.getTitle() + "-" + coupon.getSubTitle(); | |||||
| WxOrder record = new WxOrder(); | WxOrder record = new WxOrder(); | ||||
| record.setId(orderNumber); | |||||
| record.setTenantId(user.getTenantId()); | |||||
| record.setOrderNumber(orderNumber); | |||||
| record.setCUserId(user.getId()); | |||||
| record.setMerchantId(coupon.getMerchantId()); | |||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||||
| record.setPayment(payment); | |||||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||||
| record.setDetail(bodyStr); | |||||
| record.setCreateDate(curr); | |||||
| record.setUpdateDate(curr); | |||||
| try { | try { | ||||
| // 保存订单 | // 保存订单 | ||||
| record.setId(orderNumber); | |||||
| record.setTenantId(user.getTenantId()); | |||||
| record.setOrderNumber(orderNumber); | |||||
| record.setCUserId(user.getId()); | |||||
| record.setMerchantId(coupon.getMerchantId()); | |||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||||
| record.setPayment(payment); | |||||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PENDING_PAYMENT.getCode()); | |||||
| record.setDetail(bodyStr); | |||||
| record.setCreateDate(curr); | |||||
| record.setUpdateDate(curr); | |||||
| wxOrderMapper.insertSelective(record); | wxOrderMapper.insertSelective(record); | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| // TODO 增库存 | |||||
| // 加库存 | |||||
| stockBack(record); | |||||
| logger.error("保存订单:" + e.getMessage()); | logger.error("保存订单:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(), "保存订单失败:" + record.toString()); | |||||
| } | } | ||||
| return record; | |||||
| } | |||||
| /** | |||||
| * 创建 couponOrder | |||||
| * @param user | |||||
| * @param order | |||||
| * @param coupon | |||||
| */ | |||||
| private void createCouponOrder(WxCUser user, WxOrder order, WxCoupon coupon) { | |||||
| Date curr = new Date(); | |||||
| Date valid_date = (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode())? | |||||
| coupon.getValidEndDate(): | |||||
| new Date((curr.getTime()/1000+coupon.getValidDays()*24*60*60)*1000); | |||||
| final IdWorker idWorker = IdWorker.get(); | |||||
| try { | try { | ||||
| WxCouponOrder couponOrder = new WxCouponOrder(); | WxCouponOrder couponOrder = new WxCouponOrder(); | ||||
| couponOrder.setId(idWorker.nextId()); | couponOrder.setId(idWorker.nextId()); | ||||
| couponOrder.setTenantId(user.getTenantId()); | couponOrder.setTenantId(user.getTenantId()); | ||||
| couponOrder.setCouponId(couponId); | |||||
| couponOrder.setCouponId(order.getCouponId()); | |||||
| couponOrder.setCUserId(user.getId()); | couponOrder.setCUserId(user.getId()); | ||||
| couponOrder.setOrderId(orderNumber); | |||||
| couponOrder.setOrderId(order.getOrderNumber()); | |||||
| couponOrder.setExpiredTime(valid_date); | couponOrder.setExpiredTime(valid_date); | ||||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | ||||
| couponOrder.setCreateDate(curr); | couponOrder.setCreateDate(curr); | ||||
| couponOrder.setUpdateDate(curr); | couponOrder.setUpdateDate(curr); | ||||
| couponOrder.setCouponPrice(payPrice); | |||||
| couponOrder.setCouponPrice(order.getPayment()); | |||||
| wxCouponOrderMapper.insertSelective(couponOrder); | wxCouponOrderMapper.insertSelective(couponOrder); | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| // TODO 增库存 | |||||
| logger.error("WxCouponOrder:" + e.getMessage()); | logger.error("WxCouponOrder:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL.getCode(), "couponOrder保存失败!"); | |||||
| } | } | ||||
| return record; | |||||
| } | } | ||||
| @Override | @Override | ||||
| public WxOrder sendUserFreeCoupon(Long userId, Long couponId) { | public WxOrder sendUserFreeCoupon(Long userId, Long couponId) { | ||||
| // check 用户状态 | |||||
| WxCUser user = null; | WxCUser user = null; | ||||
| try { | try { | ||||
| user = wxCUserMapper.selectByPrimaryKey(userId); | user = wxCUserMapper.selectByPrimaryKey(userId); | ||||
| @@ -209,78 +293,25 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | throw new MallinkException(ErrorCode.USER_IS_EMPTY); | ||||
| } | } | ||||
| // 检查券状态 | |||||
| String couponIdStr = String.valueOf(couponId); | String couponIdStr = String.valueOf(couponId); | ||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId); | WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponId); | ||||
| if (coupon == null) { | if (coupon == null) { | ||||
| logger.error("券不存在, couponId: " + couponIdStr); | logger.error("券不存在, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | ||||
| } | } | ||||
| if (coupon.getStatus() == EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()) { | |||||
| logger.error("券已下架, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); | |||||
| } | |||||
| if (coupon.getSalePrice() != 0) { | if (coupon.getSalePrice() != 0) { | ||||
| logger.error("券不免费, couponId: " + couponIdStr); | logger.error("券不免费, couponId: " + couponIdStr); | ||||
| throw new MallinkException(ErrorCode.COUPON_IS_NOT_FREE); | throw new MallinkException(ErrorCode.COUPON_IS_NOT_FREE); | ||||
| } | } | ||||
| //加锁 | |||||
| long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | |||||
| String timeStr = String.valueOf(time); | |||||
| if(!redisLock.lock(couponIdStr, timeStr)) { | |||||
| logger.error("此券被锁定, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | |||||
| } | |||||
| int payPrice = 0; | |||||
| int payment = 0; | |||||
| int payment = coupon.getSalePrice(); | |||||
| Date curr = new Date(); | Date curr = new Date(); | ||||
| Date valid_date = null; | |||||
| // 检查 优惠券 库存 | |||||
| if (coupon.getRemainInventory() <= 0) { | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| logger.error("此券库存为0, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.REMAIN_IS_EMPTY); | |||||
| } | |||||
| // check 购买是否超限 | |||||
| int count = 0; | |||||
| try { | |||||
| WxCouponOrder query = new WxCouponOrder(); | |||||
| query.setCouponId(couponId); | |||||
| query.setCUserId(user.getId()); | |||||
| query.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||||
| count = wxCouponOrderMapper.selectCount(query); | |||||
| }catch (Exception e) { | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| logger.error("购买是否超限-DB, couponId: " + couponIdStr + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| } | |||||
| if (count > coupon.getUseLimitQuantity()) { | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| logger.error("此券购买数量已超限, couponId: " + couponIdStr + ", count: " + count); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_LIMITED); | |||||
| } | |||||
| try { | |||||
| // 减库存 | |||||
| coupon.setRemainInventory(coupon.getRemainInventory() - 1); | |||||
| wxCouponMapper.updateByPrimaryKeySelective(coupon); | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| } catch (RuntimeException e) { | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| logger.error("此券减库存失败, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| } | |||||
| payPrice = coupon.getSalePrice(); | |||||
| payment = coupon.getSalePrice(); | |||||
| valid_date = (coupon.getValidType() == EnumValidStatus.VALID_RANGE.getCode())? | |||||
| coupon.getValidEndDate(): | |||||
| new Date((curr.getTime()/1000+coupon.getValidDays()*24*60*60)*1000); | |||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| Long orderNumber = idWorker.nextId(); | Long orderNumber = idWorker.nextId(); | ||||
| @@ -290,95 +321,106 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| String bodyStr = coupon.getTitle() + "/" + coupon.getSubTitle(); | String bodyStr = coupon.getTitle() + "/" + coupon.getSubTitle(); | ||||
| WxOrder record = new WxOrder(); | WxOrder record = new WxOrder(); | ||||
| record.setId(orderNumber); | |||||
| record.setTenantId(user.getTenantId()); | |||||
| record.setOrderNumber(orderNumber); | |||||
| record.setCUserId(user.getId()); | |||||
| record.setMerchantId(coupon.getMerchantId()); | |||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||||
| record.setPayment(payment); | |||||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||||
| record.setDetail(bodyStr); | |||||
| record.setCreateDate(curr); | |||||
| record.setUpdateDate(curr); | |||||
| // 保存订单 | |||||
| try { | try { | ||||
| // 保存订单 | |||||
| record.setId(orderNumber); | |||||
| record.setTenantId(user.getTenantId()); | |||||
| record.setOrderNumber(orderNumber); | |||||
| record.setCUserId(user.getId()); | |||||
| record.setMerchantId(coupon.getMerchantId()); | |||||
| record.setPaymentType(EnumPayType.PAY_PAYMENT.getCode()); | |||||
| record.setPayment(payment); | |||||
| record.setOrderStatus(EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS.getCode()); | |||||
| record.setDetail(bodyStr); | |||||
| record.setCreateDate(curr); | |||||
| record.setUpdateDate(curr); | |||||
| wxOrderMapper.insertSelective(record); | wxOrderMapper.insertSelective(record); | ||||
| } catch (RuntimeException e) { | |||||
| // TODO 增库存 | |||||
| } catch (Exception e) { | |||||
| //加库存 | |||||
| stockBack(record); | |||||
| logger.error("保存订单:" + e.getMessage()); | logger.error("保存订单:" + e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| // 创建couponOrder | |||||
| try { | try { | ||||
| WxCouponOrder couponOrder = new WxCouponOrder(); | |||||
| couponOrder.setId(idWorker.nextId()); | |||||
| couponOrder.setTenantId(user.getTenantId()); | |||||
| couponOrder.setCouponId(couponId); | |||||
| couponOrder.setCUserId(user.getId()); | |||||
| couponOrder.setOrderId(orderNumber); | |||||
| couponOrder.setExpiredTime(valid_date); | |||||
| couponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USE_WAIT.getCode()); | |||||
| couponOrder.setCreateDate(curr); | |||||
| couponOrder.setUpdateDate(curr); | |||||
| couponOrder.setCouponPrice(payPrice); | |||||
| wxCouponOrderMapper.insertSelective(couponOrder); | |||||
| } catch (RuntimeException e) { | |||||
| // TODO 增库存 | |||||
| logger.error("WxCouponOrder:" + e.getMessage()); | |||||
| createCouponOrder(user, record, coupon); | |||||
| } catch (Exception e) { | |||||
| logger.error("保存订单:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| return record; | return record; | ||||
| } | } | ||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public int updateOrderStatus(Long orderId,EnumOrderStatus enumOrderStatus) { | |||||
| WxOrder updateRecord = wxOrderMapper.selectByPrimaryKey(orderId); | |||||
| if (updateRecord == null) { | |||||
| logger.error("order updateStatus, order not found, orderId:" + updateRecord.getId()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | |||||
| } | |||||
| public int orderSuccess(WxOrder updateOrder) { | |||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(updateOrder.getCouponId()); | |||||
| if (coupon == null) { | |||||
| logger.error("券不存在, couponId: " + updateOrder.getCouponId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_IS_EMPTY); | |||||
| } | |||||
| if (coupon.getStatus() == EnumCouponStatus.COUPON_STATUS_TAKE_OFFF.getCode()) { | |||||
| logger.error("券已下架, couponId: " + updateOrder.getCouponId()); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); | |||||
| } | |||||
| 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_IS_FAIL.getCode(), "订单更新失败:" + e.getMessage()); | |||||
| } | |||||
| // 创建couponOrder | |||||
| try { | |||||
| createCouponOrder(user, updateOrder, coupon); | |||||
| } catch (Exception e) { | |||||
| logger.error("保存订单:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | |||||
| } | |||||
| return ret; | |||||
| } | |||||
| @Override | |||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||||
| public int updateOrderStatus(WxOrder updateOrder, EnumOrderStatus enumOrderStatus) { | |||||
| Date currentDate = new Date(); | |||||
| switch (enumOrderStatus) { | switch (enumOrderStatus) { | ||||
| case ORDER_STATUS_PAYMENT_SUCCESS: { | |||||
| // 已支付,更新支付时间 | |||||
| updateRecord.setPaymentTime(currentDate); | |||||
| break; | |||||
| } | |||||
| case ORDER_STATUS_OVERTIME_CANCEL: | case ORDER_STATUS_OVERTIME_CANCEL: | ||||
| case ORDER_STATUS_REFUND_SUCCESS: | case ORDER_STATUS_REFUND_SUCCESS: | ||||
| { | |||||
| // 已取消/已退款,库存加1 | |||||
| // 获取订单相关coupon | |||||
| WxCouponOrder couponOrder = new WxCouponOrder(); | |||||
| couponOrder.setOrderId(orderId); | |||||
| List<WxCouponOrder> colist = wxCouponOrderMapper.findList(couponOrder); | |||||
| for(WxCouponOrder couponOrderX : colist) { | |||||
| String couponIdStr = String.valueOf(couponOrderX.getCouponId()); | |||||
| //加锁 | |||||
| long time = System.currentTimeMillis() + RedisLock.TIMEOUT; | |||||
| String timeStr = String.valueOf(time); | |||||
| if(!redisLock.lock(couponIdStr, timeStr)) { | |||||
| logger.error("此券被锁定, couponId: " + couponIdStr); | |||||
| throw new MallinkException(ErrorCode.TOO_MANY_REQUEST); | |||||
| } | |||||
| WxCoupon coupon = wxCouponMapper.selectByPrimaryKey(couponOrderX.getCouponId()); | |||||
| coupon.setRemainInventory(coupon.getRemainInventory() + 1); | |||||
| wxCouponMapper.updateByPrimaryKeySelective(coupon); | |||||
| //解锁 | |||||
| redisLock.unlock(couponIdStr, timeStr); | |||||
| { | |||||
| try { | |||||
| stockBack(updateOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error("库存+1失败, e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "库存+1失败, e:" + e.getMessage()); | |||||
| } | } | ||||
| break; | break; | ||||
| } | } | ||||
| } | } | ||||
| updateRecord.setOrderStatus(enumOrderStatus.getCode()); | |||||
| updateRecord.setUpdateDate(currentDate); | |||||
| return wxOrderMapper.updateByPrimaryKey(updateRecord); | |||||
| int ret = 0; | |||||
| try { | |||||
| updateOrder.setOrderStatus(enumOrderStatus.getCode()); | |||||
| updateOrder.setUpdateDate(currentDate); | |||||
| ret = wxOrderMapper.updateByPrimaryKey(updateOrder); | |||||
| }catch (Exception e) { | |||||
| logger.error("订单状态更新失败, e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单状态更新失败, e:" + e.getMessage()); | |||||
| } | |||||
| return ret; | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -16,10 +16,7 @@ import com.simple.enums.EnumPayStatus; | |||||
| import com.simple.enums.EnumPayType; | import com.simple.enums.EnumPayType; | ||||
| import com.simple.enums.EnumPayWay; | import com.simple.enums.EnumPayWay; | ||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| import com.simple.mapper.WxAppinfoMapper; | |||||
| import com.simple.mapper.WxOrderMapper; | |||||
| import com.simple.mapper.WxPayAccountMapper; | |||||
| import com.simple.mapper.WxPayOrderMapper; | |||||
| import com.simple.mapper.*; | |||||
| import com.simple.pay.WxPay; | import com.simple.pay.WxPay; | ||||
| import com.simple.pay.WxPayOrderP; | import com.simple.pay.WxPayOrderP; | ||||
| import com.simple.pay.WxPayment; | import com.simple.pay.WxPayment; | ||||
| @@ -44,6 +41,9 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| @Autowired | @Autowired | ||||
| WxAppinfoMapper wxAppinfoMapper; | WxAppinfoMapper wxAppinfoMapper; | ||||
| @Autowired | |||||
| WxCUserMapper wxCUserMapper; | |||||
| @Autowired | @Autowired | ||||
| WxPayAccountMapper wxPayAccountMapper; | WxPayAccountMapper wxPayAccountMapper; | ||||
| @@ -73,7 +73,7 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| "\"NOT_UTF8\":{\"detail\":\"编码格式错误\",\"reason\":\"未使用指定编码格式\",\"resolution\":\"请使用UTF-8编码格式\"}}"); | "\"NOT_UTF8\":{\"detail\":\"编码格式错误\",\"reason\":\"未使用指定编码格式\",\"resolution\":\"请使用UTF-8编码格式\"}}"); | ||||
| @Override | @Override | ||||
| public ResultData createPayOrder(WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| public ResultData createPayOrder(boolean isReal, WxAppinfo appInfo, WxCUser user, WxPayOrder record, EnumPayWay payWay) { | |||||
| final IdWorker idworker = IdWorker.get(); | final IdWorker idworker = IdWorker.get(); | ||||
| try { | try { | ||||
| @@ -122,32 +122,32 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| } | } | ||||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | ||||
| // 统一下单 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| wxPayOrderP.setOpenid(user.getOpenId()); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15*60*1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| if (isReal) { | |||||
| // 统一下单 | |||||
| String noncestr = Utility.generate32UUID(); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| wxPayOrderP.setOpenid(user.getOpenId()); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setNonce_str(noncestr); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15*60*1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||||
| String response = WxPay.pushOrder(BeanUtils.toStringMap(wxPayOrderP)); | |||||
| logger.info("pay order, wechat pushOrder, " + wxPayOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| returnMap.put("payOrderId", payOrderNo); | |||||
| String result_code = returnMap.get("result_code"); | |||||
| if ("SUCCESS".equals(result_code)) { | |||||
| /* | /* | ||||
| Map<String, String> signMap = WxPayment.buildWeappSecondSignMap(returnMap.get("appid"), | Map<String, String> signMap = WxPayment.buildWeappSecondSignMap(returnMap.get("appid"), | ||||
| String.valueOf(Utility.getCurrentTimeStamp()), | String.valueOf(Utility.getCurrentTimeStamp()), | ||||
| @@ -158,24 +158,44 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| returnMap.putAll(signMap); | returnMap.putAll(signMap); | ||||
| returnMap.put("paySign", signAgent); | returnMap.put("paySign", signAgent); | ||||
| */ | */ | ||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| 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); | |||||
| String prepay_id = returnMap.get("prepay_id"); | |||||
| 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 { | |||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | |||||
| } | |||||
| } else { | } else { | ||||
| JSONObject errObj = errorMap.getJSONObject(result_code); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | |||||
| WxPayOrderP wxPayOrderP = new WxPayOrderP(); | |||||
| wxPayOrderP.setOpenid(user.getOpenId()); | |||||
| wxPayOrderP.setAppid(user.getAppId()); | |||||
| wxPayOrderP.setMch_id(payAccount.getMchId()); | |||||
| wxPayOrderP.setBody(order.getDetail()); | |||||
| wxPayOrderP.setOut_trade_no(record.getPayOrderNo()); | |||||
| wxPayOrderP.setTotal_fee(order.getPayment()); | |||||
| wxPayOrderP.setSpbill_create_ip(record.getIp()); // 终端IP | |||||
| wxPayOrderP.setNotify_url(payAccount.getPayNotifyUrl()); | |||||
| wxPayOrderP.setTrade_type(WxPay.TradeType.JSAPI.name()); // 终端类型 | |||||
| wxPayOrderP.setProduct_id(String.valueOf(order.getId())); // 订单ID | |||||
| wxPayOrderP.setTime_start(Utility.getDataFormatStringYYYYMMDDHHmmss(currentDate)); | |||||
| Date futureDate = new Date(); | |||||
| futureDate.setTime(currentDate.getTime() + 15*60*1000); | |||||
| wxPayOrderP.setTime_expire(Utility.getDataFormatStringYYYYMMDDHHmmss(futureDate)); // 15分钟后结束 | |||||
| wxPayOrderP.setSign(WxPayment.createSign(BeanUtils.toStringMap(wxPayOrderP), payAccount.getApiKey())); | |||||
| Map<String, String> returnMap = BeanUtils.toStringMap(wxPayOrderP); | |||||
| return new ResultData(Result.SUCCESS, "创建支付订单成功", returnMap); | |||||
| } | } | ||||
| } catch (RuntimeException e) { | } catch (RuntimeException e) { | ||||
| throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | throw new MallinkException(ErrorCode.PAY_ORDER_ERROR.getCode(), e.getMessage()); | ||||
| @@ -310,25 +330,32 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| // 修改支付订单状态 | // 修改支付订单状态 | ||||
| WxPayOrder updateOrder = new WxPayOrder(); | |||||
| updateOrder.setId(record.getId()); | |||||
| updateOrder.setOrderId(record.getOrderId()); | |||||
| updateOrder.setUpdateTime(currentDate); | |||||
| updateOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | |||||
| updateOrder.setTransactionId(transactionId); | |||||
| try { | try { | ||||
| WxPayOrder updateOrder = new WxPayOrder(); | |||||
| updateOrder.setId(record.getId()); | |||||
| updateOrder.setOrderId(record.getOrderId()); | |||||
| updateOrder.setUpdateTime(currentDate); | |||||
| updateOrder.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | |||||
| updateOrder.setTransactionId(transactionId); | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(updateOrder); | wxPayOrderMapper.updateByPrimaryKeySelective(updateOrder); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| logger.error("支付订单数据库更新失败: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "支付订单数据库更新失败: " + e.getMessage()); | |||||
| } | } | ||||
| // 修改订单状态 | // 修改订单状态 | ||||
| try { | try { | ||||
| wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); | |||||
| wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| logger.error("订单数据库更新失败: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单数据库更新失败: " + e.getMessage()); | |||||
| } | |||||
| // 创建couponOrder | |||||
| try { | |||||
| wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); | |||||
| } catch (Exception e) { | |||||
| logger.error("订单数据库更新失败: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单数据库更新失败: " + e.getMessage()); | |||||
| } | } | ||||
| /* | /* | ||||
| @@ -360,19 +387,24 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| logger.error("pay handle, order " + record.getOrderId() + " not found , payOrderGid : " + record.getPayOrderNo()); | logger.error("pay handle, order " + record.getOrderId() + " not found , payOrderGid : " + record.getPayOrderNo()); | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | throw new MallinkException(ErrorCode.ORDER_IS_NOT_FIND); | ||||
| } | } | ||||
| WxCUser user = wxCUserMapper.selectByPrimaryKey(order.getCUserId()); | |||||
| if (user == null) { | |||||
| logger.error("pay handle, order " + record.getOrderId() + " not found , payOrderGid : " + record.getPayOrderNo()); | |||||
| throw new MallinkException(ErrorCode.USER_IS_EMPTY); | |||||
| } | |||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| if (record.getId() > 0) { | if (record.getId() > 0) { | ||||
| // 修改支付订单状态 | // 修改支付订单状态 | ||||
| // 订单金额为0时,支付订单不创建,直接更改订单状态 | // 订单金额为0时,支付订单不创建,直接更改订单状态 | ||||
| WxPayOrder updateOrder = new WxPayOrder(); | |||||
| updateOrder.setId(record.getId()); | |||||
| updateOrder.setOrderId(record.getOrderId()); | |||||
| updateOrder.setUpdateTime(currentDate); | |||||
| updateOrder.setPayOrderStatus(record.getPayOrderStatus()); | |||||
| updateOrder.setPayTimeEnd(currentDate); | |||||
| updateOrder.setFailReason(record.getFailReason()); | |||||
| try { | try { | ||||
| WxPayOrder updateOrder = new WxPayOrder(); | |||||
| updateOrder.setId(record.getId()); | |||||
| updateOrder.setOrderId(record.getOrderId()); | |||||
| updateOrder.setUpdateTime(currentDate); | |||||
| updateOrder.setPayOrderStatus(record.getPayOrderStatus()); | |||||
| updateOrder.setPayTimeEnd(currentDate); | |||||
| updateOrder.setFailReason(record.getFailReason()); | |||||
| wxPayOrderMapper.updateByPrimaryKeySelective(updateOrder); | wxPayOrderMapper.updateByPrimaryKeySelective(updateOrder); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -383,17 +415,17 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| // 修改订单状态 | // 修改订单状态 | ||||
| if (record.getPayOrderStatus() == EnumPayStatus.PAY_WAY_SUCCESS.getCode()) { | if (record.getPayOrderStatus() == EnumPayStatus.PAY_WAY_SUCCESS.getCode()) { | ||||
| try { | try { | ||||
| int _count = wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_PAYMENT_SUCCESS); | |||||
| int _count = wxOrderService.orderSuccess(order); | |||||
| if (_count > 1) { | if (_count > 1) { | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | |||||
| } | } | ||||
| } else if (record.getPayOrderStatus() == EnumPayStatus.PAY_WAY_CANCEL.getCode()) { | } else if (record.getPayOrderStatus() == EnumPayStatus.PAY_WAY_CANCEL.getCode()) { | ||||
| try { | try { | ||||
| int _count = wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL); | |||||
| int _count = wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_OVERTIME_CANCEL); | |||||
| if (_count > 1) { | if (_count > 1) { | ||||
| throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | throw new MallinkException(ErrorCode.ORDER_IS_FAIL); | ||||
| } | } | ||||
| @@ -428,6 +460,15 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||||
| return wxPayOrderMapper.selectByPrimaryKey(id); | return wxPayOrderMapper.selectByPrimaryKey(id); | ||||
| } | } | ||||
| @Override | |||||
| public WxPayOrder getByObj(WxPayOrder payOrderQ) { | |||||
| List<WxPayOrder> list = wxPayOrderMapper.findList(payOrderQ); | |||||
| if (list.size() > 0) { | |||||
| return list.get(0); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| @Override | @Override | ||||
| public void saveOrUpdate(WxPayOrder record) { | public void saveOrUpdate(WxPayOrder record) { | ||||
| if (record.getId() == null) { | if (record.getId() == null) { | ||||
| @@ -11,7 +11,6 @@ import com.simple.common.Result; | |||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.*; | import com.simple.domain.po.*; | ||||
| import com.simple.enums.EnumOrderStatus; | import com.simple.enums.EnumOrderStatus; | ||||
| import com.simple.enums.EnumPayStatus; | |||||
| import com.simple.enums.EnumPayWay; | import com.simple.enums.EnumPayWay; | ||||
| import com.simple.enums.EnumRefundStatus; | import com.simple.enums.EnumRefundStatus; | ||||
| import com.simple.exception.MallinkException; | import com.simple.exception.MallinkException; | ||||
| @@ -42,6 +41,9 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| @Autowired | @Autowired | ||||
| WxRefundOrderMapper wxRefundOrderMapper; | WxRefundOrderMapper wxRefundOrderMapper; | ||||
| @Autowired | |||||
| WxCouponVerifyMapper wxCouponVerifyMapper; | |||||
| @Autowired | @Autowired | ||||
| WxOrderMapper wxOrderMapper; | WxOrderMapper wxOrderMapper; | ||||
| @@ -211,7 +213,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| "}"); | "}"); | ||||
| @Override | @Override | ||||
| public ResultData createRefundOrder(WxAppinfo appInfo, WxRefundOrder record, EnumPayWay payWay) { | |||||
| public ResultData createRefundOrder(boolean isReal, WxAppinfo appInfo, WxRefundOrder record, WxPayOrder payOrder, EnumPayWay payWay) { | |||||
| WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | WxPayAccount payAccount = wxPayAccountMapper.selectByPrimaryKey(appInfo.getPayId()); | ||||
| if (StringUtils.isBlank(payAccount.getApiKey())) { | if (StringUtils.isBlank(payAccount.getApiKey())) { | ||||
| logger.error("支付密钥为空"); | logger.error("支付密钥为空"); | ||||
| @@ -227,57 +229,25 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| logger.error("退款订单已存在, 无法再提交退款申请"); | logger.error("退款订单已存在, 无法再提交退款申请"); | ||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | throw new MallinkException(ErrorCode.REFUND_ORDER_EXIST.getCode(), "退款订单已存在, 无法再提交退款申请"); | ||||
| } | } | ||||
| // check 支付 订单 | |||||
| WxPayOrder payOrder = null; | |||||
| Long payOrderId = 0L; | |||||
| try { | |||||
| payOrderId = Long.valueOf(record.getPayOrderNo()); | |||||
| } catch (NumberFormatException e) { | |||||
| logger.error("参数转换异常: payOrderId-" + record.getPayOrderNo()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "参数转换异常: payOrderId-" + record.getPayOrderNo()); | |||||
| } | |||||
| try { | |||||
| WxPayOrder payOrderQ = new WxPayOrder(); | |||||
| payOrderQ.setOrderId(record.getOrderId()); | |||||
| payOrderQ.setId(payOrderId); | |||||
| payOrderQ.setPayOrderNo(record.getPayOrderNo()); | |||||
| payOrderQ.setPayOrderStatus(EnumPayStatus.PAY_WAY_SUCCESS.getCode()); | |||||
| List<WxPayOrder> payOrderList = wxPayOrderMapper.findList(payOrderQ); | |||||
| if (payOrderList.size() > 0) { | |||||
| payOrder = payOrderList.get(0); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| logger.error("数据库获取异常: " + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||||
| } | |||||
| if (payOrder == null) { | |||||
| logger.error("支付订单不存在: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_PAY_ORDER_IS_NOT_EXIST); | |||||
| } | |||||
| if (payOrder.getPayAmount() <= 0) { | |||||
| logger.error("支付订单金额小于等于0: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_PAY_ORDER_IS_ZERO); | |||||
| } | |||||
| // TODO 检查 是否已核销, 已核销不能退款 | |||||
| // 创建退款订单 | // 创建退款订单 | ||||
| final IdWorker idWorker = IdWorker.get(); | final IdWorker idWorker = IdWorker.get(); | ||||
| Long id = idWorker.nextId(); | Long id = idWorker.nextId(); | ||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| record.setId(id); | |||||
| record.setTenantId(appInfo.getTenantId()); | |||||
| record.setCreateTime(currentDate); | |||||
| record.setUpdateTime(currentDate); | |||||
| record.setTransactionId(payOrder.getTransactionId()); | |||||
| record.setCUserId(payOrder.getCUserId()); | |||||
| record.setTotalFee(payOrder.getPayAmount()); | |||||
| record.setRefundFee(payOrder.getPayAmount()); | |||||
| record.setRefundTimeStart(currentDate); | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_WAIT.getCode()); | |||||
| // 退款订单 | |||||
| try { | try { | ||||
| record.setId(id); | |||||
| record.setTenantId(appInfo.getTenantId()); | |||||
| record.setCreateTime(currentDate); | |||||
| record.setUpdateTime(currentDate); | |||||
| record.setTransactionId(payOrder.getTransactionId()); | |||||
| record.setCUserId(payOrder.getCUserId()); | |||||
| record.setTotalFee(payOrder.getPayAmount()); | |||||
| record.setRefundFee(payOrder.getPayAmount()); | |||||
| record.setRefundTimeStart(currentDate); | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_WAIT.getCode()); | |||||
| int sqlRow = wxRefundOrderMapper.insertSelective(record); | int sqlRow = wxRefundOrderMapper.insertSelective(record); | ||||
| if(sqlRow != 1) { | if(sqlRow != 1) { | ||||
| logger.error("退款订单数据库插入出错: " + record.toString()); | logger.error("退款订单数据库插入出错: " + record.toString()); | ||||
| @@ -300,40 +270,60 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| wxRefundOrderP.setTotal_fee(record.getTotalFee()); | wxRefundOrderP.setTotal_fee(record.getTotalFee()); | ||||
| wxRefundOrderP.setRefund_fee(record.getRefundFee()); | wxRefundOrderP.setRefund_fee(record.getRefundFee()); | ||||
| Map signMap = new HashMap(); | |||||
| try { | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款签名异常"); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getApiKey()); | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.error("微信退款订单申请成功: " + returnMap.toString()); | |||||
| if (isReal) { | |||||
| Map signMap = new HashMap(); | |||||
| try { | try { | ||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKey(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| signMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| logger.error("退款签名异常"); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| String signAgent = WxPayment.createSign(signMap, payAccount.getApiKey()); | |||||
| signMap.put("sign", signAgent); | |||||
| String response = WxPay.orderRefund(signMap, payAccount.getCertPath(), payAccount.getApiKey()); | |||||
| logger.info("微信退款订单:" + wxRefundOrderP.toString() + ", response: " + response.toString()); | |||||
| Map<String, String> returnMap = WxPayment.xmlToMap(response); | |||||
| String result_no = returnMap.get("result_code"); | |||||
| String refund_id = returnMap.get("refund_id"); | |||||
| // 设置 微信退款订单号 | |||||
| record.setRefundId(refund_id); | |||||
| if ("SUCCESS".equals(result_no)) { | |||||
| logger.error("微信退款订单申请成功: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKey(record); | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } else { | |||||
| logger.error("微信退款订单申请失败: " + returnMap.toString()); | |||||
| try { | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKey(record); | |||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | |||||
| } catch(Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | |||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | |||||
| } | |||||
| } | } | ||||
| } else { | } else { | ||||
| logger.error("微信退款订单申请失败: " + returnMap.toString()); | |||||
| // 虚拟支付 | |||||
| Map returnMap = null; | |||||
| try { | |||||
| returnMap = BeanUtils.toStringMap(wxRefundOrderP); | |||||
| } catch (Exception e) { | |||||
| logger.error("退款签名异常"); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_CAST_ERROR.getCode(), "退款签名异常"); | |||||
| } | |||||
| try { | try { | ||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_FAIL.getCode()); | |||||
| record.setRefundOrderStatus(EnumRefundStatus.REFUND_REQ_SUCCESS.getCode()); | |||||
| wxRefundOrderMapper.updateByPrimaryKey(record); | wxRefundOrderMapper.updateByPrimaryKey(record); | ||||
| JSONObject errObj = errorRefundReqMap.getJSONObject(result_no); | |||||
| return new ResultData(ErrorCode.PAY_ORDER_ERROR.getCode(), errObj.toJSONString(), returnMap); | |||||
| } catch(Exception e) { | |||||
| return new ResultData(Result.SUCCESS, "退款订单申请成功", returnMap); | |||||
| } catch (Exception e) { | |||||
| logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | logger.error("微信退款订单更新入库出错: " + e.getMessage() + ", record: " + record.toString()); | ||||
| throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | throw new MallinkException(ErrorCode.REFUND_ORDER_ERROR); | ||||
| } | } | ||||
| @@ -493,15 +483,15 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| } | } | ||||
| Date currentDate = new Date(); | Date currentDate = new Date(); | ||||
| WxRefundOrder updateOrder = new WxRefundOrder(); | |||||
| updateOrder.setId(refundOrder.getId()); | |||||
| updateOrder.setOrderId(refundOrder.getOrderId()); | |||||
| updateOrder.setUpdateTime(currentDate); | |||||
| updateOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_SUCCESS.getCode()); | |||||
| updateOrder.setTransactionId(transactionId); | |||||
| updateOrder.setRefundId(refundId); | |||||
| // 修改退款订单状态 | // 修改退款订单状态 | ||||
| try { | try { | ||||
| WxRefundOrder updateOrder = new WxRefundOrder(); | |||||
| updateOrder.setId(refundOrder.getId()); | |||||
| updateOrder.setOrderId(refundOrder.getOrderId()); | |||||
| updateOrder.setUpdateTime(currentDate); | |||||
| updateOrder.setRefundOrderStatus(EnumRefundStatus.REFUND_SUCCESS.getCode()); | |||||
| updateOrder.setTransactionId(transactionId); | |||||
| updateOrder.setRefundId(refundId); | |||||
| wxRefundOrderMapper.updateByPrimaryKeySelective(updateOrder); | wxRefundOrderMapper.updateByPrimaryKeySelective(updateOrder); | ||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| @@ -510,7 +500,7 @@ public class WxRefundOrderServiceImpl implements WxRefundOrderService { | |||||
| // 修改订单状态 | // 修改订单状态 | ||||
| try { | try { | ||||
| wxOrderService.updateOrderStatus(order.getId(), EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS); | |||||
| wxOrderService.updateOrderStatus(order, EnumOrderStatus.ORDER_STATUS_REFUND_SUCCESS); | |||||
| } catch (Exception e) { | } catch (Exception e) { | ||||
| logger.error(e.getMessage()); | logger.error(e.getMessage()); | ||||
| throw new MallinkException(ErrorCode.DB_FAIL); | throw new MallinkException(ErrorCode.DB_FAIL); | ||||
| @@ -5,6 +5,10 @@ import javax.crypto.spec.SecretKeySpec; | |||||
| public class HMACSHA256 { | public class HMACSHA256 { | ||||
| public static final String STR2 = "198b02e8fd704e96198b02e8fd704e96"; | |||||
| public static final String IV = "198b02e8fd704e96"; | |||||
| public static String byteArrayToHexString(byte[] b) { | public static String byteArrayToHexString(byte[] b) { | ||||
| StringBuilder hs = new StringBuilder(); | StringBuilder hs = new StringBuilder(); | ||||
| String stmp; | String stmp; | ||||
| @@ -10,12 +10,13 @@ | |||||
| <result column="type" jdbcType="INTEGER" property="type" /> | <result column="type" jdbcType="INTEGER" property="type" /> | ||||
| <result column="title" jdbcType="VARCHAR" property="title" /> | <result column="title" jdbcType="VARCHAR" property="title" /> | ||||
| <result column="target_ad" jdbcType="INTEGER" property="targetAd" /> | <result column="target_ad" jdbcType="INTEGER" property="targetAd" /> | ||||
| <result column="business" jdbcType="VARCHAR" property="business" /> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | ||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | ||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`merchant_id`,`coupon_id`,`coupon_status`,`type`,`title`,`target_ad`,`create_date`,`update_date` | |||||
| `id`,`tenant_id`,`merchant_id`,`coupon_id`,`coupon_status`,`type`,`title`,`target_ad`,`business`,`create_date`,`update_date` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -83,6 +84,25 @@ | |||||
| select <include refid="allColumns" /> from wx_coupon_channel | select <include refid="allColumns" /> from wx_coupon_channel | ||||
| <include refid="dynamicWhereConditions" /> | <include refid="dynamicWhereConditions" /> | ||||
| </select> | </select> | ||||
| <select id="findVoList" parameterType="com.simple.domain.po.WxCouponChannel" resultMap="CouponChannelVoMap"> | |||||
| select <include refid="allColumns" /> from wx_coupon_channel | |||||
| <include refid="dynamicWhereConditions" /> | |||||
| </select> | |||||
| <resultMap id="CouponChannelVoMap" type="com.simple.domain.vo.WxCouponChannelVo"> | |||||
| <id column="id" jdbcType="BIGINT" property="id" /> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | |||||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | |||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||||
| <result column="coupon_status" jdbcType="INTEGER" property="couponStatus" /> | |||||
| <result column="type" jdbcType="INTEGER" property="type" /> | |||||
| <result column="title" jdbcType="VARCHAR" property="title" /> | |||||
| <result column="target_ad" jdbcType="INTEGER" property="targetAd" /> | |||||
| <result column="business" jdbcType="VARCHAR" property="business" /> | |||||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate" /> | |||||
| <result column="update_date" jdbcType="TIMESTAMP" property="updateDate" /> | |||||
| </resultMap> | |||||
| @@ -14,11 +14,11 @@ | |||||
| <result column="token" jdbcType="VARCHAR" property="token" /> | <result column="token" jdbcType="VARCHAR" property="token" /> | ||||
| <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" /> | <result column="expire_time" jdbcType="TIMESTAMP" property="expireTime" /> | ||||
| <result column="name" jdbcType="VARCHAR" property="name" /> | <result column="name" jdbcType="VARCHAR" property="name" /> | ||||
| <result column="status" jdbcType="INTEGER" property="status" /> | |||||
| </resultMap> | </resultMap> | ||||
| <sql id="allColumns"> | <sql id="allColumns"> | ||||
| `id`,`tenant_id`,`b_user_id`,`phone`,`b_user_pwd`,`merchant_id`,`create_date`,`update_date`,`app_id`,`token`,`expire_time`,`name` | |||||
| `id`,`tenant_id`,`b_user_id`,`phone`,`b_user_pwd`,`merchant_id`,`create_date`,`update_date`,`app_id`,`token`,`expire_time`,`name`,`status` | |||||
| </sql> | </sql> | ||||
| <sql id="dynamicWhereConditions"> | <sql id="dynamicWhereConditions"> | ||||
| @@ -81,6 +81,9 @@ | |||||
| <if test=" null != name "> | <if test=" null != name "> | ||||
| and `name` = #{name} | and `name` = #{name} | ||||
| </if> | </if> | ||||
| <if test=" null != status "> | |||||
| and `status` = #{status} | |||||
| </if> | |||||
| <if test=" null != ids "> | <if test=" null != ids "> | ||||
| and id in | and id in | ||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | ||||
| @@ -7,6 +7,7 @@ | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | <result column="tenant_id" jdbcType="VARCHAR" property="tenantId" /> | ||||
| <result column="c_user_id" jdbcType="BIGINT" property="cUserId" /> | <result column="c_user_id" jdbcType="BIGINT" property="cUserId" /> | ||||
| <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | <result column="merchant_id" jdbcType="BIGINT" property="merchantId" /> | ||||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId" /> | |||||
| <result column="b_user_id" jdbcType="BIGINT" property="bUserId" /> | <result column="b_user_id" jdbcType="BIGINT" property="bUserId" /> | ||||
| <result column="payment_type" jdbcType="INTEGER" property="paymentType" /> | <result column="payment_type" jdbcType="INTEGER" property="paymentType" /> | ||||
| <result column="payment" jdbcType="INTEGER" property="payment" /> | <result column="payment" jdbcType="INTEGER" property="payment" /> | ||||
| @@ -52,8 +53,13 @@ | |||||
| <if test=" null != bUserId "> | <if test=" null != bUserId "> | ||||
| and `b_user_id` = #{bUserId} | and `b_user_id` = #{bUserId} | ||||
| </if> | |||||
| </if> | |||||
| <if test=" null != couponId "> | |||||
| and `coupon_id` = #{couponId} | |||||
| </if> | |||||
| <if test=" null != paymentType "> | <if test=" null != paymentType "> | ||||
| and `payment_type` = #{paymentType} | and `payment_type` = #{paymentType} | ||||
| @@ -183,7 +189,16 @@ | |||||
| </otherwise> | </otherwise> | ||||
| </choose> | </choose> | ||||
| </select> | </select> | ||||
| <select id="findListOfUnpaidOrderByDate" parameterType="map" resultMap="BaseResultMap"> | |||||
| select <include refid="allColumns" /> from wx_order | |||||
| where 1=1 | |||||
| <if test="startDate != null"> | |||||
| AND create_date > #{startDate,jdbcType=TIMESTAMP} | |||||
| </if> | |||||
| <if test="startDate != null"> | |||||
| AND create_date < #{endDate,jdbcType=TIMESTAMP} | |||||
| </if> | |||||
| AND order_status = '0' | |||||
| </select> | |||||
| </mapper> | </mapper> | ||||