修改了套餐包可以使用余额购买

This commit is contained in:
1215525055@qq.com 2025-08-07 11:13:51 +08:00
parent cc0ec85811
commit 6e429ea577
8 changed files with 162 additions and 34 deletions

View File

@ -26,10 +26,13 @@
<orderEntry type="library" name="Maven: ch.qos.logback:logback-classic:1.2.5" level="project" />
<orderEntry type="library" name="Maven: ch.qos.logback:logback-core:1.2.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-to-slf4j:2.14.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.14.1" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:jul-to-slf4j:1.7.32" level="project" />
<orderEntry type="library" name="Maven: jakarta.annotation:jakarta.annotation-api:1.3.5" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-starter-json:2.5.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.12.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.12.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.12.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.12.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.12.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.module:jackson-module-parameter-names:2.12.4" level="project" />
@ -103,6 +106,9 @@
<orderEntry type="library" name="Maven: cn.com.tenlion:interface-project-config:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: cn.com.tenlion:pojo-project-config:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: io.swagger:swagger-annotations:1.5.9" level="project" />
<orderEntry type="library" name="Maven: ink.wgink:module-file:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: io.minio:minio:8.2.2" level="project" />
<orderEntry type="library" name="Maven: com.carrotsearch.thirdparty:simple-xml-safe:2.7.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.14" level="project" />
<orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.13" level="project" />
<orderEntry type="library" name="Maven: commons-codec:commons-codec:1.15" level="project" />
@ -138,10 +144,6 @@
<orderEntry type="library" name="Maven: ink.wgink:basic-abstract:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: com.github.pagehelper:pagehelper:5.3.1" level="project" />
<orderEntry type="library" name="Maven: com.github.jsqlparser:jsqlparser:4.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:easyexcel:3.0.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:4.1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.8" level="project" />
<orderEntry type="library" name="Maven: org.ehcache:ehcache:3.9.5" level="project" />
<orderEntry type="library" name="Maven: cglib:cglib:3.2.12" level="project" />
<orderEntry type="library" name="Maven: org.ow2.asm:asm:7.1" level="project" />
<orderEntry type="library" name="Maven: org.springframework.security:spring-security-config:5.5.2" level="project" />
@ -247,6 +249,20 @@
<orderEntry type="library" name="Maven: cn.com.tenlion:interface-smessage:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: cn.com.tenlion:pojo-smessage:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.apache.tomcat.embed:tomcat-embed-websocket:9.0.52" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:easyexcel:3.3.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:easyexcel-core:3.3.2" level="project" />
<orderEntry type="library" name="Maven: com.alibaba:easyexcel-support:3.3.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-csv:1.8" level="project" />
<orderEntry type="library" name="Maven: org.ehcache:ehcache:3.9.5" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi:4.1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:SparseBitSet:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:4.1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-schemas:4.1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:3.1.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.19" level="project" />
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.06" level="project" />
<orderEntry type="library" name="Maven: ink.wgink:redis-cache:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: ink.wgink:basic-util:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: org.springframework:spring-jdbc:5.3.9" level="project" />
@ -256,7 +272,6 @@
<orderEntry type="library" name="Maven: commons-io:commons-io:2.11.0" level="project" />
<orderEntry type="library" name="Maven: commons-net:commons-net:3.3" level="project" />
<orderEntry type="library" name="Maven: commons-fileupload:commons-fileupload:1.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-compress:1.21" level="project" />
<orderEntry type="library" name="Maven: commons-beanutils:commons-beanutils:1.9.4" level="project" />
<orderEntry type="library" name="Maven: com.alibaba.fastjson2:fastjson2:2.0.2" level="project" />
<orderEntry type="library" name="Maven: org.bouncycastle:bcprov-jdk15on:1.69" level="project" />
@ -274,11 +289,6 @@
<orderEntry type="library" name="Maven: com.alibaba:druid:1.1.9" level="project" />
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.32" level="project" />
<orderEntry type="library" name="Maven: org.springframework.boot:spring-boot-autoconfigure:2.5.4" level="project" />
<orderEntry type="library" name="Maven: ink.wgink:module-file:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: io.minio:minio:8.2.2" level="project" />
<orderEntry type="library" name="Maven: com.carrotsearch.thirdparty:simple-xml-safe:2.7.1" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.12.4" level="project" />
<orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.12.4" level="project" />
<orderEntry type="library" name="Maven: ink.wgink:module-dictionary:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: ink.wgink:basic-annotation:1.0-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: ink.wgink:login-oauth2-client:1.0-SNAPSHOT" level="project" />
@ -320,15 +330,6 @@
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.28" level="project" />
<orderEntry type="library" name="Maven: com.deepoove:poi-tl:1.12.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-lang3:3.12.0" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml:5.2.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi:5.2.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-math3:3.6.1" level="project" />
<orderEntry type="library" name="Maven: com.zaxxer:SparseBitSet:1.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.poi:poi-ooxml-lite:5.2.2" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlbeans:xmlbeans:5.0.3" level="project" />
<orderEntry type="library" name="Maven: com.github.virtuald:curvesapi:1.07" level="project" />
<orderEntry type="library" name="Maven: org.apache.logging.log4j:log4j-api:2.14.1" level="project" />
<orderEntry type="library" name="Maven: org.apache.commons:commons-collections4:4.4" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-transcoder:1.17" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-anim:1.17" level="project" />
<orderEntry type="library" name="Maven: org.apache.xmlgraphics:batik-css:1.17" level="project" />

View File

@ -1,8 +1,10 @@
package cn.com.tenlion.operator.controller.api.packageorder;
import cn.com.tenlion.operator.pojo.vos.packageorder.PackageOrderAppVO;
import cn.com.tenlion.operator.pojo.vos.packageorder.PackageOrderWriteoffVO;
import ink.wgink.annotation.CheckRequestBodyAnnotation;
import ink.wgink.common.base.DefaultBaseController;
import ink.wgink.common.component.SecurityComponent;
import ink.wgink.interfaces.consts.ISystemConstant;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.ErrorResult;
@ -14,6 +16,7 @@ import cn.com.tenlion.operator.pojo.vos.packageorder.PackageOrderVO;
import cn.com.tenlion.operator.service.packageorder.IPackageOrderService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;
@ -31,10 +34,26 @@ import java.util.Map;
@RestController
@RequestMapping(ISystemConstant.API_PREFIX + "/packageorder")
public class PackageOrderController extends DefaultBaseController {
@Autowired
protected SecurityComponent securityComponent;
@Autowired
private IPackageOrderService packageOrderService;
@ApiOperation(value = "购买套餐包-订单", notes = "购买套餐包-订单接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("buy/{infoId}")
public SuccessResultData<String> save(@PathVariable String infoId) {
try{
PackageOrderAppVO vo = new PackageOrderAppVO();
vo.setUserId(securityComponent.getCurrentUser().getUserId());
vo.setPackageInfoId(infoId);
packageOrderService.saveOrderBackPay(vo);
}catch(Exception e) {
return new SuccessResultData<String>(e.getMessage());
}
return new SuccessResultData<String>("Success");
}
@ApiOperation(value = "新增套餐包-订单", notes = "新增套餐包-订单接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save")

View File

@ -120,4 +120,6 @@ public interface IPackageOrderDao {
Integer count(Map<String, Object> params) throws SearchException;
void updatePay(Map<String, Object> params);
void updateExpireStatus(Map<String, Object> params);
}

View File

@ -6,8 +6,6 @@ import cn.com.tenlion.operator.pojo.dtos.packageinfo.PackageInfoAppDTO;
import cn.com.tenlion.operator.pojo.dtos.user.info.UserInfoDTO;
import cn.com.tenlion.operator.pojo.vos.coupon.user.RelatedUserVO;
import cn.com.tenlion.operator.util.PayUtil;
import cn.com.tenlion.smessage.pojo.dtos.smessageapplication.SmessageApplicationDTO;
import cn.com.tenlion.smessage.util.ApplicationUtil;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.SaveException;
import ink.wgink.pojo.ListPage;

View File

@ -190,7 +190,7 @@ public interface IPackageOrderService {
*/
Integer count(Map<String, Object> params);
void saveOrder(PackageOrderAppVO packageOrderVO);
String saveOrder(PackageOrderAppVO packageOrderVO);
PackageOrderDTO getByPackageNo(String packageNo);
@ -205,6 +205,9 @@ public interface IPackageOrderService {
Map<String, Integer> getCount(String userId);
void updateWriteoff(String packageOrderId, PackageOrderWriteoffVO packageOrderWriteoffVO);
void updateWriteoffAll(List<PackageOrderDTO> list);
List<PackageOrderDTO> getExpireList();
void saveOrderBackPay(PackageOrderAppVO packageOrderVO);
}

View File

@ -24,9 +24,11 @@ import cn.com.tenlion.operator.util.PayUtil;
import com.alibaba.fastjson.JSONObject;
import ink.wgink.common.base.DefaultBaseService;
import ink.wgink.exceptions.SaveException;
import ink.wgink.exceptions.SearchException;
import ink.wgink.module.oauth2.manager.OAuth2ClientTokenManager;
import ink.wgink.pojo.ListPage;
import ink.wgink.pojo.result.SuccessResult;
import ink.wgink.pojo.result.SuccessResultData;
import ink.wgink.pojo.result.SuccessResultList;
import ink.wgink.util.date.DateUtil;
import ink.wgink.util.map.HashMapUtil;
@ -328,6 +330,24 @@ public class PackageOrderServiceImpl extends DefaultBaseService implements IPack
packageOrderItemService.saveApp("minus", packageOrderItemAppVO);
}
@Override
public void updateWriteoffAll(List<PackageOrderDTO> list) {
// 扣除所有次数
for(PackageOrderDTO orderDTO : list) {
if (orderDTO.getPackageTotalSurplusCount() > 0 && !StringUtils.isEmpty(orderDTO.getPackageExpireTime())) {
PackageOrderWriteoffVO vo = new PackageOrderWriteoffVO();
vo.setPackageOutCount(orderDTO.getPackageTotalSurplusCount());
vo.setPackageOutRemark("套餐包到期");
updateWriteoff(orderDTO.getPackageOrderId(), vo);
// 做标记 , 防止该订单将来退款回来的次数也不扣掉
Map<String, Object> params = new HashMap<>();
params.put("packageOrderId", orderDTO.getPackageOrderId());
params.put("gmtModified", DateUtil.getTime());
packageOrderDao.updateExpireStatus(params);
}
}
}
@Override
public List<PackageOrderDTO> getExpireList() {
Map<String, Object> params = new HashMap<>();
@ -335,6 +355,81 @@ public class PackageOrderServiceImpl extends DefaultBaseService implements IPack
List<PackageOrderDTO> list = packageOrderDao.list(params);
return list;
}
/**
* 获取accesstoken
* @return
*/
private String getAccessToken(){
String accessToken = OAuth2ClientTokenManager.getInstance().getToken().getAccessToken();
if(StringUtils.isBlank(accessToken)){
throw new SearchException("获取accesstoken失败");
}
return accessToken;
}
@Autowired
private SystemApiPathProperties apiPathProperties;
@Override
public void saveOrderBackPay(PackageOrderAppVO packageOrderVO) {
PackageInfoDTO packageInfoDTO = iPackageInfoService.get(packageOrderVO.getPackageInfoId());
Integer money = packageInfoDTO.getPackageMoney();
String orderId = saveOrder(packageOrderVO);
/**
* 改状态
*/
// updateOrder(packageOrderVO);
PackageOrderDTO orderDTO = getByPackageNo(packageOrderVO.getAccountRechargeId());
if(orderDTO.getPackagePayStatus().equals("1")) { // 当前状态已经是已支付的不做操作
throw new SaveException("该套餐订单已购买");
}
PackageInfoAppDTO infoAppDTO = orderDTO.getPackageInfoAppDTO();
// 仅限购买1次的
if(infoAppDTO.getPackageMode().equals("single")) {
List<PackageOrderDTO> list = listByUserAndInfo(orderDTO.getPackageInfoId(), orderDTO.getCreator());
Boolean exists = false;
for(PackageOrderDTO dto : list) {
if(dto.getPackagePayStatus().equals("1")) {
exists = true;
}
}
if (exists) {
throw new SaveException("该套餐只允许购买一次");
}
}
/**
* 扣钱
*/
// 生成流水记录
AccountItemOrderVO accountItemOrderVO = new AccountItemOrderVO();
accountItemOrderVO.setOrderId(orderId);
accountItemOrderVO.setUserId(packageOrderVO.getUserId());
accountItemOrderVO.setAccountMoney(money);
accountItemOrderVO.setDescription("购买套餐包:" + packageInfoDTO.getPackageName());
JSONObject jsonObject = new JSONObject();
jsonObject.put("time", DateUtil.getTime());
jsonObject.put("money" , money);
jsonObject.put("userId", packageOrderVO.getUserId());
jsonObject.put("orderId", accountItemOrderVO.getOrderId());
accountItemOrderVO.setCode(EncryptUtil.encode(jsonObject.toJSONString()));
accountItemOrderVO.setType(2);
iAccountItemRemoteService.payOut(apiPathProperties.getUserCenter(), accountItemOrderVO, getAccessToken());
/**
* 1. 更改到账时间 , 状态
*/
String time = DateUtil.getTime();
Map<String, Object> params = super.getHashMap(2);
params.put("packageNo", packageOrderVO.getAccountRechargeId());// 关联支付
params.put("packageAccountItem", packageOrderVO.getPackageAccountItem()); // 关联扣款流水
params.put("packagePayStatus", "1"); // 已支付
params.put("packagePay", time); // 支付时间
if(!StringUtils.isEmpty(infoAppDTO.getPackageExpire())) {
params.put("packageExpireTime", calculateFutureDate(time, Integer.valueOf(infoAppDTO.getPackageExpire()))); // 到期时间
}
packageOrderDao.updatePay(params);
}
@Override
public List<PackageOrderDTO> list(Map<String, Object> params) {
@ -383,7 +478,7 @@ public class PackageOrderServiceImpl extends DefaultBaseService implements IPack
}
@Override
public void saveOrder(PackageOrderAppVO packageOrderVO) {
public String saveOrder(PackageOrderAppVO packageOrderVO) {
/**
* 1. 查询账户余额是否充足
* 2. 保存订单信息
@ -439,6 +534,10 @@ public class PackageOrderServiceImpl extends DefaultBaseService implements IPack
Integer c = count(queryCount) + 1;
String packageOrderId = "PKG" + DateUtil.getSdfTimes() + (c < 10 ? "000" : c < 100 ? "00" : c < 1000 ? "0" : "") + c;
if (StringUtils.isEmpty(packageOrderVO.getAccountRechargeId())) {
packageOrderVO.setAccountRechargeId(packageOrderId);
}
Map<String, Object> data = HashMapUtil.beanToMap(vo);
data.put("packageOrderId", packageOrderId);
String currentDate = DateUtil.getTime();
@ -453,7 +552,7 @@ public class PackageOrderServiceImpl extends DefaultBaseService implements IPack
data.put("gmtModified", currentDate);
data.put("isDelete", 0);
packageOrderDao.save(data);
return packageOrderId;
}
public static String calculateFutureDate(String dateTimeStr, int days) {

View File

@ -40,14 +40,10 @@ public class ClosePackageOrder implements Job {
IPackageOrderService orderService = QuartzConfigSpringUtil.getBean(IPackageOrderService.class);
// 查找已经过期的 , 数量还大于0的 ,
List<PackageOrderDTO> list = orderService.getExpireList();
// 扣除所有次数
for(PackageOrderDTO orderDTO : list) {
if (orderDTO.getPackageTotalSurplusCount() > 0 && !StringUtils.isEmpty(orderDTO.getPackageExpireTime())) {
PackageOrderWriteoffVO vo = new PackageOrderWriteoffVO();
vo.setPackageOutCount(orderDTO.getPackageTotalSurplusCount());
vo.setPackageOutRemark("套餐包到期");
orderService.updateWriteoff(orderDTO.getPackageOrderId(), vo);
}
// 更新已归零 1
orderService.updateWriteoffAll(list);
if (list.size() > 0) {
QuartzConfigLog.info(jobId, jobClassName, list.toString());// 自定义日志记录
}
QuartzConfigLog.info(jobId, jobClassName, jobTitle + "执行成功");// 自定义日志记录
}catch(Exception e) {

View File

@ -149,6 +149,16 @@
</foreach>
</update>
<update id="updateExpireStatus" parameterType="map">
UPDATE
operator_package_order
SET
package_expire_status = '1',
gmt_modified = #{gmtModified}
WHERE
package_order_id = #{packageOrderId} AND package_total_surplus_count = 0
</update>
<!-- 修改套餐包-订单 -->
<update id="update" parameterType="map">
UPDATE
@ -326,7 +336,7 @@
</if>
<if test="queryExpire != null and queryExpire == 'queryExpire' ">
AND t1.is_delete = 0 AND t1.package_total_surplus_count > 0 AND t1.package_expire_time != '' AND t1.package_expire_time IS NOT NULL AND t1.package_pay_status = '1'
AND NOW() > t1.package_expire_time
AND NOW() > t1.package_expire_time AND t1.package_expire_status != '1'
</if>
<if test="keYong != null and keYong != ''">
AND t1.package_total_surplus_count > 0