|
@@ -9,6 +9,7 @@ import com.miaxis.common.core.domain.entity.UserInfo;
|
|
|
import com.miaxis.common.exception.CustomException;
|
|
|
import com.miaxis.common.utils.AesUtil;
|
|
|
import com.miaxis.common.utils.SecurityUtils;
|
|
|
+import com.miaxis.user.service.IUserInfoService;
|
|
|
import com.miaxis.vip.domain.VipCode;
|
|
|
import com.miaxis.vip.service.IVipCodeService;
|
|
|
import com.miaxis.wx.domain.RefundRecord;
|
|
@@ -61,6 +62,9 @@ public class WxNotifyController {
|
|
|
private IVipCodeService vipCodeService;
|
|
|
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IUserInfoService userInfoService;
|
|
|
+
|
|
|
|
|
|
@Autowired
|
|
|
private IRefundRecordService refundRecordService;
|
|
@@ -83,11 +87,11 @@ public class WxNotifyController {
|
|
|
log.info(resourceString);
|
|
|
JSONObject jsonObject = JSONObject.parseObject(resourceString);
|
|
|
//将回调数据写入数据库
|
|
|
- writeNotifyDataToDb(jsonObject);
|
|
|
+ String outTradeNo = writeNotifyDataToDb(jsonObject);
|
|
|
//创建兑换码
|
|
|
String code = createCode();
|
|
|
//激活用户
|
|
|
- avtivityCode(code);
|
|
|
+ avtivityCode(outTradeNo,code);
|
|
|
|
|
|
WxNotifyReturnDTO wxNotifyReturnDTO = new WxNotifyReturnDTO();
|
|
|
wxNotifyReturnDTO.setCode("SUCCESS");
|
|
@@ -95,7 +99,12 @@ public class WxNotifyController {
|
|
|
return wxNotifyReturnDTO;
|
|
|
}
|
|
|
|
|
|
- private void avtivityCode(String vipCode) {
|
|
|
+ private void avtivityCode(String outTradeNo, String vipCode) {
|
|
|
+ WxOrder wxOrder = wxOrderService.getByOutTradeNo(outTradeNo);
|
|
|
+ if (wxOrder == null){
|
|
|
+ throw new CustomException("改订单不存在");
|
|
|
+ }
|
|
|
+ UserInfo userInfo = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("openid", wxOrder.getOpenid()));
|
|
|
QueryWrapper<VipCode> queryWrapper = new QueryWrapper<VipCode>();
|
|
|
queryWrapper.eq("vip_code", vipCode);
|
|
|
VipCode vipCodeEntity = vipCodeService.getOne(queryWrapper);
|
|
@@ -108,11 +117,8 @@ public class WxNotifyController {
|
|
|
if (vipCodeEntity.getStatus() == 2){
|
|
|
throw new CustomException("该激活码已作废");
|
|
|
}
|
|
|
-
|
|
|
- UserInfo student = SecurityUtils.getLoginUser().getStudent();
|
|
|
-
|
|
|
vipCodeEntity.setStatus(1);
|
|
|
- vipCodeEntity.setActivationUserId(student.getId());
|
|
|
+ vipCodeEntity.setActivationUserId(userInfo.getId());
|
|
|
vipCodeEntity.setActivationTime(new Date());
|
|
|
vipCodeService.updateById(vipCodeEntity);
|
|
|
}
|
|
@@ -228,7 +234,7 @@ public class WxNotifyController {
|
|
|
|
|
|
|
|
|
|
|
|
- public void writeNotifyDataToDb(JSONObject jsonObject) {
|
|
|
+ public String writeNotifyDataToDb(JSONObject jsonObject) {
|
|
|
String outTradeNo = jsonObject.getString("out_trade_no");
|
|
|
WxOrder wxOrder = wxOrderService.getByOutTradeNo(outTradeNo);
|
|
|
if (wxOrder == null) {
|
|
@@ -252,6 +258,7 @@ public class WxNotifyController {
|
|
|
wxOrder.setDeviceId(sceneInfo.getString("device_id"));
|
|
|
}
|
|
|
wxOrderService.updateById(wxOrder);
|
|
|
+ return outTradeNo;
|
|
|
|
|
|
}
|
|
|
|