GoodsServiceImpl.java 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. package com.kmall.admin.service.impl;
  2. import com.alibaba.druid.support.json.JSONUtils;
  3. import com.google.common.collect.ImmutableBiMap;
  4. import com.google.common.collect.Maps;
  5. import com.kmall.admin.dao.*;
  6. import com.kmall.admin.dto.GoodsDetailsDto;
  7. import com.kmall.admin.dto.GoodsDto;
  8. import com.kmall.admin.dto.GoodsPanoramaDto;
  9. import com.kmall.admin.entity.*;
  10. import com.kmall.admin.entity.mk.MkActivitiesEntity;
  11. import com.kmall.admin.service.*;
  12. import com.kmall.admin.service.mk.MkActivitiesService;
  13. import com.kmall.admin.service.mk.MkActivityFormService;
  14. import com.kmall.admin.service.GoodsService;
  15. import com.kmall.admin.utils.GoodsUtils;
  16. import com.kmall.admin.utils.ShiroUtils;
  17. import com.kmall.api.entity.exportpdf.PDFGoodsDto;
  18. import com.kmall.common.constant.Dict;
  19. import com.kmall.admin.fromcomm.entity.SysUserEntity;
  20. import com.kmall.common.utils.*;
  21. import com.kmall.common.utils.print.ticket.item.Goods;
  22. import org.apache.poi.util.StringUtil;
  23. import org.springframework.beans.factory.annotation.Autowired;
  24. import org.springframework.stereotype.Service;
  25. import org.springframework.transaction.annotation.Transactional;
  26. import java.math.BigDecimal;
  27. import java.math.RoundingMode;
  28. import java.text.SimpleDateFormat;
  29. import java.util.*;
  30. import java.util.stream.Collectors;
  31. /**
  32. * Service实现类
  33. *
  34. * @author Scott
  35. * @email
  36. * @date 2017-08-21 21:19:49
  37. */
  38. @Service("goodsService")
  39. public class GoodsServiceImpl implements GoodsService {
  40. @Autowired
  41. private MerchDao merchDao;
  42. @Autowired
  43. private GoodsDao goodsDao;
  44. @Autowired
  45. private ProductDao productDao;
  46. @Autowired
  47. private GoodsGalleryDao goodsGalleryDao;
  48. @Autowired
  49. private GoodsSpecificationDao goodsSpecificationDao;
  50. @Autowired
  51. private ProductStoreRelaDao productStoreRelaDao;
  52. @Autowired
  53. private StoreDao storeDao;
  54. @Autowired
  55. private GoodsGroupDao goodsGroupDao;
  56. @Autowired
  57. private CategoryDao categoryDao;
  58. @Autowired
  59. private SupplierDao supplierDao;
  60. @Autowired
  61. private SysCusNationCodeDao sysCusNationCodeDao;
  62. @Autowired
  63. private SysCusUnitCodeDao sysCusUnitCodeDao;
  64. @Autowired
  65. private ExportExceptionDataDao exportExceptionDataDao;
  66. @Autowired
  67. private CartDao cartDao;
  68. @Autowired
  69. private ThirdMerchantBizDao thirdMerchantBizDao;
  70. @Autowired
  71. private MngChangeDao mngChangeDao;
  72. @Autowired
  73. private MerchUserDao merchUserDao;
  74. @Autowired
  75. private StoreMngChangeDao storeMngChangeDao;
  76. @Autowired
  77. private GoodsUtils goodsUtils;
  78. @Autowired
  79. private MkActivityFormService mkActivityFormService; // 活动表
  80. @Autowired
  81. private MkActivitiesService mkActivitiesService; // 营销方式表
  82. @Autowired
  83. private MkDailyActivitiesService dailyActivitiesService; // 日常活动
  84. @Autowired
  85. private MkActivitiesCouponService couponService; // 优惠券
  86. @Autowired
  87. private MkActivitiesCombinationPriceService combinationPriceService; // 组合价
  88. @Autowired
  89. private MkActivitiesDiscountService discountService; // 折扣
  90. @Autowired
  91. private MkActivitiesFullGiftService fullGiftService; // 满赠
  92. @Autowired
  93. private MkActivitiesFullReductionService fullReductionService; // 满减
  94. @Autowired
  95. private MkActivitiesGetOneFreeGoodsService getOneFreeGoodsService; // 买一送一
  96. @Autowired
  97. private MkActivitiesPromotionService promotionService; // 临时促销
  98. @Autowired
  99. private BrandService brandService;
  100. @Override
  101. public GoodsEntity queryObject(Integer id) {
  102. Map<String, Object> map = new HashMap<String, Object>();
  103. map.put("goodsId", id);
  104. // List<GoodsAttributeEntity> attributeEntities = goodsAttributeDao.queryList(map);
  105. List<ProductEntity> productEntityList = productDao.queryList(map);
  106. GoodsEntity entity = goodsDao.queryObject(id);
  107. // entity.setAttributeEntityList(attributeEntities);
  108. entity.setProductEntityList(productEntityList);
  109. return entity;
  110. }
  111. @Override
  112. public GoodsEntity queryObjectByProdBarcodeAndBizType(String prodBarcode, Integer storeId){
  113. Map<String, Object> map = new HashMap<String, Object>();
  114. map.put("prodBarcode", prodBarcode);
  115. GoodsEntity entity = goodsDao.queryObjectByProdBarcodeAndBizType(prodBarcode, storeId);
  116. return entity;
  117. }
  118. @Override
  119. public List<GoodsEntity> queryList(Map<String, Object> map) {
  120. return goodsDao.queryList(map);
  121. }
  122. @Override
  123. public List<GoodsEntity> querySame(Map<String, Object> map) {
  124. return goodsDao.querySame(map);
  125. }
  126. @Override
  127. public int queryTotal(Map<String, Object> map) {
  128. return goodsDao.queryTotal(map);
  129. }
  130. @Override
  131. @Transactional
  132. public int save(GoodsEntity goods) {
  133. Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
  134. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  135. builder.put("merchSn", "商户编号");
  136. builder.put("thirdPartyMerchCode", "第三方商户编号");
  137. // builder.put("attributeCategory", "商品分类");
  138. // builder.put("categoryId", "商品二级分类");
  139. builder.put("goodsSn", "商品编码");
  140. builder.put("name", "商品名称");
  141. builder.put("goodsUnit", "商品单位");
  142. builder.put("prodBarcode", "产品条码");
  143. builder.put("goodsBizType", "货品业务类型");
  144. // builder.put("brandId", "品牌");
  145. builder.put("supplierId", "供应商");
  146. // builder.put("freightId", "运费模版");
  147. builder.put("goodsNumber", "商品总库存");
  148. builder.put("primaryPicUrl", "商品主图");
  149. builder.put("listPicUrl", "商品列表图");
  150. builder.put("goodsDesc", "商品描述");
  151. builder.put("isOnSale", "上架");
  152. builder.put("isHot", "热销");
  153. builder.put("englishName", "商品英文名称");
  154. builder.put("plu", "PLU");
  155. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  156. if (Integer.valueOf(r.get("code").toString()) != 0) {
  157. throw new RRException(r.get("msg").toString());
  158. } else {
  159. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  160. // 海关信息,普通货物可不添加
  161. builder.put("sku", "SKU");
  162. builder.put("goodsRate", "商品税率");
  163. // builder.put("retailPrice", "零售价");
  164. builder.put("brand", "产品品牌");
  165. builder.put("unitCode", "计量单位代码");
  166. builder.put("cusGoodsCode", "海关商品编码");
  167. builder.put("ciqProdModel", "国检规格型号");
  168. builder.put("oriCntCode", "原产国代码");
  169. builder.put("cusDeclEle", "海关申报要素");
  170. builder.put("cusRecCode", "海关备案编号");
  171. }
  172. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  173. if (Integer.valueOf(r.get("code").toString()) != 0) {
  174. throw new RRException(r.get("msg").toString());
  175. }
  176. }
  177. /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
  178. if(thirdMerchantBizEntity == null){
  179. throw new RRException("第三方商户信息不存在");
  180. }
  181. if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
  182. if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
  183. builder.put("goodsNumber", "商品库存");
  184. }
  185. }*/
  186. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  187. if (Integer.valueOf(r.get("code").toString()) != 0) {
  188. throw new RRException(r.get("msg").toString());
  189. }
  190. // 商品轮播图
  191. List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
  192. if (galleryEntityList == null || galleryEntityList.size() <= 0) {
  193. throw new RRException("至少添加一张商品轮播图!");
  194. }
  195. List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),null);
  196. if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
  197. throw new RRException("不能有重复的产品条码信息!");
  198. }
  199. SysUserEntity user = ShiroUtils.getUserEntity();
  200. Map<String, Object> map = new HashMap<>();
  201. map.put("isSame", "true");
  202. map.put("sku", goods.getSku());
  203. map.put("goodsSn", goods.getGoodsSn());
  204. map.put("goodsBizType", goods.getGoodsBizType());
  205. List<GoodsEntity> list = querySame(map);
  206. if (list != null && list.size() != 0) {
  207. throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
  208. }
  209. // 添加商品
  210. if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
  211. || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
  212. goods.setIsHot(0);
  213. }
  214. // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
  215. goods.setAddTime(new Date());
  216. goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  217. goods.setIsNew(0);
  218. goods.setCreateUserId(user.getUserId());
  219. goods.setUpdateUserId(user.getUserId());
  220. goods.setUpdateTime(new Date());
  221. goods.setModTime(new Date());
  222. goods.setCreateTime(new Date());
  223. // 新增商品
  224. goodsDao.save(goods);
  225. Long id = goods.getId();
  226. // 添加商品轮播图
  227. for (int i=0;i<galleryEntityList.size();i++) {
  228. GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
  229. galleryEntity.setMerchSn(goods.getMerchSn());
  230. galleryEntity.setGoodsId(id);
  231. galleryEntity.setSortOrder((i+1));
  232. galleryEntity.setFileType("0");//图片
  233. goodsGalleryDao.save(galleryEntity);
  234. }
  235. if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
  236. GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
  237. galleryEntity.setMerchSn(goods.getMerchSn());
  238. galleryEntity.setGoodsId(id);
  239. galleryEntity.setSortOrder(0);
  240. galleryEntity.setFileType("1");//视频
  241. goodsGalleryDao.save(galleryEntity);
  242. }
  243. /*
  244. // 添加商品参数
  245. List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
  246. if (attributeEntityList != null && attributeEntityList.size() > 0) {
  247. for (GoodsAttributeEntity item : attributeEntityList) {
  248. if (item.getIsDelete() == 0) {
  249. if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
  250. item.setGoodsId(id);
  251. item.setMerchSn(goods.getMerchSn());
  252. goodsAttributeDao.save(item);
  253. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
  254. throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
  255. } else if (item.getId() == null && item.getAttributeId() == null) {
  256. continue;
  257. }
  258. }
  259. }
  260. }*/
  261. if (goods.getGoodsNumber() != null){
  262. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  263. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(id)));
  264. mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
  265. mngChangeEntity.setChangeReason("新增商户商品总库存");
  266. mngChangeEntity.setChangeType(Dict.changeType.item_0.getItem());
  267. mngChangeEntity.setChangeNum(goods.getGoodsNumber());//变化数
  268. mngChangeEntity.setOriginalNum(0);//原库存数
  269. mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
  270. mngChangeEntity.setCreateTime(new Date());
  271. mngChangeEntity.setModTime(new Date());
  272. mngChangeEntity.setCreaterSn(user.getUsername());
  273. mngChangeEntity.setModerSn(user.getUsername());
  274. mngChangeEntity.setIsValid(0);
  275. mngChangeEntity.setMerchSn(goods.getMerchSn());
  276. mngChangeDao.save(mngChangeEntity);
  277. }
  278. // 添加产品
  279. ProductEntity product = new ProductEntity();
  280. product.setGoodsId(id);
  281. product.setGoodsSn(goods.getGoodsSn());
  282. // 保税商品,普通货物暂不添加商品规格
  283. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  284. // 添加商品规格
  285. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  286. goodsSpecification.setGoodsId(id);
  287. goodsSpecification.setValue(goods.getCiqProdModel());
  288. goodsSpecification.setSpecificationId(1);
  289. goodsSpecificationDao.save(goodsSpecification);
  290. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  291. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  292. }
  293. return productDao.save(product);
  294. }
  295. @Override
  296. @Transactional
  297. public int update(GoodsEntity goods) {
  298. Map<String, Object> valideDate = MapBeanUtil.fromObject(goods);
  299. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  300. builder.put("merchSn", "商户编号");
  301. builder.put("thirdPartyMerchCode", "第三方商户编号");
  302. // builder.put("attributeCategory", "商品分类");
  303. // builder.put("categoryId", "商品二级分类");
  304. builder.put("goodsSn", "商品编码");
  305. builder.put("name", "商品名称");
  306. builder.put("goodsUnit", "商品单位");
  307. builder.put("prodBarcode", "产品条码");
  308. builder.put("goodsBizType", "货品业务类型");
  309. // builder.put("brandId", "品牌");
  310. builder.put("supplierId", "供应商");
  311. builder.put("goodsNumber", "商品总库存");
  312. // builder.put("freightId", "运费模版");
  313. builder.put("primaryPicUrl", "商品主图");
  314. builder.put("listPicUrl", "商品列表图");
  315. // builder.put("goodsDesc", "商品描述");
  316. builder.put("isOnSale", "上架");
  317. builder.put("isHot", "热销");
  318. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  319. if (Integer.valueOf(r.get("code").toString()) != 0) {
  320. throw new RRException(r.get("msg").toString());
  321. } else {
  322. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  323. // 海关信息,普通货物可不添加
  324. builder.put("sku", "SKU");
  325. builder.put("goodsRate", "商品税率");
  326. // builder.put("retailPrice", "零售价");
  327. builder.put("brand", "产品品牌");
  328. builder.put("unitCode", "计量单位代码");
  329. builder.put("cusGoodsCode", "海关商品编码");
  330. builder.put("ciqProdModel", "国检规格型号");
  331. builder.put("oriCntCode", "原产国代码");
  332. builder.put("cusRecCode", "海关备案编号");
  333. builder.put("cusDeclEle", "海关申报要素");
  334. }
  335. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  336. if (Integer.valueOf(r.get("code").toString()) != 0) {
  337. throw new RRException(r.get("msg").toString());
  338. }
  339. }
  340. /*ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goods.getThirdPartyMerchCode());
  341. if(thirdMerchantBizEntity == null){
  342. throw new RRException("所属第三方商户不存在");
  343. }*/
  344. GoodsEntity goodsEntity = goodsDao.queryObject(goods.getId());
  345. if(goodsEntity != null){
  346. /*if(Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goods.getGoodsBizType())){
  347. if(Dict.isStockShare.item_1.getItem().equalsIgnoreCase(thirdMerchantBizEntity.getIsStockShare())){
  348. builder.put("goodsNumber", "商品库存");
  349. }
  350. }
  351. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  352. if (Integer.valueOf(r.get("code").toString()) != 0) {
  353. throw new RRException(r.get("msg").toString());
  354. }*/
  355. }else{
  356. throw new RRException("商品不存在");
  357. }
  358. // 商品轮播图
  359. List<GoodsGalleryEntity> galleryEntityList = goods.getGoodsImgList();
  360. if (galleryEntityList == null || galleryEntityList.size() <= 0) {
  361. // throw new RRException("至少保留一张商品轮播图!");
  362. }
  363. List<GoodsEntity> prodbarGoodsList = goodsDao.queryObjectByProdBarcode(goods.getProdBarcode(),goods.getMerchSn(),goods.getId());
  364. if(prodbarGoodsList != null && prodbarGoodsList.size() > 0){
  365. throw new RRException("不能有重复的产品条码信息!");
  366. }
  367. SysUserEntity user = ShiroUtils.getUserEntity();
  368. Map<String, Object> map = new HashMap<>();
  369. map.put("isSame", "true");
  370. map.put("sku", goods.getSku());
  371. map.put("goodsSn", goods.getGoodsSn());
  372. map.put("goodsBizType", goods.getGoodsBizType());
  373. map.put("id", goods.getId());
  374. List<GoodsEntity> list = querySame(map);
  375. if (list != null && list.size() != 0) {
  376. throw new RRException("已存在该商品编码,或该货品业务类型下已存在此SKU!");
  377. }
  378. // 修改商品
  379. if (Dict.orderBizType.item_02.getItem().equals(goods.getGoodsBizType())
  380. || Dict.orderBizType.item_10.getItem().equals(goods.getGoodsBizType())) {
  381. goods.setIsHot(0);
  382. }
  383. // goods.setAttributeCategory(categoryDao.queryObject(goods.getCategoryId()).getParentId());
  384. goods.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  385. goods.setIsNew(0);
  386. goods.setUpdateUserId(user.getUserId());
  387. goods.setUpdateTime(new Date());
  388. goods.setModTime(new Date());
  389. if(goods.getGoodsNumber()==null){
  390. goods.setGoodsNumber(0);
  391. }else{
  392. if(goodsEntity.getGoodsNumber() == null){
  393. goodsEntity.setGoodsNumber(0);
  394. }
  395. MngChangeEntity mngChangeEntity = new MngChangeEntity();
  396. mngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(goods.getId())));
  397. mngChangeEntity.setThirdPartyMerchCode(goods.getThirdPartyMerchCode());
  398. mngChangeEntity.setChangeReason("更新商户商品总库存");
  399. mngChangeEntity.setCreateTime(new Date());
  400. mngChangeEntity.setModTime(new Date());
  401. mngChangeEntity.setCreaterSn(user.getUsername());
  402. mngChangeEntity.setModerSn(user.getUsername());
  403. mngChangeEntity.setIsValid(0);
  404. mngChangeEntity.setMerchSn(goods.getMerchSn());
  405. if(goodsEntity.getGoodsNumber() != goods.getGoodsNumber()) {
  406. if (goodsEntity.getGoodsNumber() > goods.getGoodsNumber()) {
  407. mngChangeEntity.setChangeNum(goodsEntity.getGoodsNumber() - goods.getGoodsNumber());//变化数
  408. mngChangeEntity.setChangeType(Dict.changeType.item_4.getItem());
  409. } else {
  410. mngChangeEntity.setChangeNum(goods.getGoodsNumber() - goodsEntity.getGoodsNumber());//变化数
  411. mngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  412. }
  413. mngChangeEntity.setOriginalNum(goodsEntity.getGoodsNumber());//原库存数
  414. mngChangeEntity.setValidNum(goods.getGoodsNumber());//可用数
  415. mngChangeDao.save(mngChangeEntity);
  416. }
  417. }
  418. // 修改商品
  419. goodsDao.update(goods);
  420. // 保税商品修改各个门店商品价格
  421. List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsEntity.getId());
  422. Long[] storeIds = new Long[productStoreRelaEntityList.size()];
  423. Integer goodsNumber = goods.getGoodsNumber();//商品总库存
  424. Integer storeTotalGoodsNumber = 0;//商品分配库存
  425. if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
  426. for (int i = 0; i < productStoreRelaEntityList.size(); i++) {
  427. //修改该商品的所属商户信息,如在该商户门店中有该上架的商品信息,则提示该商品不能修改
  428. ProductStoreRelaEntity relaEntity = productStoreRelaEntityList.get(i);
  429. if(org.apache.commons.lang3.StringUtils.isNotEmpty(relaEntity.getMerchSn()) && relaEntity.getMerchSn().equalsIgnoreCase(goods.getMerchSn())
  430. && goods.getIsOnSale() == Integer.parseInt(Dict.isOnSale.item_1.getItem())) {
  431. }else {
  432. if (goods.getIsOnSale() != Integer.parseInt(Dict.isOnSale.item_0.getItem())) {
  433. throw new RRException("商品编码为【" + goods.getGoodsSn() + "】的商品已上架在商户编号为【" + relaEntity.getMerchSn() + "】的门店中,可先将该商品下架后再进行修改!");
  434. }
  435. }
  436. storeTotalGoodsNumber = storeTotalGoodsNumber + relaEntity.getStockNum();
  437. storeIds[i] = relaEntity.getStoreId();
  438. }
  439. }
  440. if(goodsEntity.getIsStockShare().equalsIgnoreCase(Dict.isStockShare.item_0.getItem())) {
  441. if (goodsNumber < storeTotalGoodsNumber) {
  442. throw new RRException("该商品已在各门店分配库存" + storeTotalGoodsNumber + ",当前商品总库存不能小于分配库存总额!请先修改门店库存!");
  443. }
  444. }else{
  445. //共享库存商品库存变化,修改该商品的所有库存信息
  446. ProductStoreRelaEntity productStoreRelaEntity = new ProductStoreRelaEntity();
  447. productStoreRelaEntity.setStockNum(goodsNumber);
  448. productStoreRelaEntity.setGoodsId(goods.getId());
  449. productStoreRelaDao.updateStockNumByGoodsId(productStoreRelaEntity);
  450. for (int i = 0; i < productStoreRelaEntityList.size(); i++) {
  451. ProductStoreRelaEntity relaEntity = productStoreRelaEntityList.get(i);
  452. //新增库存操作记录
  453. StoreMngChangeEntity storeMngChangeEntity = new StoreMngChangeEntity();
  454. storeMngChangeEntity.setChangeReason("共享库存变更,更新门店商品库存");
  455. storeMngChangeEntity.setGoodsId(Integer.parseInt(String.valueOf(relaEntity.getGoodsId())));
  456. storeMngChangeEntity.setStoreId(Integer.parseInt(String.valueOf(relaEntity.getStoreId())));
  457. storeMngChangeEntity.setMerchSn(goods.getMerchSn());
  458. storeMngChangeEntity.setCreateTime(new Date());
  459. storeMngChangeEntity.setModTime(new Date());
  460. storeMngChangeEntity.setCreaterSn(user.getUsername());
  461. storeMngChangeEntity.setModerSn(user.getUsername());
  462. storeMngChangeEntity.setIsValid(0);
  463. Integer orginalNum = relaEntity.getStockNum()==null?0:relaEntity.getStockNum();//原有库存
  464. if(goodsNumber != orginalNum) {
  465. if (orginalNum > goodsNumber) {
  466. storeMngChangeEntity.setChangeType(Dict.changeType.item_4.getItem());
  467. storeMngChangeEntity.setStoreChangeNum(orginalNum - goodsNumber);//变化数
  468. } else {
  469. storeMngChangeEntity.setChangeType(Dict.changeType.item_3.getItem());
  470. storeMngChangeEntity.setStoreChangeNum(goodsNumber - orginalNum);//变化数
  471. }
  472. storeMngChangeEntity.setStoreOriginalNum(orginalNum);//原库存数
  473. storeMngChangeEntity.setStoreValidNum(goodsNumber);//可用数
  474. storeMngChangeDao.save(storeMngChangeEntity);
  475. }
  476. }
  477. }
  478. Map cartMap = Maps.newHashMap();
  479. cartMap.put("goodsId",goods.getId());
  480. List<CartEntity> cartList = cartDao.queryList(cartMap);
  481. if (cartList != null && cartList.size() > 0) {
  482. for (CartEntity cartEntity : cartList) {
  483. // cartEntity.setRetailPrice(goods.getRetailPrice());
  484. // cartEntity.setMarketPrice(goods.getMarketPrice());
  485. cartEntity.setSku(goods.getSku());
  486. cartEntity.setGoodsName(goods.getName());
  487. cartEntity.setGoodsSn(goods.getGoodsSn());
  488. cartDao.update(cartEntity);
  489. }
  490. }
  491. // 修改商品轮播图
  492. goodsGalleryDao.deleteByGoodsId(goods.getId());
  493. for (int i=0;i<galleryEntityList.size();i++) {
  494. GoodsGalleryEntity galleryEntity =galleryEntityList.get(i);
  495. galleryEntity.setMerchSn(goods.getMerchSn());
  496. galleryEntity.setGoodsId(goods.getId());
  497. galleryEntity.setSortOrder((i+1));
  498. galleryEntity.setFileType("0");//图片
  499. goodsGalleryDao.save(galleryEntity);
  500. }
  501. if(org.apache.commons.lang.StringUtils.isNotEmpty(goods.getVideoUrl())){
  502. GoodsGalleryEntity galleryEntity = new GoodsGalleryEntity();
  503. galleryEntity.setMerchSn(goods.getMerchSn());
  504. galleryEntity.setGoodsId(goods.getId());
  505. galleryEntity.setSortOrder(0);
  506. galleryEntity.setFileType("1");//视频
  507. galleryEntity.setImgUrl(goods.getVideoUrl());
  508. goodsGalleryDao.save(galleryEntity);
  509. }
  510. /*// 修改商品参数
  511. List<GoodsAttributeEntity> attributeEntityList = goods.getAttributeEntityList();
  512. if (attributeEntityList != null && attributeEntityList.size() > 0) {
  513. for (GoodsAttributeEntity item : attributeEntityList) {
  514. if (item.getIsDelete() == 0) {
  515. if (item.getId() != null) {
  516. item.setMerchSn(goods.getMerchSn());
  517. goodsAttributeDao.update(item);
  518. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNotEmpty(item.getValue())) {
  519. item.setGoodsId(goods.getId());
  520. item.setMerchSn(goods.getMerchSn());
  521. goodsAttributeDao.save(item);
  522. } else if (item.getId() == null && item.getAttributeId() != null && StringUtils.isNullOrEmpty(item.getValue())) {
  523. throw new RRException("商品属性【" + attributeDao.queryObject(item.getAttributeId()).getName() + "】值不能为空!");
  524. } else if (item.getId() == null && item.getAttributeId() == null) {
  525. continue;
  526. }
  527. } else if (item.getIsDelete() == 1) {
  528. goodsAttributeDao.delete(item.getId());
  529. }
  530. }
  531. }*/
  532. // 修改产品
  533. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goods.getId()),"");
  534. GoodsSpecificationEntity goodsSpecification = null;
  535. // 保税商品,普通货物暂不添加商品规格
  536. if (!Dict.orderBizType.item_11.getItem().equals(goods.getGoodsBizType())) {
  537. // 添加商品规格
  538. goodsSpecification = goodsSpecificationDao.queryByGoodsId(goods.getId());
  539. if(goodsSpecification != null) {
  540. goodsSpecification.setValue(goods.getCiqProdModel());
  541. goodsSpecificationDao.update(goodsSpecification);
  542. }else{
  543. goodsSpecification = new GoodsSpecificationEntity();
  544. goodsSpecification.setGoodsId(goods.getId());
  545. goodsSpecification.setValue(goods.getCiqProdModel());
  546. goodsSpecification.setSpecificationId(1);
  547. goodsSpecificationDao.save(goodsSpecification);
  548. }
  549. //更新门店商品是否有修改字段
  550. if(storeIds.length > 0){
  551. for(int i=0;i<storeIds.length;i++){
  552. updateLoadGoodsByStoreId(storeIds[i], user);
  553. }
  554. }
  555. if(product == null){
  556. product = new ProductEntity();
  557. product.setGoodsSn(goods.getGoodsSn());
  558. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  559. product.setGoodsSpecificationIds(goodsSpecification.getId()+"");
  560. product.setGoodsId(goods.getId());
  561. product.setGoodsNumber(goods.getGoodsNumber());
  562. product.setGoodsDefault(0);
  563. return productDao.save(product);
  564. }else{
  565. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  566. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  567. return productDao.update(product);
  568. }
  569. }
  570. return 1;
  571. }
  572. @Transactional
  573. public void updateForImgUrl(GoodsEntity goodsEntity){
  574. // 修改商品
  575. goodsDao.update(goodsEntity);
  576. }
  577. /**
  578. * 更新门店商品是否有修改字段
  579. * @param storeId
  580. * @param user
  581. */
  582. private void updateLoadGoodsByStoreId(Long storeId, SysUserEntity user){
  583. List<MerchUserEntity> list = merchUserDao.queryMerchUserByLoadGoods(storeId);
  584. for(MerchUserEntity entity : list) {
  585. entity.setIsLoadGoods("1");
  586. entity.setModerSn(user.getUsername());
  587. entity.setStoreId(Integer.valueOf(String.valueOf(storeId)));
  588. merchUserDao.updateStoreLoadGoodsById(entity);
  589. }
  590. }
  591. @Override
  592. public int delete(Integer id) {
  593. SysUserEntity user = ShiroUtils.getUserEntity();
  594. GoodsEntity goodsEntity = goodsDao.queryObject(id);
  595. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_1.getItem()));
  596. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  597. goodsEntity.setUpdateUserId(user.getUserId());
  598. goodsEntity.setUpdateTime(new Date());
  599. Map params = Maps.newHashMap();
  600. params.put("goodsId", id);
  601. List<GoodsGroupEntity> groupVos = goodsGroupDao.queryList(params);
  602. if (null != groupVos && groupVos.size() > 0) {
  603. for (GoodsGroupEntity groupVo : groupVos) {
  604. groupVo.setOpenStatus(3);
  605. goodsGroupDao.update(groupVo);
  606. }
  607. }
  608. return goodsDao.update(goodsEntity);
  609. }
  610. @Override
  611. @Transactional
  612. public int deleteBatch(Integer[] ids) {
  613. int result = 0;
  614. for (Integer id : ids) {
  615. result += delete(id);
  616. }
  617. return result;
  618. }
  619. @Override
  620. @Transactional
  621. public int back(Integer[] ids) {
  622. SysUserEntity user = ShiroUtils.getUserEntity();
  623. int result = 0;
  624. for (Integer id : ids) {
  625. GoodsEntity goodsEntity = queryObject(id);
  626. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  627. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  628. goodsEntity.setUpdateUserId(user.getUserId());
  629. goodsEntity.setUpdateTime(new Date());
  630. result += goodsDao.update(goodsEntity);
  631. }
  632. return result;
  633. }
  634. @Override
  635. public int enSale(Integer id) {
  636. SysUserEntity user = ShiroUtils.getUserEntity();
  637. GoodsEntity goodsEntity = queryObject(id);
  638. if (1 == goodsEntity.getIsOnSale()) {
  639. throw new RRException("此商品已处于上架状态!");
  640. }
  641. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  642. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  643. goodsEntity.setUpdateUserId(user.getUserId());
  644. goodsEntity.setUpdateTime(new Date());
  645. return goodsDao.update(goodsEntity);
  646. }
  647. @Override
  648. public int unSale(Integer id) {
  649. SysUserEntity user = ShiroUtils.getUserEntity();
  650. GoodsEntity goodsEntity = queryObject(id);
  651. if (0 == goodsEntity.getIsOnSale()) {
  652. throw new RRException("此商品已处于下架状态!");
  653. }
  654. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  655. goodsEntity.setUpdateUserId(user.getUserId());
  656. goodsEntity.setUpdateTime(new Date());
  657. return goodsDao.update(goodsEntity);
  658. }
  659. @Override
  660. public int enSaleBatch(Integer[] ids) {
  661. int result = 0;
  662. SysUserEntity user = ShiroUtils.getUserEntity();
  663. for (Integer id : ids) {
  664. GoodsEntity goodsEntity = queryObject(id);
  665. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_1.getItem()));
  666. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  667. goodsEntity.setUpdateUserId(user.getUserId());
  668. goodsEntity.setUpdateTime(new Date());
  669. result += goodsDao.update(goodsEntity);
  670. }
  671. return result;
  672. }
  673. @Override
  674. public int unSaleBatch(Integer[] ids) {
  675. int result = 0;
  676. SysUserEntity user = ShiroUtils.getUserEntity();
  677. for (Integer id : ids) {
  678. GoodsEntity goodsEntity = queryObject(id);
  679. goodsEntity.setIsOnSale(Integer.parseInt(Dict.isOnSale.item_0.getItem()));
  680. goodsEntity.setUpdateUserId(user.getUserId());
  681. goodsEntity.setUpdateTime(new Date());
  682. result += goodsDao.update(goodsEntity);
  683. }
  684. return result;
  685. }
  686. @Override
  687. @Transactional
  688. public int uploadExcel(List<GoodsDto> goodsEntityList,int exportDataType) {
  689. SysUserEntity user = ShiroUtils.getUserEntity();
  690. String merchSn = user.getMerchSn();
  691. boolean isFail = false;
  692. List<String> failSameSkuList = new ArrayList<>(), failHotGoodsSnList = new ArrayList<>(),
  693. failSuppGoodsSnList = new ArrayList<>(),
  694. failUnitGoodsSnList = new ArrayList<>(), failNationGoodsSnList = new ArrayList<>(),failProdbarGoodsSnList = new ArrayList<>(),
  695. failTypeGoodsSnList = new ArrayList<>(), failMerchGoodsSnList = new ArrayList<>(),
  696. // failCateL2GoodsSnList = new ArrayList<>(),
  697. // failCateGoodsSnList = new ArrayList<>(),
  698. // failBrandGoodsSnList = new ArrayList<>(),
  699. // failFreightGoodsSnList = new ArrayList<>(),
  700. failMerchUserGoodsSnList = new ArrayList<>();
  701. List<String> failGoodsSnList = new ArrayList<>();
  702. List<String> failGoodsTypeList = new ArrayList<>();
  703. // List<String> failFreightList = new ArrayList<>();
  704. if (goodsEntityList != null && goodsEntityList.size() > 0) {
  705. for (int i = 0; i < goodsEntityList.size(); i++) {
  706. GoodsDto goodsDto = goodsEntityList.get(i);
  707. GoodsEntity goodsEntity = new GoodsEntity();
  708. Map<String, Object> valideDate = MapBeanUtil.fromObject(goodsDto);
  709. ImmutableBiMap.Builder builder = new ImmutableBiMap.Builder();
  710. builder.put("goodsSn", "商品编码");
  711. builder.put("thirdPartyMerchCode", "第三方商户代码");
  712. // builder.put("categoryName", "商品分类");
  713. builder.put("goodsBizType", "货品业务类型");
  714. builder.put("name", "商品名称");
  715. // builder.put("brandName", "商品品牌名称");
  716. // builder.put("defaultFreight", "运费");
  717. builder.put("isOnSaleStr", "上架");
  718. builder.put("goodsUnit", "商品单位");
  719. builder.put("isHotStr", "热销");
  720. builder.put("prodBarcode", "产品条码");
  721. // builder.put("marketPrice", "市场价");
  722. // builder.put("retailPrice", "零售价");
  723. builder.put("supplierName", "供应商");
  724. builder.put("goodsNumber", "商品总库存");
  725. R r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  726. if (Integer.valueOf(r.get("code").toString()) != 0) {
  727. throw new RRException(r.get("msg").toString());
  728. } else {
  729. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  730. // 海关信息,普通货物可不添加
  731. builder.put("goodsRate", "商品税率");
  732. builder.put("sku", "SKU");
  733. builder.put("brand", "产品品牌");
  734. builder.put("unitName", "计量单位");
  735. builder.put("oriCntName", "原产国");
  736. builder.put("cusGoodsCode", "海关商品编码");
  737. builder.put("ciqProdModel", "国检规格型号");
  738. builder.put("cusDeclEle", "海关申报要素");
  739. builder.put("cusRecCode", "海关备案编号");
  740. }
  741. r = ValidatorUtil.isEmpty(builder.build(), valideDate);
  742. if (Integer.valueOf(r.get("code").toString()) != 0) {
  743. throw new RRException(r.get("msg").toString());
  744. }
  745. }
  746. //业务类型校验
  747. if(!Dict.orderBizType.item_11.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())){
  748. if(!(Dict.orderBizType.item_02.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  749. || Dict.orderBizType.item_10.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType())
  750. || Dict.orderBizType.item_00.getItem().equalsIgnoreCase(goodsDto.getGoodsBizType()))){
  751. isFail = true;
  752. failTypeGoodsSnList.add(goodsDto.getSku());
  753. }
  754. }
  755. ThirdMerchantBizEntity thirdMerchantBizEntity = thirdMerchantBizDao.getThirdMerchangByCode(goodsDto.getThirdPartyMerchCode());
  756. if(thirdMerchantBizEntity != null){
  757. goodsEntity.setMerchSn(thirdMerchantBizEntity.getMerchSn());
  758. goodsEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  759. if(!user.getRoleType().equalsIgnoreCase(Dict.roleType.item_1.getItem())) {
  760. if (!merchSn.equalsIgnoreCase(thirdMerchantBizEntity.getMerchSn())) {
  761. isFail = true;
  762. failMerchUserGoodsSnList.add(goodsDto.getGoodsSn());
  763. }
  764. }
  765. }else{//商户不存在
  766. isFail = true;
  767. failMerchGoodsSnList.add(goodsDto.getGoodsSn());
  768. }
  769. //校验商品信息是否已存在
  770. Map<String, Object> map = new HashMap<>();
  771. map.put("isSame", "true");
  772. map.put("sku", goodsDto.getSku());
  773. map.put("goodsSn", goodsDto.getGoodsSn());
  774. map.put("goodsBizType", goodsDto.getGoodsBizType());
  775. List<GoodsEntity> list = querySame(map);
  776. if (list != null && list.size() != 0) {
  777. isFail = true;
  778. if(goodsDto.getSku()!=null) {
  779. failSameSkuList.add(goodsDto.getSku());
  780. }
  781. failGoodsSnList.add(goodsDto.getGoodsSn());
  782. failGoodsTypeList.add(goodsDto.getGoodsBizType());
  783. }
  784. //校验产品条码是否存在
  785. List<GoodsEntity> prodbarGoods = goodsDao.queryObjectByProdBarcode(goodsDto.getProdBarcode(),merchSn,null);
  786. if(prodbarGoods != null && prodbarGoods.size() > 0){
  787. isFail = true;
  788. failProdbarGoodsSnList.add(goodsDto.getGoodsSn());
  789. }else{
  790. goodsEntity.setProdBarcode(goodsDto.getProdBarcode());
  791. }
  792. //热销商品校验
  793. if (Dict.orderBizType.item_02.getItem().equals(goodsDto.getGoodsBizType())
  794. || Dict.orderBizType.item_10.getItem().equals(goodsDto.getGoodsBizType())) {
  795. if(goodsDto.getIsHotStr().equalsIgnoreCase("1")){
  796. isFail = true;
  797. failHotGoodsSnList.add(goodsDto.getGoodsSn());
  798. }
  799. }
  800. if(thirdMerchantBizEntity != null) {
  801. SupplierEntity supplierEntity = supplierDao.queryObjectByName(goodsDto.getSupplierName(), thirdMerchantBizEntity.getMerchSn(),thirdMerchantBizEntity.getThirdPartyMerchCode());
  802. if (supplierEntity == null) {
  803. //导入没有查到供货商,执行新增
  804. MerchEntity merchEntity = merchDao.findByMerchSn(thirdMerchantBizEntity.getMerchSn());
  805. if(null == merchEntity || !StringUtils.isNotEmpty(goodsDto.getSupplierFlag())){
  806. isFail = true;
  807. failSuppGoodsSnList.add(goodsDto.getGoodsSn());
  808. }
  809. supplierEntity = new SupplierEntity();
  810. supplierEntity.setLevelMerchSn(merchEntity.getMerchSn());
  811. supplierEntity.setLevelMerchFlag(merchEntity.getMerchShortName());
  812. supplierEntity.setThirdPartyMerchCode(thirdMerchantBizEntity.getThirdPartyMerchCode());
  813. supplierEntity.setChildSupplierName(goodsDto.getSupplierName());
  814. supplierEntity.setChildSupplierFlag(goodsDto.getSupplierFlag());
  815. supplierEntity.setIsShow("0");
  816. supplierDao.save(supplierEntity);
  817. goodsEntity.setSupplierId(supplierEntity.getId());
  818. } else {
  819. goodsEntity.setSupplierId(supplierEntity.getId());
  820. }
  821. }
  822. //商品配置校验
  823. /*CategoryEntity categoryEntity = categoryDao.queryObjectByName(goodsDto.getCategoryName(),goodsDto.getMerchSn());
  824. if(categoryEntity==null){
  825. isFail = true;
  826. failCateGoodsSnList.add(goodsDto.getGoodsSn());
  827. }else{
  828. if(categoryEntity.getLevel().equalsIgnoreCase("L2")) {
  829. goodsEntity.setCategoryId(categoryEntity.getId());
  830. goodsEntity.setAttributeCategory(categoryEntity.getParentId());
  831. }else{
  832. isFail = true;
  833. failCateL2GoodsSnList.add(goodsDto.getGoodsSn());
  834. }
  835. }
  836. BrandEntity brandEntity = brandDao.queryObjectByName(goodsDto.getBrandName(),goodsDto.getMerchSn());
  837. if (brandEntity == null) {
  838. isFail = true;
  839. failBrandGoodsSnList.add(goodsDto.getGoodsSn());
  840. } else {
  841. goodsEntity.setBrandId(brandEntity.getId());
  842. }
  843. //运费
  844. FreightEntity freightEntity = freightDao.queryObjectByName(goodsDto.getDefaultFreight(),goodsDto.getMerchSn());
  845. if(freightEntity==null){
  846. isFail = true;
  847. failFreightGoodsSnList.add(goodsDto.getGoodsSn());
  848. failFreightList.add(goodsDto.getDefaultFreight());
  849. }else {
  850. goodsEntity.setFreightId(freightEntity.getId());
  851. }*/
  852. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  853. SysCusUnitCodeEntity sysCusUnitCodeEntity = sysCusUnitCodeDao.queryObjectByName(goodsDto.getUnitName());
  854. if (sysCusUnitCodeEntity == null) {
  855. isFail = true;
  856. failUnitGoodsSnList.add(goodsDto.getGoodsSn());
  857. } else {
  858. goodsEntity.setUnitCode(sysCusUnitCodeEntity.getCode());
  859. }
  860. //原产国
  861. SysCusNationCodeEntity sysCusNationCodeEntity = sysCusNationCodeDao.queryObjectByName(goodsDto.getOriCntName());
  862. if (sysCusNationCodeEntity == null) {
  863. isFail = true;
  864. failNationGoodsSnList.add(goodsDto.getGoodsSn());
  865. } else {
  866. goodsEntity.setOriCntCode(sysCusNationCodeEntity.getCode());
  867. }
  868. if(goodsDto.getGoodsRate().indexOf("%") != -1){
  869. goodsDto.setGoodsRate(goodsDto.getGoodsRate().substring(0, goodsDto.getGoodsRate().indexOf("%")));
  870. }
  871. goodsEntity.setGoodsRate(BigDecimal.valueOf(Double.valueOf(goodsDto.getGoodsRate())).divide(new BigDecimal(100), 4, BigDecimal.ROUND_HALF_UP));
  872. }
  873. goodsEntity.setIsOnSale(Integer.parseInt(goodsDto.getIsOnSaleStr()));
  874. goodsEntity.setIsHot(Integer.parseInt(goodsDto.getIsHotStr()));
  875. // goodsEntity.setRetailPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getRetailPrice())));
  876. // goodsEntity.setMarketPrice(BigDecimal.valueOf(Integer.valueOf(goodsDto.getMarketPrice())));
  877. goodsEntity.setGoodsSn(goodsDto.getGoodsSn());
  878. goodsEntity.setSku(goodsDto.getSku());
  879. goodsEntity.setName(goodsDto.getName());
  880. goodsEntity.setGoodsUnit(goodsDto.getGoodsUnit());
  881. goodsEntity.setGoodsBizType(goodsDto.getGoodsBizType());
  882. goodsEntity.setBrand(goodsDto.getBrand());
  883. goodsEntity.setCusDeclEle(goodsDto.getCusDeclEle());
  884. goodsEntity.setCusGoodsCode(goodsDto.getCusGoodsCode());
  885. goodsEntity.setCusRecCode(goodsDto.getCusRecCode());
  886. goodsEntity.setCiqProdModel(goodsDto.getCiqProdModel());
  887. goodsEntity.setIsDelete(Integer.parseInt(Dict.isDelete.item_0.getItem()));
  888. goodsEntity.setIsNew(0);
  889. goodsEntity.setUpdateUserId(user.getUserId());
  890. goodsEntity.setAddTime(new Date());
  891. goodsEntity.setCreateTime(new Date());
  892. goodsEntity.setUpdateTime(new Date());
  893. goodsEntity.setModTime(new Date());
  894. goodsEntity.setGoodsNumber(Integer.parseInt(goodsDto.getGoodsNumber()));
  895. if(!isFail){
  896. GoodsEntity goods = goodsDao.queryObjectBySn(goodsDto.getGoodsSn());
  897. if(goods!=null) {// 修改商品
  898. goodsEntity.setId(goods.getId());
  899. goodsDao.update(goodsEntity);
  900. }else{
  901. goodsDao.save(goodsEntity);
  902. }
  903. // // 保税商品修改各个门店商品价格
  904. // if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  905. // List<ProductStoreRelaEntity> productStoreRelaEntityList = productStoreRelaDao.queryByGoodsId(goodsDto.getId());
  906. // if (productStoreRelaEntityList != null && productStoreRelaEntityList.size() > 0) {
  907. // for (ProductStoreRelaEntity productStoreRela : productStoreRelaEntityList) {
  908. // productStoreRela.setMarketPrice(goodsEntity.getMarketPrice());
  909. // productStoreRela.setRetailPrice(goodsEntity.getRetailPrice());
  910. // productStoreRelaDao.update(productStoreRela);
  911. // }
  912. // }
  913. // }
  914. // 修改产品
  915. ProductEntity product = productDao.queryObjectByGoodsIdAndStoreId(String.valueOf(goodsEntity.getId()), "");
  916. GoodsSpecificationEntity goodsSpecification = new GoodsSpecificationEntity();
  917. // 普通货物暂不添加商品规格
  918. if (!Dict.orderBizType.item_11.getItem().equals(goodsDto.getGoodsBizType())) {
  919. // 添加商品规格
  920. GoodsSpecificationEntity specificationEntity = goodsSpecificationDao.queryByGoodsId(goodsEntity.getId());
  921. if(specificationEntity == null) {
  922. goodsSpecification.setGoodsId(goodsEntity.getId());
  923. goodsSpecification.setValue(goodsEntity.getCiqProdModel());
  924. goodsSpecification.setSpecificationId(1);
  925. goodsSpecificationDao.save(goodsSpecification);
  926. }else {
  927. goodsSpecification.setValue(goodsDto.getCiqProdModel());
  928. goodsSpecification.setId(specificationEntity.getId());
  929. goodsSpecificationDao.update(goodsSpecification);
  930. }
  931. if(product == null){
  932. product = new ProductEntity();
  933. product.setGoodsSn(goodsDto.getGoodsSn());
  934. product.setGoodsId(goodsEntity.getId());
  935. product.setGoodsDefault(0);
  936. product.setGoodsNumber(goodsEntity.getGoodsNumber());
  937. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  938. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  939. productDao.save(product);
  940. }else{
  941. product.setGoodsSpecificationIds(goodsSpecification.getId().toString());
  942. product.setGoodsSpecificationNameValue(goodsSpecification.getValue());
  943. productDao.update(product);
  944. }
  945. }
  946. }
  947. }
  948. ExportExceptionDataEntity exportExceptionDataEntity = new ExportExceptionDataEntity();
  949. exportExceptionDataEntity.setCreaterSn(user.getUserId().toString());
  950. exportExceptionDataEntity.setUserId(user.getUserId().intValue());
  951. exportExceptionDataEntity.setCreateTime(new Date());
  952. exportExceptionDataEntity.setModTime(new Date());
  953. exportExceptionDataEntity.setMerchSn(merchSn);
  954. exportExceptionDataEntity.setStoreId(user.getStoreId());
  955. if(exportDataType == 1) {
  956. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_1.getItem());
  957. }else{
  958. exportExceptionDataEntity.setExportDataType(Dict.exportDataType.item_2.getItem());
  959. }
  960. if(failMerchUserGoodsSnList != null && failMerchUserGoodsSnList.size() > 0){
  961. exportExceptionDataEntity.setExportExceptionData("不能操作除了登录用户以外商户的商品,当前商户编号为【"+merchSn+"】,请检查商品编码【"+failMerchUserGoodsSnList+"】的商品信息");
  962. goodsUtils.save(exportExceptionDataEntity);
  963. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  964. }
  965. if(failMerchGoodsSnList != null && failMerchGoodsSnList.size() > 0){
  966. exportExceptionDataEntity.setExportExceptionData("第三方商户代码不存在,请在商城配置》第三方商户管理中维护,请检查商品编码【"+failMerchGoodsSnList+"】的商品信息,请先维护再继续操作!");
  967. goodsUtils.save(exportExceptionDataEntity);
  968. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  969. }
  970. if(failGoodsSnList != null && failGoodsSnList.size() > 0){
  971. if(failSameSkuList.size()>0) {
  972. exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  973. failGoodsTypeList + "】,SKU【" + failSameSkuList + "】的商品信息");
  974. goodsUtils.save(exportExceptionDataEntity);
  975. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  976. }else{
  977. exportExceptionDataEntity.setExportExceptionData("不能有重复的商品编码、sku信息!请检查商品编码【" + failGoodsSnList + "】,业务类型【" +
  978. failGoodsTypeList + "】的商品信息");
  979. goodsUtils.save(exportExceptionDataEntity);
  980. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  981. }
  982. }
  983. if(failTypeGoodsSnList != null && failTypeGoodsSnList.size() > 0){
  984. exportExceptionDataEntity.setExportExceptionData("货品业务类型只能是【00保税备货、02保税补货、10保税展示】!请检查商品编码【"+failTypeGoodsSnList+"】的商品信息");
  985. goodsUtils.save(exportExceptionDataEntity);
  986. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  987. }
  988. if(failProdbarGoodsSnList != null && failProdbarGoodsSnList.size() > 0){
  989. exportExceptionDataEntity.setExportExceptionData("不能有重复的产品条码信息!请检查商品编码【"+failProdbarGoodsSnList+"】的商品产品条码信息");
  990. goodsUtils.save(exportExceptionDataEntity);
  991. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  992. }
  993. if(failHotGoodsSnList != null && failHotGoodsSnList.size() > 0){
  994. exportExceptionDataEntity.setExportExceptionData("请检查业务类型为【保税补货或保税展示】的商品,商品编码【"+failHotGoodsSnList+"】的商品不能设置为热销!");
  995. goodsUtils.save(exportExceptionDataEntity);
  996. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  997. }
  998. // if(failCateGoodsSnList != null && failCateGoodsSnList.size() > 0){
  999. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中维护,商品分类与商户信息对应,请检查该商品商户信息下的分类是否维护,不存在的商品编码【"+failCateGoodsSnList+"】");
  1000. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1001. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1002. // }
  1003. // if(failCateL2GoodsSnList != null && failCateL2GoodsSnList.size() > 0){
  1004. // exportExceptionDataEntity.setExportExceptionData("分类信息请在商城配置》商品分类中查看,商品分类必须为二级分类,不存在的商品编码【"+failCateL2GoodsSnList+"】");
  1005. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1006. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1007. // }
  1008. // if(failBrandGoodsSnList != null && failBrandGoodsSnList.size() > 0){
  1009. // exportExceptionDataEntity.setExportExceptionData("品牌信息请在商城配置》品牌制造商中维护,品牌与商户信息对应,请检查该商品商户信息下的品牌是否维护,不存在的商品编码【" + failBrandGoodsSnList + "】");
  1010. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1011. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1012. // }
  1013. // if(failFreightGoodsSnList != null && failFreightGoodsSnList.size() > 0){
  1014. // exportExceptionDataEntity.setExportExceptionData("运费信息请在商城配置》运费模板中维护,运费与商户信息对应,请检查该商品商户信息下的运费是否维护,不存在的商品编码【"+failFreightGoodsSnList+"】,运费【"+failFreightList+"】");
  1015. // exportExceptionDataDao.save(exportExceptionDataEntity);
  1016. // throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1017. // }
  1018. if(failSuppGoodsSnList != null && failSuppGoodsSnList.size() > 0){
  1019. exportExceptionDataEntity.setExportExceptionData("供应商信息请在商城配置》商品供应商中维护,供应商与商户信息对应,请检查该商品商户信息下的供应商是否维护,不存在的商品编码【" + failSuppGoodsSnList + "】");
  1020. goodsUtils.save(exportExceptionDataEntity);
  1021. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1022. }
  1023. if(failUnitGoodsSnList != null && failUnitGoodsSnList.size() > 0){
  1024. exportExceptionDataEntity.setExportExceptionData("计算单位信息请在商城配置》计算单位中维护,不存在的商品编码【" + failUnitGoodsSnList + "】");
  1025. goodsUtils.save(exportExceptionDataEntity);
  1026. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1027. }
  1028. if(failNationGoodsSnList != null && failNationGoodsSnList.size() > 0){
  1029. exportExceptionDataEntity.setExportExceptionData("原产国信息请在商城配置》原产国中维护,不存在的商品编码【" + failNationGoodsSnList + "】");
  1030. goodsUtils.save(exportExceptionDataEntity);
  1031. throw new RRException("导入数据异常,异常信息请在商品管理》》商品导入异常数据中查看检查");
  1032. }
  1033. }else{
  1034. throw new RRException("导入数据为空,或者检查商品编码数据是否为空");
  1035. }
  1036. return 1;
  1037. }
  1038. @Override
  1039. public GoodsDetailsDto queryGoodsDetailsByProdBarcode(String prodBarcode, String storeId) {
  1040. return goodsDao.queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
  1041. }
  1042. @Override
  1043. public GoodsPanoramaDto searchGoodsPanoramaDtoByKeyword(String keyword) {
  1044. return goodsDao.searchGoodsPanoramaDtoByKeyword(keyword);
  1045. }
  1046. @Override
  1047. public List<GoodsEntity> queryExportList(Map<String, Object> params) {
  1048. return goodsDao.queryExportList(params);
  1049. }
  1050. /**
  1051. * 查出pdf需要的需要
  1052. *
  1053. * @param sku 商品sku
  1054. * @param storeId
  1055. * @param prodBarcode
  1056. * @return
  1057. */
  1058. @Override
  1059. public PDFGoodsDto queryForPDFData(String sku, String storeId, String prodBarcode) {
  1060. return goodsDao.queryForPDFData(sku,storeId,prodBarcode);
  1061. }
  1062. /**
  1063. * 查询产品价格
  1064. *
  1065. * @param prodBarcode
  1066. * @param storeId
  1067. * @return
  1068. */
  1069. @Override
  1070. @Transactional
  1071. public Map<String,Object> calculateGoodsDetail(String prodBarcode, String storeId) {
  1072. /**
  1073. * 1.首先根据商品条码跟门店id查询是否有库存,没库存直接返回
  1074. */
  1075. GoodsDetailsDto goods = queryGoodsDetailsByProdBarcode(prodBarcode,storeId);
  1076. if(goods == null) {
  1077. return null;
  1078. }
  1079. goods.setDiscountedPrice(new BigDecimal(0));
  1080. BigDecimal goodsRate = null;
  1081. try {
  1082. goodsRate = new BigDecimal(goods.getGoodsRate());
  1083. } catch (Exception e) {
  1084. goodsRate = new BigDecimal(0);
  1085. }
  1086. BigDecimal retailPrice = goods.getRetailPrice();
  1087. BigDecimal tax = goodsRate.multiply(retailPrice.divide(new BigDecimal(1).add(goodsRate),2,RoundingMode.HALF_DOWN)).setScale(2,RoundingMode.HALF_DOWN) ;
  1088. goods.setGoodstaxes(tax.toString());
  1089. goods.setActualPaymentAmount(retailPrice.setScale(2,RoundingMode.HALF_UP));
  1090. Map<String,Object> skuActivitiesMap = new HashMap<>();
  1091. SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
  1092. /**
  1093. * 2.查询当前时间,该门店是否有活动,如果有活动,查询开启了哪些营销方式
  1094. * 参数: 当前时间 门店id
  1095. */
  1096. List<MkActivitiesEntity> mkActivitiesEntityList = mkActivitiesService.queryByNow(storeId,format.format(new Date()));
  1097. if(mkActivitiesEntityList == null || mkActivitiesEntityList.size() == 0){
  1098. skuActivitiesMap.put("goods",goods);
  1099. return skuActivitiesMap;
  1100. }
  1101. // 遍历活动集合,查询有哪些活动是开启的
  1102. boolean daily = false,coupon = false,combinationPrice = false
  1103. ,discount = false,fullGift = false,fullReduction = false
  1104. ,getOneFree = false,promotion = false;
  1105. List<String> topicList = new ArrayList<>(); // 记录有哪些营销活动的topic
  1106. Map<String,Long> mkaIdMap = new HashMap<>(); // 记录topic跟mkaId的关系
  1107. // 将所有的营销活动新增到list中
  1108. for(MkActivitiesEntity mkActivitiesEntity : mkActivitiesEntityList){
  1109. topicList.add(mkActivitiesEntity.getMkaTopic());
  1110. mkaIdMap.put(mkActivitiesEntity.getMkaTopic(),mkActivitiesEntity.getMkaId());
  1111. }
  1112. // 判断有哪些营销活动
  1113. if(topicList.contains("zhjsp")) // 组合价
  1114. combinationPrice = true;
  1115. if(topicList.contains("dz")) // 打折
  1116. discount = true;
  1117. if(topicList.contains("mz")) //满赠
  1118. fullGift = true;
  1119. if(topicList.contains("mj")) // 满减
  1120. fullReduction = true;
  1121. if(topicList.contains("mysy")) // 买一送一
  1122. getOneFree = true;
  1123. if(topicList.contains("rchd")) // 日常活动
  1124. daily = true;
  1125. if(topicList.contains("yhq")) // 优惠券
  1126. coupon = true;
  1127. if(topicList.contains("lscx")) // 临时促销
  1128. promotion = true;
  1129. // 获取未优惠前的商品价格
  1130. retailPrice = goods.getRetailPrice();;
  1131. // 根据条码查询商品品牌名称 mall_brand mall_product_store_rela mall_goods
  1132. String brandName = goods.getBrand();
  1133. /**
  1134. * 优先级:临时促销 》买一送一=满赠 》 组合价=日常活动 》 打折=满减 》 优惠券
  1135. */
  1136. /**
  1137. * 组合价的做法就是将参与组合的条码带到收银端
  1138. * 现根据营销活动id跟条形码,查询有哪些参与该条码组合的商品
  1139. *
  1140. *
  1141. * TODO
  1142. */
  1143. if(combinationPrice){
  1144. Long mkaId = mkaIdMap.get("zhjsp");
  1145. Map<String,Object> param = new HashMap<>();
  1146. param.put("mkaId",mkaId);
  1147. param.put("prodBarcode",prodBarcode);
  1148. List<MkActivitiesCombinationPriceEntity> combinationPriceList = combinationPriceService.queryList(param);
  1149. if(combinationPriceList != null && combinationPriceList.size() > 0) {
  1150. Map<String, List<MkActivitiesCombinationPriceEntity>> collect =
  1151. combinationPriceList.stream().collect(Collectors.groupingBy(MkActivitiesCombinationPriceEntity::getCombinationType));
  1152. skuActivitiesMap.put("zhjsp",collect);
  1153. }
  1154. }
  1155. format = new SimpleDateFormat("yyyy-MM-dd");
  1156. String nowTime = format.format(new Date());
  1157. /**
  1158. * 满减可能是跟着条码,也可能跟着品牌
  1159. * 根据商品品牌跟商品条码去查询是否有优惠金额
  1160. *
  1161. * 满足金额 购买商品条码 赠品条码
  1162. *
  1163. */
  1164. Map<String,Object> fullReductionMap = new HashMap<>();
  1165. if(fullReduction){
  1166. Long mkaId = mkaIdMap.get("mj");
  1167. MkActivitiesFullReductionEntity fullReductionEntity = fullReductionService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1168. if(fullReductionEntity != null) {
  1169. if(!StringUtils.isNullOrEmpty(fullReductionEntity.getProductBrand())){
  1170. // 跟着品牌走
  1171. fullReductionMap.put(brandName,fullReductionEntity);
  1172. }else{
  1173. // 跟着条码走
  1174. fullReductionMap.put(fullReductionEntity.getBarcode(), fullReductionEntity);
  1175. }
  1176. skuActivitiesMap.put("mj",fullReductionMap);
  1177. }
  1178. }
  1179. /**
  1180. * 满赠可能是跟着条码,也可能跟着品牌
  1181. * 根据商品品牌跟商品条码去查询是否有满赠
  1182. * 1.先扫买的商品,然后查询出赠送的商品条码
  1183. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1184. * 满足的金额 购买的商品条码或者品牌 赠送的商品条码
  1185. * TODO
  1186. */
  1187. Map<String,Object> fullGiftMap = new HashMap<>();
  1188. if(fullGift){
  1189. Long mkaId = mkaIdMap.get("mz");
  1190. MkActivitiesFullGiftEntity giftEntity = fullGiftService.queryByCodeOrBrand(mkaId,prodBarcode,brandName,nowTime);
  1191. if(giftEntity != null) {
  1192. if(giftEntity.getProductBrand() != null){
  1193. // 跟着品牌走
  1194. fullGiftMap.put(brandName,giftEntity);
  1195. }else{
  1196. // 跟着条码走
  1197. fullGiftMap.put(giftEntity.getBarcode(), giftEntity);
  1198. }
  1199. skuActivitiesMap.put("mz",fullGiftMap);
  1200. }
  1201. }
  1202. /**
  1203. * 买一送一可能是跟着条码,也可能跟着品牌
  1204. * 根据商品品牌跟商品条码去查询是否有送的商品
  1205. * 有两个场景
  1206. * 1.先扫买的商品,然后查询出赠送的商品条码
  1207. * 2.先扫赠的商品,然后查询出符合条件的商品条码或者品牌
  1208. * 所以就需要一个map
  1209. * key为购买的商品条码或者商品品牌 value为赠送的商品条码
  1210. * 但是品牌是根据条码查询的,所以最终map里面的结构是
  1211. * key 商品条码 value 赠品条码
  1212. */
  1213. if(getOneFree){
  1214. Long mkaId = mkaIdMap.get("mysy");
  1215. MkActivitiesGetOneFreeGoodsEntity getOneFreeGoodsEntity = getOneFreeGoodsService.queryByCodeOrBrand(mkaId,prodBarcode,brandName);
  1216. if(getOneFreeGoodsEntity != null){
  1217. if("无".equals(getOneFreeGoodsEntity.getProductBrand())){
  1218. getOneFreeGoodsEntity.setBrand(false);
  1219. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1220. }else{
  1221. getOneFreeGoodsEntity.setBrand(true);
  1222. skuActivitiesMap.put("mysy",getOneFreeGoodsEntity);
  1223. }
  1224. }
  1225. }
  1226. // --------------------------------------------------------------------------------------
  1227. /**
  1228. * 优惠券跟着条形码走,一般是设置一个标识,然后最后输入优惠券码后,减扣对应的标识,所以返回一个map数组
  1229. */
  1230. if(coupon){
  1231. Long mkaId = mkaIdMap.get("yhq");
  1232. MkActivitiesCouponEntity couponEntity = couponService.queryByBarCode(mkaId,prodBarcode,nowTime);
  1233. if(couponEntity != null){ // 优惠券码,优惠金额
  1234. Map<String,Object> returnMap = new HashMap<>();
  1235. returnMap.put(couponEntity.getCouponSn() , couponEntity.getCouponPrice());
  1236. skuActivitiesMap.put("yhq",returnMap);
  1237. }
  1238. }
  1239. /**
  1240. * 打折的价格是与条形码对应的,所以需要根据条形码和营销方式id去查询活动价格
  1241. */
  1242. if(discount){
  1243. Long mkaId = mkaIdMap.get("dz");
  1244. MkActivitiesDiscountEntity discountEntity = discountService.queryByBarCode(mkaId,prodBarcode);
  1245. // TODO 可能会直接替代产品价格
  1246. if (discountEntity != null) {
  1247. goods.setActualPaymentAmount(discountEntity.getActivityPrice());
  1248. goods.setDiscountedPrice(retailPrice.subtract(discountEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1249. goods.setActivity("打折");
  1250. }
  1251. }
  1252. /**
  1253. * 日常活动跟着条形码走,优先级比临时促销低,但是高于正常价格
  1254. */
  1255. if(daily){
  1256. Long mkaId = mkaIdMap.get("rchd");
  1257. MkDailyActivitiesEntity dailyActivitiesEntity = dailyActivitiesService.queryByBarCode(mkaId,prodBarcode);
  1258. if(dailyActivitiesEntity != null){
  1259. goods.setActualPaymentAmount(dailyActivitiesEntity.getActivityPrice());
  1260. goods.setDiscountedPrice(retailPrice.subtract(dailyActivitiesEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1261. goods.setActivity("日常活动");
  1262. }
  1263. }
  1264. /**
  1265. * 临时促销跟着条形码走,优先级应该最高,所以排到了最下面
  1266. */
  1267. if(promotion){
  1268. Long mkaId = mkaIdMap.get("lscx");
  1269. MkActivitiesPromotionEntity promotionEntity = promotionService.queryByBarCode(mkaId,prodBarcode);
  1270. // 如果该商品存在临时促销,直接替换活动价格
  1271. if(promotionEntity != null){
  1272. goods.setActualPaymentAmount(promotionEntity.getActivityPrice());
  1273. goods.setDiscountedPrice(retailPrice.subtract(promotionEntity.getActivityPrice()).setScale(2,BigDecimal.ROUND_HALF_UP));
  1274. goods.setActivity("临时促销");
  1275. }
  1276. }
  1277. skuActivitiesMap.put("goods",goods);
  1278. return skuActivitiesMap;
  1279. }
  1280. /**
  1281. * 根据条形码查询商品
  1282. *
  1283. * @param barCode
  1284. * @return
  1285. */
  1286. @Override
  1287. public GoodsEntity queryByBarcode(String barCode) {
  1288. return goodsDao.queryByBarcode(barCode);
  1289. }
  1290. /**
  1291. * 根据sku查询商品
  1292. *
  1293. * @param sku
  1294. * @return
  1295. */
  1296. @Override
  1297. public GoodsEntity queryBySku(String sku) {
  1298. return goodsDao.queryBySku(sku);
  1299. }
  1300. /* @Override
  1301. @Transactional
  1302. public int uploadExcel(MultipartFile file) {
  1303. SysUserEntity user = ShiroUtils.getUserEntity();
  1304. List<String[]> list = ExcelImport.getExcelData(file);
  1305. // 取门店名称
  1306. StoreEntity storeEntity = storeDao.queryObjectByName(list.get(0)[3]);
  1307. if (null == storeEntity) {
  1308. return 0;
  1309. }
  1310. //去除表头两行、底部合计
  1311. if (list != null && list.size() > 3) {
  1312. ProductStoreRelaEntity storeRelaEntity;
  1313. ProductEntity productEntity;
  1314. for (int i = 2; i < list.size() - 1; i++) {
  1315. String[] item = list.get(i);
  1316. String goodsSn = item[0];
  1317. productEntity = productDao.queryObjectBySn(goodsSn);
  1318. if (StringUtils.isNullOrEmpty(goodsSn)) {
  1319. continue;
  1320. }
  1321. if (null == productEntity || null == productEntity.getId()) {
  1322. continue;
  1323. }
  1324. storeRelaEntity = productStoreRelaDao.queryByStoreIdProductId(storeEntity.getId(), productEntity.getId());
  1325. if (null != storeRelaEntity && null != storeRelaEntity.getId()) {
  1326. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1327. storeRelaEntity.setStockNum(Integer.valueOf(item[3].replace(".00", "")));
  1328. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1329. productStoreRelaDao.update(storeRelaEntity);
  1330. } else {
  1331. storeRelaEntity = new ProductStoreRelaEntity();
  1332. storeRelaEntity.setGoodsId(productEntity.getGoodsId());
  1333. storeRelaEntity.setProductId(productEntity.getId());
  1334. storeRelaEntity.setRetailPrice(new BigDecimal(item[6]));
  1335. storeRelaEntity.setMarketPrice(new BigDecimal(item[6]));
  1336. storeRelaEntity.setStockNum(Integer.valueOf(item[3]));
  1337. storeRelaEntity.setStockPrice(new BigDecimal(item[4]));
  1338. storeRelaEntity.setStoreId(storeEntity.getId());
  1339. productStoreRelaDao.save(storeRelaEntity);
  1340. }
  1341. }
  1342. }
  1343. return 1;
  1344. }*/
  1345. public GoodsEntity queryObjectBySn(String goodsSn) {
  1346. return goodsDao.queryObjectBySn(goodsSn);
  1347. }
  1348. }