package com.stylefeng.guns.modular.system.service.impl;
|
|
import com.alibaba.fastjson.JSONObject;
|
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.account.controller.AppOrderController;
|
import com.stylefeng.guns.modular.account.model.TEnterpriseWithdrawal;
|
import com.stylefeng.guns.modular.account.service.ITEnterpriseWithdrawalService;
|
import com.stylefeng.guns.modular.account.service.UserWithdrawalService;
|
import com.stylefeng.guns.modular.account.unionpay.GetOpenBodySig;
|
import com.stylefeng.guns.modular.account.unionpay.QrCodeConfiguration;
|
import com.stylefeng.guns.modular.account.unionpay.Util;
|
import com.stylefeng.guns.modular.account.util.Base64Util;
|
import com.stylefeng.guns.modular.cloudPayment.example.AllocationExample;
|
import com.stylefeng.guns.modular.cloudPayment.req.AllocationReq;
|
import com.stylefeng.guns.modular.crossCity.model.OrderCrossCity;
|
import com.stylefeng.guns.modular.crossCity.server.IOrderCrossCityService;
|
import com.stylefeng.guns.modular.smallLogistics.model.OrderLogistics;
|
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsService;
|
import com.stylefeng.guns.modular.smallLogistics.server.IOrderLogisticsSpreadService;
|
import com.stylefeng.guns.modular.specialTrain.model.OrderPrivateCar;
|
import com.stylefeng.guns.modular.specialTrain.server.IOrderPrivateCarService;
|
import com.stylefeng.guns.modular.system.dao.DispatchMapper;
|
import com.stylefeng.guns.modular.system.dao.ReassignMapper;
|
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.*;
|
import com.stylefeng.guns.modular.taxi.model.OrderTaxi;
|
import com.stylefeng.guns.modular.taxi.service.IOrderTaxiService;
|
import com.unionpay.upyzt.resp.AllocationResp;
|
import org.apache.commons.lang.time.DateFormatUtils;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Value;
|
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.util.*;
|
|
|
@Service
|
@Transactional(isolation = Isolation.READ_UNCOMMITTED, propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
|
public class ReassignServiceImpl extends ServiceImpl<ReassignMapper, Reassign> implements IReassignService {
|
|
@Resource
|
private ReassignMapper reassignMapper;
|
|
@Resource
|
private SensitiveWordsMapper sensitiveWordsMapper;
|
|
@Autowired
|
private IOrderService orderService;
|
|
@Autowired
|
private IDriverService driverService;
|
|
@Autowired
|
private ITransactionDetailsService transactionDetailsService;
|
|
@Autowired
|
private IPaymentRecordService paymentRecordService;
|
|
@Autowired
|
private PayMoneyUtil payMoneyUtil;
|
|
@Autowired
|
private IOrderTaxiService orderTaxiService;
|
|
@Autowired
|
private IIncomeService incomeService;
|
|
@Autowired
|
private ISystemNoticeService systemNoticeService;
|
|
@Autowired
|
private IOrderPrivateCarService orderPrivateCarService;
|
|
@Autowired
|
private IOrderCrossCityService orderCrossCityService;
|
|
@Autowired
|
private JGPushUtil jgPushUtil;
|
@Autowired
|
private QrCodeConfiguration qrCodeConfiguration;
|
@Resource
|
private DispatchMapper dispatchMapper;
|
|
@Autowired
|
private IOrderLogisticsService orderLogisticsService;
|
|
@Autowired
|
private ICompanyService companyService;
|
@Autowired
|
private ITEnterpriseWithdrawalService enterpriseWithdrawalService;
|
@Autowired
|
private UserWithdrawalService userWithdrawalService;
|
|
|
@Value("${callbackPath}")
|
private String callbackPath;
|
|
|
|
/**
|
* 提交改派申请
|
* @param uid 申请司机id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil saveData(Reassign reassign, Integer uid, Integer type) throws Exception {
|
type = null == type ? 2 : type;//现目前微信只支持小程序支付
|
String content = reassign.getRemark();
|
if(ToolUtil.isNotEmpty(content)){
|
List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
|
for(SensitiveWords s : sensitiveWords){
|
content = content.replaceAll(s.getContent(), "***");
|
}
|
}
|
reassign.setRemark(content);
|
ResultUtil resultUtil = ResultUtil.success();
|
Driver driver = driverService.selectById(uid);
|
// TODO: 2020/11/12 司机端不控制重复提交(如果重复提交且未支付,直接将之前的数据删除)
|
// Reassign query = reassignMapper.query(uid, null, null, null, 1);
|
// if(null != query){
|
// return ResultUtil.error("有未完成支付的改派申请");
|
// }
|
Reassign query = reassignMapper.query(uid, null, reassign.getOrderId(), reassign.getOrderType(), 1);
|
if(null != query){
|
// return ResultUtil.error("不能重复提交申请");
|
reassignMapper.deleteById(query.getId());
|
}
|
query = reassignMapper.query(uid, null, reassign.getOrderId(), reassign.getOrderType(), 2);
|
if(null != query){
|
return ResultUtil.error("您提交的申请正在处理中");
|
}
|
|
//获取支付金额
|
Double aDouble = orderService.queryReassignMoney(reassign.getOrderId(), reassign.getOrderType());
|
reassign.setMoney(aDouble);
|
reassign.setOriginalDriverId(uid);
|
reassign.setOriginalCarId(driver.getCarId());
|
reassign.setInsertTime(new Date());
|
this.insert(reassign);
|
|
systemNoticeService.addSystemNotice(2, "您的改派申请已成功提交,我们会尽快为你处理!", uid, 1);
|
|
//开始支付
|
if(null != reassign.getPayType()){
|
if(reassign.getPayType() == 1){//微信支付
|
reassign.setState(1);
|
|
resultUtil = payMoneyUtil.weixinpay("改派订单", "", reassign.getId() + "_" + reassign.getOrderType() + "_" + UUIDUtil.getRandomCode(5), aDouble.toString(), "/base/wxReassign", "APP", "");
|
paymentRecordService.saveData(1, uid, 2, reassign.getOrderId(), reassign.getOrderType(), 1, aDouble, "", 1);//添加预支付数据
|
}
|
if(reassign.getPayType() == 2){//支付宝
|
reassign.setState(1);
|
resultUtil = payMoneyUtil.alipay("改派订单", "改派订单", "", reassign.getId() + "_" + reassign.getOrderType() + "_" + UUIDUtil.getRandomCode(5), aDouble.toString(), "/base/aliReassign");
|
paymentRecordService.saveData(1, uid, 2, reassign.getOrderId(), reassign.getOrderType(), 2, aDouble, "", 1);//添加预支付数据
|
}
|
if(reassign.getPayType() == 3){//余额
|
reassign.setState(2);
|
reassign.setPayTime(new Date());
|
reassignMapper.updateById(reassign);
|
|
Double balance = driver.getBalance();
|
Double laveBusinessMoney = driver.getLaveBusinessMoney();
|
Double laveActivityMoney = driver.getLaveActivityMoney();
|
if(null == balance || balance < aDouble){
|
throw new SystemException("账户余额不足");
|
}
|
if(null != laveBusinessMoney && laveBusinessMoney.compareTo(aDouble) >= 0){
|
driver.setLaveBusinessMoney(new BigDecimal(laveBusinessMoney).subtract(new BigDecimal(aDouble)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}else if(null != laveActivityMoney && laveActivityMoney.compareTo(aDouble) >= 0){
|
driver.setLaveActivityMoney(new BigDecimal(laveActivityMoney).subtract(new BigDecimal(aDouble)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
driver.setBalance(new BigDecimal(balance).subtract(new BigDecimal(aDouble)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driverService.updateById(driver);
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "司机改派支付", aDouble, 2, 1, 2, reassign.getOrderType(), reassign.getOrderId());
|
|
|
//修改改派通知状态
|
switch (reassign.getOrderType()){
|
case 1:
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(reassign.getOrderId());
|
orderPrivateCar.setOldState(orderPrivateCar.getState());
|
orderPrivateCar.setState(11);
|
orderPrivateCar.setReassignNotice(2);
|
orderPrivateCarService.updateById(orderPrivateCar);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderPrivateCar.getCompanyId(), 4, orderPrivateCar.getId(), 1, reassign.getMoney());
|
break;
|
case 2:
|
OrderTaxi orderTaxi = orderTaxiService.selectById(reassign.getOrderId());
|
orderTaxi.setOldState(orderTaxi.getState());
|
orderTaxi.setState(11);
|
orderTaxi.setReassignNotice(2);
|
orderTaxiService.updateById(orderTaxi);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderTaxi.getCompanyId(), 4, orderTaxi.getId(), 2, reassign.getMoney());
|
break;
|
case 4:
|
OrderLogistics orderLogistics = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics.setOldState(orderLogistics.getState());
|
orderLogistics.setState(11);
|
orderLogistics.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderLogistics.getCompanyId(), 4, orderLogistics.getId(), orderLogistics.getType(), reassign.getMoney());
|
break;
|
case 5:
|
OrderLogistics orderLogistics1 = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics1.setOldState(orderLogistics1.getState());
|
orderLogistics1.setState(11);
|
orderLogistics1.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics1);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderLogistics1.getCompanyId(), 4, orderLogistics1.getId(), orderLogistics1.getType(), reassign.getMoney());
|
break;
|
}
|
|
systemNoticeService.addSystemNotice(2, "您已使用余额成功支付改派申请费用!", uid, 1);
|
//开始推送调度单
|
Map<String, String> map = new HashMap<>();
|
map.put("orderId", reassign.getOrderId().toString());
|
map.put("orderType", reassign.getOrderType().toString());
|
List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
|
for(Dispatch dispatch : dispatches){
|
jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
|
}
|
|
// TODO 司机云闪付 改派余额支付,司机电子账簿转账到平台
|
if(BigDecimal.ZERO.compareTo(new BigDecimal(aDouble)) < 0){
|
cloudPay(reassign.getOriginalDriverId(),aDouble,Util.getMerOrderId(qrCodeConfiguration.getMsgSrcId()));
|
}
|
|
}
|
if(reassign.getPayType() == 4){
|
// TODO 司机云闪付 改派调起云闪付
|
Double payMoney = reassign.getMoney();
|
paymentRecordService.saveData(1, uid, 2, reassign.getOrderId(), reassign.getOrderType(), 4, aDouble, "", 1);//添加预支付数据
|
resultUtil = placeAnOrder(new BigDecimal(payMoney), 4,1,reassign.getId());
|
}
|
}
|
return resultUtil;
|
}
|
|
private void cloudPay(Integer uid,Double total_fee,String transaction_id) {
|
System.out.println(uid+"======"+total_fee+"====="+transaction_id);
|
Driver driver = driverService.selectById(uid);
|
if(Objects.isNull(driver)){
|
throw new RuntimeException("该司机不存在!"+uid);
|
}
|
// 查询平台账户
|
Company company = companyService.selectOne(new EntityWrapper<Company>()
|
.eq("type", 1)
|
.last("LIMIT 1"));
|
System.out.println("查询平台账户==============="+company);
|
// 查询平台开户信息
|
TEnterpriseWithdrawal enterpriseWithdrawal = enterpriseWithdrawalService.selectOne(new EntityWrapper<TEnterpriseWithdrawal>()
|
.eq("companyId", company.getId())); // 替换为公司id
|
System.out.println("查询平台开户信息==============="+enterpriseWithdrawal);
|
// TODO 司机进件信息
|
UserWithdrawal driverWith = userWithdrawalService.selectOne(new EntityWrapper<UserWithdrawal>()
|
.eq("phone", driver.getPhone())
|
.last("LIMIT 1"));
|
try {
|
AllocationReq allocationReq = new AllocationReq();
|
allocationReq.setOutOrderNo(transaction_id);
|
allocationReq.setPayBalanceAcctId(driverWith.getBalanceAcctId()); // 发送方
|
allocationReq.setRecvBalanceAcctId(enterpriseWithdrawal.getBalanceAcctId()); // 接收方
|
BigDecimal multiply = new BigDecimal(100).multiply(new BigDecimal(total_fee));
|
allocationReq.setAmount(multiply.intValue()); // 金额
|
allocationReq.setPassword(Base64Util.decode(enterpriseWithdrawal.getTransactionAuthorizationCode())); // 密码
|
allocationReq.setOrderNo(transaction_id);
|
allocationReq.setOrderAmount(multiply.longValue());
|
allocationReq.setProductName("订单改派");
|
allocationReq.setProductCount(1);
|
AllocationResp allocationResp = AllocationExample.create(allocationReq);
|
System.err.println("司机分账信息:"+allocationResp);
|
} catch (Exception e) {
|
e.printStackTrace();
|
}
|
|
}
|
|
private ResultUtil placeAnOrder(BigDecimal amount, Integer type,Integer orderType,Integer reassignId) throws Exception {
|
Reassign reassign = reassignMapper.selectById(reassignId);
|
String merOrderId = Util.getMerOrderId(qrCodeConfiguration.getMsgSrcId());
|
reassign.setBillNo(merOrderId+"0");
|
reassignMapper.updateById(reassign);
|
JSONObject json = new JSONObject();
|
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); // 报文请求时间
|
json.put("merOrderId", merOrderId); // 商户订单号
|
json.put("mid", qrCodeConfiguration.getMid()); // 商户号
|
json.put("tid", qrCodeConfiguration.getTid()); // 终端号
|
json.put("instMid", qrCodeConfiguration.getInstMid()); // 业务类型
|
json.put("totalAmount", amount.multiply(new BigDecimal("100")).intValue()); // 支付总金额
|
json.put("orderDesc", "APP下单"); // 订单描述
|
json.put("srcReserve", reassignId+"_"+orderType+"_"+UUIDUtil.getRandomCode(5) + "-" +orderType+"-"+type); // 预留字段
|
json.put("subAppId", "wxasdasdasdasdads");
|
json.put("notifyUrl", "https://zhentonggongsi.com:443/driver/api/placeOrder/notifyUrl");
|
json.put("tradeType", "APP"); // 交易类型,微信必传
|
// json.put("divisionFlag", true); // 分账标记
|
// json.put("platformAmount", 0); // 平台商户分账金额
|
// ArrayList<JSONObject> subOrders = new ArrayList<>();
|
// JSONObject jsonObject = new JSONObject();
|
// jsonObject.put("mid", "988460101800201");
|
// jsonObject.put("totalAmount", 1);
|
// subOrders.add(jsonObject);
|
// json.put("subOrders", subOrders);
|
|
System.err.println("请求报文json:\n" + json);
|
String url;
|
if(1 == type){
|
// url = "https://test-api-open.chinaums.com/v1/netpay/wx/app-pre-order";// 测试
|
url = "https://api-mop.chinaums.com/v1/netpay/wx/app-pre-order";
|
}else if (2 == type){
|
// url = "https://test-api-open.chinaums.com/v1/netpay/trade/precreate";// 测试
|
url = "https://api-mop.chinaums.com/v1/netpay/trade/precreate";
|
}else {
|
// url = "https://test-api-open.chinaums.com/v1/netpay/uac/app-order";// 测试
|
url = "https://api-mop.chinaums.com/v1/netpay/uac/app-order";
|
}
|
//OPEN-BODY-SIG 方式
|
String result = GetOpenBodySig.sendOpenBodySig(qrCodeConfiguration.getAppId(),qrCodeConfiguration.getAppKey(),url, json.toString());
|
System.err.println("响应报文json:\n" + result);
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
Object appPayRequest = jsonObject.get("appPayRequest");
|
System.out.println(appPayRequest);
|
return ResultUtil.success(appPayRequest);
|
}
|
|
/**
|
* 跨城订单改派
|
* @param amount
|
* @param type
|
* @param orderType
|
* @param reassignId
|
* @return
|
* @throws Exception
|
*/
|
private ResultUtil placeAnOrder1(BigDecimal amount, Integer type,Integer orderType,Integer reassignId) throws Exception {
|
Reassign reassign = reassignMapper.selectById(reassignId);
|
String merOrderId = Util.getMerOrderId(qrCodeConfiguration.getMsgSrcId());
|
reassign.setBillNo(merOrderId+"0");
|
reassignMapper.updateById(reassign);
|
JSONObject json = new JSONObject();
|
json.put("requestTimestamp", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss")); // 报文请求时间
|
json.put("merOrderId", merOrderId); // 商户订单号
|
json.put("mid", qrCodeConfiguration.getMid()); // 商户号
|
json.put("tid", qrCodeConfiguration.getTid()); // 终端号
|
json.put("instMid", qrCodeConfiguration.getInstMid()); // 业务类型
|
json.put("totalAmount", amount.multiply(new BigDecimal("100")).intValue()); // 支付总金额
|
json.put("orderDesc", "APP下单"); // 订单描述
|
json.put("srcReserve", reassignId+"_"+orderType+"_"+UUIDUtil.getRandomCode(5) + "-" +1+"-"+type); // 预留字段
|
json.put("subAppId", "wxasdasdasdasdads");
|
json.put("notifyUrl", "https://zhentonggongsi.com:443/driver/api/placeOrder/notifyUrl");
|
json.put("tradeType", "APP"); // 交易类型,微信必传
|
// json.put("divisionFlag", true); // 分账标记
|
// json.put("platformAmount", 0); // 平台商户分账金额
|
// ArrayList<JSONObject> subOrders = new ArrayList<>();
|
// JSONObject jsonObject = new JSONObject();
|
// jsonObject.put("mid", "988460101800201");
|
// jsonObject.put("totalAmount", 1);
|
// subOrders.add(jsonObject);
|
// json.put("subOrders", subOrders);
|
|
System.err.println("请求报文json:\n" + json);
|
String url;
|
if(1 == type){
|
// url = "https://test-api-open.chinaums.com/v1/netpay/wx/app-pre-order";// 测试
|
url = "https://api-mop.chinaums.com/v1/netpay/wx/app-pre-order";
|
}else if (2 == type){
|
// url = "https://test-api-open.chinaums.com/v1/netpay/trade/precreate";// 测试
|
url = "https://api-mop.chinaums.com/v1/netpay/trade/precreate";
|
}else {
|
// url = "https://test-api-open.chinaums.com/v1/netpay/uac/app-order";// 测试
|
url = "https://api-mop.chinaums.com/v1/netpay/uac/app-order";
|
}
|
//OPEN-BODY-SIG 方式
|
String result = GetOpenBodySig.sendOpenBodySig(qrCodeConfiguration.getAppId(),qrCodeConfiguration.getAppKey(),url, json.toString());
|
System.err.println("响应报文json:\n" + result);
|
JSONObject jsonObject = JSONObject.parseObject(result);
|
Object appPayRequest = jsonObject.get("appPayRequest");
|
System.out.println(appPayRequest);
|
return ResultUtil.success(appPayRequest);
|
}
|
|
|
/**
|
* 提交改派申请(跨城专用)
|
* @param uid 申请司机id
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public ResultUtil saveData_(Reassign reassign, String orderIds, Integer uid, Integer type) throws Exception {
|
type = null == type ? 2 : type;//现目前微信只支持小程序支付
|
String content = reassign.getRemark();
|
if(ToolUtil.isNotEmpty(content)){
|
List<SensitiveWords> sensitiveWords = sensitiveWordsMapper.selectList(null);
|
for(SensitiveWords s : sensitiveWords){
|
content = content.replaceAll(s.getContent(), "***");
|
}
|
}
|
reassign.setRemark(content);
|
ResultUtil resultUtil = ResultUtil.success();
|
Driver driver = driverService.selectById(uid);
|
// TODO: 2020/11/12 司机端不控制重复提交(如果重复提交且未支付,直接将之前的数据删除)
|
// Reassign query = reassignMapper.query(uid, null, null, null, 1);
|
// if(null != query){
|
// return ResultUtil.error("有未完成支付的改派申请");
|
// }
|
String[] split = orderIds.split(",");//获取支付金额
|
Double aDouble = orderService.queryReassignMoney(Integer.valueOf(split[0]), 3);
|
Double totalMoney = aDouble * split.length;
|
String ids = "";
|
for(String id : split){
|
Reassign query = reassignMapper.query(uid, null, Integer.valueOf(id), 3, 1);
|
if(null != query){
|
// return ResultUtil.error("不能重复提交申请");
|
reassignMapper.deleteById(query.getId());
|
}
|
query = reassignMapper.query(uid, null, Integer.valueOf(id), 3, 2);
|
if(null != query){
|
return ResultUtil.error("您提交的申请正在处理中");
|
}
|
|
reassign.setMoney(aDouble);
|
reassign.setOrderId(Integer.valueOf(id));
|
reassign.setOrderType(3);
|
reassign.setOriginalDriverId(uid);
|
reassign.setOriginalCarId(driver.getCarId());
|
reassign.setInsertTime(new Date());
|
reassign.setState(1);
|
this.insert(reassign);
|
ids += reassign.getId() + ",";
|
}
|
ids = ids.substring(0, ids.length() - 1);
|
systemNoticeService.addSystemNotice(2, "您的改派申请已成功提交,我们会尽快为你处理!", uid, 1);
|
|
//开始支付
|
if(null != reassign.getPayType()){
|
if(reassign.getPayType() == 1){//微信支付
|
String[] split1 = ids.split(",");
|
|
resultUtil = payMoneyUtil.weixinpay("改派订单", "", ids + "_3_" + UUIDUtil.getRandomCode(5), totalMoney.toString(), "/base/wxReassign", "APP", "");
|
for(String id : split1){
|
paymentRecordService.saveData(1, uid, 2, Integer.valueOf(id), 3, 1, aDouble, "", 1);//添加预支付数据
|
}
|
}
|
if(reassign.getPayType() == 2){//支付宝
|
String[] split1 = ids.split(",");
|
resultUtil = payMoneyUtil.alipay("改派订单", "改派订单", "", ids + "_3_" + UUIDUtil.getRandomCode(5), totalMoney.toString(), "/base/aliReassign");
|
for(String id : split1){
|
paymentRecordService.saveData(1, uid, 2, Integer.valueOf(id), 3, 2, aDouble, "", 1);//添加预支付数据
|
}
|
}
|
if(reassign.getPayType() == 3){//余额
|
for(String id : split){
|
Reassign query = reassignMapper.query(uid, null, Integer.valueOf(id), 3, 1);
|
query.setState(2);
|
query.setPayTime(new Date());
|
reassignMapper.updateById(query);
|
//添加交易明细
|
transactionDetailsService.saveData(uid, "司机改派支付", aDouble, 2, 1, 2, 3, Integer.valueOf(id));
|
}
|
Double balance = driver.getBalance();
|
Double laveBusinessMoney = driver.getLaveBusinessMoney();
|
Double laveActivityMoney = driver.getLaveActivityMoney();
|
if(null == balance || balance < totalMoney){
|
throw new SystemException("账户余额不足");
|
}
|
if(null != laveBusinessMoney && laveBusinessMoney.compareTo(totalMoney) >= 0){
|
driver.setLaveBusinessMoney(new BigDecimal(laveBusinessMoney).subtract(new BigDecimal(totalMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}else if(null != laveActivityMoney && laveActivityMoney.compareTo(totalMoney) >= 0){
|
driver.setLaveActivityMoney(new BigDecimal(laveActivityMoney).subtract(new BigDecimal(totalMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
}
|
driver.setBalance(new BigDecimal(balance).subtract(new BigDecimal(totalMoney)).setScale(2, BigDecimal.ROUND_HALF_EVEN).doubleValue());
|
driverService.updateById(driver);
|
|
|
//修改改派通知状态
|
for(String id : split){
|
OrderCrossCity orderCrossCity = orderCrossCityService.selectById(id);
|
orderCrossCity.setOldState(orderCrossCity.getState());
|
orderCrossCity.setState(11);
|
orderCrossCity.setReassignNotice(2);
|
orderCrossCityService.updateById(orderCrossCity);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderCrossCity.getCompanyId(), 4, orderCrossCity.getId(), 3, reassign.getMoney());
|
}
|
systemNoticeService.addSystemNotice(2, "您已使用余额成功支付改派申请费用!", uid, 1);
|
//开始推送调度单
|
Map<String, String> map = new HashMap<>();
|
map.put("orderId", reassign.getOrderId().toString());
|
map.put("orderType", reassign.getOrderType().toString());
|
List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
|
for(Dispatch dispatch : dispatches){
|
jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
|
}
|
}
|
if(reassign.getPayType() == 4){
|
|
String[] split1 = ids.split(",");
|
resultUtil = placeAnOrder1(new BigDecimal(aDouble), 4,3,Integer.valueOf(split1[0]));
|
for(String id : split1){
|
// TODO 司机云闪付 跨城改派调起云闪付
|
paymentRecordService.saveData(1, uid, 2, Integer.valueOf(id), 3, 4, aDouble, "", 1);//添加预支付数据
|
}
|
}
|
}
|
return resultUtil;
|
}
|
|
|
|
|
/**
|
* 获取列表数据
|
* @param uid
|
* @param pageNum
|
* @param size
|
* @return
|
* @throws Exception
|
*/
|
@Override
|
public List<Map<String, Object>> queryList(Integer uid, Integer pageNum, Integer size) throws Exception {
|
pageNum = (pageNum - 1) * size;
|
return reassignMapper.queryList(uid, pageNum, size);
|
}
|
|
|
/**
|
* 改派支付完成后的操作
|
* @param id 改派单id
|
* @param order_id 工行支付订单
|
* @param type 1=微信,2=支付宝,4=云闪付
|
* @throws Exception
|
*/
|
@Override
|
public void payReassign(String id, String order_id, Integer type) throws Exception {
|
System.out.println("改派支付完成后的操作");
|
String[] s = id.split("_");
|
if(Integer.valueOf(s[1]) == 3){//跨城订单
|
System.out.println("跨城订单");
|
String[] split = s[0].split(",");
|
List<Reassign> reassigns = this.selectBatchIds(Arrays.asList(split));
|
Driver driver = driverService.selectById(reassigns.get(0).getOriginalDriverId());
|
for(String key : split){
|
PaymentRecord query = paymentRecordService.query(1, driver.getId(), 2, Integer.valueOf(key), 3, type, 1);
|
if(null != query){
|
System.out.println("跨城订单开始");
|
//添加交易明细
|
transactionDetailsService.saveData(reassigns.get(0).getOriginalDriverId(), "司机改派支付", reassigns.get(0).getMoney(), 2, 1, 2, 3, Integer.valueOf(key));
|
System.out.println("==============添加交易明细完毕===================");
|
for(Reassign reassign : reassigns){
|
reassign.setState(2);
|
reassign.setPayOrder(order_id);
|
reassign.setPayTime(new Date());
|
this.updateById(reassign);
|
//开始推送调度单
|
Map<String, String> map = new HashMap<>();
|
map.put("orderId", reassign.getOrderId().toString());
|
map.put("orderType", reassign.getOrderType().toString());
|
List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
|
for(Dispatch dispatch : dispatches){
|
jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
|
}
|
}
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
System.out.println("==============paymentRecord完毕==================="+query);
|
//修改改派通知状态
|
for(Reassign reassign : reassigns){
|
OrderCrossCity orderCrossCity1 = orderCrossCityService.selectById(reassign.getOrderId());
|
orderCrossCity1.setOldState(orderCrossCity1.getState());
|
orderCrossCity1.setState(11);
|
orderCrossCity1.setReassignNotice(2);
|
orderCrossCityService.updateById(orderCrossCity1);
|
System.out.println("==============跨城修改改派通知状态完毕==================="+orderCrossCity1);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderCrossCity1.getCompanyId(), 4, orderCrossCity1.getId(), 3, reassign.getMoney());
|
}
|
systemNoticeService.addSystemNotice(2, "您已使用" + (type == 1 ? "微信" : (type == 2?"支付宝":"云闪付")) + "成功支付改派申请费用!", reassigns.get(0).getOriginalDriverId(), 1);
|
System.out.println("==============跨城修改改派通知状态完毕===================");
|
}else{
|
System.err.println("预支付数据异常(orderId = " + id + ")");
|
}
|
}
|
|
|
}else{//其他订单
|
System.out.println("其他订单");
|
Reassign reassign = this.selectById(s[0]);
|
Driver driver = driverService.selectById(reassign.getOriginalDriverId());
|
PaymentRecord query = paymentRecordService.query(1, driver.getId(), 2, reassign.getOrderId(), reassign.getOrderType(), type, 1);
|
System.out.println("==============paymentRecord查询==================="+query);
|
if(null != query){
|
//添加交易明细
|
transactionDetailsService.saveData(reassign.getOriginalDriverId(), "司机改派支付", reassign.getMoney(), 2, 1, 2, reassign.getOrderType(), reassign.getOrderId());
|
reassign.setState(2);
|
reassign.setPayOrder(order_id);
|
reassign.setPayTime(new Date());
|
this.updateById(reassign);
|
|
query.setState(2);
|
query.setCode(order_id);
|
paymentRecordService.updateById(query);
|
System.out.println("==============paymentRecord完毕==================="+query);
|
|
//修改改派通知状态
|
switch (reassign.getOrderType()){
|
case 1:
|
OrderPrivateCar orderPrivateCar = orderPrivateCarService.selectById(reassign.getOrderId());
|
orderPrivateCar.setOldState(orderPrivateCar.getState());
|
orderPrivateCar.setState(11);
|
orderPrivateCar.setReassignNotice(2);
|
orderPrivateCarService.updateById(orderPrivateCar);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderPrivateCar.getCompanyId(), 4, orderPrivateCar.getId(), 1, reassign.getMoney());
|
System.out.println("==============快车完毕==================="+orderPrivateCar);
|
break;
|
case 2:
|
OrderTaxi orderTaxi = orderTaxiService.selectById(reassign.getOrderId());
|
orderTaxi.setOldState(orderTaxi.getState());
|
orderTaxi.setState(11);
|
orderTaxi.setReassignNotice(2);
|
orderTaxiService.updateById(orderTaxi);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderTaxi.getCompanyId(), 4, orderTaxi.getId(), 2, reassign.getMoney());
|
System.out.println("==============出租车完毕==================="+orderTaxi);
|
break;
|
case 4:
|
OrderLogistics orderLogistics = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics.setOldState(orderLogistics.getState());
|
orderLogistics.setState(11);
|
orderLogistics.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderLogistics.getCompanyId(), 4, orderLogistics.getId(), 4, reassign.getMoney());
|
System.out.println("==============物流订单完毕1==================="+orderLogistics);
|
break;
|
case 5:
|
OrderLogistics orderLogistics1 = orderLogisticsService.selectById(reassign.getOrderId());
|
orderLogistics1.setOldState(orderLogistics1.getState());
|
orderLogistics1.setState(11);
|
orderLogistics1.setReassignNotice(2);
|
orderLogisticsService.updateById(orderLogistics1);
|
|
//添加已收入明细
|
incomeService.saveData(1, orderLogistics1.getCompanyId(), 4, orderLogistics1.getId(), 5, reassign.getMoney());
|
System.out.println("==============物流订单完毕2==================="+orderLogistics1);
|
break;
|
}
|
systemNoticeService.addSystemNotice(2, "您已使用" + (type == 1 ? "微信" :(type == 2?"支付宝":"云闪付") ) + "成功支付改派申请费用!", reassign.getOriginalDriverId(), 1);
|
//开始推送调度单
|
Map<String, String> map = new HashMap<>();
|
map.put("orderId", reassign.getOrderId().toString());
|
map.put("orderType", reassign.getOrderType().toString());
|
List<Dispatch> dispatches = dispatchMapper.queryDispatchs(driver.getFranchiseeId() == null ? driver.getCompanyId() : driver.getFranchiseeId(), 1);
|
for(Dispatch dispatch : dispatches){
|
jgPushUtil.push(2,"有新的改派订单需要处理,请及时处理!", "订单改派", map, "DISPATCH" + dispatch.getId());
|
}
|
System.out.println("==============其他订单完毕===================");
|
}else{
|
System.err.println("预支付数据异常(orderId = " + id + ")");
|
}
|
}
|
|
|
}
|
}
|