|
|
|
@ -1,17 +1,25 @@ |
|
|
|
package cn.chjyj.szwh.controller.api; |
|
|
|
|
|
|
|
import cn.chjyj.szwh.bean.Order; |
|
|
|
import cn.chjyj.szwh.bean.User; |
|
|
|
import cn.chjyj.szwh.bean.*; |
|
|
|
import cn.chjyj.szwh.controller.BaseController; |
|
|
|
import cn.chjyj.szwh.service.OrderService; |
|
|
|
import cn.chjyj.szwh.service.UserService; |
|
|
|
import cn.chjyj.szwh.exception.ChException; |
|
|
|
import cn.chjyj.szwh.service.*; |
|
|
|
import cn.chjyj.szwh.utils.RedisUtils; |
|
|
|
import cn.chjyj.szwh.utils.SzOrderUtils; |
|
|
|
import cn.chjyj.szwh.utils.SzwhApiUtils; |
|
|
|
import cn.chjyj.szwh.vo.OrderDetailVo; |
|
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
|
import com.sun.org.apache.xpath.internal.operations.Or; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
import org.apache.commons.logging.LogFactory; |
|
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
|
import org.springframework.web.bind.annotation.*; |
|
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.text.SimpleDateFormat; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
@ -23,10 +31,22 @@ import java.util.Map; |
|
|
|
@RestController |
|
|
|
@RequestMapping(name = "/api/Order", method = RequestMethod.POST) |
|
|
|
public class OrderController extends BaseController { |
|
|
|
private static Log log = LogFactory.getLog(OrderController.class); |
|
|
|
@Autowired |
|
|
|
private OrderService orderService; |
|
|
|
@Autowired |
|
|
|
private UserService userService; |
|
|
|
@Autowired |
|
|
|
private GoodsService goodsService; |
|
|
|
@Autowired |
|
|
|
private GoodsDetailService goodsDetailService; |
|
|
|
//结算设置
|
|
|
|
@Autowired |
|
|
|
private AccountRatioSettingService accountRatioSettingService; |
|
|
|
@Autowired |
|
|
|
private AccountRatioDetailService accountRatioDetailService; |
|
|
|
@Autowired |
|
|
|
private OrderUserService orderUserService; |
|
|
|
|
|
|
|
/** |
|
|
|
* 获取订单信息 |
|
|
|
@ -82,26 +102,52 @@ public class OrderController extends BaseController { |
|
|
|
|
|
|
|
/** |
|
|
|
* 创建订单 |
|
|
|
* @param reqString 接收到的数据为json字符串 |
|
|
|
* @param request 接收到的请求 |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@RequestMapping("/createOrder") |
|
|
|
public JSONObject createOrder(@RequestBody String reqString, HttpServletRequest request) { |
|
|
|
public JSONObject createOrder(HttpServletRequest request) { |
|
|
|
// 商品编号,逗号分隔
|
|
|
|
String goodsIsli=request.getParameter("goods_isli"); |
|
|
|
// 是否在购物车
|
|
|
|
String isCar = request.getParameter("is_car"); |
|
|
|
//用户购买年限,逗号分隔
|
|
|
|
String userYears = request.getParameter("user_years"); |
|
|
|
// 用户编码
|
|
|
|
String userIsli= request.getParameter("user_isli"); |
|
|
|
|
|
|
|
log.info("创建订单接口"+request.toString()); |
|
|
|
String msg=""; |
|
|
|
int code=400; |
|
|
|
String sign = request.getHeader("sign"); |
|
|
|
//redis中是否存在
|
|
|
|
String r_key="createOrder_"+sign; |
|
|
|
if(StringUtils.isNotEmpty(RedisUtils.get(r_key))){ |
|
|
|
msg="请勿重复提交"; |
|
|
|
code=400; |
|
|
|
throw new ChException("请勿重复提交",400); |
|
|
|
} |
|
|
|
// 存入redis
|
|
|
|
RedisUtils.set(r_key,1,10); |
|
|
|
//用户购物车
|
|
|
|
String shopCar = RedisUtils.get("car_"+userIsli); |
|
|
|
//分割多个goodsisli
|
|
|
|
String goodArr[]=goodsIsli.split(","); |
|
|
|
// 购买年限数组
|
|
|
|
String uYears[] = userYears.split(","); |
|
|
|
//用户信息
|
|
|
|
User buser = userService.getUserByIsli(userIsli); |
|
|
|
|
|
|
|
//只有一条记录的时候
|
|
|
|
if(goodArr.length==1){ |
|
|
|
|
|
|
|
}else{ //多个商品编号
|
|
|
|
|
|
|
|
} |
|
|
|
if(StringUtils.isBlank(reqString)){ |
|
|
|
JSONObject json = JSONObject.parseObject(reqString); |
|
|
|
String user_isli = json.getString("user_isli"); |
|
|
|
//查找对应的用户
|
|
|
|
User dbuser = userService.getUserByIsli(user_isli); |
|
|
|
//未能删除成功
|
|
|
|
if(!RedisUtils.delete(r_key)){ |
|
|
|
throw new ChException("请勿重复提交",400); |
|
|
|
} |
|
|
|
jsonObject.put("code",code); |
|
|
|
jsonObject.put("msg",msg); |
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
@ -130,4 +176,115 @@ public class OrderController extends BaseController { |
|
|
|
// 请求转发到远程服务器
|
|
|
|
return jsonObject; |
|
|
|
} |
|
|
|
|
|
|
|
private String buyFindGoods(String userIsli,String goodsIsli,int userYears){ |
|
|
|
Goods goods= goodsService.getGoodsByIsli(goodsIsli); |
|
|
|
if(goods==null){ |
|
|
|
throw new ChException("没有该标的",400); |
|
|
|
} |
|
|
|
|
|
|
|
GoodsDetail goodsDetail = goodsDetailService.getGoodsDetailBygid(goods.getGoodsDetailId()); |
|
|
|
int count = Integer.valueOf(userYears); |
|
|
|
if(goodsDetail.getGoodsEntrust()==1){ |
|
|
|
count=1; |
|
|
|
} |
|
|
|
// 结算设置
|
|
|
|
AccountRatioSetting accountRatioSetting = accountRatioSettingService.getUsingAccRationSetting(); |
|
|
|
//结算分配信息
|
|
|
|
AccountRatioDetail accountRatioDetail = accountRatioDetailService.getAccRatioDetailUnderRole(accountRatioSetting.getId(), |
|
|
|
2); |
|
|
|
// 判断当前订单是否存在问题
|
|
|
|
Order order=new Order(); |
|
|
|
//校验订单信息合法
|
|
|
|
SzOrderUtils.checkOrder(goods,goodsDetail,null,userIsli); |
|
|
|
//服务费
|
|
|
|
BigDecimal serviceCharge=new BigDecimal(0.00); |
|
|
|
//订单总费用
|
|
|
|
BigDecimal totalMoney=new BigDecimal(0.00); |
|
|
|
int status=0;//订单状态
|
|
|
|
int payStatus=0;//支付状态
|
|
|
|
// 付费商品
|
|
|
|
if(goodsDetail.getChargesType()==2){ |
|
|
|
if(accountRatioDetail.getCalculate()==1){ |
|
|
|
//rate 小于等于0
|
|
|
|
if(accountRatioDetail.getRatio().compareTo(new BigDecimal(0))!=1){ |
|
|
|
// 服务费0
|
|
|
|
serviceCharge = new BigDecimal(0.00); |
|
|
|
}else{ |
|
|
|
// 购买数量* 单价*(分配比例/100)
|
|
|
|
serviceCharge =new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.multiply(accountRatioDetail.getRatio().divide(new BigDecimal(100))); |
|
|
|
} |
|
|
|
}else{ |
|
|
|
//固定金额
|
|
|
|
// 购买数量*单机+固定费额
|
|
|
|
serviceCharge = new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.add(accountRatioDetail.getAmount()); |
|
|
|
} |
|
|
|
//总的额度
|
|
|
|
totalMoney = new BigDecimal(count).multiply(goodsDetail.getPrice()) |
|
|
|
.add(serviceCharge) |
|
|
|
.add(goodsDetail.getEarnestMoney()); |
|
|
|
status=1; |
|
|
|
payStatus=1; |
|
|
|
}else{ |
|
|
|
// 免费
|
|
|
|
serviceCharge =new BigDecimal(0.00); |
|
|
|
totalMoney = new BigDecimal(0.00); |
|
|
|
status=2; |
|
|
|
payStatus=2; //已支付
|
|
|
|
} |
|
|
|
// 订单编号
|
|
|
|
String batchCode = SzOrderUtils.createOrderBatchcode(); |
|
|
|
// 增加到订单商品详情
|
|
|
|
OrderGoodsDetail orderGoodsDetail = SzOrderUtils.mkOrderGoodsDetail(goodsDetail,batchCode,count,userYears); |
|
|
|
// 补充其他未添加的属性
|
|
|
|
orderGoodsDetail.setEntrustIslicode(goods.getUserIslicode()); |
|
|
|
// 订单服务费
|
|
|
|
orderGoodsDetail.setServiceCharge(serviceCharge); |
|
|
|
//总金额
|
|
|
|
orderGoodsDetail.setMoney(totalMoney); |
|
|
|
orderGoodsDetail.setIslicode(goods.getIsLicode()); |
|
|
|
// 查找用户
|
|
|
|
OrderUser orderUser = orderUserService.getOrderUser(batchCode,goods.getIsLicode()); |
|
|
|
int userId=0; |
|
|
|
if(orderUser!=null){ |
|
|
|
userId = orderUser.getId(); |
|
|
|
}else{ |
|
|
|
// 获取远程用户信息
|
|
|
|
JSONObject userjson = SzwhApiUtils.getApiUser(userIsli); |
|
|
|
if(StringUtils.isBlank(userjson.getString("data"))){ |
|
|
|
throw new ChException("未查询到用户信息,下单失败",400); |
|
|
|
} |
|
|
|
//添加用户
|
|
|
|
OrderUser odu =SzOrderUtils.mkOrderUser(batchCode,userjson,0); |
|
|
|
orderUserService.addOrderUser(odu); |
|
|
|
userId = odu.getId(); |
|
|
|
} |
|
|
|
|
|
|
|
// 订单实体
|
|
|
|
order.setBatchcode(batchCode); |
|
|
|
order.setUserId(userId); |
|
|
|
order.setBuyIslicode(userIsli); |
|
|
|
order.setTotalServiceCharge(serviceCharge); |
|
|
|
order.setTotalMoney(totalMoney); |
|
|
|
order.setType(1); |
|
|
|
order.setStatus(status); |
|
|
|
order.setPayStatus(payStatus); |
|
|
|
// 分配设置编号
|
|
|
|
order.setAccountRatioId(accountRatioSetting.getId()); |
|
|
|
//如果是付费
|
|
|
|
if(goodsDetail.getChargesType()==1){ |
|
|
|
order.setPaymenttime(new Date()); |
|
|
|
} |
|
|
|
order.setCreatetime(new Date()); |
|
|
|
// 订单信息入库
|
|
|
|
int ret = orderService.addOrder(order); |
|
|
|
if(ret==1){ |
|
|
|
if(status==2){ |
|
|
|
// 更新订单信息
|
|
|
|
} |
|
|
|
} |
|
|
|
return ""; |
|
|
|
} |
|
|
|
} |
|
|
|
|