diff --git a/.idea/operator-plugin.iml b/.idea/operator-plugin.iml
index 4545e15..a065600 100644
--- a/.idea/operator-plugin.iml
+++ b/.idea/operator-plugin.iml
@@ -26,10 +26,13 @@
+
+
+
@@ -103,6 +106,9 @@
+
+
+
@@ -138,10 +144,6 @@
-
-
-
-
@@ -247,6 +249,20 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
@@ -256,7 +272,6 @@
-
@@ -274,11 +289,6 @@
-
-
-
-
-
@@ -320,15 +330,6 @@
-
-
-
-
-
-
-
-
-
diff --git a/src/main/java/cn/com/tenlion/operator/controller/api/packageorder/PackageOrderController.java b/src/main/java/cn/com/tenlion/operator/controller/api/packageorder/PackageOrderController.java
index 73abf51..2cbc952 100644
--- a/src/main/java/cn/com/tenlion/operator/controller/api/packageorder/PackageOrderController.java
+++ b/src/main/java/cn/com/tenlion/operator/controller/api/packageorder/PackageOrderController.java
@@ -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 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(e.getMessage());
+ }
+ return new SuccessResultData("Success");
+ }
+
@ApiOperation(value = "新增套餐包-订单", notes = "新增套餐包-订单接口")
@ApiResponses({@ApiResponse(code = 400, message = "请求失败", response = ErrorResult.class)})
@PostMapping("save")
diff --git a/src/main/java/cn/com/tenlion/operator/dao/packageorder/IPackageOrderDao.java b/src/main/java/cn/com/tenlion/operator/dao/packageorder/IPackageOrderDao.java
index e576b44..7cfb770 100644
--- a/src/main/java/cn/com/tenlion/operator/dao/packageorder/IPackageOrderDao.java
+++ b/src/main/java/cn/com/tenlion/operator/dao/packageorder/IPackageOrderDao.java
@@ -120,4 +120,6 @@ public interface IPackageOrderDao {
Integer count(Map params) throws SearchException;
void updatePay(Map params);
+
+ void updateExpireStatus(Map params);
}
\ No newline at end of file
diff --git a/src/main/java/cn/com/tenlion/operator/service/packageinfo/impl/PackageInfoServiceImpl.java b/src/main/java/cn/com/tenlion/operator/service/packageinfo/impl/PackageInfoServiceImpl.java
index 9f6276c..9751131 100644
--- a/src/main/java/cn/com/tenlion/operator/service/packageinfo/impl/PackageInfoServiceImpl.java
+++ b/src/main/java/cn/com/tenlion/operator/service/packageinfo/impl/PackageInfoServiceImpl.java
@@ -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;
diff --git a/src/main/java/cn/com/tenlion/operator/service/packageorder/IPackageOrderService.java b/src/main/java/cn/com/tenlion/operator/service/packageorder/IPackageOrderService.java
index f62a95d..3dd2cc0 100644
--- a/src/main/java/cn/com/tenlion/operator/service/packageorder/IPackageOrderService.java
+++ b/src/main/java/cn/com/tenlion/operator/service/packageorder/IPackageOrderService.java
@@ -190,7 +190,7 @@ public interface IPackageOrderService {
*/
Integer count(Map params);
- void saveOrder(PackageOrderAppVO packageOrderVO);
+ String saveOrder(PackageOrderAppVO packageOrderVO);
PackageOrderDTO getByPackageNo(String packageNo);
@@ -205,6 +205,9 @@ public interface IPackageOrderService {
Map getCount(String userId);
void updateWriteoff(String packageOrderId, PackageOrderWriteoffVO packageOrderWriteoffVO);
+ void updateWriteoffAll(List list);
List getExpireList();
+
+ void saveOrderBackPay(PackageOrderAppVO packageOrderVO);
}
\ No newline at end of file
diff --git a/src/main/java/cn/com/tenlion/operator/service/packageorder/impl/PackageOrderServiceImpl.java b/src/main/java/cn/com/tenlion/operator/service/packageorder/impl/PackageOrderServiceImpl.java
index 5f47717..7d3c7cc 100644
--- a/src/main/java/cn/com/tenlion/operator/service/packageorder/impl/PackageOrderServiceImpl.java
+++ b/src/main/java/cn/com/tenlion/operator/service/packageorder/impl/PackageOrderServiceImpl.java
@@ -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 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 params = new HashMap<>();
+ params.put("packageOrderId", orderDTO.getPackageOrderId());
+ params.put("gmtModified", DateUtil.getTime());
+ packageOrderDao.updateExpireStatus(params);
+ }
+ }
+ }
+
@Override
public List getExpireList() {
Map params = new HashMap<>();
@@ -335,6 +355,81 @@ public class PackageOrderServiceImpl extends DefaultBaseService implements IPack
List 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 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 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 list(Map 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 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) {
diff --git a/src/main/java/cn/com/tenlion/operator/task/ClosePackageOrder.java b/src/main/java/cn/com/tenlion/operator/task/ClosePackageOrder.java
index 2b324c2..a312f20 100644
--- a/src/main/java/cn/com/tenlion/operator/task/ClosePackageOrder.java
+++ b/src/main/java/cn/com/tenlion/operator/task/ClosePackageOrder.java
@@ -40,14 +40,10 @@ public class ClosePackageOrder implements Job {
IPackageOrderService orderService = QuartzConfigSpringUtil.getBean(IPackageOrderService.class);
// 查找已经过期的 , 数量还大于0的 ,
List 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) {
diff --git a/src/main/resources/mybatis/mapper/packageorder/package-order-mapper.xml b/src/main/resources/mybatis/mapper/packageorder/package-order-mapper.xml
index 6f2ae6c..c6c2986 100644
--- a/src/main/resources/mybatis/mapper/packageorder/package-order-mapper.xml
+++ b/src/main/resources/mybatis/mapper/packageorder/package-order-mapper.xml
@@ -149,6 +149,16 @@
+
+ UPDATE
+ operator_package_order
+ SET
+ package_expire_status = '1',
+ gmt_modified = #{gmtModified}
+ WHERE
+ package_order_id = #{packageOrderId} AND package_total_surplus_count = 0
+
+
UPDATE
@@ -326,7 +336,7 @@
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'
AND t1.package_total_surplus_count > 0