Commit 2d6bd1d4 authored by Quxl's avatar Quxl

x

parent 2c6ff00b
package com.egolm.oms.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
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.oms.config.XException;
import com.egolm.oms.model.TSalesOrder;
import com.egolm.oms.model.TSalesOrderDtl;
import com.egolm.oms.service.OrderService;
import com.egolm.oms.service.QiyeWxService;
import com.egolm.oms.service.QiyeWxService.WxMessage;
import com.egolm.oms.service.QiyeWxService.WxMessage.MiniprogramNotice;
import com.egolm.oms.util.I18NUtils;
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
QiyeWxService wxService;
/**
* 订单检查
* <p>Title: orderCheck</p>
* <p>Description: </p>
* @param params
* @return
* @see com.egolm.shop.api.service.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 {
Map<String, Object> lastest = resultMap.get(resultMap.size() - 1);
rjx = Rjx.jsonErr().setMessage((String)lastest.get("ErrorMsg"));
}
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);
this.sendWxMessage(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);
this.sendWxMessage(order.getsSalesOrderID());
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);
}
this.sendWxMessage(order.getsSalesOrderID());
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);
this.sendWxMessage(order.getsSalesOrderID());
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);
}
private void sendWxMessage(String sSalesOrderID) {
TSalesOrder order = jdbcTemplate.queryForBean("select * from tSalesOrder where sSalesOrderID = ?", TSalesOrder.class, sSalesOrderID);
String salesmanNo = order.getsSalesmanNO();
String shopNo = order.getsShopNO();
BigDecimal totalAmount = order.getnTotalSaleAmount();
BigDecimal totalSaleQty = order.getnTotalSaleQty();
String payType = order.getsSalesOrderPayType();
Map<String, Object> salesman = null;
try {
salesman = jdbcTemplate.queryForMap("select * from tSalesman where sSalesmanNO = ?", salesmanNo);
} catch (EmptyResultDataAccessException e) {
e.printStackTrace();
}
if(salesman != null) {
String dateString = DateUtil.format(new Date());
Map<String, Object> shop = jdbcTemplate.queryForMap("select * from tShop where sShopNO = ?", shopNo);
String custNo = (String)shop.get("sCustNO");
String shopMemo = (String)shop.get("sMemo");
Map<String, Object> cust = jdbcTemplate.queryForMap("select * from tCustomer where sCustNO = ?", custNo);;
String custName = (String)cust.get("sCustName");
String sCompanyAccountID = (String)salesman.get("sCompanyAccountID");
WxMessage wxMessage = new WxMessage(sCompanyAccountID);
MiniprogramNotice notice = new MiniprogramNotice();
wxMessage.setMiniprogram_notice(notice);
notice.setDescription(dateString);
notice.setTitle("客户订单通知");
notice.setPage("pages/ordermanage/detail/detail?SalesmanNO=" + salesmanNo + "&isShare=1&id=" + sSalesOrderID + "&isActive=0");
Map<Object, Object> params = new LinkedHashMap<Object, Object>();
params.put("订单状态", "待审核");
params.put("客户", custName);
params.put("订单金额", totalAmount);
params.put("商品数量", totalSaleQty);
params.put("支付方式", payType);
params.put("订单时间", dateString);
params.put("备注", StringUtil.isBlank(shopMemo) ? " " : shopMemo);
notice.setContent_item(params);
wxService.sendMessage(wxMessage);
}
}
}
package com.egolm.oms.service.impl;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
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.oms.config.XException;
import com.egolm.oms.model.TSalesOrder;
import com.egolm.oms.model.TSalesOrderDtl;
import com.egolm.oms.service.OrderService;
import com.egolm.oms.service.QiyeWxService;
import com.egolm.oms.service.QiyeWxService.WxMessage;
import com.egolm.oms.service.QiyeWxService.WxMessage.MiniprogramNotice;
import com.egolm.oms.util.I18NUtils;
@Service
public class OrderServiceImpl implements OrderService {
@Autowired
private JdbcTemplate jdbcTemplate;
@Autowired
QiyeWxService wxService;
/**
* 订单检查
* <p>Title: orderCheck</p>
* <p>Description: </p>
* @param params
* @return
* @see com.egolm.shop.api.service.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 {
Map<String, Object> lastest = resultMap.get(resultMap.size() - 1);
rjx = Rjx.jsonErr().setMessage((String)lastest.get("ErrorMsg"));
}
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);
this.sendWxMessage(sSalesOrderID);
}
return Rjx.jsonOk().setData(commitMap).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);
this.sendWxMessage(order.getsSalesOrderID());
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);
}
this.sendWxMessage(order.getsSalesOrderID());
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);
this.sendWxMessage(order.getsSalesOrderID());
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);
}
private void sendWxMessage(String sSalesOrderID) {
TSalesOrder order = jdbcTemplate.queryForBean("select * from tSalesOrder where sSalesOrderID = ?", TSalesOrder.class, sSalesOrderID);
String salesmanNo = order.getsSalesmanNO();
String shopNo = order.getsShopNO();
BigDecimal totalAmount = order.getnTotalSaleAmount();
BigDecimal totalSaleQty = order.getnTotalSaleQty();
String payType = order.getsSalesOrderPayType();
Map<String, Object> salesman = null;
try {
salesman = jdbcTemplate.queryForMap("select * from tSalesman where sSalesmanNO = ?", salesmanNo);
} catch (EmptyResultDataAccessException e) {
e.printStackTrace();
}
if(salesman != null) {
String dateString = DateUtil.format(new Date());
Map<String, Object> shop = jdbcTemplate.queryForMap("select * from tShop where sShopNO = ?", shopNo);
String custNo = (String)shop.get("sCustNO");
String shopMemo = (String)shop.get("sMemo");
Map<String, Object> cust = jdbcTemplate.queryForMap("select * from tCustomer where sCustNO = ?", custNo);;
String custName = (String)cust.get("sCustName");
String sCompanyAccountID = (String)salesman.get("sCompanyAccountID");
WxMessage wxMessage = new WxMessage(sCompanyAccountID);
MiniprogramNotice notice = new MiniprogramNotice();
wxMessage.setMiniprogram_notice(notice);
notice.setDescription(dateString);
notice.setTitle("客户订单通知");
notice.setPage("pages/ordermanage/detail/detail?SalesmanNO=" + salesmanNo + "&isShare=1&id=" + sSalesOrderID + "&isActive=0");
Map<Object, Object> params = new LinkedHashMap<Object, Object>();
params.put("订单状态", "待审核");
params.put("客户", custName);
params.put("订单金额", totalAmount);
params.put("商品数量", totalSaleQty);
params.put("支付方式", payType);
params.put("订单时间", dateString);
params.put("备注", StringUtil.isBlank(shopMemo) ? " " : shopMemo);
notice.setContent_item(params);
wxService.sendMessage(wxMessage);
}
}
}
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