Commit ad5e2b8b authored by Quxl's avatar Quxl

x

parent 9371178b
package com.egolm.shop.controller;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.DateUtil;
import com.egolm.common.FileUtil;
import com.egolm.common.HttpUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.Page;
import com.egolm.shop.service.OrderService;
import com.egolm.shop.util.XmlUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
@Api(tags={"订单相关接口"})
@RestController
@RequestMapping("order")
public class OrderController {
@Autowired
private OrderService orderService;
@Value("${wx.md5Key}")
private String md5Key;
@ApiOperation("订单提交前检查")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="shopNO", dataType = "String", required = true, value = "店铺编号"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = false, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/check",method=RequestMethod.GET)
public String check(HttpServletRequest request) {
String shopNO = request.getParameter("shopNO");
String terminal = request.getParameter("terminal");
String langID = request.getParameter("langID");
Map<String,Object> params = new HashMap<String,Object>();
params.put("shopNO", shopNO);
params.put("terminal", terminal);
params.put("langID", langID);
return orderService.orderCheck(params);
}
@ApiOperation("订单正式提交(JSON格式)")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="data", dataType = "String", required = false, value = "JSON格式", defaultValue = "{\"shopNO\": \"00029975\",\"terminal\": \"wechat\",\"langID\": \"936\",\"payTypeID\":1,\"addrID\":\"111111\",\"orderMemo\":\"备注\",\"couponNO\":\"\",\"couponTypeID\":\"\", \"bankType\": \"xxx\", 'bankAccount': 'xxx', 'bankAccountName': 'xxx', 'revBankType': 'xxx', 'revBankAccount': 'xxx', 'revBankAccountNo': 'xxx', 'formId': 'xxx', 'email': 'xxx', 'salesmanNo': 'xxx'}"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = false, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/submit",method=RequestMethod.POST,produces = "application/json")
public String submit(HttpServletRequest request) {
String reqJson = request.getParameter("data");
JSONObject jsonObj = JSONObject.parseObject(reqJson);
System.out.println("submit-------"+reqJson);
return orderService.submit(jsonObj);
}
@ApiOperation("获取主订单列表")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="orgNo", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name="shopNo", dataType = "String", required = true, value = "店铺编号"),
@ApiImplicitParam(paramType = "query", name="status", dataType = "int", required = true, value = "订单状态 0.全部 1. 待付款 2.待审核 3.待发货 4.已发货 5.已完成 6.已取消"),
@ApiImplicitParam(paramType = "query", name="orderType", dataType = "int", required = true, value = "订单类型 1正常 2门店装饰 3众筹", allowMultiple=true),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
@ApiImplicitParam(paramType = "query", name = "index", dataType = "String", required = true, value = "第几页", defaultValue = "1"),
@ApiImplicitParam(paramType = "query", name = "limit", dataType = "String", required = true, value = "每页数量", defaultValue = "20"),
})
@RequestMapping(value = "/getOrderList",method=RequestMethod.GET)
public String getOrderList(String orgNo, String shopNo, Integer status, Integer[] orderType, String langID, Integer index, Integer limit) {
List<String> types = new ArrayList<String>();
if(orderType != null) {
for(Integer id : orderType) {
if(id != null) {
types.add("" + id);
}
}
}
Page page = new Page();
page.setIndex(Long.valueOf(index));
page.setLimit(Long.valueOf(limit));
page.setLimitKey("dOrderTime desc");
return orderService.queryOrderList(orgNo, shopNo, status, types.toArray(new String[types.size()]), langID, page);
}
@ApiOperation("获取主订单详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="salesOrderId", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/getOrderDetail",method=RequestMethod.GET)
public String getOrderDetail(String salesOrderId, String langID, Integer index, Integer limit) {
return orderService.getOrderDetail(salesOrderId);
}
@ApiOperation("获取子订单列表及详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="salesOrderId", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/getSubOrderList",method=RequestMethod.GET)
public String getSubOrderList(String salesOrderId) {
return orderService.queryOrderDetailList(salesOrderId);
}
@ApiOperation("获取子订单详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="subOrderID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/getSubOrderDetail",method=RequestMethod.GET)
public String getSubOrderDetail(String subOrderID) {
return orderService.getSubOrderDetail(subOrderID);
}
@ApiOperation("获取送货单详情")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="aocOrderID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/getDeliverSubDetail",method=RequestMethod.GET)
public String getDeliverSubDetail(String aocOrderID) {
List<Map<String, Object>> list = orderService.getDeliverSubDetail(aocOrderID);
return Rjx.jsonOk().setData(list).toJson();
}
@ApiOperation("小程序在线支付交易成功通知支付状态")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="nPayAmount", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name="sOpenID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name="sTransTraceNO", dataType = "String", required = true, value="微信支付订单号"),
@ApiImplicitParam(paramType = "query", name="sOutTradeNO", dataType = "String", required = true, value="商户支付单号"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/paySuccess",method=RequestMethod.GET)
public String paySuccess(BigDecimal nPayAmount, String sOpenID, String sTransTraceNO, String sOutTradeNO) {
try {
String[] ary = sOutTradeNO.split("_", 2);
orderService.paySuccess(ary[0], nPayAmount, sOpenID, sTransTraceNO, sOutTradeNO, new Date());
return Rjx.jsonOk().toJson();
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().setMessage(e.getMessage()).toJson();
}
}
@ApiOperation("微信小程序支付回调")
@RequestMapping(value = "/wxPayNotify",method= {RequestMethod.GET, RequestMethod.POST})
public String wxPayNotify(HttpServletRequest request) {
Map<String, String> result = new HashMap<String, String>();
try {
InputStream instream = request.getInputStream();
byte[] bytes = FileUtil.streamToBytes(instream);
String inputXmlString = new String(bytes, "utf-8");
System.out.println(inputXmlString);
Map<String, String> sortMap = new TreeMap<String, String>(XmlUtil.toMap(inputXmlString));
String sign = sortMap.remove("sign");
String queryString = HttpUtil.formatToQueryString(sortMap) + "&key=" + md5Key;
String _sign = StringUtil.toMD5HexString(queryString).toUpperCase();
if(_sign.equals(sign)) {
String result_code = sortMap.get("result_code");
String return_code = sortMap.get("return_code");
if("SUCCESS".equals(return_code) && "SUCCESS".equals(result_code)) {
String out_trade_no = sortMap.get("out_trade_no");
String[] ary = out_trade_no.split("_", 2);
String transaction_id = sortMap.get("transaction_id");
String payEndTime = sortMap.get("time_end");
String openid = sortMap.get("openid");
String total_fee = sortMap.get("total_fee");
String sSalesOrderID = ary[0];
String sTransTraceNO = transaction_id;
String sOpenID = openid;
String sOutTradeNO = out_trade_no;
Date date = DateUtil.parse(payEndTime, "yyyyMMddHHmmss");
BigDecimal nPayAmount = new BigDecimal(total_fee);
orderService.paySuccess(sSalesOrderID, nPayAmount, sOpenID, sTransTraceNO, sOutTradeNO, date);
}
result.put("return_code", "SUCCESS");
result.put("return_msg", "OK");
} else {
result.put("return_code", "FAIL");
result.put("return_msg", "签名校验失败");
}
} catch (Throwable e) {
e.printStackTrace();
result.put("return_code", "FAIL");
result.put("return_msg", e.getMessage());
}
return XmlUtil.toXml(result);
}
@Transactional
@ApiOperation("取消未付款订单")
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="sSalesOrderID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
@RequestMapping(value = "/cancelOrder",method=RequestMethod.GET)
public String cancelOrder(String sSalesOrderID) {
orderService.cancelOrder(sSalesOrderID);
return Rjx.jsonOk().toJson();
}
@ApiOperation("提交组合促销订单")
@RequestMapping(value = "/submitByGroup",method=RequestMethod.GET)
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="orgNo", dataType = "String", required = true, value="sOrgNO"),
@ApiImplicitParam(paramType = "query", name="shopNo", dataType = "String", required = true, value="店铺编号"),
@ApiImplicitParam(paramType = "query", name="promoPaperNO", dataType = "String", required = true, value="活动编号"),
@ApiImplicitParam(paramType = "query", name="promoGroupNO", dataType = "String", required = true, value="组合编号"),
@ApiImplicitParam(paramType = "query", name="saleQty", dataType = "String", required = true, value="组合数量"),
@ApiImplicitParam(paramType = "query", name="addrId", dataType = "String", required = true, value="地址ID"),
@ApiImplicitParam(paramType = "query", name="payTypeId", dataType = "String", required = true, value="支付类型: 1.货到付款 4.在线支付 2.线下转账"),
@ApiImplicitParam(paramType = "query", name="salesmanNo", dataType = "String", required = true, value="业务员"),
@ApiImplicitParam(paramType = "query", name="formId", dataType = "String", required = true, value=""),
@ApiImplicitParam(paramType = "query", name="bankType", dataType = "String", required = true, value="银行"),
@ApiImplicitParam(paramType = "query", name="bankAccount", dataType = "String", required = true, value="银行账号"),
@ApiImplicitParam(paramType = "query", name="bankAccountName", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankType", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankAccount", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankAccountNo", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="memo", dataType = "String", required = true, value="备注"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
public String submitByGroup(String orgNo, String shopNo, String promoPaperNO, String promoGroupNO, Integer saleQty, String addrId, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo) {
String sSalesOrderID = orderService.submitByGroup(orgNo, shopNo, promoPaperNO, promoGroupNO, saleQty, addrId, payTypeId, terminal, salesmanNo, formId, bankType, bankAccount, bankAccountName, revBankType, revBankAccount, revBankAccountNo, memo);
return Rjx.jsonOk().set("sSalesOrderID", sSalesOrderID).toJson();
}
@ApiOperation("提交众筹订单")
@RequestMapping(value = "/submitByZhc",method=RequestMethod.GET)
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="orgNo", dataType = "String", required = true, value="sOrgNO"),
@ApiImplicitParam(paramType = "query", name="shopNo", dataType = "String", required = true, value="店铺编号"),
@ApiImplicitParam(paramType = "query", name="planId", dataType = "int", required = true, value="众筹计划ID"),
@ApiImplicitParam(paramType = "query", name="saleQty", dataType = "String", required = true, value="购买数量"),
@ApiImplicitParam(paramType = "query", name="addrId", dataType = "String", required = true, value="地址ID"),
@ApiImplicitParam(paramType = "query", name="salesmanNo", dataType = "String", required = true, value="业务员"),
@ApiImplicitParam(paramType = "query", name="payTypeId", dataType = "String", required = true, value="支付类型: 1.货到付款 4.在线支付 2.线下转账"),
@ApiImplicitParam(paramType = "query", name="formId", dataType = "String", required = true, value=""),
@ApiImplicitParam(paramType = "query", name="bankType", dataType = "String", required = true, value="银行"),
@ApiImplicitParam(paramType = "query", name="bankAccount", dataType = "String", required = true, value="银行账号"),
@ApiImplicitParam(paramType = "query", name="bankAccountName", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankType", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankAccount", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankAccountNo", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="memo", dataType = "String", required = true, value="备注"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
public String submitByZhc(String orgNo, String shopNo, Integer planId, Integer saleQty, String addrId, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo) {
String sSalesOrderID = orderService.submitByZhc(orgNo, shopNo, planId, saleQty, addrId, payTypeId, terminal, salesmanNo, formId, bankType, bankAccount, bankAccountName, revBankType, revBankAccount, revBankAccountNo, memo);
return Rjx.jsonOk().set("sSalesOrderID", sSalesOrderID).toJson();
}
@ApiOperation("提交门店装饰订单")
@RequestMapping(value = "/submitByMdzs",method=RequestMethod.GET)
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="orgNo", dataType = "String", required = true, value="sOrgNO"),
@ApiImplicitParam(paramType = "query", name="shopNo", dataType = "String", required = true, value="店铺编号"),
@ApiImplicitParam(paramType = "query", name="contractNo", dataType = "string", required = true, value="经销商合同编号 sAgentContractNO"),
@ApiImplicitParam(paramType = "query", name="goodsId", dataType = "int", required = true, value="商品ID"),
@ApiImplicitParam(paramType = "query", name="saleQty", dataType = "String", required = true, value="购买数量"),
@ApiImplicitParam(paramType = "query", name="addrId", dataType = "String", required = true, value="地址ID"),
@ApiImplicitParam(paramType = "query", name="email", dataType = "String", required = true, value="邮箱"),
@ApiImplicitParam(paramType = "query", name="salesmanNo", dataType = "String", required = true, value="业务员"),
@ApiImplicitParam(paramType = "query", name="payTypeId", dataType = "String", required = true, value="支付类型: 1.货到付款 4.在线支付 2.线下转账"),
@ApiImplicitParam(paramType = "query", name="formId", dataType = "String", required = true, value=""),
@ApiImplicitParam(paramType = "query", name="bankType", dataType = "String", required = true, value="银行"),
@ApiImplicitParam(paramType = "query", name="bankAccount", dataType = "String", required = true, value="银行账号"),
@ApiImplicitParam(paramType = "query", name="bankAccountName", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankType", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankAccount", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="revBankAccountNo", dataType = "String"),
@ApiImplicitParam(paramType = "query", name="memo", dataType = "String", required = true, value="备注"),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
public String submitByMdzs(String orgNo, String shopNo, String contractNo, Integer goodsId, Integer saleQty, String addrId, String email, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo) {
String sSalesOrderID = orderService.submitByMdzs(orgNo, shopNo, contractNo, goodsId, saleQty, addrId, email, payTypeId, terminal, salesmanNo, formId, bankType, bankAccount, bankAccountName, revBankType, revBankAccount, revBankAccountNo, memo);
return Rjx.jsonOk().set("sSalesOrderID", sSalesOrderID).toJson();
}
@ApiOperation("确认收货")
@RequestMapping(value = "/confirmReceipt",method=RequestMethod.GET)
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", name="custNo", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name="subOrderID", dataType = "String", required = true),
@ApiImplicitParam(paramType = "query", name = "terminal", dataType = "String", required = true, value = "终端标识", defaultValue = "wechat"),
@ApiImplicitParam(paramType = "query", name = "langID", dataType = "String", required = true, value = "语言", defaultValue = "936"),
})
public String confirmReceipt(String custNo, String subOrderID) {
orderService.confirmReceipt(custNo, subOrderID);
return Rjx.jsonOk().toJson();
}
}
package com.egolm.shop.pojo.model;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Entity;
@Entity(name="tSalesOrder")
public class TSalesOrder {
private String sSalesOrderID;
private String sOrgNO;
private String sCustNO;
private String sShopNO;
private String sSalesOrderPayTypeID;
private String sSalesOrderPayType;
private Date dOrderDate;
private Date dOrderTime;
private BigDecimal nTotalSaleQty;
private BigDecimal nTotalSaleAmount;
private BigDecimal nTotalDisAmount;
private String sTerminalTypeID;
private String sTerminalType;
private Date dOrderCancelTime;
private String sOrderCancelRemark;
private String sOrderCancelUser;
private String sAddrID;
private String sContacts;
private String sMobile;
private String sTel;
private String sAddress;
private String sPostalcode;
private String sEmail;
private String sOrderMemo;
private String sThirdPartyPaperNO;
private String sThirdPartyID;
private String sThirdPartyName;
private Integer nOrderStatus;
private String sOrderStatusName;
private Date dUpdate;
private Integer nTag;
private Date dLastUpdateTime;
private String sSubOrderID;
private String sSalesmanNO;
private BigDecimal nExpressFee;
private String sDeliveryTypeID;
private String sDeliveryType;
private String sBankType;
private String sBankAccount;
private String sBankAccountName;
private String sRevBankType;
private String sRevBankAccount;
private String sRevBankAccountNO;
private String sFormID;
private String sB2BOrderTypeID;
private String sB2BOrderType;
private Integer nPlanID;
public Integer getnPlanID() {
return nPlanID;
}
public void setnPlanID(Integer nPlanID) {
this.nPlanID = nPlanID;
}
public String getsSalesOrderID() {
return sSalesOrderID;
}
public void setsSalesOrderID(String sSalesOrderID) {
this.sSalesOrderID = sSalesOrderID;
}
public String getsOrgNO() {
return sOrgNO;
}
public void setsOrgNO(String sOrgNO) {
this.sOrgNO = sOrgNO;
}
public String getsCustNO() {
return sCustNO;
}
public void setsCustNO(String sCustNO) {
this.sCustNO = sCustNO;
}
public String getsShopNO() {
return sShopNO;
}
public void setsShopNO(String sShopNO) {
this.sShopNO = sShopNO;
}
public String getsSalesOrderPayTypeID() {
return sSalesOrderPayTypeID;
}
public void setsSalesOrderPayTypeID(String sSalesOrderPayTypeID) {
this.sSalesOrderPayTypeID = sSalesOrderPayTypeID;
}
public String getsSalesOrderPayType() {
return sSalesOrderPayType;
}
public void setsSalesOrderPayType(String sSalesOrderPayType) {
this.sSalesOrderPayType = sSalesOrderPayType;
}
public Date getdOrderDate() {
return dOrderDate;
}
public void setdOrderDate(Date dOrderDate) {
this.dOrderDate = dOrderDate;
}
public Date getdOrderTime() {
return dOrderTime;
}
public void setdOrderTime(Date dOrderTime) {
this.dOrderTime = dOrderTime;
}
public BigDecimal getnTotalSaleQty() {
return nTotalSaleQty;
}
public void setnTotalSaleQty(BigDecimal nTotalSaleQty) {
this.nTotalSaleQty = nTotalSaleQty;
}
public BigDecimal getnTotalSaleAmount() {
return nTotalSaleAmount;
}
public void setnTotalSaleAmount(BigDecimal nTotalSaleAmount) {
this.nTotalSaleAmount = nTotalSaleAmount;
}
public BigDecimal getnTotalDisAmount() {
return nTotalDisAmount;
}
public void setnTotalDisAmount(BigDecimal nTotalDisAmount) {
this.nTotalDisAmount = nTotalDisAmount;
}
public String getsTerminalTypeID() {
return sTerminalTypeID;
}
public void setsTerminalTypeID(String sTerminalTypeID) {
this.sTerminalTypeID = sTerminalTypeID;
}
public String getsTerminalType() {
return sTerminalType;
}
public void setsTerminalType(String sTerminalType) {
this.sTerminalType = sTerminalType;
}
public Date getdOrderCancelTime() {
return dOrderCancelTime;
}
public void setdOrderCancelTime(Date dOrderCancelTime) {
this.dOrderCancelTime = dOrderCancelTime;
}
public String getsOrderCancelRemark() {
return sOrderCancelRemark;
}
public void setsOrderCancelRemark(String sOrderCancelRemark) {
this.sOrderCancelRemark = sOrderCancelRemark;
}
public String getsOrderCancelUser() {
return sOrderCancelUser;
}
public void setsOrderCancelUser(String sOrderCancelUser) {
this.sOrderCancelUser = sOrderCancelUser;
}
public String getsAddrID() {
return sAddrID;
}
public void setsAddrID(String sAddrID) {
this.sAddrID = sAddrID;
}
public String getsContacts() {
return sContacts;
}
public void setsContacts(String sContacts) {
this.sContacts = sContacts;
}
public String getsMobile() {
return sMobile;
}
public void setsMobile(String sMobile) {
this.sMobile = sMobile;
}
public String getsTel() {
return sTel;
}
public void setsTel(String sTel) {
this.sTel = sTel;
}
public String getsAddress() {
return sAddress;
}
public void setsAddress(String sAddress) {
this.sAddress = sAddress;
}
public String getsPostalcode() {
return sPostalcode;
}
public void setsPostalcode(String sPostalcode) {
this.sPostalcode = sPostalcode;
}
public String getsEmail() {
return sEmail;
}
public void setsEmail(String sEmail) {
this.sEmail = sEmail;
}
public String getsOrderMemo() {
return sOrderMemo;
}
public void setsOrderMemo(String sOrderMemo) {
this.sOrderMemo = sOrderMemo;
}
public String getsThirdPartyPaperNO() {
return sThirdPartyPaperNO;
}
public void setsThirdPartyPaperNO(String sThirdPartyPaperNO) {
this.sThirdPartyPaperNO = sThirdPartyPaperNO;
}
public String getsThirdPartyID() {
return sThirdPartyID;
}
public void setsThirdPartyID(String sThirdPartyID) {
this.sThirdPartyID = sThirdPartyID;
}
public String getsThirdPartyName() {
return sThirdPartyName;
}
public void setsThirdPartyName(String sThirdPartyName) {
this.sThirdPartyName = sThirdPartyName;
}
public Integer getnOrderStatus() {
return nOrderStatus;
}
public void setnOrderStatus(Integer nOrderStatus) {
this.nOrderStatus = nOrderStatus;
}
public String getsOrderStatusName() {
return sOrderStatusName;
}
public void setsOrderStatusName(String sOrderStatusName) {
this.sOrderStatusName = sOrderStatusName;
}
public Date getdUpdate() {
return dUpdate;
}
public void setdUpdate(Date dUpdate) {
this.dUpdate = dUpdate;
}
public Integer getnTag() {
return nTag;
}
public void setnTag(Integer nTag) {
this.nTag = nTag;
}
public Date getdLastUpdateTime() {
return dLastUpdateTime;
}
public void setdLastUpdateTime(Date dLastUpdateTime) {
this.dLastUpdateTime = dLastUpdateTime;
}
public String getsSubOrderID() {
return sSubOrderID;
}
public void setsSubOrderID(String sSubOrderID) {
this.sSubOrderID = sSubOrderID;
}
public String getsSalesmanNO() {
return sSalesmanNO;
}
public void setsSalesmanNO(String sSalesmanNO) {
this.sSalesmanNO = sSalesmanNO;
}
public BigDecimal getnExpressFee() {
return nExpressFee;
}
public void setnExpressFee(BigDecimal nExpressFee) {
this.nExpressFee = nExpressFee;
}
public String getsDeliveryTypeID() {
return sDeliveryTypeID;
}
public void setsDeliveryTypeID(String sDeliveryTypeID) {
this.sDeliveryTypeID = sDeliveryTypeID;
}
public String getsDeliveryType() {
return sDeliveryType;
}
public void setsDeliveryType(String sDeliveryType) {
this.sDeliveryType = sDeliveryType;
}
public String getsBankType() {
return sBankType;
}
public void setsBankType(String sBankType) {
this.sBankType = sBankType;
}
public String getsBankAccount() {
return sBankAccount;
}
public void setsBankAccount(String sBankAccount) {
this.sBankAccount = sBankAccount;
}
public String getsFormID() {
return sFormID;
}
public void setsFormID(String sFormID) {
this.sFormID = sFormID;
}
public String getsB2BOrderTypeID() {
return sB2BOrderTypeID;
}
public void setsB2BOrderTypeID(String sB2BOrderTypeID) {
this.sB2BOrderTypeID = sB2BOrderTypeID;
}
public String getsB2BOrderType() {
return sB2BOrderType;
}
public void setsB2BOrderType(String sB2BOrderType) {
this.sB2BOrderType = sB2BOrderType;
}
public String getsBankAccountName() {
return sBankAccountName;
}
public void setsBankAccountName(String sBankAccountName) {
this.sBankAccountName = sBankAccountName;
}
public String getsRevBankType() {
return sRevBankType;
}
public void setsRevBankType(String sRevBankType) {
this.sRevBankType = sRevBankType;
}
public String getsRevBankAccount() {
return sRevBankAccount;
}
public void setsRevBankAccount(String sRevBankAccount) {
this.sRevBankAccount = sRevBankAccount;
}
public String getsRevBankAccountNO() {
return sRevBankAccountNO;
}
public void setsRevBankAccountNO(String sRevBankAccountNO) {
this.sRevBankAccountNO = sRevBankAccountNO;
}
}
package com.egolm.shop.pojo.model;
import java.math.BigDecimal;
import java.util.Date;
import javax.persistence.Entity;
@Entity(name="tSalesOrderDtl")
public class TSalesOrderDtl {
private String sSalesOrderID;
private Integer nIdx;
private String sAgentContractNO;
private Integer nAgentID;
private String sWarehouseNO;
private String sBarcode;
private Integer nGoodsID;
private String sGoodsDesc;
private BigDecimal nSaleQty;
private BigDecimal nSalePrice;
private BigDecimal nSaleAmount;
private BigDecimal nDisAmount;
private String sMemo;
private Date dUpdate;
private Integer nTag;
private Date dLastUpdateTime;
private String sPromoActionTypeID;
private String sPromoActionType;
private String sPromoPaperNO;
private BigDecimal nExpressFee;
public String getsSalesOrderID() {
return sSalesOrderID;
}
public void setsSalesOrderID(String sSalesOrderID) {
this.sSalesOrderID = sSalesOrderID;
}
public Integer getnIdx() {
return nIdx;
}
public void setnIdx(Integer nIdx) {
this.nIdx = nIdx;
}
public String getsAgentContractNO() {
return sAgentContractNO;
}
public void setsAgentContractNO(String sAgentContractNO) {
this.sAgentContractNO = sAgentContractNO;
}
public Integer getnAgentID() {
return nAgentID;
}
public void setnAgentID(Integer nAgentID) {
this.nAgentID = nAgentID;
}
public String getsWarehouseNO() {
return sWarehouseNO;
}
public void setsWarehouseNO(String sWarehouseNO) {
this.sWarehouseNO = sWarehouseNO;
}
public String getsBarcode() {
return sBarcode;
}
public void setsBarcode(String sBarcode) {
this.sBarcode = sBarcode;
}
public Integer getnGoodsID() {
return nGoodsID;
}
public void setnGoodsID(Integer nGoodsID) {
this.nGoodsID = nGoodsID;
}
public String getsGoodsDesc() {
return sGoodsDesc;
}
public void setsGoodsDesc(String sGoodsDesc) {
this.sGoodsDesc = sGoodsDesc;
}
public BigDecimal getnSaleQty() {
return nSaleQty;
}
public void setnSaleQty(BigDecimal nSaleQty) {
this.nSaleQty = nSaleQty;
}
public BigDecimal getnSalePrice() {
return nSalePrice;
}
public void setnSalePrice(BigDecimal nSalePrice) {
this.nSalePrice = nSalePrice;
}
public BigDecimal getnSaleAmount() {
return nSaleAmount;
}
public void setnSaleAmount(BigDecimal nSaleAmount) {
this.nSaleAmount = nSaleAmount;
}
public BigDecimal getnDisAmount() {
return nDisAmount;
}
public void setnDisAmount(BigDecimal nDisAmount) {
this.nDisAmount = nDisAmount;
}
public String getsMemo() {
return sMemo;
}
public void setsMemo(String sMemo) {
this.sMemo = sMemo;
}
public Date getdUpdate() {
return dUpdate;
}
public void setdUpdate(Date dUpdate) {
this.dUpdate = dUpdate;
}
public Integer getnTag() {
return nTag;
}
public void setnTag(Integer nTag) {
this.nTag = nTag;
}
public Date getdLastUpdateTime() {
return dLastUpdateTime;
}
public void setdLastUpdateTime(Date dLastUpdateTime) {
this.dLastUpdateTime = dLastUpdateTime;
}
public String getsPromoActionTypeID() {
return sPromoActionTypeID;
}
public void setsPromoActionTypeID(String sPromoActionTypeID) {
this.sPromoActionTypeID = sPromoActionTypeID;
}
public String getsPromoActionType() {
return sPromoActionType;
}
public void setsPromoActionType(String sPromoActionType) {
this.sPromoActionType = sPromoActionType;
}
public String getsPromoPaperNO() {
return sPromoPaperNO;
}
public void setsPromoPaperNO(String sPromoPaperNO) {
this.sPromoPaperNO = sPromoPaperNO;
}
public BigDecimal getnExpressFee() {
return nExpressFee;
}
public void setnExpressFee(BigDecimal nExpressFee) {
this.nExpressFee = nExpressFee;
}
}
package com.egolm.shop.service;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.jdbc.Page;
public interface OrderService {
public String orderCheck(Map<String,Object> params);
public String submit(JSONObject submitObj);
public String queryOrderList(String orgNo, String shopNo, Integer status, String[] orderType, String langID, Page page);
public String queryOrderDetailList(String salesOrderId);
public String getOrderDetail(String salesOrderId);
public void paySuccess(String sSalesOrderID, BigDecimal nPayAmount, String sOpenID, String sTransTraceNO, String sOutTradeNO, Date dPayDateTime);
public String getSubOrderDetail(String subOrderID);
public void cancelOrder(String sSalesOrderID);
public String submitByGroup(String orgNo, String shopNo, String prompPaperNO, String promoGroupNO, Integer saleQty, String addrId, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo);
public String submitByZhc(String orgNo, String shopNo, Integer planId, Integer saleQty, String addrId, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo);
public String submitByMdzs(String orgNo, String shopNo, String contractNo, Integer goodsId, Integer saleQty, String addrId, String email, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo);
public void confirmReceipt(String custNo, String subOrderID);
public List<Map<String, Object>> getDeliverSubDetail(String aocOrderID);
}
package com.egolm.shop.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.UncategorizedSQLException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.DateUtil;
import com.egolm.common.StringUtil;
import com.egolm.common.Util;
import com.egolm.common.bean.Rjx;
import com.egolm.common.jdbc.JdbcTemplate;
import com.egolm.common.jdbc.Page;
import com.egolm.common.jdbc.dialect.Dialect;
import com.egolm.common.jdbc.dialect.SqlServerDialect;
import com.egolm.common.jdbc.dialect.bean.Sql;
import com.egolm.shop.config.XException;
import com.egolm.shop.pojo.model.TSalesOrder;
import com.egolm.shop.pojo.model.TSalesOrderDtl;
import com.egolm.shop.service.OrderService;
import com.egolm.shop.util.I18NUtils;
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private JdbcTemplate jdbcTemplate;
/**
* 订单检查
* <p>Title: orderCheck</p>
* <p>Description: </p>
* @param params
* @return
* @see com.egolm.oms.service.OrderService#orderCheck(java.util.Map)
*/
public String orderCheck(Map<String,Object> params) {
jdbcTemplate.setDialect(new SqlServerDialect());
String LangID = params.get("langID")+"";
try {
Rjx rjx;
String shopNO = params.get("shopNO")+"";
String terminal = params.get("terminal")+"";
String sql="exec up_NewCreateCartTempItem '"+shopNO+"','"+terminal+"' ";
List<Map<String ,Object>> resultMap=jdbcTemplate.executeMutil(sql).getDatas().get(0);
System.out.println(sql);
if (Util.objTo(resultMap.get(0).get("Status"), Integer.class) == 0 && Util.objTo(resultMap.get(resultMap.size()-1).get("Status"), Integer.class) == 0) {
rjx = Rjx.jsonOk();
rjx.setData(resultMap);
} else {
rjx = Rjx.jsonErr();
}
return rjx.toJson();
} catch(UncategorizedSQLException se) {
String errorFullMsg = se.getMessage();
String key = "com.microsoft.sqlserver.jdbc.SQLServerException:";
String errorSubMsg = errorFullMsg.substring(errorFullMsg.lastIndexOf(key)+key.length(), errorFullMsg.length());
System.out.println(errorFullMsg);
System.out.println(errorSubMsg);
return Rjx.jsonErr().setMessage(I18NUtils.getMessage(LangID, "Msg_Submit_Goods_error")).set("result", errorSubMsg).toJson();
}catch (Exception e) {
System.out.println("e...."+e.getMessage());
e.printStackTrace();
return Rjx.jsonErr().setMessage(I18NUtils.getMessage(LangID, "Msg_Submit_Goods_failure")).toJson();
}
}
/**
*
* @Title: submit
* @Description: 提交订单
* @param: @param submitObj
* @param: @return
* @return: String
* @throws
*/
public String submit(JSONObject submitObj) {
jdbcTemplate.setDialect(new SqlServerDialect());
String LangID=""+submitObj.get("langID");
try {
String shopNO=""+submitObj.get("shopNO");
String payID=""+submitObj.get("payTypeID");
String terminalTypeID=""+submitObj.get("terminal");
String addrID=""+submitObj.get("addrID");
String orderMemo=""+submitObj.get("orderMemo");
String couponNO=""+submitObj.get("couponNO");
String couponTypeID=""+submitObj.get("couponTypeID");
String formId = submitObj.getString("formId");
String bankType = submitObj.getString("bankType");
String bankAccount = submitObj.getString("bankAccount");
String bankAccountName = submitObj.getString("bankAccountName");
String revBankType = submitObj.getString("revBankType");
String revBankAccount = submitObj.getString("revBankAccount");
String revBankAccountNo = submitObj.getString("revBankAccountNo");
String email = submitObj.getString("email");
String salesmanNo = submitObj.getString("salesmanNo");
bankAccountName = StringUtil.isBlank(bankAccountName) ? "" : bankAccountName;
revBankType = StringUtil.isBlank(revBankType) ? "" : revBankType;
revBankAccount = StringUtil.isBlank(revBankAccount) ? "" : revBankAccount;
revBankAccountNo = StringUtil.isBlank(revBankAccountNo) ? "" : revBankAccountNo;
String sql = "exec up_NewCreatetSalesOrder '" + shopNO + "',null, '" + payID + "', '" + terminalTypeID + "', '" + addrID + "', '" + orderMemo + "', '" + couponNO + "','" + couponTypeID + "', '', '1', '" + (bankType == null ? "" : bankType) + "', '" + (bankAccount == null ? "" : bankAccount) + "', '" + bankAccountName + "', '" + revBankType + "', '" + revBankAccount + "', '" + revBankAccountNo + "'";
List<Map<String, Object>> commitMap = jdbcTemplate.executeMutil(sql).getDatas().get(0);
if (commitMap != null && commitMap.size() > 0 && commitMap.get(0) != null && Util.objTo(commitMap.get(0).get("Status"), Integer.class) == 0 && Util.objTo(commitMap.get(commitMap.size()-1).get("Status"), Integer.class) == 0) {
String sSalesOrderID = (String)commitMap.get(0).get("SalesOrderID");
jdbcTemplate.update("update tSalesOrder set sFormID = ?, sEmail = ?, sSalesmanNO = ? where sSalesOrderID = ?", formId, email, salesmanNo, sSalesOrderID);
return Rjx.jsonOk().setData(commitMap).toJson();
} else {
String errorMsg = "";
if(commitMap.size()>1){
errorMsg = (String)commitMap.get(0).get("StatusName")+";"+(String)commitMap.get(1).get("StatusName");
}else{
errorMsg = (String)commitMap.get(0).get("StatusName");
}
return Rjx.jsonErr().setMessage(I18NUtils.getMessage(LangID, "Msg_Submit_Order_failure")).set("errorMsg", errorMsg).toJson();
}
} catch (Exception e) {
e.printStackTrace();
return Rjx.jsonErr().set("errorMsg", e.getMessage()).setMessage(I18NUtils.getMessage(LangID, "Msg_Submit_Order_error")).toJson();
}
}
@Override
public String queryOrderList(String orgNo, String shopNo, Integer status, String[] orderType, String langID, Page page) {
if(status == null) {
status = 0;
}
//订单状态 0.全部 1. 待付款 2.待审核 3.待发货 4.已发货 5.已完成 6.已取消
String sql = "select * from tSalesOrder where sShopNO = '" + shopNo + "' and sOrgNO = '" + orgNo + "'";
if(status == 0) {
sql += "";
} else if(status == 1) {
sql += " and sSalesOrderPayTypeID = '4' and nOrderStatus = 0";
} else if(status == 2) {
sql += " and ((sSalesOrderPayTypeID = '2' and nOrderStatus = 0) or (sSalesOrderPayTypeID = '4' and nOrderStatus&37 = 32))";
} else if(status == 3) {
sql += " and nOrderStatus&29 = 4";
} else if(status == 4) {
sql += " and nOrderStatus&129 = 128";
} else if(status == 5) {
sql += " and nOrderStatus&17 = 16";
} else if(status == 6) {
sql += " and nOrderStatus&1 = 1";
} else {
throw new XException("订单状态不存在");
}
if(orderType != null && orderType.length > 0) {
sql += " and sB2BOrderTypeID in (" + StringUtil.join("', '", "'", "'", "", orderType) + ")";
}
List<Map<String, Object>> orderList = jdbcTemplate.limit(sql, page);
if(orderList.size() > 0) {
List<String> orderIds = orderList.stream().map(o-> (String)o.get("sSalesOrderID")).collect(Collectors.toList());
String sql2 = "select sod.*, agp.sURL from tSalesOrderDtl sod left join V_GetminAgentGoodsPic agp on agp.nAgentID = sod.nAgentID and agp.nGoodsID = sod.nGoodsID and agp.sPicTypeID = 1 where sod.sSalesOrderID in (" + StringUtil.join("', '", "'", "'", orderIds) + ")";
List<Map<String, Object>> orderDtlList = jdbcTemplate.queryForList(sql2);
Map<String, List<Map<String, Object>>> dtlML = Util.listToML(orderDtlList, "sSalesOrderID");
for(Map<String, Object> orderMap : orderList) {
String sSalesOrderID = (String)orderMap.get("sSalesOrderID");
List<Map<String, Object>> dtlList = dtlML.get(sSalesOrderID);
orderMap.put("list", dtlList);
}
String sql3 = "select * from tSalesOrderSub where sSalesOrderID in (" + StringUtil.join("', '", "'", "'", orderIds) + ")";
List<Map<String, Object>> subList = jdbcTemplate.queryForList(sql3);
if(subList.size() > 0) {
List<String> subIds = subList.stream().map(o-> (String)o.get("sSubOrderID")).collect(Collectors.toList());
String sql4 = "select sosd.*, agp.sURL from tSalesOrderSubDtl sosd left join V_GetminAgentGoodsPic agp on agp.nAgentID = sosd.nAgentID and agp.nGoodsID = sosd.nGoodsID and agp.sPicTypeID = 1 where sosd.sSubOrderID in (" + StringUtil.join("', '", "'", "'", subIds) + ")";
List<Map<String, Object>> subDtlList = jdbcTemplate.queryForList(sql4);
Map<String, List<Map<String, Object>>> subDtlML = Util.listToML(subDtlList, "sSubOrderID");
for(Map<String, Object> subMap : subList) {
String sSubOrderID = (String)subMap.get("sSubOrderID");
List<Map<String, Object>> dtlList = subDtlML.get(sSubOrderID);
subMap.put("list", dtlList);
}
}
Map<String, List<Map<String, Object>>> ml = Util.listToML(subList, "sSalesOrderID");
for(Map<String, Object> orderMap : orderList) {
String sSalesOrderID = (String)orderMap.get("sSalesOrderID");
List<Map<String, Object>> subListItem = ml.get(sSalesOrderID);
orderMap.put("subList", subListItem == null ? new Object[0] : subListItem);
}
}
return Rjx.jsonOk().set("list", orderList).toJson();
}
@Override
public String getOrderDetail(String salesOrderId) {
Map<String, Object> orderMap = null;
try {
orderMap =jdbcTemplate.queryForMap("select * from tSalesOrder where sSalesOrderID = ?", salesOrderId);
} catch (EmptyResultDataAccessException e) {
throw new XException("订单编号错误或订单不存在");
}
List<Map<String, Object>> orderDtlList = new ArrayList<Map<String, Object>>();
if(orderMap.size() > 0) {
String sql2 = "select sod.*, agp.sURL, pm.sPromoTheme, pm.sPromoActionType sPromoType, pm.sPromoActionTypeID sPromoTypeID from tSalesOrderDtl sod left join tYWPromoMain pm on pm.sPromoPaperNO = sod.sPromoPaperNO left join V_GetminAgentGoodsPic agp on agp.nAgentID = sod.nAgentID and agp.nGoodsID = sod.nGoodsID and agp.sPicTypeID = 1 where sod.sSalesOrderID = ?";
orderDtlList = jdbcTemplate.queryForList(sql2, salesOrderId);
}
String sqlPay = ""
+ "select "
+ "sum(case when sPayTypeID = '1' then nPayAmount else 0 end) nCashPayAmount, "
+ "sum(case when sPayTypeID = 'WxPay' then nPayAmount else 0 end) nWxPayAmount, "
+ "sum(case when sPayTypeID = 'Coupon' then nPayAmount else 0 end) nCouponPayAmount, "
+ "sum(nPayAmount) nTotalPayAmount "
+ "from tSalesOrderPay where sSalesOrderID = ?";
Map<String, Object> payMap = jdbcTemplate.queryForMap(sqlPay, salesOrderId);
payMap.put("nOrderTotalAmount", orderMap.get("nTotalSaleAmount"));
return Rjx.jsonOk().set("payData", payMap).set("list", orderMap).set("detail", orderDtlList).toJson();
}
@Override
public String queryOrderDetailList(String salesOrderId) {
String sql = "select * from tSalesOrderSub where sSalesOrderID = ?";
List<Map<String, Object>> subList = jdbcTemplate.queryForList(sql, salesOrderId);
if(subList.size() > 0) {
List<String> subIds = subList.stream().map(o-> (String)o.get("sSubOrderID")).collect(Collectors.toList());
String sql2 = "select sosd.*, agp.sURL, pm.sPromoTheme, pm.sPromoActionType sPromoType, pm.sPromoActionTypeID sPromoTypeID from tSalesOrderSubDtl sosd left join tYWPromoMain pm on pm.sPromoPaperNO = sosd.sPromoPaperNO left join V_GetminAgentGoodsPic agp on agp.nAgentID = sosd.nAgentID and agp.nGoodsID = sosd.nGoodsID and agp.sPicTypeID = 1 where sosd.sSubOrderID in (" + StringUtil.join("', '", "'", "'", subIds) + ")";
List<Map<String, Object>> subDtlList = jdbcTemplate.queryForList(sql2);
Map<String, List<Map<String, Object>>> subDtlML = Util.listToML(subDtlList, "sSalesOrderID");
for(Map<String, Object> subMap : subList) {
String sSubOrderID = (String)subMap.get("sSubOrderID");
List<Map<String, Object>> dtlList = subDtlML.get(sSubOrderID);
subMap.put("list", dtlList);
}
}
return Rjx.jsonOk().set("list", subList).toJson();
}
@Override
@Transactional
public void paySuccess(String sSalesOrderID, BigDecimal nPayAmount, String sOpenID, String sTransTraceNO, String sOutTradeNO, Date dPayDateTime) {
Integer nIdx = jdbcTemplate.queryForInt("select ISNULL(MAX(nIdx),0) from tSalesOrderPay where sSalesOrderID = ?", sSalesOrderID);
nPayAmount = nPayAmount.multiply(new BigDecimal(0.01)).setScale(2, BigDecimal.ROUND_HALF_UP);
Map<String, Object> map = new HashMap<String, Object>();
map.put("sSalesOrderID", sSalesOrderID);
map.put("nIdx", ++nIdx);
map.put("sPayTypeID", "WxPay");
map.put("sPayType", "微信支付(小程序)");
map.put("nPayAmount", nPayAmount);
map.put("sOutTradeNO", sOutTradeNO);
map.put("nPayDisAmount", BigDecimal.ZERO);
map.put("dPayDateTime", dPayDateTime);
map.put("sTransTraceNO", sTransTraceNO);
map.put("sPayCardNO", sOpenID);
map.put("nTag", 0);
map.put("dLastUpdateTime", new Date());
Dialect dialect = jdbcTemplate.getDialect();
Sql sqlDesc = dialect.argsInsert("tSalesOrderPay", map);
String sql = "if not exists (select * from tSalesOrderPay where sTransTraceNO = '" + sTransTraceNO + "') " + sqlDesc.getSql();
jdbcTemplate.update(sql, sqlDesc.getArgs());
jdbcTemplate.update("update tSalesOrder set nOrderStatus = nOrderStatus|32 where sSalesOrderID = ?", sSalesOrderID);
try {
jdbcTemplate.executeMutil("exec Up_Ego_SplitOrderPrd '" + sSalesOrderID + "'");
} catch (UncategorizedSQLException e) {
if(e.getMessage().contains("已拆单")) {
return;
}
throw e;
}
}
@Override
public String getSubOrderDetail(String subOrderID) {
new ArrayList<Map<String, Object>>();
Map<String, Object> subOrderMap = jdbcTemplate.queryForMap(""
+ "select "
+ "sos.*, "
+ "case when sos.nOrderStatus&145 = 144 then '16' when sos.nOrderStatus&145 = 128 then '8' when sos.nOrderStatus&145 = 0 then '4' when sos.nOrderStatus&5 = 4 then '2' else '0' end nOrderStatus, "
+ "case when sos.nOrderStatus&145 = 144 then '已完成' when sos.nOrderStatus&145 = 128 then '配送中' when sos.nOrderStatus&145 = 0 then '待发货' when sos.nOrderStatus&5 = 4 then '已审核' else '未审核' end sOrderStatusText "
+ "from tSalesOrderSub sos where sos.sSubOrderID = ?", subOrderID);
Map<String, Object> orderMap = jdbcTemplate.queryForMap(""
+ "select "
+ "so.*, "
+ "case when so.nOrderStatus&145 = 144 then '16' when so.nOrderStatus&145 = 128 then '8' when so.nOrderStatus&145 = 0 then '4' when so.nOrderStatus&5 = 4 then '2' else '0' end nOrderStatus, "
+ "case when so.nOrderStatus&145 = 144 then '已完成' when so.nOrderStatus&145 = 128 then '配送中' when so.nOrderStatus&145 = 0 then '待发货' when so.nOrderStatus&5 = 4 then '已审核' else '未审核' end sOrderStatusText "
+ "from tSalesOrder so where so.sSalesOrderID = ?", subOrderMap.get("sSalesOrderID"));
String sql = ""
+ "select "
+ "sosd.*, "
+ "agp.sURL, "
+ "pm.sPromoTheme, "
+ "pm.sPromoActionType sPromoType, "
+ "pm.sPromoActionTypeID sPromoTypeID "
+ "from tSalesOrderSubDtl sosd "
+ "left join tYWPromoMain pm on pm.sPromoPaperNO = sosd.sPromoPaperNO "
+ "left join V_GetminAgentGoodsPic agp on agp.nAgentID = sosd.nAgentID and agp.nGoodsID = sosd.nGoodsID and agp.sPicTypeID = 1 where sosd.sSubOrderID = ?";
List<Map<String, Object>> dtlList = jdbcTemplate.queryForList(sql, subOrderID);
Map<String, Object> deliver = jdbcTemplate.queryForMap("SELECT sum(a.nNum) nTotalCount, sum(a.nPrice * a.nNum) nTotalAmount FROM tSalesOrderDeliverSubDtl a where a.sSubOrderID = ?", subOrderID);
String sql3 = "select sSubOrderID, nOrderMoney, sAocOrderID, sAocOrderNumber, nOrderNum, nPickupNum, sExpressNO, sExpressName from tSalesOrderDeliverSub where nTag&1 = 0 and sSubOrderID = ?";
List<Map<String, Object>> deliverSubList = jdbcTemplate.queryForList(sql3, subOrderID);
return Rjx.jsonOk().set("deliver", deliver).set("deliverList", deliverSubList).set("order", orderMap).set("subOrder", subOrderMap).set("list", dtlList).toJson();
}
@Override
public void cancelOrder(String sSalesOrderID) {
jdbcTemplate.executeMutil("exec up_CancelledSalesOrder '" + sSalesOrderID + "'");
}
@Override
@Transactional
public String submitByGroup(String orgNo, String shopNo, String promoPaperNO, String promoGroupNO, Integer saleQty, String addrId, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo) {
XException.assertNotBlank(orgNo, "OrgNO不能为空");
XException.assertNotBlank(shopNo, "ShopNO不能为空");
XException.assertNotBlank(promoPaperNO, "PromoPaperNO不能为空");
XException.assertNotBlank(promoGroupNO, "PromoGroupNO不能为空");
XException.assertNotBlank(saleQty, "SaleQty不能为空");
XException.assertNotBlank(addrId, "AddrID不能为空");
XException.assertNotBlank(payTypeId, "PayTypeID不能为空");
String stockSql = "select og.sWarehouseNO, og.sAgentContractNO, og.nGoodsID, og.nStockQty, og.nLockedQty from tPromoRuleGoods prg, V_OrgGoods og where prg.sAgentContractNO = og.sAgentContractNO and prg.nGoodsID = og.nGoodsID and og.sOrgNO = ? and prg.sPromoPaperNO = ? and prg.sPromoGroupNO = ?";
List<Map<String, Object>> stockList = jdbcTemplate.queryForList(stockSql, orgNo, promoPaperNO, promoGroupNO);
Map<String, Map<String, Object>> stockMM = Util.listToMM(stockList, "_", "sAgentContractNO", "nGoodsID");
Map<String, Object> custMap = jdbcTemplate.queryForMap("select c.* from tCustomer c, tShop s where c.sCustNO = s.sCustNO and s.sShopNO = ? and s.sOrgNO = ?", shopNo, orgNo);
String sCustTypeID = (String)custMap.get("sCustTypeID");
String sCustNO = (String)custMap.get("sCustNO");
this.saveOrderBankAccount(sCustNO, bankType, bankAccount);
Map<String, Object> addrMap = jdbcTemplate.queryForMap("select * from tCustAddress where sAddrID = ?", addrId);
List<String> address = new ArrayList<String>();
address.add((String)addrMap.get("sProvince"));
address.add((String)addrMap.get("sCity"));
address.add((String)addrMap.get("sDistrict"));
address.add((String)addrMap.get("sAddress"));
address = address.stream().filter(o -> o != null).collect(Collectors.toList());
String sAddress = StringUtil.join(" ", address);
String sMobile = (String)addrMap.get("sMobile");
String sEmail = (String)addrMap.get("sEmail");
String sPostalcode = (String)addrMap.get("sPostalcode");
String sContacts = (String)addrMap.get("sContacts");
String sql = "" +
"SELECT DISTINCT " +
" GoodsID = b.nGoodsID, " +
" GoodsDesc = ag.sGoodsDesc, " +
" AgentContractNO = ag.sAgentContractNO, " +
" RealSalePrice = isnull(ap.nRealSalePrice, ag.nRealSalePrice), " +
" AgentID = ag.nAgentID, " +
" Barcode = ag.sMainBarcode, " +
" MeetQty = b.nMeetQty, " +
" Price = b.nPrice " +
" FROM tPromo a, tPromoRuleGoods b, tPromoCustBWList c, tAgent at, tAgentContractGoods ag " +
" LEFT JOIN tAgentCustTypePrice ap ON ap.sCustTypeID = c.sShopNO and ap.sAgentContractNO = ag.sAgentContractNO and ap.nGoodsID = ag.nGoodsID " +
" WHERE " +
" a.sPromoPaperNO = c.sPromoPaperNO " +
" AND a.sPromoPaperNO = b.sPromoPaperNO " +
" AND b.sAgentContractNO = ag.sAgentContractNO " +
" AND ag.nAgentID = at.nAgentID " +
" AND b.nGoodsID = ag.nGoodsID " +
" AND a.sPromoActionTypeID = '3' " +
" AND a.nTag&3=2 " +
" AND b.nTag&3=2 " +
" AND getdate() BETWEEN a.dPromoBeginDate AND a.dPromoEndDate " +
" AND CASE WHEN nUseCycle&1 = 1 THEN '1,' ELSE '' END + " +
" CASE WHEN nUseCycle&2 = 2 THEN '2,' ELSE '' END + " +
" CASE WHEN nUseCycle&4 = 4 THEN '3,' ELSE '' END + " +
" CASE WHEN nUseCycle&8 = 8 THEN '4,' ELSE '' END + " +
" CASE WHEN nUseCycle&16 = 16 THEN '5,' ELSE '' END + " +
" CASE WHEN nUseCycle&32 = 32 THEN '6,' ELSE '' END + " +
" CASE WHEN nUseCycle&64 = 64 THEN '7' ELSE '' END LIKE '%' + convert(VARCHAR,datepart(weekday,getdate())) + '%' " +
" AND a.sPromoPaperNO = ? " +
" AND b.sPromoGroupNO = ? " +
" AND c.sShopNO = ? ";
List<Map<String, Object>> goodsList = jdbcTemplate.queryForList(sql.replaceAll("\\s+", " "), promoPaperNO, promoGroupNO, sCustTypeID);
if(goodsList.size() == 0) {
throw new XException("对不起,您不能购买该礼包");
}
BigDecimal Qty = BigDecimal.valueOf(saleQty);
BigDecimal nOrderTotalAmount = BigDecimal.ZERO;
BigDecimal nPayTotalAmount = BigDecimal.ZERO;
BigDecimal nTotalSaleQty = BigDecimal.ZERO;
List<Object[]> batchArgs = new ArrayList<Object[]>();
for(Map<String, Object> gMap : goodsList) {
String GoodsDesc = (String)gMap.get("GoodsDesc");
String sAgentContractNO = (String)gMap.get("AgentContractNO");
Integer nGoodsID = ((Number)gMap.get("GoodsID")).intValue();
String key = sAgentContractNO + "_" + nGoodsID;
Map<String, Object> stockMap = stockMM.get(key);
if(stockMap == null) {
throw new XException("活动商品库存异常");
}
BigDecimal nStockQty = (BigDecimal)stockMap.get("nStockQty");
BigDecimal nLockedQty = (BigDecimal)stockMap.get("nLockedQty");
BigDecimal MeetQty = (BigDecimal)gMap.get("MeetQty");
BigDecimal nTotalMeetQty = MeetQty.multiply(Qty);
if(nStockQty.subtract(nLockedQty).compareTo(nTotalMeetQty) < 0) {
throw new XException("商品[" + GoodsDesc + "]库存不足");
}
String sWarehouseNO = (String)stockMap.get("sWarehouseNO");
batchArgs.add(new Object[] {nTotalMeetQty, sAgentContractNO, nGoodsID, sWarehouseNO});
BigDecimal RealSalePrice = (BigDecimal)gMap.get("RealSalePrice");
BigDecimal Price = (BigDecimal)gMap.get("Price");
BigDecimal TotalAmount = RealSalePrice.multiply(nTotalMeetQty);
BigDecimal PayAmount = Price.multiply(nTotalMeetQty);
nOrderTotalAmount = nOrderTotalAmount.add(TotalAmount);
nPayTotalAmount = nPayTotalAmount.add(PayAmount);
nTotalSaleQty = nTotalSaleQty.add(nTotalMeetQty);
gMap.put("WarehouseNO", sWarehouseNO);
}
jdbcTemplate.batchUpdate("update tAgentStockOnline set nLockedQty = (nLockedQty + ?) where sAgentContractNO = ? and nGoodsID = ? and sWarehouseNO = ?", batchArgs);
BigDecimal nTotalDisAmount = nOrderTotalAmount.subtract(nPayTotalAmount);
BigDecimal nTotalSaleAmount = nPayTotalAmount;
TSalesOrder order = new TSalesOrder();
order.setsSalesOrderID(System.currentTimeMillis() + "");
order.setdLastUpdateTime(new Date());
order.setsCustNO(sCustNO);
order.setsShopNO(shopNo);
order.setsOrgNO(orgNo);
order.setdOrderDate(DateUtil.start(new Date()));
order.setdOrderTime(new Date());
order.setdUpdate(new Date());
order.setnOrderStatus(0);
order.setsOrderStatusName("制单");
order.setnTotalDisAmount(nTotalDisAmount);
order.setnTotalSaleAmount(nTotalSaleAmount);
order.setsSalesmanNO(salesmanNo);
order.setnTag(0);
order.setnTotalSaleQty(nTotalSaleQty);
order.setsAddress(sAddress);
order.setsEmail(sEmail);
order.setsMobile(sMobile);
order.setsContacts(sContacts);
order.setsPostalcode(sPostalcode);
order.setnExpressFee(BigDecimal.ZERO);
order.setsAddrID(addrId);
order.setsBankType(bankType);
order.setsBankAccount(bankAccount);
order.setsBankAccountName(bankAccountName);
order.setsRevBankType(revBankType);
order.setsRevBankAccount(revBankAccount);
order.setsRevBankAccountNO(revBankAccountNo);
order.setsDeliveryType("送货");
order.setsDeliveryTypeID("1");
order.setsSalesOrderPayTypeID(payTypeId);
order.setsSalesOrderPayType("1".equals(payTypeId) ? "货到付款" : ("4".equals(payTypeId) ? "在线支付" : ("2".equals(payTypeId) ? "线下转账" : "")));
order.setsTerminalTypeID(terminal.equals("wechat") ? "WX" : terminal);
order.setsTerminalType(terminal.equals("wechat") ? "微信" : terminal);
order.setsFormID(formId);
order.setsB2BOrderTypeID("4");
order.setsB2BOrderType("组合礼包订单");
order.setsOrderMemo(memo);
jdbcTemplate.save(order);
List<TSalesOrderDtl> list = new ArrayList<TSalesOrderDtl>();
Integer index = 1;
for(Map<String, Object> gMap : goodsList) {
TSalesOrderDtl dtl = new TSalesOrderDtl();
String sSalesOrderID = order.getsSalesOrderID();
Date dUpdate = new Date();
BigDecimal MeetQty = (BigDecimal)gMap.get("MeetQty");
Integer nAgentID = ((Number)gMap.get("AgentID")).intValue();
BigDecimal RealSalePrice = (BigDecimal)gMap.get("RealSalePrice");
BigDecimal Price = (BigDecimal)gMap.get("Price");
BigDecimal nDisAmount = RealSalePrice.subtract(Price).multiply(MeetQty).multiply(Qty);
BigDecimal nSaleAmount = Price.multiply(MeetQty).multiply(Qty);
BigDecimal nSalePrice = Price;
BigDecimal nSaleQty = MeetQty.multiply(Qty);
BigDecimal nExpressFee = BigDecimal.ZERO;
Integer nGoodsID = ((Number)gMap.get("GoodsID")).intValue();
String sAgentContractNO = (String)gMap.get("AgentContractNO");
String sBarcode = (String)gMap.get("Barcode");
String sGoodsDesc = (String)gMap.get("GoodsDesc");
String sWarehouseNO = (String)gMap.get("WarehouseNO");
dtl.setsSalesOrderID(sSalesOrderID);
dtl.setdUpdate(dUpdate);
dtl.setnAgentID(nAgentID);
dtl.setnDisAmount(nDisAmount);
dtl.setnExpressFee(nExpressFee);
dtl.setnGoodsID(nGoodsID);
dtl.setnIdx(index++);
dtl.setnSaleAmount(nSaleAmount);
dtl.setnSalePrice(nSalePrice);
dtl.setnSaleQty(nSaleQty);
dtl.setnTag(0);
dtl.setsAgentContractNO(sAgentContractNO);
dtl.setsBarcode(sBarcode);
dtl.setsGoodsDesc(sGoodsDesc);
dtl.setsMemo(memo);
dtl.setsPromoActionType("组合折扣");
dtl.setsPromoActionTypeID("3");
dtl.setsPromoPaperNO(promoPaperNO);
dtl.setsSalesOrderID(sSalesOrderID);
dtl.setsWarehouseNO(sWarehouseNO);
dtl.setdLastUpdateTime(new Date());
list.add(dtl);
}
jdbcTemplate.batchSave(list);
return order.getsSalesOrderID();
}
@Override
@Transactional
public String submitByZhc(String orgNo, String shopNo, Integer planId, Integer saleQty, String addrId, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo) {
XException.assertNotBlank(orgNo, "OrgNO不能为空");
XException.assertNotBlank(shopNo, "ShopNO不能为空");
XException.assertNotBlank(planId, "PlanID不能为空");
XException.assertNotBlank(saleQty, "SaleQty不能为空");
XException.assertNotBlank(addrId, "AddrID不能为空");
XException.assertNotBlank(payTypeId, "PayTypeID不能为空");
XException.assertNotBlank(terminal, "Terminal不能为空");
BigDecimal Qty = BigDecimal.valueOf(saleQty);
Map<String, Object> custMap = jdbcTemplate.queryForMap("select c.* from tCustomer c, tShop s where c.sCustNO = s.sCustNO and s.sShopNO = ?", shopNo);
String sCustNO = (String)custMap.get("sCustNO");
this.saveOrderBankAccount(sCustNO, bankType, bankAccount);
Map<String, Object> addrMap = jdbcTemplate.queryForMap("select * from tCustAddress where sAddrID = ?", addrId);
List<String> address = new ArrayList<String>();
address.add((String)addrMap.get("sProvince"));
address.add((String)addrMap.get("sCity"));
address.add((String)addrMap.get("sDistrict"));
address.add((String)addrMap.get("sAddress"));
address = address.stream().filter(o -> o != null).collect(Collectors.toList());
String sAddress = StringUtil.join(" ", address);
String sMobile = (String)addrMap.get("sMobile");
String sEmail = (String)addrMap.get("sEmail");
String sPostalcode = (String)addrMap.get("sPostalcode");
String sContacts = (String)addrMap.get("sContacts");
String sqlplan = ""
+ "SELECT " +
" t.*, " +
" og.nAgentID, " +
" og.sWarehouseNO, " +
" og.sGoodsDesc, " +
" og.sMainBarcode " +
"FROM " +
" ( " +
" SELECT " +
" zp.*, " +
" j.dStartDate, " +
" j.dEndDate, " +
" j.nProjectAmount, " +
" j.sProjectName, " +
" j.sOrgNO " +
" FROM " +
" tZHCPlan zp, " +
" tZHCProject j " +
" WHERE " +
" zp.nPlanID = ? " +
" AND zp.nProjectID = j.nProjectID " +
" AND j.sOrgNO = ? " +
" AND j.dStartDate <= getdate( ) " +
" AND j.dEndDate >= getdate( ) " +
" ) t " +
" LEFT JOIN V_OrgGoods og ON og.sOrgNO = t.sOrgNO " +
" AND og.sAgentContractNO = t.sAgentContractNO " +
" AND og.nGoodsID = t.nGoodsID";
Map<String, Object> gMap = jdbcTemplate.queryForMap(sqlplan.replaceAll("\\s+", " "), planId, orgNo);
BigDecimal nPrice = (BigDecimal)gMap.get("nPrice");
BigDecimal nTotalSaleAmount = nPrice.multiply(Qty);
BigDecimal nPlanStock = (BigDecimal)gMap.get("nPlanStock");
Map<String, Object> planSum = jdbcTemplate.queryForMap("select sum(nTotalSaleQty) nOrderQty, sum(nTotalSaleAmount) nOrderAmount from tSalesOrder where nPlanID = ? and nOrderStatus&1 = 0", planId);
BigDecimal nOrderQty = (BigDecimal)planSum.get("nOrderQty");
nOrderQty = nOrderQty == null ? BigDecimal.ZERO : nOrderQty;
nPlanStock = nPlanStock == null ? BigDecimal.ZERO : nPlanStock;
if(nOrderQty.compareTo(nPlanStock) == 0) {
throw new XException("该档众筹产品已售罄,请重新选择");
}
if(nOrderQty.add(Qty).compareTo(nPlanStock) > 0) {
throw new XException("该档众筹产品数量不足,请重新选择数量");
}
TSalesOrder order = new TSalesOrder();
order.setnPlanID(planId);
order.setsSalesOrderID(System.currentTimeMillis() + "");
order.setdLastUpdateTime(new Date());
order.setsCustNO(sCustNO);
order.setsShopNO(shopNo);
order.setsOrgNO(orgNo);
order.setnTag(0);
order.setdOrderDate(DateUtil.start(new Date()));
order.setdOrderTime(new Date());
order.setdUpdate(new Date());
order.setnOrderStatus(0);
order.setsOrderStatusName("制单");
order.setnTotalDisAmount(BigDecimal.ZERO);
order.setnTotalSaleAmount(nTotalSaleAmount);
order.setnTotalSaleQty(Qty);
order.setsAddress(sAddress);
order.setsEmail(sEmail);
order.setsMobile(sMobile);
order.setsContacts(sContacts);
order.setsPostalcode(sPostalcode);
order.setsSalesmanNO(salesmanNo);
order.setnExpressFee(BigDecimal.ZERO);
order.setsAddrID(addrId);
order.setsBankType(bankType);
order.setsBankAccount(bankAccount);
order.setsBankAccountName(bankAccountName);
order.setsRevBankType(revBankType);
order.setsRevBankAccount(revBankAccount);
order.setsRevBankAccountNO(revBankAccountNo);
order.setsDeliveryType("送货");
order.setsDeliveryTypeID("1");
order.setsSalesOrderPayTypeID(payTypeId);
order.setsSalesOrderPayType("1".equals(payTypeId) ? "货到付款" : ("4".equals(payTypeId) ? "在线支付" : ("2".equals(payTypeId) ? "线下转账" : "")));
order.setsTerminalTypeID(terminal.equals("wechat") ? "WX" : terminal);
order.setsTerminalType(terminal.equals("wechat") ? "微信" : terminal);
order.setsFormID(formId);
order.setsB2BOrderTypeID("3");
order.setsB2BOrderType("众筹订单");
order.setsOrderMemo(memo);
jdbcTemplate.save(order);
TSalesOrderDtl dtl = new TSalesOrderDtl();
String sSalesOrderID = order.getsSalesOrderID();
Date dUpdate = new Date();
Integer nGoodsID = ((Number)gMap.get("nGoodsID")).intValue();
String sAgentContractNO = (String)gMap.get("sAgentContractNO");
String sBarcode = (String)gMap.get("sMainBarcode");
String sGoodsDesc = (String)gMap.get("sGoodsDesc");
String sWarehouseNO = (String)gMap.get("sWarehouseNO");
Integer nAgentID = ((Number)gMap.get("nAgentID")).intValue();
dtl.setsSalesOrderID(sSalesOrderID);
dtl.setdUpdate(dUpdate);
dtl.setnAgentID(nAgentID);
dtl.setnDisAmount(BigDecimal.ZERO);
dtl.setnExpressFee(BigDecimal.ZERO);
dtl.setnGoodsID(nGoodsID);
dtl.setnIdx(1);
dtl.setnSaleAmount(nTotalSaleAmount);
dtl.setnSalePrice(nPrice);
dtl.setnSaleQty(Qty);
dtl.setnTag(0);
dtl.setsAgentContractNO(sAgentContractNO);
dtl.setdLastUpdateTime(new Date());
dtl.setsBarcode(sBarcode);
dtl.setsGoodsDesc(sGoodsDesc);
dtl.setsMemo(memo);
dtl.setsSalesOrderID(sSalesOrderID);
dtl.setsWarehouseNO(sWarehouseNO);
jdbcTemplate.save(dtl);
{
Long nProjectID = jdbcTemplate.queryForLong("select nProjectID from tZHCPlan where nPlanID = ?", planId);
String sql = "select count(so.sSalesOrderID) nSalePaperQty, isnull(sum(so.nTotalSaleQty), 0) nSaleQty, isnull(sum(so.nTotalSaleAmount), 0) nSaleAmount from tSalesOrder so, tZHCPlan p where so.sB2BOrderTypeID = '3' and so.nTag&1 = 0 and so.nPlanID = p.nPlanID and p.nProjectID = ?";
Map<String, Object> map = jdbcTemplate.queryForMap(sql, nProjectID);
Integer nSalePaperQty = ((Number)map.get("nSalePaperQty")).intValue();
BigDecimal nSaleQty = (BigDecimal)map.get("nSaleQty");
BigDecimal nSaleAmount = (BigDecimal)map.get("nSaleAmount");
String sqlUpdate = "update tZHCProject set nSalePaperQty = ?, nSaleQty = ?, nSaleAmount = ? where nProjectID = ?";
jdbcTemplate.executeUpdate(sqlUpdate, nSalePaperQty, nSaleQty, nSaleAmount, nProjectID);
}
return order.getsSalesOrderID();
}
@Override
public String submitByMdzs(String orgNo, String shopNo, String contractNo, Integer goodsId, Integer saleQty, String addrId, String email, String payTypeId, String terminal, String salesmanNo, String formId, String bankType, String bankAccount, String bankAccountName, String revBankType, String revBankAccount, String revBankAccountNo, String memo) {
XException.assertNotBlank(orgNo, "OrgNO不能为空");
XException.assertNotBlank(shopNo, "ShopNO不能为空");
XException.assertNotBlank(contractNo, "ContractNO不能为空");
XException.assertNotBlank(goodsId, "GoodsID不能为空");
XException.assertNotBlank(saleQty, "SaleQty不能为空");
XException.assertNotBlank(addrId, "AddrID不能为空");
XException.assertNotBlank(payTypeId, "PayTypeID不能为空");
XException.assertNotBlank(terminal, "Terminal不能为空");
Map<String, Object> custMap = jdbcTemplate.queryForMap("select c.* from tCustomer c, tShop s where c.sCustNO = s.sCustNO and s.sShopNO = ?", shopNo);
String sCustTypeID = (String)custMap.get("sCustTypeID");
String sCustNO = (String)custMap.get("sCustNO");
this.saveOrderBankAccount(sCustNO, bankType, bankAccount);
BigDecimal Qty = BigDecimal.valueOf(saleQty);
Map<String, Object> addrMap = jdbcTemplate.queryForMap("select * from tCustAddress where sAddrID = ?", addrId);
List<String> address = new ArrayList<String>();
address.add((String)addrMap.get("sProvince"));
address.add((String)addrMap.get("sCity"));
address.add((String)addrMap.get("sDistrict"));
address.add((String)addrMap.get("sAddress"));
address = address.stream().filter(o -> o != null).collect(Collectors.toList());
String sAddress = StringUtil.join(" ", address);
String sMobile = (String)addrMap.get("sMobile");
String sPostalcode = (String)addrMap.get("sPostalcode");
String sContacts = (String)addrMap.get("sContacts");
String gSql = "select t.*, ap.nRealSalePrice nApSalePrice from V_OrgGoods t left join tAgentCustTypePrice ap on ap.sCustTypeID = ? and ap.sAgentContractNO = t.sAgentContractNO and ap.nGoodsID = t.nGoodsID where t.sOrgNO = ? and t.sAgentContractNO = ? and t.nGoodsID = ?";
Map<String, Object> gMap = jdbcTemplate.queryForMap(gSql, sCustTypeID, orgNo, contractNo, goodsId);
BigDecimal nStockQty = (BigDecimal)gMap.get("nStockQty");
BigDecimal nLockedQty = (BigDecimal)gMap.get("nLockedQty");
BigDecimal stock = nStockQty.subtract(nLockedQty);
String sGoodsDesc = (String)gMap.get("sGoodsDesc");
String sAgentContractNO = (String)gMap.get("sAgentContractNO");
Integer nGoodsID = (Integer)gMap.get("nGoodsID");
String sWarehouseNO = (String)gMap.get("sWarehouseNO");
String sBarcode = (String)gMap.get("sMainBarcode");
Integer nAgentID = ((Number)gMap.get("nAgentID")).intValue();
if(stock.compareTo(Qty) < 0) {
throw new XException("商品[" + sGoodsDesc + "]库存不足");
} else {
String stockSql = "update tAgentStockOnline set nLockedQty = nLockedQty + ? where sAgentContractNO = ? and nGoodsID = ? and sWarehouseNO = ?";
jdbcTemplate.update(stockSql, Qty, sAgentContractNO, nGoodsID, sWarehouseNO);
}
BigDecimal nTotalSaleAmount = BigDecimal.ZERO;
BigDecimal nRealSalePrice = (BigDecimal)gMap.get("nApSalePrice");
if(nRealSalePrice == null) {
nRealSalePrice = (BigDecimal)gMap.get("nRealSalePrice");
}
nTotalSaleAmount = nTotalSaleAmount.add(nRealSalePrice.multiply(Qty));
TSalesOrder order = new TSalesOrder();
order.setsSalesOrderID(System.currentTimeMillis() + "");
order.setdLastUpdateTime(new Date());
order.setsCustNO(sCustNO);
order.setsShopNO(shopNo);
order.setsOrgNO(orgNo);
order.setnTag(0);
order.setdOrderDate(DateUtil.start(new Date()));
order.setdOrderTime(new Date());
order.setdUpdate(new Date());
order.setsSalesmanNO(salesmanNo);
order.setnOrderStatus(0);
order.setsOrderStatusName("制单");
order.setnTotalDisAmount(BigDecimal.ZERO);
order.setnTotalSaleAmount(nTotalSaleAmount);
order.setnTotalSaleQty(Qty);
order.setsAddress(sAddress);
order.setsEmail(email);
order.setsMobile(sMobile);
order.setsContacts(sContacts);
order.setsPostalcode(sPostalcode);
order.setnExpressFee(BigDecimal.ZERO);
order.setsAddrID(addrId);
order.setsBankType(bankType);
order.setsBankAccount(bankAccount);
order.setsBankAccountName(bankAccountName);
order.setsRevBankType(revBankType);
order.setsRevBankAccount(revBankAccount);
order.setsRevBankAccountNO(revBankAccountNo);
order.setsDeliveryType("送货");
order.setsDeliveryTypeID("1");
order.setsSalesOrderPayTypeID(payTypeId);
order.setsSalesOrderPayType("1".equals(payTypeId) ? "货到付款" : ("4".equals(payTypeId) ? "在线支付" : ("2".equals(payTypeId) ? "线下转账" : "")));
order.setsTerminalTypeID(terminal.equals("wechat") ? "WX" : terminal);
order.setsTerminalType(terminal.equals("wechat") ? "微信" : terminal);
order.setsFormID(formId);
order.setsB2BOrderTypeID("2");
order.setsB2BOrderType("门店装饰订单");
order.setsOrderMemo(memo);
jdbcTemplate.save(order);
TSalesOrderDtl dtl = new TSalesOrderDtl();
String sSalesOrderID = order.getsSalesOrderID();
Date dUpdate = new Date();
dtl.setsSalesOrderID(sSalesOrderID);
dtl.setdUpdate(dUpdate);
dtl.setnAgentID(nAgentID);
dtl.setnDisAmount(BigDecimal.ZERO);
dtl.setnExpressFee(BigDecimal.ZERO);
dtl.setnGoodsID(nGoodsID);
dtl.setnIdx(1);
dtl.setnSaleAmount(nTotalSaleAmount);
dtl.setnSalePrice(nRealSalePrice);
dtl.setnSaleQty(Qty);
dtl.setnTag(0);
dtl.setsAgentContractNO(sAgentContractNO);
dtl.setdLastUpdateTime(new Date());
dtl.setsBarcode(sBarcode);
dtl.setsGoodsDesc(sGoodsDesc);
dtl.setsMemo(memo);
dtl.setsSalesOrderID(sSalesOrderID);
dtl.setsWarehouseNO(sWarehouseNO);
jdbcTemplate.save(dtl);
return order.getsSalesOrderID();
}
private void saveOrderBankAccount(String sCustNO, String sBankType, String sBankAccountNO) {
if(StringUtil.isNotBlank(sCustNO, sBankType, sBankAccountNO)) {
String sql = ""
+ "DECLARE @CustNO VARCHAR(36) "
+ "DECLARE @CustName VARCHAR(36) "
+ "DECLARE @BankType VARCHAR(36) "
+ "DECLARE @BankTypeID VARCHAR(36) "
+ "DECLARE @BankAccountNO VARCHAR(36) "
+ "SELECT @CustNO = '" + sCustNO + "' "
+ "SELECT @BankType = '" + sBankType + "' "
+ "SELECT @BankAccountNO = '" + sBankAccountNO + "' "
+ "SELECT @CustName = sCustName FROM tCustomer WHERE sCustNO = @CustNO "
+ "SELECT @BankTypeID = sComID from tCommon where sLangID = '936' and sCommonNO = 'Bank' and sComDesc = @BankType "
+ "SELECT @BankTypeID = ISNULL(@BankTypeID, @BankType) "
+ "SELECT @CustName = ISNULL(@CustName, @CustNO) "
+ "IF NOT EXISTS (SELECT * FROM tCustBank WHERE sCustNO = @CustNO AND sBankAccountNO = @BankAccountNO) "
+ "BEGIN "
+ "INSERT INTO tCustBank "
+ "(sCustNO, sBankTypeID, sBankType, sBankAccountNO, sBankAccount, nTag, sCreateUser, dCreateDate, sConfirmUser, dConfirmDate, dLastUpdateTime) "
+ "VALUES "
+ "(@CustNO, @BankTypeID, @BankType, @BankAccountNO, @CustNO, 0, @CustNO, GETDATE(), @CustNO, GETDATE(), GETDATE())"
+ "END";
jdbcTemplate.update(sql);
}
}
@Override
public void confirmReceipt(String custNo, String subOrderID) {
String sql = ""
+ "DECLARE @CustNO VARCHAR(20) "
+ "DECLARE @SubOrderID VARCHAR(20) "
+ "DECLARE @SalesOrderID VARCHAR(20) "
+ "DECLARE @OrderStatusName VARCHAR(20) "
+ "DECLARE @OrderStatus INT "
+ "DECLARE @TargetStatus INT "
+ "SELECT @CustNO = '" + custNo + "' "
+ "SELECT @SubOrderID = '" + subOrderID + "' "
+ "SELECT @TargetStatus = 16 "
+ "SELECT @OrderStatusName = '收货完成' "
+ "SELECT @OrderStatus = nOrderStatus FROM tSalesOrderSub WHERE sSubOrderID = @SubOrderID "
+ "IF @OrderStatus&@TargetStatus = 0 "
+ "BEGIN "
+ "SELECT @SalesOrderID = sSalesOrderID FROM tSalesOrderSub WHERE sSubOrderID = @SubOrderID "
+ "UPDATE tSalesOrderSub SET nOrderStatus = nOrderStatus|@TargetStatus, nOrderStatusName = @OrderStatusName, dLastUpdateTime = GETDATE() WHERE sSubOrderID = @SubOrderID "
+ "UPDATE tSalesOrderSubDtl SET nReceiveQty = td.nSendQty, nReceiveAmount = td.nSendAmount, dLastUpdateTime = GETDATE() FROM tSalesOrderSub t, tSalesOrderSubDtl td WHERE t.sSubOrderID = td.sSubOrderID AND t.sSubOrderID = @SubOrderID AND td.nReceiveQty IS NULL "
+ "DECLARE @Idx INT "
+ "SELECT @Idx = ISNULL(MAX(nIdx), 0) + 1 FROM tSalesOrderSubStatus WHERE sSubOrderID = @SubOrderID "
+ "INSERT INTO tSalesOrderSubStatus "
+ "(sSubOrderID, nIdx, sSalesOrderID, nOrderStatusStep, sOrderStatusName, sOrderStatusUser, dOrderStatusTime, dLastUpdateTime) "
+ "VALUES "
+ "(@SubOrderID, @Idx, @SalesOrderID, @TargetStatus, @OrderStatusName, @CustNO, GETDATE(), GETDATE()) "
+ "exec up_UpdateSalesOrderStatus @SalesOrderID, @SubOrderID, @CustNO, @TargetStatus, @OrderStatusName, @OrderStatusName "
+ "END"
;
jdbcTemplate.update(sql);
}
@Override
public List<Map<String, Object>> getDeliverSubDetail(String aocOrderID) {
return jdbcTemplate.queryForList("select * from tSalesOrderDeliverSubDtl where nTag&1 = 0 and sAocOrderID = ?", aocOrderID);
}
}
package com.egolm.shop.util;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.StringWriter;
import java.util.HashMap;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.w3c.dom.CDATASection;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import com.alibaba.fastjson.JSON;
public class XmlUtil {
public static Map<String, String> toMap(String xml) {
try {
Map<String, String> data = new HashMap<>();
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
InputStream stream = new ByteArrayInputStream(xml.getBytes("UTF-8"));
org.w3c.dom.Document doc = documentBuilder.parse(stream);
doc.getDocumentElement().normalize();
NodeList nodeList = doc.getDocumentElement().getChildNodes();
for (int idx = 0; idx < nodeList.getLength(); ++idx) {
Node node = nodeList.item(idx);
if (node.getNodeType() == Node.ELEMENT_NODE) {
org.w3c.dom.Element element = (org.w3c.dom.Element) node;
data.put(element.getNodeName(), element.getTextContent());
}
}
stream.close();
return data;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static String toXml(Map<String, String> data){
try {
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
org.w3c.dom.Document document = documentBuilder.newDocument();
org.w3c.dom.Element root = document.createElement("xml");
document.appendChild(root);
for (String key : data.keySet()) {
String value = data.get(key);
value = value == null ? "" : value;
org.w3c.dom.Element filed = document.createElement(key);
CDATASection cdata = document.createCDATASection(value);
filed.appendChild(cdata);
root.appendChild(filed);
}
TransformerFactory tf = TransformerFactory.newInstance();
Transformer transformer = tf.newTransformer();
DOMSource source = new DOMSource(document);
transformer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
transformer.setOutputProperty(OutputKeys.INDENT, "yes");
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
transformer.transform(source, result);
String output = writer.getBuffer().toString();
writer.close();
return output;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
public static void main(String[] args) {
Map<String,String> map = new HashMap<String,String>();
map.put("AA", "G\nGG");
String xml = toXml(map);
System.out.println(xml);
map = toMap(xml);
System.out.println(JSON.toJSONString(map));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment