| @@ -0,0 +1,104 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderPressService; | |||
| import com.iformall.service.WxOrderService; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiImplicitParam; | |||
| import io.swagger.annotations.ApiImplicitParams; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.GetMapping; | |||
| import org.springframework.web.bind.annotation.PostMapping; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import java.util.Date; | |||
| @RestController | |||
| @RequestMapping("/api/press") | |||
| @Api(description = "砍价接口") | |||
| public class WxPressOrderController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Autowired | |||
| WxCouponService wxCouponService; | |||
| @Autowired | |||
| WxOrderPressService wxOrderPressService; | |||
| // 砍价列表 - couponchannel | |||
| @ApiOperation("砍价订单-分页列表接口") | |||
| @GetMapping("pressOrderist") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData pressOrderist(Integer pageNum, Integer pageSize) { | |||
| WxCUser user = getUser(); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("我的砍价-分页列表接口") | |||
| @GetMapping("pressCouponList") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||
| public ResultData pressCouponList(Integer pageNum, Integer pageSize) { | |||
| WxCUser user = getUser(); | |||
| return new ResultData(); | |||
| } | |||
| // 发起砍价 | |||
| @ApiOperation("砍价详情") | |||
| @PostMapping("pressOrderDetail") | |||
| public ResultData pressOrderDetail() { | |||
| WxCUser user = getUser(); | |||
| return new ResultData(); | |||
| } | |||
| @ApiOperation("参与砍价") | |||
| @PostMapping("pressOrderJoin") | |||
| public ResultData pressOrderJoin(Long orderId) { | |||
| Date curDate = new Date(); | |||
| WxCUser user = getUser(); | |||
| WxOrder order = wxOrderService.getById(orderId); | |||
| if(order == null) { | |||
| logger.error("订单不存在:" + orderId); | |||
| return new ResultData(ErrorCode.ORDER_IS_NOT_FIND); | |||
| } | |||
| WxCoupon coupon = wxCouponService.getById(order.getProductId()); | |||
| if(coupon == null) { | |||
| logger.error("券不存在:" + order.getProductId()); | |||
| return new ResultData(ErrorCode.COUPON_IS_EMPTY); | |||
| } | |||
| if(order.getPressEndDate().after(curDate)) { | |||
| logger.error("砍价已超时:" + orderId); | |||
| return new ResultData(ErrorCode.COUPON_PRESS_IS_OVERTIME); | |||
| } | |||
| if(order.getPressCurrentNum().equals(coupon.getPressLimitNum())) { | |||
| logger.error("砍价已结束:" + orderId); | |||
| return new ResultData(ErrorCode.COUPON_PRESS_HAD_FINISHED); | |||
| } | |||
| wxOrderPressService.pressCouponJoin(order, coupon, user); | |||
| return new ResultData(); | |||
| } | |||
| } | |||
| @@ -157,6 +157,13 @@ public enum ErrorCode{ | |||
| */ | |||
| CARD_SPEND_IS_PAID(9050, "卡消费已支付"), | |||
| /** | |||
| * 砍价 | |||
| */ | |||
| COUPON_PRESS_HAD_FINISHED(9070, "砍价已完成"), | |||
| COUPON_PRESS_IS_OVERTIME(9071, "砍价已超时"), | |||
| /** | |||
| @@ -2,6 +2,9 @@ package com.iformall.service; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderPress; | |||
| public interface WxOrderPressService { | |||
| @@ -37,6 +40,14 @@ public interface WxOrderPressService { | |||
| * @param id | |||
| */ | |||
| void deleteById(Long id); | |||
| /** | |||
| * 加入砍价 | |||
| * @param order | |||
| * @param coupon | |||
| * @param user | |||
| */ | |||
| void pressCouponJoin(WxOrder order, WxCoupon coupon, WxCUser user); | |||
| @@ -3,19 +3,32 @@ package com.iformall.service.impl; | |||
| import java.util.*; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxCUser; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderPress; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.WxOrderMapper; | |||
| import com.iformall.mapper.WxOrderPressMapper; | |||
| import com.iformall.service.WxOrderPressService; | |||
| import com.iformall.utils.PressUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import com.iformall.common.IdWorker; | |||
| @Service | |||
| public class WxOrderPressServiceImpl implements WxOrderPressService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxOrderPressMapper wxOrderPressMapper; | |||
| @Autowired | |||
| WxOrderMapper wxOrderMapper; | |||
| @Override | |||
| public PageInfo<WxOrderPress> listAsPage(WxOrderPress record, Integer pageIndex, Integer pageSize) { | |||
| @@ -43,9 +56,44 @@ public class WxOrderPressServiceImpl implements WxOrderPressService { | |||
| public void deleteById(Long id) { | |||
| wxOrderPressMapper.deleteByPrimaryKey(id); | |||
| } | |||
| @Override | |||
| public void pressCouponJoin(WxOrder order, WxCoupon coupon, WxCUser user) { | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| Date curDate = new Date(); | |||
| // 添加 wx_order_press | |||
| int total = coupon.getPrice() - coupon.getSalePrice(); | |||
| int left_total = order.getPressCurrentValue(); | |||
| WxOrderPress orderPress = new WxOrderPress(); | |||
| orderPress.setId(idWorker.nextId()); | |||
| orderPress.setOrderId(order.getId()); | |||
| orderPress.setUserId(user.getId()); | |||
| orderPress.setCreateDate(curDate); | |||
| orderPress.setPressValue(PressUtils.stateLessPressValue(total, left_total, coupon.getPressLimitNum(), order.getPressCurrentNum())); | |||
| try { | |||
| // 保存订单 | |||
| wxOrderPressMapper.insertSelective(orderPress); | |||
| } catch (RuntimeException e) { | |||
| logger.error("保存砍价记录Err:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| // 更新砍价信息 | |||
| WxOrder orderUpdatePress = new WxOrder(); | |||
| orderUpdatePress.setId(order.getId()); | |||
| orderUpdatePress.setPressCurrentNum(order.getPressCurrentNum() + 1); | |||
| orderUpdatePress.setPressCurrentValue(left_total - orderPress.getPressValue()); | |||
| orderUpdatePress.setUpdateDate(new Date()); | |||
| try { | |||
| // 保存订单 | |||
| wxOrderMapper.updateByPrimaryKeySelective(orderUpdatePress); | |||
| } catch (RuntimeException e) { | |||
| logger.error("更新订单Err:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| } | |||
| @@ -432,7 +432,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| } catch (RuntimeException e) { | |||
| // 库存恢复 | |||
| stockBack(record); | |||
| logger.error("保存砍价记录Err:" + e.getMessage()); | |||
| logger.error("更新订单记录Err:" + e.getMessage()); | |||
| throw new MallinkException(ErrorCode.ORDER_SAVE_ERR); | |||
| } | |||
| } | |||