Merge remote-tracking branch 'origin/master'

This commit is contained in:
HH 2022-05-11 20:10:10 +08:00
commit 2c5da04cc1
18 changed files with 180 additions and 104 deletions

View File

@ -2,10 +2,24 @@ package com.ghy.web.controller.order;
import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.utils.StringUtils;
import com.ghy.customer.domain.Customer;
import com.ghy.customer.service.CustomerService;
import com.ghy.goods.service.GoodsService;
import com.ghy.order.domain.OrderMaster;
import com.ghy.order.request.AppOrderRequest;
import com.ghy.order.service.OrderDetailService;
import com.ghy.order.service.OrderMasterService;
import com.ghy.payment.service.FinancialDetailService;
import com.ghy.payment.service.FinancialMasterService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import java.math.BigDecimal;
import java.util.List;
/** /**
* @author clunt * @author clunt
* 下单接口 * 下单接口
@ -14,19 +28,46 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/order") @RequestMapping("/order")
public class OrderController extends BaseController { public class OrderController extends BaseController {
@PostMapping("/app") @Autowired
public AjaxResult appOrder(){ private CustomerService customerService;
//TODO 校验商品信息(库存)
//TODO 计算商品费用和运费汇总 @Autowired
private GoodsService goodsService;
//TODO 生成主单 @Autowired
private OrderMasterService orderMasterService;
@Autowired
private OrderDetailService orderDetailService;
@Autowired
private FinancialMasterService financialMasterService;
@Autowired
private FinancialDetailService financialDetailService;
@PostMapping("/server/app")
public AjaxResult appOrder(AppOrderRequest appOrderRequest){
// 校验用户信息
Customer customer = customerService.selectByCustomerId(appOrderRequest.getCustomerId());
if(StringUtils.isNull(customer)){
return AjaxResult.error("用户不存在!");
}
// 校验商品信息(库存)
boolean flag = goodsService.checkStore(appOrderRequest.getGoodsList());
if(!flag){
return AjaxResult.error("库存不足!");
}
// 计算商品费用
BigDecimal totalPay = goodsService.calculate(appOrderRequest.getGoodsList());
//TODO 生成主单 and 细单
OrderMaster orderMaster = orderMasterService.createMasterOrder(appOrderRequest);
//TODO 生成细单 //TODO 生成细单
//TODO 生成财务主单 //TODO 生成财务主单
//TODO 生成财务细单 //TODO 生成财务细单(含分销等.)
return AjaxResult.success(); return AjaxResult.success();
} }

View File

@ -4,6 +4,8 @@ import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity; import com.ghy.common.core.domain.BaseEntity;
import lombok.Data; import lombok.Data;
import java.util.List;
/** /**
* @author clunt * @author clunt
* 消费者实体 * 消费者实体
@ -37,5 +39,10 @@ public class Customer extends BaseEntity {
@Excel(name = "用户头像", cellType = Excel.ColumnType.STRING) @Excel(name = "用户头像", cellType = Excel.ColumnType.STRING)
private String customerLogoUrl; private String customerLogoUrl;
@Excel(name = "上级分销人", cellType = Excel.ColumnType.NUMERIC)
private Long customerPlace;
@Excel(name = "祖级分销人", cellType = Excel.ColumnType.NUMERIC)
private Long parentCustomerPlace;
} }

View File

@ -1,34 +0,0 @@
package com.ghy.customer.domain;
import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
/**
* @author clunt
* 用户多级分销最多不超过3级
*/
@Data
public class CustomerPlace extends BaseEntity {
private static final long serialVersionUID = 1L;
@Excel(name = "分销id", cellType = Excel.ColumnType.NUMERIC)
private Long customerPlaceId;
@Excel(name = "用户id", cellType = Excel.ColumnType.NUMERIC)
private Long customerId;
@Excel(name = "父级id", cellType = Excel.ColumnType.NUMERIC)
private Long parentCustomerId;
@Excel(name = "分销类型", cellType = Excel.ColumnType.STRING)
private Integer placeType;
@Excel(name = "分销比例", cellType = Excel.ColumnType.STRING)
private String placeRate;
@Excel(name = "分销金额", cellType = Excel.ColumnType.STRING)
private String placeMoney;
}

View File

@ -1,11 +0,0 @@
package com.ghy.customer.mapper;
/**
* @author clunt
* 多级分销接口类
*/
public interface CustomerPlaceMapper {
}

View File

@ -1,15 +0,0 @@
package com.ghy.customer.service;
/**
* @author clunt
* 多级分销
*/
public interface CustomerPlaceService {
// 新增分销用户
// 获取用户分销关系
// 设置分销比例
}

View File

@ -1,15 +0,0 @@
package com.ghy.customer.service.impl;
import com.ghy.customer.service.CustomerPlaceService;
import org.springframework.stereotype.Service;
/**
* @author clunt
* 多级分销实现类
*/
@Service
public class CustomerPlaceServiceImpl implements CustomerPlaceService {
}

View File

@ -5,7 +5,6 @@ import com.ghy.common.exception.ServiceException;
import com.ghy.customer.domain.Customer; import com.ghy.customer.domain.Customer;
import com.ghy.customer.mapper.CustomerMapper; import com.ghy.customer.mapper.CustomerMapper;
import com.ghy.customer.service.CustomerService; import com.ghy.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -18,7 +17,7 @@ import java.util.List;
@Service @Service
public class CustomerServiceImpl implements CustomerService { public class CustomerServiceImpl implements CustomerService {
@Autowired @Resource
private CustomerMapper customerMapper; private CustomerMapper customerMapper;
@Override @Override

View File

@ -11,6 +11,9 @@
<result property="password" column="password" /> <result property="password" column="password" />
<result property="status" column="status" /> <result property="status" column="status" />
<result property="customerLogoUrl" column="customer_logo_url" /> <result property="customerLogoUrl" column="customer_logo_url" />
<result property="customerPlace" column="customer_place" />
<result property="parentCustomerPlace" column="parent_customer_place" />
<result property="customerLogoUrl" column="customer_logo_url" />
<result property="createBy" column="create_by" /> <result property="createBy" column="create_by" />
<result property="createTime" column="create_time" /> <result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" /> <result property="updateBy" column="update_by" />
@ -20,7 +23,7 @@
<sql id="selectCustomer"> <sql id="selectCustomer">
SELECT customer_id, name, account, phone, open_id, password, status, SELECT customer_id, name, account, phone, open_id, password, status,
customer_logo_url, create_by, create_time, remark customer_logo_url, customer_place, parent_customer_place, create_by, create_time, remark
FROM customer FROM customer
</sql> </sql>

View File

@ -1,20 +0,0 @@
<?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="com.ghy.customer.mapper.CustomerPlaceMapper">
<resultMap id="GoodsImgsResult" type="com.ghy.customer.domain.CustomerPlace">
<result property="customerPlaceId" column="customer_place_id"/>
<result property="customerId" column="customer_id" />
<result property="createBy" column="create_by" />
<result property="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
<result property="updateTime" column="update_time" />
<result property="remark" column="remark" />
</resultMap>
<sql id="selectCustomerPlace">
</sql>
</mapper>

View File

@ -1,6 +1,7 @@
package com.ghy.goods.mapper; package com.ghy.goods.mapper;
import com.ghy.goods.domain.Goods; import com.ghy.goods.domain.Goods;
import com.ghy.goods.request.AppGoodsRequest;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List; import java.util.List;
@ -11,6 +12,12 @@ import java.util.List;
*/ */
public interface GoodsMapper { public interface GoodsMapper {
/**
* @param goods 商品信息
* @return 校验是否满足库存
*/
int checkAGoodsStore(AppGoodsRequest goods);
/** /**
* @param goods 商品属性 * @param goods 商品属性
* @return 成功条数 * @return 成功条数

View File

@ -0,0 +1,21 @@
package com.ghy.goods.request;
import lombok.Data;
/**
* 小程序下单请求体
* @author clunt
*/
@Data
public class AppGoodsRequest {
// 商品id
private Long goodsId;
// 数量
private Integer num;
}

View File

@ -1,7 +1,9 @@
package com.ghy.goods.service; package com.ghy.goods.service;
import com.ghy.goods.domain.Goods; import com.ghy.goods.domain.Goods;
import com.ghy.goods.request.AppGoodsRequest;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@ -11,6 +13,18 @@ import java.util.List;
*/ */
public interface GoodsService { public interface GoodsService {
/**
* @param goodsList 需要校验库存的商品list
* @return 校验结果
*/
boolean checkStore(List<AppGoodsRequest> goodsList);
/**
* @param goodsList 需要校验库存的商品list
* @return 商品总价
*/
BigDecimal calculate(List<AppGoodsRequest> goodsList);
/** /**
* @param goods 商品属性 * @param goods 商品属性
* @return 成功条数 * @return 成功条数

View File

@ -6,12 +6,14 @@ import com.ghy.common.exception.ServiceException;
import com.ghy.common.utils.StringUtils; import com.ghy.common.utils.StringUtils;
import com.ghy.goods.domain.Goods; import com.ghy.goods.domain.Goods;
import com.ghy.goods.mapper.GoodsMapper; import com.ghy.goods.mapper.GoodsMapper;
import com.ghy.goods.request.AppGoodsRequest;
import com.ghy.goods.service.GoodsService; import com.ghy.goods.service.GoodsService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert; import org.springframework.util.Assert;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List; import java.util.List;
/** /**
@ -25,6 +27,27 @@ public class GoodsServiceImpl implements GoodsService {
@Resource @Resource
private GoodsMapper goodsMapper; private GoodsMapper goodsMapper;
@Override
public boolean checkStore(List<AppGoodsRequest> goodsList) {
for (AppGoodsRequest goods : goodsList) {
int num = goodsMapper.checkAGoodsStore(goods);
if (num == 0) {
return false;
}
}
return true;
}
@Override
public BigDecimal calculate(List<AppGoodsRequest> goodsList) {
BigDecimal totalPay = BigDecimal.ZERO;
for (AppGoodsRequest appGoodsRequest : goodsList){
Goods goods = goodsMapper.selectById(appGoodsRequest.getGoodsId());
totalPay = totalPay.add(goods.getGoodsPrice().multiply(BigDecimal.valueOf(appGoodsRequest.getNum())));
}
return totalPay;
}
@Override @Override
@Transactional(rollbackFor = Exception.class) @Transactional(rollbackFor = Exception.class)
public int insertGoods(Goods goods) { public int insertGoods(Goods goods) {

View File

@ -30,6 +30,12 @@
FROM goods FROM goods
</sql> </sql>
<select id="checkAGoodsStore" parameterType="com.ghy.goods.request.AppGoodsRequest" resultMap="GoodsResult">
<include refid="selectGoods" />
where goods_id = #{goodsId} and goods_number >= #{num}
</select>
<update id="updateGoods" parameterType="com.ghy.goods.domain.Goods"> <update id="updateGoods" parameterType="com.ghy.goods.domain.Goods">
UPDATE goods UPDATE goods
<set> <set>

View File

@ -23,6 +23,11 @@
<artifactId>ghy-common</artifactId> <artifactId>ghy-common</artifactId>
</dependency> </dependency>
<dependency>
<groupId>com.ghy</groupId>
<artifactId>ghy-goods</artifactId>
</dependency>
</dependencies> </dependencies>
</project> </project>

View File

@ -0,0 +1,36 @@
package com.ghy.order.request;
import com.ghy.goods.request.AppGoodsRequest;
import lombok.Data;
import java.util.List;
/**
* 小程序下单请求体
* @author clunt
*/
@Data
public class AppOrderRequest {
// 消费者id
private Long customerId;
// 用于计算价格等
private List<AppGoodsRequest> goodsList;
// 预约上门时间
private String serverTime;
// 地址
private Long addressId;
// 支付方式
private Integer payType;
//是否需要发票
private Integer isNeedBill;
// 备注
private String remark;
}

View File

@ -1,6 +1,7 @@
package com.ghy.order.service; package com.ghy.order.service;
import com.ghy.order.domain.OrderMaster; import com.ghy.order.domain.OrderMaster;
import com.ghy.order.request.AppOrderRequest;
import java.util.List; import java.util.List;
@ -11,6 +12,8 @@ import java.util.List;
*/ */
public interface OrderMasterService { public interface OrderMasterService {
OrderMaster createMasterOrder(AppOrderRequest appOrderRequest);
/** /**
* @param orderMaster 主订单属性 * @param orderMaster 主订单属性
* @return 成功条数 * @return 成功条数

View File

@ -4,6 +4,7 @@ import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.text.Convert; import com.ghy.common.core.text.Convert;
import com.ghy.order.domain.OrderMaster; import com.ghy.order.domain.OrderMaster;
import com.ghy.order.mapper.OrderMasterMapper; import com.ghy.order.mapper.OrderMasterMapper;
import com.ghy.order.request.AppOrderRequest;
import com.ghy.order.service.OrderMasterService; import com.ghy.order.service.OrderMasterService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -21,6 +22,11 @@ public class OrderMasterServiceImpl implements OrderMasterService {
@Resource @Resource
private OrderMasterMapper orderMasterMapper; private OrderMasterMapper orderMasterMapper;
@Override
public OrderMaster createMasterOrder(AppOrderRequest appOrderRequest) {
return null;
}
@Override @Override
public int insertOrderMaster(OrderMaster orderMaster) { public int insertOrderMaster(OrderMaster orderMaster) {
return orderMasterMapper.insertOrderMaster(orderMaster); return orderMasterMapper.insertOrderMaster(orderMaster);