调整商城随机获取推荐;模板商品生成课卡;修订商品最高与最低消费

This commit is contained in:
DB 2023-11-13 16:55:58 +08:00
parent ca60e849b7
commit 921a09c428
19 changed files with 277 additions and 92 deletions

View File

@ -12,6 +12,7 @@ import lombok.experimental.Accessors;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.sql.Date; import java.sql.Date;
import java.time.LocalDate;
/** /**
* 果酱-课卡模板 实体类 * 果酱-课卡模板 实体类
@ -47,7 +48,7 @@ public class CardTemplate extends BaseEntity implements Serializable {
/** /**
* 云校区id * 云校区id
*/ */
private String cloudCampusId; private String cloudStoreId;
/** /**
* 是否使用(0否1是) * 是否使用(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; private Boolean isMember;
/**
* 模板类型(0:课时卡,1:时限卡,2:储值卡)
*/
@Column(ignore = true)
private String oldTemplateType;
/** /**
* 逻辑删除(0否1是) * 逻辑删除(0否1是)
*/ */

View File

@ -14,4 +14,13 @@ import java.util.List;
*/ */
public interface CardTemplateService extends IService<CardTemplate> { 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);
} }

View File

@ -1,14 +1,23 @@
package com.cpop.jambox.business.service.impl; 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.entity.CardTemplate;
import com.cpop.jambox.business.mapper.CardTemplateMapper; import com.cpop.jambox.business.mapper.CardTemplateMapper;
import com.cpop.jambox.business.service.BrandExtendService;
import com.cpop.jambox.business.service.CardTemplateService; 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 com.mybatisflex.spring.service.impl.ServiceImpl;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.io.File; import java.io.File;
import java.util.List; 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.CardTemplateTableDef.CARD_TEMPLATE;
/** /**
@ -20,4 +29,33 @@ import static com.cpop.jambox.business.entity.table.CardTemplateTableDef.CARD_TE
@Service("cardTemplateService") @Service("cardTemplateService")
public class CardTemplateServiceImpl extends ServiceImpl<CardTemplateMapper, CardTemplate> implements 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;
}
} }

View File

@ -13,11 +13,11 @@ import okhttp3.OkHttpClient;
import okhttp3.Request; import okhttp3.Request;
import okhttp3.RequestBody; import okhttp3.RequestBody;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.security.core.parameters.P;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.IOException; import java.io.IOException;
import java.util.Date; import java.time.LocalDate;
import java.time.format.DateTimeFormatter;
/** /**
* @author DB * @author DB
@ -35,8 +35,6 @@ public class CardTemplateAsyncTask {
try { try {
//查询课卡信息 //查询课卡信息
CardTemplate cardTemplate = SpringUtils.getBean(CardTemplateService.class).getById(cardTemplateId); CardTemplate cardTemplate = SpringUtils.getBean(CardTemplateService.class).getById(cardTemplateId);
//课卡名称
jsonBody.put("periodName", cardTemplate.getName());
//时限卡 //时限卡
if (cardTemplate.getTemplateType().equals(1)) { if (cardTemplate.getTemplateType().equals(1)) {
jsonBody.put("moneyCard", true); jsonBody.put("moneyCard", true);
@ -52,6 +50,7 @@ public class CardTemplateAsyncTask {
jsonBody.put("timeLimit", false); jsonBody.put("timeLimit", false);
// 课时卡课时数 // 课时卡课时数
jsonBody.put("periodNumber", cardTemplate.getClassNumber()); jsonBody.put("periodNumber", cardTemplate.getClassNumber());
}
// 课卡到期时间 // 课卡到期时间
if (null != cardTemplate.getDayAppointment()){ if (null != cardTemplate.getDayAppointment()){
// 日最大约课次数 // 日最大约课次数
@ -70,16 +69,14 @@ public class CardTemplateAsyncTask {
// 最大停卡次数 // 最大停卡次数
jsonBody.put("maxStopTime", cardTemplate.getBufferDay()); jsonBody.put("maxStopTime", cardTemplate.getBufferDay());
} }
}
//课卡有效期 //课卡有效期
String periodExpire; String periodExpire;
if (null != cardTemplate.getValidDay() && cardTemplate.getValidDay() > 0) { if (null != cardTemplate.getValidDay() && cardTemplate.getValidDay() > 0) {
//减一天 //减一天
Date date = DateUtils.addDateDays(new Date(), cardTemplate.getValidDay() - 1); LocalDate localDate = LocalDate.now().plusDays(cardTemplate.getValidDay() - 1);
periodExpire = DateUtils.dateTime(date); periodExpire = localDate.format(DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD));
} else { } else {
//TODO:可能需要调整 periodExpire = cardTemplate.getEndDate().format(DateTimeFormatter.ofPattern(DateUtils.YYYY_MM_DD));
periodExpire = DateUtils.parseDateToStr("yyyy-MM-dd", cardTemplate.getEndDate());
} }
jsonBody.put("periodExpire", periodExpire); jsonBody.put("periodExpire", periodExpire);
//获取课卡信息 //获取课卡信息

View File

@ -107,6 +107,10 @@ logging:
level: level:
com.github.binarywang.wxpay: debug com.github.binarywang.wxpay: debug
#商城相关配置文件
mall:
cloudBaseUrl: https://test.cpopsz.com/test/ass/
#微信支付 #微信支付
wx: wx:
pay: pay:

View File

@ -72,6 +72,10 @@ logging:
level: level:
com.github.binarywang.wxpay: error com.github.binarywang.wxpay: error
#商城相关配置文件
mall:
cloudBaseUrl: https://api.jamboxsys.com/jambox/ass/
#微信支付 #微信支付
wx: wx:
pay: pay:

View File

@ -102,6 +102,10 @@ logging:
level: level:
com.github.binarywang.wxpay: debug com.github.binarywang.wxpay: debug
#商城相关配置文件
mall:
cloudBaseUrl: https://test.cpopsz.com/test/ass/
#微信支付 #微信支付
wx: wx:
pay: pay:

View File

@ -95,17 +95,21 @@ public class ProductBo implements Serializable {
@ApiModelProperty("限制数量") @ApiModelProperty("限制数量")
private Integer limitNum; private Integer limitNum;
/**
* 旧课卡模板id
*/
@ApiModelProperty("旧课卡模板id")
private String cardTemplateId;
/** /**
* 规格集合 * 规格集合
*/ */
@NotEmpty(message = "规格详情不能为空")
@ApiModelProperty(value = "规格集合",required = true) @ApiModelProperty(value = "规格集合",required = true)
private List<ProductSpecificationBo> specificationList; private List<ProductSpecificationBo> specificationList;
/** /**
* 规格详情 * 规格详情
*/ */
@NotEmpty(message = "规格详情不能为空")
@ApiModelProperty(value = "规格详情",required = true) @ApiModelProperty(value = "规格详情",required = true)
private List<ProductRecordBo> recordList; private List<ProductRecordBo> recordList;
} }

View File

@ -49,10 +49,4 @@ public class ProductRecordBo implements Serializable {
*/ */
@ApiModelProperty("记录消耗积分") @ApiModelProperty("记录消耗积分")
private Integer recordPoints; private Integer recordPoints;
/**
* 乐观锁标记
*/
@ApiModelProperty("乐观锁标记")
private Integer version;
} }

View File

@ -46,6 +46,21 @@ public class MiniProductController {
return R.ok(page); 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 下单需要选择店铺/校区 * @descriptions 下单需要选择店铺/校区
* @author DB * @author DB

View File

@ -96,14 +96,14 @@ public class Product extends BaseEntity implements Serializable {
private Boolean isTop; private Boolean isTop;
/** /**
* 最高价 * 最高价/最高消耗积分 消费
*/ */
private BigDecimal maxPrice; private BigDecimal maxConsume;
/** /**
* 最低价 * 最低价/最低消耗积分
*/ */
private BigDecimal minPrice; private BigDecimal minConsume;
/** /**
* 课卡模板id * 课卡模板id

View File

@ -105,4 +105,14 @@ public interface ProductService extends IService<Product> {
* @return: com.cpop.mall.business.vo.ProductInfoVo * @return: com.cpop.mall.business.vo.ProductInfoVo
*/ */
ProductInfoVo getProductInfo(String id); 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);
} }

View File

@ -279,7 +279,7 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements
//获取涉及到的商品 //获取涉及到的商品
ProductService productService = SpringUtils.getBean(ProductService.class); ProductService productService = SpringUtils.getBean(ProductService.class);
List<Product> productList = productService.queryChain() 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) .from(PRODUCT)
.leftJoin(PRODUCT_RECORD).on(PRODUCT_RECORD.PRODUCT_ID.eq(PRODUCT.ID)) .leftJoin(PRODUCT_RECORD).on(PRODUCT_RECORD.PRODUCT_ID.eq(PRODUCT.ID))
.where(PRODUCT_RECORD.ID.in(orderDetails.stream().map(OrderDetail::getProductRecordId).collect(Collectors.toSet()))) .where(PRODUCT_RECORD.ID.in(orderDetails.stream().map(OrderDetail::getProductRecordId).collect(Collectors.toSet())))

View File

@ -10,7 +10,9 @@ import com.cpop.core.utils.SecurityUtils;
import com.cpop.core.utils.SpringUtils; import com.cpop.core.utils.SpringUtils;
import com.cpop.core.utils.sql.SqlUtils; import com.cpop.core.utils.sql.SqlUtils;
import com.cpop.jambox.business.entity.BrandExtend; 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.BrandExtendService;
import com.cpop.jambox.business.service.CardTemplateService;
import com.cpop.mall.business.bo.ProductBo; import com.cpop.mall.business.bo.ProductBo;
import com.cpop.mall.business.bo.ProductPageBo; import com.cpop.mall.business.bo.ProductPageBo;
import com.cpop.mall.business.bo.ProductRecordBo; import com.cpop.mall.business.bo.ProductRecordBo;
@ -42,6 +44,7 @@ import java.util.Comparator;
import java.util.List; import java.util.List;
import static com.cpop.jambox.business.entity.table.BrandExtendTableDef.BRAND_EXTEND; 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.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.OrderDetailTableDef.ORDER_DETAIL;
import static com.cpop.mall.business.entity.table.OrderEvaluateTableDef.ORDER_EVALUATE; 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.mall.business.entity.table.ProductTableDef.PRODUCT;
import static com.cpop.system.business.entity.table.BrandTableDef.BRAND; import static com.cpop.system.business.entity.table.BrandTableDef.BRAND;
import static com.cpop.system.business.entity.table.StoreTableDef.STORE; 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.*;
import static com.mybatisflex.core.query.QueryMethods.sum;
/** /**
* 商城-商品表 服务层实现 * 商城-商品表 服务层实现
@ -79,9 +81,9 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
//价格排序 //价格排序
if (null != bo.getPriceOrder()){ if (null != bo.getPriceOrder()){
if (bo.getPriceOrder()) { if (bo.getPriceOrder()) {
queryWrapper.orderBy(PRODUCT.MAX_PRICE.desc()); queryWrapper.orderBy(PRODUCT.MAX_CONSUME.desc());
} else { } else {
queryWrapper.orderBy(PRODUCT.MIN_PRICE.asc()); queryWrapper.orderBy(PRODUCT.MIN_CONSUME.asc());
} }
} }
return this.mapper.paginateWithRelationsAs(Page.of(pageDomain.getPageNum(), pageDomain.getPageSize()), 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 (null != bo.getPriceOrder()){
if (bo.getPriceOrder()) { if (bo.getPriceOrder()) {
queryWrapper.orderBy(PRODUCT.MIN_PRICE.desc()); queryWrapper.orderBy(PRODUCT.MAX_CONSUME.desc());
} else { } else {
queryWrapper.orderBy(PRODUCT.MIN_PRICE.asc()); queryWrapper.orderBy(PRODUCT.MIN_CONSUME.asc());
} }
} }
if (null != bo.getProductType()){ if (null != bo.getProductType()){
@ -206,24 +208,56 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginUserInfo(); JSONObject loginStaffInfo = SecurityUtils.getInstance().getLoginUserInfo();
product.setBrandId(loginStaffInfo.getString("brandId")); product.setBrandId(loginStaffInfo.getString("brandId"));
} }
//规格
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.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 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); BigDecimal minPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).min(Comparator.comparing(x -> x)).orElse(null);
product.setMaxPrice(maxPrice).setMinPrice(minPrice); product.setMaxConsume(maxPrice).setMinConsume(minPrice);
}
this.save(product); this.save(product);
//保存规格 productSpecifications = BeanUtils.mapToList(bo.getSpecificationList(), ProductSpecification.class);
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class); //保存商品记录
List<ProductSpecification> productSpecifications = BeanUtils.mapToList(bo.getSpecificationList(), ProductSpecification.class); recordList = BeanUtils.mapToList(bo.getRecordList(), ProductRecord.class);
}
productSpecifications.forEach(item -> { productSpecifications.forEach(item -> {
item.setProductId(product.getId()); item.setProductId(product.getId());
}); });
//保存规格
productSpecificationService.saveBatch(productSpecifications); productSpecificationService.saveBatch(productSpecifications);
//保存商品记录
List<ProductRecord> recordList = BeanUtils.mapToList(bo.getRecordList(), ProductRecord.class);
ProductRecordService specificationRecordService = SpringUtils.getBean(ProductRecordService.class);
recordList.forEach(item -> { recordList.forEach(item -> {
item.setProductId(product.getId()); item.setProductId(product.getId());
}); });
//保存记录
specificationRecordService.saveBatch(recordList); specificationRecordService.saveBatch(recordList);
} }
@ -238,10 +272,18 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public void updateProduct(ProductBo bo) { public void updateProduct(ProductBo bo) {
Product product = BeanUtils.mapToClass(bo, Product.class); Product product = BeanUtils.mapToClass(bo, Product.class);
//积分支付
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 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); BigDecimal minPrice = bo.getRecordList().stream().map(ProductRecordBo::getRecordPrice).min(Comparator.comparing(x -> x)).orElse(null);
product.setMaxPrice(maxPrice).setMinPrice(minPrice); product.setMaxConsume(maxPrice).setMinConsume(minPrice);
}
this.updateById(product); this.updateById(product);
//保存规格 //保存规格
ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class); ProductSpecificationService productSpecificationService = SpringUtils.getBean(ProductSpecificationService.class);
@ -301,11 +343,14 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
try { try {
DataSourceKey.use("jambox"); DataSourceKey.use("jambox");
rowList = Db.selectListByQuery("t_card_template", QueryWrapper.create() 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") .from("t_card_template").as("tct")
.leftJoin("t_brand_info").as("tbi").on("tbi.id = tct.brand_id") .leftJoin("t_brand_info").as("tbi").on("tbi.id = tct.brand_id")
.where("tbi.brand_id = ?", brandExtend.getBrandCloudId()) .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); cardTemplateListVos = RowUtil.toEntityList(rowList, JamboxCardTemplateListVo.class);
} finally { } finally {
DataSourceKey.clear(); DataSourceKey.clear();
@ -401,4 +446,26 @@ public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> impl
public ProductInfoVo getProductInfo(String id) { public ProductInfoVo getProductInfo(String id) {
return this.mapper.selectOneWithRelationsByIdAs(id, ProductInfoVo.class); 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);
}
} }

View File

@ -1,12 +1,11 @@
package com.cpop.mall.business.task; package com.cpop.mall.business.task;
import com.alibaba.fastjson.JSONObject; 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.core.utils.SpringUtils;
import com.cpop.jambox.business.entity.StoreExtend; 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.service.StoreExtendService;
import com.cpop.jambox.business.task.CardTemplateAsyncTask;
import com.cpop.jambox.framework.constant.JamboxCloudUrl; import com.cpop.jambox.framework.constant.JamboxCloudUrl;
import com.cpop.mall.business.entity.Order; import com.cpop.mall.business.entity.Order;
import com.cpop.mall.business.entity.OrderDetail; 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.entity.ProductRecord;
import com.cpop.mall.business.service.ProductRecordService; import com.cpop.mall.business.service.ProductRecordService;
import okhttp3.*; import okhttp3.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.util.Date; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -31,6 +31,23 @@ import static com.cpop.jambox.business.entity.table.StoreExtendTableDef.STORE_EX
*/ */
@Component @Component
public class OrderDetailAsyncTask { 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") @Async("customAsyncThreadPool")
public void asyncProcessingOrderDetails(Order order, JSONObject loginUserInfo, List<OrderDetail> orderDetails, List<Product> productList) { 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)); Map<String, Product> productMap = productList.stream().collect(Collectors.toMap(Product::getId, item -> item));
@ -44,27 +61,42 @@ public class OrderDetailAsyncTask {
orderDetails.forEach(item -> { orderDetails.forEach(item -> {
//获取当前订单记录的商品信息 //获取当前订单记录的商品信息
ProductRecord productRecord = productRecordMap.get(item.getProductRecordId()); ProductRecord productRecord = productRecordMap.get(item.getProductRecordId());
Product product = productMap.get(productRecord.getId()); Product product = productMap.get(productRecord.getProductId());
//课卡 //课卡
if (product.getProductType() == 0) { if (product.getProductType() == 0) {
//课卡信息 //课卡信息
JSONObject jsonBody = new JSONObject(); JSONObject jsonBody = new JSONObject();
jsonBody.put("_type", "addPeriod"); jsonBody.put("_type", "addPeriod");
//订单id //订单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("storeId", storeCloudMap.get(item.getStoreId()));
//手机号 //手机号
jsonBody.put("phone", loginUserInfo.getString("phoneNumber")); jsonBody.put("phone", loginUserInfo.getString("phoneNumber"));
//客户名称 //客户名称
jsonBody.put("customerName", loginUserInfo.getString("nickName")); jsonBody.put("customerName", loginUserInfo.getString("nickName"));
//客户性别 //模板id
jsonBody.put("customerSex", loginUserInfo.getBoolean("sex") ? "" : ""); jsonBody.put("templateId", product.getCardTemplateId());
//客户地址 //订单来源
jsonBody.put("customerAddress", order.getReceiveAddress()); jsonBody.put("orderSource", OrderSource.MALL.toString());
SpringUtils.getBean(CardTemplateAsyncTask.class).cloudCreateCard(jsonBody, product.getCardTemplateId()); //模板对应实际地址
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());
}
} }
}); });
} }

View File

@ -70,7 +70,7 @@ public class ProductRecordSyncStockTask {
while (iterator.hasNext()) { while (iterator.hasNext()) {
Map.Entry<String, Integer> next = iterator.next(); Map.Entry<String, Integer> next = iterator.next();
boolean update = productRecordService.updateChain() 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(); .where(PRODUCT_RECORD.ID.eq(next.getKey())).update();
//如果更新成功移除 //如果更新成功移除
if (update) { if (update) {

View File

@ -74,13 +74,13 @@ public class MiniProductPageVo implements Serializable {
* 最高价 * 最高价
*/ */
@ApiModelProperty("最高价") @ApiModelProperty("最高价")
private BigDecimal maxPrice; private BigDecimal maxConsume;
/** /**
* 最低价 * 最低价
*/ */
@ApiModelProperty("最低价") @ApiModelProperty("最低价")
private BigDecimal minPrice; private BigDecimal minConsume;
/** /**
* 支付方式(微信支付:0;积分支付:1) * 支付方式(微信支付:0;积分支付:1)

View File

@ -82,14 +82,14 @@ public class ProductInfoVo implements Serializable {
/** /**
* 最高价 * 最高价
*/ */
@ApiModelProperty("最高") @ApiModelProperty("最高消耗")
private BigDecimal maxPrice; private BigDecimal maxConsume;
/** /**
* 最低价 * 最低价
*/ */
@ApiModelProperty("最低") @ApiModelProperty("最低消耗")
private BigDecimal minPrice; private BigDecimal minConsume;
/** /**
* 支付方式(微信支付:0;积分支付:1) * 支付方式(微信支付:0;积分支付:1)

View File

@ -97,16 +97,16 @@ public class ProductPageVo implements Serializable {
private Integer buyRestrict; private Integer buyRestrict;
/** /**
* 最高 * 最高消费
*/ */
@ApiModelProperty("最高") @ApiModelProperty("最高消费")
private BigDecimal maxPrice; private BigDecimal maxConsume;
/** /**
* 最低 * 最低消费
*/ */
@ApiModelProperty("最低") @ApiModelProperty("最低消费")
private BigDecimal minPrice; private BigDecimal minConsume;
/** /**
* 限购数量 * 限购数量