This commit is contained in:
yangdanqi 2022-05-12 09:42:50 +08:00
commit 83be387381
29 changed files with 603 additions and 288 deletions

View File

@ -1,7 +1,6 @@
package com.ghy.web.controller.goods;
import com.ghy.common.annotation.Log;
import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.common.core.page.TableDataInfo;
@ -86,11 +85,6 @@ public class GoodsController extends BaseController {
@PostMapping("/add")
@ResponseBody
public AjaxResult addSave(@Validated Goods goods) {
if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsNameUnique(goods))) {
return error("新增商品'" + goods.getGoodsName() + "'失败,商品名称已存在");
} else if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsCodeUnique(goods))) {
return error("新增商品'" + goods.getGoodsName() + "'失败,商品编码已存在");
}
goods.setCreateBy(getLoginName());
goods.setDeptId(getSysUser().getDeptId());
return toAjax(goodsService.insertGoods(goods));
@ -102,6 +96,8 @@ public class GoodsController extends BaseController {
@RequiresPermissions("goods:goods:edit")
@GetMapping("/edit/{goodsId}")
public String edit(@PathVariable("goodsId") Long goodsId, ModelMap mmap) {
Long parentId = ShiroUtils.getSysUser().getParentId();
mmap.put("deptGoodsCategories", deptGoodsCategoryService.list(parentId));
mmap.put("goods", goodsService.selectById(goodsId));
return PREFIX + "/edit";
}
@ -114,11 +110,6 @@ public class GoodsController extends BaseController {
@PostMapping("/edit")
@ResponseBody
public AjaxResult editSave(@Validated Goods goods) {
if (UserConstants.GOODS_NAME_NOT_UNIQUE.equals(goodsService.checkGoodsNameUnique(goods))) {
return error("修改商品'" + goods.getGoodsName() + "'失败,商品名称已存在");
} else if (UserConstants.GOODS_CODE_NOT_UNIQUE.equals(goodsService.checkGoodsCodeUnique(goods))) {
return error("修改商品'" + goods.getGoodsCode() + "'失败,商品编码已存在");
}
goods.setUpdateBy(getLoginName());
return toAjax(goodsService.updateGoods(goods));
}

View File

@ -2,10 +2,24 @@ package com.ghy.web.controller.order;
import com.ghy.common.core.controller.BaseController;
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.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import java.math.BigDecimal;
import java.util.List;
/**
* @author clunt
* 下单接口
@ -14,19 +28,46 @@ import org.springframework.web.bind.annotation.RequestMapping;
@RequestMapping("/order")
public class OrderController extends BaseController {
@PostMapping("/app")
public AjaxResult appOrder(){
//TODO 校验商品信息(库存)
@Autowired
private CustomerService customerService;
//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 生成财务细单(含分销等.)
return AjaxResult.success();
}

View File

@ -0,0 +1,53 @@
package com.ghy.web.controller.pay;
import com.ghy.common.adapay.AdapayService;
import com.ghy.common.adapay.callback.PayCallback;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
import com.ghy.order.domain.OrderMaster;
import com.ghy.order.service.OrderMasterService;
import com.huifu.adapay.core.exception.BaseAdaPayException;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Map;
/**
* 支付宝支付API
*
* @author HH 2022/5/10
*/
@RestController
@RequestMapping("pay/ali")
public class AlipayController extends BaseController {
@Resource
private PayCallback payCallback;
@Resource
private AdapayService adapayService;
@Resource
private OrderMasterService orderMasterService;
/**
* 支付宝正扫支付
*/
@PostMapping("qr")
public AjaxResult qrPay(String orderMasterCode) {
OrderMaster orderMaster = orderMasterService.selectByCode(orderMasterCode);
if (orderMaster == null) {
return AjaxResult.error("订单不存在");
}
Map<String, Object> map;
try {
// TODO 订单里需要补充支付金额tittle简要描述分账信息description
map = adapayService.alipayQrPay(payCallback, orderMaster.getCode(), "orderMaster.get支付金额",
"orderMaster.getTittle()", "orderMaster.get简要描述", "orderMaster.getDivMember", "orderMaster.getDescription");
} catch (BaseAdaPayException e) {
logger.error("获取微信用户信息失败", e);
return AjaxResult.error();
}
return AjaxResult.success(map);
}
}

View File

@ -2,8 +2,8 @@ package com.ghy.web.controller.pay;
import com.alibaba.fastjson.JSONObject;
import com.ghy.common.adapay.AdapayService;
import com.ghy.common.adapay.callback.PayCallback;
import com.ghy.common.adapay.callback.model.WxLiteExpend;
import com.ghy.common.adapay.callback.reply.WxPubPayCallBack;
import com.ghy.common.config.WxConfig;
import com.ghy.common.core.controller.BaseController;
import com.ghy.common.core.domain.AjaxResult;
@ -21,7 +21,6 @@ import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.List;
import java.util.Map;
@Controller
@ -34,16 +33,20 @@ public class WxPayController extends BaseController {
private AdapayService adapayService;
@Resource
private OrderMasterService orderMasterService;
@Resource
private PayCallback payCallback;
/**
* 微信小程序支付
*/
@PostMapping("lite")
public AjaxResult litePay(HttpServletRequest request) {
String code = request.getParameter("code");
String orderMasterCode = request.getParameter("orderMasterCode");
List<OrderMaster> orderMasters = orderMasterService.selectOrderMasterList(new OrderMaster(orderMasterCode));
if (orderMasters.isEmpty()) {
OrderMaster orderMaster = orderMasterService.selectByCode(orderMasterCode);
if (orderMaster == null) {
return AjaxResult.error("订单不存在");
}
OrderMaster orderMaster = orderMasters.get(0);
JSONObject wxUser;
try {
wxUser = WxUtils.getOpenid(code, wxConfig.getAppId(), wxConfig.getSecret());
@ -54,11 +57,11 @@ public class WxPayController extends BaseController {
String openId = wxUser.getString("openid");
//调用adapay微信公众号支付.
WxLiteExpend expend = new WxLiteExpend();
expend.setOpen_id(openId);
expend.setOpenId(openId);
Map<String, Object> map;
try {
// TODO 订单里需要补充支付金额tittle简要描述分账信息description
map = adapayService.wxPubPay(new WxPubPayCallBack(), expend, orderMaster.getCode(), "orderMaster.get支付金额",
map = adapayService.wxPubPay(payCallback, expend, orderMaster.getCode(), "orderMaster.get支付金额",
"orderMaster.getTittle()", "orderMaster.get简要描述", "orderMaster.getDivMember", "orderMaster.getDescription");
} catch (BaseAdaPayException e) {
logger.error("获取微信用户信息失败", e);
@ -89,8 +92,8 @@ public class WxPayController extends BaseController {
logger.info("open id is " + openId);
//调用adapay微信公众号支付.
WxLiteExpend expend = new WxLiteExpend();
expend.setOpen_id(openId);
Map<String, Object> map = adapayService.wxPubPay(new WxPubPayCallBack(), expend, "wxPay123456" + Math.ceil(Math.random() * 100), "1.00",
expend.setOpenId(openId);
Map<String, Object> map = adapayService.wxPubPay(payCallback, expend, "wxPay123456" + Math.ceil(Math.random() * 100), "1.00",
"测试商品", "测试商品detail", null, "description");
//拼接消息给前端.前端通过JSAPI调用微信支付
map.forEach((key, value) -> {

View File

@ -0,0 +1,34 @@
package com.ghy.web.core;
import com.ghy.common.adapay.callback.PayCallback;
import com.ghy.common.adapay.callback.model.PayReply;
import com.ghy.order.service.OrderDetailService;
import com.ghy.order.service.OrderMasterService;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import javax.annotation.Resource;
/**
* 用户支付后
*/
@Configuration
public class AfterPay {
@Resource
OrderMasterService orderMasterService;
@Resource
OrderDetailService orderDetailService;
@Bean
public PayCallback payCallback() {
return new PayCallback() {
@Override
public void onReply(PayReply reply) {
// TODO 修改 OrderMaster 订单状态
// TODO 修改 OrderDetail 订单状态
// TODO 保存支付结果到MySQL
}
};
}
}

View File

@ -13,7 +13,8 @@
<div class="form-group">
<label class="col-sm-4 control-label is-required">商品名称:</label>
<div class="col-sm-8">
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30" required>
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30"
required>
</div>
</div>
</div>
@ -21,7 +22,8 @@
<div class="form-group">
<label class="col-sm-4 control-label is-required">价格:</label>
<div class="col-sm-8">
<input name="goodsPrice" placeholder="请输入商品价格" class="form-control" type="text" maxlength="12" required>
<input name="goodsPrice" placeholder="请输入商品价格" class="form-control" type="text" maxlength="12"
required>
</div>
</div>
</div>
@ -31,7 +33,8 @@
<div class="form-group">
<label class="col-sm-4 control-label is-required">优惠价:</label>
<div class="col-sm-8">
<input name="discountsPrice" placeholder="请输入优惠价" class="form-control" type="text" maxlength="12" required>
<input name="discountsPrice" placeholder="请输入优惠价" class="form-control" type="text"
maxlength="12" required>
</div>
</div>
</div>
@ -39,7 +42,8 @@
<div class="form-group">
<label class="col-sm-4 control-label is-required">团购价:</label>
<div class="col-sm-8">
<input name="groupPrice" placeholder="请输入团购价" class="form-control" type="text" maxlength="12" required>
<input name="groupPrice" placeholder="请输入团购价" class="form-control" type="text" maxlength="12"
required>
</div>
</div>
</div>
@ -50,7 +54,8 @@
<label class="col-sm-4 control-label">商品类别:</label>
<div class="col-xs-8">
<select name="deptGoodsCategoryId" class="form-control m-b">
<option th:each="item : ${deptGoodsCategories}" th:text="${item.goodsCategoryName}" th:value="${item.deptGoodsCategoryId}"></option>
<option th:each="item : ${deptGoodsCategories}" th:text="${item.goodsCategoryName}"
th:value="${item.deptGoodsCategoryId}"></option>
</select>
</div>
</div>
@ -60,7 +65,8 @@
<label class="col-sm-4 control-label">状态:</label>
<div class="col-sm-8">
<select name="status" class="form-control m-b" th:with="type=${@dict.getType('goods_status')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"></option>
<option th:each="dict : ${type}" th:text="${dict.dictLabel}"
th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
@ -71,7 +77,8 @@
<div class="form-group">
<label class="col-sm-4 control-label is-required">商品库存:</label>
<div class="col-sm-8">
<input name="goodsNumber" placeholder="请输入商品库存" class="form-control" type="text" maxlength="12" required>
<input name="goodsNumber" placeholder="请输入商品库存" class="form-control" type="text" maxlength="12"
required>
</div>
</div>
</div>
@ -91,25 +98,16 @@
</form>
</div>
<div class="row">
<div class="col-sm-offset-5 col-sm-10">
<button type="button" class="btn btn-sm btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
<button type="button" class="btn btn-sm btn-danger" onclick="closeItem()"><i class="fa fa-reply-all"></i>关 闭 </button>
</div>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script>
var prefix = ctx + "goods/goods";
$("#form-goods-add").validate({
onkeyup: false,
rules:{
},
messages: {
},
rules: {},
messages: {},
focusCleanup: true
});
@ -117,7 +115,7 @@
if ($.validate.form()) {
var data = $("#form-goods-add").serializeArray();
$.operate.saveTab(prefix + "/add", data);
$.modal.close(index);
$.modal.close();
}
}

View File

@ -0,0 +1,134 @@
<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
<th:block th:include="include :: header('修改商品')"/>
<th:block th:include="include :: select2-css"/>
</head>
<body>
<div class="main-content">
<form class="form-horizontal" id="form-goods-edit" th:object="${goods}">
<input id="goodsId" name="goodsId" type="hidden" th:field="*{goodsId}"/>
<h4 class="form-header h4">基本信息</h4>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label is-required">商品名称:</label>
<div class="col-sm-8">
<input name="goodsName" placeholder="请输入商品名称" class="form-control" type="text" maxlength="30"
th:field="*{goodsName}"
required>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label is-required">价格:</label>
<div class="col-sm-8">
<input name="goodsPrice" placeholder="请输入商品价格" class="form-control" type="text" maxlength="12"
th:field="*{goodsPrice}"
required>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label is-required">优惠价:</label>
<div class="col-sm-8">
<input name="discountsPrice" placeholder="请输入优惠价" class="form-control" type="text"
th:field="*{discountsPrice}"
maxlength="12" required>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label is-required">团购价:</label>
<div class="col-sm-8">
<input name="groupPrice" placeholder="请输入团购价" class="form-control" type="text" maxlength="12"
th:field="*{groupPrice}"
required>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label">商品类别:</label>
<div class="col-xs-8">
<select name="deptGoodsCategoryId" class="form-control m-b">
<option th:each="item : ${deptGoodsCategories}" th:text="${item.goodsCategoryName}"
th:value="${item.deptGoodsCategoryId}" th:field="*{deptGoodsCategoryId}"></option>
</select>
</div>
</div>
</div>
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label">状态:</label>
<div class="col-sm-8">
<select name="status" class="form-control m-b" th:with="type=${@dict.getType('goods_status')}">
<option th:each="dict : ${type}" th:text="${dict.dictLabel}" th:field="*{status}"
th:value="${dict.dictValue}"></option>
</select>
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-sm-6">
<div class="form-group">
<label class="col-sm-4 control-label is-required">商品库存:</label>
<div class="col-sm-8">
<input name="goodsNumber" placeholder="请输入商品库存" class="form-control" type="text" maxlength="12"
th:field="*{goodsNumber}"
required>
</div>
</div>
</div>
</div>
<h4 class="form-header h4">其他信息</h4>
<div class="row">
<div class="col-sm-12">
<div class="form-group">
<label class="col-xs-2 control-label">备注:</label>
<div class="col-xs-10">
<textarea name="remark" maxlength="500" class="form-control" rows="3"
th:field="*{remark}"></textarea>
</div>
</div>
</div>
</div>
</form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
var prefix = ctx + "goods/goods";
$("#form-goods-edit").validate({
onkeyup: false,
rules: {},
messages: {},
focusCleanup: true
});
function submitHandler() {
if ($.validate.form()) {
var data = $("#form-goods-edit").serializeArray();
$.operate.saveTab(prefix + "/edit", data);
$.modal.close();
}
}
</script>
</body>
</html>

View File

@ -159,7 +159,7 @@ public class AdapayService {
}
/**
* 微信小程序支付
* 微信公众号支付
*/
public Map<String, Object> wxPubPay(PayCallback callback, WxLiteExpend expend, String orderNo, String payAmt,
String goodsTittle, String goodsDesc, String divMembers, String description) throws BaseAdaPayException {

View File

@ -1,14 +1,10 @@
package com.ghy.common.adapay.callback.model;
import lombok.Data;
/**
* 所有支付渠道扩展参数的父类
*
* @author HH 2022/3/31
*/
@Data
public class Expend {
private String open_id;
}

View File

@ -1,15 +0,0 @@
package com.ghy.common.adapay.callback.reply;
import com.ghy.common.adapay.callback.PayCallback;
import com.ghy.common.adapay.callback.model.PayReply;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class WxPubPayCallBack implements PayCallback {
@Override
public void onReply(PayReply reply) {
// 更新工单状态
log.info("wx pub pay response is : " + reply.toString());
}
}

View File

@ -4,6 +4,8 @@ import com.ghy.common.annotation.Excel;
import com.ghy.common.core.domain.BaseEntity;
import lombok.Data;
import java.util.List;
/**
* @author clunt
* 消费者实体
@ -37,5 +39,10 @@ public class Customer extends BaseEntity {
@Excel(name = "用户头像", cellType = Excel.ColumnType.STRING)
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.mapper.CustomerMapper;
import com.ghy.customer.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
@ -18,7 +17,7 @@ import java.util.List;
@Service
public class CustomerServiceImpl implements CustomerService {
@Autowired
@Resource
private CustomerMapper customerMapper;
@Override

View File

@ -11,6 +11,9 @@
<result property="password" column="password" />
<result property="status" column="status" />
<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="createTime" column="create_time" />
<result property="updateBy" column="update_by" />
@ -20,7 +23,7 @@
<sql id="selectCustomer">
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
</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,8 @@
package com.ghy.goods.mapper;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.request.AppGoodsRequest;
import org.apache.ibatis.annotations.Param;
import java.util.List;
@ -11,29 +13,35 @@ import java.util.List;
public interface GoodsMapper {
/**
* @param goods 商品属性
* @return 成功条数
* @param goods 商品信息
* @return 校验是否满足库存
*/
public int insertGoods(Goods goods);
int checkAGoodsStore(AppGoodsRequest goods);
/**
* @param goods 商品属性
* @return 成功条数
*/
public int updateGoods(Goods goods);
int insertGoods(Goods goods);
/**
* @param goods 商品属性
* @return 成功条数
*/
int updateGoods(Goods goods);
/**
* @param goods 商品入参
* @return 商品集合
*/
public List<Goods> selectGoodsList(Goods goods);
List<Goods> selectGoodsList(Goods goods);
/**
* @param goodsId 商品id
* @return 商品
*/
public Goods selectById(Long goodsId);
Goods selectById(Long goodsId);
/**
* 批量删除商品信息
@ -41,19 +49,19 @@ public interface GoodsMapper {
* @param goodsId 需要删除的数据ID
* @return 结果
*/
public int deleteGoodsByIds(Long[] goodsId);
int deleteGoodsByIds(Long[] goodsId);
/**
* @param goodsName 商品名称
* @return 商品信息
*/
public Goods checkGoodsNameUnique(String goodsName);
Goods checkGoodsNameUnique(String goodsName);
/**
* @param goodsCode 商品编码
* @return 商品信息
*/
public Goods checkGoodsCodeUnique(String goodsCode);
Goods checkGoodsCodeUnique(String goodsCode);
/**
* 用商品类别ID查询一条商品信息
@ -63,4 +71,13 @@ public interface GoodsMapper {
* @return 商品信息
*/
Goods selectOneByGoodsCategoryId(Long goodsCategoryId);
/**
* 设置商品编号
*
* @param goodsId 商品ID
* @param goodsCode 商品编号
* @return
*/
int setCode(@Param("goodsId") Long goodsId, @Param("goodsCode") String goodsCode);
}

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,58 +1,75 @@
package com.ghy.goods.service;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.request.AppGoodsRequest;
import java.math.BigDecimal;
import java.util.List;
/**
* 商品模块接口
*
* @author clunt
*/
public interface GoodsService {
/**
* @param goods 商品属性
* @return 成功条数
* @param goodsList 需要校验库存的商品list
* @return 校验结果
*/
public int insertGoods(Goods goods);
boolean checkStore(List<AppGoodsRequest> goodsList);
/**
* @param goodsList 需要校验库存的商品list
* @return 商品总价
*/
BigDecimal calculate(List<AppGoodsRequest> goodsList);
/**
* @param goods 商品属性
* @return 成功条数
*/
public int updateGoods(Goods goods);
int insertGoods(Goods goods);
/**
* @param goods 商品属性
* @return 成功条数
*/
int updateGoods(Goods goods);
/**
* @param goods 商品入参
* @return 商品集合
*/
public List<Goods> selectGoodsList(Goods goods);
List<Goods> selectGoodsList(Goods goods);
/**
* @param goodsId 商品id
* @return 商品
*/
public Goods selectById(Long goodsId);
Goods selectById(Long goodsId);
/**
* @param ids 商品ids
* @return 删除结果
*/
public int deleteGoodsByIds(String ids);
int deleteGoodsByIds(String ids);
/**
* 校验商品名称是否重复
*
* @param goods 商品属性
* @return 校验结果 1存在 0不存在
*/
public String checkGoodsNameUnique(Goods goods);
String checkGoodsNameUnique(Goods goods);
/**
* 校验商品编码是否重复
*
* @param goods 商品属性
* @return 校验结果 1存在 0不存在
*/
public String checkGoodsCodeUnique(Goods goods);
String checkGoodsCodeUnique(Goods goods);
}

View File

@ -6,14 +6,19 @@ import com.ghy.common.exception.ServiceException;
import com.ghy.common.utils.StringUtils;
import com.ghy.goods.domain.Goods;
import com.ghy.goods.mapper.GoodsMapper;
import com.ghy.goods.request.AppGoodsRequest;
import com.ghy.goods.service.GoodsService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.List;
/**
* 商品模块实现类
*
* @author clunt
*/
@Service
@ -23,8 +28,33 @@ public class GoodsServiceImpl implements GoodsService {
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
@Transactional(rollbackFor = Exception.class)
public int insertGoods(Goods goods) {
return goodsMapper.insertGoods(goods);
goodsMapper.insertGoods(goods);
Assert.notNull(goods.getGoodsId(), "操作失败");
String code = String.format("GD%019d", goods.getGoodsId());
return goodsMapper.setCode(goods.getGoodsId(), code);
}
@Override
@ -45,11 +75,9 @@ public class GoodsServiceImpl implements GoodsService {
@Override
public int deleteGoodsByIds(String ids) {
Long[] goodsIds = Convert.toLongArray(ids);
for (Long goodsId : goodsIds)
{
for (Long goodsId : goodsIds) {
Goods goods = selectById(goodsId);
if (countUserGoodsById(goods) > 0)
{
if (countUserGoodsById(goods) > 0) {
throw new ServiceException(String.format("%1$s正在使用,不能删除", goods.getGoodsName()));
}
}
@ -60,8 +88,7 @@ public class GoodsServiceImpl implements GoodsService {
public String checkGoodsNameUnique(Goods goods) {
Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
Goods info = goodsMapper.checkGoodsNameUnique(goods.getGoodsName());
if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue())
{
if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue()) {
return UserConstants.GOODS_NAME_NOT_UNIQUE;
}
return UserConstants.GOODS_NAME_UNIQUE;
@ -71,8 +98,7 @@ public class GoodsServiceImpl implements GoodsService {
public String checkGoodsCodeUnique(Goods goods) {
Long goodsId = StringUtils.isNull(goods.getGoodsId()) ? -1L : goods.getGoodsId();
Goods info = goodsMapper.checkGoodsCodeUnique(goods.getGoodsCode());
if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue())
{
if (StringUtils.isNotNull(info) && info.getGoodsId().longValue() != goodsId.longValue()) {
return UserConstants.GOODS_CODE_NOT_UNIQUE;
}
return UserConstants.GOODS_CODE_UNIQUE;

View File

@ -30,11 +30,15 @@
FROM goods
</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 goods
<set>
<if test="goodsCode != null and goodsCode != ''">goods_code = #{goodsCode},</if>
<if test="deptId != null and deptId != ''">dept_id = #{deptId},</if>
<if test="goodsName != null and goodsName != ''">goods_name = #{goodsName},</if>
<if test="goodsPrice != null and goodsPrice != ''">goods_price = #{goodsPrice},</if>
<if test="discountsPrice != null and discountsPrice != ''">discounts_price = #{discountsPrice},</if>
@ -52,6 +56,12 @@
WHERE goods_id = #{goodsId}
</update>
<update id="setCode">
UPDATE goods
SET goods_code = #{goodsCode}, update_time = sysdate()
WHERE goods_id = #{goodsId}
</update>
<insert id="insertGoods" parameterType="com.ghy.goods.domain.Goods" useGeneratedKeys="true" keyProperty="goodsId">
insert into goods(
<if test="goodsCode != null and goodsCode != ''">goods_code,</if>

View File

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

View File

@ -49,4 +49,11 @@ public interface OrderMasterMapper {
*/
OrderMaster checkOrderMasterCodeUnique(String orderMasterCode);
/**
* OrderMaster 查询主订单信息
*
* @param orderMasterCode 主订单code
* @return 主订单信息
*/
OrderMaster selectByCode(String orderMasterCode);
}

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;
import com.ghy.order.domain.OrderMaster;
import com.ghy.order.request.AppOrderRequest;
import java.util.List;
@ -11,6 +12,8 @@ import java.util.List;
*/
public interface OrderMasterService {
OrderMaster createMasterOrder(AppOrderRequest appOrderRequest);
/**
* @param orderMaster 主订单属性
* @return 成功条数
@ -36,6 +39,14 @@ public interface OrderMasterService {
*/
OrderMaster selectById(Long orderMasterId);
/**
* OrderMaster 查询主订单信息
*
* @param orderMasterCode 主订单code
* @return 主订单信息
*/
OrderMaster selectByCode(String orderMasterCode);
/**
* @param ids 主订单ids
* @return 删除结果

View File

@ -4,6 +4,7 @@ import com.ghy.common.constant.UserConstants;
import com.ghy.common.core.text.Convert;
import com.ghy.order.domain.OrderMaster;
import com.ghy.order.mapper.OrderMasterMapper;
import com.ghy.order.request.AppOrderRequest;
import com.ghy.order.service.OrderMasterService;
import org.springframework.stereotype.Service;
@ -21,6 +22,11 @@ public class OrderMasterServiceImpl implements OrderMasterService {
@Resource
private OrderMasterMapper orderMasterMapper;
@Override
public OrderMaster createMasterOrder(AppOrderRequest appOrderRequest) {
return null;
}
@Override
public int insertOrderMaster(OrderMaster orderMaster) {
return orderMasterMapper.insertOrderMaster(orderMaster);
@ -41,6 +47,11 @@ public class OrderMasterServiceImpl implements OrderMasterService {
return orderMasterMapper.selectById(orderMasterId);
}
@Override
public OrderMaster selectByCode(String orderMasterCode) {
return orderMasterMapper.selectByCode(orderMasterCode);
}
@Override
public int deleteOrderMasterByIds(String ids) {
Long[] orderMasterIds = Convert.toLongArray(ids);

View File

@ -133,4 +133,9 @@
WHERE `code` =#{orderMasterCode} LIMIT 1
</select>
<select id="selectByCode" parameterType="String" resultType="com.ghy.order.domain.OrderMaster">
<include refid="selectOrderMaster"/>
WHERE `code` = #{orderMasterCode}
</select>
</mapper>