|
@@ -1,6 +1,7 @@
|
|
package com.kmall.api.service;
|
|
package com.kmall.api.service;
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
+import com.kmall.api.contants.Dict;
|
|
import com.kmall.api.dao.*;
|
|
import com.kmall.api.dao.*;
|
|
import com.kmall.api.entity.*;
|
|
import com.kmall.api.entity.*;
|
|
import com.kmall.api.util.CommonUtil;
|
|
import com.kmall.api.util.CommonUtil;
|
|
@@ -117,19 +118,7 @@ public class ApiOrderService {
|
|
Map resultObj = new HashMap();
|
|
Map resultObj = new HashMap();
|
|
|
|
|
|
Integer userCouponId = jsonParam.getInteger("userCouponId");
|
|
Integer userCouponId = jsonParam.getInteger("userCouponId");
|
|
- String postscript = jsonParam.getString("postscript");
|
|
|
|
- Long fullCutCouponId = jsonParam.getLong("fullCutCouponId");
|
|
|
|
- AddressVo addressVo = jsonParam.getObject("checkedAddress", AddressVo.class);
|
|
|
|
String formId = jsonParam.getString("formId");
|
|
String formId = jsonParam.getString("formId");
|
|
- Date delivery_date = jsonParam.getDate("delivery_date");
|
|
|
|
- if (null == delivery_date) {
|
|
|
|
- delivery_date = new Date();
|
|
|
|
- }
|
|
|
|
- String delivery_remark = jsonParam.getString("delivery_remark");
|
|
|
|
- if (StringUtils.isNullOrEmpty(delivery_remark)) {
|
|
|
|
- delivery_remark = "尽快送达";
|
|
|
|
- }
|
|
|
|
- BigDecimal freightPrice = new BigDecimal(10.00);
|
|
|
|
//获取要购买的商品
|
|
//获取要购买的商品
|
|
Map param = new HashMap();
|
|
Map param = new HashMap();
|
|
param.put("user_id", loginUser.getId());
|
|
param.put("user_id", loginUser.getId());
|
|
@@ -156,10 +145,117 @@ public class ApiOrderService {
|
|
productInfo.addSellVolume();
|
|
productInfo.addSellVolume();
|
|
productVos.add(productInfo);
|
|
productVos.add(productInfo);
|
|
}
|
|
}
|
|
|
|
+ List<OrderVo> orderInfoList = new ArrayList();
|
|
|
|
+ //订单按业务类型进行分单
|
|
|
|
+ for (CartVo goodsItem : checkedGoodsList) {
|
|
|
|
+ OrderVo order00 = new OrderVo();
|
|
|
|
+ OrderVo order02 = new OrderVo();
|
|
|
|
+ OrderVo order10 = new OrderVo();
|
|
|
|
+ OrderVo order11 = new OrderVo();
|
|
|
|
+ if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsItem.getGoodsBizType())){
|
|
|
|
+ order00 = setOrderVo(loginUser,jsonParam,storeId,checkedGoodsList,goodsItem.getGoodsBizType());
|
|
|
|
+ order00.setOrderBizType(goodsItem.getGoodsBizType());//订单业务类型:00:保税备货, 02:保税展示补货,10:保税展示跨境,11:普通商品
|
|
|
|
+ orderInfoList.add(order00);
|
|
|
|
+ }
|
|
|
|
+ if(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsItem.getGoodsBizType())){
|
|
|
|
+ order02 = setOrderVo(loginUser,jsonParam,storeId,checkedGoodsList,goodsItem.getGoodsBizType());
|
|
|
|
+ order02.setOrderBizType(goodsItem.getGoodsBizType());
|
|
|
|
+ orderInfoList.add(order02);
|
|
|
|
+ }
|
|
|
|
+ if(Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsItem.getGoodsBizType())){
|
|
|
|
+ order10 = setOrderVo(loginUser,jsonParam,storeId,checkedGoodsList,goodsItem.getGoodsBizType());
|
|
|
|
+ order10.setOrderBizType(goodsItem.getGoodsBizType());
|
|
|
|
+ orderInfoList.add(order10);
|
|
|
|
+ }
|
|
|
|
+ if(Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsItem.getGoodsBizType())){
|
|
|
|
+ order11 = setOrderVo(loginUser,jsonParam,storeId,checkedGoodsList,goodsItem.getGoodsBizType());
|
|
|
|
+ order11.setOrderBizType(goodsItem.getGoodsBizType());
|
|
|
|
+ orderInfoList.add(order11);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ //开启事务,插入订单信息和订单商品
|
|
|
|
+ if(orderInfoList != null && orderInfoList.size() > 0) {
|
|
|
|
+ apiOrderMapper.saveBatch(orderInfoList);
|
|
|
|
+
|
|
|
|
+ for (OrderVo orderInfo : orderInfoList) {
|
|
|
|
+ if (null == orderInfo.getId()) {
|
|
|
|
+ throw new RRException("订单提交失败");
|
|
|
|
+ // resultObj.put("errno", 1);
|
|
|
|
+ // resultObj.put("errmsg", "订单提交失败");
|
|
|
|
+ // return resultObj;
|
|
|
|
+ }
|
|
|
|
+ //新增订单详情
|
|
|
|
+ for (CartVo goodsItem : checkedGoodsList) {
|
|
|
|
+ //统计商品总价
|
|
|
|
+ List<OrderGoodsVo> orderGoodsData = new ArrayList();
|
|
|
|
+ if (orderInfo.getOrderBizType().equalsIgnoreCase(goodsItem.getGoodsBizType())) {
|
|
|
|
+ OrderGoodsVo orderGoodsVo = setOrderGoodsVo(orderInfo, goodsItem);
|
|
|
|
+ apiOrderGoodsMapper.save(orderGoodsVo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ for (ProductVo productVo : productVos) {
|
|
|
|
+ apiProductMapper.updateStockNum(productVo);
|
|
|
|
+ }
|
|
|
|
+ // formIds保存
|
|
|
|
+ formIdsService.save(loginUser.getId(), formId, 1);
|
|
|
|
+
|
|
|
|
+ //清空已购买的商品
|
|
|
|
+ apiCartMapper.deleteByCart(loginUser.getId(), storeId, 1);
|
|
|
|
+ resultObj.put("errno", 0);
|
|
|
|
+ resultObj.put("errmsg", "订单提交成功");
|
|
|
|
+ //
|
|
|
|
+ Map orderInfoMap = new HashMap();
|
|
|
|
+ orderInfoMap.put("orderInfo", orderInfoList);
|
|
|
|
+ resultObj.put("data", orderInfoMap);
|
|
|
|
+
|
|
|
|
+ // 优惠券标记已用
|
|
|
|
+ for (OrderVo orderInfo : orderInfoList) {
|
|
|
|
+ if (null != userCouponId && 0 != userCouponId) {
|
|
|
|
+ UserCouponVo userCouponVo = apiUserCouponMapper.queryObject(userCouponId);
|
|
|
|
+ if (null != userCouponVo && (null == userCouponVo.getOrder_id() || 0 == userCouponVo.getOrder_id())) {
|
|
|
|
+ userCouponVo.setUsed_time(new Date());
|
|
|
|
+ userCouponVo.setOrder_id(orderInfo.getId());
|
|
|
|
+ apiUserCouponMapper.update(userCouponVo);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return resultObj;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 设置订单数据
|
|
|
|
+ * @param loginUser
|
|
|
|
+ * @param jsonParam
|
|
|
|
+ * @param storeId
|
|
|
|
+ * @param checkedGoodsList
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ public OrderVo setOrderVo(UserVo loginUser,JSONObject jsonParam,Long storeId,List<CartVo> checkedGoodsList,String orderBizType){
|
|
|
|
+ Integer userCouponId = jsonParam.getInteger("userCouponId");
|
|
|
|
+ String postscript = jsonParam.getString("postscript");
|
|
|
|
+ Long fullCutCouponId = jsonParam.getLong("fullCutCouponId");
|
|
|
|
+ BigDecimal freightPrice = new BigDecimal(10.00);
|
|
|
|
+ AddressVo addressVo = jsonParam.getObject("checkedAddress", AddressVo.class);
|
|
|
|
+ Date delivery_date = jsonParam.getDate("delivery_date");
|
|
|
|
+ if (null == delivery_date) {
|
|
|
|
+ delivery_date = new Date();
|
|
|
|
+ }
|
|
|
|
+ String delivery_remark = jsonParam.getString("delivery_remark");
|
|
|
|
+ if (StringUtils.isNullOrEmpty(delivery_remark)) {
|
|
|
|
+ delivery_remark = "尽快送达";
|
|
|
|
+ }
|
|
|
|
+
|
|
//统计商品总价
|
|
//统计商品总价
|
|
BigDecimal goodsTotalPrice = new BigDecimal(0.00);
|
|
BigDecimal goodsTotalPrice = new BigDecimal(0.00);
|
|
for (CartVo cartItem : checkedGoodsList) {
|
|
for (CartVo cartItem : checkedGoodsList) {
|
|
- goodsTotalPrice = goodsTotalPrice.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
|
|
|
|
|
|
+ if(orderBizType.equalsIgnoreCase(cartItem.getGoodsBizType())){
|
|
|
|
+ goodsTotalPrice = goodsTotalPrice.add(cartItem.getRetail_price().multiply(new BigDecimal(cartItem.getNumber())));
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
//获取订单使用的优惠券
|
|
//获取订单使用的优惠券
|
|
@@ -197,7 +293,7 @@ public class ApiOrderService {
|
|
BigDecimal orderTotalPrice = goodsTotalPrice.add(freightPrice); //订单的总价
|
|
BigDecimal orderTotalPrice = goodsTotalPrice.add(freightPrice); //订单的总价
|
|
|
|
|
|
BigDecimal actualPrice = orderTotalPrice.subtract(fullCutCouponDec).subtract(couponPrice); //减去其它支付的金额后,要实际支付的金额
|
|
BigDecimal actualPrice = orderTotalPrice.subtract(fullCutCouponDec).subtract(couponPrice); //减去其它支付的金额后,要实际支付的金额
|
|
- //
|
|
|
|
|
|
+
|
|
OrderVo orderInfo = new OrderVo();
|
|
OrderVo orderInfo = new OrderVo();
|
|
orderInfo.setOrder_sn(CommonUtil.generateOrderNumber());
|
|
orderInfo.setOrder_sn(CommonUtil.generateOrderNumber());
|
|
orderInfo.setUser_id(loginUser.getId());
|
|
orderInfo.setUser_id(loginUser.getId());
|
|
@@ -231,67 +327,36 @@ public class ApiOrderService {
|
|
orderInfo.setShipping_status(0);
|
|
orderInfo.setShipping_status(0);
|
|
orderInfo.setPay_status(0);
|
|
orderInfo.setPay_status(0);
|
|
orderInfo.setShipping_id(0L);
|
|
orderInfo.setShipping_id(0L);
|
|
- orderInfo.setShipping_fee(new
|
|
|
|
-
|
|
|
|
- BigDecimal(0));
|
|
|
|
|
|
+ orderInfo.setShipping_fee(new BigDecimal(0));
|
|
orderInfo.setIntegral(0);
|
|
orderInfo.setIntegral(0);
|
|
orderInfo.setCoupon_name(couponName);
|
|
orderInfo.setCoupon_name(couponName);
|
|
- orderInfo.setIntegral_money(new
|
|
|
|
|
|
+ orderInfo.setIntegral_money(new BigDecimal(0));
|
|
|
|
+ orderInfo.setCreateTime(new Date());
|
|
|
|
+ orderInfo.setModTime(new Date());
|
|
|
|
+ orderInfo.setPayMobile(loginUser.getMobile());
|
|
|
|
+ orderInfo.setPayTransactionId("");
|
|
|
|
+ return orderInfo;
|
|
|
|
+ }
|
|
|
|
|
|
- BigDecimal(0));
|
|
|
|
- //开启事务,插入订单信息和订单商品
|
|
|
|
- apiOrderMapper.save(orderInfo);
|
|
|
|
- if (null == orderInfo.getId()) {
|
|
|
|
- throw new RRException("订单提交失败");
|
|
|
|
-// resultObj.put("errno", 1);
|
|
|
|
-// resultObj.put("errmsg", "订单提交失败");
|
|
|
|
-// return resultObj;
|
|
|
|
- }
|
|
|
|
- for (ProductVo productVo : productVos) {
|
|
|
|
- apiProductMapper.updateStockNum(productVo);
|
|
|
|
- }
|
|
|
|
- // formIds保存
|
|
|
|
- formIdsService.save(orderInfo.getUser_id(), formId, 1);
|
|
|
|
- //统计商品总价
|
|
|
|
- List<OrderGoodsVo> orderGoodsData = new ArrayList();
|
|
|
|
- for (CartVo goodsItem : checkedGoodsList) {
|
|
|
|
- OrderGoodsVo orderGoodsVo = new OrderGoodsVo();
|
|
|
|
- orderGoodsVo.setOrder_id(orderInfo.getId());
|
|
|
|
- orderGoodsVo.setGoods_id(goodsItem.getGoods_id());
|
|
|
|
- orderGoodsVo.setGoods_sn(goodsItem.getGoods_sn());
|
|
|
|
- orderGoodsVo.setProduct_id(goodsItem.getProduct_id());
|
|
|
|
- orderGoodsVo.setGoods_name(goodsItem.getGoods_name());
|
|
|
|
- orderGoodsVo.setList_pic_url(goodsItem.getList_pic_url());
|
|
|
|
- orderGoodsVo.setMarket_price(goodsItem.getMarket_price());
|
|
|
|
- orderGoodsVo.setRetail_price(goodsItem.getRetail_price());
|
|
|
|
- orderGoodsVo.setNumber(goodsItem.getNumber());
|
|
|
|
- orderGoodsVo.setGoods_specification_name_value(goodsItem.getGoods_specification_name_value());
|
|
|
|
- orderGoodsVo.setGoods_specification_ids(goodsItem.getGoods_specification_ids());
|
|
|
|
- orderGoodsData.add(orderGoodsVo);
|
|
|
|
- apiOrderGoodsMapper.save(orderGoodsVo);
|
|
|
|
- }
|
|
|
|
|
|
|
|
- //清空已购买的商品
|
|
|
|
- apiCartMapper.deleteByCart(loginUser.getId(), storeId, 1);
|
|
|
|
- resultObj.put("errno", 0);
|
|
|
|
- resultObj.put("errmsg", "订单提交成功");
|
|
|
|
- //
|
|
|
|
- Map orderInfoMap = new HashMap();
|
|
|
|
- orderInfoMap.put("orderInfo", orderInfo);
|
|
|
|
- //
|
|
|
|
- resultObj.put("data", orderInfoMap);
|
|
|
|
- // 优惠券标记已用
|
|
|
|
- if (null != userCouponId && 0 != userCouponId) {
|
|
|
|
- UserCouponVo userCouponVo = apiUserCouponMapper.queryObject(userCouponId);
|
|
|
|
- if (null != userCouponVo && (null == userCouponVo.getOrder_id() || 0 == userCouponVo.getOrder_id())) {
|
|
|
|
- userCouponVo.setUsed_time(new Date());
|
|
|
|
- userCouponVo.setOrder_id(orderInfo.getId());
|
|
|
|
- apiUserCouponMapper.update(userCouponVo);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return resultObj;
|
|
|
|
|
|
+ public OrderGoodsVo setOrderGoodsVo(OrderVo orderInfo,CartVo goodsItem){
|
|
|
|
+ OrderGoodsVo orderGoodsVo = new OrderGoodsVo();
|
|
|
|
+ orderGoodsVo.setOrder_id(orderInfo.getId());
|
|
|
|
+ orderGoodsVo.setGoods_id(goodsItem.getGoods_id());
|
|
|
|
+ orderGoodsVo.setGoods_sn(goodsItem.getGoods_sn());
|
|
|
|
+ orderGoodsVo.setProduct_id(goodsItem.getProduct_id());
|
|
|
|
+ orderGoodsVo.setGoods_name(goodsItem.getGoods_name());
|
|
|
|
+ orderGoodsVo.setList_pic_url(goodsItem.getList_pic_url());
|
|
|
|
+ orderGoodsVo.setMarket_price(goodsItem.getMarket_price());
|
|
|
|
+ orderGoodsVo.setRetail_price(goodsItem.getRetail_price());
|
|
|
|
+ orderGoodsVo.setNumber(goodsItem.getNumber());
|
|
|
|
+ orderGoodsVo.setGoods_specification_name_value(goodsItem.getGoods_specification_name_value());
|
|
|
|
+ orderGoodsVo.setGoods_specification_ids(goodsItem.getGoods_specification_ids());
|
|
|
|
+ orderGoodsVo.setOrderBizType(goodsItem.getGoodsBizType());
|
|
|
|
+ orderGoodsVo.setCreateTime(new Date());
|
|
|
|
+ orderGoodsVo.setModTime(new Date());
|
|
|
|
+ return orderGoodsVo;
|
|
}
|
|
}
|
|
-
|
|
|
|
/**
|
|
/**
|
|
* 支付成功通知
|
|
* 支付成功通知
|
|
*/
|
|
*/
|