嗨森逛服务
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
hai-server/hai-service/src/main/java/com/hai/service/impl/HighOrderServiceImpl.java

1529 lines
66 KiB

package com.hai.service.impl;
import com.alibaba.fastjson.JSON;
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.common.pay.util.XmlUtil;
import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.security.AESEncodeUtil;
import com.hai.common.utils.DateUtil;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.IDGenerator;
import com.hai.common.utils.WxUtils;
import com.hai.config.*;
import com.hai.dao.*;
import com.hai.entity.*;
import com.hai.entity.OutRechargeOrder;
import com.hai.enum_type.*;
import com.hai.model.*;
import com.hai.msg.entity.MsgTopic;
import com.hai.order.type.OrderPayType;
import com.hai.order.type.OrderProductType;
import com.hai.order.utils.OrderUtil;
import com.hai.service.*;
import com.hai.service.pay.impl.GoodsOrderServiceImpl;
import org.apache.commons.collections4.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.util.EntityUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Isolation;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.*;
/**
* @Auther: 胡锐
* @Description:
* @Date: 2021/3/26 23:06
*/
@Service("highOrderService")
public class HighOrderServiceImpl implements HighOrderService {
@Resource
private HighOrderMapper highOrderMapper;
@Resource
private HighDeviceService deviceService;
@Resource
private BsRequestRecordService bsRequestRecordService;
@Resource
private HighUserPayPasswordService highUserPayPasswordService;
@Resource
private ThirdProductConfig thirdProductConfig;
@Resource
private HighOrderMapperExt highOrderMapperExt;
@Resource
private HighUserCardService highUserCardService;
@Resource
private HighChildOrderMapper highChildOrderMapper;
@Resource
private HighCouponCodeService highCouponCodeService;
@Resource
private HighCouponService highCouponService;
@Resource
private HighGasOrderPushMapper highGasOrderPushMapper;
@Resource
private HighCouponHandselService highCouponHandselService;
@Resource
private HighCouponCodeOtherMapper highCouponCodeOtherMapper;
@Resource
private HighUserService highUserService;
@Resource
private HighUserCouponMapper highUserCouponMapper;
@Resource
private HighDiscountUserRelMapper highDiscountUserRelMapper;
@Resource
private HighDiscountUserRelService highDiscountUserRelService;
@Resource
private HighDiscountAgentCodeService highDiscountAgentCodeService;
@Resource
private HighDiscountPackageService discountPackageService;
@Resource
private HighDiscountPackageRecordService discountPackageRecordService;
@Resource
private HighMerchantStoreService highMerchantStoreService;
@Resource
private HighOrderService highOrderService;
@Resource
private HighOrderPreService highOrderPreService;
@Resource
private HighActivityInfoService highActivityInfoService;
@Resource
private HighActivityUserLotteryNumService highActivityUserLotteryNumService;
@Resource
private HighDiscountPackageActualService discountPackageActualService;
@Resource
private HighDiscountPackageDiscountActualService discountPackageDiscountActualService;
@Resource
private HuiLianTongConfig huiLianTongConfig;
@Resource
private HighOilCardService oilCardService;
@Resource
private HighFleetOilCardService fleetOilCardService;
@Resource
private RedisTemplate redisTemplate;
@Resource
private GoodsOrderServiceImpl goodsOrderService;
@Resource
private MqttProviderConfig mqttProviderConfig;
@Resource
private BaiduVoiceService baiduVoiceService;
@Resource
private ApiMerchantsService apiMerchantsService;
@Resource
private ApiAmountRecordService apiAmountRecordService;
@Resource
private ApiOrderRecordService apiOrderRecordService;
@Resource
private ApiMemberProductService apiMemberProductService;
@Resource
private ShellGroupService shellGroupService;
@Resource
private JinZhuJiaYouService jinZhuJiaYouService;
@Override
@Transactional(
isolation = Isolation.SERIALIZABLE,
propagation = Propagation.REQUIRES_NEW)
public void insertOrder(HighOrder highOrder) throws Exception {
highOrderMapper.insert(highOrder);
// 使用优惠券
if (highOrder.getMemDiscountId() != null) {
HighDiscountUserRel discountUserRel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId());
discountUserRel.setUseTime(new Date()); // 使用时间
discountUserRel.setStatus(2); //状态 0:已过期 1:未使用 2:已使用
highDiscountUserRelService.updateDiscountUserRel(discountUserRel);
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(discountUserRel.getDiscountAgentCodeId());
code.setStatus(3);
highDiscountAgentCodeService.updateCode(code);
}
for (int i = 0; i < highOrder.getHighChildOrderList().size(); i++) {
HighChildOrder childOrder = highOrder.getHighChildOrderList().get(i);
childOrder.setOrderId(highOrder.getId());
highChildOrderMapper.insert(childOrder);
// 商品类型 1:卡卷
if (childOrder.getGoodsType() == 1) {
// 查询卡券
HighCoupon couponDetail = highCouponService.getCouponDetail(childOrder.getGoodsId());
if (couponDetail.getCouponSource() != 4 && couponDetail.getCouponSource() != 5) {
// 查询待销售
List<HighCouponCode> list = highCouponCodeService.getNoSaleCode(childOrder.getGoodsId());
if (list == null || list.size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, "");
}
list.get(0).setChildOrderId(childOrder.getId());
list.get(0).setStatus(99); // 状态:1.待销售 2.未使用 3.已使用 99.预支付
highCouponCodeService.updateCouponCode(list.get(0));
childOrder.setExt1(list.get(0).getExt1());
highChildOrderMapper.updateByPrimaryKey(childOrder);
}
if (couponDetail.getCouponSource().equals(4)) {
String code = String.valueOf(new Random().nextInt(899999) + 100000);
// 下单请求
JSONObject jsonObject = HuiLianTongConfig.recharge(highOrder.getOrderNo() + "_"+code,
childOrder.getSaleCount(),
couponDetail.getCouponKey(),
highOrder.getMemPhone());
System.out.println(jsonObject);
if (!jsonObject.getString("respCode").equals("0000")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "下单失败");
}
JSONObject response = HuiLianTongUnionCardConfig.resolveResponse(jsonObject.getString("data"));
if (!response.getString("respCode").equals("0000")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, response.getString("msg"));
}
childOrder.setExt2(response.getJSONObject("data").getString("rechargeOrderId"));
highChildOrderMapper.updateByPrimaryKey(childOrder);
}
/* if (!childOrder.getGiveawayType()) {
// 查看是否需要赠送卡卷
List<HighCouponHandselModel> handselListByCoupon = highCouponHandselService.getHandselListByCoupon(childOrder.getGoodsId());
if (handselListByCoupon != null && handselListByCoupon.size() > 0) {
for (HighCouponHandsel highCouponHandsel : handselListByCoupon) {
// 查询卡卷信息
HighCoupon coupon = highCouponService.getCouponById(highCouponHandsel.getHandselCouponId());
if (coupon == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_COUPON, "");
}
// 查询赠送卡卷 是否有库存,没有就不赠送
if (highCouponCodeService.getStockCountByCoupon(coupon.getId()) > 0) {
HighChildOrder highChildOrder = new HighChildOrder();
highChildOrder.setOrderId(highOrder.getId());
highChildOrder.setGoodsType(1);
highChildOrder.setGoodsId(coupon.getId());
highChildOrder.setGoodsName(coupon.getCouponName());
highChildOrder.setGoodsImg(coupon.getCouponImg());
highChildOrder.setGoodsSpecName("默认");
highChildOrder.setGoodsPrice(new BigDecimal(0));
highChildOrder.setGoodsActualPrice(new BigDecimal("0"));
highChildOrder.setSaleCount(1);
highChildOrder.setTotalPrice(new BigDecimal(0));
highChildOrder.setGiveawayType(true); // 是否是赠品 0:否 1:是
highChildOrder.setChildOrderStatus(1); // 1 待支付 2 已支付 3.已完成 4. 已退款 5.已取消
highChildOrder.setPraiseStatus(0);
highOrder.getHighChildOrderList().add(highChildOrder);
}
}
}
}*/
}
if (childOrder.getGoodsType() == 3) {
// 加油站详情
HighMerchantStore store = highMerchantStoreService.getDetailById(childOrder.getGoodsId());
if (store == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_FOUND_ORDER, "");
}
if (store.getSourceType().equals(MerchantStoreSourceType.type4.getNumber())) {
/*// 查询金猪油品数据
JinZhuJiaYouOilNo jzOilNo = JinZhuJiaYouOilNo.getDataByOilNo(Integer.valueOf(childOrder.getGasOilNo()));
if (jzOilNo == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "暂时无法提交订单,未知的油品");
}
// 创建金猪订单
JSONObject jzOrderObject = jinZhuJiaYouService.createOrder(highOrder.getOrderNo(),
highOrder.getTotalPrice(),
store.getStoreKey(),
jzOilNo.getOilNoCode(),
childOrder.getGasGunNo(),
highOrder.getMemPhone()
);
childOrder.setGasOrderNo(jzOrderObject.getJSONObject("data").getString("systemOrderNo"));
childOrder.setGasPriceChannelPay(jzOrderObject.getJSONObject("data").getBigDecimal("paymentAmount"));
highChildOrderMapper.updateByPrimaryKey(childOrder);*/
}
}
if (childOrder.getGoodsType() == 7) {
// 查询库存
List<HighDiscountPackageActual> list = discountPackageActualService.getListByPackageId(childOrder.getGoodsId().intValue(), 1);
if (list == null || list.size() == 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COUPON_STOCK_INSUFFICIENT, "");
}
list.get(0).setUserId(highOrder.getMemId().intValue());
list.get(0).setChildOrderId(childOrder.getId());
list.get(0).setStatus(2); // 状态: 1: 待分配 2:预分配(售卖)3:已分配
discountPackageActualService.updateHighDiscountPackageActual(list.get(0));
}
}
// 积分抵扣,卡券除外
if (!highOrder.getHighChildOrderList().get(0).getGoodsType().equals(1) && highOrder.getPayGold() != null) {
// 积分转换成金额
BigDecimal goldPrice = new BigDecimal(highOrder.getPayGold().toString()).divide(new BigDecimal(100));
// 积分金额大于应付金额
if (goldPrice.compareTo(highOrder.getPayablePrice()) == 1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "支付的积分金额大于支付金额");
}
// 应付金额 减去 积分抵扣金额 = 支付金额
highOrder.setPayPrice(highOrder.getPayablePrice().subtract(goldPrice));
// 积分金额小于应付金额
if (goldPrice.compareTo(highOrder.getPayablePrice()) == -1) {
updateOrderDetail(highOrder);
// 扣除用户积分
highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayGold(), 2, 2, highOrder.getId(),
"抵扣积分订单:" + highOrder.getOrderNo() + ",使用积分:" + highOrder.getPayGold() , highOrder.getOrderNo());
}
// 积分金额等于应付金额
/* if (goldPrice.compareTo(highOrder.getPayablePrice()) == 0) {
if (StringUtils.isBlank(highOrder.getPayPwd())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, "");
}
// 查询用户密码
HighUserPayPassword userPayPwd = highUserPayPasswordService.getDetailByUser(highOrder.getMemId());
if (userPayPwd == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, "");
}
// 校验支付密码是否正确
if (!userPayPwd.getPassword().equals(AESEncodeUtil.aesEncrypt(highOrder.getPayPwd()))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, "");
}
// 扣除用户积分
highUserService.goldHandle(highOrder.getMemId(), highOrder.getPayGold(), 2, 2, highOrder.getId(),
"抵扣积分订单:" + highOrder.getOrderNo() + ",使用积分:" + highOrder.getPayGold());
highOrder.setOrderStatus(OrderStatusEnum.type3.getType());
highOrder.setPayRealPrice(highOrder.getPayPrice());
highOrder.setPayTime(new Date());
for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) {
childOrder.setChildOrderStatus(3);
}
updateOrder(highOrder);
// 订单完成业务处理
orderBusinessTransaction(highOrder);
}*/
}
}
@Override
public void updateChildOrder(HighChildOrder highChildOrder) {
highChildOrderMapper.updateByPrimaryKey(highChildOrder);
}
@Override
@Transactional(propagation = Propagation.REQUIRED)
public void updateOrder(HighOrder highOrder) {
highOrderMapper.updateByPrimaryKey(highOrder);
for (HighChildOrder childOrder : highOrder.getHighChildOrderList()) {
highChildOrderMapper.updateByPrimaryKey(childOrder);
}
}
@Override
public void updateOrderDetail(HighOrder highOrder) {
highOrderMapper.updateByPrimaryKey(highOrder);
}
@Override
public Integer getUndoneChildOrder(Long orderId) {
HighOrder order = getOrderById(orderId);
Integer count = 0;
for (HighChildOrder childOrder : order.getHighChildOrderList()) {
if (childOrder.getChildOrderStatus() != 3) {
count++;
}
}
return count;
}
@Override
public HighOrder getDetailById(Long orderId) {
return highOrderMapper.selectByPrimaryKey(orderId);
}
@Override
public HighChildOrder getChildOrderById(Long childOrderId) {
return highChildOrderMapper.selectByPrimaryKey(childOrderId);
}
@Override
public HighChildOrder getChildOrderByUserGoods(Long userId, Integer goodsType, Long goodsId) {
HighChildOrderExample example = new HighChildOrderExample();
example.createCriteria().andMemIdEqualTo(userId).andGoodsTypeEqualTo(goodsType).andGoodsIdEqualTo(goodsId);
List<HighChildOrder> list = highChildOrderMapper.selectByExample(example);
if (list.size() > 0) {
return list.get(0);
}
return null;
}
@Override
public List<HighChildOrder> getChildOrderByOrder(Long orderId) {
HighChildOrderExample example = new HighChildOrderExample();
example.createCriteria().andOrderIdEqualTo(orderId);
return highChildOrderMapper.selectByExample(example);
}
@Override
public List<HighChildOrder> getChildOrderList(Map<String, Object> map) {
HighChildOrderExample example = new HighChildOrderExample();
HighChildOrderExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "memId") != null) {
criteria.andOrderIdEqualTo(MapUtils.getLong(map, "memId"));
}
if (MapUtils.getLong(map, "childOrdeStatus") != null) {
criteria.andChildOrderStatusEqualTo(MapUtils.getInteger(map, "childOrdeStatus"));
}
if (MapUtils.getString(map, "childOrdeStatusList") != null) {
String[] childOrdeStatusLists = MapUtils.getString(map, "childOrdeStatusList").split(",");
List<Integer> integerList = new ArrayList<>();
for (String status : childOrdeStatusLists) {
integerList.add(Integer.parseInt(status));
}
criteria.andChildOrderStatusIn(integerList);
}
if (MapUtils.getLong(map, "goodsType") != null) {
criteria.andGoodsTypeEqualTo(MapUtils.getInteger(map, "goodsType"));
}
if (MapUtils.getLong(map, "goodsId") != null) {
criteria.andGoodsIdEqualTo(MapUtils.getLong(map, "goodsId"));
}
if (MapUtils.getLong(map, "giveawayType") != null) {
criteria.andGiveawayTypeEqualTo(MapUtils.getBoolean(map, "giveawayType"));
}
return highChildOrderMapper.selectByExample(example);
}
@Override
public HighOrder getOrderById(Long id) {
HighOrder order = highOrderMapper.selectByPrimaryKey(id);
if (order == null) {
return null;
}
order.setHighChildOrderList(getChildOrderByOrder(order.getId()));
if (order.getMemDiscountId() != null) {
// order.setHighDiscount(highDiscountUserRelService.getRelById(order.getMemDiscountId()).getHighDiscount());
}
return order;
}
@Override
public HighOrder getOrderByOrderNo(String orderNo) {
HighOrderExample example = new HighOrderExample();
example.createCriteria().andOrderNoEqualTo(orderNo);
List<HighOrder> list = highOrderMapper.selectByExample(example);
if (list != null && list.size() > 0) {
return getOrderById(list.get(0).getId());
}
return null;
}
@Override
public HighOrder getOrderByMap(Map<String, Object> map) {
HighOrderExample example = new HighOrderExample();
HighOrderExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "memId") != null) {
criteria.andMemIdEqualTo(MapUtils.getLong(map, "memId"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "status"))) {
String[] statuses = MapUtils.getString(map, "status").split(",");
List<Integer> list = new ArrayList<>();
for (String status : statuses) {
list.add(Integer.parseInt(status));
}
criteria.andOrderStatusIn(list);
}
List<HighOrder> list = highOrderMapper.selectByExample(example);
if (!list.isEmpty()) {
return list.get(0);
}
return null;
}
@Override
public List<HighOrderData> getOrderBList(Map<String, Object> map) {
return highOrderMapperExt.selectOrderDataList(map);
}
@Override
public List<HighOrder> getOrderList(Map<String, Object> map) {
HighOrderExample example = new HighOrderExample();
HighOrderExample.Criteria criteria = example.createCriteria();
if (MapUtils.getLong(map, "memId") != null) {
criteria.andMemIdEqualTo(MapUtils.getLong(map, "memId"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "status"))) {
String[] statuses = MapUtils.getString(map, "status").split(",");
List<Integer> list = new ArrayList<>();
for (String status : statuses) {
list.add(Integer.parseInt(status));
}
criteria.andOrderStatusIn(list);
}
if (MapUtils.getString(map, "orderNo") != null) {
criteria.andOrderNoEqualTo(MapUtils.getString(map, "orderNo"));
}
if (MapUtils.getString(map, "phone") != null) {
criteria.andMemPhoneEqualTo(MapUtils.getString(map, "phone"));
}
if (MapUtils.getInteger(map, "productType") != null) {
criteria.andProductTypeEqualTo(MapUtils.getInteger(map, "productType"));
}
if (StringUtils.isNotBlank(MapUtils.getString(map, "createTimeS")) && StringUtils.isNotBlank(MapUtils.getString(map, "createTimeE"))) {
criteria.andCreateTimeBetween(
DateUtil.format(MapUtils.getString(map, "createTimeS"), "yyyy-MM-dd HH:mm:ss"),
DateUtil.format(MapUtils.getString(map, "createTimeE"), "yyyy-MM-dd HH:mm:ss"));
}
example.setOrderByClause("create_time desc");
List<HighOrder> list = highOrderMapper.selectByExample(example);
if (list.size() > 0) {
for (HighOrder order : list) {
order.setHighChildOrderList(getChildOrderByOrder(order.getId()));
}
}
return list;
}
@Override
public List<HighOrderModel> getGoodsOrderModelList(Map<String, Object> map) throws Exception {
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeS") != null) {
map.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeE") != null) {
map.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return highOrderMapper.selectGoodsOrderList(map);
}
@Override
public List<HighOrderModel> getGasOrderModelList(Map<String, Object> map) throws Exception {
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeS") != null) {
map.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeE") != null) {
map.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return null;//highOrderMapper.selectGasOrderList(map);
}
@Override
public List<HighOrderModel> getKfcOrderModelList(Map<String, Object> map) throws Exception {
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeS") != null) {
map.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeE") != null) {
map.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return highOrderMapper.selectKfcOrderList(map);
}
@Override
public List<HighOrderModel> getCinemaOrderList(Map<String, Object> map) throws Exception {
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeS") != null) {
map.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeE") != null) {
map.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return highOrderMapper.selectCinemaOrderList(map);
}
@Override
public List<HighOrderModel> getMobileOrderList(Map<String, Object> map) throws Exception {
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeS") != null) {
map.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeE") != null) {
map.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return highOrderMapper.getMobileOrderList(map);
}
@Override
public List<HighOrderModel> getOrderListByIdCode(String identificationCode, Map<String, Object> map) throws Exception {
map.put("identificationCode", identificationCode);
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeS") != null) {
map.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeE") != null) {
map.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return highOrderMapper.getOrderListByIdCode(map);
}
@Override
public HighOrder getConsumeOrderByDiscountCode(Long discountCodeId) {
// 查询优惠券有没有被使用
HighDiscountUserRelExample example = new HighDiscountUserRelExample();
example.createCriteria().andDiscountAgentCodeIdEqualTo(discountCodeId).andStatusEqualTo(2);
List<HighDiscountUserRel> userRels = highDiscountUserRelMapper.selectByExample(example);
if (userRels.size() > 0) {
HighOrderExample orderExample = new HighOrderExample();
orderExample.createCriteria().andMemDiscountIdEqualTo(userRels.get(0).getId());
List<HighOrder> orderList = highOrderMapper.selectByExample(orderExample);
if (orderList.size() > 0) {
HighOrder highOrder = orderList.get(0);
highOrder.setHighChildOrderList(getChildOrderByOrder(highOrder.getId()));
return highOrder;
}
}
return null;
}
@Override
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void childOrderComplete(Long childOrderId) {
HighChildOrder childOrder = highChildOrderMapper.selectByPrimaryKey(childOrderId);
if (childOrder == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.REQ_PARAMS_ERROR, "");
}
childOrder.setChildOrderStatus(3);
highChildOrderMapper.updateByPrimaryKey(childOrder);
// 查询未完成的子订单数量
Integer count = getUndoneChildOrder(childOrder.getOrderId());
if (count == 0) {
HighOrder order = getOrderById(childOrder.getOrderId());
order.setOrderStatus(3);
order.setFinishTime(new Date());
highOrderMapper.updateByPrimaryKey(order);
}
}
@Override
public Long countOrderByUserId(Long memId, Integer status) {
HighOrderExample example = new HighOrderExample();
HighOrderExample.Criteria criteria = example.createCriteria();
criteria.andMemIdEqualTo(memId);
criteria.andOrderStatusEqualTo(status);
return highOrderMapper.countByExample(example);
}
@Override
public Integer countUnusedDiscountByUserId(Long userId, Integer status) {
HighDiscountUserRelExample example = new HighDiscountUserRelExample();
HighDiscountUserRelExample.Criteria criteria = example.createCriteria();
if (userId != null) {
criteria.andUserIdEqualTo(userId);
}
if (status != null) {
criteria.andStatusEqualTo(status);
}
example.setOrderByClause("create_time desc");
return highDiscountUserRelMapper.selectByExample(example).size();
}
@Override
public List<HighOrder> getTest() {
return highOrderMapperExt.selectTest();
}
@Override
public List<HighOrderModel> selectDiscountPackageOrderList(Map<String, Object> map) throws Exception {
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeS") != null) {
map.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "payTimeE") != null) {
map.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return highOrderMapper.selectDiscountPackageOrderList(map);
}
@Override
public OrderCountModel orderByIndex(Integer code) {
return highOrderMapper.orderByIndex(code);
}
@Override
public OrderCountModel HLTOrderByIndex(Integer code) {
return highOrderMapper.HLTOrderByIndex(code);
}
@Override
public List<HighOrderModel> HLTOrderByList(Integer code) throws Exception {
Map<String, Object> map = new HashMap<>();
map.put("identificationCode", code);
map.put("orderStatus", "2,3");
map.put("payType", "1,2,3,5");
return highOrderMapper.selectOrderList(map);
}
@Override
public BigDecimal orderPriceTotal(Map<String, Object> map) {
if (highOrderMapper.orderPriceTotal(map) == null) {
return new BigDecimal(0);
}
return highOrderMapper.orderPriceTotal(map);
}
@Override
public BigDecimal rechargePriceTotal(Map<String, Object> map) {
if (highOrderMapper.rechargePriceTotal(map) == null) {
return new BigDecimal(0);
}
return highOrderMapper.rechargePriceTotal(map);
}
@Override
public Long orderPriceCount(Map<String, Object> map) {
return highOrderMapper.orderPriceCount(map);
}
@Override
public Long rechargePriceCount(Map<String, Object> map) {
return highOrderMapper.rechargePriceCount(map);
}
@Override
public List<OrderSumModel> getOrderSumOrderByDate() {
return highOrderMapper.getOrderSumOrderByDate();
}
@Override
public List<OrderSumModel> getOrderSumRechargeByDate() {
return highOrderMapper.getOrderSumRechargeByDate();
}
@Override
public List<DateCountModel> getDateCountByUser() {
return highOrderMapper.getDateCountByUser();
}
@Override
public List<DateCountModel> getDateCountByOrder() {
return highOrderMapper.getDateCountByOrder();
}
@Override
public List<DateCountModel> getDateCountByRecharge() {
return highOrderMapper.getDateCountByRecharge();
}
@Override
public TyOrderCountModel TyOrderStatistics(Map<String, Object> map) throws Exception {
if (MapUtils.getLong(map, "createTimeS") != null) {
map.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(map, "createTimeE") != null) {
map.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(map, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
TyOrderCountModel tyOrderCountModel = new TyOrderCountModel();
if (highOrderMapper.TyOrderCount(map) != null) {
tyOrderCountModel = highOrderMapper.TyOrderCount(map);
tyOrderCountModel.setOrderNum(highOrderMapper.TyOrderNum(map));
}
Integer[] priceArr = {100, 200, 300, 400, 20000};
List<TyOrderGorpModel> priceList = new ArrayList<>();
for (Integer s : priceArr) {
TyOrderGorpModel tyOrderGorpModel = new TyOrderGorpModel();
map.put("totalPrice", s);
tyOrderGorpModel.setName(priceName(s));
tyOrderGorpModel.setValue(highOrderMapper.TyOrderNumByPrice(map));
priceList.add(tyOrderGorpModel);
}
priceList.get(1).setValue(priceList.get(1).getValue() - priceList.get(0).getValue());
priceList.get(2).setValue(priceList.get(2).getValue() - priceList.get(1).getValue() - priceList.get(0).getValue());
priceList.get(3).setValue(priceList.get(3).getValue() - priceList.get(2).getValue() - priceList.get(1).getValue() - priceList.get(0).getValue());
priceList.get(4).setValue(priceList.get(4).getValue() - priceList.get(3).getValue() - priceList.get(2).getValue() - priceList.get(1).getValue() - priceList.get(0).getValue());
tyOrderCountModel.setPriceGorp(priceList);
tyOrderCountModel.setPayTypeGorp(highOrderMapper.TyOrderNumGroupByPayType(map));
tyOrderCountModel.setGasOilNoGorp(highOrderMapper.TyOrderNumGroupByGasOilNo(map));
return tyOrderCountModel;
}
@Override
public Map<String, Object> getGasTheDayOrderCount(Long storeId, String status) {
return highOrderMapperExt.selectGasTheDayOrderCount(storeId, status);
}
@Override
public Map<String, Object> getGasStaffTheDayOrderCount(Long gasStaffId, String status) {
return highOrderMapperExt.selectGasStaffTheDayOrderCount(gasStaffId,status);
}
@Override
public Map<String, Object> getGasHistoryOrderCount(Long storeId, String status) {
return highOrderMapperExt.selectGasHistoryOrderCount(storeId, status);
}
@Override
public Map<String, Object> getGasStaffHistoryOrderCount(Long gasStaffId, String status) {
return highOrderMapperExt.selectGasStaffHistoryOrderCount(gasStaffId,status);
}
@Override
public Map<String, Object> countGasOrder(Map<String, Object> param) throws Exception {
if (MapUtils.getLong(param, "createTimeS") != null) {
param.put("createTimeS", DateUtil.date2String(new Date(MapUtils.getLong(param, "createTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(param, "createTimeE") != null) {
param.put("createTimeE", DateUtil.date2String(new Date(MapUtils.getLong(param, "createTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(param, "payTimeS") != null) {
param.put("payTimeS", DateUtil.date2String(new Date(MapUtils.getLong(param, "payTimeS")), "yyyy-MM-dd HH:mm:ss"));
}
if (MapUtils.getLong(param, "payTimeE") != null) {
param.put("payTimeE", DateUtil.date2String(new Date(MapUtils.getLong(param, "payTimeE")), "yyyy-MM-dd HH:mm:ss"));
}
return highOrderMapperExt.countGasStoreOrder(param);
}
@Override
public Map<String, Object> hltCardNoTopUpStatistic() {
return highOrderMapperExt.HltCardNoTopUpStatistic();
}
@Override
public GasOrderModel getGasOrderDetail(String orderNo) {
Map<String, Object> param = new HashMap<>();
param.put("orderNo", orderNo);
/*List<GasOrderModel> list = highOrderMapperExt.selectGasOrderList(param);
if (list.size() > 0) {
return list.get(0);
}*/
return null;
}
@Override
public void printGasOrder(Long gasId, HighGasOrder order, boolean makeUp) {
if (order == null) {
return;
}
// 查询油站云打印设备
List<HighDevice> deviceList = deviceService.getDeviceListByStoreId(gasId);
for (HighDevice device : deviceList) {
Map<String, Object> receiptMap = new HashMap<>();
receiptMap.put("receiptTop", device.getReceiptTop());
receiptMap.put("receiptSource", device.getReceiptSource());
receiptMap.put("receiptBottom", device.getReceiptBottom());
if (device.getType().equals(DeviceTypeEnum.type1.getType())) {
new Thread(() -> {
try {
SpPrinterConfig sp = new SpPrinterConfig();
sp.print(device.getDeviceSn(),
SpPrinterTemplate.oilCashierStubTemp(
order.getStoreName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
order.getMemPhone(),
order.getGasGunNo(),
order.getGasOilNo(),
order.getGasOilLiters().toString(),
order.getGasRefuelPrice().toString(),
receiptMap,
makeUp
), 1);
sp.print(device.getDeviceSn(),
SpPrinterTemplate.oilClientStubTemp(
order.getStoreName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
order.getMemPhone(),
order.getGasGunNo(),
order.getGasOilNo(),
order.getGasOilLiters().toString(),
order.getGasRefuelPrice().toString(),
receiptMap,
makeUp
), 1);
} catch (Exception e) {
e.printStackTrace();
}
}).start();
}
if (device.getType().equals(DeviceTypeEnum.type2.getType())) {
new Thread(() -> {
try {
mqttProviderConfig.publish(2, false, device.getDeviceImei(),
ZkcPrinterTemplate.oilCashierStubTemp(
order.getStoreName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
order.getMemPhone(),
"嗨森逛",
order.getGasGunNo(),
order.getGasOilNo(),
order.getGasOilLiters().toString(),
order.getGasRefuelPrice().toString(),
receiptMap,
makeUp
));
mqttProviderConfig.publish(2, false, device.getDeviceImei(),
ZkcPrinterTemplate.oilClientStubTemp(
order.getStoreName(),
order.getOrderNo(),
DateUtil.date2String(order.getPayTime(), "yyyy-MM-dd HH:mm:ss"),
order.getMemPhone(),
"嗨森逛",
order.getGasGunNo(),
order.getGasOilNo(),
order.getGasOilLiters().toString(),
order.getGasRefuelPrice().toString(),
receiptMap,
makeUp
));
} catch (Exception e) {
e.getMessage();
}
}).start();
}
}
}
public String priceName(Integer num) {
switch (num) {
case 100:
return "100元以下";
case 200:
return "100-200元";
case 300:
return "200-300元";
case 400:
return "300-400元";
default:
return "400元以上";
}
}
@Override
@Transactional(
isolation = Isolation.SERIALIZABLE,
propagation = Propagation.REQUIRES_NEW)
public HighOrder insertThirdProduct(JSONObject object) throws Exception {
HighOrder highOrder = new HighOrder();
// highOrder.setMerchId(object.getString("mchId"));
highOrder.setWhetherRebate(false);
HighUser user = highUserService.findByUserId(object.getLong("userId"));
JSONObject jsonObject = null;
JSONObject requestContent = null;
// 积分抵扣金额
BigDecimal integralPrice = new BigDecimal(0);
// 优惠券抵扣金额
BigDecimal discountPrice = new BigDecimal(0);
// 实际支付金额
BigDecimal orderPayPrice = new BigDecimal(0);
// 市场金额
BigDecimal marketPrice = new BigDecimal(0);
// 查询详单订单的实际
JSONObject productDetail = thirdProductConfig.getThirdPartyByDetail(object.getInteger("platformId"), object.getInteger("productType"), object.getLong("companyId") , object.getLong("productId") , null , "");
highOrder.setProductType(object.getInteger("productType"));
JSONObject userToken = QianZhuConfig.getTokenV2(user.getId().toString(), user.getName(), user.getPhone());
if (!userToken.getBoolean("success")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
}
// 1 星巴克 2 肯德基 3 会员充值
if (object.getInteger("productType") == 1) {
List<String> List = new ArrayList<>();
JSONArray array = object.getJSONArray("orderItems");
for (Object o : array) {
JSONObject object1 = (JSONObject) o;
Map<String, Object> contentMap = new LinkedHashMap<>();
if (!object1.getString("productId").equals("")) {
contentMap.put("productId", object1.getString("productId"));
}
if (!object1.getString("cupSize").equals("")) {
contentMap.put("cupSize", object1.getString("cupSize"));
}
if (!object1.getString("temperature").equals("")) {
contentMap.put("temperature", object1.getString("temperature"));
}
if (!object1.getString("cream").equals("")) {
contentMap.put("cream", object1.getString("cream"));
}
if (!object1.getString("espresso").equals("")) {
contentMap.put("espresso", object1.getString("espresso"));
}
if (!object1.getString("milk").equals("")) {
contentMap.put("milk", object1.getString("milk"));
}
if (!object1.getString("milkBubble").equals("")) {
contentMap.put("milkBubble", object1.getString("milkBubble"));
}
if (!"".equals(object1.getString("num"))) {
contentMap.put("num", object1.getString("num"));
}
List.add(JSON.toJSONString(contentMap));
}
// 下单
jsonObject = QianZhuConfig.starbucksOrders(user.getId().toString(), object.getString("storeCode"), List.toString().replace(" ", ""), object.getString("customerMobile"));
// 判断下单是否成功
if (!Objects.equals(jsonObject.getString("code"), "200")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
}
if (!jsonObject.getBoolean("success")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
}
// 根据订单号查询订单详情
JSONObject orderObject = QianZhuConfig.starbucksOrderByOrderNo(jsonObject.getJSONObject("data").getString("orderNo"));
// 判断是否成功
if (!orderObject.getBoolean("success")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
}
// 插入订单内容
highOrder.setOrderNo(jsonObject.getJSONObject("data").getString("orderNo"));
// highOrder.setRegionId(object.getString("regionId"));
highOrder.setCompanyId(object.getLong("companyId"));
highOrder.setCreateTime(new Date());
highOrder.setMemId(user.getId());
highOrder.setMemName(user.getName());
highOrder.setMemPhone(user.getPhone());
highOrder.setOrderStatus(1);
highOrderMapper.insert(highOrder);
// 获取星巴克订单内容
JSONArray starbucksOrder = orderObject.getJSONObject("data").getJSONArray("orderItems");
for (Object starbucksObject : starbucksOrder) {
JSONObject childObject = (JSONObject) starbucksObject;
HighChildOrder childOrder = new HighChildOrder();
childOrder.setOrderId(highOrder.getId());
childOrder.setChildOrderStatus(1);
childOrder.setGoodsType(9);
childOrder.setStoreId(object.getLong("storeCode"));
childOrder.setGoodsId(object.getLong("productId"));
childOrder.setStoreAddress(childObject.getString("storeAddress"));
childOrder.setStoreName(childObject.getString("storeName"));
childOrder.setGoodsName(childObject.getString("productName"));
childOrder.setGoodsImg(childObject.getString("imgUrl"));
childOrder.setSaleCount(childObject.getInteger("quantity"));
childOrder.setGoodsPrice(childObject.getBigDecimal("marketPrice"));
// 计算利润
BigDecimal profitPrice = childObject.getBigDecimal("marketPrice").multiply(productDetail.getBigDecimal("priceDiscount").divide(new BigDecimal(100)));
// 计算子订单支付金额
BigDecimal childPrice = childObject.getBigDecimal("unitPrice").add(profitPrice).setScale(2 , RoundingMode.HALF_UP);
if (childPrice.compareTo(childObject.getBigDecimal("marketPrice")) > 0) {
childPrice = childObject.getBigDecimal("marketPrice");
}
if (object.getLong("memDiscountId") != null) {
childOrder.setGoodsActualPrice(childObject.getBigDecimal("marketPrice"));
} else {
childOrder.setGoodsActualPrice(childPrice);
}
childPrice = childPrice.multiply(childObject.getBigDecimal("quantity"));
// 计算总订单实际支付金额
orderPayPrice = orderPayPrice.add(childPrice);
// 计算市场价金额
marketPrice = marketPrice.add(childObject.getBigDecimal("marketPrice").multiply(childObject.getBigDecimal("quantity")));
childOrder.setTotalPrice(childPrice);
highChildOrderMapper.insert(childOrder);
}
} else if (object.getInteger("productType") == 2) {
if (object.getInteger("eatType") == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "请选择就餐方式!");
}
// 下单
jsonObject = QianZhuConfig.createKfcOrder(object.getInteger("eatType"), object.getString("storeCode"), object.getString("customerMobile"), object.getString("orderItems"), object.getString("userId"));
// 判断下单是否成功
if (!Objects.equals(jsonObject.getString("code"), "10000")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
}
// 根据订单号查询订单详情
JSONObject orderObject = QianZhuConfig.getKfcOrderByOrderNo(jsonObject.getJSONObject("data").getString("orderNo"));
// 判断下单是否成功
if (!orderObject.getBoolean("success")) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, jsonObject.getString("message"));
}
// 插入订单内容
highOrder.setOrderNo(jsonObject.getJSONObject("data").getString("orderNo"));
// highOrder.setRegionId(object.getString("regionId"));
highOrder.setCompanyId(object.getLong("companyId"));
highOrder.setCreateTime(new Date());
highOrder.setMemId(user.getId());
highOrder.setMemName(user.getName());
highOrder.setMemPhone(user.getPhone());
highOrder.setOrderStatus(1);
highOrderMapper.insert(highOrder);
// 获取肯德基订单内容
JSONArray kfcOrder = orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getJSONArray("items");
for (Object kfcObject : kfcOrder) {
JSONObject childObject = (JSONObject) kfcObject;
HighChildOrder childOrder = new HighChildOrder();
childOrder.setOrderId(highOrder.getId());
childOrder.setChildOrderStatus(1);
childOrder.setGoodsType(4);
childOrder.setGoodsId(object.getLong("productId"));
childOrder.setStoreAddress(orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getString("storeAddress"));
childOrder.setStoreName(orderObject.getJSONObject("data").getJSONObject("kfcPlaceOrder").getString("storeName"));
childOrder.setGoodsName(childObject.getString("productName"));
childOrder.setGoodsImg(childObject.getString("imageUrl"));
childOrder.setSaleCount(childObject.getInteger("quantity"));
childOrder.setGoodsPrice(childObject.getBigDecimal("originPrice"));
// 计算利润
BigDecimal profitPrice = childObject.getBigDecimal("originPrice").multiply(productDetail.getBigDecimal("priceDiscount").divide(new BigDecimal(100)));
// 计算子订单支付金额
BigDecimal childPrice = childObject.getBigDecimal("price").add(profitPrice).setScale(2 , RoundingMode.HALF_UP);
if (childPrice.compareTo(childObject.getBigDecimal("originPrice")) > 0) {
childPrice = childObject.getBigDecimal("originPrice");
}
if (object.getLong("memDiscountId") != null) {
childOrder.setGoodsActualPrice(childObject.getBigDecimal("originPrice"));
} else {
childOrder.setGoodsActualPrice(childPrice);
}
childPrice = childPrice.multiply(childObject.getBigDecimal("quantity"));
// 计算总订单实际支付金额
orderPayPrice = orderPayPrice.add(childPrice);
// 计算市场价金额
marketPrice = marketPrice.add(childObject.getBigDecimal("originPrice").multiply(childObject.getBigDecimal("quantity")));
childOrder.setTotalPrice(childPrice);
highChildOrderMapper.insert(childOrder);
}
} else if (object.getInteger("productType") == 3) {
ApiMemberProduct memberProduct = apiMemberProductService.findById(object.getLong("goodsId"));
if (memberProduct == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "当前产品不可购买");
}
object.put("productId", memberProduct.getProductId());
// 插入订单内容
highOrder.setOrderNo("HF" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5));
// highOrder.setRegionId(object.getString("regionId"));
highOrder.setCompanyId(object.getLong("companyId"));
highOrder.setCreateTime(new Date());
highOrder.setMemId(user.getId());
highOrder.setMemName(user.getName());
highOrder.setMemPhone(user.getPhone());
highOrder.setOrderStatus(1);
// 计算实际支付金额
orderPayPrice = memberProduct.getCostPrice().add(memberProduct.getPrice().multiply(productDetail.getBigDecimal("priceDiscount").divide(new BigDecimal(100)))).setScale(2, RoundingMode.HALF_UP);
if (orderPayPrice.compareTo(memberProduct.getPrice()) > 0) {
orderPayPrice = memberProduct.getPrice();
}
// 计算市场价金额
marketPrice = memberProduct.getPrice();
highOrderMapper.insert(highOrder);
HighChildOrder childOrder = new HighChildOrder();
childOrder.setOrderId(highOrder.getId());
childOrder.setChildOrderStatus(1);
childOrder.setGoodsType(10);
childOrder.setStoreId(object.getLong("storeCode"));
childOrder.setGoodsId(memberProduct.getId());
childOrder.setGoodsName(memberProduct.getName());
childOrder.setSaleCount(1);
childOrder.setGoodsPrice(marketPrice);
if (object.getLong("memDiscountId") != null) {
childOrder.setGoodsActualPrice(marketPrice);
childOrder.setTotalPrice(marketPrice);
} else {
childOrder.setGoodsActualPrice(orderPayPrice);
childOrder.setTotalPrice(orderPayPrice);
}
highChildOrderMapper.insert(childOrder);
}
// 定义优惠券
HighDiscountUserRel highDiscountUserRel = null;
// 判断是否有优惠券
if (object.getLong("memDiscountId") != null) {
orderPayPrice = marketPrice;
// 优惠券信息
highDiscountUserRel = highDiscountUserRelService.getRelById(object.getLong("memDiscountId"));
highOrder.setMemDiscountId(object.getLong("memDiscountId"));
if (highDiscountUserRel == null || highDiscountUserRel.getStatus() != 1) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "优惠券状态错误");
}
if (!highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type4.getType())
&& !highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type5.getType())
&& !highDiscountUserRel.getHighDiscount().getUseScope().equals(DiscountUseScope.type6.getType())
) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "无法使用此优惠券");
}
}
// 优惠券抵扣
if (highDiscountUserRel != null) {
highOrder.setMemDiscountName(highDiscountUserRel.getHighDiscount().getDiscountName());
// 卡卷类型 1:满减 2:抵扣 3:折扣
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 1) {
// 如果商品支付总额 小于 满减价格
if (orderPayPrice.compareTo(highDiscountUserRel.getHighDiscount().getDiscountCondition()) < 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.UN_MEMBER_ERROR, "订单未达到" + highDiscountUserRel.getHighDiscount().getDiscountCondition() + "元,无法使用此优惠券");
}
// 满减额度
discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice();
}
// 卡卷类型 1:满减 2:抵扣 3:折扣
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 2) {
// 满减额度
discountPrice = highDiscountUserRel.getHighDiscount().getDiscountPrice();
}
// 卡卷类型 1:满减 2:抵扣 3:折扣
if (highDiscountUserRel.getHighDiscount().getDiscountType() == 3) {
// 满减额度
discountPrice = orderPayPrice.subtract(orderPayPrice.multiply(highDiscountUserRel.getHighDiscount().getDiscountPrice())).setScale(2, RoundingMode.HALF_UP);
}
}
// 使用优惠券
if (highOrder.getMemDiscountId() != null) {
HighDiscountUserRel discountUserRel = highDiscountUserRelService.getRelById(highOrder.getMemDiscountId());
discountUserRel.setUseTime(new Date()); // 使用时间
discountUserRel.setStatus(2); //状态 0:已过期 1:未使用 2:已使用
highDiscountUserRelService.updateDiscountUserRel(discountUserRel);
HighDiscountAgentCode code = highDiscountAgentCodeService.getCodeById(discountUserRel.getDiscountAgentCodeId());
code.setStatus(3);
highDiscountAgentCodeService.updateCode(code);
}
// 使用积分
// 判断积分数量是否大于0
if (object.getLong("integralNum") != null) {
if (object.getLong("integralNum") > 0 && productDetail.getBigDecimal("integralDiscount").compareTo(new BigDecimal("0")) > 0) {
// 判断用户积分是否够
if (object.getLong("integralNum") > user.getGold()) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "用户积分不足");
}
// 积分抵扣金额
integralPrice = object.getBigDecimal("integralNum").divide(new BigDecimal(100).setScale(2, RoundingMode.HALF_UP));
// 最高可抵扣金额
BigDecimal maxIntegralDeductionPrice = orderPayPrice.multiply(productDetail.getBigDecimal("integralDiscount")).divide(new BigDecimal(100)).setScale(2, RoundingMode.HALF_UP);
// 判读积分是否大于限制额度
if (maxIntegralDeductionPrice.compareTo(integralPrice) < 0) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.COMMON_ERROR, "订单最大抵扣积分金额:" + maxIntegralDeductionPrice);
}
// 判断积分抵扣比例是否为100% 并且积分数量是否可以抵扣最后的支付金额
if (productDetail.getBigDecimal("integralDiscount").compareTo(new BigDecimal(100)) == 0 && integralPrice.compareTo(orderPayPrice) == 0) {
// 查询用户支付密码
HighUserPayPassword userPayPassword = highUserPayPasswordService.getDetailByUser(object.getLong("userId"));
if (userPayPassword == null) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_SET_USER_PAY_PWD, "");
}
if (StringUtils.isBlank(object.getString("password"))) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.NOT_ENTER_USER_PAY_PWD, "");
}
// 校验支付密码
if (!AESEncodeUtil.aesEncrypt(object.getString("password")).equals(userPayPassword.getPassword())) {
throw ErrorHelp.genException(SysCode.System, ErrorCode.USER_PAY_PWD_ERROR, "");
}
}
}
}
highOrder.setTotalDeductionPrice(discountPrice);
highOrder.setPayGold(object.getInteger("integralNum"));
highOrder.setTotalPrice(orderPayPrice);
highOrder.setPayPrice(orderPayPrice.subtract(discountPrice));
if (integralPrice.compareTo(new BigDecimal(0)) > 0) {
highOrder.setPayPrice(highOrder.getPayPrice().subtract(integralPrice));
String remark = "订单" + highOrder.getOrderNo() + "下单,使用积分:" + object.getInteger("integralNum");
highUserService.goldHandle(highOrder.getMemId(), object.getInteger("integralNum"), 2, 2, highOrder.getId() , remark , highOrder.getOrderNo());
}
// 判断积分支付是否扣完金额
if (highOrder.getPayPrice().compareTo(new BigDecimal(0)) == 0) {
highOrder.setOrderStatus(2);
// highOrder.setPayModel(1);
highOrder.setPayType(3);
highOrder.setPayTime(new Date());
highOrder.setPaySerialNo("HF" + DateUtil.date2String(new Date(), "yyyyMMddHHmmss") + IDGenerator.nextId(5));
} else {
highOrder.setOrderStatus(1);
}
highOrder.setPayRealPrice(highOrder.getPayPrice());
highOrder.setRemarks(object.getString("customerMobile"));
highOrderMapper.updateByPrimaryKey(highOrder);
if (highOrder.getOrderStatus() == 2) {
HighOrder highOrderList = highOrderService.getOrderById(highOrder.getId());
for (HighChildOrder childOrder : highOrderList.getHighChildOrderList()) {
childOrder.setChildOrderStatus(2);
}
// 推送订单记录
HighGasOrderPush highGasOrderPush = new HighGasOrderPush();
// 1 星巴克 2 肯德基 3:第三方会员充值
if (object.getInteger("productType") == 1) {
highGasOrderPush.setType(OrderPushType.type8.getType());
requestContent = QianZhuConfig.starbucksOrdersPay(highOrder.getOrderNo());
} else if (object.getInteger("productType") == 2){
highGasOrderPush.setType(OrderPushType.type4.getType());
requestContent = QianZhuConfig.payKfcOrder(highOrder.getOrderNo());
} else if (object.getInteger("productType") == 3){
highGasOrderPush.setType(OrderPushType.type9.getType());
requestContent = QianZhuConfig.insertV2(object.getString("productId") , highOrder.getOrderNo() , object.getString("customerMobile"));
}
highGasOrderPush.setOrderNo(highOrder.getOrderNo());
highGasOrderPush.setCreateTime(new Date());
highGasOrderPush.setRequestContent(highOrder.getOrderNo());
highGasOrderPush.setReturnContent(requestContent.toJSONString());
highGasOrderPushMapper.insert(highGasOrderPush);
}
return highOrder;
}
@Override
public Long whetherCheck(Long memId, Integer status) {
HighOrderExample example = new HighOrderExample();
HighOrderExample.Criteria criteria = example.createCriteria();
criteria.andMemIdEqualTo(memId).andOrderStatusEqualTo(status).andWhetherCheckEqualTo(false);
return highOrderMapper.countByExample(example);
}
@Override
public List<HighOrder> integralRebateOrder() {
HighOrderExample example = new HighOrderExample();
HighOrderExample.Criteria criteria = example.createCriteria();
criteria.andOrderStatusEqualTo(3).andWhetherRebateEqualTo(false).andPayRealPriceGreaterThan(new BigDecimal(0)).andPayTypeNotEqualTo(3);
return highOrderMapper.selectByExample(example);
}
@Override
public List<HighOrder> promoteOrderList(String identificationCode) throws Exception {
HighOrderExample example = new HighOrderExample();
HighOrderExample.Criteria criteria = example.createCriteria();
criteria.andPromoteCodeEqualTo(identificationCode).andOrderStatusEqualTo(3);
List<HighOrder> list = highOrderMapper.selectByExample(example);
for (HighOrder order : list) {
order.setTime(DateUtil.date2String(order.getCreateTime() , "MM月dd日 HH:mm"));
order.setGoodsTypeName("下单:" + OrderProductType.getDataByType(order.getProductType()).getName());
}
return list;
}
}