Commit abbf0ad4 by weijiguang

优化店铺距离限制

parent 9ca18783
...@@ -162,7 +162,7 @@ public class OrderController extends BaseController { ...@@ -162,7 +162,7 @@ public class OrderController extends BaseController {
order.setPaidAmount(order.getAmount().add(order.getCouponAmount())); order.setPaidAmount(order.getAmount().add(order.getCouponAmount()));
order.setCouponId(couponVo.getCouponId()); order.setCouponId(couponVo.getCouponId());
} else { } else {
couponUserService.orderDetailCheckAndAssign(order.getOrderDetails()); couponUserService.orderDetailCheckAndAssign(order.getShopId(), order.getOrderDetails());
} }
AjaxResult ajaxResult = orderService.insertOrder(loginUser, order, couponUserId); AjaxResult ajaxResult = orderService.insertOrder(loginUser, order, couponUserId);
......
...@@ -36,7 +36,7 @@ public interface GoodsSkuMapper ...@@ -36,7 +36,7 @@ public interface GoodsSkuMapper
* @param ids * @param ids
* @return * @return
*/ */
List<GoodsSku> selectSkuListForOrder(@Param("ids") List<Long> ids); List<GoodsSku> selectSkuListForOrder(@Param("shopId") Long shopId, @Param("ids") List<Long> ids);
/** /**
* 新增由规格选项组合生成商品sku * 新增由规格选项组合生成商品sku
......
...@@ -31,5 +31,5 @@ public interface ICouponUserService { ...@@ -31,5 +31,5 @@ public interface ICouponUserService {
void resovleCouponFitable(List<CouponVo> couponVos, Order order); void resovleCouponFitable(List<CouponVo> couponVos, Order order);
List<GoodsSku> orderDetailCheckAndAssign(List<OrderDetail> orderDetails); List<GoodsSku> orderDetailCheckAndAssign(Long shopId, List<OrderDetail> orderDetails);
} }
...@@ -178,11 +178,11 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -178,11 +178,11 @@ public class CouponUserServiceImpl implements ICouponUserService {
/** 可用门店和时段的校验 */ /** 可用门店和时段的校验 */
this.checkShopAndWeeklyFitable(couponVos, order.getShopId()); this.checkShopAndWeeklyFitable(couponVos, order.getShopId());
/** 可用饮品范围的判断 */ /** 可用饮品范围的判断 */
checkGoodsFitable(couponVos, order.getOrderDetails()); checkGoodsFitable(order.getShopId(), couponVos, order.getOrderDetails());
} }
private void checkGoodsFitable(List<CouponVo> couponVos, List<OrderDetail> orderDetails) { private void checkGoodsFitable(Long shopId, List<CouponVo> couponVos, List<OrderDetail> orderDetails) {
List<GoodsSku> goodsSkus = this.orderDetailCheckAndAssign(orderDetails); List<GoodsSku> goodsSkus = this.orderDetailCheckAndAssign(shopId, orderDetails);
List<Long> goodsIds = goodsSkus.stream().map(GoodsSku::getGoodsId).collect(Collectors.toList()); List<Long> goodsIds = goodsSkus.stream().map(GoodsSku::getGoodsId).collect(Collectors.toList());
List<Goods> goods = goodsMapper.selectGoodsByIds(goodsIds); List<Goods> goods = goodsMapper.selectGoodsByIds(goodsIds);
Assert.notEmpty(goods, "未查询到匹配的商品信息[id=" + goodsIds + "]"); Assert.notEmpty(goods, "未查询到匹配的商品信息[id=" + goodsIds + "]");
...@@ -234,11 +234,11 @@ public class CouponUserServiceImpl implements ICouponUserService { ...@@ -234,11 +234,11 @@ public class CouponUserServiceImpl implements ICouponUserService {
} }
@Override @Override
public List<GoodsSku> orderDetailCheckAndAssign(List<OrderDetail> orderDetails) { public List<GoodsSku> orderDetailCheckAndAssign(Long shopId, List<OrderDetail> orderDetails) {
Assert.notEmpty(orderDetails, "商品明细还未传递"); Assert.notEmpty(orderDetails, "商品明细还未传递");
List<Long> skuIds = orderDetails.stream().map(OrderDetail::getSkuId).collect(Collectors.toList()); List<Long> skuIds = orderDetails.stream().map(OrderDetail::getSkuId).collect(Collectors.toList());
Assert.notEmpty(skuIds, "skuId还未传递"); Assert.notEmpty(skuIds, "skuId还未传递");
List<GoodsSku> goodsSkus = goodsSkuMapper.selectSkuListForOrder(skuIds); List<GoodsSku> goodsSkus = goodsSkuMapper.selectSkuListForOrder(shopId, skuIds);
log.info("sku id size is {} and query size is {}", skuIds.size(), goodsSkus.size()); log.info("sku id size is {} and query size is {}", skuIds.size(), goodsSkus.size());
Assert.isTrue(goodsSkus.size() == skuIds.size(), "未查询到匹配的sku记录"); Assert.isTrue(goodsSkus.size() == skuIds.size(), "未查询到匹配的sku记录");
// sku的ID和价格字典 // sku的ID和价格字典
......
...@@ -21,10 +21,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" ...@@ -21,10 +21,11 @@ PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
<select id="selectSkuListForOrder" resultMap="GoodsSkuResult"> <select id="selectSkuListForOrder" resultMap="GoodsSkuResult">
select gs.id, gs.goods_id, gs.price, select gs.id, gs.goods_id, gs.price,
case when sgs.discount>=0 then sgs.discount else gs.discount end as discount, case when sgs.discount>=0 then sgs.discount else gs.discount end as discount, gs.is_deleted
gs.is_deleted from goods_sku gs from goods_sku gs
left join shop_goods_sku sgs on gs.goods_id = sgs.goods_id and gs.id = sgs.sku_id left join shop_goods_sku sgs on gs.goods_id = sgs.goods_id and gs.id = sgs.sku_id
where gs.id in where sgs.shop_id = #{shopId}
and gs.id in
<foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach> <foreach collection="ids" item="id" separator="," open="(" close=")">#{id}</foreach>
</select> </select>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment