Kaynağa Gözat

Merge remote-tracking branch 'origin/master'

LIDEXI 4 yıl önce
ebeveyn
işleme
5144409c79

+ 16 - 0
src/main/java/org/springblade/common/constant/SystemConstant.java

@@ -135,4 +135,20 @@ public interface SystemConstant {
 			this.value = value;
 		}
 	}
+
+	@Getter
+	enum AgentEnable{
+		IS_ENABLE("启用", 1),
+		NOT_ENABLE("禁用", -1);
+
+		String name;
+		Integer value;
+		AgentEnable(String name, Integer value){
+			this.name = name;
+			this.value = value;
+		}
+	}
+
+
+
 }

+ 3 - 0
src/main/java/org/springblade/modules/ldt/billrecord/entity/BillRecord.java

@@ -168,4 +168,7 @@ public class BillRecord extends BaseEntity {
 
 	@ApiModelProperty("openId")
 	private String openId;
+
+	@ApiModelProperty("平台订单id")
+	private String platformId;
 }

+ 1 - 1
src/main/java/org/springblade/modules/ldt/billrecord/mapper/BillRecordMapper.xml

@@ -29,7 +29,7 @@
         <result column="pay_success_date" property="paySuccessDate"/>
         <result column="payer_info" property="payerInfo"/>
         <result column="pay_status" property="payStatus"/>
-
+        <result column="platform_id" property="platformId"/>
     </resultMap>
 
 

+ 0 - 2
src/main/java/org/springblade/modules/payment/controller/PaymentController.java

@@ -42,8 +42,6 @@ public class PaymentController {
 	){
 		//获取支付插件
 		Payment payment =  pluginBuild(paymentType);
-
-
 		//解析支付场景
 		PaymentScene scene = Optional.ofNullable(PaymentScene.valueOf(paymentScene))
 				.orElseThrow(()-> new BizException(ResCode.PAY_SCENE_ERROR));

+ 16 - 4
src/main/java/org/springblade/modules/payment/entity/SuccessParams.java

@@ -19,12 +19,24 @@ public class SuccessParams {
 	public static final String PAY_STATUS_SUCCESS = "success";
 	public static final String PAY_STATUS_FAIL = "fail";
 
-	//订单id
+	/**
+	 * 订单id
+	 */
 	private String billId;
-	//平台订单id
+	/**
+	 * 平台id
+	 */
 	private String platformId;
-	//支付状态
+	/**
+	 * orderId
+	 */
+	private String orderId;
+	/**
+	 * 支付状态
+	 */
 	private String status;
-	//订单类型
+	/**
+	 * 订单类型
+	 */
 	private String orderType;
 }

+ 46 - 2
src/main/java/org/springblade/modules/payment/listener/AgentChargeListener.java

@@ -1,5 +1,13 @@
 package org.springblade.modules.payment.listener;
 
+import cn.hutool.core.lang.Assert;
+import org.springblade.common.constant.SystemConstant;
+import org.springblade.core.mp.support.Condition;
+import org.springblade.core.tool.utils.BeanUtil;
+import org.springblade.modules.ldt.agenter.entity.Agenter;
+import org.springblade.modules.ldt.agenter.service.IAgenterService;
+import org.springblade.modules.ldt.billrecord.entity.BillRecord;
+import org.springblade.modules.ldt.billrecord.service.IBillRecordService;
 import org.springblade.modules.payment.entity.SuccessParams;
 import org.springblade.modules.payment.event.AgentChargeEvent;
 import org.springblade.modules.payment.event.UserPayEvent;
@@ -8,6 +16,9 @@ import org.springframework.scheduling.annotation.Async;
 import org.springframework.stereotype.Component;
 import org.springframework.transaction.annotation.Transactional;
 
+import javax.annotation.Resource;
+import java.util.Objects;
+
 /**
  * @author: lianghanqiang
  * @description: 代理付款回调
@@ -16,12 +27,45 @@ import org.springframework.transaction.annotation.Transactional;
 @Component
 public class AgentChargeListener {
 
+	@Resource
+	private IBillRecordService billRecordService;
+	@Resource
+	private IAgenterService agenterService;
+
+	private final static String SUCCESS_STATUS = "success";
+
 
 	@EventListener
 	@Async
-	@Transactional
 	public void PaySuccess(AgentChargeEvent agentChargeEvent){
 		SuccessParams successParams = agentChargeEvent.getSuccessParams();
-		System.out.println(successParams);
+		//获取订单信息
+		BillRecord billRecord = billRecordService.getById(successParams.getBillId());
+		Assert.notNull(billRecord, "支付记录中无此订单");
+		billRecord.setPlatformId(successParams.getPlatformId());
+		System.out.println("successParams"+successParams);
+		//已付款状态,只存平台订单id
+		if (Objects.equals(billRecord.getPayStatus(), SystemConstant.BillRecordPayStatus.PAYED.getValue())) {
+			System.out.println("1");
+			//有可能是前端状态传错,把平台订单id存起来
+			billRecordService.updateById(billRecord);
+			return;
+		}
+		String status = successParams.getStatus();
+		if (Objects.equals(status, SUCCESS_STATUS)) {
+			System.out.println("2");
+			//支付成功
+			billRecord.setPayStatus(SystemConstant.BillRecordPayStatus.PAYED.getValue());
+			billRecordService.updateById(billRecord);
+			//代理状态改为激活状态
+			Long userId = billRecord.getUserId();
+			Agenter agenter = agenterService.getOne(Condition.getQueryWrapper(new Agenter()).lambda().eq(Agenter::getUserId, userId));
+			Assert.notNull(agenter, billRecord.getId()+"未找到代理信息");
+			agenter.setEnabled(SystemConstant.AgentEnable.IS_ENABLE.getValue());
+			agenterService.updateById(agenter);
+		}
+		System.out.println("3");
+
+
 	}
 }