12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652 |
- package com.iamberry.rst.service.cm;
- import com.github.pagehelper.PageHelper;
- import com.iamberry.redis.RedisUtils;
- import com.iamberry.rst.core.cm.SalesOrder;
- import com.iamberry.rst.core.cm.SalesOrderItem;
- import com.iamberry.rst.core.cm.StoreInfo;
- import com.iamberry.rst.core.dm.SupplierProduct;
- import com.iamberry.rst.core.fm.ComplaintDetectInfo;
- import com.iamberry.rst.core.fm.InventoryInfo;
- import com.iamberry.rst.core.fm.InventoryLog;
- import com.iamberry.rst.core.order.*;
- import com.iamberry.rst.core.page.PagedResult;
- import com.iamberry.rst.core.sys.Admin;
- import com.iamberry.rst.core.sys.SysConfig;
- import com.iamberry.rst.core.tools.LogisticsInfo;
- import com.iamberry.rst.faces.address.AddressService;
- import com.iamberry.rst.faces.cm.InventoryService;
- import com.iamberry.rst.faces.cm.SalesOrderService;
- import com.iamberry.rst.faces.cm.StoreInfoService;
- import com.iamberry.rst.faces.order.EfastOrderService;
- import com.iamberry.rst.faces.order.OrderWarehouseService;
- import com.iamberry.rst.faces.product.ProductService;
- import com.iamberry.rst.service.cm.mapper.SalesOrderMapper;
- import com.iamberry.rst.service.dm.mapper.SupplierProductMapper;
- import com.iamberry.rst.service.fm.mapper.ComplaintDetectInfoMapper;
- import com.iamberry.rst.service.fm.mapper.InventoryLogMapper;
- import com.iamberry.rst.service.fm.mapper.InventoryMapper;
- import com.iamberry.rst.service.order.mapper.ProvincesLogisticsMapper;
- import com.iamberry.rst.service.product.mapper.ProductMapper;
- import com.iamberry.rst.service.sys.mapper.SysConfigMapper;
- import com.iamberry.rst.util.PageUtil;
- import com.iamberry.wechat.tools.DateTimeUtil;
- import net.sf.json.JSONArray;
- import net.sf.json.JSONObject;
- import org.slf4j.Logger;
- import org.slf4j.LoggerFactory;
- import org.springframework.beans.BeanUtils;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.stereotype.Service;
- import org.springframework.transaction.annotation.Transactional;
- import java.sql.SQLException;
- import java.text.SimpleDateFormat;
- import java.util.*;
- /**
- * Created by liuzhiwei on 2017/10/31.
- */
- @Service
- public class SalesOrderServiceImpl implements SalesOrderService {
- private static Logger logger = LoggerFactory.getLogger(CustomerServiceImpl.class);
- @Autowired
- private SalesOrderMapper salesOrderMapper;
- @Autowired
- private ProductService productService;
- @Autowired
- private StoreInfoService storeInfoService;
- @Autowired
- private EfastOrderService efastOrderService;
- @Autowired
- private SalesOrderService salesOrderService;
- @Autowired
- private SysConfigMapper sysConfigMapper;
- @Autowired
- private AddressService addressService;
- @Autowired
- private ProvincesLogisticsMapper provincesLogisticsMapper;
- @Autowired
- private ProductMapper productMapper;
- @Autowired
- private InventoryMapper inventoryMapper;
- @Autowired
- private InventoryLogMapper inventoryLogMapper;
- @Autowired
- private ComplaintDetectInfoMapper complaintDetectInfoMapper;
- @Autowired
- private OrderWarehouseService orderWarehouseService;
- @Autowired
- private InventoryService inventoryService;
- @Autowired
- private SupplierProductMapper supplierProductMapper;
- @Override
- public Integer addSalesOrder(SalesOrder salesOrder) {
- return salesOrderMapper.addSalesOrder(salesOrder);
- }
- @Override
- @Transactional
- public Integer addSalesOrderManual(SalesOrder salesOrder) {
- salesOrderMapper.addSalesOrder(salesOrder);
- return null;
- }
- @Override
- public SalesOrder getSalesOrderById(Integer salesId) {
- return salesOrderMapper.getSalesOrderById(salesId);
- }
- @Override
- @Transactional(rollbackFor = {SQLException.class, RuntimeException.class})
- public Integer updateSalesOrder(SalesOrder salesOrder) {
- Integer res = salesOrderMapper.updateSalesOrder(salesOrder);
- if (res == null || res <= 0) {
- return 0;
- }
- //确认订单需要填入产品成本价格
- if(salesOrder.getSalesStatus() != null && salesOrder.getSalesStatus() == 1){
- SalesOrderItem salesOrderItem = new SalesOrderItem();
- salesOrderItem.setItemOrderId(salesOrder.getSalesId());
- List<SalesOrderItem> salesOrderItemList = salesOrderMapper.listSalesOrderItem(salesOrderItem);
- List<SalesOrderItem> newSalesOrderItem = new ArrayList<>();
- for (SalesOrderItem soi:salesOrderItemList) {
- SupplierProduct supplierProduct = supplierProductMapper.getSupplierProductByColorId(soi.getItemColorId());
- if(supplierProduct != null){
- SalesOrderItem newSalesOrder = new SalesOrderItem();
- newSalesOrder.setItemCost(supplierProduct.getSpCost());
- newSalesOrder.setItemCostTotal(supplierProduct.getSpCost() * soi.getItemNum());
- newSalesOrder.setItemId(soi.getItemId());
- newSalesOrderItem.add(newSalesOrder);
- }else{
- throw new RuntimeException("确认订单失败-未查询到该产品("+ soi.getItemProductName() +"-"+ soi.getItemProductColor() +")的成本价格");
- }
- }
- for (SalesOrderItem soi : newSalesOrderItem) {
- Integer flag = salesOrderMapper.updateOrderItemObj(soi);
- if(flag < 1){
- throw new RuntimeException("确认订单失败-修改产品项的成本价格失败");
- }
- }
- }
- // 作废订单时需要返还库存
- if(salesOrder.getSalesStatus() != null && salesOrder.getSalesStatus() == 3){
- // 如果已出库则返还库存
- SalesOrder so = salesOrderMapper.getSalesOrderById(salesOrder.getSalesId());
- if(so.getSalesDeliver() == 2){
- returnInventory(salesOrder.getSalesId(),so.getSalesWarehouseId());
- }
- }
- return 1;
- }
- @Transactional
- @Override
- public Integer updateOrderInfo(SalesOrder salesOrder) {
- //删除订单项
- int flag = salesOrderMapper.delOrderItem(salesOrder.getSalesId());
- if (flag <= 0) {
- throw new RuntimeException("删除订单项失败!");
- }
- calculationTotal(salesOrder,salesOrder.getSalesOrderItemList());
- //修改订单
- flag = salesOrderMapper.updateSalesOrder(salesOrder);
- if (flag <= 0) {
- throw new RuntimeException("修改订单失败!");
- }
- //批量添加订单项数据
- flag = salesOrderMapper.addOrderItemList(salesOrder.getSalesOrderItemList());
- if (flag <= 0) {
- throw new RuntimeException("增加订单项失败!");
- }
- // 更新Redis缓存
- Map<String,String> map = System.getenv();
- String name = map.get("COMPUTERNAME");
- if ("iZ94klno8qrZ".equalsIgnoreCase(name)) {
- name = "RST_";
- } else {
- name = "adv_";
- }
- RedisUtils.del(name + "ORDER_ITEM_" + salesOrder.getSalesId());
- return flag;
- }
- @Override
- public Integer addSalesOrderList(List<SalesOrder> list) {
- return salesOrderMapper.addSalesOrderList(list);
- }
- @Override
- public List<SalesOrder> listSalesOrder(SalesOrder salesOrder) {
- return salesOrderMapper.listSalesOrder(salesOrder);
- }
- @Override
- public Integer listSalesOrderNum(SalesOrder salesOrder) {
- return salesOrderMapper.listSalesOrderNum(salesOrder);
- }
- @Override
- public PagedResult<SalesOrder> listSalesOrderPage(int pageNO, int pageSize, SalesOrder salesOrder, boolean isTotalNum) {
- salesOrder.setStartOrderNO((pageNO-1) * pageSize);
- salesOrder.setEndOrderNO(pageSize);
- //查询订单列表信息
- List<SalesOrder> orderList = salesOrderMapper.listSalesOrderNew(salesOrder);
- for(SalesOrder so : orderList){
- SalesOrderItem salesOrderItem = new SalesOrderItem();
- salesOrderItem.setItemOrderId(so.getSalesId());
- List<SalesOrderItem> salesOrderItemList = salesOrderMapper.listSalesOrderItem(salesOrderItem);
- //去除已退货的订单项
- /*int num = salesOrderItemList.size(); 2019年7月10日 更新
- for(int i = 0;i< num;){
- SalesOrderItem item = salesOrderItemList.get(i);
- if(item.getItemNum().intValue() == item.getItemReturnNum().intValue()){
- salesOrderItemList.remove(i);
- num = salesOrderItemList.size();
- i = 0;
- }else{
- i++;
- }
- }*/
- for(SalesOrderItem item : salesOrderItemList){//判断是否包含净水机 1是 2否
- if(item.getColorIsMachine() != null){
- if(item.getColorIsMachine() == 1){
- so.setIsDevelop(1);
- }else{
- so.setIsDevelop(2);
- }
- }else{
- so.setIsDevelop(1);
- }
- }
- so.setSalesOrderItemList(salesOrderItemList);
- }
- PagedResult<SalesOrder> result = PageUtil.getPage(orderList);
- // 查询分页的数据
- int count = salesOrderMapper.listSalesOrderNum(salesOrder);
- result.setTotal(count);
- if(count%pageSize==0){
- count=count/pageSize;
- } else{
- count=count/pageSize+1;
- }
- result.setPages(count);
- result.setPageNo(pageNO);
- result.setPageSize(pageSize);
- return result;
- }
- @Override
- public List<PostInfo> listWaitPrintOrderNum(Integer salesWarehouseId) {
- return salesOrderMapper.listWaitPrintOrderNum(salesWarehouseId);
- }
- @Override
- public PagedResult<SalesOrder> listAwaitSendSalesOrderPage(int pageNO, int pageSize, SalesOrder salesOrder, boolean isTotalNum) {
- PageHelper.startPage(pageNO, pageSize, isTotalNum);
- //查询订单列表信息
- List<SalesOrder> orderList = salesOrderMapper.listAwaitSendSalesOrderPage(salesOrder);
- return PageUtil.getPage(orderList);
- }
- @Override
- @Transactional
- public boolean addOrderAndItem(SalesOrder salesOrder, List<SalesOrderItem> list) throws Exception {
- if (list == null || list.size() == 0) {
- throw new RuntimeException("获取订单信息出错!");
- }
- SalesOrder verifyOrder = new SalesOrder();
- verifyOrder.setSalesOrderId(salesOrder.getSalesOrderId());
- //查询该订单是否存在,如果存在,不需要再次添加到订单中
- int count = salesOrderMapper.getOrderInfoCount(verifyOrder);
- if (count > 0) {
- return true;
- }
- //添加订单数据
- calculationTotal(salesOrder,list);
- try {
- int orderNum = salesOrderMapper.addSalesOrder(salesOrder);
- if (orderNum <= 0) {
- throw new RuntimeException("获取订单信息出错!");
- }
- } catch (Exception e) {
- return true;
- }
- for (SalesOrderItem item : list) {
- item.setItemOrderId(salesOrder.getSalesId());
- }
- //批量添加订单项数据
- int itemNum = salesOrderMapper.addOrderItemList(list);
- if (itemNum <= 0) {
- throw new RuntimeException("获取订单信息出错!");
- }
- return true;
- }
- @Override
- @Transactional
- public SalesOrder addOrderAndIteminfo(SalesOrder salesOrder, List<SalesOrderItem> list) {
- calculationTotal(salesOrder,list);
- //添加订单数据
- int orderNum = salesOrderMapper.addSalesOrder(salesOrder);
- if (orderNum <= 0) {
- return salesOrder;
- }
- for (SalesOrderItem item : list) {
- item.setItemOrderId(salesOrder.getSalesId());
- }
- //批量添加订单项数据
- int itemNum = salesOrderMapper.addOrderItemList(list);
- if (itemNum <= 0) {
- return salesOrder;
- }
- return salesOrder;
- }
- @Override
- public void parseOrder(SalesOrder oginerOrder, List<SalesOrder> listOrder) {
- // 订单项拆分完成,直接返回
- if (oginerOrder.getSalesOrderItemList().size() <= 0) {
- return;
- }
- List<DownsingleRuleInfo> listDownsingleRuleInfo = salesOrderService.listDownsingleRule();
- if(listDownsingleRuleInfo.size() < 1){
- listOrder.add(oginerOrder);
- return;
- }
- // 拆单,比较的是数量和产品
- Map<String, SalesOrderItem> itemMap = new HashMap<>(oginerOrder.getSalesOrderItemList().size());
- for (SalesOrderItem item : oginerOrder.getSalesOrderItemList()) {
- SalesOrderItem itemTwo = new SalesOrderItem();
- BeanUtils.copyProperties(item,itemTwo);
- itemMap.put(item.getItemColorBar(), itemTwo);
- }
- // 遍历拆单规则
- int ruleCount = 0;
- for (DownsingleRuleInfo rule : listDownsingleRuleInfo) {
- // 一个拆单规则
- int count = 0;
- for (DownsingleRuleItemInfo item : rule.getDownsingleRuleItemList()) {
- if (itemMap.get(item.getDownsingleItemBar()) != null) {
- if (item.getDownsingleItemNum() <= itemMap.get(item.getDownsingleItemBar()).getItemNum()) {
- count ++;
- }
- }
- }
- if (count == rule.getDownsingleRuleItemList().size()) {
- // 满足拆单条件
- SalesOrder newOrder = new SalesOrder();
- BeanUtils.copyProperties(oginerOrder,newOrder);
- newOrder.setSalesOrderItemList(new ArrayList<SalesOrderItem>(count));
- for (DownsingleRuleItemInfo item : rule.getDownsingleRuleItemList()) {
- SalesOrderItem temp = new SalesOrderItem();
- BeanUtils.copyProperties(itemMap.get(item.getDownsingleItemBar()),temp);
- temp.setItemNum(item.getDownsingleItemNum());
- newOrder.getSalesOrderItemList().add(temp);
- }
- listOrder.add(newOrder);
- // 继续递归
- for (DownsingleRuleItemInfo item : rule.getDownsingleRuleItemList()) {
- if (item.getDownsingleItemNum().equals(itemMap.get(item.getDownsingleItemBar()).getItemNum())) {
- // 数量和拆单规则相同,则删除原订单的订单项
- /*oginerOrder.getSalesOrderItemList().remove(itemMap.get(item.getDownsingleItemBar()));*/
- for(int i = 0;i<oginerOrder.getSalesOrderItemList().size();i++){
- if(oginerOrder.getSalesOrderItemList().get(i).getItemColorBar() .equals(item.getDownsingleItemBar())){
- oginerOrder.getSalesOrderItemList().remove(i);
- }
- }
- } else {
- // SalesOrderItem orderItem = itemMap.get(item.getDownsingleItemBar());
- SalesOrderItem orderItem = new SalesOrderItem();
- BeanUtils.copyProperties(itemMap.get(item.getDownsingleItemBar()),orderItem);
- int oldCount = orderItem.getItemNum();
- /*orderItem.setItemNum(oldCount - item.getDownsingleItemNum());*/
- for(int i = 0;i<oginerOrder.getSalesOrderItemList().size();i++){
- if(oginerOrder.getSalesOrderItemList().get(i).getItemColorBar() .equals(item.getDownsingleItemBar())){
- oginerOrder.getSalesOrderItemList().get(i).setItemNum(oldCount - item.getDownsingleItemNum());
- }
- }
- }
- }
- salesOrderService.parseOrder(oginerOrder, listOrder);
- break;
- } else {
- // 不满足, 继续下一个规则
- // 如果是最后一个拆单规则,则不拆单
- if ((ruleCount + 1) == listDownsingleRuleInfo.size()) {
- if (oginerOrder.getSalesOrderItemList().size() > 0) {
- listOrder.add(oginerOrder);
- }
- }
- }
- ruleCount++;
- }
- }
- @Override
- @Transactional
- public boolean addRstOrderAndIteminfo(SalesOrder salesOrder){
- //总支付金额
- Integer salesPayMoney = 0;
- for (SalesOrderItem soi : salesOrder.getSalesOrderItemList()) {
- if(soi.getItemProductDiscount() != null){
- Integer differenceNumber = soi.getItemNum()*soi.getItemProductDiscount() - soi.getItemTotal();
- differenceNumber = Math.abs(differenceNumber); //绝对值
- if(soi.getItemProductDiscount() == 0 || soi.getItemProductDiscount() == 1 || differenceNumber > 1){
- Double dis = Double.valueOf(soi.getItemTotal())/soi.getItemNum();
- soi.setItemProductDiscount(dis.intValue());
- }
- }else{
- Double dis = Double.valueOf(soi.getItemTotal())/soi.getItemNum();
- soi.setItemProductDiscount(dis.intValue());
- }
- salesPayMoney += soi.getItemTotal();
- }
- //合并订单项-------------statr
- List<SalesOrderItem> listItem = salesOrder.getSalesOrderItemList();
- salesOrder.setSalesOrderItemList(null);
- List<SalesOrderItem> list = new ArrayList<>();
- for (int i = 0;i<listItem.size();i++){
- if(i < listItem.size() - 1 ){
- for(int j = 0;j<listItem.size();j++){
- if (i != j){
- if(listItem.get(i).getItemColorBar().equals(listItem.get(j).getItemColorBar())){
- listItem.get(i).setItemNum(listItem.get(i).getItemNum()+listItem.get(j).getItemNum());
- }
- }
- }
- }
- boolean bl = true;
- for (SalesOrderItem salesOrderItem : list){
- if(salesOrderItem.getItemColorBar().equals(listItem.get(i).getItemColorBar())){
- bl = false;
- }
- }
- if(bl){
- list.add(listItem.get(i));
- }
- }
- //合并订单项----------------------end
- //匹配拆单规则 分割订单-------------state
- List<SalesOrder> listSalesOrder = new ArrayList<>();
- salesOrder.setSalesOrderItemList(list);
- salesOrderService.parseOrder(salesOrder, listSalesOrder);
- //匹配拆单规则 分割订单-------------end
- boolean msg = false;
- /*根据省份来分配物流公司*/
- salesOrderService.setProvincesLogistics(listSalesOrder);
- /*查询成本*/
- for (SalesOrder so:listSalesOrder) {
- for (SalesOrderItem soi:so.getSalesOrderItemList()) {
- SupplierProduct supplierProduct = supplierProductMapper.getSupplierProductByColorId(soi.getItemColorId());
- if(supplierProduct != null){
- soi.setItemCost(supplierProduct.getSpCost());
- soi.setItemCostTotal(supplierProduct.getSpCost() * soi.getItemNum());
- }else{
- throw new RuntimeException("确认订单失败-未查询到该产品("+ soi.getItemProductName() +"-"+ soi.getItemProductColor() +")的成本价格");
- }
- }
- }
- for (int i = 0; i < listSalesOrder.size() ; i++) {
- boolean isLastItem = false;
- if((i+1) >= listSalesOrder.size()){
- isLastItem = true;
- }
- SalesOrder so = listSalesOrder.get(i);
- for (int j = 0; j < so.getSalesOrderItemList().size(); j++) {
- SalesOrderItem soi = so.getSalesOrderItemList().get(j);
- if((j+1) >= so.getSalesOrderItemList().size() && isLastItem){
- soi.setItemTotal(salesPayMoney);
- if(salesPayMoney > 0){
- soi.setItemProductDiscount(salesPayMoney/soi.getItemNum());
- }
- }else{
- Integer total = soi.getItemNum()*soi.getItemProductDiscount();
- soi.setItemTotal(total);
- salesPayMoney -= total;
- }
- }
- }
- //判断主从订单--------------------state
- if (listSalesOrder.size() > 0){
- SalesOrder mainOrder = null;
- for (int s = 0;s < listSalesOrder.size();s++){
- if(mainOrder == null){
- for(int i = 0;i<listSalesOrder.get(s).getSalesOrderItemList().size();i++){
- int isMachine = salesOrderService.getIsMachine(listSalesOrder.get(s).getSalesOrderItemList().get(i).getItemColorBar());
- if( isMachine == 1){//1:水机 2:其它产品 0:未查到
- mainOrder = listSalesOrder.get(s);
- listSalesOrder.remove(s);
- break;
- }
- }
- }
- }
- if(mainOrder == null){//如果不存有水机的订单则默认第一个订单为主订单
- mainOrder = listSalesOrder.get(0);
- listSalesOrder.remove(0);
- }
- //判断主从订单--------------------end
- msg = salesOrderService.addRstOrderinfo(mainOrder,listSalesOrder,null);
- }
- return msg;
- }
- @Override
- @Transactional
- public boolean addRstOrderinfo(SalesOrder mainOrder,List<SalesOrder> listSalesOrder,String[] detectIds) {
- Integer flag = salesOrderMapper.getOrderBySalesDealCodeNum(mainOrder.getSalesDealCode());
- if(flag > 0){
- throw new RuntimeException("交易号("+ mainOrder.getSalesDealCode() +")重复,请重新生成交易号!");
- }
- if(mainOrder.getSalesAddressPostcode() == null){
- throw new RuntimeException("未获取到邮政编码信息,请检查地址信息!");
- }
- if(mainOrder.getSalesCreateTime() == null){
- /*保证时间与以前一样*/
- mainOrder.setSalesCreateTime(new Date());
- }
- calculationTotal(mainOrder,mainOrder.getSalesOrderItemList());
- int orderNum = salesOrderMapper.addSalesOrder(mainOrder);
- if (orderNum <= 0) {
- throw new RuntimeException("添加订单出错--------!");
- }
- for (SalesOrderItem item : mainOrder.getSalesOrderItemList()) {
- item.setItemOrderId(mainOrder.getSalesId());
- }
- //批量添加订单项数据
- int itemNum = salesOrderMapper.addOrderItemList(mainOrder.getSalesOrderItemList());
- if (itemNum <= 0) {
- throw new RuntimeException("添加订单出错--------!");
- }else{
- if(listSalesOrder.size() > 0){
- for (int i = 0;i<listSalesOrder.size();i++){
- listSalesOrder.get(i).setSalesDealCode(listSalesOrder.get(i).getSalesDealCode()+"-"+(i+1));
- if(listSalesOrder.get(i).getSalesOrderId() != null && !"".equals(listSalesOrder.get(i).getSalesOrderId())){
- listSalesOrder.get(i).setSalesOrderId(listSalesOrder.get(i).getSalesOrderId()+"-"+(i+1));
- }
- listSalesOrder.get(i).setSalesMainOrderId(mainOrder.getSalesId());
- listSalesOrder.get(i).setSalesId(null);
- calculationTotal(listSalesOrder.get(i),listSalesOrder.get(i).getSalesOrderItemList());
- orderNum = salesOrderMapper.addSalesOrder(listSalesOrder.get(i));
- if (orderNum <= 0) {
- throw new RuntimeException("添加订单出错--------!");
- }
- for (SalesOrderItem item : listSalesOrder.get(i).getSalesOrderItemList()) {
- item.setItemOrderId(listSalesOrder.get(i).getSalesId());
- }
- //批量添加订单项数据
- itemNum = salesOrderMapper.addOrderItemList(listSalesOrder.get(i).getSalesOrderItemList());
- if (itemNum <= 0) {
- throw new RuntimeException("添加订单出错--------!");
- }
- }
- }
- }
- //修为维修记录为已下单
- if(detectIds != null){
- if(detectIds.length > 0){
- for(String detectId : detectIds){
- ComplaintDetectInfo detectInfo = new ComplaintDetectInfo();
- detectInfo.setDetectId(Integer.valueOf(detectId));
- detectInfo.setDetectPlaceorder(2);
- detectInfo.setSalesOrderId(mainOrder.getSalesOrderId());
- /*detectInfo.setDetectSalesId(mainOrder.getSalesId());*/
- complaintDetectInfoMapper.updateDetectById(detectInfo);
- }
- }
- }
- return true;
- }
- /**
- * 根据省份来分配物流公司
- * @param listSalesOrder
- * @return
- */
- @Override
- public void setProvincesLogistics(List<SalesOrder> listSalesOrder){
- for (SalesOrder salesOrder:listSalesOrder) {
- boolean flag = false;
- for (SalesOrderItem salesOrderItem:salesOrder.getSalesOrderItemList()) {
- ProductColor productColor = productService.getColorByBar(salesOrderItem.getItemColorBar());
- if(productColor.getColorIsMachine() == 1){
- flag = true;
- }
- }
- if(flag){
- String addresses[] = salesOrder.getSalesAddressInfo().split("-");
- if(addresses == null || addresses.length < 3){
- addresses = salesOrder.getSalesAddressInfo().split(" ");
- }
- if(addresses == null || addresses.length < 3){
- addresses = salesOrder.getSalesAddressInfo().split("_");
- }
- if(addresses == null || addresses.length < 3){
- break;
- }
- String provincesStr = addresses[0];
- provincesStr = provincesStr.substring(0,2);
- ProvincesLogistics provincesLogistics = new ProvincesLogistics();
- provincesLogistics.setProvince(provincesStr);
- List<ProvincesLogistics> provincesLogisticsList = provincesLogisticsMapper.getProvincesLogisticsList(provincesLogistics);
- if(provincesLogisticsList == null || provincesLogisticsList.size() < 1){
- /*未查到地址*/
- break;
- }
- //设置快递公司
- provincesLogistics = provincesLogisticsList.get(0);
- if(provincesLogistics.getLogisticsRstCode() != null){
- salesOrder.setSalesPostFirm(provincesLogistics.getLogisticsRstCode());
- }
- }
- }
- }
- @Override
- public List<SalesOrderItem> listSalesOrderItem(SalesOrderItem salesOrderItem) {
- // 通过计算机名称来判断服务器环境
- /*Map<String,String> map = System.getenv();
- String name = map.get("COMPUTERNAME");
- if ("iZ94klno8qrZ".equalsIgnoreCase(name)) {
- name = "RST_";
- } else {
- name = "adv_";
- }
- // 获取数据
- String key = name + "ORDER_ITEM_" + salesOrderItem.getItemOrderId();
- List<SalesOrderItem> list = RedisUtils.list(key, SalesOrderItem.class);
- if (list == null ) {
- list = salesOrderMapper.listSalesOrderItem(salesOrderItem);
- RedisUtils.put(key, list);
- RedisUtils.expire(key, new Date(259200000 + System.currentTimeMillis()));
- }*/
- return salesOrderMapper.listSalesOrderItem(salesOrderItem);
- }
- @Override
- public Integer updateOrderList(JSONArray orderList, List<SalesOrder> list) {
- List<SalesOrder> salesOrders = new ArrayList<SalesOrder>();
- //订单号相同时,判断状态,发货状态,物流公司,物流单号等是否相同,如果有一个不同,则需添加到salesOrders中进行同步
- for (int i = 0;i < orderList.size();i++) {
- JSONObject orderInfo = orderList.getJSONObject(i);
- for (SalesOrder salesOrder : list) {
- if (orderInfo.get("order_sn").equals(salesOrder.getSalesOrderId())
- && !(orderInfo.getInt("order_status") == salesOrder.getSalesStatus()
- && orderInfo.getInt("shipping_status") == salesOrder.getSalesShippingStatus()
- && orderInfo.getInt("pay_status") == salesOrder.getSalesPayStatus()
- && orderInfo.getInt("process_status") == salesOrder.getSalesProcessStatus()
- && orderInfo.getInt("is_send") == salesOrder.getSalesIsSend()
- && orderInfo.getInt("is_locked") == salesOrder.getSalesIsLocked()
- && orderInfo.getInt("is_separate") == salesOrder.getSalesIsSeparate()
- && orderInfo.getString("shipping_name").equals(salesOrder.getSalesPostFirm())
- && orderInfo.getString("invoice_no").equals(salesOrder.getSalesPostNum())
- )) {
- SalesOrder order = new SalesOrder();
- order.setSalesId(salesOrder.getSalesId());
- order.setSalesStatus(orderInfo.getInt("order_status"));
- order.setSalesShippingStatus(orderInfo.getInt("shipping_status"));
- order.setSalesPayStatus(orderInfo.getInt("pay_status"));
- order.setSalesProcessStatus(orderInfo.getInt("process_status"));
- order.setSalesIsSend(orderInfo.getInt("is_send"));
- order.setSalesIsLocked(orderInfo.getInt("is_locked"));
- order.setSalesIsSeparate(orderInfo.getInt("is_separate"));
- order.setSalesPostFirm(orderInfo.getString("shipping_name"));
- order.setSalesPostNum(orderInfo.getString("invoice_no"));
- salesOrders.add(order);
- }
- }
- }
- if (salesOrders != null && salesOrders.size() > 0) {
- //批量修改订单状态等信息
- return salesOrderMapper.updateOrderList(salesOrders);
- } else {
- return 1;
- }
- }
- @Override
- public Integer updateReturnOrderList(JSONArray orderList, List<SalesOrder> list) {
- List<SalesOrder> salesOrders = new ArrayList<SalesOrder>();
- //订单号相同时,判断状态,发货状态,物流公司,物流单号等是否相同,如果有一个不同,则需添加到salesOrders中进行同步
- for (int i = 0;i < orderList.size();i++) {
- JSONObject orderInfo = orderList.getJSONObject(i);
- for (SalesOrder salesOrder : list) {
- if (orderInfo.get("relating_order_sn").equals(salesOrder.getSalesOrderId())) {
- SalesOrder order = new SalesOrder();
- switch (orderInfo.getInt("process_type")) {
- case 1://退货
- order.setSalesOrderStatus(3);
- break;
- case 4://换货
- order.setSalesOrderStatus(2);
- break;
- default:
- order.setSalesOrderStatus(3);
- break;
- }
- order.setSalesId(salesOrder.getSalesId());
- salesOrders.add(order);
- }
- }
- }
- //批量修改订单状态等信息
- return salesOrderMapper.updateOrderList(list);
- }
- @Override
- public void addSalesOrderList(JSONObject obj) throws Exception{
- if (obj == null) {
- return;
- }
- JSONArray orderList = obj.getJSONArray("list");
- if (orderList == null || orderList.size() == 0) {
- return;
- }
- String endTime = sysConfigMapper.getSysConfig(1);
- for (int i = 0;i < orderList.size();i++) {
- JSONObject order = orderList.getJSONObject(i);
- //获取订单详情
- JSONObject orderInfo = null;
- try{
- orderInfo = efastOrderService.getOrderFormEfast(order.getString("deal_code"));
- }catch (Exception e){
- logger.info("获取订单失败;异常编号:505;失败原因:"+ e.getMessage() +"--获取失败订单号:" + orderList.getJSONObject(i).getString("deal_code"));
- }
- if (orderInfo == null) {
- continue;
- }
- if (!orderInfo.has("orders")) {
- continue;
- }
- //获取订单项集合
- JSONArray itemArray = orderInfo.getJSONArray("orders");
- if (itemArray == null || itemArray.size() == 0) {
- continue;
- }
- SalesOrder salesOrder = new SalesOrder();
- salesOrder.setSalesOrderId(order.getString("order_sn"));//订单编号
- salesOrder.setSalesDealCode(order.getString("deal_code"));//交易号
- salesOrder.setSalesOrderStatus(1);//订单状态
- salesOrder.setSalesShippingStatus(order.getInt("shipping_status"));//发货状态 0:未发货,1:已发货,3:备货中
- salesOrder.setSalesPayStatus(order.getInt("pay_status"));//是否付款 0:未付款,2:已付款
- salesOrder.setSalesProcessStatus(order.getInt("process_status"));//单据状态
- salesOrder.setSalesIsSend(order.getInt("is_send"));//是否通知配货
- salesOrder.setSalesIsLocked(order.getInt("is_locked"));//是否锁定
- salesOrder.setSalesIsSeparate(order.getInt("is_separate"));//是否缺货
- salesOrder.setSalesStatus(order.getInt("order_status"));//订单状态 0:未确认,1:已确认,2:挂起,3:作废
- salesOrder.setSalesPostFirm(order.getString("shipping_name").trim());//快递方式代码
- salesOrder.setSalesPostNum(order.getString("invoice_no").trim());//快递单号
- salesOrder.setSalesOpenId(order.getString("mobile").trim());//唯一标识
- salesOrder.setSalesPayType(efastOrderService.getPayType(order.getString("pay_name").trim()));//支付方式
- salesOrder.setSalesPayTime(new Date(order.getLong("pay_time")*1000));//支付时间
- salesOrder.setSalesUserRemark(order.getString("postscript"));//买家留言
- salesOrder.setSalesAdminRemark(order.getString("to_buyer"));//商家留言
- salesOrder.setSalesAmount((int)(order.getDouble("order_amount")*100));//应付款
- salesOrder.setSalesPayMoney((int)(order.getDouble("money_paid")*100));//已付款
- salesOrder.setSalesAddressName(order.getString("consignee").trim());//收货人
- String mobile = order.getString("mobile").replaceAll("[\\u00A0]+", "").trim();
- salesOrder.setSalesAddressTel(mobile);//收货人电话
- salesOrder.setSalesAddressInfo(order.getString("address").replaceAll(" ","-"));//收货地址
- salesOrder.setSalesShippingFee((int)(order.getDouble("shipping_fee")*100));//邮费
- salesOrder.setSalesCreateTime(DateTimeUtil.parse(order.getString("create_time"),"yyyy-MM-dd HH:mm:ss"));//创建时间
- if (order.getInt("shipping_status") == 1) {
- if(order.has("delivery_time")){
- salesOrder.setSalesSendTime(DateTimeUtil.parse(order.getString("delivery_time"),"yyyy-MM-dd HH:mm:ss"));//发货时间
- }else{
- salesOrder.setSalesSendTime(new Date());//发货时间
- }
- }
- salesOrder.setSalesDiscountMoney(salesOrder.getSalesAmount() - salesOrder.getSalesPayMoney());//优惠金额
- salesOrder.setSalesPledgeMoney(0);//押金金额
- salesOrder.setSalesRemainDeposit(0);//待提取金额
- salesOrder.setSalesSendType(2);//发货方式,默认为物流发货
- salesOrder.setSalesSalesTime(salesOrder.getSalesCreateTime());//订购时间
- salesOrder.setSalesWaitMoney(0);//待付金额
- salesOrder.setSalesLastMoney(salesOrder.getSalesPayMoney());//本次支付金额
- salesOrder.setSalesPayNumber("0000");//支付尾号
- salesOrder.setSalesType(1);//订单类型
- endTime = order.getString("create_time"); //获取
- //查询店铺信息
- StoreInfo storeInfo = new StoreInfo();
- storeInfo.setStoreEfast(order.getString("sd_id"));
- List<StoreInfo> storeList = storeInfoService.listStore(storeInfo);
- int storeId = 0;
- int companyId = 0;
- if (storeList != null && storeList.size() > 0) {
- storeInfo = storeList.get(0);
- storeId = storeInfo.getStoreId();
- companyId = storeInfo.getCompanyId();
- }
- salesOrder.setSalesStoreId(storeId);//店铺id
- salesOrder.setSalesCompanyId(companyId);//销售公司id
- List<SalesOrderItem> itemList = new ArrayList<SalesOrderItem>();
- for (int j = 0;j < itemArray.size();j++) {
- ProductColor color = new ProductColor();
- JSONObject itemJson = itemArray.getJSONObject(j);
- SalesOrderItem item = new SalesOrderItem();
- color.setColorBar(itemJson.getString("goods_sn"));
- List<ProductColor> colorList = productService.listproductAndColor(color);
- if (colorList != null && colorList.size() > 0) {
- color = colorList.get(0);
- item.setItemColorBar(itemJson.getString("goods_sn"));//商品69码
- item.setItemNum(itemJson.getInt("goods_number"));//商品数量
- item.setItemCreateTime(salesOrder.getSalesCreateTime());
- item.setItemColorId(color.getColorId());
- item.setItemProductColor(color.getColorName());
- item.setItemProductDiscount(color.getColorDiscount());
- item.setItemProductId(color.getColorProductId());
- item.setItemProductName(color.getProductName());
- item.setItemProductPic(color.getColorPicture());
- item.setItemProductType(color.getProductType());
- item.setItemProductPrice(color.getColorPrice());
- item.setItemIsSource(1);
- itemList.add(item);
- }
- // else {
- // //获取配件信息
- // FittingsInfo fittingsInfo = new FittingsInfo();
- // fittingsInfo.setFittingsBar(itemJson.getString("goods_sn"));
- // List<FittingsInfo> Fittings = fittingsInfoMapper.listFittings(fittingsInfo);
- // if (Fittings == null || Fittings.size() == 0) {
- // continue;
- // }
- // fittingsInfo = Fittings.get(0);
- // item.setItemColorBar(itemJson.getString("goods_sn"));//商品69码
- // item.setItemNum(itemJson.getInt("goods_number"));//商品数量
- // item.setItemCreateTime(salesOrder.getSalesCreateTime());
- // item.setItemColorId(fittingsInfo.getFittingsId());
- // item.setItemProductColor(fittingsInfo.getFittingsName());
- // item.setItemProductDiscount(fittingsInfo.getFittingsDiscount());
- // item.setItemProductId(fittingsInfo.getProductId());
- // item.setItemProductName(fittingsInfo.getFittingsName());
- // item.setItemProductPic("");
- // item.setItemProductType(0);
- // item.setItemProductPrice(fittingsInfo.getFittingsPrice());
- // item.setItemIsSource(2);
- // itemList.add(item);
- // }
- }
- //添加订单和订单项
- try{
- salesOrderService.addOrderAndItem(salesOrder,itemList);
- }catch (Exception e){
- logger.info("添加订单失败,异常编号:505;失败原因:+"+ e.getMessage() +"Efast编号:"+ salesOrder.getSalesOrderId());
- }
- }
- SysConfig sysConfig = new SysConfig(1,endTime);
- sysConfigMapper.updateSysConfig(sysConfig);
- }
- @Override
- @Transactional
- public boolean syncEfastOrder(JSONObject orderInfo) throws Exception {
- if (orderInfo == null) {
- throw new RuntimeException("获取Efast订单信息出错!");
- }
- if (!orderInfo.has("orders")) {
- throw new RuntimeException("获取Efast订单信息出错!");
- }
- //获取订单项集合
- JSONArray itemArray = orderInfo.getJSONArray("orders");
- if (itemArray == null || itemArray.size() == 0) {
- throw new RuntimeException("获取Efast订单信息出错!");
- }
- SalesOrder salesOrder = new SalesOrder();
- salesOrder.setSalesOrderId(orderInfo.getString("order_sn"));//订单编号
- salesOrder.setSalesDealCode(orderInfo.getString("deal_code"));//交易号
- salesOrder.setSalesOrderStatus(1);//订单状态
- salesOrder.setSalesShippingStatus(orderInfo.getInt("shipping_status"));//发货状态 0:未发货,1:已发货,3:备货中
- salesOrder.setSalesPayStatus(orderInfo.getInt("pay_status"));//是否付款 0:未付款,2:已付款
- salesOrder.setSalesProcessStatus(orderInfo.getInt("process_status"));//单据状态
- salesOrder.setSalesIsSend(orderInfo.getInt("is_send"));//是否通知配货
- salesOrder.setSalesIsLocked(orderInfo.getInt("is_locked"));//是否锁定
- salesOrder.setSalesIsSeparate(orderInfo.getInt("is_separate"));//是否缺货
- salesOrder.setSalesStatus(orderInfo.getInt("order_status"));//订单状态 0:未确认,1:已确认,2:挂起,3:作废
- salesOrder.setSalesPostFirm(new String(orderInfo.getString("shipping_name")).trim());//快递方式代码
- salesOrder.setSalesPostNum(new String(orderInfo.getString("invoice_no")).trim());//快递单号
- salesOrder.setSalesOpenId(orderInfo.getString("mobile").trim());//唯一标识
- salesOrder.setSalesPayType(efastOrderService.getPayType(orderInfo.getString("pay_name").trim()));//支付方式
- salesOrder.setSalesPayTime(new Date(orderInfo.getLong("pay_time")*1000));//支付时间
- salesOrder.setSalesUserRemark(orderInfo.getString("postscript"));//买家留言
- salesOrder.setSalesAdminRemark(orderInfo.getString("to_buyer"));//商家留言
- salesOrder.setSalesAmount((int)(orderInfo.getDouble("order_amount")*100));//应付款
- salesOrder.setSalesPayMoney((int)(orderInfo.getDouble("money_paid")*100));//已付款
- salesOrder.setSalesAddressName(orderInfo.getString("consignee"));//收货人
- String mobile = orderInfo.getString("mobile").replaceAll("[\\u00A0]+", "");
- salesOrder.setSalesAddressTel(mobile.trim());//收货人电话
- salesOrder.setSalesAddressInfo(orderInfo.getString("address").replaceAll(" ","-"));//收货地址
- salesOrder.setSalesShippingFee((int)(orderInfo.getDouble("shipping_fee")*100));//邮费
- salesOrder.setSalesCreateTime(new Date(orderInfo.getLong("pay_time")*1000));//创建时间
- if (orderInfo.getInt("shipping_status") == 1) {
- if(orderInfo.has("delivery_time")){
- salesOrder.setSalesSendTime(DateTimeUtil.parse(orderInfo.getString("delivery_time"),"yyyy-MM-dd HH:mm:ss"));//发货时间
- }else{
- salesOrder.setSalesSendTime(new Date());//发货时间
- }
- }
- salesOrder.setSalesDiscountMoney(salesOrder.getSalesAmount() - salesOrder.getSalesPayMoney());//优惠金额
- salesOrder.setSalesPledgeMoney(0);//押金金额
- salesOrder.setSalesRemainDeposit(0);//待提取金额
- salesOrder.setSalesSendType(2);//发货方式,默认为物流发货
- salesOrder.setSalesSalesTime(salesOrder.getSalesCreateTime());//订购时间
- salesOrder.setSalesWaitMoney(0);//待付金额
- salesOrder.setSalesLastMoney(salesOrder.getSalesPayMoney());//本次支付金额
- salesOrder.setSalesPayNumber("0000");//支付尾号
- salesOrder.setSalesType(1);//订单类型
- //查询店铺信息
- StoreInfo storeInfo = new StoreInfo();
- if (orderInfo.has("sd_id")) {
- storeInfo.setStoreEfast(orderInfo.getString("sd_id"));
- } else {
- storeInfo.setStoreEfast("1");
- }
- List<StoreInfo> storeList = storeInfoService.listStore(storeInfo);
- int storeId = 0;
- int companyId = 0;
- if (storeList != null && storeList.size() > 0) {
- storeInfo = storeList.get(0);
- storeId = storeInfo.getStoreId();
- companyId = storeInfo.getCompanyId();
- }
- salesOrder.setSalesStoreId(storeId);//店铺id
- salesOrder.setSalesCompanyId(companyId);//销售公司id
- List<SalesOrderItem> itemList = new ArrayList<SalesOrderItem>();
- for (int j = 0;j < itemArray.size();j++) {
- ProductColor color = new ProductColor();
- JSONObject itemJson = itemArray.getJSONObject(j);
- SalesOrderItem item = new SalesOrderItem();
- color.setColorBar(itemJson.getString("goods_barcode"));
- List<ProductColor> colorList = productService.listproductAndColor(color);
- if (colorList != null && colorList.size() > 0) {
- color = colorList.get(0);
- item.setItemColorBar(itemJson.getString("goods_barcode"));//商品69码
- item.setItemNum(itemJson.getInt("goods_number"));//商品数量
- item.setItemCreateTime(salesOrder.getSalesCreateTime());
- item.setItemColorId(color.getColorId());
- item.setItemProductColor(color.getColorName());
- item.setItemProductDiscount(color.getColorDiscount());
- item.setItemProductId(color.getColorProductId());
- item.setItemProductName(color.getProductName());
- item.setItemProductPic(color.getColorPicture());
- item.setItemProductType(color.getProductType());
- item.setItemProductPrice(color.getColorPrice());
- item.setItemIsSource(1);
- itemList.add(item);
- }
- // else {
- // //获取配件信息
- // FittingsInfo fittingsInfo = new FittingsInfo();
- // fittingsInfo.setFittingsBar(itemJson.getString("goods_barcode"));
- // List<FittingsInfo> Fittings = fittingsInfoMapper.listFittings(fittingsInfo);
- // if (Fittings == null || Fittings.size() == 0) {
- // continue;
- // }
- // fittingsInfo = Fittings.get(0);
- // item.setItemColorBar(itemJson.getString("goods_barcode"));//商品69码
- // item.setItemNum(itemJson.getInt("goods_number"));//商品数量
- // item.setItemCreateTime(salesOrder.getSalesCreateTime());
- // item.setItemColorId(fittingsInfo.getFittingsId());
- // item.setItemProductColor(fittingsInfo.getFittingsName());
- // item.setItemProductDiscount(fittingsInfo.getFittingsDiscount());
- // item.setItemProductId(fittingsInfo.getProductId());
- // item.setItemProductName(fittingsInfo.getFittingsName());
- // item.setItemProductPic("");
- // item.setItemProductType(0);
- // item.setItemProductPrice(fittingsInfo.getFittingsPrice());
- // item.setItemIsSource(2);
- // itemList.add(item);
- // }
- }
- boolean flag = salesOrderService.addOrderAndItem(salesOrder,itemList);
- if (flag) {
- return true;
- } else {
- throw new RuntimeException("添加订单项出错!");
- }
- }
- @Override
- public Integer getOrderInfoCount(SalesOrder salesOrder) {
- return salesOrderMapper.getOrderInfoCount(salesOrder);
- }
- @Override
- public List<SalesOrder> listOrderExcel(SalesOrder salesOrder) {
- return salesOrderMapper.listOrderExcel(salesOrder);
- }
- @Override
- public Integer listOrderExcelNum(SalesOrder salesOrder) {
- return salesOrderMapper.listOrderExcelNum(salesOrder);
- }
- @Override
- public Integer delOrder(String orderId) {
- return salesOrderMapper.delOrder(orderId);
- }
- @Override
- @Transactional
- public Integer delSalesOrder(Integer id) {
- //查询出库状态判断是否需要返还库存
- SalesOrder so = salesOrderMapper.getSalesOrderById(id);
- if(so.getSalesDeliver() == 2){
- returnInventory(id,so.getSalesWarehouseId());
- }
- //判断是否绑定维修信息,并解除绑定
- if(so != null){
- //查询封装售后维修编号
- List<ComplaintDetectInfo> listDetect = complaintDetectInfoMapper.listComplaintDetectBySalesId(so.getSalesOrderId());
- if(listDetect != null && listDetect.size() > 0){
- for (ComplaintDetectInfo info: listDetect){
- ComplaintDetectInfo detectInfo = new ComplaintDetectInfo();
- detectInfo.setDetectId(info.getDetectId());
- detectInfo.setDetectPlaceorder(1);
- detectInfo.setSalesOrderId("");
- complaintDetectInfoMapper.updateDetectById(detectInfo);
- }
- }
- }
- // 检查客诉是否使用订单,如果有使用订单,无法删除
- salesOrderMapper.delOrderItem(id);
- salesOrderMapper.delSalesOrder(id);
- return 1;
- }
- @Override
- public Integer updateOrderItem(SalesOrderItem salesOrderItem) {
- return salesOrderMapper.updateOrderItem(salesOrderItem);
- }
- @Override
- public SalesOrder getSalesOrderByLogistics(SalesOrder salesOrder) {
- return salesOrderMapper.getSalesOrderByLogistics(salesOrder);
- }
- @Override
- public Integer updateOrderListIsDownload(List<SalesOrder> list) {
- return salesOrderMapper.updateOrderListIsDownload(list);
- }
- @Override
- public Integer updateSalesOrderByDealCode(SalesOrder salesOrder) {
- return salesOrderMapper.updateSalesOrderByDealCode(salesOrder);
- }
- @Override
- public List<LogisticsInfo> getLogisticsInfo(LogisticsInfo logisticsInfo) {
- return salesOrderMapper.getLogisticsInfo(logisticsInfo);
- }
- @Override
- public List<DownsingleRuleInfo> listDownsingleRule() {
- return salesOrderMapper.listDownsingleRule();
- }
- @Override
- public Integer getIsMachine(String colorBar) {
- return salesOrderMapper.getIsMachine(colorBar);
- }
- @Override
- public Integer getOrderBySalesDealCodeNum(String code) {
- return salesOrderMapper.getOrderBySalesDealCodeNum(code);
- }
- @Override
- public Integer listSalesOrderAndItemNum(SalesOrder salesOrder) {
- return salesOrderMapper.listSalesOrderAndItemNum(salesOrder);
- }
- @Override
- public List<SalesOrder> listSalesOrderAndItem(SalesOrder salesOrder) {
- return salesOrderMapper.listSalesOrderAndItem(salesOrder);
- }
- @Override
- public Integer getSalesOrderNum(SalesOrder salesOrder) {
- return salesOrderMapper.getSalesOrderNum(salesOrder);
- }
- @Transactional
- @Override
- public Integer listConfirmSalesOrderByBatch(String salesBatchId) {
- Integer flag = 0;
- SalesOrder salesOrder = new SalesOrder();
- salesOrder.setSalesBatchId(salesBatchId);
- List<SalesOrder> salesOrderList = salesOrderMapper.listSalesOrder(salesOrder);
- if(salesOrderList == null || salesOrderList.size() < 1){
- throw new RuntimeException("查询订单失败!");
- }
- for (SalesOrder so:salesOrderList){
- flag = salesOrderService.confirmSalesOrder(so.getSalesId());
- }
- return flag;
- }
- @Override
- public Integer noticeDistribution(SalesOrder salesOrder) {
- // 检查订单是否已经有了配送方式,如果没有不允许通知配货 -- 移到controller中自己添加
- // SalesOrder temp = salesOrderMapper.getSalesOrderById(salesOrder.getSalesId());
- // if (temp == null || temp.getSalesPostFirm() == null || temp.getSalesPostFirm().isEmpty()) {
- // return 0;
- // }
- return salesOrderMapper.noticeDistribution(salesOrder);
- }
- @Transactional
- @Override
- public Integer confirmSalesOrder(Integer saleId) {
- /*
- * 查询订单
- * 查询订单项
- * 删除订单
- * 修改查询的订单状态
- * 添加订单
- */
- if(saleId == null ){
- throw new RuntimeException("确认订单失败-订单id异常!");
- }
- SalesOrder salesOrder = salesOrderMapper.getSalesOrderById(saleId);
- if(salesOrder == null){
- throw new RuntimeException("确认订单失败-订单异常!");
- }
- Integer flag = 0;
- SalesOrderItem salesOrderItem = new SalesOrderItem();
- salesOrderItem.setItemOrderId(salesOrder.getSalesId());
- List<SalesOrderItem> salesOrderItemList = salesOrderMapper.listSalesOrderItem(salesOrderItem);
- if(salesOrderItemList == null || salesOrderItemList.size()<1){
- throw new RuntimeException("确认订单失败-查询订单项失败!");
- }
- salesOrder.setSalesOrderItemList(salesOrderItemList);
- flag = salesOrderMapper.delOrderById(salesOrder.getSalesId());
- if(flag < 1){
- throw new RuntimeException("确认订单失败-删除订单失败!");
- }
- flag = salesOrderMapper.delOrderItem(salesOrder.getSalesId());
- if(flag < 1){
- throw new RuntimeException("确认订单失败-删除订单项失败!");
- }
- //1:确认 状态
- salesOrder.setSalesStatus(1);
- boolean fl = salesOrderService.addRstOrderAndIteminfo(salesOrder);
- if(!fl){
- throw new RuntimeException("确认订单失败-添加订单失败!");
- }
- return flag;
- }
- @Override
- public Integer distributionExpress(SalesOrder salesOrder) {
- return salesOrderMapper.distributionExpress(salesOrder);
- }
- @Override
- public Integer listSalesPostFirm(SalesOrder salesOrder) {
- return salesOrderMapper.listSalesPostFirm(salesOrder);
- }
- @Override
- public Integer listSalesPostFirmByIds(SalesOrder salesOrder) {
- return salesOrderMapper.listSalesPostFirmByIds(salesOrder);
- }
- @Override
- public SalesOrder getSalesOrderByPostNum(String postNum) {
- return salesOrderMapper.getSalesOrderByPostNum(postNum);
- }
- @Transactional
- @Override
- public synchronized Integer updateDeliver(SalesOrder salesOrder) {
- Integer flag = salesOrderMapper.updateDeliver(salesOrder);
- if(flag < 1){
- throw new RuntimeException("出库失败,订单出库失败。");
- }
- boolean isMachineRetuen = false; //是否原机退回
- ComplaintDetectInfo complaintDetectInfo = new ComplaintDetectInfo();
- complaintDetectInfo.setSalesOrderId(salesOrder.getSalesOrderId());
- List<ComplaintDetectInfo> complaintDetectInfoList = complaintDetectInfoMapper.listComplaintDetectByOrderId(complaintDetectInfo);
- if(complaintDetectInfoList != null && complaintDetectInfoList.size() > 0) {
- ComplaintDetectInfo cdinfo = complaintDetectInfoList.get(0);
- if (5 == cdinfo.getDetectProcessingResults()) { //detectProcessingResults
- isMachineRetuen = true;
- }
- }
- if(isMachineRetuen){
- //减去售后仓库不良品
- ComplaintDetectInfo cdinfo = complaintDetectInfoList.get(0);
- InventoryInfo inventoryInfo1 = new InventoryInfo();
- inventoryInfo1.setInventoryDefectiveProductNum(1);
- inventoryInfo1.setInventoryProductColorId(cdinfo.getProductColorId());
- inventoryInfo1.setWarehouseId(2);
- inventoryInfo1.setInventoryRecentRecord("维修机器-原机返回(维修ID:" + cdinfo.getDetectNumber() + ")");
- flag = inventoryService.minusInventory(inventoryInfo1);
- if (flag < 1) {
- throw new RuntimeException("出库失败。维修库存调整失败");
- }
- }else{ //正常库存出库(包含正常销售与售后)
- if(salesOrder.getSalesDeliver() == 2){//标记出库,修改库存
- if(!salesOrderService.updateInventory(salesOrder.getSalesId(),salesOrder.getSalesWarehouseId())){
- throw new RuntimeException("出库失败,【出库】库存修改失败。");
- }
- }
- if(salesOrder.getSalesDeliver() == 1){//标记未出库,修改库存
- if(!salesOrderService.returnInventory(salesOrder.getSalesId(),salesOrder.getSalesWarehouseId())){
- throw new RuntimeException("出库失败,【返还库存】库存修改失败。");
- }
- }
- }
- return flag;
- }
- //减少库存
- @Transactional
- @Override
- public boolean updateInventory(Integer salesId,Integer salesWarehouseId){
- OrderWarehouse orderWarehouse = orderWarehouseService.getOrderWarehouseById(salesWarehouseId);
- if(orderWarehouse == null){
- throw new RuntimeException("【出库】更新库存失败,查询仓库信息失败。");
- }
- String warehouseName = orderWarehouse.getWarehouseName();
- SalesOrderItem salesOrderItem = new SalesOrderItem();
- salesOrderItem.setItemOrderId(salesId);
- List<SalesOrderItem> listOrderitem = salesOrderService.listSalesOrderItem(salesOrderItem);
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- for(SalesOrderItem item : listOrderitem){
- InventoryInfo info = inventoryMapper.getByInventoryByBar(item.getItemColorBar(),salesWarehouseId);
- if(info != null){
- if(info.getInventoryGoodProductNum() >= item.getItemNum()){
- info.setInventoryGoodProductNum(info.getInventoryGoodProductNum() - item.getItemNum());
- info.setInventoryRecentRecord(sdf.format(new Date())+"出库"+item.getItemNum()+"件,订单号:"+item.getSalesOrderId());
- Integer flag = inventoryMapper.updateById(info);
- if(flag < 1){
- throw new RuntimeException("【出库】更新库存失败,库存修改失败。");
- }
- //添加日志
- InventoryLog inventoryLog = new InventoryLog();
- inventoryLog.setLogProductName(info.getInventoryProductName());
- inventoryLog.setLogProductBar(info.getInventoryProductBar());
- inventoryLog.setLogRemainingNum(item.getItemNum());
- inventoryLog.setLogType(2);
- inventoryLog.setLogOperationType(2);
- inventoryLog.setLogDesc(sdf.format(new Date())+"待发货标记出库"+item.getItemNum()+"件,订单号:"+item.getSalesOrderId());
- inventoryLog.setLogQualityType(1);
- inventoryLog.setLogWarehouseId(salesWarehouseId);
- flag = inventoryLogMapper.insert(inventoryLog);
- if(flag < 1){
- throw new RuntimeException("【出库】更新库存失败,增加库存记录失败。");
- }
- }else{
- throw new RuntimeException("【出库】更新库存失败,"+ warehouseName +"["+ item.getItemProductName()+ "("+ item.getItemProductColor() +")" +"]库存不足。");
- }
- }else{
- throw new RuntimeException("【出库】更新库存失败,未查询到库存信息,请确认“"+ warehouseName +"”是否有该产品["+ item.getItemProductName()+ "("+ item.getItemProductColor() +")" +"]库存信息。");
- }
- }
- return true;
- }
- //标记未出库时返还库存
- @Transactional
- @Override
- public boolean returnInventory(Integer salesId,Integer salesWarehouseId){
- OrderWarehouse orderWarehouse = orderWarehouseService.getOrderWarehouseById(salesWarehouseId);
- if(orderWarehouse == null){
- throw new RuntimeException("【返还库存】更新库存失败,查询仓库信息失败。");
- }
- String warehouseName = orderWarehouse.getWarehouseName();
- SalesOrderItem salesOrderItem = new SalesOrderItem();
- salesOrderItem.setItemOrderId(salesId);
- List<SalesOrderItem> listOrderitem = salesOrderService.listSalesOrderItem(salesOrderItem);
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- for(SalesOrderItem item : listOrderitem){
- InventoryInfo info = inventoryMapper.getByInventoryByBar(item.getItemColorBar(),salesWarehouseId);
- if(info != null){
- info.setInventoryGoodProductNum(info.getInventoryGoodProductNum() + item.getItemNum());
- info.setInventoryRecentRecord(sdf.format(new Date())+"删除/作废/标记未出库时订单返还库存"+item.getItemNum()+"件,订单号:"+item.getSalesOrderId());
- Integer flag = inventoryMapper.updateById(info);
- if(flag < 1){
- throw new RuntimeException("【返还库存】更新库存失败,库存修改失败。");
- }
- //添加日志
- InventoryLog inventoryLog = new InventoryLog();
- inventoryLog.setLogProductName(info.getInventoryProductName());
- inventoryLog.setLogProductBar(info.getInventoryProductBar());
- inventoryLog.setLogRemainingNum(item.getItemNum());
- inventoryLog.setLogType(1);
- inventoryLog.setLogOperationType(1);
- inventoryLog.setLogDesc(sdf.format(new Date())+"删除/作废/标记未出库时订单返还库存"+item.getItemNum()+"件,订单号:"+item.getSalesOrderId());
- inventoryLog.setLogQualityType(1);
- inventoryLog.setLogWarehouseId(salesWarehouseId);
- flag = inventoryLogMapper.insert(inventoryLog);
- if(flag < 1){
- throw new RuntimeException("【返还库存】更新库存失败,增加库存记录失败。");
- }
- }else{
- throw new RuntimeException("【返还库存】更新库存失败,未查询到库存信息,请确认“"+ warehouseName +"”是否有该产品["+ item.getItemProductName()+ "("+ item.getItemProductColor() +")" +"]库存信息。");
- }
- }
- return true;
- }
- @Override
- public List<SalesOrderItem> getDeliverNum(SalesOrder salesOrder) {
- return salesOrderMapper.getDeliverNum(salesOrder);
- }
- @Override
- public List<Date> getNotSendDate() {
- return salesOrderMapper.getNotSendDate();
- }
- @Override
- public List<SalesOrder> salesOrderListAndItem(SalesOrder salesOrder) {
- return salesOrderMapper.salesOrderListAndItem(salesOrder);
- }
- @Override
- public PagedResult<SalesOrder> salesOrderListAndItemPage(int pageNO, int pageSize, SalesOrder salesOrder, boolean isTotalNum) {
- PageHelper.startPage(pageNO, pageSize, isTotalNum);
- List<SalesOrder> list = salesOrderMapper.salesOrderListAndItem(salesOrder);
- return PageUtil.getPage(list);
- }
- @Override
- public List<SalesOrderItem> selectSalesOrderItemList(Integer salesId) {
- return salesOrderMapper.selectSalesOrderItemList(salesId);
- }
- @Transactional
- @Override
- public Boolean addCorrectInfo(OrderCorrectInfo orderCorrectInfo, String arrayItem, Admin admin) {
- //添加更新信息
- orderCorrectInfo.setAdminId(admin.getAdminId());
- if(salesOrderMapper.addCorrectInfo(orderCorrectInfo) < 1){
- throw new RuntimeException("更正订单-订单异常!");
- }
- //封装订单项数据
- JSONArray jsonArray = JSONArray.fromObject(arrayItem);
- List salesOrderItemList = ((List)JSONArray.toCollection(jsonArray, SalesOrderItem.class));
- for(Object temp : salesOrderItemList){
- SalesOrderItem salesOrderItem = (SalesOrderItem) temp;
- //查询订单项原数量
- SalesOrderItem orderItem = salesOrderMapper.getSalesOrderItem(salesOrderItem.getItemId());
- OrderCorrectItem orderCorrectItem = new OrderCorrectItem();
- orderCorrectItem.setCorrectId(orderCorrectInfo.getCorrectId());
- orderCorrectItem.setOrderItemId(salesOrderItem.getItemId());
- orderCorrectItem.setItemProductColor(salesOrderItem.getItemProductColor());
- orderCorrectItem.setItemProductName(salesOrderItem.getItemProductName());
- orderCorrectItem.setCorrectNum(salesOrderItem.getItemNum());
- orderCorrectItem.setOldNum(orderItem.getItemNum());
- if(orderItem.getItemNum().intValue() != salesOrderItem.getItemNum().intValue()){
- //查询订单判断是否已出库
- SalesOrder so = salesOrderMapper.getSalesOrderById(orderCorrectInfo.getItemOrderId());
- if(so.getSalesDeliver() == 2){
- //返还库存
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- InventoryInfo info = inventoryMapper.getByInventoryByBar(orderItem.getItemColorBar(),so.getSalesWarehouseId());
- //添加日志
- InventoryLog inventoryLog = new InventoryLog();
- inventoryLog.setLogProductName(info.getInventoryProductName());
- inventoryLog.setLogProductBar(info.getInventoryProductBar());
- inventoryLog.setLogOperationType(1);
- inventoryLog.setLogQualityType(1);
- inventoryLog.setLogWarehouseId(1);
- if(orderItem.getItemNum() > salesOrderItem.getItemNum()){//原数量大于更正后数量
- info.setInventoryGoodProductNum(info.getInventoryGoodProductNum() + (orderItem.getItemNum() - salesOrderItem.getItemNum()));
- info.setInventoryRecentRecord(sdf.format(new Date())+"更正订单返还库存:"+(orderItem.getItemNum() - salesOrderItem.getItemNum())+"件");
- inventoryLog.setLogRemainingNum(orderItem.getItemNum() - salesOrderItem.getItemNum());
- inventoryLog.setLogType(2);
- inventoryLog.setLogDesc(sdf.format(new Date())+"更正订单返还库存:"+(orderItem.getItemNum() - salesOrderItem.getItemNum())+"件");
- }else if(orderItem.getItemNum() < salesOrderItem.getItemNum()){
- if(info.getInventoryGoodProductNum() > (salesOrderItem.getItemNum() - orderItem.getItemNum())){
- info.setInventoryGoodProductNum(info.getInventoryGoodProductNum() - (salesOrderItem.getItemNum() - orderItem.getItemNum()));
- info.setInventoryRecentRecord(sdf.format(new Date())+"更正订单减少库存:"+(orderItem.getItemNum() - salesOrderItem.getItemNum())+"件");
- inventoryLog.setLogRemainingNum(salesOrderItem.getItemNum() - orderItem.getItemNum());
- inventoryLog.setLogType(1);
- inventoryLog.setLogDesc(sdf.format(new Date())+"更正订单减少库存:"+(salesOrderItem.getItemNum() - orderItem.getItemNum())+"件");
- }else{
- return false;
- }
- }
- inventoryMapper.updateById(info);
- inventoryLogMapper.insert(inventoryLog);
- }
- //修改订单项数量
- orderItem.setItemNum(salesOrderItem.getItemNum());
- if(salesOrderMapper.updateOrderItemById(orderItem) < 1){
- throw new RuntimeException("更正订单-修改订单项数量失败!");
- }
- if(salesOrderMapper.addCorrectItem(orderCorrectItem) < 1){
- throw new RuntimeException("更正订单-添加记录失败!");
- }
- }
- }
- return true;
- }
- //更正订单时返还库存
- public boolean returnInventoryByItemId(Integer itemId){
- SalesOrderItem salesOrderItem = new SalesOrderItem();
- salesOrderItem.setItemId(itemId);
- List<SalesOrderItem> listOrderitem = salesOrderService.listSalesOrderItem(salesOrderItem);
- SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- for(SalesOrderItem item : listOrderitem){
- SalesOrder so = salesOrderMapper.getSalesOrderById(item.getItemOrderId());
- InventoryInfo info = inventoryMapper.getByInventoryByBar(item.getItemColorBar(),so.getSalesWarehouseId());
- if(info != null){
- info.setInventoryGoodProductNum(info.getInventoryGoodProductNum() + item.getItemNum());
- info.setInventoryRecentRecord(sdf.format(new Date())+"删除/作废订单返还库存:"+item.getItemNum()+"件");
- inventoryMapper.updateById(info);
- //添加日志
- InventoryLog inventoryLog = new InventoryLog();
- inventoryLog.setLogProductName(info.getInventoryProductName());
- inventoryLog.setLogProductBar(info.getInventoryProductBar());
- inventoryLog.setLogRemainingNum(item.getItemNum());
- inventoryLog.setLogType(1);
- inventoryLog.setLogOperationType(1);
- inventoryLog.setLogDesc(sdf.format(new Date())+"删除/作废订单返还库存:"+item.getItemNum()+"件");
- inventoryLog.setLogQualityType(1);
- inventoryLog.setLogWarehouseId(1);
- inventoryLogMapper.insert(inventoryLog);
- }
- }
- return true;
- }
- @Override
- public Integer addCorrectItem(OrderCorrectItem orderCorrectItem) {
- return salesOrderMapper.addCorrectItem(orderCorrectItem);
- }
- @Override
- public OrderCorrectInfo getOrderCorrectInfo(Integer correctId) {
- return salesOrderMapper.getOrderCorrectInfo(correctId);
- }
- @Override
- public List<OrderCorrectItem> listOrderCorrectItem(Integer correctId) {
- return salesOrderMapper.listOrderCorrectItem(correctId);
- }
- @Override
- public SalesOrderItem getSalesOrderItem(Integer itemId) {
- return salesOrderMapper.getSalesOrderItem(itemId);
- }
- @Override
- public Integer updateOrderItemById(SalesOrderItem salesOrderItem) {
- return salesOrderMapper.updateOrderItemById(salesOrderItem);
- }
- @Override
- public List<OrderCorrectInfo> listOrderCorrectInfo(Integer orderId) {
- return salesOrderMapper.listOrderCorrectInfo(orderId);
- }
- @Override
- public OrderWarehouse selectAdminWarehouse(Integer adminId) {
- return salesOrderMapper.selectAdminWarehouse(adminId);
- }
- @Override
- public List<OrderWarehouse> listOrderWarehouse() {
- return salesOrderMapper.listOrderWarehouse();
- }
- @Transactional
- @Override
- public List<SalesOrder> salesOrderAndItemStat(SalesOrder salesOrder) {
- return salesOrderMapper.salesOrderAndItemStat(salesOrder);
- }
- @Transactional
- @Override
- public Integer splitOrder(String mainOrderId, List<SalesOrder> salesOrderList) {
- /**
- * 1.查询以前的所有订单
- * 2.通过比对,余下删除的订单集合orderList
- * 3.给订单项赋值,并且删除该订单的订单项,新增订单项
- * 4.删除orderList
- */
- Integer flag = 0;
- SalesOrder mainOrder = new SalesOrder();
- mainOrder.setSalesDealCode(mainOrderId);
- List<SalesOrder> orderList = salesOrderService.salesOrderListAndItem(mainOrder);
- SalesOrder or = new SalesOrder();
- or.setSalesMainOrderId(orderList.get(0).getSalesId());
- //该订单为主订单
- List<SalesOrder> sonSalesOrderList = salesOrderService.salesOrderListAndItem(or);
- orderList.addAll(sonSalesOrderList);
- for (SalesOrder salesOrder:salesOrderList) {
- //orderList还有的订单,最后做删除
- for (int j=0;j<orderList.size();j++){
- if(salesOrder.getSalesDealCode().equals(orderList.get(j).getSalesDealCode())){
- orderList.remove(j);
- }
- }
- //以前的订单并且已发货之后无法做任何操作
- if(salesOrder.getSalesId() != null && salesOrder.getSalesShippingStatus() > 0){
- continue;
- }
- //订单项赋值
- for (SalesOrderItem itemSaleItem:salesOrder.getSalesOrderItemList()) {
- ProductColor productColor = productMapper.getProductBySku(itemSaleItem.getItemColorBar());
- itemSaleItem.setItemProductId(productColor.getColorProductId());
- itemSaleItem.setItemProductColor(productColor.getColorName());
- itemSaleItem.setColorAbbreviation(productColor.getColorAbbreviation());
- itemSaleItem.setProductAbbreviation(productColor.getColorAbbreviation());
- itemSaleItem.setItemIsSource(1);
- //itemSaleItem.setItemProductDiscount(productColor.getColorDiscount());
- itemSaleItem.setItemProductPrice(itemSaleItem.getItemProductDiscount());
- itemSaleItem.setItemProductPic(productColor.getColorPicture());
- itemSaleItem.setItemProductName(productColor.getProductName());
- itemSaleItem.setItemProductType(productColor.getProductType());
- itemSaleItem.setItemColorId(productColor.getColorId());
- if(salesOrder.getSalesId() != null){
- itemSaleItem.setItemOrderId(salesOrder.getSalesId());
- }
- }
- Integer salesId = salesOrder.getSalesId();
- if(salesId == null){
- //添加订单和订单项
- salesOrderService.addOrderAndIteminfo(salesOrder,salesOrder.getSalesOrderItemList());
- }else{
- //其余全部做修改,删除订单项,添加新的订单项
- flag = salesOrderMapper.delOrderItem(salesOrder.getSalesId());
- if(flag < 1){
- throw new RuntimeException("删除订单项失败,订单交易号:"+salesOrder.getSalesDealCode());
- }
- calculationTotal(null,salesOrder.getSalesOrderItemList());
- flag = salesOrderMapper.addOrderItemList(salesOrder.getSalesOrderItemList());
- if(flag < 1){
- throw new RuntimeException("添加订单项失败,订单交易号:"+salesOrder.getSalesDealCode());
- }
- }
- }
- for (SalesOrder soDelete:orderList) {
- flag = salesOrderService.delSalesOrder(soDelete.getSalesId());
- if(flag < 1){
- throw new RuntimeException("删除订单失败,删除订单交易号:"+soDelete.getSalesDealCode());
- }
- }
- return flag;
- }
- @Override
- public AfterrulesInfo getAfterrulesInfo(Integer storeId) {
- return salesOrderMapper.getAfterrulesInfo(storeId);
- }
- @Override
- public Integer updateOrderItemReturnNum(SalesOrderItem salesOrderItem) {
- return salesOrderMapper.updateOrderItemReturnNum(salesOrderItem);
- }
- @Override
- public List<SmsSignatureInfo> listSmsSignatureInfo(SmsSignatureInfo smsSignatureInfo) {
- return salesOrderMapper.listSmsSignatureInfo(smsSignatureInfo);
- }
- @Override
- public List<SmsTemplateInfo> listSmsTemplateInfo(SmsTemplateInfo smsTemplateInfo) {
- return salesOrderMapper.listSmsTemplateInfo(smsTemplateInfo);
- }
- @Override
- public SalesOrder getStatusNum() {
- return salesOrderMapper.getStatusNum();
- }
- @Override
- public SalesOrder getSalesOrderByOrderId(String salesOrderId) {
- return salesOrderMapper.getSalesOrderByOrderId(salesOrderId);
- }
- @Override
- public Integer updateOrderItemObj(SalesOrderItem salesOrderItem) {
- return salesOrderMapper.updateOrderItemObj(salesOrderItem);
- }
- @Override
- public Integer updateSalesOrderBySalesPostNum(SalesOrder salesOrder) {
- return salesOrderMapper.updateSalesOrderBySalesPostNum(salesOrder);
- }
- /***
- * 计算金额
- * @param salesOrder
- * @param salesOrderItemList
- */
- public void calculationTotal(SalesOrder salesOrder,List<SalesOrderItem> salesOrderItemList){
- Integer salesAmount=0,salesPayMoney=0;
- for (SalesOrderItem soi:salesOrderItemList) {
- if(soi.getItemTotal() == null || soi.getItemTotal() == 0){
- soi.setItemTotal(soi.getItemNum() * soi.getItemProductDiscount());
- }
- salesAmount += (soi.getItemNum() * soi.getItemProductPrice());
- salesPayMoney += soi.getItemTotal();
- }
- if(salesOrder != null && salesPayMoney!=0){
- salesOrder.setSalesAmount(salesAmount);
- salesOrder.setSalesPayMoney(salesPayMoney);
- }
- }
- }
|