| @@ -64,14 +64,4 @@ public class WxCouponOrderController extends BaseController | |||||
| public ResultData findById(Long id) { | public ResultData findById(Long id) { | ||||
| return new ResultData(Result.SUCCESS,"查询成功",wxCouponOrderService.getById(id)); | return new ResultData(Result.SUCCESS,"查询成功",wxCouponOrderService.getById(id)); | ||||
| } | } | ||||
| @ApiOperation("核销接口") | |||||
| @PostMapping("verify") | |||||
| public ResultData verify(@RequestBody WxCouponOrder wxCouponOrder) { | |||||
| wxCouponOrderService.verify(wxCouponOrder.getId(),getUser()); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,113 @@ | |||||
| 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.WxCouponOrder; | |||||
| import com.simple.exception.MallinkException; | |||||
| import com.simple.service.WxCouponOrderService; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiImplicitParam; | |||||
| import io.swagger.annotations.ApiImplicitParams; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.apache.log4j.Logger; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("wxCouponOrder") | |||||
| @Api(description="核销和用户卡券查询接口") | |||||
| public class WxCouponOrderController extends BaseController | |||||
| { | |||||
| private Logger logger = Logger.getLogger(WxCouponOrderController.class); | |||||
| @Autowired | |||||
| private WxCouponOrderService wxCouponOrderService; | |||||
| @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 WxCouponOrder wxCouponOrder, Integer pageNum, Integer pageSize) { | |||||
| if (null == wxCouponOrder) wxCouponOrder = new WxCouponOrder(); | |||||
| final PageInfo<WxCouponOrder> page = wxCouponOrderService.listAsPage(wxCouponOrder, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| @ApiOperation("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxCouponOrder wxCouponOrder) { | |||||
| //Assert.notNull(wxCouponOrder.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxCouponOrderService.saveOrUpdate(wxCouponOrder); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxCouponOrder wxCouponOrder) { | |||||
| wxCouponOrderService.saveOrUpdate(wxCouponOrder); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxCouponOrderService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @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,"查询成功",wxCouponOrderService.getById(id)); | |||||
| } | |||||
| @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") | |||||
| @PostMapping("verify") | |||||
| public ResultData verify(@RequestBody Map<String, String> paramMap) { | |||||
| logger.info(paramMap.toString()); | |||||
| String couponOrderIdStr = paramMap.get("couponOrderId"); | |||||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||||
| logger.error("couponOrderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId不能为空"); | |||||
| } | |||||
| Long couponOrderId = 0L; | |||||
| try { | |||||
| couponOrderId = Long.valueOf(couponOrderIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| couponOrderId = 0L; | |||||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId参数不正确"); | |||||
| } | |||||
| return wxCouponOrderService.verify(couponOrderId, getUser()); | |||||
| } | |||||
| @ApiOperation(value = "退券接口", notes = "{\"couponOrderId\":\"string\"}") | |||||
| @PostMapping("refund") | |||||
| public ResultData refund(@RequestBody Map<String, String> paramMap) { | |||||
| logger.info(paramMap.toString()); | |||||
| String couponOrderIdStr = paramMap.get("couponOrderId"); | |||||
| if (StringUtils.isBlank(couponOrderIdStr)) { | |||||
| logger.error("couponOrderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId不能为空"); | |||||
| } | |||||
| Long couponOrderId = 0L; | |||||
| try { | |||||
| couponOrderId = Long.valueOf(couponOrderIdStr); | |||||
| } catch (NumberFormatException e) { | |||||
| couponOrderId = 0L; | |||||
| logger.error("couponOrderId参数不正确: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.PARAMETER_NOT_NULL.getCode(), "couponOrderId参数不正确"); | |||||
| } | |||||
| return wxCouponOrderService.refund(couponOrderId, getUser()); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,115 @@ | |||||
| 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.*; | |||||
| 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.PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||||
| } | |||||
| if (StringUtils.isBlank(payOrderIdStr)) { | |||||
| logger.error("payOrderId不能为空: " + paramMap.toString()); | |||||
| return new ResultData(ErrorCode.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.PARAMETER_NOT_NULL.getCode(), "orderId参数不正确"); | |||||
| } | |||||
| WxRefundOrder refundOrder = new WxRefundOrder(); | |||||
| refundOrder.setPayOrderNo(payOrderIdStr); | |||||
| refundOrder.setOrderId(orderId); | |||||
| WxMerchantBUser bUser = getUser(); | |||||
| WxAppinfo appinfo = getAppInfo(bUser.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("新增接口") | |||||
| @PostMapping("add") | |||||
| public ResultData add(@RequestBody WxRefundOrder wxRefundOrder) { | |||||
| //Assert.notNull(wxRefundOrder.getName(), "角色名不能为空"); | |||||
| //Assert.isTrue(!checkUnique(sysRole.getName(), null), "重复的角色名"); | |||||
| wxRefundOrderService.saveOrUpdate(wxRefundOrder); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id更新接口") | |||||
| @PostMapping("update") | |||||
| public ResultData update(@RequestBody WxRefundOrder wxRefundOrder) { | |||||
| wxRefundOrderService.saveOrUpdate(wxRefundOrder); | |||||
| return new ResultData(); | |||||
| } | |||||
| @ApiOperation("根据id删除接口") | |||||
| @GetMapping("/del") | |||||
| @ApiImplicitParam(name="id",value="id",dataType="Long", paramType = "query",required=true) | |||||
| public ResultData delete(Long id) { | |||||
| wxRefundOrderService.deleteById(id); | |||||
| return new ResultData(Result.SUCCESS, "删除成功", null); | |||||
| } | |||||
| @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)); | |||||
| } | |||||
| } | |||||
| @@ -5,6 +5,7 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.MallUserInfo; | import com.simple.domain.po.MallUserInfo; | ||||
| import com.simple.domain.po.WxCouponOrder; | import com.simple.domain.po.WxCouponOrder; | ||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| public interface WxCouponOrderService { | public interface WxCouponOrderService { | ||||
| @@ -12,8 +13,8 @@ public interface WxCouponOrderService { | |||||
| * 根据实体查询分页列表 | * 根据实体查询分页列表 | ||||
| * | * | ||||
| * @param record | * @param record | ||||
| * @param offset | |||||
| * @param limit | |||||
| * @param pageIndex | |||||
| * @param pageSize | |||||
| * @return | * @return | ||||
| */ | */ | ||||
| PageInfo<WxCouponOrder> listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize); | PageInfo<WxCouponOrder> listAsPage(WxCouponOrder record, Integer pageIndex, Integer pageSize); | ||||
| @@ -40,20 +41,20 @@ public interface WxCouponOrderService { | |||||
| */ | */ | ||||
| void deleteById(Long id); | void deleteById(Long id); | ||||
| /** | /** | ||||
| * 根据主键Id(券码)核销 | |||||
| * 根据主键couponOrderId(券码)核销 | |||||
| * | * | ||||
| * @param id | |||||
| * @param mallUserInfo 核销人(登录用户) | |||||
| * @param couponOrderId | |||||
| * @param bUser 核销人(登录用户) | |||||
| */ | */ | ||||
| ResultData verify(Long id, MallUserInfo mallUserInfo); | |||||
| ResultData verify(Long couponOrderId, WxMerchantBUser bUser); | |||||
| /** | /** | ||||
| * 根据主键Id(券码)退券(款) | |||||
| * 根据主键couponOrderId(券码)退券(款) | |||||
| * | * | ||||
| * @param id | |||||
| * @param mallUserInfo 退券(款)人(登录用户) | |||||
| * @param couponOrderId | |||||
| * @param bUser 退券(款)人(登录用户) | |||||
| */ | */ | ||||
| ResultData refund(Long id, MallUserInfo mallUserInfo); | |||||
| ResultData refund(Long couponOrderId, WxMerchantBUser bUser); | |||||
| @@ -8,9 +8,13 @@ import com.simple.common.Result; | |||||
| import com.simple.common.ResultData; | import com.simple.common.ResultData; | ||||
| import com.simple.domain.po.MallUserInfo; | import com.simple.domain.po.MallUserInfo; | ||||
| import com.simple.domain.po.WxCouponOrder; | import com.simple.domain.po.WxCouponOrder; | ||||
| import com.simple.domain.po.WxMerchantBUser; | |||||
| import com.simple.enums.EnumCouponOrderStatus; | import com.simple.enums.EnumCouponOrderStatus; | ||||
| import com.simple.enums.EnumCouponStatus; | |||||
| import com.simple.exception.MallinkException; | |||||
| import com.simple.mapper.WxCouponOrderMapper; | import com.simple.mapper.WxCouponOrderMapper; | ||||
| import com.simple.service.WxCouponOrderService; | import com.simple.service.WxCouponOrderService; | ||||
| import org.apache.log4j.Logger; | |||||
| 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 org.springframework.transaction.annotation.Propagation; | import org.springframework.transaction.annotation.Propagation; | ||||
| @@ -20,7 +24,8 @@ import java.util.Date; | |||||
| @Service | @Service | ||||
| public class WxCouponOrderServiceImpl implements WxCouponOrderService { | public class WxCouponOrderServiceImpl implements WxCouponOrderService { | ||||
| private Logger logger = Logger.getLogger(WxCouponOrderServiceImpl.class); | |||||
| @Autowired | @Autowired | ||||
| WxCouponOrderMapper wxCouponOrderMapper; | WxCouponOrderMapper wxCouponOrderMapper; | ||||
| @@ -55,45 +60,60 @@ public class WxCouponOrderServiceImpl implements WxCouponOrderService { | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public ResultData verify(Long id, MallUserInfo mallUserInfo) { | |||||
| WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(id); | |||||
| if (wxCouponOrder.getCouponOrderStatus() == 2) { | |||||
| return new ResultData(Result.ERROR, "已过期"); | |||||
| public ResultData verify(Long couponOrderId, WxMerchantBUser bUser) { | |||||
| WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); | |||||
| if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode()) { | |||||
| logger.error("已过期: couponOrder-" + couponOrderId); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); | |||||
| } | |||||
| if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()) { | |||||
| logger.error("已退款: couponOrder-" + couponOrderId); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_INVALID); | |||||
| } | } | ||||
| if (wxCouponOrder.getCouponOrderStatus() == 3) { | |||||
| return new ResultData(Result.ERROR, "已退款"); | |||||
| if (wxCouponOrder.getCouponOrderStatus() == EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()) { | |||||
| logger.error("已经核销过的券: couponOrder-" + couponOrderId); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_USED); | |||||
| } | } | ||||
| if (wxCouponOrder.getCouponOrderStatus() == 1) { | |||||
| return new ResultData(Result.ERROR, "已经核销过的券"); | |||||
| try { | |||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode()); //1核销 | |||||
| wxCouponOrder.setBUserId(bUser.getId()); | |||||
| wxCouponOrder.setUpdateDate(new Date()); | |||||
| wxCouponOrderMapper.updateByPrimaryKeySelective(wxCouponOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error("db failed: couponOrder-" + couponOrderId + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||||
| } | } | ||||
| wxCouponOrder.setCouponOrderStatus(1); //1核销 | |||||
| wxCouponOrder.setBUserId(mallUserInfo.getId()); | |||||
| wxCouponOrder.setUpdateDate(new Date()); | |||||
| wxCouponOrderMapper.updateByPrimaryKeySelective(wxCouponOrder); | |||||
| return new ResultData(); | |||||
| return new ResultData(wxCouponOrder); | |||||
| } | } | ||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public ResultData refund(Long id, MallUserInfo mallUserInfo) { | |||||
| WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(id); | |||||
| public ResultData refund(Long couponOrderId, WxMerchantBUser bUser) { | |||||
| WxCouponOrder wxCouponOrder = wxCouponOrderMapper.selectByPrimaryKey(couponOrderId); | |||||
| if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode())) { | if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_OVER_TIME.getCode())) { | ||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_OVER_TIME); | |||||
| logger.error("已过期: couponOrder-" + couponOrderId); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); | |||||
| } | } | ||||
| if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode())) { | if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode())) { | ||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_INVALID); | |||||
| logger.error("已退款: couponOrder-" + couponOrderId); | |||||
| throw new MallinkException(ErrorCode.COUPON_ORDER_IS_OVER_TIME); | |||||
| } | } | ||||
| if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode())) { | if (wxCouponOrder.getCouponOrderStatus().equals(EnumCouponOrderStatus.COUPON_ORDER_USED.getCode())) { | ||||
| logger.error("已经核销过的券: couponOrder-" + couponOrderId); | |||||
| return new ResultData(ErrorCode.COUPON_ORDER_IS_USED); | return new ResultData(ErrorCode.COUPON_ORDER_IS_USED); | ||||
| } | } | ||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | |||||
| wxCouponOrder.setBUserId(mallUserInfo.getId()); | |||||
| wxCouponOrder.setUpdateDate(new Date()); | |||||
| wxCouponOrderMapper.updateByPrimaryKeySelective(wxCouponOrder); | |||||
| try { | |||||
| wxCouponOrder.setCouponOrderStatus(EnumCouponOrderStatus.COUPON_ORDER_INVALID.getCode()); //3退款,券作废 | |||||
| wxCouponOrder.setBUserId(bUser.getId()); | |||||
| wxCouponOrder.setUpdateDate(new Date()); | |||||
| wxCouponOrderMapper.updateByPrimaryKeySelective(wxCouponOrder); | |||||
| } catch (Exception e) { | |||||
| logger.error("db failed: couponOrder-" + couponOrderId + ", e:" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "DB FAILD " + e.getMessage()); | |||||
| } | |||||
| return new ResultData(wxCouponOrder); | return new ResultData(wxCouponOrder); | ||||
| } | } | ||||