GoodsServiceImpl.java 74 KB

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