调整商城随机获取推荐;模板商品生成课卡;修订商品最高与最低消费
This commit is contained in:
parent
ca60e849b7
commit
921a09c428
@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
import java.sql.Date;
|
||||
import java.time.LocalDate;
|
||||
|
||||
/**
|
||||
* 果酱-课卡模板 实体类。
|
||||
@ -47,7 +48,7 @@ public class CardTemplate extends BaseEntity implements Serializable {
|
||||
/**
|
||||
* 云校区id
|
||||
*/
|
||||
private String cloudCampusId;
|
||||
private String cloudStoreId;
|
||||
|
||||
/**
|
||||
* 是否使用(0否1是)
|
||||
@ -67,12 +68,12 @@ public class CardTemplate extends BaseEntity implements Serializable {
|
||||
/**
|
||||
* 开始日期
|
||||
*/
|
||||
private Date startDate;
|
||||
private LocalDate startDate;
|
||||
|
||||
/**
|
||||
* 结束日期
|
||||
*/
|
||||
private Date endDate;
|
||||
private LocalDate endDate;
|
||||
|
||||
/**
|
||||
* 价格
|
||||
@ -124,6 +125,12 @@ public class CardTemplate extends BaseEntity implements Serializable {
|
||||
*/
|
||||
private Boolean isMember;
|
||||
|
||||
/**
|
||||
* 模板类型(0:课时卡,1:时限卡,2:储值卡)
|
||||
*/
|
||||
@Column(ignore = true)
|
||||
private String oldTemplateType;
|
||||
|
||||
/**
|
||||
* 逻辑删除(0否1是)
|
||||
*/
|
||||
|
||||
@ -14,4 +14,13 @@ import java.util.List;
|
||||
*/
|
||||
public interface CardTemplateService extends IService<CardTemplate> {
|
||||
|
||||
/**
|
||||
* @descriptions 旧品牌信息
|
||||
* @author DB
|
||||
* @date 2023/11/13 12:39
|
||||
* @param oldTemplateId 旧模板id
|
||||
* @param brandId 品牌id
|
||||
* @return: com.cpop.jambox.business.entity.CardTemplate
|
||||
*/
|
||||
CardTemplate getOldTemplateInfo(String oldTemplateId, String brandId);
|
||||
}
|
||||
|
||||
@ -1,14 +1,23 @@
|
||||
package com.cpop.jambox.business.service.impl;
|
||||
|
||||
import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.jambox.business.entity.BrandExtend;
|
||||
import com.cpop.jambox.business.entity.CardTemplate;
|
||||
import com.cpop.jambox.business.mapper.CardTemplateMapper;
|
||||
import com.cpop.jambox.business.service.BrandExtendService;
|
||||
import com.cpop.jambox.business.service.CardTemplateService;
|
||||
import com.mybatisflex.core.datasource.DataSourceKey;
|
||||
import com.mybatisflex.core.query.QueryWrapper;
|
||||
import com.mybatisflex.core.row.Db;
|
||||
import com.mybatisflex.core.row.Row;
|
||||
import com.mybatisflex.core.row.RowUtil;
|
||||
import com.mybatisflex.spring.service.impl.ServiceImpl;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND;
|
||||
import static com.cpop.jambox.business.entity.table.CardTemplateTableDef.CARD_TEMPLATE;
|
||||
|
||||
/**
|
||||
@ -20,4 +29,33 @@ import static com.cpop.jambox.business.entity.table.CardTemplateTableDef.CARD_TE
|
||||
@Service("cardTemplateService")
|
||||
public class CardTemplateServiceImpl extends ServiceImpl<CardTemplateMapper, CardTemplate> implements CardTemplateService {
|
||||
|
||||
/**
|
||||
* @descriptions 获取模板信息
|
||||
* @author DB
|
||||
* @date 2023/11/13 12:00
|
||||
* @param oldTemplateId 旧模板id
|
||||
* @param brandId 品牌id
|
||||
* @return: com.cpop.jambox.business.entity.CardTemplate
|
||||
*/
|
||||
@Override
|
||||
public CardTemplate getOldTemplateInfo(String oldTemplateId, String brandId) {
|
||||
//查询模板信息
|
||||
CardTemplate cardTemplate;
|
||||
try {
|
||||
DataSourceKey.use("jambox");
|
||||
Row row = Db.selectOneByQuery("t_card_template", QueryWrapper.create()
|
||||
.select("template_id AS oldTemplateId", "store_id AS cloudStoreId", "open_status AS status", "name", "day AS validDay",
|
||||
"start AS startDate", "end AS endDate", "price", "number AS classNumber", "week_appointment", "day_appointment",
|
||||
"time_limit AS oldTemplateType", "type AS scopeUse", "pay_type", "template_qr_code AS qrCode", "is_member")
|
||||
.from("t_card_template")
|
||||
.where("template_id = ?", oldTemplateId));
|
||||
cardTemplate = RowUtil.toEntity(row, CardTemplate.class);
|
||||
} finally {
|
||||
DataSourceKey.clear();
|
||||
}
|
||||
//获取云品牌信息
|
||||
BrandExtend brandExtend = SpringUtils.getBean(BrandExtendService.class).getOne(QueryWrapper.create().where(BRAND_EXTEND.BRAND_ID.eq(brandId)));
|
||||
cardTemplate.setCloudBrandId(brandExtend.getBrandCloudId());
|
||||
return cardTemplate;
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,11 +13,11 @@ import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.security.core.parameters.P;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Date;
|
||||
import java.time.LocalDate;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
/**
|
||||
* @author DB
|
||||
@ -35,8 +35,6 @@ public class CardTemplateAsyncTask {
|
||||
try {
|
||||
//查询课卡信息
|
||||
CardTemplate cardTemplate = SpringUtils.getBean(CardTemplateService.class).getById(cardTemplateId);
|
||||
//课卡名称
|
||||
jsonBody.put("periodName", cardTemplate.getName());
|
||||
//时限卡
|
||||
if (cardTemplate.getTemplateType().equals(1)) {
|
||||
jsonBody.put("moneyCard", true);
|
||||
@ -52,34 +50,33 @@ public class CardTemplateAsyncTask {
|
||||
jsonBody.put("timeLimit", false);
|
||||
// 课时卡课时数
|
||||
jsonBody.put("periodNumber", cardTemplate.getClassNumber());
|
||||
// 课卡到期时间
|
||||
if (null != cardTemplate.getDayAppointment()){
|
||||
// 日最大约课次数
|
||||
jsonBody.put("maxFrequency", cardTemplate.getDayAppointment());
|
||||
}
|
||||
if (StringUtils.isNotBlank(cardTemplate.getName())){
|
||||
// 课卡名称
|
||||
jsonBody.put("periodName", cardTemplate.getName());
|
||||
}
|
||||
if (null != cardTemplate.getWeekAppointment()){
|
||||
// 周最大约课次数
|
||||
jsonBody.put("maxWeekFrequency", cardTemplate.getWeekAppointment());
|
||||
}
|
||||
// 首次上课开始计有效期
|
||||
if (null != cardTemplate.getBufferDay()){
|
||||
// 最大停卡次数
|
||||
jsonBody.put("maxStopTime", cardTemplate.getBufferDay());
|
||||
}
|
||||
}
|
||||
// 课卡到期时间
|
||||
if (null != cardTemplate.getDayAppointment()){
|
||||
// 日最大约课次数
|
||||
jsonBody.put("maxFrequency", cardTemplate.getDayAppointment());
|
||||
}
|
||||
if (StringUtils.isNotBlank(cardTemplate.getName())){
|
||||
// 课卡名称
|
||||
jsonBody.put("periodName", cardTemplate.getName());
|
||||
}
|
||||
if (null != cardTemplate.getWeekAppointment()){
|
||||
// 周最大约课次数
|
||||
jsonBody.put("maxWeekFrequency", cardTemplate.getWeekAppointment());
|
||||
}
|
||||
// 首次上课开始计有效期
|
||||
if (null != cardTemplate.getBufferDay()){
|
||||
// 最大停卡次数
|
||||
jsonBody.put("maxStopTime", cardTemplate.getBufferDay());
|
||||
}
|
||||
//课卡有效期
|
||||
String periodExpire;
|
||||
if (null != cardTemplate.getValidDay() && cardTemplate.getValidDay() > 0) {
|
||||
//减一天
|
||||
Date date = DateUtils.addDateDays(new Date(), cardTemplate.getValidDay() - 1);
|
||||
periodExpire = DateUtils.dateTime(date);
|
||||
LocalDate localDate = LocalDate.now().plusDays(cardTemplate.getValidDay() - 1);
|
||||
periodExpire = localDate.format(DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD));
|
||||
} else {
|
||||
//TODO:可能需要调整
|
||||
periodExpire = DateUtils.parseDateToStr("yyyy-MM-dd", cardTemplate.getEndDate());
|
||||
periodExpire = cardTemplate.getEndDate().format(DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD));
|
||||
}
|
||||
jsonBody.put("periodExpire", periodExpire);
|
||||
//获取课卡信息
|
||||
|
||||
@ -107,6 +107,10 @@ logging:
|
||||
level:
|
||||
com.github.binarywang.wxpay: debug
|
||||
|
||||
#商城相关配置文件
|
||||
mall:
|
||||
cloudBaseUrl: https://test.cpopsz.com/test/ass/
|
||||
|
||||
#微信支付
|
||||
wx:
|
||||
pay:
|
||||
|
||||
@ -72,6 +72,10 @@ logging:
|
||||
level:
|
||||
com.github.binarywang.wxpay: error
|
||||
|
||||
#商城相关配置文件
|
||||
mall:
|
||||
cloudBaseUrl: https://api.jamboxsys.com/jambox/ass/
|
||||
|
||||
#微信支付
|
||||
wx:
|
||||
pay:
|
||||
|
||||
@ -102,6 +102,10 @@ logging:
|
||||
level:
|
||||
com.github.binarywang.wxpay: debug
|
||||
|
||||
#商城相关配置文件
|
||||
mall:
|
||||
cloudBaseUrl: https://test.cpopsz.com/test/ass/
|
||||
|
||||
#微信支付
|
||||
wx:
|
||||
pay:
|
||||
|
||||
@ -95,17 +95,21 @@ public class ProductBo implements Serializable {
|
||||
@ApiModelProperty("限制数量")
|
||||
private Integer limitNum;
|
||||
|
||||
/**
|
||||
* 旧课卡模板id
|
||||
*/
|
||||
@ApiModelProperty("旧课卡模板id")
|
||||
private String cardTemplateId;
|
||||
|
||||
/**
|
||||
* 规格集合
|
||||
*/
|
||||
@NotEmpty(message = "规格详情不能为空")
|
||||
@ApiModelProperty(value = "规格集合",required = true)
|
||||
private List<ProductSpecificationBo> specificationList;
|
||||
|
||||
/**
|
||||
* 规格详情
|
||||
*/
|
||||
@NotEmpty(message = "规格详情不能为空")
|
||||
@ApiModelProperty(value = "规格详情",required = true)
|
||||
private List<ProductRecordBo> recordList;
|
||||
}
|
||||
|
||||
@ -49,10 +49,4 @@ public class ProductRecordBo implements Serializable {
|
||||
*/
|
||||
@ApiModelProperty("记录消耗积分")
|
||||
private Integer recordPoints;
|
||||
|
||||
/**
|
||||
* 乐观锁标记
|
||||
*/
|
||||
@ApiModelProperty("乐观锁标记")
|
||||
private Integer version;
|
||||
}
|
||||
|
||||
@ -46,6 +46,21 @@ public class MiniProductController {
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 查询商城同类型随机商品
|
||||
* @author DB
|
||||
* @date 2023/11/13 16:24
|
||||
* @param productType 商品类型
|
||||
* @param id id
|
||||
* @return: com.cpop.core.base.R<com.mybatisflex.core.paginate.Page<com.cpop.mall.business.vo.MiniProductPageVo>>
|
||||
*/
|
||||
@GetMapping("/getSameTypeRandomProduct")
|
||||
@ApiOperation("查询商城同类型随机商品")
|
||||
public R<Page<MiniProductPageVo>> getSameTypeRandomProduct(@RequestParam("productType") @ApiParam(value = "商品类型", required = true) Integer productType, @RequestParam("id") @ApiParam(value = "商品id", required = true) String id) {
|
||||
Page<MiniProductPageVo> page = productService.getSameTypeRandomProduct(id, productType);
|
||||
return R.ok(page);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 下单需要选择店铺/校区
|
||||
* @author DB
|
||||
|
||||
@ -96,14 +96,14 @@ public class Product extends BaseEntity implements Serializable {
|
||||
private Boolean isTop;
|
||||
|
||||
/**
|
||||
* 最高价
|
||||
* 最高价/最高消耗积分 消费
|
||||
*/
|
||||
private BigDecimal maxPrice;
|
||||
private BigDecimal maxConsume;
|
||||
|
||||
/**
|
||||
* 最低价
|
||||
* 最低价/最低消耗积分
|
||||
*/
|
||||
private BigDecimal minPrice;
|
||||
private BigDecimal minConsume;
|
||||
|
||||
/**
|
||||
* 课卡模板id
|
||||
|
||||
@ -105,4 +105,14 @@ public interface ProductService extends IService<Product> {
|
||||
* @return: com.cpop.mall.business.vo.ProductInfoVo
|
||||
*/
|
||||
ProductInfoVo getProductInfo(String id);
|
||||
|
||||
/**
|
||||
* @descriptions 查询商城同类型随机商品
|
||||
* @author DB
|
||||
* @date 2023/11/13 16:24
|
||||
* @param id 主键
|
||||
* @param productType 商品类型
|
||||
* @return: com.mybatisflex.core.paginate.Page<com.cpop.mall.business.vo.MiniProductPageVo>
|
||||
*/
|
||||
Page<MiniProductPageVo> getSameTypeRandomProduct(String id, Integer productType);
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
//获取涉及到的商品
|
||||
ProductService productService = SpringUtils.getBean(ProductService.class);
|
||||
List<Product> productList = productService.queryChain()
|
||||
.select(PRODUCT.ID, PRODUCT.PRODUCT_NAME, PRODUCT.DESCRIPTION)
|
||||
.select(PRODUCT.ID, PRODUCT.PRODUCT_NAME, PRODUCT.DESCRIPTION, PRODUCT.PRODUCT_TYPE, PRODUCT.CARD_TEMPLATE_ID)
|
||||
.from(PRODUCT)
|
||||
.leftJoin(PRODUCT_RECORD).on(PRODUCT_RECORD.PRODUCT_ID.eq(PRODUCT.ID))
|
||||
.where(PRODUCT_RECORD.ID.in(orderDetails.stream().map(OrderDetail::getProductRecordId).collect(Collectors.toSet())))
|
||||
@ -326,9 +326,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
|
||||
QuartzEnums.ORDER_OVERTIME_UN_PAY_TASK.getGroup());
|
||||
}
|
||||
//更新订单
|
||||
this.updateChain().set(ORDER.RECEIVE_PHONE,bo.getReceivePhone())
|
||||
.set(ORDER.RECEIVE_ADDRESS,bo.getReceiveAddress())
|
||||
.set(ORDER.RECEIVE_NAME,bo.getReceiveName())
|
||||
this.updateChain().set(ORDER.RECEIVE_PHONE, bo.getReceivePhone())
|
||||
.set(ORDER.RECEIVE_ADDRESS, bo.getReceiveAddress())
|
||||
.set(ORDER.RECEIVE_NAME, bo.getReceiveName())
|
||||
.where(ORDER.ID.eq(bo.getId()))
|
||||
.update();
|
||||
//异步处理订单详情
|
||||
|
||||
@ -10,7 +10,9 @@ import com.cpop.core.utils.SecurityUtils;
|
||||
import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.core.utils.sql.SqlUtils;
|
||||
import com.cpop.jambox.business.entity.BrandExtend;
|
||||
import com.cpop.jambox.business.entity.CardTemplate;
|
||||
import com.cpop.jambox.business.service.BrandExtendService;
|
||||
import com.cpop.jambox.business.service.CardTemplateService;
|
||||
import com.cpop.mall.business.bo.ProductBo;
|
||||
import com.cpop.mall.business.bo.ProductPageBo;
|
||||
import com.cpop.mall.business.bo.ProductRecordBo;
|
||||
@ -42,6 +44,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND;
|
||||
import static com.cpop.jambox.business.entity.table.CardTemplateTableDef.CARD_TEMPLATE;
|
||||
import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EXTEND;
|
||||
import static com.cpop.mall.business.entity.table.OrderDetailTableDef.ORDER_DETAIL;
|
||||
import static com.cpop.mall.business.entity.table.OrderEvaluateTableDef.ORDER_EVALUATE;
|
||||
@ -51,8 +54,7 @@ import static com.cpop.mall.business.entity.table.ProductSpecificationTableDef.P
|
||||
import static com.cpop.mall.business.entity.table.ProductTableDef.PRODUCT;
|
||||
import static com.cpop.system.business.entity.table.BrandTableDef.BRAND;
|
||||
import static com.cpop.system.business.entity.table.StoreTableDef.STORE;
|
||||
import static com.mybatisflex.core.query.QueryMethods.groupConcat;
|
||||
import static com.mybatisflex.core.query.QueryMethods.sum;
|
||||
import static com.mybatisflex.core.query.QueryMethods.*;
|
||||
|
||||
/**
|
||||
* 商城-商品表 服务层实现。
|
||||
@ -79,9 +81,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
//价格排序
|
||||
if (null != bo.getPriceOrder()){
|
||||
if (bo.getPriceOrder()) {
|
||||
queryWrapper.orderBy(PRODUCT.MAX_PRICE.desc());
|
||||
queryWrapper.orderBy(PRODUCT.MAX_CONSUME.desc());
|
||||
} else {
|
||||
queryWrapper.orderBy(PRODUCT.MIN_PRICE.asc());
|
||||
queryWrapper.orderBy(PRODUCT.MIN_CONSUME.asc());
|
||||
}
|
||||
}
|
||||
return this.mapper.paginateWithRelationsAs(Page.of(pageDomain.getPageNum(), pageDomain.getPageSize()),
|
||||
@ -134,9 +136,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
//价格排序
|
||||
if (null != bo.getPriceOrder()){
|
||||
if (bo.getPriceOrder()) {
|
||||
queryWrapper.orderBy(PRODUCT.MIN_PRICE.desc());
|
||||
queryWrapper.orderBy(PRODUCT.MAX_CONSUME.desc());
|
||||
} else {
|
||||
queryWrapper.orderBy(PRODUCT.MIN_PRICE.asc());
|
||||
queryWrapper.orderBy(PRODUCT.MIN_CONSUME.asc());
|
||||
}
|
||||
}
|
||||
if (null != bo.getProductType()){
|
||||
@ -206,24 +208,56 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginUserInfo();
|
||||
product.setBrandId(loginStaffInfo.getString("brandId"));
|
||||
}
|
||||
//计算最高最低价
|
||||
BigDecimal maxPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).max(Comparator.comparing(x -> x)).orElse(null);
|
||||
BigDecimal minPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).min(Comparator.comparing(x -> x)).orElse(null);
|
||||
product.setMaxPrice(maxPrice).setMinPrice(minPrice);
|
||||
this.save(product);
|
||||
//保存规格
|
||||
//规格
|
||||
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class);
|
||||
List<ProductSpecification> productSpecifications = BeanUtils.mapToList(bo.getSpecificationList(), ProductSpecification.class);
|
||||
List<ProductSpecification> productSpecifications;
|
||||
//记录
|
||||
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
|
||||
//保存商品记录
|
||||
List<ProductRecord> recordList;
|
||||
//判断当前传入的是否是课卡
|
||||
if (bo.getProductType() == 0) {
|
||||
//获取模板相关信息
|
||||
CardTemplate oldTemplateInfo = SpringUtils.getBean(CardTemplateService.class).getOldTemplateInfo(bo.getCardTemplateId(), product.getBrandId());
|
||||
product.setMaxConsume(oldTemplateInfo.getPrice()).setMinConsume(oldTemplateInfo.getPrice());
|
||||
this.save(product);
|
||||
//课卡模板获取固定规格
|
||||
ProductSpecification productSpecification = new ProductSpecification();
|
||||
productSpecification.setSpecificationNames(oldTemplateInfo.getName());
|
||||
productSpecifications = new ArrayList<ProductSpecification>();
|
||||
productSpecifications.add(productSpecification);
|
||||
//记录
|
||||
recordList = new ArrayList<ProductRecord>();
|
||||
ProductRecord productRecord = new ProductRecord();
|
||||
productRecord.setRecordNum(2147483647).setRecordNames(productSpecification.getSpecificationNames()).setRecordPrice(oldTemplateInfo.getPrice()).setRecordPoints(0);
|
||||
recordList.add(productRecord);
|
||||
} else {
|
||||
//积分支付
|
||||
if (bo.getPayType() == 1) {
|
||||
//计算最高最低价
|
||||
Integer maxPoint = bo.getRecordList().stream().map(ProductRecordBo::getRecordPoints).max(Comparator.comparing(x -> x)).orElse(0);
|
||||
Integer minPoint = bo.getRecordList().stream().map(ProductRecordBo::getRecordPoints).min(Comparator.comparing(x -> x)).orElse(0);
|
||||
product.setMaxConsume(BigDecimal.valueOf(maxPoint)).setMinConsume(BigDecimal.valueOf(minPoint));
|
||||
} else {
|
||||
//计算最高最低价
|
||||
BigDecimal maxPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).max(Comparator.comparing(x -> x)).orElse(null);
|
||||
BigDecimal minPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).min(Comparator.comparing(x -> x)).orElse(null);
|
||||
product.setMaxConsume(maxPrice).setMinConsume(minPrice);
|
||||
}
|
||||
this.save(product);
|
||||
productSpecifications = BeanUtils.mapToList(bo.getSpecificationList(), ProductSpecification.class);
|
||||
//保存商品记录
|
||||
recordList = BeanUtils.mapToList(bo.getRecordList(), ProductRecord.class);
|
||||
}
|
||||
productSpecifications.forEach(item -> {
|
||||
item.setProductId(product.getId());
|
||||
});
|
||||
//保存规格
|
||||
productSpecificationService.saveBatch(productSpecifications);
|
||||
//保存商品记录
|
||||
List<ProductRecord> recordList = BeanUtils.mapToList(bo.getRecordList(), ProductRecord.class);
|
||||
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
|
||||
recordList.forEach(item -> {
|
||||
item.setProductId(product.getId());
|
||||
});
|
||||
//保存记录
|
||||
specificationRecordService.saveBatch(recordList);
|
||||
}
|
||||
|
||||
@ -238,10 +272,18 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public void updateProduct(ProductBo bo) {
|
||||
Product product = BeanUtils.mapToClass(bo, Product.class);
|
||||
//计算最高最低价
|
||||
BigDecimal maxPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).max(Comparator.comparing(x -> x)).orElse(null);
|
||||
BigDecimal minPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).min(Comparator.comparing(x -> x)).orElse(null);
|
||||
product.setMaxPrice(maxPrice).setMinPrice(minPrice);
|
||||
//积分支付
|
||||
if (bo.getPayType() == 1) {
|
||||
//计算最高最低价
|
||||
Integer maxPoint = bo.getRecordList().stream().map(ProductRecordBo::getRecordPoints).max(Comparator.comparing(x -> x)).orElse(0);
|
||||
Integer minPoint = bo.getRecordList().stream().map(ProductRecordBo::getRecordPoints).min(Comparator.comparing(x -> x)).orElse(0);
|
||||
product.setMaxConsume(BigDecimal.valueOf(maxPoint)).setMinConsume(BigDecimal.valueOf(minPoint));
|
||||
} else {
|
||||
//计算最高最低价
|
||||
BigDecimal maxPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).max(Comparator.comparing(x -> x)).orElse(null);
|
||||
BigDecimal minPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).min(Comparator.comparing(x -> x)).orElse(null);
|
||||
product.setMaxConsume(maxPrice).setMinConsume(minPrice);
|
||||
}
|
||||
this.updateById(product);
|
||||
//保存规格
|
||||
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class);
|
||||
@ -301,11 +343,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
try {
|
||||
DataSourceKey.use("jambox");
|
||||
rowList = Db.selectListByQuery("t_card_template", QueryWrapper.create()
|
||||
.select("tct.template_id AS id,tct.brand_id,tct.name")
|
||||
.select("tct.template_id AS id", "tct.brand_id", "tct.name")
|
||||
.from("t_card_template").as("tct")
|
||||
.leftJoin("t_brand_info").as("tbi").on("tbi.id = tct.brand_id")
|
||||
.where("tbi.brand_id = ?", brandExtend.getBrandCloudId())
|
||||
.or("tct.brand_id = ?", brandExtend.getBrandCloudId()));
|
||||
.or("tct.brand_id = ?", brandExtend.getBrandCloudId())
|
||||
//未被删除的模板
|
||||
.and("tct.deleted = 1")
|
||||
.orderBy("tct.creation_time", false));
|
||||
cardTemplateListVos = RowUtil.toEntityList(rowList, JamboxCardTemplateListVo.class);
|
||||
} finally {
|
||||
DataSourceKey.clear();
|
||||
@ -401,4 +446,26 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
|
||||
public ProductInfoVo getProductInfo(String id) {
|
||||
return this.mapper.selectOneWithRelationsByIdAs(id, ProductInfoVo.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* @descriptions 查询商城同类型随机商品
|
||||
* @author DB
|
||||
* @date 2023/11/13 16:24
|
||||
* @param id 主键
|
||||
* @param productType 商品类型
|
||||
* @return: com.mybatisflex.core.paginate.Page<com.cpop.mall.business.vo.MiniProductPageVo>
|
||||
*/
|
||||
@Override
|
||||
public Page<MiniProductPageVo> getSameTypeRandomProduct(String id, Integer productType) {
|
||||
//获取当前用户品牌
|
||||
JSONObject loginUserInfo = SecurityUtils.getInstance().getLoginUserInfo();
|
||||
PageDomain pageDomain = SqlUtils.getInstance().getPageDomain();
|
||||
return this.mapper.paginateWithRelationsAs(pageDomain.getPageNum(), pageDomain.getPageSize(),
|
||||
QueryWrapper.create().select()
|
||||
.where(PRODUCT.BRAND_ID.eq(loginUserInfo.getString("brandId")))
|
||||
.and(PRODUCT.PRODUCT_TYPE.eq(productType))
|
||||
.and("id >= (((SELECT MAX(id) FROM cp_mall_product)-(SELECT MIN(id) FROM cp_mall_product)) * RAND() + (SELECT MIN(id) FROM cp_mall_product))")
|
||||
.and(PRODUCT.IS_UP.eq(true)),
|
||||
MiniProductPageVo.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,12 +1,11 @@
|
||||
package com.cpop.mall.business.task;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cpop.common.utils.DateUtils;
|
||||
import com.cpop.core.base.enums.OrderSource;
|
||||
import com.cpop.core.base.exception.ServiceException;
|
||||
import com.cpop.core.utils.SpringUtils;
|
||||
import com.cpop.jambox.business.entity.StoreExtend;
|
||||
import com.cpop.jambox.business.service.CardTemplateService;
|
||||
import com.cpop.jambox.business.service.StoreExtendService;
|
||||
import com.cpop.jambox.business.task.CardTemplateAsyncTask;
|
||||
import com.cpop.jambox.framework.constant.JamboxCloudUrl;
|
||||
import com.cpop.mall.business.entity.Order;
|
||||
import com.cpop.mall.business.entity.OrderDetail;
|
||||
@ -14,10 +13,11 @@ import com.cpop.mall.business.entity.Product;
|
||||
import com.cpop.mall.business.entity.ProductRecord;
|
||||
import com.cpop.mall.business.service.ProductRecordService;
|
||||
import okhttp3.*;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Date;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
@ -31,6 +31,23 @@ import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EX
|
||||
*/
|
||||
@Component
|
||||
public class OrderDetailAsyncTask {
|
||||
|
||||
/**
|
||||
* 云地址
|
||||
*/
|
||||
@Value("${mall.cloudBaseUrl}")
|
||||
private String cloudBaseUrl;
|
||||
|
||||
/**
|
||||
* @descriptions 订单详情异步任务
|
||||
* @author DB
|
||||
* @date 2023/11/13 15:37
|
||||
* @param order 订单
|
||||
* @param loginUserInfo 用户详情
|
||||
* @param orderDetails 订单详情
|
||||
* @param productList 商品列表
|
||||
* @return: void
|
||||
*/
|
||||
@Async("customAsyncThreadPool")
|
||||
public void asyncProcessingOrderDetails(Order order, JSONObject loginUserInfo, List<OrderDetail> orderDetails, List<Product> productList) {
|
||||
Map<String, Product> productMap = productList.stream().collect(Collectors.toMap(Product::getId, item -> item));
|
||||
@ -44,27 +61,42 @@ public class OrderDetailAsyncTask {
|
||||
orderDetails.forEach(item -> {
|
||||
//获取当前订单记录的商品信息
|
||||
ProductRecord productRecord = productRecordMap.get(item.getProductRecordId());
|
||||
Product product = productMap.get(productRecord.getId());
|
||||
Product product = productMap.get(productRecord.getProductId());
|
||||
//课卡
|
||||
if (product.getProductType() == 0) {
|
||||
//课卡信息
|
||||
JSONObject jsonBody = new JSONObject();
|
||||
jsonBody.put("_type", "addPeriod");
|
||||
//订单id
|
||||
jsonBody.put("classCardId", order.getId());
|
||||
jsonBody.put("mallOrderId", order.getId());
|
||||
//办卡实收金额
|
||||
jsonBody.put("money", order.getTotalAmount());
|
||||
jsonBody.put("money", productRecord.getRecordPrice());
|
||||
//店铺/校区
|
||||
jsonBody.put("storeId", storeCloudMap.get(item.getStoreId()));
|
||||
//手机号
|
||||
jsonBody.put("phone", loginUserInfo.getString("phoneNumber"));
|
||||
//客户名称
|
||||
jsonBody.put("customerName", loginUserInfo.getString("nickName"));
|
||||
//客户性别
|
||||
jsonBody.put("customerSex", loginUserInfo.getBoolean("sex") ? "女" : "男");
|
||||
//客户地址
|
||||
jsonBody.put("customerAddress", order.getReceiveAddress());
|
||||
SpringUtils.getBean(CardTemplateAsyncTask.class).cloudCreateCard(jsonBody, product.getCardTemplateId());
|
||||
//模板id
|
||||
jsonBody.put("templateId", product.getCardTemplateId());
|
||||
//订单来源
|
||||
jsonBody.put("orderSource", OrderSource.MALL.toString());
|
||||
//模板对应实际地址
|
||||
jsonBody.put("templateUrl", cloudBaseUrl);
|
||||
//获取课卡信息
|
||||
OkHttpClient client = new OkHttpClient().newBuilder().build();
|
||||
MediaType mediaType = MediaType.parse("application/json");
|
||||
RequestBody body = RequestBody.create(mediaType, jsonBody.toJSONString());
|
||||
Request request = new Request.Builder()
|
||||
.url(JamboxCloudUrl.COMMON_CARD_URL)
|
||||
.method("POST", body)
|
||||
.addHeader("Content-Type", "application/json")
|
||||
.build();
|
||||
try {
|
||||
client.newCall(request).execute();
|
||||
} catch (IOException e) {
|
||||
throw new ServiceException(e.getMessage());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ public class ProductRecordSyncStockTask {
|
||||
while (iterator.hasNext()) {
|
||||
Map.Entry<String, Integer> next = iterator.next();
|
||||
boolean update = productRecordService.updateChain()
|
||||
.setRaw(PRODUCT_RECORD.RECORD_NUM, "record_num +" + next.getValue())
|
||||
.setRaw(PRODUCT_RECORD.RECORD_NUM, "record_num -" + next.getValue())
|
||||
.where(PRODUCT_RECORD.ID.eq(next.getKey())).update();
|
||||
//如果更新成功,移除
|
||||
if (update) {
|
||||
|
||||
@ -74,13 +74,13 @@ public class MiniProductPageVo implements Serializable {
|
||||
* 最高价
|
||||
*/
|
||||
@ApiModelProperty("最高价")
|
||||
private BigDecimal maxPrice;
|
||||
private BigDecimal maxConsume;
|
||||
|
||||
/**
|
||||
* 最低价
|
||||
*/
|
||||
@ApiModelProperty("最低价")
|
||||
private BigDecimal minPrice;
|
||||
private BigDecimal minConsume;
|
||||
|
||||
/**
|
||||
* 支付方式(微信支付:0;积分支付:1)
|
||||
|
||||
@ -82,14 +82,14 @@ public class ProductInfoVo implements Serializable {
|
||||
/**
|
||||
* 最高价
|
||||
*/
|
||||
@ApiModelProperty("最高价")
|
||||
private BigDecimal maxPrice;
|
||||
@ApiModelProperty("最高消耗")
|
||||
private BigDecimal maxConsume;
|
||||
|
||||
/**
|
||||
* 最低价
|
||||
*/
|
||||
@ApiModelProperty("最低价")
|
||||
private BigDecimal minPrice;
|
||||
@ApiModelProperty("最低消耗")
|
||||
private BigDecimal minConsume;
|
||||
|
||||
/**
|
||||
* 支付方式(微信支付:0;积分支付:1)
|
||||
|
||||
@ -97,16 +97,16 @@ public class ProductPageVo implements Serializable {
|
||||
private Integer buyRestrict;
|
||||
|
||||
/**
|
||||
* 最高价
|
||||
* 最高消费
|
||||
*/
|
||||
@ApiModelProperty("最高价")
|
||||
private BigDecimal maxPrice;
|
||||
@ApiModelProperty("最高消费")
|
||||
private BigDecimal maxConsume;
|
||||
|
||||
/**
|
||||
* 最低价
|
||||
* 最低消费
|
||||
*/
|
||||
@ApiModelProperty("最低价")
|
||||
private BigDecimal minPrice;
|
||||
@ApiModelProperty("最低消费")
|
||||
private BigDecimal minConsume;
|
||||
|
||||
/**
|
||||
* 限购数量
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user