前言
在前面的开发中,我们成功完成了商品分类和商品信息的搭建,开发了收银台基础。现在,我们将进一步完善收银台的功能,添加开卡和结算功能,并在后台实现会员卡的创建和订单保存。同时,我们还将保存页面vue data数据用于修改订单
1.收银台添加开卡功能 后期不仅限开发 还有续卡 套餐...
2.结算后需要生成订单在此注意几个订单的问题
- 需要有主订单表 一个订单有多个商品需要创建一个订单详情表与之关联
- 还需要创建一个支付方式表 一个订单有多种支付方式
- 订单表需要关联会员id便于筛查和查询消费记录
- 添加状态字段用于消单、改单 (并创建一个表保存当前vue实例的data用于修改订单)
以下为相关表格
java
CREATE TABLE `business_sell` (
`SELL_ID` varchar(32) NOT NULL COMMENT '订单id',
`SELL_NO` varchar(255) DEFAULT NULL COMMENT '订单号',
`SERIAL_NO` varchar(32) DEFAULT NULL COMMENT '流水号',
`MEMBER_ID` varchar(32) DEFAULT NULL COMMENT '会员ID',
`MEMBER_NAME` varchar(255) DEFAULT NULL COMMENT '会员名称',
`MEMBER_CARD_ID` varchar(32) DEFAULT NULL COMMENT '会员卡id',
`SELL_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '消费金额',
`REAL_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '实际入账',
`SELL_TYPE` tinyint(2) DEFAULT NULL COMMENT '1开卡 2续卡 3项目/卖品',
`SELL_STATUS` tinyint(2) DEFAULT '0' COMMENT '0正常 1取消',
`DELETED` tinyint(2) DEFAULT '0' COMMENT '0正常 1删除',
`VERSION` bigint(10) DEFAULT '0' COMMENT '乐观锁字段',
`SHOP_ID` varchar(32) DEFAULT NULL COMMENT '门店id',
`SHOP_NAME` varchar(255) DEFAULT NULL COMMENT '门店名',
`CREATE_NAME` varchar(255) DEFAULT NULL COMMENT '创建人',
`CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间',
`CREATE_ID` varchar(32) DEFAULT NULL COMMENT '创建人id',
`UPDATE_TIME` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`UPDATE_NAME` varchar(255) DEFAULT NULL COMMENT '修改人',
`UPDATE_ID` varchar(32) DEFAULT NULL COMMENT '修改人id',
`MEMBER_CARD_AFTER_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '消费后金额',
`MEMBER_CARD_BEFORE_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '消费前赠送金额',
`MEMBER_CARD_BEFORE_GIVE_AMOUNT` decimal(10,2) DEFAULT NULL,
`MEMBER_CARD_AFTER_GIVE_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '消费后赠送金额',
PRIMARY KEY (`SELL_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单';
java
CREATE TABLE `business_sell_detail` (
`SELL_DETAIL_ID` varchar(32) NOT NULL COMMENT '销售细单id',
`MEMBER_ID` varchar(32) DEFAULT NULL COMMENT '会员id',
`SELL_ID` varchar(32) DEFAULT NULL COMMENT '订单id',
`SELL_TYPE` tinyint(2) DEFAULT NULL COMMENT '1开卡 2续卡 3项目 4卖品',
`MEMBER_CARD_ID` varchar(32) DEFAULT NULL COMMENT '会员卡id',
`PRODUCT_ID` varchar(32) DEFAULT NULL COMMENT '商品ID',
`PRODUCT_NAME` varchar(255) DEFAULT NULL COMMENT '商品名',
`COUNT` int(10) DEFAULT '1' COMMENT '商品数量',
`DISCOUNT` decimal(10,2) DEFAULT NULL COMMENT '折扣',
`AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '金额',
`REAL_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '实际金额',
`CARD_ID` varchar(32) DEFAULT NULL COMMENT '卡项ID',
`CARD_NAME` varchar(255) DEFAULT NULL COMMENT '卡名',
`GIVE_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '赠送金额',
`SHOP_ID` varchar(32) DEFAULT NULL COMMENT '门店id',
`SHOP_NAME` varchar(255) DEFAULT NULL COMMENT '门店名',
`CREATE_NAME` varchar(255) DEFAULT NULL COMMENT '创建人',
`CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间',
`CREATE_ID` varchar(32) DEFAULT NULL COMMENT '创建人id',
`UPDATE_TIME` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`UPDATE_NAME` varchar(255) DEFAULT NULL COMMENT '修改人',
`UPDATE_ID` varchar(32) DEFAULT NULL COMMENT '修改人id',
`SELL_STATUS` tinyint(2) DEFAULT '0' COMMENT '0正常 1取消',
PRIMARY KEY (`SELL_DETAIL_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单详情';
java
CREATE TABLE `business_sellpay` (
`SELL_PAY_ID` varchar(32) NOT NULL COMMENT '支付id',
`SELL_ID` varchar(32) DEFAULT NULL COMMENT '销售单id',
`PAY_NAME` varchar(255) DEFAULT NULL COMMENT '支付方式名称',
`PAY_TYPE` tinyint(2) DEFAULT NULL COMMENT '1.卡金 2.扫码 3.现金 888.优惠 ',
`AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '金额',
PRIMARY KEY (`SELL_PAY_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单支付';
java
CREATE TABLE `business_selljson` (
`JSON_ID` varchar(32) NOT NULL,
`SELL_ID` varchar(32) DEFAULT NULL COMMENT '订单id',
`SELL_JSON` json DEFAULT NULL COMMENT '获得下订单时的JSON',
PRIMARY KEY (`JSON_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='订单json';
3.订单创建完毕后还需要创建会员卡
这样后续就可以选择会员卡卡金支付了
java
CREATE TABLE `business_member_card` (
`MEMBER_CARD_ID` varchar(32) NOT NULL COMMENT '会员卡id',
`MEMBER_ID` varchar(32) DEFAULT NULL COMMENT '会员id',
`CARD_ID` varchar(32) DEFAULT NULL COMMENT '卡项ID',
`CARD_NO` varchar(255) DEFAULT NULL COMMENT '卡号',
`CARD_NAME` varchar(255) DEFAULT NULL COMMENT '卡名称',
`AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '余额',
`GIVE_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '赠送金额',
`DISCOUNT` decimal(10,2) DEFAULT NULL COMMENT '商品折扣',
`BUILD_CARD_AMOUNT` decimal(10,2) DEFAULT NULL COMMENT '开卡金额',
`PUSH_MONEY` decimal(10,2) DEFAULT NULL COMMENT '提成比例',
`CARD_STATUS` tinyint(2) DEFAULT '0' COMMENT '0正常 1取消',
`DELETED` tinyint(2) DEFAULT '0' COMMENT '0正常 1删除',
`VERSION` bigint(10) DEFAULT '0' COMMENT '乐观锁字段',
`SHOP_ID` varchar(32) DEFAULT NULL COMMENT '门店id',
`SHOP_NAME` varchar(255) DEFAULT NULL COMMENT '门店名',
`CREATE_NAME` varchar(255) DEFAULT NULL COMMENT '创建人',
`CREATE_TIME` datetime DEFAULT NULL COMMENT '创建时间',
`CREATE_ID` varchar(32) DEFAULT NULL COMMENT '创建人id',
`UPDATE_TIME` datetime DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP COMMENT '修改时间',
`UPDATE_NAME` varchar(255) DEFAULT NULL COMMENT '修改人',
`UPDATE_ID` varchar(32) DEFAULT NULL COMMENT '修改人id',
PRIMARY KEY (`MEMBER_CARD_ID`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='会员卡';
java
package com.dd.admin.business.pay.service.impl;
import com.dd.admin.business.card.entity.Card;
import com.dd.admin.business.card.service.CardService;
import com.dd.admin.business.memberCard.domain.MemberCardVo;
import com.dd.admin.business.memberCard.entity.MemberCard;
import com.dd.admin.business.memberCard.service.MemberCardService;
import com.dd.admin.business.pay.domain.BaseSell;
import com.dd.admin.business.pay.domain.BuildCardForm;
import com.dd.admin.business.pay.domain.BuildCardSell;
import com.dd.admin.business.pay.service.AddSellDetailService;
import com.dd.admin.business.sell.entity.Sell;
import com.dd.admin.business.sell.service.SellService;
import com.dd.admin.business.sellDetail.entity.SellDetail;
import com.dd.admin.business.sellDetail.service.SellDetailService;
import com.dd.admin.business.sellPay.entity.Sellpay;
import com.dd.admin.business.sellPay.service.SellpayService;
import com.dd.admin.common.exception.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import static com.dd.admin.business.pay.enmus.CashierExceptionEnum.CARDNO_ALREADY_EXIST;
@Service
public class SellDetailBuildCard implements AddSellDetailService {
@Autowired
private CardService cardService;
@Autowired
private MemberCardService memberCardService;
@Autowired
private SellDetailService sellDetailService;
@Autowired
private SellpayService sellpayService;
@Autowired
private SellService sellService;
@Override
public void addSellDetail(Sell sell, BaseSell sellDto) {
//转换数据
BuildCardSell buildCardSell = (BuildCardSell) sellDto;
// 1 获取开卡金额 等信息 先开卡
String cardId = buildCardSell.getBuildCardForm().getCardId();
//获取需要的开卡信息
Card card = cardService.getById(cardId);
//开卡
MemberCard memberCard = buildMemberCard(sell, buildCardSell.getBuildCardForm(), card);
//2生成销售细单
SellDetail sellDetail = addSellDetail(sell,buildCardSell,memberCard);
//添加支付方式
sellpayService.addSellPayList(buildCardSell.getSellPayList(),sell.getSellId());
//4因为是开卡还要设置额外信息
Sell extraSellInfo = new Sell();
extraSellInfo.setSellId(sell.getSellId());
//设置会员信息
extraSellInfo.setMemberId(buildCardSell.getMemberId());
extraSellInfo.setMemberName(buildCardSell.getMemberName());
//设置订单的卡信息
extraSellInfo.setMemberCardId(memberCard.getMemberCardId());
//设置订单的卡余额
extraSellInfo.setMemberCardBeforeAmount(BigDecimal.ZERO);
extraSellInfo.setMemberCardBeforeGiveAmount(BigDecimal.ZERO);
extraSellInfo.setMemberCardAfterAmount(memberCard.getAmount());
extraSellInfo.setMemberCardAfterGiveAmount(memberCard.getGiveAmount());
sellService.updateById(extraSellInfo);
}
MemberCard buildMemberCard(Sell sell, BuildCardForm buildCardForm, Card card){
//设置卡的基本和余额信息
MemberCard memberCard = new MemberCard();
memberCard.setMemberId(sell.getMemberId());
memberCard.setCardId(card.getCardId());
memberCard.setCardName(card.getCardName());
String cardNo = buildCardForm.getCardNo();
MemberCardVo membercardVo = memberCardService.selectOneByCardNo(cardNo);
if(membercardVo!=null){
throw new ApiException(CARDNO_ALREADY_EXIST);
}
memberCard.setCardNo(buildCardForm.getCardNo());
memberCard.setAmount(buildCardForm.getCardAmount());
memberCard.setBuildCardAmount(buildCardForm.getCardAmount());
memberCard.setGiveAmount(buildCardForm.getGiveAmount());
//获取订单的卡折扣信息 设置进会员卡中
memberCard.setDiscount(card.getCardDiscount());
//设置该卡的提成金额
memberCard.setPushMoney(card.getCardPushPercent());
memberCardService.save(memberCard);
return memberCard;
}
SellDetail addSellDetail(Sell sell,BuildCardSell buildCardSell,MemberCard membercard){
BuildCardForm buildCardForm = buildCardSell.getBuildCardForm();
SellDetail sellDetail = new SellDetail();
//3设置订单id 订单类型 订单状态
sellDetail.setSellId(sell.getSellId());
sellDetail.setSellType(sell.getSellType());
sellDetail.setMemberId(sell.getMemberId());
//设置商品信息
sellDetail.setCardId(buildCardForm.getCardId());
sellDetail.setCardName(buildCardForm.getCardName());
sellDetail.setAmount(buildCardForm.getCardAmount());
sellDetail.setGiveAmount(buildCardForm.getGiveAmount());
sellDetail.setRealAmount(sell.getRealAmount());
//设置会员信息
sellDetail.setMemberCardId(membercard.getMemberCardId());
//开卡后卡金和赠送金
sellDetail.setAmount(membercard.getAmount());
sellDetail.setGiveAmount(membercard.getGiveAmount());
//保存销售细单
sellDetailService.save(sellDetail);
return sellDetail;
}
}
后续我们需要完成收银台的选择会员卡支付
订单管理功能