1. 新增平台商品库存
This commit is contained in:
2026-05-20 15:38:06 +08:00
parent 0d6a254661
commit 7e2f759bd4
22 changed files with 992 additions and 3 deletions

View File

@@ -0,0 +1,57 @@
alter table merchant_catalog
add stock int4 default 0 not null;
comment on column public.merchant_catalog.stock is '库存';
alter table merchant_catalog
add version int4 default 0 not null;
comment on column public.merchant_catalog.version is '乐观锁';
DROP TABLE IF EXISTS merchant_catalog_operate_log;
create table merchant_catalog_operate_log
(
id int8 not null primary key,
merchant_id int8 not null default -1,
merchant_account varchar(20) not null default '',
product_id int8 not null,
product_name varchar(255) not null default '',
type int4 default 1, -- 1-扣减 2-增加 3-下架
affected_stock int4 not null,
remark text,
create_user int8,
create_dept int8,
create_time timestamp(6),
update_user int8,
update_time timestamp(6),
status int4 default 1,
is_deleted int4 default 0
);
CREATE INDEX idx_merchant_catalog_log_merchant_id_create_time
ON merchant_catalog_operate_log (merchant_id, create_time DESC) WHERE is_deleted = 0;
CREATE INDEX idx_merchant_catalog_log_product_id_create_time
ON merchant_catalog_operate_log (product_id, create_time DESC) WHERE is_deleted = 0;
CREATE INDEX idx_merchant_catalog_log_create_time
ON merchant_catalog_operate_log (create_time DESC) WHERE is_deleted = 0;
COMMENT ON TABLE merchant_catalog_operate_log IS '自营商家产品目录操作日志';
COMMENT ON COLUMN merchant_catalog_operate_log.id IS '主键';
COMMENT ON COLUMN merchant_catalog_operate_log.merchant_id IS '商家id';
COMMENT ON COLUMN merchant_catalog_operate_log.merchant_account IS '商家账号';
COMMENT ON COLUMN merchant_catalog_operate_log.product_id IS '商品id';
COMMENT ON COLUMN merchant_catalog_operate_log.product_name IS '商品名称';
COMMENT ON COLUMN merchant_catalog_operate_log.type IS '操作类型:1-扣减 2-增加 3-下架';
COMMENT ON COLUMN merchant_catalog_operate_log.affected_stock IS '受影响数量';
COMMENT ON COLUMN merchant_catalog_operate_log.remark IS '备注';
comment on column merchant_catalog_operate_log.create_user is '创建人';
comment on column merchant_catalog_operate_log.create_dept is '创建部门';
comment on column merchant_catalog_operate_log.create_time is '创建时间';
comment on column merchant_catalog_operate_log.update_user is '修改人';
comment on column merchant_catalog_operate_log.update_time is '修改时间';
comment on column merchant_catalog_operate_log.status is '状态';
comment on column merchant_catalog_operate_log.is_deleted is '是否已删除';

View File

@@ -24,6 +24,8 @@ public class MarketMerchantCatalogApiVO implements Serializable {
private BigDecimal salePrice; private BigDecimal salePrice;
private Integer stock;
private String remark; private String remark;
} }

View File

@@ -144,4 +144,24 @@ public class MerchantCatalogController extends BladeController {
return R.status(catalogService.submitPlatformCatalog(catalog)); return R.status(catalogService.submitPlatformCatalog(catalog));
} }
/**
* 自营商家商品表 新增平台商品库存
*/
@PostMapping("/increase-stock")
@ApiOperationSupport(order = 9)
@Operation(summary = "新增平台商品库存", description = "传入id,num")
public R increaseStock(@RequestParam String id, @RequestParam String num) {
return R.status(catalogService.increaseStock(Func.toLong(id), Func.toInt(num)));
}
/**
* 自营商家商品表 减扣平台商品库存
*/
@PostMapping("/reduce-stock")
@ApiOperationSupport(order = 9)
@Operation(summary = "减扣平台商品库存", description = "传入id,num")
public R reduceStock(@RequestParam String id, @RequestParam String num) {
return R.status(catalogService.reduceStock(Func.toLong(id), Func.toInt(num)));
}
} }

View File

@@ -0,0 +1,162 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.controller;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import lombok.AllArgsConstructor;
import jakarta.validation.Valid;
import org.springblade.core.secure.BladeUser;
import org.springblade.core.secure.annotation.IsAdmin;
import org.springblade.core.mp.support.Condition;
import org.springblade.core.mp.support.Query;
import org.springblade.core.secure.annotation.PreAuth;
import org.springblade.core.tool.api.R;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.market.excel.MerchantCatalogOperateLogExcel;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import org.springblade.modules.market.pojo.vo.MerchantCatalogOperateLogVO;
import org.springblade.modules.market.service.IMerchantCatalogOperateLogService;
import org.springblade.modules.market.wrapper.MerchantCatalogOperateLogWrapper;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.boot.ctrl.BladeController;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.excel.util.ExcelUtil;
import java.util.Map;
import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
/**
* 自营商家产品目录操作日志 控制器
*
* @author BladeX
* @since 2026-05-20
*/
@RestController
@AllArgsConstructor
@RequestMapping("/market/catalog-operate-log")
@Tag(name = "自营商家产品目录操作日志", description = "自营商家产品目录操作日志接口")
@PreAuth("hasAnyRole('administrator', 'admin', 'operator')")
public class MerchantCatalogOperateLogController extends BladeController {
private final IMerchantCatalogOperateLogService catalogOperateLogService;
/**
* 自营商家产品目录操作日志 详情
*/
@GetMapping("/detail")
@ApiOperationSupport(order = 1)
@Operation(summary = "详情", description = "传入catalogOperateLog")
public R<MerchantCatalogOperateLogVO> detail(MerchantCatalogOperateLogEntity catalogOperateLog) {
MerchantCatalogOperateLogEntity detail = catalogOperateLogService.getOne(Condition.getQueryWrapper(catalogOperateLog));
return R.data(MerchantCatalogOperateLogWrapper.build().entityVO(detail));
}
/**
* 自营商家产品目录操作日志 分页
*/
@GetMapping("/list")
@ApiOperationSupport(order = 2)
@Operation(summary = "分页", description = "传入catalogOperateLog")
public R<IPage<MerchantCatalogOperateLogVO>> list(@Parameter(hidden = true) @RequestParam Map<String, Object> catalogOperateLog, Query query) {
IPage<MerchantCatalogOperateLogEntity> pages = catalogOperateLogService.page(Condition.getPage(query), Condition.getQueryWrapper(catalogOperateLog, MerchantCatalogOperateLogEntity.class));
return R.data(MerchantCatalogOperateLogWrapper.build().pageVO(pages));
}
/**
* 自营商家产品目录操作日志 自定义分页
*/
@GetMapping("/page")
@ApiOperationSupport(order = 3)
@Operation(summary = "分页", description = "传入catalogOperateLog")
public R<IPage<MerchantCatalogOperateLogVO>> page(MerchantCatalogOperateLogVO catalogOperateLog, Query query) {
IPage<MerchantCatalogOperateLogVO> pages = catalogOperateLogService.selectCatalogOperateLogPage(Condition.getPage(query), catalogOperateLog);
return R.data(pages);
}
/**
* 自营商家产品目录操作日志 新增
*/
@PostMapping("/save")
@ApiOperationSupport(order = 4)
@Operation(summary = "新增", description = "传入catalogOperateLog")
public R save(@Valid @RequestBody MerchantCatalogOperateLogEntity catalogOperateLog) {
return R.status(catalogOperateLogService.save(catalogOperateLog));
}
/**
* 自营商家产品目录操作日志 修改
*/
@PostMapping("/update")
@ApiOperationSupport(order = 5)
@Operation(summary = "修改", description = "传入catalogOperateLog")
public R update(@Valid @RequestBody MerchantCatalogOperateLogEntity catalogOperateLog) {
return R.status(catalogOperateLogService.updateById(catalogOperateLog));
}
/**
* 自营商家产品目录操作日志 新增或修改
*/
@PostMapping("/submit")
@ApiOperationSupport(order = 6)
@Operation(summary = "新增或修改", description = "传入catalogOperateLog")
public R submit(@Valid @RequestBody MerchantCatalogOperateLogEntity catalogOperateLog) {
return R.status(catalogOperateLogService.saveOrUpdate(catalogOperateLog));
}
/**
* 自营商家产品目录操作日志 删除
*/
@PostMapping("/remove")
@ApiOperationSupport(order = 7)
@Operation(summary = "逻辑删除", description = "传入ids")
public R remove(@Parameter(description = "主键集合", required = true) @RequestParam String ids) {
return R.status(catalogOperateLogService.deleteLogic(Func.toLongList(ids)));
}
/**
* 导出数据
*/
@IsAdmin
@GetMapping("/export-catalogOperateLog")
@ApiOperationSupport(order = 9)
@Operation(summary = "导出数据", description = "传入catalogOperateLog")
public void exportCatalogOperateLog(@Parameter(hidden = true) @RequestParam Map<String, Object> catalogOperateLog, BladeUser bladeUser, HttpServletResponse response) {
QueryWrapper<MerchantCatalogOperateLogEntity> queryWrapper = Condition.getQueryWrapper(catalogOperateLog, MerchantCatalogOperateLogEntity.class);
//if (!AuthUtil.isAdministrator()) {
// queryWrapper.lambda().eq(CatalogOperateLog::getTenantId, bladeUser.getTenantId());
//}
//queryWrapper.lambda().eq(CatalogOperateLogEntity::getIsDeleted, BladeConstant.DB_NOT_DELETED);
List<MerchantCatalogOperateLogExcel> list = catalogOperateLogService.exportCatalogOperateLog(queryWrapper);
ExcelUtil.export(response, "自营商家产品目录操作日志数据" + DateUtil.time(), "自营商家产品目录操作日志数据表", list, MerchantCatalogOperateLogExcel.class);
}
}

View File

@@ -0,0 +1,28 @@
package org.springblade.modules.market.eums;
import lombok.Getter;
@Getter
public enum CatalogOperationType {
REDUCE(1, "扣减"),
INCREASE(2, "增加"),
UNLIST(3, " 下架");
private final int code;
private final String desc;
CatalogOperationType(int code, String desc) {
this.code = code;
this.desc = desc;
}
public static CatalogOperationType fromCode(int code) {
for (CatalogOperationType type : CatalogOperationType.values()) {
if (type.getCode() == code) {
return type;
}
}
throw new IllegalArgumentException("Invalid merchant payout account type code: " + code);
}
}

View File

@@ -0,0 +1,110 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.excel;
import lombok.Data;
import java.util.Date;
import cn.idev.excel.annotation.ExcelProperty;
import cn.idev.excel.annotation.write.style.ColumnWidth;
import cn.idev.excel.annotation.write.style.ContentRowHeight;
import cn.idev.excel.annotation.write.style.HeadRowHeight;
import java.io.Serializable;
import java.io.Serial;
/**
* 自营商家产品目录操作日志 Excel实体类
*
* @author BladeX
* @since 2026-05-20
*/
@Data
@ColumnWidth(25)
@HeadRowHeight(20)
@ContentRowHeight(18)
public class MerchantCatalogOperateLogExcel implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 主键
*/
@ColumnWidth(20)
@ExcelProperty("主键")
private Long id;
/**
* 商家id
*/
@ColumnWidth(20)
@ExcelProperty("商家id")
private Long merchantId;
/**
* 商家账号
*/
@ColumnWidth(20)
@ExcelProperty("商家账号")
private String merchantAccount;
/**
* 商品id
*/
@ColumnWidth(20)
@ExcelProperty("商品id")
private Long productId;
/**
* 商品名称
*/
@ColumnWidth(20)
@ExcelProperty("商品名称")
private String productName;
/**
* 操作类型:1-扣减 2-增加 3-下架
*/
@ColumnWidth(20)
@ExcelProperty("操作类型:1-扣减 2-增加 3-下架")
private Integer type;
/**
* 受影响数量
*/
@ColumnWidth(20)
@ExcelProperty("受影响数量")
private Integer affectedStock;
/**
* 备注
*/
@ColumnWidth(20)
@ExcelProperty("备注")
private String remark;
/**
* 是否已删除
*/
@ColumnWidth(20)
@ExcelProperty("是否已删除")
private Integer isDeleted;
}

View File

@@ -38,6 +38,7 @@
set amount = amount + #{amount} , version = version + 1 set amount = amount + #{amount} , version = version + 1
where id = #{userId} and version = #{version} where id = #{userId} and version = #{version}
</update> </update>
<update id="deductCashCoupon"> <update id="deductCashCoupon">
update update
cash_coupon cash_coupon

View File

@@ -49,5 +49,7 @@ public interface MerchantCatalogMapper extends BaseMapper<MerchantCatalogEntity>
*/ */
List<MerchantCatalogVO> selectMerchantCatalogPage(IPage page, MerchantCatalogVO catalogVO); List<MerchantCatalogVO> selectMerchantCatalogPage(IPage page, MerchantCatalogVO catalogVO);
int reduceStockById(Long id, Integer quantity, Integer version);
int increaseStockById(Long id, Integer quantity, Integer version);
} }

View File

@@ -14,7 +14,9 @@
<result column="thumb_image_url" property="thumbImageUrl"/> <result column="thumb_image_url" property="thumbImageUrl"/>
<result column="cost_price" property="costPrice"/> <result column="cost_price" property="costPrice"/>
<result column="sale_price" property="salePrice"/> <result column="sale_price" property="salePrice"/>
<result column="stock" property="stock"/>
<result column="remark" property="remark"/> <result column="remark" property="remark"/>
<result column="version" property="version"/>
<result column="create_user" property="createUser"/> <result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/> <result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/> <result column="create_time" property="createTime"/>
@@ -24,7 +26,6 @@
<result column="is_deleted" property="isDeleted"/> <result column="is_deleted" property="isDeleted"/>
</resultMap> </resultMap>
<select id="selectMerchantCatalogPage" resultMap="merchantCatalogResultMap"> <select id="selectMerchantCatalogPage" resultMap="merchantCatalogResultMap">
select * from merchant_catalog where is_deleted = 0 select * from merchant_catalog where is_deleted = 0
<if test="catalogVO.type !=null"> <if test="catalogVO.type !=null">
@@ -36,4 +37,16 @@
order by create_time desc order by create_time desc
</select> </select>
<update id="reduceStockById">
update merchant_catalog
set stock = stock - #{quantity}, version = version + 1
where id = #{id} and version = #{version} and (stock - #{quantity}) >= 0
</update>
<update id="increaseStockById">
update merchant_catalog
set stock = stock + #{quantity}, version = version + 1
where id = #{id} and version = #{version}
</update>
</mapper> </mapper>

View File

@@ -0,0 +1,64 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.mapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.ibatis.annotations.Param;
import org.springblade.modules.market.excel.MerchantCatalogOperateLogExcel;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import org.springblade.modules.market.pojo.vo.MerchantCatalogOperateLogVO;
import java.util.List;
/**
* 自营商家产品目录操作日志 Mapper 接口
*
* @author BladeX
* @since 2026-05-20
*/
public interface MerchantCatalogOperateLogMapper extends BaseMapper<MerchantCatalogOperateLogEntity> {
/**
* 自定义分页
*
* @param page 分页参数
* @param catalogOperateLog 查询参数
* @return List<CatalogOperateLogVO>
*/
List<MerchantCatalogOperateLogVO> selectCatalogOperateLogPage(IPage page, MerchantCatalogOperateLogVO catalogOperateLog);
/**
* 获取导出数据
*
* @param queryWrapper 查询条件
* @return List<CatalogOperateLogExcel>
*/
List<MerchantCatalogOperateLogExcel> exportCatalogOperateLog(@Param("ew") Wrapper<MerchantCatalogOperateLogEntity> queryWrapper);
}

View File

@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="org.springblade.modules.market.mapper.MerchantCatalogOperateLogMapper">
<!-- 通用查询映射结果 -->
<resultMap id="catalogOperateLogResultMap" type="org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity">
<result column="id" property="id"/>
<result column="merchant_id" property="merchantId"/>
<result column="merchant_account" property="merchantAccount"/>
<result column="product_id" property="productId"/>
<result column="product_name" property="productName"/>
<result column="type" property="type"/>
<result column="affected_stock" property="affectedStock"/>
<result column="remark" property="remark"/>
<result column="create_user" property="createUser"/>
<result column="create_dept" property="createDept"/>
<result column="create_time" property="createTime"/>
<result column="update_user" property="updateUser"/>
<result column="update_time" property="updateTime"/>
<result column="status" property="status"/>
<result column="is_deleted" property="isDeleted"/>
</resultMap>
<select id="selectCatalogOperateLogPage" resultMap="catalogOperateLogResultMap">
select * from merchant_catalog_operate_log where is_deleted = 0
</select>
<select id="exportCatalogOperateLog" resultType="org.springblade.modules.market.excel.MerchantCatalogOperateLogExcel">
SELECT * FROM merchant_catalog_operate_log ${ew.customSqlSegment}
</select>
</mapper>

View File

@@ -0,0 +1,46 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.pojo.dto;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import java.io.Serial;
/**
* 自营商家产品目录操作日志 数据传输对象实体类
*
* @author BladeX
* @since 2026-05-20
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class MerchantCatalogOperateLogDTO extends MerchantCatalogOperateLogEntity {
@Serial
private static final long serialVersionUID = 1L;
}

View File

@@ -27,6 +27,7 @@ package org.springblade.modules.market.pojo.entity;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.annotation.Version;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data; import lombok.Data;
@@ -102,6 +103,17 @@ public class MerchantCatalogEntity extends BaseEntity {
*/ */
@Schema(description = "销售价(当商品类型为平台商品时,统一销售价格)") @Schema(description = "销售价(当商品类型为平台商品时,统一销售价格)")
private BigDecimal salePrice; private BigDecimal salePrice;
/**
* 库存
*/
@Schema(description = "库存")
private Integer stock;
/**
* 乐观锁
*/
@Schema(description = "乐观锁")
@Version
private Integer version;
/** /**
* 备注 * 备注
*/ */

View File

@@ -0,0 +1,86 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.pojo.entity;
import lombok.Data;
import io.swagger.v3.oas.annotations.media.Schema;
import com.baomidou.mybatisplus.annotation.TableName;
import lombok.EqualsAndHashCode;
import org.springblade.core.mp.base.BaseEntity;
import java.io.Serial;
/**
* 自营商家产品目录操作日志 实体类
*
* @author BladeX
* @since 2026-05-20
*/
@Data
@TableName("merchant_catalog_operate_log")
@Schema(description = "CatalogOperateLog对象")
@EqualsAndHashCode(callSuper = true)
public class MerchantCatalogOperateLogEntity extends BaseEntity {
@Serial
private static final long serialVersionUID = 1L;
/**
* 商家id
*/
@Schema(description = "商家id")
private Long merchantId;
/**
* 商家账号
*/
@Schema(description = "商家账号")
private String merchantAccount;
/**
* 商品id
*/
@Schema(description = "商品id")
private Long productId;
/**
* 商品名称
*/
@Schema(description = "商品名称")
private String productName;
/**
* 操作类型:1-扣减 2-增加 3-下架
*/
@Schema(description = "操作类型:1-扣减 2-增加 3-下架")
private Integer type;
/**
* 受影响数量
*/
@Schema(description = "受影响数量")
private Integer affectedStock;
/**
* 备注
*/
@Schema(description = "备注")
private String remark;
}

View File

@@ -0,0 +1,46 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.pojo.vo;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import java.io.Serial;
/**
* 自营商家产品目录操作日志 视图实体类
*
* @author BladeX
* @since 2026-05-20
*/
@Data
@EqualsAndHashCode(callSuper = true)
public class MerchantCatalogOperateLogVO extends MerchantCatalogOperateLogEntity {
@Serial
private static final long serialVersionUID = 1L;
}

View File

@@ -0,0 +1,62 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseService;
import org.springblade.modules.market.excel.MerchantCatalogOperateLogExcel;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import org.springblade.modules.market.pojo.vo.MerchantCatalogOperateLogVO;
import java.util.List;
/**
* 自营商家产品目录操作日志 服务类
*
* @author BladeX
* @since 2026-05-20
*/
public interface IMerchantCatalogOperateLogService extends BaseService<MerchantCatalogOperateLogEntity> {
/**
* 自定义分页
*
* @param page 分页参数
* @param catalogOperateLog 查询参数
* @return IPage<CatalogOperateLogVO>
*/
IPage<MerchantCatalogOperateLogVO> selectCatalogOperateLogPage(IPage<MerchantCatalogOperateLogVO> page, MerchantCatalogOperateLogVO catalogOperateLog);
/**
* 导出数据
*
* @param queryWrapper 查询条件
* @return List<CatalogOperateLogExcel>
*/
List<MerchantCatalogOperateLogExcel> exportCatalogOperateLog(Wrapper<MerchantCatalogOperateLogEntity> queryWrapper);
}

View File

@@ -55,4 +55,11 @@ public interface IMerchantCatalogService extends BaseService<MerchantCatalogEnti
boolean submitMerchantCatalog(Long userId, Long productId, String productName, String thumbImageUrl, List<String> mainImageUrls, List<String> detailImageUrls); boolean submitMerchantCatalog(Long userId, Long productId, String productName, String thumbImageUrl, List<String> mainImageUrls, List<String> detailImageUrls);
void reduceStockByMerchant(Long merchantId, String merchantAccount, Long catalogId, Integer quantity);
void increaseStockByMerchant(Long merchantId, String merchantAccount, Long catalogId, Integer quantity);
boolean increaseStock(Long id, Integer quantity);
boolean reduceStock(Long id, Integer quantity);
} }

View File

@@ -0,0 +1,63 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.service.impl;
import org.springblade.modules.market.excel.MerchantCatalogOperateLogExcel;
import org.springblade.modules.market.mapper.MerchantCatalogOperateLogMapper;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import org.springblade.modules.market.pojo.vo.MerchantCatalogOperateLogVO;
import org.springblade.modules.market.service.IMerchantCatalogOperateLogService;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springblade.core.mp.base.BaseServiceImpl;
import java.util.List;
/**
* 自营商家产品目录操作日志 服务实现类
*
* @author BladeX
* @since 2026-05-20
*/
@Service
public class MerchantCatalogOperateLogServiceImpl extends BaseServiceImpl<MerchantCatalogOperateLogMapper, MerchantCatalogOperateLogEntity> implements IMerchantCatalogOperateLogService {
@Override
public IPage<MerchantCatalogOperateLogVO> selectCatalogOperateLogPage(IPage<MerchantCatalogOperateLogVO> page, MerchantCatalogOperateLogVO catalogOperateLog) {
return page.setRecords(baseMapper.selectCatalogOperateLogPage(page, catalogOperateLog));
}
@Override
public List<MerchantCatalogOperateLogExcel> exportCatalogOperateLog(Wrapper<MerchantCatalogOperateLogEntity> queryWrapper) {
List<MerchantCatalogOperateLogExcel> catalogOperateLogList = baseMapper.exportCatalogOperateLog(queryWrapper);
//catalogOperateLogList.forEach(catalogOperateLog -> {
// catalogOperateLog.setTypeName(DictCache.getValue(DictEnum.YES_NO, CatalogOperateLog.getType()));
//});
return catalogOperateLogList;
}
}

View File

@@ -36,15 +36,19 @@ import org.springblade.core.redis.ratelimiter.RateLimiter;
import org.springblade.core.tool.utils.StringUtil; import org.springblade.core.tool.utils.StringUtil;
import org.springblade.modules.api.vo.MarketMerchantCatalogApiVO; import org.springblade.modules.api.vo.MarketMerchantCatalogApiVO;
import org.springblade.modules.market.convert.MarketMerchantConvert; import org.springblade.modules.market.convert.MarketMerchantConvert;
import org.springblade.modules.market.eums.CatalogOperationType;
import org.springblade.modules.market.eums.MerchantProductType; import org.springblade.modules.market.eums.MerchantProductType;
import org.springblade.modules.market.eums.MerchantType; import org.springblade.modules.market.eums.MerchantType;
import org.springblade.modules.market.mapper.MerchantCatalogMapper; import org.springblade.modules.market.mapper.MerchantCatalogMapper;
import org.springblade.modules.market.pojo.entity.MerchantCatalogEntity; import org.springblade.modules.market.pojo.entity.MerchantCatalogEntity;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import org.springblade.modules.market.pojo.vo.MerchantCatalogVO; import org.springblade.modules.market.pojo.vo.MerchantCatalogVO;
import org.springblade.modules.market.service.IMerchantCatalogOperateLogService;
import org.springblade.modules.market.service.IMerchantCatalogService; import org.springblade.modules.market.service.IMerchantCatalogService;
import org.springblade.modules.system.pojo.entity.User; import org.springblade.modules.system.pojo.entity.User;
import org.springblade.modules.system.service.IUserService; import org.springblade.modules.system.service.IUserService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.util.List; import java.util.List;
@@ -63,6 +67,8 @@ public class MerchantCatalogServiceImpl extends BaseServiceImpl<MerchantCatalogM
private final IUserService userService; private final IUserService userService;
private final IMerchantCatalogOperateLogService operateLogService;
private static final String MERCHANT_CATALOG_QUANTITY_LIMIT = "merchant.catalog.quantity.limit"; private static final String MERCHANT_CATALOG_QUANTITY_LIMIT = "merchant.catalog.quantity.limit";
@Override @Override
@@ -153,4 +159,109 @@ public class MerchantCatalogServiceImpl extends BaseServiceImpl<MerchantCatalogM
return saveOrUpdate(entity); return saveOrUpdate(entity);
} }
@Override
@Transactional(rollbackFor = Exception.class)
public void reduceStockByMerchant(Long merchantId, String merchantAccount, Long catalogId, Integer quantity) {
if (merchantId == null || StringUtil.isBlank(merchantAccount) || catalogId == null || quantity == null || quantity < 1) {
throw new ServiceException("无效参数");
}
MerchantCatalogEntity catalog = getById(catalogId);
if (catalog == null) {
throw new ServiceException("无效产品");
}
if (baseMapper.reduceStockById(catalog.getId(), quantity, catalog.getVersion()) != 1) {
throw new ServiceException("商品目录减扣库存失败");
}
MerchantCatalogOperateLogEntity operateLog = new MerchantCatalogOperateLogEntity();
operateLog.setMerchantId(merchantId);
operateLog.setMerchantAccount(merchantAccount);
operateLog.setProductId(catalogId);
operateLog.setProductName(catalog.getProductName());
operateLog.setType(CatalogOperationType.REDUCE.getCode());
operateLog.setAffectedStock(quantity);
if (!operateLogService.save(operateLog)) {
throw new ServiceException("操作失败");
}
}
@Override
@Transactional(rollbackFor = Exception.class)
public void increaseStockByMerchant(Long merchantId, String merchantAccount, Long catalogId, Integer quantity) {
if (merchantId == null || StringUtil.isBlank(merchantAccount) || catalogId == null || quantity == null || quantity < 1) {
throw new ServiceException("无效参数");
}
MerchantCatalogEntity catalog = getById(catalogId);
if (catalog == null) {
throw new ServiceException("无效产品");
}
if (baseMapper.increaseStockById(catalog.getId(), quantity, catalog.getVersion()) != 1) {
throw new ServiceException("商品目录新增库存失败");
}
MerchantCatalogOperateLogEntity operateLog = new MerchantCatalogOperateLogEntity();
operateLog.setMerchantId(merchantId);
operateLog.setMerchantAccount(merchantAccount);
operateLog.setProductId(catalogId);
operateLog.setProductName(catalog.getProductName());
operateLog.setType(CatalogOperationType.INCREASE.getCode());
operateLog.setAffectedStock(quantity);
if (!operateLogService.save(operateLog)) {
throw new ServiceException("操作失败");
}
}
@Override
public boolean increaseStock(Long id, Integer quantity) {
if (quantity < 1) {
throw new ServiceException("无效数量");
}
MerchantCatalogEntity catalog = getById(id);
if (catalog == null) {
throw new ServiceException("无效商品");
}
if (!catalog.getType().equals(MerchantProductType.PLATFORM.getCode())) {
throw new ServiceException("无效商品类型");
}
if (baseMapper.increaseStockById(catalog.getId(), quantity, catalog.getVersion()) != 1) {
throw new ServiceException("商品目录新增库存失败");
}
MerchantCatalogOperateLogEntity operateLog = new MerchantCatalogOperateLogEntity();
operateLog.setMerchantId(-1L);
operateLog.setMerchantAccount("后台账户");
operateLog.setProductId(id);
operateLog.setProductName(catalog.getProductName());
operateLog.setType(CatalogOperationType.INCREASE.getCode());
operateLog.setAffectedStock(quantity);
if (!operateLogService.save(operateLog)) {
throw new ServiceException("操作失败");
}
return true;
}
@Override
public boolean reduceStock(Long id, Integer quantity) {
if (quantity < 1) {
throw new ServiceException("无效数量");
}
MerchantCatalogEntity catalog = getById(id);
if (catalog == null) {
throw new ServiceException("无效商品");
}
if (!catalog.getType().equals(MerchantProductType.PLATFORM.getCode())) {
throw new ServiceException("无效商品类型");
}
if (baseMapper.reduceStockById(catalog.getId(), quantity, catalog.getVersion()) != 1) {
throw new ServiceException("商品目录减扣库存失败");
}
MerchantCatalogOperateLogEntity operateLog = new MerchantCatalogOperateLogEntity();
operateLog.setMerchantId(-1L);
operateLog.setMerchantAccount("后台账户");
operateLog.setProductId(id);
operateLog.setProductName(catalog.getProductName());
operateLog.setType(CatalogOperationType.REDUCE.getCode());
operateLog.setAffectedStock(quantity);
if (!operateLogService.save(operateLog)) {
throw new ServiceException("操作失败");
}
return true;
}
} }

View File

@@ -122,6 +122,7 @@ public class MerchantInventoryServiceImpl extends BaseServiceImpl<MerchantInvent
MerchantProductType currentType = MerchantProductType.fromCode(catalog.getType()); MerchantProductType currentType = MerchantProductType.fromCode(catalog.getType());
switch (currentType) { switch (currentType) {
case PLATFORM -> { case PLATFORM -> {
catalogService.reduceStockByMerchant(userId, user.getAccount(), catalog.getId(), num);
BigDecimal totalAmount = catalog.getCostPrice().multiply(BigDecimal.valueOf(num)); BigDecimal totalAmount = catalog.getCostPrice().multiply(BigDecimal.valueOf(num));
if (!cashCouponService.deductCashCoupon(new MarketCashCouponApiDTO(userId, totalAmount, MarketBusinessModule.MERCHANT_PURCHASING, null, "", String.format("采购商品 [%s],编号 [%d],数量 [%d]", catalog.getProductName(), catalog.getId(), num)))) { if (!cashCouponService.deductCashCoupon(new MarketCashCouponApiDTO(userId, totalAmount, MarketBusinessModule.MERCHANT_PURCHASING, null, "", String.format("采购商品 [%s],编号 [%d],数量 [%d]", catalog.getProductName(), catalog.getId(), num)))) {
throw new ServiceException("扣除现金券失败"); throw new ServiceException("扣除现金券失败");
@@ -207,7 +208,7 @@ public class MerchantInventoryServiceImpl extends BaseServiceImpl<MerchantInvent
throw new ServiceException("商品不存在"); throw new ServiceException("商品不存在");
} }
if(orderMapper.exists(Wrappers.lambdaQuery(MerchantOrderEntity.class).eq(MerchantOrderEntity::getInventoryId, inventory.getId()).notIn(MerchantOrderEntity::getStatus, List.of(OrderStatus.COMPLETED.getCode(),OrderStatus.CANCELLED.getCode())))){ if (orderMapper.exists(Wrappers.lambdaQuery(MerchantOrderEntity.class).eq(MerchantOrderEntity::getInventoryId, inventory.getId()).notIn(MerchantOrderEntity::getStatus, List.of(OrderStatus.COMPLETED.getCode(), OrderStatus.CANCELLED.getCode())))) {
throw new ServiceException("当前商品有为完成订单,无法进行下架操作"); throw new ServiceException("当前商品有为完成订单,无法进行下架操作");
} }
@@ -222,6 +223,7 @@ public class MerchantInventoryServiceImpl extends BaseServiceImpl<MerchantInvent
throw new ServiceException("未找到商品目录,操作失败"); throw new ServiceException("未找到商品目录,操作失败");
} }
if (inventoryType == MerchantProductType.PLATFORM) { if (inventoryType == MerchantProductType.PLATFORM) {
catalogService.increaseStockByMerchant(userId, inventory.getUserAccount(), catalog.getId(), inventory.getStock());
BigDecimal totalCashCouponAmount = catalog.getCostPrice().multiply(BigDecimal.valueOf(inventory.getStock())); BigDecimal totalCashCouponAmount = catalog.getCostPrice().multiply(BigDecimal.valueOf(inventory.getStock()));
if (!cashCouponService.addCashCoupon(new MarketCashCouponApiDTO(userId, totalCashCouponAmount, MarketBusinessModule.MERCHANT_UNLIST, null, "", String.format("下架商品 [%s],编号 [%d],数量 [%d]", catalog.getProductName(), catalog.getId(), inventory.getStock())))) { if (!cashCouponService.addCashCoupon(new MarketCashCouponApiDTO(userId, totalCashCouponAmount, MarketBusinessModule.MERCHANT_UNLIST, null, "", String.format("下架商品 [%s],编号 [%d],数量 [%d]", catalog.getProductName(), catalog.getId(), inventory.getStock())))) {
throw new ServiceException("返还现金券失败"); throw new ServiceException("返还现金券失败");
@@ -272,6 +274,7 @@ public class MerchantInventoryServiceImpl extends BaseServiceImpl<MerchantInvent
MerchantProductType currentType = MerchantProductType.fromCode(catalog.getType()); MerchantProductType currentType = MerchantProductType.fromCode(catalog.getType());
switch (currentType) { switch (currentType) {
case PLATFORM -> { case PLATFORM -> {
catalogService.reduceStockByMerchant(userId, user.getAccount(), catalog.getId(), num);
finalPrice = finalPrice.add(catalog.getSalePrice()); finalPrice = finalPrice.add(catalog.getSalePrice());
BigDecimal totalAmount = catalog.getCostPrice().multiply(BigDecimal.valueOf(num)); BigDecimal totalAmount = catalog.getCostPrice().multiply(BigDecimal.valueOf(num));
if (!cashCouponService.deductCashCoupon(new MarketCashCouponApiDTO(userId, totalAmount, MarketBusinessModule.MERCHANT_PURCHASING, null, "", String.format("采购商品 [%s],编号 [%d],数量 [%d]", catalog.getProductName(), catalog.getId(), num)))) { if (!cashCouponService.deductCashCoupon(new MarketCashCouponApiDTO(userId, totalAmount, MarketBusinessModule.MERCHANT_PURCHASING, null, "", String.format("采购商品 [%s],编号 [%d],数量 [%d]", catalog.getProductName(), catalog.getId(), num)))) {
@@ -404,7 +407,7 @@ public class MerchantInventoryServiceImpl extends BaseServiceImpl<MerchantInvent
if (Objects.isNull(inventory)) { if (Objects.isNull(inventory)) {
throw new ServiceException("无效商品"); throw new ServiceException("无效商品");
} }
if (Objects.equals(userId, inventory.getUserId())){ if (Objects.equals(userId, inventory.getUserId())) {
throw new ServiceException("无法关注自己的店铺"); throw new ServiceException("无法关注自己的店铺");
} }
if (favoriteService.hasFavorite(userId, inventory.getUserId())) { if (favoriteService.hasFavorite(userId, inventory.getUserId())) {

View File

@@ -0,0 +1,60 @@
/**
* BladeX Commercial License Agreement
* Copyright (c) 2018-2099, https://bladex.cn. All rights reserved.
* <p>
* Use of this software is governed by the Commercial License Agreement
* obtained after purchasing a license from BladeX.
* <p>
* 1. This software is for development use only under a valid license
* from BladeX.
* <p>
* 2. Redistribution of this software's source code to any third party
* without a commercial license is strictly prohibited.
* <p>
* 3. Licensees may copyright their own code but cannot use segments
* from this software for such purposes. Copyright of this software
* remains with BladeX.
* <p>
* Using this software signifies agreement to this License, and the software
* must not be used for illegal purposes.
* <p>
* THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY. The author is
* not liable for any claims arising from secondary or illegal development.
* <p>
* Author: Chill Zhuang (bladejava@qq.com)
*/
package org.springblade.modules.market.wrapper;
import org.springblade.core.mp.support.BaseEntityWrapper;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.modules.market.pojo.entity.MerchantCatalogOperateLogEntity;
import org.springblade.modules.market.pojo.vo.MerchantCatalogOperateLogVO;
import java.util.Objects;
/**
* 自营商家产品目录操作日志 包装类,返回视图层所需的字段
*
* @author BladeX
* @since 2026-05-20
*/
public class MerchantCatalogOperateLogWrapper extends BaseEntityWrapper<MerchantCatalogOperateLogEntity, MerchantCatalogOperateLogVO> {
public static MerchantCatalogOperateLogWrapper build() {
return new MerchantCatalogOperateLogWrapper();
}
@Override
public MerchantCatalogOperateLogVO entityVO(MerchantCatalogOperateLogEntity catalogOperateLog) {
MerchantCatalogOperateLogVO catalogOperateLogVO = Objects.requireNonNull(BeanUtil.copyProperties(catalogOperateLog, MerchantCatalogOperateLogVO.class));
//User createUser = UserCache.getUser(catalogOperateLog.getCreateUser());
//User updateUser = UserCache.getUser(catalogOperateLog.getUpdateUser());
//catalogOperateLogVO.setCreateUserName(createUser.getName());
//catalogOperateLogVO.setUpdateUserName(updateUser.getName());
return catalogOperateLogVO;
}
}