| @@ -24,7 +24,6 @@ import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| @RestController | |||
| @@ -85,7 +84,7 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| } | |||
| @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\"}") | |||
| @ApiOperation(value = "下订单", notes = "{\"couponChannelId\":\"String\",\"couponId\":\"String\",\"press\":\"String\",\"orderGroupId\":\"String\"}") | |||
| @PostMapping("save") | |||
| public ResultData saveOrder(@RequestBody Map<String, String> paramMap) { | |||
| logger.info("OrderSave: " + paramMap.toString()); | |||
| @@ -94,11 +93,12 @@ public class WxOrderController extends BaseController { | |||
| String couponChannelIdStr = paramMap.get("couponChannelId"); | |||
| String couponIdStr = paramMap.get("couponId"); | |||
| String pressStr = paramMap.get("press"); | |||
| String orderGroupIdStr = paramMap.get("orderGroupId"); | |||
| if (StringUtils.isBlank(couponChannelIdStr)) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponChannelId不能为空"); | |||
| } | |||
| Long couponChannelId = 0L, couponId = 0L; | |||
| Long couponChannelId = 0L, couponId = 0L, orderGroupId = 0L; | |||
| boolean isPress = false; | |||
| if (StringUtils.isNotBlank(couponChannelIdStr)) { | |||
| @@ -143,10 +143,17 @@ public class WxOrderController extends BaseController { | |||
| } | |||
| } | |||
| WxCUser user = getUser(); | |||
| if (orderGroupIdStr != null) { | |||
| try { | |||
| orderGroupId = Long.valueOf(orderGroupIdStr); | |||
| } catch (Exception e) { | |||
| logger.error("orderGroupId转换失败"); | |||
| } | |||
| } | |||
| WxCUser user = getUser(); | |||
| try { | |||
| WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress); | |||
| WxOrder order = wxOrderService.saveCouponOrder(user, couponChannelId, couponId, isPress, orderGroupId); | |||
| return new ResultData(order); | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| @@ -0,0 +1,94 @@ | |||
| package com.iformall.controller; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderGroup; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.service.WxCouponService; | |||
| import com.iformall.service.WxOrderGroupService; | |||
| 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.ModelAttribute; | |||
| import org.springframework.web.bind.annotation.RequestMapping; | |||
| import org.springframework.web.bind.annotation.RestController; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/orderGroup") | |||
| @Api(description = "拼团接口") | |||
| public class WxOrderGroupController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Autowired | |||
| WxCouponService wxCouponService; | |||
| @Autowired | |||
| WxOrderGroupService wxOrderGroupService; | |||
| @ApiOperation(value = "查询差1个的团购信息") | |||
| @GetMapping("queryRemainOne") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "couponId", value = "券ID", dataType = "Long", paramType = "query", required = true) | |||
| }) | |||
| public ResultData queryRemainOne(@ModelAttribute WxOrderGroup wxOrderGroup) { | |||
| if (wxOrderGroup.getCouponId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); | |||
| } | |||
| wxOrderGroup.setRemainPeople(1); | |||
| wxOrderGroup.setStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING.getCode()); | |||
| wxOrderGroup.setTenantId(getTenantId()); | |||
| return wxOrderGroupService.queryRemainOne(wxOrderGroup); | |||
| } | |||
| @ApiOperation(value = "我的拼团") | |||
| @GetMapping("queryOrderGroup") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryOrderGroup(Integer pageNum, Integer pageSize) { | |||
| WxOrder wxOrder = new WxOrder(); | |||
| wxOrder.setCUserId(getUserId()); | |||
| wxOrder.setTenantId(getTenantId()); | |||
| final PageInfo<Map<String, Object>> page = wxOrderGroupService.queryOrderGroup(wxOrder, pageNum, pageSize); | |||
| return new ResultData(page); | |||
| } | |||
| @ApiOperation(value = "拼团状态") | |||
| @GetMapping("queryOrderGroupStatus") | |||
| @ApiImplicitParams({ | |||
| @ApiImplicitParam(name = "orderId", value = "orderId", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "couponId", value = "couponId", dataType = "Long", paramType = "query", required = true), | |||
| @ApiImplicitParam(name = "id", value = "id", dataType = "Long", paramType = "query", required = true), | |||
| }) | |||
| public ResultData queryOrderGroupStatus(@ModelAttribute WxOrderGroup wxOrderGroup) { | |||
| if (wxOrderGroup.getId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "id不能为空"); | |||
| } | |||
| if (wxOrderGroup.getCouponId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "couponId不能为空"); | |||
| } | |||
| if (wxOrderGroup.getOrderId() == null) { | |||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL.getCode(), "orderId不能为空"); | |||
| } | |||
| wxOrderGroup.setTenantId(getTenantId()); | |||
| return wxOrderGroupService.queryOrderGroupStatus(wxOrderGroup); | |||
| } | |||
| } | |||
| @@ -105,7 +105,8 @@ public class WxOrder implements Serializable { | |||
| @Transient | |||
| protected String statusStr; | |||
| @io.swagger.annotations.ApiModelProperty(value = "拼团ID", name = "orderGroupId") | |||
| private Long orderGroupId; | |||
| public Long getOrderNumber() { | |||
| return orderNumber; | |||
| @@ -186,7 +187,15 @@ public class WxOrder implements Serializable { | |||
| this.cUserId = cUserId; | |||
| } | |||
| public Long getCouponChannelId() { | |||
| public Long getCUserId() { | |||
| return cUserId; | |||
| } | |||
| public void setCUserId(Long _cUserId) { | |||
| cUserId = _cUserId; | |||
| } | |||
| public Long getCouponChannelId() { | |||
| return couponChannelId; | |||
| } | |||
| @@ -258,7 +267,15 @@ public class WxOrder implements Serializable { | |||
| this.statusStr = statusStr; | |||
| } | |||
| public static enum Field | |||
| public Long getOrderGroupId() { | |||
| return orderGroupId; | |||
| } | |||
| public void setOrderGroupId(Long orderGroupId) { | |||
| this.orderGroupId = orderGroupId; | |||
| } | |||
| public static enum Field | |||
| { | |||
| Id_ASC("`id` ASC"),Id_DESC("`id` DESC") | |||
| ,OrderNumber_ASC("`order_number` ASC"),OrderNumber_DESC("`order_number` DESC") | |||
| @@ -0,0 +1,146 @@ | |||
| package com.iformall.domain.po; | |||
| import lombok.Data; | |||
| import javax.persistence.Id; | |||
| import javax.persistence.Table; | |||
| import javax.persistence.Transient; | |||
| import java.io.Serializable; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| @Table(name = "wx_order_group") | |||
| @Data | |||
| public class WxOrderGroup implements Serializable { | |||
| private static final long serialVersionUID = 1L; | |||
| @Id | |||
| protected Long id; | |||
| @Transient | |||
| protected List<Long> ids; | |||
| @Transient | |||
| protected String sortColumns; | |||
| public Long getId() { | |||
| return id; | |||
| } | |||
| public void setId(Long id) { | |||
| this.id = id; | |||
| } | |||
| public String getSortColumns() { | |||
| return sortColumns; | |||
| } | |||
| public List<Long> getIds() { | |||
| return ids; | |||
| } | |||
| public void setIds(List<Long> ids) { | |||
| this.ids = ids; | |||
| } | |||
| /** | |||
| * 租户ID | |||
| **/ | |||
| @io.swagger.annotations.ApiModelProperty(value = "租户ID", name = "tenantId") | |||
| private String tenantId; | |||
| /** | |||
| * 订单ID | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "订单ID", name = "orderId") | |||
| private Long orderId; | |||
| /** | |||
| * 券ID | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "参与人ID", name = "userId") | |||
| private Long couponId; | |||
| /** | |||
| * 剩余人数 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "剩余人数", name = "remainPeople") | |||
| private Integer remainPeople; | |||
| /** | |||
| * 过期时间 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "过期时间", name = "expiredDate") | |||
| private Date expiredDate; | |||
| /** | |||
| * 创建时间 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "创建时间", name = "createDate") | |||
| private Date createDate; | |||
| /** | |||
| * 更新时间 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "更新时间", name = "updateDate") | |||
| private Date updateDate; | |||
| /** | |||
| * 状态 | |||
| */ | |||
| @io.swagger.annotations.ApiModelProperty(value = "状态", name = "status") | |||
| private Integer status; | |||
| @io.swagger.annotations.ApiModelProperty(value = "用户ID", name = "userId") | |||
| private Long userId; | |||
| public static enum Field { | |||
| Id_ASC("`id` ASC"), Id_DESC("`id` DESC"); | |||
| private String value; | |||
| Field(String value) { | |||
| this.value = value; | |||
| } | |||
| public String getValue() { | |||
| return value; | |||
| } | |||
| public void setCol(String value) { | |||
| this.value = value; | |||
| } | |||
| @Override | |||
| public String toString() { | |||
| return this.getValue(); | |||
| } | |||
| } | |||
| public void setSortColumns(WxOrder.Field... fields) { | |||
| if (fields == null || fields.length == 0) { | |||
| return; | |||
| } | |||
| for (int k = 0; k < fields.length; k++) { | |||
| if (fields[k] == null) { | |||
| return; | |||
| } | |||
| } | |||
| StringBuilder sb = new StringBuilder(fields[0].toString()); | |||
| for (int k = 1; k < fields.length; k++) { | |||
| sb.append(","); | |||
| sb.append(fields[k].toString()); | |||
| } | |||
| this.sortColumns = sb.toString(); | |||
| } | |||
| public void setSortColumns(String sortColumns) { | |||
| if (sortColumns == null || "".equals(sortColumns.trim())) { | |||
| return; | |||
| } | |||
| if (sortColumns.contains(",")) { | |||
| String[] cols = sortColumns.split(","); | |||
| java.util.List<WxOrder.Field> fList = new java.util.ArrayList(); | |||
| for (int k = 0; k < cols.length; k++) { | |||
| fList.add(WxOrder.Field.valueOf(cols[k])); | |||
| } | |||
| this.setSortColumns(fList.toArray(new WxOrder.Field[fList.size()])); | |||
| } else { | |||
| this.setSortColumns(WxOrder.Field.valueOf(sortColumns)); | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,37 @@ | |||
| package com.iformall.enums; | |||
| /** | |||
| * Created by Stormeye on 2018/08/09. | |||
| */ | |||
| public enum EnumOrderGroupStatus { | |||
| COUPON_ORDER_USED(1, "拼团中"), | |||
| COUPON_ORDER_OVER_TIME(2, "拼团成功"), | |||
| COUPON_ORDER_INVALID(3, "拼团超时"), | |||
| CARD_USING(4, "拼团失败"),; | |||
| public static EnumOrderGroupStatus getEnum(Integer code) { | |||
| for (EnumOrderGroupStatus value : values()) { | |||
| if (value.getCode().equals(code)) { | |||
| return value; | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| private Integer code; | |||
| private String message; | |||
| EnumOrderGroupStatus(Integer code, String message) { | |||
| this.code = code; | |||
| this.message = message; | |||
| } | |||
| public Integer getCode() { | |||
| return code; | |||
| } | |||
| public String getMessage() { | |||
| return message; | |||
| } | |||
| } | |||
| @@ -16,7 +16,11 @@ public enum EnumOrderStatus { | |||
| ORDER_STATUS_PRESSING(6, "砍价中"), | |||
| ORDER_STATUS_PRESS_COMPLETE(7, "砍价完成"), | |||
| ORDER_STATUS_PRESS_OVERTIME(8, "砍价已过期"), | |||
| ORDER_STATUS_PRESS_CANCEL(9, "砍价已取消") | |||
| ORDER_STATUS_PRESS_CANCEL(9, "砍价已取消"), | |||
| ORDER_STATUS_COOPERATING(10, "拼团中"), | |||
| ORDER_STATUS_COOPERATING_COMPLETE(11, "拼团完成"), | |||
| ORDER_STATUS_COOPERATING_OVERTIME(12, "拼团已过期"), | |||
| ORDER_STATUS_COOPERATING_CANCEL(13, "拼团失败") | |||
| ; | |||
| public static EnumOrderStatus getEnum(Integer code) { | |||
| @@ -0,0 +1,20 @@ | |||
| package com.iformall.mapper; | |||
| import com.iformall.common.CommonMapper; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderGroup; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * @author gongbiao | |||
| */ | |||
| public interface WxOrderGroupMapper extends CommonMapper<WxOrderGroup, Long> { | |||
| Map<String, Object> queryRemainOne(WxOrderGroup group); | |||
| List<Map<String, Object>> queryOrderGroup(WxOrder wxOrder); | |||
| } | |||
| @@ -0,0 +1,24 @@ | |||
| package com.iformall.service; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.WxCoupon; | |||
| import com.iformall.domain.po.WxOrder; | |||
| import com.iformall.domain.po.WxOrderGroup; | |||
| import java.util.Map; | |||
| /** | |||
| * @author gongbiao | |||
| */ | |||
| public interface WxOrderGroupService { | |||
| void createOrderGroup(WxOrder order, WxCoupon wxCoupon); | |||
| ResultData queryRemainOne(WxOrderGroup wxOrderGroup); | |||
| PageInfo<Map<String, Object>> queryOrderGroup(WxOrder wxOrder, Integer pageNum, Integer pageSize); | |||
| ResultData queryOrderGroupStatus(WxOrderGroup wxOrderGroup); | |||
| } | |||
| @@ -37,9 +37,10 @@ public interface WxOrderService { | |||
| * 提交订单 | |||
| * @param user | |||
| * @param couponId | |||
| * @param orderGroupId | |||
| * @return 订单id | |||
| */ | |||
| WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress); | |||
| WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress, Long orderGroupId); | |||
| /** | |||
| * 付款码支付 | |||
| @@ -0,0 +1,184 @@ | |||
| package com.iformall.service.impl; | |||
| import com.github.pagehelper.PageHelper; | |||
| import com.github.pagehelper.PageInfo; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.common.IdWorker; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.domain.po.*; | |||
| import com.iformall.enums.EnumOrderStatus; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.service.WxOrderGroupService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.util.ArrayList; | |||
| import java.util.Date; | |||
| import java.util.List; | |||
| import java.util.Map; | |||
| /** | |||
| * @author gongbiao | |||
| */ | |||
| @Service | |||
| public class WxOrderGroupServiceImpl implements WxOrderGroupService { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| WxOrderGroupMapper wxOrderGroupMapper; | |||
| @Autowired | |||
| WxOrderMapper wxOrderMapper; | |||
| @Autowired | |||
| WxOrderService wxOrderService; | |||
| @Autowired | |||
| WxCUserMapper wxCUserMapper; | |||
| @Autowired | |||
| WxCouponMapper wxCouponMapper; | |||
| @Autowired | |||
| WxMallMapper wxMallMapper; | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, rollbackFor = {Exception.class}) | |||
| public void createOrderGroup(WxOrder order, WxCoupon wxCoupon) { | |||
| Long orderGroupId = order.getOrderGroupId(); | |||
| Long notOrderGroupId = 0L; | |||
| //查看是否首次拼团,orderGroupId不等于0代表不是首次拼团,因为第二个加入的拼团者肯定有团单号 | |||
| if (!orderGroupId.equals(notOrderGroupId)) { | |||
| logger.info("非首次拼团,更新拼团信息"); | |||
| WxOrderGroup wxOrderGroup = wxOrderGroupMapper.selectByPrimaryKey(orderGroupId); | |||
| int remainPeople = wxOrderGroup.getRemainPeople() - 1; | |||
| int endPeople = 0; | |||
| wxOrderGroup.setStatus(remainPeople == endPeople ? EnumOrderStatus.ORDER_STATUS_COOPERATING_COMPLETE.getCode() : wxOrderGroup.getStatus()); | |||
| wxOrderGroup.setRemainPeople(remainPeople); | |||
| wxOrderGroup.setUpdateDate(new Date()); | |||
| try { | |||
| wxOrderGroupMapper.updateByPrimaryKeySelective(wxOrderGroup); | |||
| } catch (Exception e) { | |||
| logger.error("更新拼团信息失败", e); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| //更新order | |||
| order.setPressEndDate(wxOrderGroup.getExpiredDate()); | |||
| order.setOrderGroupId(wxOrderGroup.getId()); | |||
| try { | |||
| wxOrderMapper.updateByPrimaryKey(order); | |||
| } catch (Exception e) { | |||
| logger.error("更新订单信息失败", e); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| if (remainPeople == endPeople) { | |||
| //得到所有拼团的order | |||
| WxOrder wxOrder = new WxOrder(); | |||
| wxOrder.setTenantId(order.getTenantId()); | |||
| wxOrder.setOrderGroupId(orderGroupId); | |||
| List<WxOrder> list = wxOrderMapper.findList(wxOrder); | |||
| for (WxOrder temp : list) { | |||
| try { | |||
| wxOrderService.couponOrderSuccess(temp); | |||
| } catch (Exception e) { | |||
| logger.error("创建COUPON_ORDER失败", e); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| } | |||
| } | |||
| } else { | |||
| logger.info("首次拼团,创建拼团信息"); | |||
| WxOrderGroup wxOrderGroup = new WxOrderGroup(); | |||
| final IdWorker idWorker = IdWorker.get(); | |||
| long groupId = idWorker.nextId(); | |||
| wxOrderGroup.setId(groupId); | |||
| wxOrderGroup.setTenantId(order.getTenantId()); | |||
| wxOrderGroup.setOrderId(order.getId()); | |||
| wxOrderGroup.setCouponId(wxCoupon.getId()); | |||
| wxOrderGroup.setRemainPeople(wxCoupon.getPressLimitNum() - 1); | |||
| wxOrderGroup.setUserId(order.getCUserId()); | |||
| Date date = new Date(); | |||
| wxOrderGroup.setCreateDate(date); | |||
| wxOrderGroup.setUpdateDate(date); | |||
| wxOrderGroup.setStatus(EnumOrderStatus.ORDER_STATUS_COOPERATING.getCode()); | |||
| Date expiredDate = DateUtils.getHourTimeAfter(wxCoupon.getPressLimitHours(), new Date()); | |||
| if (expiredDate.after(wxCoupon.getValidEndDate())) { | |||
| expiredDate = wxCoupon.getValidEndDate(); | |||
| } | |||
| wxOrderGroup.setExpiredDate(expiredDate); | |||
| try { | |||
| wxOrderGroupMapper.insertSelective(wxOrderGroup); | |||
| } catch (Exception e) { | |||
| logger.error("创建拼团信息失败", e); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| //更新order | |||
| order.setPressEndDate(expiredDate); | |||
| order.setOrderGroupId(groupId); | |||
| try { | |||
| wxOrderMapper.updateByPrimaryKey(order); | |||
| } catch (Exception e) { | |||
| logger.error("更新订单信息失败", e); | |||
| throw new MallinkException(ErrorCode.DB_FAIL); | |||
| } | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData queryRemainOne(WxOrderGroup wxOrderGroup) { | |||
| //取过期时间最大的数据 | |||
| WxOrderGroup group = wxOrderGroupMapper.select(wxOrderGroup).stream().max((x, y) -> { | |||
| return x.getExpiredDate().after(y.getExpiredDate()) ? 1 : 0; | |||
| }).orElse(null); | |||
| if (group == null) { | |||
| return new ResultData(Result.SUCCESS, "查询成功", group); | |||
| } | |||
| Map<String, Object> result = wxOrderGroupMapper.queryRemainOne(group); | |||
| return new ResultData(Result.SUCCESS, "查询成功", result); | |||
| } | |||
| @Override | |||
| public PageInfo<Map<String, Object>> queryOrderGroup(WxOrder wxOrder, Integer pageIndex, Integer pageSize) { | |||
| return PageHelper.startPage(pageIndex, pageSize).doSelectPageInfo(() -> wxOrderGroupMapper.queryOrderGroup(wxOrder)); | |||
| } | |||
| @Override | |||
| public ResultData queryOrderGroupStatus(WxOrderGroup wxOrderGroup) { | |||
| WxOrder wxOrder = new WxOrder(); | |||
| wxOrder.setId(wxOrderGroup.getOrderId()); | |||
| List<Map<String, Object>> couponOrderGroupList = wxOrderGroupMapper.queryOrderGroup(wxOrder); | |||
| Map<String, Object> couponOrderGroup = couponOrderGroupList.get(0); | |||
| //商场地址 | |||
| WxMall wxMall = new WxMall(); | |||
| wxMall.setTenantId(wxOrderGroup.getTenantId()); | |||
| List<WxMall> list = wxMallMapper.findList(wxMall); | |||
| if (!list.isEmpty()) { | |||
| couponOrderGroup.put("addr", list.get(0).getAddr()); | |||
| } | |||
| //参团人员 | |||
| wxOrder = new WxOrder(); | |||
| wxOrder.setOrderGroupId(wxOrderGroup.getId()); | |||
| wxOrder.setTenantId(wxOrderGroup.getTenantId()); | |||
| List<WxOrder> orderList = wxOrderMapper.select(wxOrder); | |||
| if (orderList.size() > 1) { | |||
| List<Long> ids = new ArrayList<>(); | |||
| for (WxOrder order : orderList) { | |||
| ids.add(order.getCUserId()); | |||
| } | |||
| WxCUser user = new WxCUser(); | |||
| user.setIds(ids); | |||
| List<WxCUser> userList = wxCUserMapper.findList(user); | |||
| couponOrderGroup.put("userList", userList); | |||
| } | |||
| return new ResultData(Result.SUCCESS, "查询成功", couponOrderGroup); | |||
| } | |||
| } | |||
| @@ -306,7 +306,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| @Override | |||
| @Transactional(propagation = Propagation.REQUIRED, readOnly = false, rollbackFor = {Exception.class}) | |||
| public WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress) { | |||
| public WxOrder saveCouponOrder(WxCUser user, Long couponChannelId, Long couponId, boolean isPress, Long orderGroupId) { | |||
| // 检查用户 | |||
| if (user == null) { | |||
| logger.error("用户不存在"); | |||
| @@ -369,6 +369,7 @@ public class WxOrderServiceImpl implements WxOrderService { | |||
| record.setDetail(bodyStr); | |||
| record.setCreateDate(curr); | |||
| record.setUpdateDate(curr); | |||
| record.setOrderGroupId(orderGroupId); | |||
| if (isPress) { | |||
| // 初始砍价信息 | |||
| record.setPressCurrentNum(0); | |||
| @@ -13,10 +13,7 @@ import com.iformall.enums.*; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.mapper.*; | |||
| import com.iformall.pay.*; | |||
| import com.iformall.service.WxAppinfoService; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.service.WxOrderService; | |||
| import com.iformall.service.WxPayOrderService; | |||
| import com.iformall.service.*; | |||
| import com.iformall.utils.BeanUtils; | |||
| import com.iformall.utils.MapUtil; | |||
| import com.iformall.utils.Utility; | |||
| @@ -28,6 +25,7 @@ import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.stereotype.Service; | |||
| import org.springframework.transaction.annotation.Propagation; | |||
| import org.springframework.transaction.annotation.Transactional; | |||
| import java.text.ParseException; | |||
| import java.util.*; | |||
| @@ -74,6 +72,10 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| @Autowired | |||
| WxAppinfoService wxAppinfoService; | |||
| @Autowired | |||
| WxOrderGroupService wxOrderGroupService; | |||
| JSONObject errorMap = JSON.parseObject("{" + | |||
| "\"NOAUTH\":{\"detail\":\"商户无此接口权限\",\"reason\":\"商户未开通此接口权限\",\"resolution\":\"请商户前往申请此接口权限\"}," + | |||
| "\"NOTENOUGH\":{\"detail\":\"余额不足\",\"reason\":\"用户帐号余额不足\",\"resolution\":\"用户帐号余额不足,请用户充值或更换支付卡后再支付\"}," + | |||
| @@ -1210,12 +1212,27 @@ public class WxPayOrderServiceImpl implements WxPayOrderService { | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "支付订单数据库更新失败: " + e.getMessage()); | |||
| } | |||
| // 修改订单状态 | |||
| try { | |||
| wxOrderService.couponOrderSuccess(order); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | |||
| //如果是Coupon是团购类型创建拼团信息不创建COUPON_ORDER | |||
| //查询券的类型 | |||
| Long productId = order.getProductId(); | |||
| WxCoupon wxCoupon = wxCouponMapper.selectByPrimaryKey(productId); | |||
| Integer type = wxCoupon.getType(); | |||
| if (type.equals(EnumCouponType.COUPON_GROUP.getCode())) { | |||
| try { | |||
| wxOrderGroupService.createOrderGroup(order, wxCoupon); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "拼团创建失败"); | |||
| } | |||
| } else { | |||
| // 修改订单状态 | |||
| try { | |||
| wxOrderService.couponOrderSuccess(order); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| throw new MallinkException(ErrorCode.DB_FAIL.getCode(), "订单更新"); | |||
| } | |||
| } | |||
| /* | |||
| @@ -653,13 +653,13 @@ | |||
| <sql id="allCUserCardListColumns"> | |||
| co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.expired_time,co.coupon_order_status,co.create_date,co.update_date, | |||
| c.cover_img,c.title,c.sub_title,c.detail,c.unit,c.remark, | |||
| a.amount,a.remaining_amount,c.support_transfer | |||
| a.amount,a.remaining_amount,a.support_transfer | |||
| </sql> | |||
| <sql id="allCUserCardDetailColumns"> | |||
| co.id,co.tenant_id,co.coupon_id,co.coupon_type,co.c_user_id,co.owner_id,co.b_user_id,co.order_id,co.expired_time,co.coupon_order_status,co.create_date,co.update_date,co.coupon_price, | |||
| c.cover_img,c.title,c.sub_title,c.sale_price,c.price,c.unit,c.detail,c.remark, | |||
| a.amount,a.remaining_amount,c.support_transfer | |||
| a.amount,a.remaining_amount,a.support_transfer | |||
| </sql> | |||
| @@ -0,0 +1,91 @@ | |||
| <?xml version="1.0" encoding="UTF-8"?> | |||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||
| <mapper namespace="com.iformall.mapper.WxOrderGroupMapper"> | |||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxOrderGroup"> | |||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||
| <result column="order_id" jdbcType="BIGINT" property="orderId"/> | |||
| <result column="coupon_id" jdbcType="BIGINT" property="couponId"/> | |||
| <result column="remain_people" jdbcType="INTEGER" property="remainPeople"/> | |||
| <result column="create_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="update_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="expired_date" jdbcType="TIMESTAMP" property="createDate"/> | |||
| <result column="status" jdbcType="SMALLINT" property="status"/> | |||
| <result column="user_id" jdbcType="BIGINT" property="userId"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`order_id`,`coupon_id`,`remain_people`,`create_date`,`update_date`,`expired_date`,`status`,`user_id` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| where 1 = 1 | |||
| <if test=" null != id "> | |||
| and `id` = #{id} | |||
| </if> | |||
| <if test=" null != tenantId "> | |||
| and `tenant_id` = #{tenantId} | |||
| </if> | |||
| <if test=" null != orderId "> | |||
| and `order_id` = #{orderId} | |||
| </if> | |||
| <if test=" null != userId "> | |||
| and `coupon_id` = #{couponId} | |||
| </if> | |||
| <if test=" null != pressValue "> | |||
| and `remain_people` = #{remainPeople} | |||
| </if> | |||
| <if test=" null != createDate "> | |||
| and `create_date` = #{createDate} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| #{idItem} | |||
| </foreach> | |||
| </if> | |||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||
| </sql> | |||
| <select id="findList" parameterType="com.iformall.domain.po.WxOrderGroup" resultMap="BaseResultMap"> | |||
| select | |||
| <include refid="allColumns"/> | |||
| from wx_order_group | |||
| <include refid="dynamicWhereConditions"/> | |||
| </select> | |||
| <select id="queryRemainOne" parameterType="com.iformall.domain.po.WxOrderGroup" resultType="hashmap"> | |||
| select o.press_end_date expiredDate,o.order_group_id orderGroupId,c.nick_name nickName, | |||
| c.avatar_url avatarUrl | |||
| from wx_order o | |||
| left join wx_c_user c on o.c_user_id=c.id | |||
| where o.tenant_id=#{tenantId} and o.id=#{orderId} | |||
| </select> | |||
| <select id="queryOrderGroup" parameterType="com.iformall.domain.po.WxOrder" resultType="hashmap"> | |||
| select o.id orderId,o.order_status orderStatus,o.order_group_id orderGroupId,c.title,c.sub_title subTitle, | |||
| c.sale_price salePrice,c.cover_img coverImg,g.remain_people remainPeople,c.id couponId,g.expired_date | |||
| expiredDate, | |||
| g.user_id firstUser,u.nick_name nickName,u.avatar_url avatarUrl | |||
| from wx_order o | |||
| left join wx_coupon c on o.product_id=c.id | |||
| left join wx_order_group g on o.order_group_id=g.id | |||
| left join wx_c_user u on o.c_user_id=u.id | |||
| where o.tenant_id=#{tenantId} | |||
| <if test=" null != cUserId "> | |||
| and o.c_user_id=#{cUserId} | |||
| </if> | |||
| <if test=" null != id "> | |||
| and o.id=#{id} | |||
| </if> | |||
| and o.order_group_id!=0 | |||
| order by o.id desc,o.order_status | |||
| </select> | |||
| </mapper> | |||
| @@ -19,11 +19,13 @@ | |||
| <result column="press_end_date" jdbcType="TIMESTAMP" property="pressEndDate"/> | |||
| <result column="press_current_num" jdbcType="INTEGER" property="pressCurrentNum"/> | |||
| <result column="press_current_value" jdbcType="INTEGER" property="pressCurrentValue"/> | |||
| <result column="order_group_id" jdbcType="BIGINT" property="orderGroupId"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`order_number`,`tenant_id`,`c_user_id`,`coupon_channel_id`,`product_id`,`type`,`payment_type`,`payment`,`payment_time`,`order_status`,`create_date`,`update_date`,`detail`, | |||
| `press_end_date`,`press_current_num`,`press_current_value` | |||
| `press_end_date`,`press_current_num`,`press_current_value`,`order_group_id` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -96,7 +98,11 @@ | |||
| <if test=" null != pressCurrentValue "> | |||
| and `press_current_value` = #{pressCurrentValue} | |||
| </if> | |||
| <if test=" null != orderGroupId "> | |||
| and `order_group_id` = #{orderGroupId} | |||
| </if> | |||
| <if test=" null != statusS "> | |||
| and `order_status` in | |||
| <foreach collection="statusS" index="index" item="sItem" open="(" separator="," close=")"> | |||