Selaa lähdekoodia

使用优惠券的订单金额

zoujiajian 2 vuotta sitten
vanhempi
sitoutus
3116db416a

+ 2 - 0
netflix-dao/src/main/java/com/cyksj/mapper/OrderDonMapper.java

@@ -89,4 +89,6 @@ public interface OrderDonMapper extends BaseMapper<OrderDon> {
 	List<Long> getPayGoodsIds(@Param("userIds") List<Long> relationUserIdList);
 
 	BigDecimal getTotalRefundAmountTime(@Param("startDate") Date startDate, @Param("endDate") Date endDate);
+
+	BigDecimal getCouponUsedMoney(Long couponId);
 }

+ 6 - 0
netflix-dao/src/main/resources/mapper/OrderDonMapper.xml

@@ -507,4 +507,10 @@
             and created_time &lt; #{endDate}
         </if>
     </select>
+
+    <select id="getCouponUsedMoney" resultType="java.math.BigDecimal">
+        select sum(money) - sum(ifnull(refund_money, 0))
+        from (select id from coupon_user where coupon_id = #{couponId}) cu
+                 inner join order_don o on o.coupon_user_id = cu.id and o.status not in ('close', 'noPayment')
+    </select>
 </mapper>

+ 11 - 0
netflix-web/src/main/java/com/cyksj/web/controller/manage/coupon/CouponController.java

@@ -38,6 +38,8 @@ import org.springframework.web.bind.annotation.*;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.validation.constraints.Min;
+import java.math.BigDecimal;
+import java.math.RoundingMode;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
@@ -536,4 +538,13 @@ public class CouponController {
 				.build());
 		return GatewayResponse.SUCCESS.newBuilder().toResult(search);
 	}
+
+	/**
+	 * 使用优惠券订单金额
+	 */
+	@GetMapping("/get/used/money/{couponId}")
+	public Result<BigDecimal> getUsedMoney(@PathVariable Long couponId) {
+		BigDecimal money = Optional.ofNullable(orderDonMapper.getCouponUsedMoney(couponId)).orElse(BigDecimal.ZERO);
+		return GatewayResponse.SUCCESS.newBuilder().toResult(money.divide(BigDecimal.valueOf(100), 2, RoundingMode.DOWN));
+	}
 }