|
|
@@ -7,6 +7,7 @@ import com.izouma.nineth.dto.PageQuery;
|
|
|
import com.izouma.nineth.enums.MetaPropUsedType;
|
|
|
import com.izouma.nineth.enums.MetaStoreCommodityType;
|
|
|
import com.izouma.nineth.exception.BusinessException;
|
|
|
+import com.izouma.nineth.repo.MetaStorePurchaseRecordRepo;
|
|
|
import com.izouma.nineth.repo.MetaStoreRepo;
|
|
|
import com.izouma.nineth.repo.MetaUserPropRepo;
|
|
|
import com.izouma.nineth.service.MetaStoreService;
|
|
|
@@ -34,6 +35,8 @@ public class MetaStoreController extends BaseController {
|
|
|
|
|
|
private MetaUserPropRepo metaUserPropRepo;
|
|
|
|
|
|
+ private MetaStorePurchaseRecordRepo metaStorePurchaseRecordRepo;
|
|
|
+
|
|
|
//@PreAuthorize("hasRole('ADMIN')")
|
|
|
@PostMapping("/save")
|
|
|
public MetaStore save(@RequestBody MetaStore record) {
|
|
|
@@ -120,15 +123,25 @@ public class MetaStoreController extends BaseController {
|
|
|
if (CollectionUtils.isEmpty(metaStores)) {
|
|
|
return MetaRestResult.returnSuccess(metaStores);
|
|
|
}
|
|
|
+ Long userId = SecurityUtils.getAuthenticatedUser().getId();
|
|
|
if (MetaStoreCommodityType.META_PROP.equals(commodityType)) {
|
|
|
- Long userId = SecurityUtils.getAuthenticatedUser().getId();
|
|
|
metaStores.forEach(metaStore -> {
|
|
|
MetaUserProp metaUserProp = metaUserPropRepo.findByUserIdAndMetaPropIdAndDel(userId, metaStore.getMetaPropId(), false);
|
|
|
if (Objects.nonNull(metaUserProp) && MetaPropUsedType.PERMANENT.equals(metaUserProp.getUsedType()) && metaUserProp.getNum() >= 1) {
|
|
|
metaStore.setCanPurchase(false);
|
|
|
}
|
|
|
});
|
|
|
+ return MetaRestResult.returnSuccess(metaStores);
|
|
|
}
|
|
|
+ metaStores.forEach(metaStore -> {
|
|
|
+ int count = metaStorePurchaseRecordRepo.countByMetaStoreIdAndUserId(metaStore.getId(), userId);
|
|
|
+ if (metaStore.getPurchaseLimitNum() > count) {
|
|
|
+ metaStore.setRemainingPurchaseNum(metaStore.getPurchaseLimitNum() - count);
|
|
|
+ } else {
|
|
|
+ metaStore.setRemainingPurchaseNum(0);
|
|
|
+ metaStore.setCanPurchase(false);
|
|
|
+ }
|
|
|
+ });
|
|
|
return MetaRestResult.returnSuccess(metaStores);
|
|
|
}
|
|
|
}
|