|
@ -18,6 +18,7 @@ import org.jeecg.modules.GiveGifts.entity.GiveGifts; |
|
|
import org.jeecg.modules.GiveGifts.service.IGiveGiftsService; |
|
|
import org.jeecg.modules.GiveGifts.service.IGiveGiftsService; |
|
|
import org.jeecg.modules.commonBookNovel.entity.CommonBookNovel; |
|
|
import org.jeecg.modules.commonBookNovel.entity.CommonBookNovel; |
|
|
import org.jeecg.modules.commonBookNovel.service.ICommonBookNovelService; |
|
|
import org.jeecg.modules.commonBookNovel.service.ICommonBookNovelService; |
|
|
|
|
|
import org.jeecg.modules.commonConfig.service.ICommonConfigService; |
|
|
import org.jeecg.modules.commonGift.entity.CommonGift; |
|
|
import org.jeecg.modules.commonGift.entity.CommonGift; |
|
|
import org.jeecg.modules.commonGift.service.ICommonGiftService; |
|
|
import org.jeecg.modules.commonGift.service.ICommonGiftService; |
|
|
import org.jeecg.modules.commonGiftBack.service.ICommonGiftBackService; |
|
|
import org.jeecg.modules.commonGiftBack.service.ICommonGiftBackService; |
|
@ -42,6 +43,8 @@ import org.springframework.transaction.annotation.Transactional; |
|
|
|
|
|
|
|
|
import javax.annotation.Resource; |
|
|
import javax.annotation.Resource; |
|
|
import java.math.BigDecimal; |
|
|
import java.math.BigDecimal; |
|
|
|
|
|
import java.util.ArrayList; |
|
|
|
|
|
import java.util.HashMap; |
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
import static org.jeecg.modules.online.auth.b.a.*; |
|
|
import static org.jeecg.modules.online.auth.b.a.*; |
|
@ -88,6 +91,9 @@ public class AppletOrderServiceImpl implements AppletOrderService { |
|
|
@Autowired |
|
|
@Autowired |
|
|
private ICommonOrderService commonOrderService; |
|
|
private ICommonOrderService commonOrderService; |
|
|
|
|
|
|
|
|
|
|
|
@Autowired |
|
|
|
|
|
private ICommonConfigService commonConfigService; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//查询互动打赏礼物信息列表 |
|
|
//查询互动打赏礼物信息列表 |
|
|
@Override |
|
|
@Override |
|
@ -168,7 +174,7 @@ public class AppletOrderServiceImpl implements AppletOrderService { |
|
|
|
|
|
|
|
|
//创建支付套餐订单 |
|
|
//创建支付套餐订单 |
|
|
@Override |
|
|
@Override |
|
|
public Result<?> createPayPackageOrder(String token, String packageId){ |
|
|
|
|
|
|
|
|
public Result<?> createPayPackageOrder(String token, String packageId, String payType){ |
|
|
HanHaiMember member = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
HanHaiMember member = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
//套餐标识不能为空 |
|
|
//套餐标识不能为空 |
|
|
if(StringUtils.isEmpty(packageId)){ |
|
|
if(StringUtils.isEmpty(packageId)){ |
|
@ -193,19 +199,41 @@ public class AppletOrderServiceImpl implements AppletOrderService { |
|
|
.status("0") |
|
|
.status("0") |
|
|
.build(); |
|
|
.build(); |
|
|
|
|
|
|
|
|
commonOrderService.save(order); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//吊起微信支付 |
|
|
|
|
|
|
|
|
commonOrderService.save(order); |
|
|
|
|
|
Object appOrder = null; |
|
|
int i = order.getPrice().multiply(new BigDecimal(100)).intValue(); |
|
|
int i = order.getPrice().multiply(new BigDecimal(100)).intValue(); |
|
|
Object appOrder = mpWxPayService.createOrder( |
|
|
|
|
|
"充值豆豆", |
|
|
|
|
|
"127.0.0.1", |
|
|
|
|
|
order.getId(), |
|
|
|
|
|
i, |
|
|
|
|
|
order.getId(), |
|
|
|
|
|
member.getAppletOpenid(), |
|
|
|
|
|
"{}"); |
|
|
|
|
|
|
|
|
if ("web".equals(payType)){ |
|
|
|
|
|
|
|
|
|
|
|
HashMap<String, Object> map = new HashMap<>(); |
|
|
|
|
|
|
|
|
|
|
|
Object pay = mpWxPayService.createQrOrder( |
|
|
|
|
|
"充值豆豆", |
|
|
|
|
|
"127.0.0.1", |
|
|
|
|
|
order.getId(), |
|
|
|
|
|
i, |
|
|
|
|
|
order.getId(), |
|
|
|
|
|
"{}"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map.put("pay", pay); |
|
|
|
|
|
map.put("orderId", order.getId()); |
|
|
|
|
|
|
|
|
|
|
|
appOrder = map; |
|
|
|
|
|
|
|
|
|
|
|
}else { |
|
|
|
|
|
//吊起微信支付 |
|
|
|
|
|
appOrder = mpWxPayService.createOrder( |
|
|
|
|
|
"充值豆豆", |
|
|
|
|
|
"127.0.0.1", |
|
|
|
|
|
order.getId(), |
|
|
|
|
|
i, |
|
|
|
|
|
order.getId(), |
|
|
|
|
|
member.getAppletOpenid(), |
|
|
|
|
|
"{}"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("支付成功", appOrder); |
|
|
return Result.OK("支付成功", appOrder); |
|
|
} |
|
|
} |
|
@ -282,76 +310,109 @@ public class AppletOrderServiceImpl implements AppletOrderService { |
|
|
.userId(member.getId()) |
|
|
.userId(member.getId()) |
|
|
.build()); |
|
|
.build()); |
|
|
|
|
|
|
|
|
// TODO 这里需要给作者分钱 |
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("赠送礼物成功"); |
|
|
return Result.OK("赠送礼物成功"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//购买章节 |
|
|
|
|
|
|
|
|
//购买章节(支持批量订阅,多个章节ID用逗号隔开) |
|
|
@Override |
|
|
@Override |
|
|
@Transactional |
|
|
@Transactional |
|
|
public Result<?> buyNovel(String token, String bookId, String novelId){ |
|
|
|
|
|
|
|
|
public Result<?> buyNovel(String token, String bookId, String novelIds){ |
|
|
HanHaiMember member = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
HanHaiMember member = shiroRealm.checkUserTokenIsEffectHanHaiOpenId(token); |
|
|
|
|
|
|
|
|
CommonShop book = commonShopService.getById(bookId); |
|
|
CommonShop book = commonShopService.getById(bookId); |
|
|
CommonBookNovel chapter = commonBookNovelService.getById(novelId); |
|
|
|
|
|
|
|
|
|
|
|
if(ObjectUtils.isEmpty(book)){ |
|
|
if(ObjectUtils.isEmpty(book)){ |
|
|
Result.error("书籍不存在"); |
|
|
|
|
|
|
|
|
return Result.error("书籍不存在"); |
|
|
} |
|
|
} |
|
|
if(ObjectUtils.isEmpty(chapter)){ |
|
|
|
|
|
Result.error("章节不存在"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(StringUtils.isBlank(novelIds)){ |
|
|
|
|
|
return Result.error("章节ID不能为空"); |
|
|
} |
|
|
} |
|
|
|
|
|
// 解析章节ID列表 |
|
|
|
|
|
String[] novelIdArray = novelIds.split(","); |
|
|
|
|
|
|
|
|
|
|
|
// 获取订阅配置 |
|
|
|
|
|
String subscribeNum = commonConfigService.getContentByName("chapter_subscribe_num"); |
|
|
|
|
|
int sNum = StringUtils.isNotBlank(subscribeNum) ? Integer.valueOf(subscribeNum) : 999999999;//默认不消耗豆豆 |
|
|
|
|
|
|
|
|
|
|
|
// 记录需要订阅的章节和总消费 |
|
|
|
|
|
List<CommonBookNovel> chaptersToSubscribe = new ArrayList<>(); |
|
|
|
|
|
List<String> chapterTitles = new ArrayList<>(); |
|
|
|
|
|
int totalCost = 0; |
|
|
|
|
|
|
|
|
|
|
|
// 批量检查章节是否存在和是否已订阅 |
|
|
|
|
|
for(String novelId : novelIdArray){ |
|
|
|
|
|
novelId = novelId.trim(); |
|
|
|
|
|
if(StringUtils.isEmpty(novelId)){ |
|
|
|
|
|
continue; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
CommonChapterSubscribe one = commonChapterSubscribeService.lambdaQuery() |
|
|
|
|
|
.eq(CommonChapterSubscribe::getBookId, bookId) |
|
|
|
|
|
.eq(CommonChapterSubscribe::getUserId, member.getId()) |
|
|
|
|
|
.eq(CommonChapterSubscribe::getChapterId, novelId) |
|
|
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(one)){ |
|
|
|
|
|
//消耗的豆豆 |
|
|
|
|
|
// TODO 这里需要计算豆豆 |
|
|
|
|
|
Integer i = chapter.getNum() / 200; |
|
|
|
|
|
|
|
|
|
|
|
if (member.getIntegerPrice().intValue() < i){ |
|
|
|
|
|
Result.error("豆豆不足"); |
|
|
|
|
|
|
|
|
CommonBookNovel chapter = commonBookNovelService.getById(novelId); |
|
|
|
|
|
if(ObjectUtils.isEmpty(chapter)){ |
|
|
|
|
|
return Result.error("章节不存在: " + novelId); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查是否已经订阅 |
|
|
|
|
|
CommonChapterSubscribe existSubscribe = commonChapterSubscribeService.lambdaQuery() |
|
|
|
|
|
.eq(CommonChapterSubscribe::getBookId, bookId) |
|
|
|
|
|
.eq(CommonChapterSubscribe::getUserId, member.getId()) |
|
|
|
|
|
.eq(CommonChapterSubscribe::getChapterId, novelId) |
|
|
|
|
|
.one(); |
|
|
|
|
|
|
|
|
|
|
|
if (ObjectUtils.isEmpty(existSubscribe)){ |
|
|
|
|
|
// 计算消费的豆豆 |
|
|
|
|
|
Integer chapterCost = chapter.getNum() / sNum; |
|
|
|
|
|
totalCost += chapterCost; |
|
|
|
|
|
chaptersToSubscribe.add(chapter); |
|
|
|
|
|
chapterTitles.add(chapter.getTitle()); |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 如果没有需要订阅的章节 |
|
|
|
|
|
if(chaptersToSubscribe.isEmpty()){ |
|
|
|
|
|
return Result.OK("所有章节已订阅"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// 检查豆豆是否足够 |
|
|
|
|
|
if (member.getIntegerPrice().intValue() < totalCost){ |
|
|
|
|
|
return Result.error("豆豆不足,需要" + totalCost + "豆豆"); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
// 添加订阅记录 |
|
|
|
|
|
|
|
|
// 批量添加订阅记录 |
|
|
|
|
|
List<CommonChapterSubscribe> subscribeList = new ArrayList<>(); |
|
|
|
|
|
for(CommonBookNovel chapter : chaptersToSubscribe){ |
|
|
CommonChapterSubscribe subscribe = CommonChapterSubscribe.builder() |
|
|
CommonChapterSubscribe subscribe = CommonChapterSubscribe.builder() |
|
|
.authorId(book.getUserId()) |
|
|
.authorId(book.getUserId()) |
|
|
.bookId(bookId) |
|
|
.bookId(bookId) |
|
|
.userId(member.getId()) |
|
|
.userId(member.getId()) |
|
|
.chapterId(novelId) |
|
|
|
|
|
|
|
|
.chapterId(chapter.getId()) |
|
|
.build(); |
|
|
.build(); |
|
|
commonChapterSubscribeService.save(subscribe); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 减去豆豆 |
|
|
|
|
|
BigDecimal integerPrice = member.getIntegerPrice(); |
|
|
|
|
|
member.setIntegerPrice(integerPrice.subtract(new BigDecimal(i))); |
|
|
|
|
|
hanHaiMemberService.updateById(member); |
|
|
|
|
|
|
|
|
|
|
|
//增加亲密值 |
|
|
|
|
|
commonRankingService.addIntimacy(member.getId(), bookId, i); |
|
|
|
|
|
book.setQmNum(book.getQmNum() + i); |
|
|
|
|
|
commonShopService.updateById(book); |
|
|
|
|
|
|
|
|
|
|
|
// 添加消费记录 |
|
|
|
|
|
commonMoneyLogService.save(CommonMoneyLog.builder() |
|
|
|
|
|
.title("订阅" + book.getName() + "的章节" + chapter.getTitle()) |
|
|
|
|
|
.oldMoney(integerPrice) |
|
|
|
|
|
.money(new BigDecimal(i)) |
|
|
|
|
|
.type(1)//支付豆豆 |
|
|
|
|
|
.state(0) |
|
|
|
|
|
.userId(member.getId()) |
|
|
|
|
|
.build()); |
|
|
|
|
|
|
|
|
|
|
|
// TODO 这里需要给作者分钱 |
|
|
|
|
|
|
|
|
subscribeList.add(subscribe); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return Result.OK("购买成功"); |
|
|
|
|
|
|
|
|
commonChapterSubscribeService.saveBatch(subscribeList); |
|
|
|
|
|
|
|
|
|
|
|
// 扣除豆豆 |
|
|
|
|
|
BigDecimal integerPrice = member.getIntegerPrice(); |
|
|
|
|
|
member.setIntegerPrice(integerPrice.subtract(new BigDecimal(totalCost))); |
|
|
|
|
|
hanHaiMemberService.updateById(member); |
|
|
|
|
|
|
|
|
|
|
|
//增加亲密值 |
|
|
|
|
|
commonRankingService.addIntimacy(member.getId(), bookId, totalCost); |
|
|
|
|
|
book.setQmNum(book.getQmNum() + totalCost); |
|
|
|
|
|
commonShopService.updateById(book); |
|
|
|
|
|
|
|
|
|
|
|
// 添加消费记录 |
|
|
|
|
|
String chapterNames = String.join("、", chapterTitles); |
|
|
|
|
|
commonMoneyLogService.save(CommonMoneyLog.builder() |
|
|
|
|
|
.title("订阅" + book.getName() + "的章节:" + chapterNames) |
|
|
|
|
|
.oldMoney(integerPrice) |
|
|
|
|
|
.money(new BigDecimal(totalCost)) |
|
|
|
|
|
.type(1)//支付豆豆 |
|
|
|
|
|
.state(0) |
|
|
|
|
|
.userId(member.getId()) |
|
|
|
|
|
.build()); |
|
|
|
|
|
|
|
|
|
|
|
return Result.OK("批量购买成功,共订阅" + chaptersToSubscribe.size() + "个章节"); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |