优化商城分类及商品管理

This commit is contained in:
2024-07-27 23:08:31 +08:00
parent 9847a03743
commit 2402c8b3f4
12 changed files with 187 additions and 106 deletions
@@ -213,22 +213,12 @@ public class MpController extends BaseController {
public ApiResult<?> index(GoodsParam param) { public ApiResult<?> index(GoodsParam param) {
// 使用关联查询 // 使用关联查询
final HashMap<String, Object> layout = new HashMap<>(); final HashMap<String, Object> layout = new HashMap<>();
// 瀑布流商品数据 // 瀑布流商品数据 (type:0 商城商品,1 外卖商品)
final List<Goods> goods = goodsService.list(new LambdaQueryWrapper<Goods>().ne(Goods::getCategoryParent, "外卖").last("limit 10")); // final List<Goods> goods = goodsService.list(new LambdaQueryWrapper<Goods>().ne(Goods::getType, 0).last("limit 10"));
final List<Goods> foods = goodsService.list(new LambdaQueryWrapper<Goods>().eq(Goods::getCategoryParent, "外卖").last("limit 10")); // final List<Goods> foods = goodsService.list(new LambdaQueryWrapper<Goods>().eq(Goods::getType, 1).last("limit 10"));
// List<Goods> evenNumbers = new ArrayList<>();
// List<Goods> oddNumbers = new ArrayList<>();
// for (Goods g : goods) {
// final int index = goods.indexOf(g);
// if (index % 2 == 0) {
// evenNumbers.add(g);
// } else {
// oddNumbers.add(g);
// }
// }
layout.put("goods",goods); layout.put("goods",goodsService.getGoodsSpecType0());
layout.put("foods", foods); layout.put("foods", goodsService.getGoodsSpecType1());
return success(layout); return success(layout);
} }
@@ -13,6 +13,7 @@ import com.gxwebsoft.cms.param.MpPagesParam;
import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@@ -37,7 +38,9 @@ public class MpPagesServiceImpl extends ServiceImpl<MpPagesMapper, MpPages> impl
PageParam<MpPages, MpPagesParam> page = new PageParam<>(param); PageParam<MpPages, MpPagesParam> page = new PageParam<>(param);
page.setDefaultOrder("sort_number asc, create_time asc"); page.setDefaultOrder("sort_number asc, create_time asc");
List<MpPages> list = baseMapper.selectPageRel(page, param); List<MpPages> list = baseMapper.selectPageRel(page, param);
if (param.getSceneType() != null && param.getSceneType().equals("showMpMenus")) { System.out.println("param = " + param);
System.out.println("list2 = " + list);
if (!CollectionUtils.isEmpty(list) && param.getSceneType() != null && param.getSceneType().equals("showMpMenus")) {
final List<MpMenu> mpMenus = mpMenuService.list(new LambdaUpdateWrapper<MpMenu>().eq(MpMenu::getPageId, list.get(0).getId())); final List<MpMenu> mpMenus = mpMenuService.list(new LambdaUpdateWrapper<MpMenu>().eq(MpMenu::getPageId, list.get(0).getId()));
final Map<Integer, List<MpMenu>> collect = mpMenus.stream().collect(Collectors.groupingBy(MpMenu::getParentId)); final Map<Integer, List<MpMenu>> collect = mpMenus.stream().collect(Collectors.groupingBy(MpMenu::getParentId));
final List<MpAd> ads = mpAdService.list(new LambdaUpdateWrapper<MpAd>().eq(MpAd::getPageId, list.get(0).getId())); final List<MpAd> ads = mpAdService.list(new LambdaUpdateWrapper<MpAd>().eq(MpAd::getPageId, list.get(0).getId()));
@@ -1,18 +1,21 @@
package com.gxwebsoft.shop.controller; package com.gxwebsoft.shop.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.gxwebsoft.common.core.web.ApiResult; import com.gxwebsoft.common.core.web.ApiResult;
import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.common.core.web.BatchParam; import com.gxwebsoft.common.core.web.BatchParam;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
import com.gxwebsoft.common.system.entity.User; import com.gxwebsoft.common.system.entity.User;
import com.gxwebsoft.shop.entity.Goods; import com.gxwebsoft.shop.entity.*;
import com.gxwebsoft.shop.entity.GoodsCategory;
import com.gxwebsoft.shop.param.GoodsCategoryParam; import com.gxwebsoft.shop.param.GoodsCategoryParam;
import com.gxwebsoft.shop.param.GoodsSpecParam;
import com.gxwebsoft.shop.service.GoodsCategoryService; import com.gxwebsoft.shop.service.GoodsCategoryService;
import com.gxwebsoft.shop.service.GoodsService; import com.gxwebsoft.shop.service.GoodsService;
import com.gxwebsoft.shop.service.GoodsSpecService;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource; import javax.annotation.Resource;
@@ -36,6 +39,8 @@ public class GoodsCategoryController extends BaseController {
@Resource @Resource
private GoodsCategoryService goodsCategoryService; private GoodsCategoryService goodsCategoryService;
@Resource @Resource
private GoodsSpecService goodsSpecService;
@Resource
private GoodsService goodsService; private GoodsService goodsService;
@ApiOperation("查询全部商品分类(树型结构)") @ApiOperation("查询全部商品分类(树型结构)")
@@ -43,11 +48,36 @@ public class GoodsCategoryController extends BaseController {
public ApiResult<List<GoodsCategory>> getTree(GoodsCategoryParam param) { public ApiResult<List<GoodsCategory>> getTree(GoodsCategoryParam param) {
final List<GoodsCategory> list = goodsCategoryService.listRel(param); final List<GoodsCategory> list = goodsCategoryService.listRel(param);
final Set<Integer> categoryIds = list.stream().map(GoodsCategory::getCategoryId).collect(Collectors.toSet()); final Set<Integer> categoryIds = list.stream().map(GoodsCategory::getCategoryId).collect(Collectors.toSet());
final List<Goods> goods = goodsService.list(new LambdaQueryWrapper<Goods>().in(Goods::getCategoryId, categoryIds).eq(Goods::getStatus,0).eq(Goods::getDeleted,0)); if (categoryIds.isEmpty()) {
return success(list);
}
final List<Goods> goods = goodsService.getGoodsSpec();
System.out.println("goodsBySpec = " + goods);
// final List<Goods> goods = goodsService.list(new LambdaQueryWrapper<Goods>().in(Goods::getCategoryId, categoryIds).eq(Goods::getStatus,0).eq(Goods::getDeleted,0));
final Map<Integer, List<Goods>> collectGoods = goods.stream().collect(Collectors.groupingBy(Goods::getCategoryId)); final Map<Integer, List<Goods>> collectGoods = goods.stream().collect(Collectors.groupingBy(Goods::getCategoryId));
final List<GoodsSpec> specs = goodsSpecService.list(new LambdaQueryWrapper<GoodsSpec>().in(GoodsSpec::getGoodsId, categoryIds));
System.out.println("specs = " + specs);
final Map<Integer, List<GoodsSpec>> collectGoodsSpec = specs.stream().collect(Collectors.groupingBy(GoodsSpec::getGoodsId));
list.forEach(d -> { list.forEach(d -> {
d.setName(d.getTitle()); d.setName(d.getTitle());
final List<Goods> goodsList = collectGoods.get(d.getCategoryId());
if (!CollectionUtils.isEmpty(goodsList)) {
// goodsList.forEach(v -> {
// System.out.println("v = " + v);
// final String specValue = v.getSpecValue();
// System.out.println("collectGoodsSpec = " + collectGoodsSpec);
// final List<GoodsSpec> goodsSpecs = collectGoodsSpec.get(v.getGoodsId());
// if (!CollectionUtils.isEmpty(goodsSpecs)) {
// final GoodsSpec spec = goodsSpecs.get(0);
// v.setGoodsSpecValue(spec.getSpecValue());
// }
// });
d.setChildrens(collectGoods.get(d.getCategoryId())); d.setChildrens(collectGoods.get(d.getCategoryId()));
}
}); });
return success(list); return success(list);
} }
@@ -2,8 +2,10 @@ package com.gxwebsoft.shop.controller;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper; import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.gxwebsoft.common.core.utils.JSONUtil;
import com.gxwebsoft.common.core.web.BaseController; import com.gxwebsoft.common.core.web.BaseController;
import com.gxwebsoft.shop.entity.GoodsSku; import com.gxwebsoft.shop.entity.GoodsSku;
import com.gxwebsoft.shop.entity.GoodsSkuVO;
import com.gxwebsoft.shop.entity.GoodsSpec; import com.gxwebsoft.shop.entity.GoodsSpec;
import com.gxwebsoft.shop.service.GoodsService; import com.gxwebsoft.shop.service.GoodsService;
import com.gxwebsoft.shop.entity.Goods; import com.gxwebsoft.shop.entity.Goods;
@@ -85,7 +87,17 @@ public class GoodsController extends BaseController {
@GetMapping("/{id}") @GetMapping("/{id}")
public ApiResult<Goods> get(@PathVariable("id") Integer id) { public ApiResult<Goods> get(@PathVariable("id") Integer id) {
// 使用关联查询 // 使用关联查询
return success(goodsService.getByIdRel(id)); final Goods goods = goodsService.getByIdRel(id);
// 提取specValue
final GoodsSpec spec = goodsSpecService.getOne(new LambdaQueryWrapper<GoodsSpec>().eq(GoodsSpec::getGoodsId, id).last("limit 1"));
if (spec != null) {
final String specValue = spec.getSpecValue();
final Object object = JSONUtil.parseObject(specValue, Object.class);
goods.setGoodsSpecValue(object);
}
return success(goods);
} }
@PreAuthorize("hasAuthority('shop:goods:save')") @PreAuthorize("hasAuthority('shop:goods:save')")
@@ -109,7 +121,6 @@ public class GoodsController extends BaseController {
@ApiOperation("修改商品记录表") @ApiOperation("修改商品记录表")
@PutMapping() @PutMapping()
public ApiResult<?> update(@RequestBody Goods goods) { public ApiResult<?> update(@RequestBody Goods goods) {
System.out.println("getGoodsSpec = " + goods.getGoodsSpec());
if (goodsService.updateById(goods)) { if (goodsService.updateById(goods)) {
// 删除旧信息 // 删除旧信息
goodsSpecService.remove(new LambdaQueryWrapper<GoodsSpec>().eq(GoodsSpec::getGoodsId, goods.getGoodsId())); goodsSpecService.remove(new LambdaQueryWrapper<GoodsSpec>().eq(GoodsSpec::getGoodsId, goods.getGoodsId()));
@@ -129,6 +129,14 @@ public class Goods implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private GoodsSpec goodsSpec; private GoodsSpec goodsSpec;
@ApiModelProperty(value = "规格值")
@TableField(exist = false)
private String specValue;
@ApiModelProperty(value = "商品规格值")
@TableField(exist = false)
private Object goodsSpecValue;
@ApiModelProperty(value = "商品sku列表") @ApiModelProperty(value = "商品sku列表")
@TableField(exist = false) @TableField(exist = false)
private List<GoodsSku> goodsSkus; private List<GoodsSku> goodsSkus;
@@ -39,7 +39,7 @@ public class GoodsCategory implements Serializable {
@TableField(exist = false) @TableField(exist = false)
private String name; private String name;
@ApiModelProperty(value = "类型 0列表 1单页 2外链") @ApiModelProperty(value = "类型 0商城分类 1外卖分类")
private Integer type; private Integer type;
@ApiModelProperty(value = "分类图片") @ApiModelProperty(value = "分类图片")
@@ -78,6 +78,9 @@ public class GoodsCategory implements Serializable {
@ApiModelProperty(value = "是否显示在首页") @ApiModelProperty(value = "是否显示在首页")
private Integer showIndex; private Integer showIndex;
@ApiModelProperty(value = "商铺ID")
private Integer merchantId;
@ApiModelProperty(value = "状态, 0正常, 1禁用") @ApiModelProperty(value = "状态, 0正常, 1禁用")
private Integer status; private Integer status;
@@ -2,6 +2,7 @@ package com.gxwebsoft.shop.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage; import com.baomidou.mybatisplus.core.metadata.IPage;
import com.github.yulichang.base.MPJBaseMapper;
import com.gxwebsoft.shop.entity.Goods; import com.gxwebsoft.shop.entity.Goods;
import com.gxwebsoft.shop.param.GoodsParam; import com.gxwebsoft.shop.param.GoodsParam;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
@@ -14,7 +15,7 @@ import java.util.List;
* @author 科技小王子 * @author 科技小王子
* @since 2024-07-25 19:22:01 * @since 2024-07-25 19:22:01
*/ */
public interface GoodsMapper extends BaseMapper<Goods> { public interface GoodsMapper extends MPJBaseMapper<Goods> {
/** /**
* 分页查询 * 分页查询
@@ -55,6 +55,9 @@
<if test="param.showIndex != null"> <if test="param.showIndex != null">
AND a.show_index = #{param.showIndex} AND a.show_index = #{param.showIndex}
</if> </if>
<if test="param.merchantId != null">
AND a.merchant_id = #{param.merchantId}
</if>
<if test="param.status != null"> <if test="param.status != null">
AND a.status = #{param.status} AND a.status = #{param.status}
</if> </if>
@@ -81,6 +81,9 @@ public class GoodsCategoryParam extends BaseParam {
@QueryField(type = QueryType.EQ) @QueryField(type = QueryType.EQ)
private Integer showIndex; private Integer showIndex;
@ApiModelProperty(value = "商铺ID")
private Integer merchantId;
@ApiModelProperty(value = "状态, 0正常, 1禁用") @ApiModelProperty(value = "状态, 0正常, 1禁用")
@QueryField(type = QueryType.EQ) @QueryField(type = QueryType.EQ)
private Integer status; private Integer status;
@@ -40,4 +40,13 @@ public interface GoodsService extends IService<Goods> {
Goods getByIdRel(Integer goodsId); Goods getByIdRel(Integer goodsId);
void saveBatchByAsync(Goods goods); void saveBatchByAsync(Goods goods);
List<Goods> getGoodsSpec();
// 商城商品
List<Goods> getGoodsSpecType0();
// 外卖商品
List<Goods> getGoodsSpecType1();
} }
@@ -1,13 +1,13 @@
package com.gxwebsoft.shop.service.impl; package com.gxwebsoft.shop.service.impl;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.gxwebsoft.shop.entity.GoodsSku; import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.gxwebsoft.shop.entity.GoodsSpec; import com.gxwebsoft.common.core.utils.JSONUtil;
import com.gxwebsoft.shop.entity.SpecValue; import com.gxwebsoft.shop.entity.*;
import com.gxwebsoft.shop.mapper.GoodsMapper; import com.gxwebsoft.shop.mapper.GoodsMapper;
import com.gxwebsoft.shop.service.GoodsService; import com.gxwebsoft.shop.service.GoodsService;
import com.gxwebsoft.shop.entity.Goods;
import com.gxwebsoft.shop.param.GoodsParam; import com.gxwebsoft.shop.param.GoodsParam;
import com.gxwebsoft.common.core.web.PageParam; import com.gxwebsoft.common.core.web.PageParam;
import com.gxwebsoft.common.core.web.PageResult; import com.gxwebsoft.common.core.web.PageResult;
@@ -19,6 +19,7 @@ import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
@@ -51,7 +52,10 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
list.forEach(d -> { list.forEach(d -> {
final List<GoodsSpec> goodsSpecs = collectSpecs.get(d.getGoodsId()); final List<GoodsSpec> goodsSpecs = collectSpecs.get(d.getGoodsId());
if (!CollectionUtils.isEmpty(goodsSpecs)) { if (!CollectionUtils.isEmpty(goodsSpecs)) {
d.setGoodsSpec(goodsSpecs.get(0)); final GoodsSpec spec = goodsSpecs.get(0);
final String value = spec.getSpecValue();
final Object object = JSONUtil.parseObject(value,Object.class);
d.setGoodsSpecValue(object);
} }
// d.setGoodsSkus(collectSkus.get(d.getGoodsId())); // d.setGoodsSkus(collectSkus.get(d.getGoodsId()));
}); });
@@ -80,9 +84,14 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
public void saveBatchByAsync(Goods goods) { public void saveBatchByAsync(Goods goods) {
// 保存商品多规格 // 保存商品多规格
if (goods.getSpecs().equals(1)) { if (goods.getSpecs().equals(1)) {
final GoodsSpec goodsSpec = goods.getGoodsSpec(); final GoodsSpec spec = goods.getGoodsSpec();
goodsSpec.setGoodsId(goods.getGoodsId()); if (spec != null) {
goodsSpecService.save(goodsSpec); spec.setGoodsId(goods.getGoodsId());
if(spec.getSpecValue() == null){
spec.setSpecValue(JSON.toJSONString(new ArrayList<>()));
}
goodsSpecService.save(spec);
// 保存商品sku表 // 保存商品sku表
final List<GoodsSku> goodsSkus = goods.getGoodsSkus(); final List<GoodsSku> goodsSkus = goods.getGoodsSkus();
if (!CollectionUtils.isEmpty(goodsSkus)) { if (!CollectionUtils.isEmpty(goodsSkus)) {
@@ -93,5 +102,41 @@ public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements
} }
} }
} }
}
@Override
public List<Goods> getGoodsSpec() {
// 多表查询
MPJLambdaWrapper<Goods> mpjLambdaWrapper = new MPJLambdaWrapper<>();
mpjLambdaWrapper.selectAll(Goods.class)
.select(GoodsSpec::getSpecValue)
.select(GoodsSpec::getSpecName)
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId);
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
}
@Override
public List<Goods> getGoodsSpecType0() {
// 多表查询
MPJLambdaWrapper<Goods> mpjLambdaWrapper = new MPJLambdaWrapper<>();
mpjLambdaWrapper.selectAll(Goods.class)
.select(GoodsSpec::getSpecValue)
.select(GoodsSpec::getSpecName)
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
.eq(Goods::getType,0);
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
}
@Override
public List<Goods> getGoodsSpecType1() {
// 多表查询
MPJLambdaWrapper<Goods> mpjLambdaWrapper = new MPJLambdaWrapper<>();
mpjLambdaWrapper.selectAll(Goods.class)
.select(GoodsSpec::getSpecValue)
.select(GoodsSpec::getSpecName)
.leftJoin(GoodsSpec.class,GoodsSpec::getGoodsId,GoodsSpec::getGoodsId)
.eq(Goods::getType,1);
return baseMapper.selectJoinList(Goods.class, mpjLambdaWrapper);
}
} }
@@ -147,11 +147,16 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
Order order = param.getOne(baseMapper.selectListRel(param)); Order order = param.getOne(baseMapper.selectListRel(param));
if (order != null) { if (order != null) {
final List<OrderInfo> list = orderInfoService.list(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getOrderId, orderId)); final List<OrderInfo> list = orderInfoService.list(new LambdaQueryWrapper<OrderInfo>().eq(OrderInfo::getOrderId, orderId));
// 订单信息
order.setOrderInfo(list); order.setOrderInfo(list);
if (!CollectionUtils.isEmpty(list)) { if (!CollectionUtils.isEmpty(list)) {
final OrderInfo orderInfo = list.get(0); final OrderInfo orderInfo = list.get(0);
final int i = orderInfo.getDateTime().compareTo(DateUtil.today()); final int i = orderInfo.getDateTime().compareTo(DateUtil.today());
} }
// 订单商品
final List<OrderGoods> orderGoods = orderGoodsService.list(new LambdaQueryWrapper<OrderGoods>().eq(OrderGoods::getOrderId, orderId));
order.setGoodsList(orderGoods);
// 生成订单核销码 // 生成订单核销码
// requestUtil.setTenantId(order.getTenantId().toString()); // requestUtil.setTenantId(order.getTenantId().toString());
// order.setQrcode(requestUtil.getOrderQRCodeUnlimited(order.getOrderNo())); // order.setQrcode(requestUtil.getOrderQRCodeUnlimited(order.getOrderNo()));
@@ -260,78 +265,48 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
@Override @Override
@Transactional(rollbackFor = {Exception.class}) @Transactional(rollbackFor = {Exception.class})
public Boolean payByBalance(Order order) { public Boolean payByBalance(Order order) {
final Users users = usersService.getByPhone(order.getPhone()); final User loginUser = order.getLoginUser();
if (users.getMoney().compareTo(order.getTotalPrice()) < 0) {
if (loginUser.getBalance().compareTo(order.getTotalPrice()) < 0) {
throw new BusinessException("余额不足"); throw new BusinessException("余额不足");
} }
// 发放积分
usersService.addIntegral(order); // 发起网络请求(更新余额接口)
final RequestUtil requestUtil = new RequestUtil();
requestUtil.setAccessToken(order.getAccessToken());
requestUtil.setTenantId(order.getTenantId().toString());
String api = "/system/user/updateUserBalance"; // 更新余额接口
final BigDecimal subtract = loginUser.getBalance().subtract(order.getTotalPrice());
loginUser.setBalance(subtract);
// 累加会员积分
String key = "SiteInfo:" + order.getTenantId();
final String siteInfo = redisUtil.get(key);
// 从缓存读取信息
if (StrUtil.isNotBlank(siteInfo)) {
final Website website = JSONObject.parseObject(siteInfo, Website.class);
final List<WebsiteField> fields = website.getFields();
if (!CollectionUtils.isEmpty(fields)) {
fields.forEach(d -> {
if (d.getName().equals("integral_enabled") && d.getValue().equals("1")) {
loginUser.setPoints(loginUser.getPoints() + order.getPayPrice().intValue());
}
});
}
}
final ApiResult<?> apiResult = requestUtil.updateUserBalance(api, loginUser);
if (apiResult.getCode().equals(0)) {
// 修改订单状态 // 修改订单状态
order.setPayStatus(1); order.setPayStatus(1);
order.setPayTime(DateUtil.date()); order.setPayTime(DateUtil.date());
order.setExpirationTime(DateUtil.offset(DateUtil.date(), DateField.YEAR, 10)); order.setExpirationTime(DateUtil.offset(DateUtil.date(), DateField.YEAR, 10));
orderService.updateById(order); orderService.updateById(order);
orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId, order.getOrderId()).set(OrderInfo::getPayStatus, 1)); orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId, order.getOrderId()).set(OrderInfo::getPayStatus, 1));
// 更新会员卡状态 // 发放积分
if (order.getType().equals(2)) { usersService.addIntegral(order);
final UserCard userCard = userCardService.getById(order.getCardId()); return true;
userCard.setStatus(1); }
userCardService.updateById(userCard);
}
return true; return true;
// 发起网络请求(更新余额接口)
// final RequestUtil requestUtil = new RequestUtil();
// requestUtil.setAccessToken(order.getAccessToken());
// requestUtil.setTenantId(order.getTenantId().toString());
// String api = "/system/user/updateUserBalance"; // 更新余额接口
// final BigDecimal subtract = loginUser.getMoney().subtract(order.getTotalPrice());
//
// loginUser.setBalance(subtract);
// 累加会员积分
// String key = "SiteInfo:" + order.getTenantId();
// final String siteInfo = redisUtil.get(key);
// 从缓存读取信息
// if(StrUtil.isNotBlank(siteInfo)){
// final Website website = JSONObject.parseObject(siteInfo, Website.class);
// final List<WebsiteField> fields = website.getFields();
// fields.forEach(d -> {
// if(d.getName().equals("integral_enabled") && d.getValue().equals("1")){
// loginUser.setPoints(loginUser.getPoints() + order.getPayPrice().intValue());
// }
// });
// }
// final ApiResult<?> apiResult = requestUtil.updateUserBalance(api, loginUser);
// if (apiResult.getCode().equals(0)) {
// // 记录余额明细
// final UserBalanceLog balanceLog = new UserBalanceLog();
// balanceLog.setUserId(order.getUserId());
// balanceLog.setScene(20);
// balanceLog.setOrderNo(order.getOrderNo());
// balanceLog.setMoney(order.getPayPrice());
// balanceLog.setBalance(subtract);
// balanceLog.setRemark(order.getComments());
// balanceLog.setMerchantId(order.getMerchantId());
// userBalanceLogService.save(balanceLog);
// // 修改订单状态
// order.setPayStatus(1);
// order.setPayTime(DateUtil.date());
// order.setExpirationTime(DateUtil.offset(DateUtil.date(), DateField.YEAR, 10));
// orderService.updateById(order);
// orderInfoService.update(new LambdaUpdateWrapper<OrderInfo>().eq(OrderInfo::getOrderId,order.getOrderId()).set(OrderInfo::getPayStatus,1));
// // 更新会员卡状态
// if(order.getType().equals(2)){
// final UserCard userCard = userCardService.getById(order.getCardId());
// userCard.setPayStatus(1);
// userCardService.updateById(userCard);
// }
// // 发放积分
// usersService.addIntegral(order);
// return true;
// }
// return true;
} }