前言
💖💖作者:计算机程序员小杨 💙💙个人简介:我是一名计算机相关专业的从业者,擅长Java、微信小程序、Python、Golang、安卓Android等多个IT方向。会做一些项目定制化开发、代码讲解、答辩教学、文档编写、也懂一些降重方面的技巧。热爱技术,喜欢钻研新工具和框架,也乐于通过代码解决实际问题,大家有技术代码这一块的问题可以问我! 💛💛想说的话:感谢大家的关注与支持! 💕💕文末获取源码联系 计算机程序员小杨 💜💜 网站实战项目 安卓/小程序实战项目 大数据实战项目 深度学习实战项目 计算机毕业设计选题 💜💜
一.开发工具简介
后端开发语言:Java 后端框架:Spring Boot(Spring+SpringMVC+Mybatis) 前端:微信小程序 数据库:MySQL 系统架构:C/S 开发工具:微信小程序开发工具
二.系统内容简介
《特产销售小程序》是一款基于微信生态的地方特产电商平台,采用C/S架构设计,后端使用Java语言配合Spring Boot框架(集成Spring+SpringMVC+Mybatis)构建稳定的服务端系统,前端运行于微信小程序平台,数据存储采用MySQL关系型数据库。系统涵盖用户管理、特产分类管理、特产信息管理、促销活动管理、举报记录管理、论坛分类管理、充值记录管理、交流论坛、系统管理、订单管理等十大核心功能模块。用户可以通过微信小程序便捷地浏览各类地方特产,参与促销活动,完成在线购买,同时平台提供交流论坛功能让用户分享特产使用心得和购买体验。管理员可通过后台系统对商品信息、用户数据、订单流程进行全面管控,确保平台运营的规范性和用户体验的优质性。整个系统设计注重用户操作的便利性和管理功能的完整性,为地方特产的线上销售提供了完整的技术解决方案。
三.系统功能演示
四.系统界面展示
五.系统源码展示
import org.apache.spark.sql.SparkSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;
@Service
public class ProductManagementService {
@Autowired
private ProductMapper productMapper;
@Autowired
private CategoryMapper categoryMapper;
private SparkSession spark = SparkSession.builder().appName("ProductAnalysis").master("local[*]").getOrCreate();
public Result addProduct(ProductAddRequest request) {
if (request.getProductName() == null || request.getProductName().trim().isEmpty()) {
return Result.error("商品名称不能为空");
}
if (request.getPrice() == null || request.getPrice().compareTo(BigDecimal.ZERO) <= 0) {
return Result.error("商品价格必须大于0");
}
QueryWrapper<Product> wrapper = new QueryWrapper<>();
wrapper.eq("product_name", request.getProductName()).eq("category_id", request.getCategoryId());
Product existProduct = productMapper.selectOne(wrapper);
if (existProduct != null) {
return Result.error("同类别下已存在相同名称的商品");
}
Category category = categoryMapper.selectById(request.getCategoryId());
if (category == null || category.getStatus() != 1) {
return Result.error("所选分类不存在或已禁用");
}
Product product = new Product();
product.setProductName(request.getProductName());
product.setProductDesc(request.getProductDesc());
product.setPrice(request.getPrice());
product.setStock(request.getStock());
product.setCategoryId(request.getCategoryId());
product.setProductImages(String.join(",", request.getImageUrls()));
product.setStatus(1);
product.setCreateTime(LocalDateTime.now());
product.setUpdateTime(LocalDateTime.now());
product.setSalesCount(0);
product.setOriginPlace(request.getOriginPlace());
int result = productMapper.insert(product);
if (result > 0) {
spark.sql("INSERT INTO product_analytics SELECT product_id, category_id, price, create_time FROM products WHERE product_id = " + product.getProductId());
return Result.success("商品添加成功", product);
}
return Result.error("商品添加失败");
}
}
@Service
public class OrderManagementService {
@Autowired
private OrderMapper orderMapper;
@Autowired
private OrderItemMapper orderItemMapper;
@Autowired
private ProductMapper productMapper;
@Autowired
private UserMapper userMapper;
private SparkSession spark = SparkSession.builder().appName("OrderAnalysis").master("local[*]").getOrCreate();
public Result createOrder(OrderCreateRequest request) {
User user = userMapper.selectById(request.getUserId());
if (user == null || user.getStatus() != 1) {
return Result.error("用户不存在或已被禁用");
}
if (request.getOrderItems() == null || request.getOrderItems().isEmpty()) {
return Result.error("订单商品列表不能为空");
}
BigDecimal totalAmount = BigDecimal.ZERO;
for (OrderItemRequest item : request.getOrderItems()) {
Product product = productMapper.selectById(item.getProductId());
if (product == null || product.getStatus() != 1) {
return Result.error("商品[" + item.getProductId() + "]不存在或已下架");
}
if (product.getStock() < item.getQuantity()) {
return Result.error("商品[" + product.getProductName() + "]库存不足");
}
BigDecimal itemTotal = product.getPrice().multiply(new BigDecimal(item.getQuantity()));
totalAmount = totalAmount.add(itemTotal);
}
if (user.getBalance().compareTo(totalAmount) < 0) {
return Result.error("用户余额不足,请先充值");
}
String orderNo = "ORD" + System.currentTimeMillis() + String.format("%04d", (int)(Math.random() * 10000));
Order order = new Order();
order.setOrderNo(orderNo);
order.setUserId(request.getUserId());
order.setTotalAmount(totalAmount);
order.setOrderStatus(1);
order.setPaymentStatus(0);
order.setDeliveryAddress(request.getDeliveryAddress());
order.setReceiverName(request.getReceiverName());
order.setReceiverPhone(request.getReceiverPhone());
order.setCreateTime(LocalDateTime.now());
order.setUpdateTime(LocalDateTime.now());
orderMapper.insert(order);
for (OrderItemRequest itemReq : request.getOrderItems()) {
Product product = productMapper.selectById(itemReq.getProductId());
OrderItem orderItem = new OrderItem();
orderItem.setOrderId(order.getOrderId());
orderItem.setProductId(itemReq.getProductId());
orderItem.setProductName(product.getProductName());
orderItem.setProductPrice(product.getPrice());
orderItem.setQuantity(itemReq.getQuantity());
orderItem.setSubtotal(product.getPrice().multiply(new BigDecimal(itemReq.getQuantity())));
orderItemMapper.insert(orderItem);
product.setStock(product.getStock() - itemReq.getQuantity());
product.setSalesCount(product.getSalesCount() + itemReq.getQuantity());
productMapper.updateById(product);
}
user.setBalance(user.getBalance().subtract(totalAmount));
userMapper.updateById(user);
spark.sql("INSERT INTO order_analytics SELECT order_id, user_id, total_amount, create_time FROM orders WHERE order_id = " + order.getOrderId());
return Result.success("订单创建成功", order);
}
}
@Service
public class PromotionManagementService {
@Autowired
private PromotionMapper promotionMapper;
@Autowired
private PromotionProductMapper promotionProductMapper;
@Autowired
private ProductMapper productMapper;
private SparkSession spark = SparkSession.builder().appName("PromotionAnalysis").master("local[*]").getOrCreate();
public Result createPromotion(PromotionCreateRequest request) {
if (request.getPromotionName() == null || request.getPromotionName().trim().isEmpty()) {
return Result.error("促销活动名称不能为空");
}
if (request.getStartTime() == null || request.getEndTime() == null) {
return Result.error("活动开始时间和结束时间不能为空");
}
if (request.getStartTime().isAfter(request.getEndTime())) {
return Result.error("活动开始时间不能晚于结束时间");
}
if (request.getEndTime().isBefore(LocalDateTime.now())) {
return Result.error("活动结束时间不能早于当前时间");
}
if (request.getDiscountRate() == null || request.getDiscountRate().compareTo(BigDecimal.ZERO) <= 0 || request.getDiscountRate().compareTo(new BigDecimal("1")) >= 0) {
return Result.error("折扣率必须在0-1之间");
}
QueryWrapper<Promotion> wrapper = new QueryWrapper<>();
wrapper.eq("promotion_name", request.getPromotionName()).eq("status", 1);
Promotion existPromotion = promotionMapper.selectOne(wrapper);
if (existPromotion != null) {
return Result.error("已存在同名的有效促销活动");
}
Promotion promotion = new Promotion();
promotion.setPromotionName(request.getPromotionName());
promotion.setPromotionDesc(request.getPromotionDesc());
promotion.setPromotionType(request.getPromotionType());
promotion.setDiscountRate(request.getDiscountRate());
promotion.setStartTime(request.getStartTime());
promotion.setEndTime(request.getEndTime());
promotion.setStatus(1);
promotion.setCreateTime(LocalDateTime.now());
promotion.setUpdateTime(LocalDateTime.now());
promotion.setParticipantCount(0);
promotionMapper.insert(promotion);
if (request.getProductIds() != null && !request.getProductIds().isEmpty()) {
for (Long productId : request.getProductIds()) {
Product product = productMapper.selectById(productId);
if (product == null || product.getStatus() != 1) {
continue;
}
QueryWrapper<PromotionProduct> ppWrapper = new QueryWrapper<>();
ppWrapper.eq("product_id", productId).eq("promotion_status", 1);
PromotionProduct existPP = promotionProductMapper.selectOne(ppWrapper);
if (existPP != null) {
continue;
}
PromotionProduct promotionProduct = new PromotionProduct();
promotionProduct.setPromotionId(promotion.getPromotionId());
promotionProduct.setProductId(productId);
promotionProduct.setOriginalPrice(product.getPrice());
promotionProduct.setPromotionPrice(product.getPrice().multiply(request.getDiscountRate()));
promotionProduct.setPromotionStatus(1);
promotionProduct.setCreateTime(LocalDateTime.now());
promotionProductMapper.insert(promotionProduct);
}
}
spark.sql("INSERT INTO promotion_analytics SELECT promotion_id, discount_rate, start_time, end_time FROM promotions WHERE promotion_id = " + promotion.getPromotionId());
return Result.success("促销活动创建成功", promotion);
}
}
六.系统文档展示
结束
💕💕文末获取源码联系 计算机程序员小杨