|
@@ -0,0 +1,102 @@
|
|
|
|
+package com.fdkankan.ucenter.pay.strategy.impl;
|
|
|
|
+
|
|
|
|
+import com.fdkankan.ucenter.entity.CameraDetail;
|
|
|
|
+import com.fdkankan.ucenter.entity.IncrementOrder;
|
|
|
|
+import com.fdkankan.ucenter.entity.User;
|
|
|
|
+import com.fdkankan.ucenter.entity.UserIncrement;
|
|
|
|
+import com.fdkankan.ucenter.pay.strategy.OrderStrategy;
|
|
|
|
+import com.fdkankan.ucenter.service.*;
|
|
|
|
+import com.fdkankan.ucenter.util.DateUserUtil;
|
|
|
|
+import lombok.extern.log4j.Log4j2;
|
|
|
|
+import org.joda.time.DateTime;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.stereotype.Component;
|
|
|
|
+
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.UUID;
|
|
|
|
+
|
|
|
|
+@Log4j2
|
|
|
|
+@Component
|
|
|
|
+public class IncrementOrderImpl implements OrderStrategy {
|
|
|
|
+ @Autowired
|
|
|
|
+ private IIncrementOrderService incrementOrderService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserIncrementService userIncrementService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private IUserService userService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ISceneProService sceneProService;
|
|
|
|
+ @Autowired
|
|
|
|
+ ICameraDetailService cameraDetailService;
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public void handleOrder(String orderSn, String tradeNo, String openId, int paymentTypeName, Long spaceId) throws Exception {
|
|
|
|
+ IncrementOrder responseIncrementOrder = incrementOrderService.getByOrderSn(orderSn);
|
|
|
|
+ if (responseIncrementOrder == null) {
|
|
|
|
+ log.error("找不到订单:" + orderSn);
|
|
|
|
+ throw new Exception("找不到订单,out_trade_no错误");
|
|
|
|
+ }
|
|
|
|
+ // 更新增值权益订单
|
|
|
|
+ boolean result = incrementOrderService.paySuccessIncrementOrder(orderSn, tradeNo, paymentTypeName);
|
|
|
|
+ if (!result){
|
|
|
|
+ log.error("更新增值权益订单失败");
|
|
|
|
+ throw new Exception("更新增值权益订单失败");
|
|
|
|
+ }
|
|
|
|
+ UserIncrement userIncrementEntity = new UserIncrement();
|
|
|
|
+ if(responseIncrementOrder.getIncrementId() == null){
|
|
|
|
+
|
|
|
|
+ //新的增值权益套餐方案
|
|
|
|
+ DateTime date = new DateTime().plusYears(1);
|
|
|
|
+
|
|
|
|
+ if(responseIncrementOrder.getCount() > 0){
|
|
|
|
+ for(int i = 0, len = responseIncrementOrder.getCount(); i < len; i++){
|
|
|
|
+ userIncrementEntity = new UserIncrement();
|
|
|
|
+ userIncrementEntity.setKeyWord(UUID.randomUUID().toString().replace("-", ""));
|
|
|
|
+ userIncrementEntity.setUserId(responseIncrementOrder.getUserId());
|
|
|
|
+ userIncrementEntity.setOrderSn(orderSn);
|
|
|
|
+ userIncrementEntity.setIncrementStartTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ userIncrementEntity.setIncrementEndTime(DateUserUtil.getDate(date.toDate()));
|
|
|
|
+ userIncrementEntity.setIsExpired(0);
|
|
|
|
+ userIncrementService.save(userIncrementEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ userIncrementEntity = userIncrementService.getById(responseIncrementOrder.getIncrementId());
|
|
|
|
+ DateTime date = null;
|
|
|
|
+ Date nowDate = new Date();
|
|
|
|
+ if(DateUserUtil.getDate(userIncrementEntity.getIncrementEndTime()).getTime() > nowDate.getTime()){
|
|
|
|
+ date = new DateTime(userIncrementEntity.getIncrementEndTime()).plusYears(1);
|
|
|
|
+ if(DateUserUtil.getDate(userIncrementEntity.getIncrementEndTime()).getYear() % 4 == 0){
|
|
|
|
+ date.plusDays(1);
|
|
|
|
+ }
|
|
|
|
+ }else {
|
|
|
|
+ date = new DateTime(nowDate).plusYears(1);
|
|
|
|
+ if(nowDate.getYear() % 4 == 0){
|
|
|
|
+ date.plusDays(1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ userIncrementEntity.setIncrementEndTime(DateUserUtil.getDate(date.toDate()));
|
|
|
|
+ userIncrementEntity.setOrderSn(userIncrementEntity.getOrderSn() + "," + orderSn);
|
|
|
|
+ userIncrementEntity.setCreateTime(DateUserUtil.getDate(new Date()));
|
|
|
|
+ userIncrementEntity.setIsExpired(0);
|
|
|
|
+ userIncrementService.updateById(userIncrementEntity);
|
|
|
|
+
|
|
|
|
+ //解封所有场景
|
|
|
|
+ if(userIncrementEntity.getUserId() != null && userIncrementEntity.getCameraId() != null){
|
|
|
|
+ CameraDetail cameraDetail = cameraDetailService.getByCameraId(userIncrementEntity.getCameraId());
|
|
|
|
+ sceneProService.lockOrUnLockBySpace(cameraDetail, userIncrementEntity.getCameraId(),1);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ User userEntity = userService.getById(userIncrementEntity.getUserId());
|
|
|
|
+ if(userEntity != null){
|
|
|
|
+ userEntity.setDownloadNumTotal(userEntity.getDownloadNumTotal() + responseIncrementOrder.getCount() * 10);
|
|
|
|
+ userService.updateById(userEntity);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
|
|
+ public String getType() {
|
|
|
|
+ return "increment";
|
|
|
|
+ }
|
|
|
|
+}
|