parent
864830e1be
commit
51accb2d04
@ -0,0 +1,19 @@ |
||||
package com.hai.service; |
||||
|
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.entity.HighOrder; |
||||
|
||||
/** |
||||
* 千猪订单 |
||||
*/ |
||||
public interface HighQzOrderService { |
||||
|
||||
/** |
||||
* 组装千猪订单 |
||||
* @param orderNo |
||||
* @param orderType |
||||
* @return |
||||
*/ |
||||
HighOrder assemblyQzOrder(String orderNo,String orderType) throws Exception; |
||||
|
||||
} |
@ -0,0 +1,111 @@ |
||||
package com.hai.service.impl; |
||||
|
||||
import com.alibaba.fastjson.JSONArray; |
||||
import com.alibaba.fastjson.JSONObject; |
||||
import com.hai.common.exception.ErrorCode; |
||||
import com.hai.common.exception.ErrorHelp; |
||||
import com.hai.common.exception.SysCode; |
||||
import com.hai.config.QianZhuConfig; |
||||
import com.hai.entity.HighChildOrder; |
||||
import com.hai.entity.HighOrder; |
||||
import com.hai.entity.HighUser; |
||||
import com.hai.service.HighOrderService; |
||||
import com.hai.service.HighQzOrderService; |
||||
import com.hai.service.HighUserService; |
||||
import org.springframework.stereotype.Service; |
||||
|
||||
import javax.annotation.Resource; |
||||
import java.math.BigDecimal; |
||||
import java.util.ArrayList; |
||||
|
||||
@Service("highQzOrderService") |
||||
public class HighQzOrderServiceImpl implements HighQzOrderService { |
||||
|
||||
@Resource |
||||
private HighUserService highUserService; |
||||
|
||||
@Resource |
||||
private HighOrderService highOrderService; |
||||
|
||||
@Override |
||||
public HighOrder assemblyQzOrder(String orderNo,String orderType) throws Exception { |
||||
HighOrder highOrder = new HighOrder(); |
||||
JSONObject orderDetail = null; |
||||
if (orderType.equals("KFC")) { |
||||
orderDetail = QianZhuConfig.getKfcOrderByOrderNo(orderNo); |
||||
} |
||||
|
||||
if (orderType.equals("CINEMA")) { |
||||
orderDetail = QianZhuConfig.getCinemaOrderByOrderNo(orderNo); |
||||
} |
||||
|
||||
if (orderDetail != null && orderDetail.getBoolean("success") == true) { |
||||
JSONObject data = orderDetail.getJSONObject("data"); |
||||
|
||||
HighOrder order = highOrderService.getOrderByOrderNo(orderNo); |
||||
if (order != null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单已存在"); |
||||
} |
||||
HighUser highUser = highUserService.findByUnionId(data.getString("platformUniqueId")); |
||||
if (highUser == null) { |
||||
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "未找到用户"); |
||||
} |
||||
highOrder.setHighChildOrderList(new ArrayList<>()); |
||||
highOrder.setOrderNo(orderNo); |
||||
highOrder.setMemId(highUser.getId()); |
||||
highOrder.setMemName(data.getString("userName")); |
||||
highOrder.setMemPhone(data.getString("userMobile")); |
||||
highOrder.setPayModel(2); |
||||
highOrder.setPayType(2); |
||||
highOrder.setPayPrice(data.getBigDecimal("totalPrice")); |
||||
highOrder.setTotalPrice(data.getBigDecimal("totalPrice")); |
||||
highOrder.setDeductionPrice(new BigDecimal("0")); |
||||
highOrder.setOrderStatus(1); |
||||
highOrder.setCreateTime(data.getDate("createTime")); |
||||
highOrder.setRemarks(data.getString("userRemark")); |
||||
|
||||
HighChildOrder highChildOrder; |
||||
if (orderType.equals("KFC")) { |
||||
// 商品信息
|
||||
JSONObject kfcPlaceOrder = data.getJSONObject("kfcPlaceOrder"); |
||||
JSONArray items = kfcPlaceOrder.getJSONArray("items"); |
||||
for (Object goodsObject : items) { |
||||
JSONObject object = JSONObject.parseObject(JSONObject.toJSONString(goodsObject), JSONObject.class); |
||||
highChildOrder = new HighChildOrder(); |
||||
highChildOrder.setMemId(highOrder.getMemId()); |
||||
highChildOrder.setGoodsType(4); |
||||
highChildOrder.setGoodsName(object.getString("productName")); |
||||
highChildOrder.setGoodsImg(object.getString("imageUrl")); |
||||
highChildOrder.setGoodsSpecName("默认"); |
||||
highChildOrder.setGoodsPrice(new BigDecimal(object.getString("originPrice"))); |
||||
highChildOrder.setGoodsActualPrice(new BigDecimal(object.getString("price"))); |
||||
highChildOrder.setSaleCount(object.getInteger("quantity")); |
||||
highChildOrder.setTotalPrice(new BigDecimal(highChildOrder.getSaleCount().toString()).multiply(highChildOrder.getGoodsPrice())); |
||||
highChildOrder.setGiveawayType(false); |
||||
highChildOrder.setChildOrdeStatus(1); |
||||
highChildOrder.setPraiseStatus(0); |
||||
highOrder.getHighChildOrderList().add(highChildOrder); |
||||
} |
||||
} |
||||
|
||||
if (orderType.equals("CINEMA")) { |
||||
highChildOrder = new HighChildOrder(); |
||||
highChildOrder.setMemId(highOrder.getMemId()); |
||||
highChildOrder.setGoodsType(5); |
||||
highChildOrder.setGoodsName(data.getString("cinemaName")); |
||||
highChildOrder.setGoodsImg(data.getString("pic")); |
||||
highChildOrder.setGoodsSpecName("默认"); |
||||
highChildOrder.setGoodsPrice(new BigDecimal(data.getString("unitPrice"))); |
||||
highChildOrder.setSaleCount(data.getInteger("seatsCount")); |
||||
highChildOrder.setTotalPrice(new BigDecimal(highChildOrder.getSaleCount().toString()).multiply(highChildOrder.getGoodsPrice())); |
||||
highChildOrder.setGoodsActualPrice(highChildOrder.getTotalPrice()); |
||||
highChildOrder.setGiveawayType(false); |
||||
highChildOrder.setChildOrdeStatus(1); |
||||
highChildOrder.setPraiseStatus(0); |
||||
highOrder.getHighChildOrderList().add(highChildOrder); |
||||
} |
||||
} |
||||
highOrderService.insertOrder(highOrder); |
||||
return highOrder; |
||||
} |
||||
} |
Loading…
Reference in new issue