|
@@ -1,23 +1,24 @@
|
|
|
package com.caimei.controller.order;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSON;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.caimei.entity.CmOperationUser;
|
|
|
import com.caimei.entity.WxJsonModel;
|
|
|
import com.caimei.service.order.OrderService;
|
|
|
+import com.caimei.utils.HttpRequest;
|
|
|
import com.caimei.utils.JsonMapper;
|
|
|
import com.caimei.utils.SessionHelper;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Controller;
|
|
|
-import org.springframework.util.CollectionUtils;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
-import org.thymeleaf.expression.Maps;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
|
import java.util.HashMap;
|
|
|
-import java.util.List;
|
|
|
import java.util.Map;
|
|
|
|
|
|
/**
|
|
@@ -30,6 +31,10 @@ public class OrderController {
|
|
|
|
|
|
@Autowired
|
|
|
private OrderService orderService;
|
|
|
+ @Value("${miniprogram.AppId}")
|
|
|
+ private String AppId;
|
|
|
+ @Value("${miniprogram.AppSecret}")
|
|
|
+ private String AppSecret;
|
|
|
|
|
|
/**
|
|
|
* 确认订单信息
|
|
@@ -55,6 +60,51 @@ public class OrderController {
|
|
|
return WxJsonModel.newInstance().success(shareCode);
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 分享订单,分享码验证通过
|
|
|
+ */
|
|
|
+ @ResponseBody
|
|
|
+ @RequestMapping("/shareCode")
|
|
|
+ public WxJsonModel verifyShareCode(String shareCode, String code, Integer orderID, HttpServletRequest request) {
|
|
|
+ WxJsonModel model = WxJsonModel.newInstance();
|
|
|
+ logger.info("Start get SessionKey");
|
|
|
+ Map<String, Object> map = new HashMap<>();
|
|
|
+ String referer = request.getHeader("Referer"); //获取当前微信小程序的环境
|
|
|
+ logger.info("referer-is----:" + referer);
|
|
|
+ map.put("referer", referer);
|
|
|
+ String requestUrl = "https://api.weixin.qq.com/sns/jscode2session";
|
|
|
+ Map<String, String> requestUrlParam = new HashMap<String, String>();
|
|
|
+ requestUrlParam.put("appid", AppId);//小程序appId
|
|
|
+ requestUrlParam.put("secret", AppSecret);//小程序appsecret
|
|
|
+ requestUrlParam.put("js_code", code);//小程序端返回的code
|
|
|
+ requestUrlParam.put("grant_type", "authorization_code");//默认参数
|
|
|
+ //发送post请求读取调用微信接口获取openid用户唯一标识
|
|
|
+ String infos;
|
|
|
+ try {
|
|
|
+ infos = HttpRequest.sendPost(requestUrl, requestUrlParam);
|
|
|
+ } catch (Exception e) {
|
|
|
+ model.setData(map);
|
|
|
+ return model.error("服务器内部异常");
|
|
|
+ }
|
|
|
+ //解析相应内容(转换成json对象)
|
|
|
+ JSONObject jsonObject = JSON.parseObject(infos);
|
|
|
+ String openid = jsonObject.getString("openid");
|
|
|
+ logger.info("openid----->" + openid);
|
|
|
+ String session_key = jsonObject.getString("session_key");
|
|
|
+ String errcode = jsonObject.getString("errcode");
|
|
|
+ String errmsg = jsonObject.getString("errmsg");
|
|
|
+ if (!org.springframework.util.StringUtils.isEmpty(errcode) &&
|
|
|
+ (errcode.equals("-1") || errcode.equals("40029") || errcode.equals("45011"))) {
|
|
|
+ model.setMsg(errmsg);
|
|
|
+ model.setData(map);
|
|
|
+ map.put("sessionKey", session_key);
|
|
|
+ model.setCode("-1");
|
|
|
+ return model;
|
|
|
+ }
|
|
|
+ WxJsonModel jsonModel = orderService.verifyShareCode(shareCode, openid, orderID);
|
|
|
+ return jsonModel;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 订单详情
|
|
|
*/
|
|
@@ -68,6 +118,7 @@ public class OrderController {
|
|
|
/**
|
|
|
* 提交订单接口
|
|
|
*
|
|
|
+ * @return code:1000=用户账户异常,1001=数据异常
|
|
|
* @Param params参数格式:
|
|
|
* 参数1=userId用户ID
|
|
|
* 参数2=organizeID组织ID,
|
|
@@ -76,69 +127,68 @@ public class OrderController {
|
|
|
* 参数5=orderInfo订单信息参数格式:
|
|
|
* [
|
|
|
* {"shopId":1001,
|
|
|
- * "note":81,
|
|
|
- * "productInfo":[{"productId":1,"productNum":80},{"productId":2,"productNum":100}]
|
|
|
+ * "note":81,
|
|
|
+ * "productInfo":[{"productId":1,"productNum":80},{"productId":2,"productNum":100}]
|
|
|
* }
|
|
|
- *]
|
|
|
- *参数6=balanceDeductionFlag是否使用余额抵扣(1使用,2使用)
|
|
|
- *参数7=orderShouldPayFee订单应付金额(商品总金额 - 余额抵扣 - 经理折扣默认为0)
|
|
|
- * @return code:1000=用户账户异常,1001=数据异常
|
|
|
+ * ]
|
|
|
+ * 参数6=balanceDeductionFlag是否使用余额抵扣(1使用,2使用)
|
|
|
+ * 参数7=orderShouldPayFee订单应付金额(商品总金额 - 余额抵扣 - 经理折扣默认为0)
|
|
|
*/
|
|
|
@ResponseBody
|
|
|
@RequestMapping("/submitOrder")
|
|
|
- public WxJsonModel submitOrder(String params,HttpServletRequest request) {
|
|
|
+ public WxJsonModel submitOrder(String params, HttpServletRequest request) {
|
|
|
WxJsonModel wxJsonModel = WxJsonModel.newInstance();
|
|
|
- logger.info(">>>>>>订单信息params:"+params);
|
|
|
+ logger.info(">>>>>>订单信息params:" + params);
|
|
|
//检查用户是否登入
|
|
|
CmOperationUser currentUser = SessionHelper.getCurrentUser(request);
|
|
|
- if(null == currentUser){
|
|
|
- return wxJsonModel.error("1000","用户账户异常");
|
|
|
+ if (null == currentUser) {
|
|
|
+ return wxJsonModel.error("1000", "用户账户异常");
|
|
|
}
|
|
|
Integer cmOperationID = currentUser.getId();//当前操作者ID
|
|
|
if (StringUtils.isBlank(params)) {
|
|
|
- return wxJsonModel.error("1001","数据异常" );
|
|
|
+ return wxJsonModel.error("1001", "数据异常");
|
|
|
}
|
|
|
- Map<String, Object> map = new HashMap<String,Object>();
|
|
|
- try{
|
|
|
- map =(Map<String, Object>) JsonMapper.getInstance().fromJsonString(params, Map.class);
|
|
|
- if(null == map){
|
|
|
+ Map<String, Object> map = new HashMap<String, Object>();
|
|
|
+ try {
|
|
|
+ map = (Map<String, Object>) JsonMapper.getInstance().fromJsonString(params, Map.class);
|
|
|
+ if (null == map) {
|
|
|
logger.info(">>>>>数据异常,参数不能为空");
|
|
|
- return wxJsonModel.error("1001","数据异常" );
|
|
|
+ return wxJsonModel.error("1001", "数据异常");
|
|
|
}
|
|
|
Integer userId = (Integer) map.get("userId");
|
|
|
Integer organizeID = (Integer) map.get("organizeID");
|
|
|
String cartType = (String) map.get("cartType");
|
|
|
Integer addressID = (Integer) map.get("addressID");
|
|
|
- Object orderInfo = map.get("orderInfo");
|
|
|
+ Object orderInfo = map.get("orderInfo");
|
|
|
String balanceDeductionFlag = (String) map.get("balanceDeductionFlag");
|
|
|
Double orderShouldPayFee = (Double) map.get("orderShouldPayFee");//此金额为前端计算,适用于后端计算金额复查
|
|
|
//校验传入参数的正确性
|
|
|
- if(null == userId){
|
|
|
- return wxJsonModel.error("1001","用户数据异常" );
|
|
|
+ if (null == userId) {
|
|
|
+ return wxJsonModel.error("1001", "用户数据异常");
|
|
|
}
|
|
|
- if(null ==organizeID){
|
|
|
- return wxJsonModel.error("1001","组织数据异常" );
|
|
|
+ if (null == organizeID) {
|
|
|
+ return wxJsonModel.error("1001", "组织数据异常");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(cartType)){
|
|
|
- return wxJsonModel.error("1001","购买类型数据异常" );
|
|
|
+ if (StringUtils.isEmpty(cartType)) {
|
|
|
+ return wxJsonModel.error("1001", "购买类型数据异常");
|
|
|
}
|
|
|
- if(null ==addressID){
|
|
|
- return wxJsonModel.error("1001","地址数据异常" );
|
|
|
+ if (null == addressID) {
|
|
|
+ return wxJsonModel.error("1001", "地址数据异常");
|
|
|
}
|
|
|
- if(null == orderInfo){
|
|
|
- return wxJsonModel.error("1001","订单数据异常" );
|
|
|
+ if (null == orderInfo) {
|
|
|
+ return wxJsonModel.error("1001", "订单数据异常");
|
|
|
}
|
|
|
- if(StringUtils.isEmpty(balanceDeductionFlag)){
|
|
|
- return wxJsonModel.error("1001","余额抵扣数据异常" );
|
|
|
+ if (StringUtils.isEmpty(balanceDeductionFlag)) {
|
|
|
+ return wxJsonModel.error("1001", "余额抵扣数据异常");
|
|
|
}
|
|
|
- if(null == orderShouldPayFee){
|
|
|
- return wxJsonModel.error("1001","订单应付金额数据异常" );
|
|
|
+ if (null == orderShouldPayFee) {
|
|
|
+ return wxJsonModel.error("1001", "订单应付金额数据异常");
|
|
|
}
|
|
|
//保存订单信息
|
|
|
- return orderService.saveOrderInfo(wxJsonModel, userId, organizeID, cartType, addressID, orderInfo, balanceDeductionFlag, orderShouldPayFee,cmOperationID);
|
|
|
- }catch (Exception e){
|
|
|
- logger.info(">>>>>系统异常"+e.getMessage());
|
|
|
- return wxJsonModel.error("1001","数据异常" );
|
|
|
+ return orderService.saveOrderInfo(wxJsonModel, userId, organizeID, cartType, addressID, orderInfo, balanceDeductionFlag, orderShouldPayFee, cmOperationID);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.info(">>>>>系统异常" + e.getMessage());
|
|
|
+ return wxJsonModel.error("1001", "数据异常");
|
|
|
|
|
|
}
|
|
|
}
|