|
|
|
@ -1,16 +1,17 @@ |
|
|
|
package cn.chjyj.szwh.service.impl; |
|
|
|
|
|
|
|
import cn.chjyj.szwh.bean.Goods; |
|
|
|
import cn.chjyj.szwh.bean.Order; |
|
|
|
import cn.chjyj.szwh.bean.OrderGoodsDetail; |
|
|
|
import cn.chjyj.szwh.bean.OrderUser; |
|
|
|
import cn.chjyj.szwh.mapper.GoodsMapper; |
|
|
|
import cn.chjyj.szwh.mapper.OrderGoodsDetailMapper; |
|
|
|
import cn.chjyj.szwh.mapper.OrderMapper; |
|
|
|
import cn.chjyj.szwh.mapper.OrderUserMapper; |
|
|
|
import cn.chjyj.szwh.bean.*; |
|
|
|
import cn.chjyj.szwh.constant.ChConstant; |
|
|
|
import cn.chjyj.szwh.mapper.*; |
|
|
|
import cn.chjyj.szwh.service.IndexService; |
|
|
|
import cn.chjyj.szwh.service.PayService; |
|
|
|
import cn.chjyj.szwh.utils.ProperUtils; |
|
|
|
import cn.chjyj.szwh.utils.RequestUtils; |
|
|
|
import cn.chjyj.szwh.utils.SzwhApiUtils; |
|
|
|
import cn.chjyj.szwh.utils.TaxUtils; |
|
|
|
import cn.chjyj.szwh.utils.pay.security.AesEncryption; |
|
|
|
import com.alibaba.fastjson2.JSON; |
|
|
|
import com.alibaba.fastjson2.JSONArray; |
|
|
|
import com.alibaba.fastjson2.JSONObject; |
|
|
|
import org.apache.commons.lang3.StringUtils; |
|
|
|
import org.apache.commons.logging.Log; |
|
|
|
@ -36,6 +37,8 @@ public class PayServiceImpl implements PayService { |
|
|
|
//商品信息
|
|
|
|
@Autowired |
|
|
|
private GoodsMapper goodsMapper; |
|
|
|
@Autowired |
|
|
|
private TicketMapper ticketMapper; |
|
|
|
|
|
|
|
/** |
|
|
|
* 关闭七日以前的已经支付了的订单 |
|
|
|
@ -67,9 +70,11 @@ public class PayServiceImpl implements PayService { |
|
|
|
if(order.getPayStatus()!=2){ |
|
|
|
// do nothing
|
|
|
|
} |
|
|
|
//订单状态
|
|
|
|
Integer status = order.getStatus(); |
|
|
|
Integer closeStatus= order.getCloseStatus(); |
|
|
|
Integer type =order.getType(); |
|
|
|
//查询购买用户
|
|
|
|
String buyIslicode = order.getBuyIslicode(); |
|
|
|
//购买用户
|
|
|
|
OrderUser oduser = orderUserMapper.getUserOrder(batchcode,buyIslicode); |
|
|
|
@ -77,11 +82,10 @@ public class PayServiceImpl implements PayService { |
|
|
|
Date paytime = order.getPaymenttime(); |
|
|
|
// 同步到其他平台
|
|
|
|
List syncList =new ArrayList<>(); |
|
|
|
//商品对应的合约编号
|
|
|
|
Map<Integer,String> ccmap = new HashMap(); |
|
|
|
//
|
|
|
|
Calendar cal= Calendar.getInstance(); |
|
|
|
|
|
|
|
// 分配比例设置及详情
|
|
|
|
|
|
|
|
|
|
|
|
//订单商品详情
|
|
|
|
List<OrderGoodsDetail> orderGoodsDetailList = orderGoodsDetailMapper.getOrderGoodsDetailByBatchCode(batchcode); |
|
|
|
for(OrderGoodsDetail odgd:orderGoodsDetailList){ |
|
|
|
@ -104,25 +108,105 @@ public class PayServiceImpl implements PayService { |
|
|
|
// }
|
|
|
|
//合约关联编码(订单交易isli标识码)
|
|
|
|
String contractcode=""; |
|
|
|
if(StringUtils.isEmpty(odgd.getContractCode())){ |
|
|
|
// $ratio_setting = AccountRatioSetting::where('is_deleted', 0)->where('status', 1)->find();
|
|
|
|
// $entrust_ratio_detail = AccountRatioDetail::where('setting_id', $ratio_setting->id)->where('role_type', 1)->find();
|
|
|
|
// $ratio = 0;
|
|
|
|
// $entrust_number = 0;
|
|
|
|
// if($entrust_ratio_detail['calculate'] == 1){
|
|
|
|
// $entrust_number = $entrust_ratio_detail['ratio'];
|
|
|
|
// }else{
|
|
|
|
// $entrust_number = $entrust_ratio_detail['amount'];
|
|
|
|
// }
|
|
|
|
// $ratio = round(1 - ($entrust_number / 100), 4);
|
|
|
|
if(StringUtils.isEmpty(odgd.getContractCode()) || "-".equals(odgd.getContractCode())){ |
|
|
|
String ratio="0.00"; |
|
|
|
// 远程获取查询对应的 islicode
|
|
|
|
SzwhApiUtils.getApplyLinkCode(odgd.getGoodsIslicode(),buyIslicode,ratio,transCount,dateStr,batchcode); |
|
|
|
JSONObject aplinkCodeJson=SzwhApiUtils.getApplyLinkCode(odgd.getGoodsIslicode(), |
|
|
|
buyIslicode,ratio,transCount,dateStr,batchcode); |
|
|
|
log.info("订单合约编号:"+aplinkCodeJson); |
|
|
|
JSONArray aparr = aplinkCodeJson.getJSONArray("data"); |
|
|
|
JSONObject lkcjson = (JSONObject) aparr.get(0); |
|
|
|
// 返回的值是 buyIslicode 为键名的内容
|
|
|
|
contractcode = lkcjson.getString(buyIslicode); |
|
|
|
}else{ |
|
|
|
contractcode = odgd.getContractCode(); |
|
|
|
} |
|
|
|
//合约关联编号,更新到订单商品详情中
|
|
|
|
Map ogdmap= new HashMap(); |
|
|
|
ogdmap.put("contract_code",contractcode); |
|
|
|
orderGoodsDetailMapper.updateOrderGoodsDetail(ogdmap,odgd.getId()); |
|
|
|
//订单商品详情id,为key, 合约编号为键值
|
|
|
|
ccmap.put(odgd.getId(),contractcode); |
|
|
|
|
|
|
|
//配置文件中读取渠道
|
|
|
|
String channelIsli = ProperUtils.getSzwhProp("CHANNEL_ISLI"); |
|
|
|
//构建同步map
|
|
|
|
Map syncmap = new HashMap(); |
|
|
|
syncmap.put("userId",buyIslicode); |
|
|
|
syncmap.put("requestIsliFlag",channelIsli); //渠道编号
|
|
|
|
syncmap.put("goodsIslicode",odgd.getGoodsIslicode()); |
|
|
|
syncmap.put("goodsName" ,odgd.getGoodsName()); |
|
|
|
syncmap.put("orderIslicode" ,contractcode); |
|
|
|
syncmap.put("batchcode",odgd.getBatchcode()); |
|
|
|
syncmap.put("chargesType",odgd.getMoney()); |
|
|
|
//委托周期
|
|
|
|
String entrmonth=odgd.getContractualPeriod()==1?"永久":"一次性"; |
|
|
|
syncmap.put("entrustMonth",entrmonth); |
|
|
|
//委托类型
|
|
|
|
String gentr = odgd.getGoodsEntrust()==1?"转让":"许可"; |
|
|
|
syncmap.put("goodsEntrust" ,gentr); |
|
|
|
syncmap.put("goodsOwnership",odgd.getGoodsOwnership()); |
|
|
|
//商品类型
|
|
|
|
String gtype =odgd.getGoodsType()==1?"文化资源数据":"文化数字内容"; |
|
|
|
syncmap.put("goodsType",gtype); |
|
|
|
syncmap.put("payStatus", 1); |
|
|
|
syncmap.put("closeStatus" ,closeStatus-1); |
|
|
|
syncmap.put("transactionCount",odgd.getTransactionCount()); |
|
|
|
//订单类型
|
|
|
|
String typeStr=""; |
|
|
|
switch (type){ |
|
|
|
case 1:typeStr="委托订单";break; |
|
|
|
case 2:typeStr="认证订单";break; |
|
|
|
default:typeStr="服务订单";break; |
|
|
|
} |
|
|
|
syncmap.put("type",typeStr); |
|
|
|
syncmap.put("buyUsername",buyName); |
|
|
|
syncmap.put("entrustIslicode" ,odgd.getEntrustIslicode()); |
|
|
|
//委托用户名
|
|
|
|
OrderUser orderUser = orderUserMapper.getUserOrder(odgd.getBatchcode(),odgd.getIslicode()); |
|
|
|
String entrustUsername = orderUser!=null?orderUser.getName():"-"; |
|
|
|
syncmap.put("entrustUsername",entrustUsername); |
|
|
|
//add to list
|
|
|
|
syncList.add(syncmap); |
|
|
|
} |
|
|
|
|
|
|
|
//list 转为json 发送到相关接口
|
|
|
|
JSONArray wsynarr = new JSONArray(syncList); |
|
|
|
//待同步过去的订单信息
|
|
|
|
String forsync = wsynarr.toJSONString(); |
|
|
|
JSONObject outSyncJson =SzwhApiUtils.synchInfo(forsync); |
|
|
|
log.info(batchcode+"订单获取下载地址:"+outSyncJson); |
|
|
|
//返回链接地址
|
|
|
|
if("00000000".equals(outSyncJson.getString("resultCode"))){ |
|
|
|
JSONArray syncArray = outSyncJson.getJSONArray("data"); |
|
|
|
//获取解密地址
|
|
|
|
JSONObject sjson = (JSONObject) syncArray.get(0); |
|
|
|
//资源下载地址
|
|
|
|
String sourceUrl= sjson.getString("source_url"); |
|
|
|
//替换,然后提取出基本的地址信息
|
|
|
|
String resUrl = sourceUrl.replace("{isliCode}/{contractISLICode}",""); |
|
|
|
log.info("source base url:"+resUrl); |
|
|
|
//遍历数据
|
|
|
|
for(OrderGoodsDetail ogd:orderGoodsDetailList){ |
|
|
|
//todo 检查 source_download 是否有内容
|
|
|
|
//请求依据同步订单信息返回的地址获取解密资源地址
|
|
|
|
JSONObject resJson = SzwhApiUtils.getDownOrdRes(resUrl,ogd.getIslicode(),ccmap.get(ogd.getId())); |
|
|
|
log.info(ogd.getId()+"资源解密地址:"+resJson); |
|
|
|
//更新订单商品资源详情
|
|
|
|
JSONArray ogdJarr = resJson.getJSONArray("data"); |
|
|
|
JSONObject togjson = (JSONObject) ogdJarr.get(0); |
|
|
|
// source_download map
|
|
|
|
JSONObject sdown = new JSONObject(); |
|
|
|
sdown.put("url",togjson.getString("url")); |
|
|
|
sdown.put("status",4); |
|
|
|
//合约关联编号,更新到订单商品详情中
|
|
|
|
Map togmap = new HashMap(); |
|
|
|
togmap.put("source_download",sdown.toString()); |
|
|
|
orderGoodsDetailMapper.updateOrderGoodsDetail(togmap,ogd.getId()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
@ -170,13 +254,12 @@ public class PayServiceImpl implements PayService { |
|
|
|
//更新订单指定字段
|
|
|
|
orderMapper.updateOrderStatus(upmap,order.getId()); |
|
|
|
} |
|
|
|
//订单信息发送至分发系统
|
|
|
|
|
|
|
|
// 处理订单其他信息
|
|
|
|
payFinishOperate(order.getBatchcode()); |
|
|
|
//买家发票信息等
|
|
|
|
invoiceBuyOperate(order.getBatchcode()); |
|
|
|
//卖家发票
|
|
|
|
// $this->payFinishOperate($batchcode);
|
|
|
|
// $this->invoiceBuyOperate($batchcode);
|
|
|
|
// $this->invoiceSellerOperate($batchcode);
|
|
|
|
invoiceSellerOperate(order.getBatchcode()); |
|
|
|
} |
|
|
|
|
|
|
|
}catch (Exception ex){ |
|
|
|
@ -184,4 +267,95 @@ public class PayServiceImpl implements PayService { |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* 买家发票信息 |
|
|
|
* @param bathcode |
|
|
|
* @return |
|
|
|
*/ |
|
|
|
@Override |
|
|
|
public int invoiceBuyOperate(String bathcode) { |
|
|
|
//发票存放路径
|
|
|
|
String pdfpath= ChConstant.INVOICE; |
|
|
|
//订单
|
|
|
|
Order order = orderMapper.getOrderByBatchcode(bathcode); |
|
|
|
//用户信息
|
|
|
|
OrderUser orderUser = orderUserMapper.getUserOrder(bathcode,order.getBuyIslicode()); |
|
|
|
//发票数据集合
|
|
|
|
Map invoiceMap = new HashMap(); |
|
|
|
invoiceMap.put("buyerName",orderUser.getName()); |
|
|
|
invoiceMap.put("buyerType","01"); //购买方类型01:企业
|
|
|
|
invoiceMap.put("buyerTaxNo",orderUser.getUscc());//税号
|
|
|
|
//订单商品详情
|
|
|
|
List <OrderGoodsDetail> ordglist = orderGoodsDetailMapper.getOrderGoodsDetailByBatchCode(bathcode); |
|
|
|
//发票信息
|
|
|
|
List taxlist = TaxUtils.TaxSpilt(ordglist,orderUser); |
|
|
|
//
|
|
|
|
for(int i=0;i<taxlist.size();i++){ |
|
|
|
//taxlist.get(i).add
|
|
|
|
String taxreq = JSONObject.toJSONString(taxlist.get(i)); |
|
|
|
//发送请求
|
|
|
|
JSONObject outTax = SzwhApiUtils.taxRequest(taxreq); |
|
|
|
//判断请求结果
|
|
|
|
if(outTax!=null){ |
|
|
|
if("S".equals(outTax.getString("operateCode"))){ |
|
|
|
JSONArray ottaxArr = outTax.getJSONArray("datas"); |
|
|
|
for(int o=1;o<ottaxArr.size();o++){ |
|
|
|
JSONObject tdjson = (JSONObject) ottaxArr.get(o); |
|
|
|
//下载pdf 文件到 对应目录
|
|
|
|
String dpdf = outTax.getString("pdfUrl"); |
|
|
|
//ticketid
|
|
|
|
Long ticketid = outTax.getLong("serialNo"); |
|
|
|
// 存储到本地
|
|
|
|
String path= RequestUtils.downTaxTicket(dpdf,ticketid+".pdfs"); |
|
|
|
//构建发票实体
|
|
|
|
Ticket ticket = new Ticket(); |
|
|
|
ticket.setBatchcode(bathcode); |
|
|
|
ticket.setIslicode(order.getBuyIslicode()); |
|
|
|
ticket.setTicketid(ticketid); |
|
|
|
//
|
|
|
|
String totalTax =outTax.getString("totalAmountTax"); |
|
|
|
ticket.setTicketmoney(new BigDecimal(totalTax)); |
|
|
|
ticket.setPdfurl(dpdf); |
|
|
|
//
|
|
|
|
ticket.setTicketStatus(3); |
|
|
|
ticket.setTickettime(new Date()); |
|
|
|
ticket.setTicketapimessage("-"); |
|
|
|
//插入记录
|
|
|
|
ticketMapper.addTicket(ticket); |
|
|
|
} |
|
|
|
}else{ //
|
|
|
|
//构建发票实体
|
|
|
|
Ticket ticket = new Ticket(); |
|
|
|
ticket.setBatchcode(bathcode); |
|
|
|
ticket.setIslicode(order.getBuyIslicode()); |
|
|
|
ticket.setTicketid(0l); |
|
|
|
//
|
|
|
|
String totalTax =outTax.getString("totalAmountTax"); |
|
|
|
ticket.setTicketmoney(new BigDecimal(totalTax)); |
|
|
|
//
|
|
|
|
JSONArray ottaxArr = outTax.getJSONArray("datas"); |
|
|
|
for(int x=0;x<ottaxArr.size();x++){ |
|
|
|
JSONObject xjson = (JSONObject) ottaxArr.get(x); |
|
|
|
ticket.setPdfurl(xjson.getString("pdfUrl")); |
|
|
|
} |
|
|
|
|
|
|
|
//
|
|
|
|
ticket.setTicketStatus(4); |
|
|
|
ticket.setTickettime(new Date()); |
|
|
|
ticket.setTicketapimessage(outTax.getString("message")); |
|
|
|
//insert into
|
|
|
|
ticketMapper.addTicket(ticket); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
@Override |
|
|
|
public int invoiceSellerOperate(String bathcode) { |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|