package com.stylefeng.guns.modular.CharteredCar.server.impl;
|
|
import com.baomidou.mybatisplus.mapper.EntityWrapper;
|
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
|
import com.stylefeng.guns.core.util.ToolUtil;
|
import com.stylefeng.guns.modular.CharteredCar.dao.OrderCharteredCarMapper;
|
import com.stylefeng.guns.modular.CharteredCar.model.OrderCharteredCar;
|
import com.stylefeng.guns.modular.CharteredCar.server.IOrderCharteredCarService;
|
import com.stylefeng.guns.modular.crossCity.dao.OrderCrossCityMapper;
|
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
|
import com.stylefeng.guns.modular.specialTrain.dao.OrderPrivateCarMapper;
|
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
|
import com.stylefeng.guns.modular.system.dao.SensitiveWordsMapper;
|
import com.stylefeng.guns.modular.system.model.*;
|
import com.stylefeng.guns.modular.system.service.*;
|
import com.stylefeng.guns.modular.system.util.DateUtil;
|
import com.stylefeng.guns.modular.system.util.PayMoneyUtil;
|
import com.stylefeng.guns.modular.system.util.ResultUtil;
|
import com.stylefeng.guns.modular.system.util.UUIDUtil;
|
import com.stylefeng.guns.modular.system.warpper.PreferentialDataVo;
|
import com.stylefeng.guns.modular.taxi.dao.OrderTaxiMapper;
|
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
|
import com.stylefeng.guns.modular.taxi.model.PaymentRecord;
|
import com.stylefeng.guns.modular.taxi.service.IPaymentRecordService;
|
import com.stylefeng.guns.modular.taxi.service.ITransactionDetailsService;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.stereotype.Service;
|
|
import javax.annotation.Resource;
|
import java.math.BigDecimal;
|
import java.util.Date;
|
import java.util.HashMap;
|
import java.util.List;
|
import java.util.Map;
|
|
|
@Service
|
public class OrderCharteredCarServiceImpl extends ServiceImpl<OrderCharteredCarMapper, OrderCharteredCar> implements IOrderCharteredCarService {
|
|
@Resource
|
private OrderCharteredCarMapper orderCharteredCarMapper;
|
|
@Resource
|
private SensitiveWordsMapper sensitiveWordsMapper;
|
|
@Autowired
|
private ICompanyCityService companyCityService;
|
|
@Autowired
|
private DateUtil dateUtil;
|
|
@Autowired
|
private IOrderCancelService orderCancelService;
|
|
@Autowired
|
private ISystemNoticeService systemNoticeService;
|
|
@Resource
|
private OrderPrivateCarMapper orderPrivateCarMapper;
|
|
@Resource
|
private OrderTaxiMapper orderTaxiMapper;
|
|
@Resource
|
private OrderCrossCityMapper orderCrossCityMapper;
|
|
@Autowired
|
private IUserInfoService userInfoService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
@Autowired
|
private IPaymentRecordService paymentRecordService;
|
|
@Autowired
|
private IIncomeService incomeService;
|
|
@Autowired
|
private ITransactionDetailsService transactionDetailsService;
|
|
@Autowired
|
private ISysIntegralService sysIntegralService;
|
|
|
|
/**
|
* 保存数据
|
* @param traveltime
|
* @param carTime
|
* @param modelUse
|
* @param peopleNumber
|
* @param contactPerson
|
* @param contactPhone
|
* @param uid
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil orderCharteredCar(Date travelTime, Integer carTime, Integer serverCarModelId, String modelUse, Integer peopleNumber,
|
String contactPerson, String contactPhone, String placeLonLat, Integer uid) throws Exception {
|
|
/**
|
* 1.出租车、专车、跨城有待支付的订单不能叫车
|
* 2.小件物流有未完成的订单可以下跨城、专车、出租车
|
* 3.出租车、专车、跨城有预约单可以下即时单
|
*/
|
List<OrderPrivateCar> orderPrivateCars = orderPrivateCarMapper.queryByState(uid, null, 1, 7, 12);
|
if(orderPrivateCars.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
List<OrderTaxi> list = orderTaxiMapper.queryByState_(uid, null, 1, 7, 12);
|
if(list.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
List<OrderCrossCity> orderCrossCities1 = orderCrossCityMapper.queryByState(uid, 7, 12);
|
if(orderCrossCities1.size() > 0){
|
return ResultUtil.error("有未完成的订单");
|
}
|
|
|
OrderCharteredCar orderCharteredCar = new OrderCharteredCar();
|
orderCharteredCar.setUserId(uid);
|
Company query = companyCityService.query(placeLonLat.split(",")[0], placeLonLat.split(",")[1]);
|
if(null == query){
|
return ResultUtil.error("该地点暂无企业服务");
|
}
|
orderCharteredCar.setCompanyId(query.getId());
|
orderCharteredCar.setOrderNumber(this.getOrderNum());
|
orderCharteredCar.setTraveltime(travelTime);
|
orderCharteredCar.setCarTime(carTime);
|
orderCharteredCar.setServerCarModelId(serverCarModelId);
|
orderCharteredCar.setModelUse(modelUse);
|
orderCharteredCar.setPeopleNumber(peopleNumber);
|
orderCharteredCar.setContactPerson(contactPerson);
|
orderCharteredCar.setContactPhone(contactPhone);
|
orderCharteredCar.setState(1);
|
orderCharteredCar.setIsDelete(1);
|
orderCharteredCar.setInsertTime(new Date());
|
this.insert(orderCharteredCar);
|
return ResultUtil.success();
|
}
|
|
|
/**
|
* 获取个人中心订单列表
|
* @param uid
|
* @param pageNum
|
* @param size
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryMyOrderList(Integer uid, Integer pageNum, Integer size) throws Exception {
|
pageNum = (pageNum - 1) * size;
|
List<Map<String, Object>> maps = orderCharteredCarMapper.queryMyOrderList(uid, pageNum, size);
|
return maps;
|
}
|
|
|
@Override
|
public ResultUtil addCancle(Integer id, String reason, String remark, Integer uid) throws Exception {
|
if(ToolUtil.isNotEmpty(remark)){
|
if(ToolUtil.isNotEmpty(remark)){
|
List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
|
for(SensitiveWords s : sensitiveWords){
|
remark = remark.replaceAll(s.getContent(), "***");
|
}
|
}
|
}
|
|
OrderCharteredCar orderCharteredCar = this.selectById(id);
|
if(null == orderCharteredCar){
|
return ResultUtil.error("取消订单失败,订单信息有误");
|
}
|
if(orderCharteredCar.getState() != 1){
|
return ResultUtil.error("取消订单失败,不合法的操作");
|
}
|
|
OrderCancel orderCancel = new OrderCancel();
|
orderCancel.setOrderId(id);
|
orderCancel.setOrderType(6);
|
orderCancel.setReason(reason);
|
orderCancel.setRemark(remark);
|
orderCancel.setState(2);
|
orderCancel.setInsertTime(new Date());
|
orderCancel.setUserType(1);
|
orderCancelService.insert(orderCancel);
|
orderCharteredCar.setState(3);
|
this.updateById(orderCharteredCar);
|
|
//添加消息
|
systemNoticeService.addSystemNotice(1, "您已成功取消旅游包车订单,谢谢使用!", orderCharteredCar.getUserId(), 1);
|
Map<String, Object> map = new HashMap<>();
|
map.put("id", orderCancel.getId());
|
return ResultUtil.success(map);
|
}
|
|
|
|
|
public synchronized String getOrderNum() throws Exception{
|
int size = this.selectCount(null);
|
return "CHARTERED" + String.valueOf(1000000 + size + 1).substring(1);
|
}
|
|
@Override
|
public ResultUtil payThankYouFee(Integer uid, Integer orderId, Double money, Integer payType, Integer type) throws Exception {
|
UserInfo userInfo = userInfoService.selectById(uid);
|
OrderCharteredCar orderCharteredCar = this.selectById(orderId);
|
ResultUtil resultUtil = ResultUtil.success();
|
if(payType == 1){//微信支付
|
String app = type == 1 ? "APP" : "JSAPI";
|
resultUtil = payMoneyUtil.weixinpay("感谢费", "", orderId + "_6_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/wxPayThankYouFee", app, userInfo.getAppletsOpenId());
|
paymentRecordService.saveData(3, uid, 1, orderId, 6, 1, money, "", 1);//添加预支付数据
|
}
|
if(payType == 2){//支付宝支付
|
resultUtil = payMoneyUtil.alipay("感谢费", "感谢费", "", orderId + "_6_" + UUIDUtil.getRandomCode(5), money.toString(), "/base/aliPayThankYouFee");
|
paymentRecordService.saveData(1, uid, 1, orderId, 6, 2, money, "", 1);//添加预支付数据
|
}
|
if(payType == 3){//余额支付
|
if(userInfo.getBalance() == null || userInfo.getBalance() < money){
|
return ResultUtil.error("余额不足,无法完成支付", "");
|
}
|
|
userInfo.setBalance(new BigDecimal(userInfo.getBalance()).subtract(new BigDecimal(money)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
|
SysIntegral query1 = sysIntegralService.selectOne(new EntityWrapper<SysIntegral>().eq("companyId", orderCharteredCar.getCompanyId()));
|
userInfo.setIntegral(userInfo.getIntegral() + (money.intValue() * query1.getIntegral()));//积分
|
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "包车-感谢费", money, 2, 1, 1, 6, orderId);
|
userInfoService.updateById(userInfo);
|
|
orderCharteredCar.setThankYouFee(money);
|
this.updateById(orderCharteredCar);
|
|
//添加已收入明细
|
incomeService.saveData(1, 1, 6, orderCharteredCar.getId(), 6, money);
|
systemNoticeService.addSystemNotice(1, "您已使用余额成功完成感谢费支付,谢谢使用!", uid, 1);
|
}
|
return resultUtil;
|
}
|
|
@Override
|
public void payThankYouFeeCallback(Integer orderId, String order_id, Integer payType) throws Exception {
|
OrderCharteredCar orderCharteredCar = this.selectById(orderId);
|
PaymentRecord query = paymentRecordService.query(3, orderCharteredCar.getUserId(), 1, orderId, 6, payType, 1);
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
|
UserInfo userInfo = userInfoService.selectById(orderCharteredCar.getUserId());
|
SysIntegral query1 = sysIntegralService.selectOne(new EntityWrapper<SysIntegral>().eq("companyId", orderCharteredCar.getCompanyId()));
|
userInfo.setIntegral(userInfo.getIntegral() + (query.getAmount().intValue() * query1.getIntegral()));//积分
|
//添加交易明细
|
transactionDetailsService.saveData(userInfo.getId(), "包车-感谢费", query.getAmount(), 2, 1, 1, 6, orderId);
|
userInfoService.updateById(userInfo);
|
|
orderCharteredCar.setThankYouFee(query.getAmount());
|
this.updateById(orderCharteredCar);
|
|
//添加已收入明细
|
incomeService.saveData(1, 1, 6, orderCharteredCar.getId(), 6, query.getAmount());
|
systemNoticeService.addSystemNotice(1, "您已使用" + (payType == 1 ? "微信" : "支付宝") + "成功完成感谢费支付,谢谢使用!", userInfo.getId(), 1);
|
}
|
|
@Override
|
public PreferentialDataVo queryBalance1(Integer orderId, Integer uid) throws Exception {
|
PreferentialDataVo preferentialDataVo = new PreferentialDataVo();
|
UserInfo userInfo = userInfoService.selectById(uid);
|
preferentialDataVo.setBalance(userInfo.getBalance());
|
return preferentialDataVo;
|
}
|
}
|