Commit 7ab82873 authored by Quxl's avatar Quxl

x

parent f756b39e
package com.egolm.shop.api;
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.api.service.OrderService;
import com.egolm.shop.common.utils.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.api;
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.api.service.OrderService;
import com.egolm.shop.common.utils.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();
}
}
public static void main(String[] args) {
String md5Key = "FFRlbnBheS5jb20gQ0EgQ2VudGVyMRsw";
String inputXmlString = "<xml><appid><![CDATA[wxb1ec171f1bac3429]]></appid>\r\n" +
"<bank_type><![CDATA[OTHERS]]></bank_type>\r\n" +
"<cash_fee><![CDATA[11310]]></cash_fee>\r\n" +
"<fee_type><![CDATA[CNY]]></fee_type>\r\n" +
"<is_subscribe><![CDATA[N]]></is_subscribe>\r\n" +
"<mch_id><![CDATA[1559500511]]></mch_id>\r\n" +
"<nonce_str><![CDATA[1902442834]]></nonce_str>\r\n" +
"<openid><![CDATA[oqKxp5DEQx9TkuxAUq8aD6RxK3Zs]]></openid>\r\n" +
"<out_trade_no><![CDATA[15766669640469_964423]]></out_trade_no>\r\n" +
"<result_code><![CDATA[SUCCESS]]></result_code>\r\n" +
"<return_code><![CDATA[SUCCESS]]></return_code>\r\n" +
"<sign><![CDATA[D1D039E92700DBADAFBC8891DD312986]]></sign>\r\n" +
"<time_end><![CDATA[20191218190304]]></time_end>\r\n" +
"<total_fee>11310</total_fee>\r\n" +
"<trade_type><![CDATA[JSAPI]]></trade_type>\r\n" +
"<transaction_id><![CDATA[4200000440201912185176717219]]></transaction_id>\r\n" +
"</xml>";
System.out.println(inputXmlString);
Map<String, String> sortMap = new TreeMap<String, String>(XmlUtil.toMap(inputXmlString));
String queryString = HttpUtil.formatToQueryString(sortMap) + "&key=" + md5Key;
String _sign = StringUtil.toMD5HexString(queryString).toUpperCase();
System.out.println(_sign);
System.out.println(sortMap.get("sign"));
}
@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();
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");
} 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.api.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.api.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.api.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.shop.api.service.OrderService;
import com.egolm.shop.api.service.QiyeWxService;
import com.egolm.shop.api.service.QiyeWxService.WxMessage;
import com.egolm.shop.api.service.QiyeWxService.WxMessage.MiniprogramNotice;
import com.egolm.shop.bean.TSalesOrder;
import com.egolm.shop.bean.TSalesOrderDtl;
import com.egolm.shop.common.XException;
import com.egolm.shop.common.utils.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 {
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);
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) {
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("当前时间");
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("订单时间", DateUtil.format(new Date()));
params.put("备注", StringUtil.isBlank(shopMemo) ? " " : shopMemo);
notice.setContent_item(params);
wxService.sendMessage(wxMessage);
}
}
}
package com.egolm.shop.api.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.shop.api.service.OrderService;
import com.egolm.shop.api.service.QiyeWxService;
import com.egolm.shop.api.service.QiyeWxService.WxMessage;
import com.egolm.shop.api.service.QiyeWxService.WxMessage.MiniprogramNotice;
import com.egolm.shop.bean.TSalesOrder;
import com.egolm.shop.bean.TSalesOrderDtl;
import com.egolm.shop.common.XException;
import com.egolm.shop.common.utils.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).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);
}
}
}
package com.egolm.shop.api.service.impl;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.DateUtil;
import com.egolm.common.StringUtil;
import com.egolm.shop.api.service.QiyeWxService;
import com.egolm.shop.common.utils.HttpUtil;
import com.egolm.shop.common.utils.HttpUtil.HttpReqObject;
import com.egolm.shop.common.utils.HttpUtil.HttpRespObject;
import com.egolm.shop.common.utils.HttpUtil.JsonReqObject;
import com.egolm.shop.common.utils.HttpUtil.SSLVersion;
@Service
public class QiyeWxServiceImpl implements QiyeWxService {
@Value("${qiyewx.corpid}")
private String corpid;
@Value("${qiyewx.corpsecret}")
private String corpsecret;
@Value("${qiyewx.baseUrl}")
private String baseUrl;
@Value("${qiyewx.msg.redirect.appid}")
private String redirectAppid;
@Autowired
private RedisTemplate<String, String> redis;
@Override
public String getTokenString() {
String redisCacheKey = PrefixRedisTokenKey + corpid;
Long systemTime = System.currentTimeMillis();
String tokenObjectString = redis.opsForValue().get(redisCacheKey);
if(StringUtil.isNotBlank(tokenObjectString)) {
JSONObject tokenObject = JSON.parseObject(tokenObjectString);
Integer errcode = tokenObject.getInteger("errcode");
if(errcode == 0) {
Long expires_in = tokenObject.getLong("expires_in");
String loadTimeString = tokenObject.getString("loadTime");
if(expires_in != null && StringUtil.isNotBlank(loadTimeString)) {
Date loadTime = DateUtil.parse(loadTimeString, "yyyy-MM-dd HH:mm:ss");
Long expireTime = loadTime.getTime() + (expires_in*1000L);
if((expireTime - DevTime) > systemTime) {
String access_token = tokenObject.getString("access_token");
if(StringUtil.isNotBlank(access_token)) {
return access_token;
}
}
}
}
}
String requestUrl = baseUrl + MessageFormat.format(UrlGetToken, corpid, corpsecret);
HttpRespObject resp = HttpUtil.newInstance().setSSLVersion(SSLVersion.SSLv3).get(new HttpReqObject(requestUrl, null, null));
if(resp.getHttpCode() == 200) {
String text = resp.getResponseBody();
JSONObject tokenObject = JSON.parseObject(text);
Integer code = tokenObject.getInteger("errcode");
if(code == 0) {
tokenObject.put("loadTime", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
redis.opsForValue().set(redisCacheKey, tokenObject.toJSONString());
return tokenObject.getString("access_token");
}
}
return null;
}
@Override
public void refreshToken() {
String redisCacheKey = PrefixRedisTokenKey + corpid;
redis.delete(redisCacheKey);
}
@Override
public void sendMessage(WxMessage wxMessage) {
String tokenString = this.getTokenString();
String requestUrl = baseUrl + MessageFormat.format(UrlSendMsg, tokenString);
Map<String, String> headers = new HashMap<String, String>();
headers.put("content-type", "application/x-www-form-urlencoded");
wxMessage.getMiniprogram_notice().setAppid(redirectAppid);
HttpUtil.newInstance().setSSLVersion(SSLVersion.SSLv3).postJson(new JsonReqObject(requestUrl, wxMessage, headers));
}
}
package com.egolm.shop.api.service.impl;
import java.text.MessageFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.egolm.common.DateUtil;
import com.egolm.common.StringUtil;
import com.egolm.shop.api.service.QiyeWxService;
import com.egolm.shop.api.service.QiyeWxService.WxMessage;
import com.egolm.shop.common.utils.HttpUtil;
import com.egolm.shop.common.utils.HttpUtil.HttpReqObject;
import com.egolm.shop.common.utils.HttpUtil.HttpRespObject;
import com.egolm.shop.common.utils.HttpUtil.JsonReqObject;
import com.egolm.shop.common.utils.HttpUtil.SSLVersion;
@Service
public class QiyeWxServiceImpl implements QiyeWxService {
@Value("${qiyewx.corpid}")
private String corpid;
@Value("${qiyewx.corpsecret}")
private String corpsecret;
@Value("${qiyewx.baseUrl}")
private String baseUrl;
@Value("${qiyewx.msg.redirect.appid}")
private String redirectAppid;
@Autowired
private RedisTemplate<String, String> redis;
@Override
public String getTokenString() {
String redisCacheKey = PrefixRedisTokenKey + corpid;
Long systemTime = System.currentTimeMillis();
String tokenObjectString = redis.opsForValue().get(redisCacheKey);
if(StringUtil.isNotBlank(tokenObjectString)) {
JSONObject tokenObject = JSON.parseObject(tokenObjectString);
Integer errcode = tokenObject.getInteger("errcode");
if(errcode == 0) {
Long expires_in = tokenObject.getLong("expires_in");
String loadTimeString = tokenObject.getString("loadTime");
if(expires_in != null && StringUtil.isNotBlank(loadTimeString)) {
Date loadTime = DateUtil.parse(loadTimeString, "yyyy-MM-dd HH:mm:ss");
Long expireTime = loadTime.getTime() + (expires_in*1000L);
if((expireTime - DevTime) > systemTime) {
String access_token = tokenObject.getString("access_token");
if(StringUtil.isNotBlank(access_token)) {
return access_token;
}
}
}
}
}
String requestUrl = baseUrl + MessageFormat.format(UrlGetToken, corpid, corpsecret);
HttpRespObject resp = HttpUtil.newInstance().setSSLVersion(SSLVersion.SSLv3).get(new HttpReqObject(requestUrl, null, null));
if(resp.getHttpCode() == 200) {
String text = resp.getResponseBody();
JSONObject tokenObject = JSON.parseObject(text);
Integer code = tokenObject.getInteger("errcode");
if(code == 0) {
tokenObject.put("loadTime", DateUtil.format(new Date(), "yyyy-MM-dd HH:mm:ss"));
redis.opsForValue().set(redisCacheKey, tokenObject.toJSONString());
return tokenObject.getString("access_token");
}
}
return null;
}
@Override
public void refreshToken() {
String redisCacheKey = PrefixRedisTokenKey + corpid;
redis.delete(redisCacheKey);
}
@Override
public void sendMessage(WxMessage wxMessage) {
String tokenString = this.getTokenString();
String requestUrl = baseUrl + MessageFormat.format(UrlSendMsg, tokenString);
Map<String, String> headers = new HashMap<String, String>();
headers.put("content-type", "application/x-www-form-urlencoded");
wxMessage.getMiniprogram_notice().setAppid(redirectAppid);
HttpUtil.newInstance().setSSLVersion(SSLVersion.SSLv3).postJson(new JsonReqObject(requestUrl, wxMessage, headers));
}
}
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