Jelajahi Sumber

fix 礼品卡可用数量

zoujiajian 2 tahun lalu
induk
melakukan
7279e35dbe

+ 1 - 1
netflix-dao/src/main/java/com/cyksj/mapper/GiftCardUserRecordMapper.java

@@ -14,6 +14,6 @@ import java.math.BigDecimal;
  *创建时间:2023/8/28 12:01
  */
 public interface GiftCardUserRecordMapper extends BaseMapper<GiftCardUserRecord> {
-	@Update("update gift_card_user_record set remain_crash = remain_crash + #{addCash} where id = #{gcId} and remain_crash = #{remainCash}")
+	@Update("update gift_card_user_record set remain_crash = remain_crash + #{addCash},is_used = 0 where id = #{gcId} and remain_crash = #{remainCash}")
 	Integer updateGiftCardRemainCash(@Param("gcId") Long gcId, @Param("addCash") BigDecimal addCash, @Param("remainCash") BigDecimal remainCash);
 }

+ 3 - 0
netflix-dao/src/main/java/com/cyksj/model/manage/views/OrderDonSearchView.java

@@ -153,6 +153,9 @@ public class OrderDonSearchView {
 	@DbIgnore
 	private List<GoodsDonSkuView> benefitsViews;
 
+	@DbField("o.pay_title")
+	private String payTitle;
+
 	/**
 	 * 关联兑换码
 	 */

+ 5 - 0
netflix-dao/src/main/java/com/cyksj/model/views/UserPersonalView.java

@@ -44,5 +44,10 @@ public class UserPersonalView {
 	 */
 	private Boolean isNoPayment;
 
+	/**
+	 * 礼品卡可用数量
+	 */
+	private Integer numOfGiftCard;
+
 	private String phone;
 }

+ 0 - 4
netflix-service/src/main/java/com/cyksj/service/giftcard/impl/GiftCardOrderUseRecordServiceImpl.java

@@ -38,10 +38,6 @@ public class GiftCardOrderUseRecordServiceImpl extends ServiceImpl<GiftCardOrder
 					BigDecimal remainCash = giftCardUserRecord.getRemainCash();
 					Integer update = giftCardUserRecordMapper.updateGiftCardRemainCash(gcId, addCash, remainCash);
 					if (update > 0) {
-						this.update(null, Wrappers.lambdaUpdate(GiftCardOrderUseRecord.class)
-								.set(GiftCardOrderUseRecord::getIsUsed, false)
-								.eq(GiftCardOrderUseRecord::getId, data.getId())
-								.eq(GiftCardOrderUseRecord::getIsUsed, true));
 						break;
 					}
 				}

+ 5 - 4
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -1919,13 +1919,13 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				BigDecimal remainCash = giftCard.getRemainCash();
 				//扣完
 				if (remainCash.compareTo(deductCash) == 0) {
-					deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords);
+					deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords, true);
 					deductCash = BigDecimal.ZERO;
 				} else if (remainCash.compareTo(deductCash) < 0) {
-					deductGiftCardCash(user.getId(), giftCard.getId(), remainCash, remainCash, gcUseRecords);
+					deductGiftCardCash(user.getId(), giftCard.getId(), remainCash, remainCash, gcUseRecords, true);
 					deductCash = deductCash.subtract(remainCash);
 				} else if (remainCash.compareTo(deductCash) > 0) {
-					deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords);
+					deductGiftCardCash(user.getId(), giftCard.getId(), deductCash, remainCash, gcUseRecords, false);
 					deductCash = BigDecimal.ZERO;
 				}
 			}
@@ -2131,9 +2131,10 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 		}
 	}
 
-	private void deductGiftCardCash(Long userId, Long gcId, BigDecimal deductCash, BigDecimal gcRemainCash, List<GiftCardOrderUseRecord> gcUseRecords) {
+	private void deductGiftCardCash(Long userId, Long gcId, BigDecimal deductCash, BigDecimal gcRemainCash, List<GiftCardOrderUseRecord> gcUseRecords, Boolean isUsed) {
 		Boolean is_update = giftCardUserRecordService.update(null, Wrappers.lambdaUpdate(GiftCardUserRecord.class)
 				.set(GiftCardUserRecord::getRemainCash, gcRemainCash.subtract(deductCash))
+				.set(isUsed, GiftCardUserRecord::getIsUsed, isUsed)
 				.eq(GiftCardUserRecord::getId, gcId)
 				.eq(GiftCardUserRecord::getIsPay, true)
 				.eq(GiftCardUserRecord::getRemainCash, gcRemainCash));

+ 7 - 0
netflix-web/src/main/java/com/cyksj/web/controller/user/UserController.java

@@ -118,6 +118,13 @@ public class UserController {
                 .eq(OrderDon::getUserId, userId)
                 .eq(OrderDon::getStatus, OrderDon.Status.noPayment).last("limit 1"));
         personalView.setIsNoPayment(orderDon != null ? true : false);
+        //礼品卡可用数量
+        Number numOfGiftCard = beanSearcher.searchCount(GiftCardUserRecord.class, MapUtils.builder()
+                .field(GiftCardUserRecord::getToUserId, userId)
+                .field(GiftCardUserRecord::getIsPay, true)
+                .field(GiftCardUserRecord::getIsUsed, false)
+                .build());
+        personalView.setNumOfGiftCard(numOfGiftCard.intValue());
         return GatewayResponse.SUCCESS.newBuilder().toResult(personalView);
     }