|
@@ -5,8 +5,8 @@ import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.auth.api.client.SysUserFeignService;
|
|
|
import com.ym.mec.auth.api.entity.SysUser;
|
|
|
-import com.ym.mec.biz.dal.dao.SellOrderDao;
|
|
|
import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentGoodsSellDao;
|
|
|
import com.ym.mec.biz.dal.dao.StudentRepairDao;
|
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
import com.ym.mec.biz.dal.dto.BasicUserDto;
|
|
@@ -67,7 +67,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
@Autowired
|
|
|
private SellOrderService sellOrderService;
|
|
|
@Autowired
|
|
|
- private SellOrderDao sellOrderDao;
|
|
|
+ private StudentGoodsSellDao studentGoodsSellDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Integer, StudentRepair> getDAO() {
|
|
@@ -103,11 +103,11 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
- public Map addGoodsSellOrder(GoodsSellDto goodsSellDto) throws Exception {
|
|
|
+ public Map addGoodsSellOrder(StudentGoodsSell studentGoodsSell) throws Exception {
|
|
|
SysUser sysUser = sysUserFeignService.queryUserInfo();
|
|
|
Integer studentId = sysUser.getId();
|
|
|
- String goodsId = goodsSellDto.getGoodsId();
|
|
|
- if (StringUtils.isEmpty(goodsId)) {
|
|
|
+ List<GoodsSellDto> goodsSellDtos = studentGoodsSell.getGoodsSellDtos();
|
|
|
+ if(goodsSellDtos == null || goodsSellDtos.size() == 0){
|
|
|
throw new BizException("请选择需要购买的商品");
|
|
|
}
|
|
|
if (studentId == null) {
|
|
@@ -116,14 +116,31 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
studentDao.lockUser(studentId);
|
|
|
SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+ studentGoodsSell.setOrderNo(orderNo);
|
|
|
|
|
|
- String[] goodsIds = goodsId.split(",");
|
|
|
- Map<String, BigDecimal> map = getMap("goods", "id_", "group_purchase_price_", goodsId, String.class, BigDecimal.class);
|
|
|
+ List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
+// Map<Integer, List<GoodsSellDto>> goodsMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
+// String[] goodsIds = goodsId.split(",");
|
|
|
+ Map<Integer, BigDecimal> map = getMap("goods", "id_", "market_price_", goodsIds, Integer.class, BigDecimal.class);
|
|
|
BigDecimal amount = BigDecimal.ZERO;
|
|
|
- for (String id : goodsIds) {
|
|
|
+ for (Integer id : goodsIds) {
|
|
|
amount.add(map.get(id));
|
|
|
}
|
|
|
- List<Goods> goods = goodsService.findGoodsByIds(goodsId);
|
|
|
+ studentGoodsSell.setGoodsJson(JSONObject.toJSONString(goodsSellDtos));
|
|
|
+ studentGoodsSell.setTotalAmount(amount);
|
|
|
+ if(studentGoodsSell.getId() == null){
|
|
|
+ studentGoodsSellDao.insert(studentGoodsSell);
|
|
|
+ }else {
|
|
|
+ studentGoodsSellDao.update(studentGoodsSell);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (studentGoodsSell.getType() == 1) {
|
|
|
+ Map<String, Object> repairInfoMap = new HashMap<>();
|
|
|
+ MapUtil.populateMap(repairInfoMap, studentGoodsSell);
|
|
|
+ return repairInfoMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ List<Goods> goods = goodsService.findGoodsByIds(StringUtils.join(goodsIds,","));
|
|
|
|
|
|
StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
studentPaymentOrder.setUserId(studentId);
|
|
@@ -139,7 +156,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
Map<Integer, List<Goods>> collect = goods.stream().collect(Collectors.groupingBy(Goods::getId));
|
|
|
List<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
|
|
|
- for (String id : goodsIds) {
|
|
|
+ for (Integer id : goodsIds) {
|
|
|
Goods e = collect.get(id).get(0);
|
|
|
StudentPaymentOrderDetail studentPaymentOrderDetail = new StudentPaymentOrderDetail();
|
|
|
studentPaymentOrderDetail.setRemitFee(BigDecimal.ZERO);
|
|
@@ -153,7 +170,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
}
|
|
|
studentPaymentOrderDetail.setType(type);
|
|
|
studentPaymentOrderDetail.setPrice(e.getGroupPurchasePrice());
|
|
|
- studentPaymentOrderDetail.setGoodsIdList(id);
|
|
|
+ studentPaymentOrderDetail.setGoodsIdList(id.toString());
|
|
|
studentPaymentOrderDetail.setPaymentOrderId(studentPaymentOrder.getId());
|
|
|
studentPaymentOrderDetail.setKitGroupPurchaseType(KitGroupPurchaseTypeEnum.GROUP);
|
|
|
studentPaymentOrderDetailList.add(studentPaymentOrderDetail);
|
|
@@ -162,7 +179,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
|
|
|
|
studentPaymentOrder.setVersion(0);
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
|
- if (goodsSellDto.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentId);
|
|
|
if (userCashAccount == null) {
|
|
|
throw new BizException("用户账户找不到");
|