|
@@ -3,6 +3,8 @@ package com.miaxis.app.controller.wx;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
|
|
+import com.miaxis.birthday.domain.BirthdayLog;
|
|
|
+import com.miaxis.birthday.service.IBirthdayLogService;
|
|
|
import com.miaxis.common.config.WxpayConfig;
|
|
|
import com.miaxis.common.constant.Constants;
|
|
|
import com.miaxis.common.core.controller.BaseController;
|
|
@@ -16,6 +18,7 @@ import com.miaxis.common.utils.ip.IpUtils;
|
|
|
import com.miaxis.common.utils.uuid.CommonUtils;
|
|
|
import com.miaxis.exam.domain.ExamInfo;
|
|
|
import com.miaxis.exam.service.IExamInfoService;
|
|
|
+import com.miaxis.system.service.ISysConfigService;
|
|
|
import com.miaxis.system.service.ISysDictDataService;
|
|
|
import com.miaxis.vip.service.IVipUserExamService;
|
|
|
import com.miaxis.wx.domain.WxOrder;
|
|
@@ -73,9 +76,17 @@ public class WxController extends BaseController {
|
|
|
@Autowired
|
|
|
private ISysDictDataService dictDataService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private ISysConfigService configService;
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private IExamInfoService examInfoService;
|
|
|
|
|
|
+ @Autowired
|
|
|
+ private IBirthdayLogService birthdayLogService;
|
|
|
+
|
|
|
+
|
|
|
@Autowired
|
|
|
private IVipUserExamService vipUserExamService;
|
|
|
|
|
@@ -231,9 +242,9 @@ public class WxController extends BaseController {
|
|
|
*/
|
|
|
@PostMapping(value = "/xcxPrepareOrder")
|
|
|
@ApiOperation("微信小程序支付下单")
|
|
|
- public Response<JSONObject> xcxPrepareOrder(@RequestBody WxOrderDTO wxOrderDTO) throws Exception{
|
|
|
+ public Response<JSONObject> xcxPrepareOrder(@RequestBody WxOrderDTO wxOrderDTO) throws Exception {
|
|
|
UserInfo userInfo = SecurityUtils.getLoginUser().getStudent();
|
|
|
- if(wxOrderDTO.getGoodsType()==1) {
|
|
|
+ if (wxOrderDTO.getGoodsType() == 1) {
|
|
|
int count = vipUserExamService.getUserExamByUnionIdAndGoodsId(userInfo.getUnionId(), wxOrderDTO.getGoodsId());
|
|
|
if (count > 0) {
|
|
|
throw new CustomException("您已购买过该考场,退回上个页面,重新进入。");
|
|
@@ -257,8 +268,32 @@ public class WxController extends BaseController {
|
|
|
order.setOrderStatus(OrderStatusEnum.PROCESSING.getCode());
|
|
|
wxOrderService.save(order);
|
|
|
return Response.success(placeXcxWxOrder(order, examInfo.getName()));
|
|
|
- } else if (wxOrderDTO.getGoodsType()==2) {
|
|
|
+ } else if (wxOrderDTO.getGoodsType() == 2) {
|
|
|
throw new CustomException("请正确传入GoodsType,GoodsType=2未开发");
|
|
|
+ } else if (wxOrderDTO.getGoodsType() == 3) {
|
|
|
+ String baziPriceStr = configService.selectConfigByKey("bazi_price");
|
|
|
+ BirthdayLog birthdayLog = birthdayLogService.getById(wxOrderDTO.getGoodsId()); //记录ID
|
|
|
+ if(birthdayLog!=null && (birthdayLog.getIsPay()==1 || birthdayLog.getIsPay()==2)) {
|
|
|
+ throw new CustomException("您已支付此订单,退回上个页面,重新进入。");
|
|
|
+ }
|
|
|
+ //创建本地微信订单
|
|
|
+ WxOrder order = new WxOrder();
|
|
|
+ String orderCode = getOrderCode(userInfo.getId());
|
|
|
+ order.setGoodsId(birthdayLog.getId()); //八字记录ID
|
|
|
+ order.setGoodsName("八字排盘");
|
|
|
+ order.setGoodsType(3);
|
|
|
+ order.setOutTradeNo(orderCode);
|
|
|
+ order.setUserId(userInfo.getId());
|
|
|
+ order.setXcxOpenid(userInfo.getXcxOpenid());
|
|
|
+ order.setAppOpenid(userInfo.getAppOpenid());
|
|
|
+ order.setGzhOpenid(userInfo.getGzhOpenid());
|
|
|
+ order.setUnionId(userInfo.getUnionId());
|
|
|
+ order.setPhoneType(wxOrderDTO.getPhoneType()); //手机类型 1:苹果 2:安卓
|
|
|
+ order.setForeType(wxOrderDTO.getForeType()); //前端类型 1:app 2:小程序 3:公众号
|
|
|
+ order.setTotal(Integer.parseInt(baziPriceStr));
|
|
|
+ order.setOrderStatus(OrderStatusEnum.PROCESSING.getCode());
|
|
|
+ wxOrderService.save(order);
|
|
|
+ return Response.success(placeXcxWxOrder(order, "八字排盘"));
|
|
|
} else {
|
|
|
throw new CustomException("请正确传入GoodsType。");
|
|
|
}
|
|
@@ -284,6 +319,7 @@ public class WxController extends BaseController {
|
|
|
.put("out_trade_no", order.getOutTradeNo());
|
|
|
rootNode.putObject("amount").put("total", order.getTotal());
|
|
|
rootNode.putObject("payer").put("openid", order.getXcxOpenid());
|
|
|
+ rootNode.putObject("settle_info").put("profit_sharing",true);
|
|
|
objectMapper.writeValue(bos, rootNode);
|
|
|
httpPost.setEntity(new StringEntity(rootNode.toString(), "utf-8"));
|
|
|
HttpResponse response = httpClient.execute(httpPost);
|