添加会员等级管理和下单
This commit is contained in:
parent
f414a38498
commit
acae6552dc
@ -7,19 +7,14 @@ import java.util.Optional;
|
|||||||
import com.ruoyi.common.utils.SecurityUtils;
|
import com.ruoyi.common.utils.SecurityUtils;
|
||||||
import com.ruoyi.system.domain.CartItem;
|
import com.ruoyi.system.domain.CartItem;
|
||||||
import com.ruoyi.system.domain.OrderItem;
|
import com.ruoyi.system.domain.OrderItem;
|
||||||
|
import com.ruoyi.system.domain.VipItem;
|
||||||
import com.ruoyi.system.service.ICartItemService;
|
import com.ruoyi.system.service.ICartItemService;
|
||||||
|
import com.ruoyi.system.service.IVipItemService;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import org.springframework.beans.BeanUtils;
|
import org.springframework.beans.BeanUtils;
|
||||||
import org.springframework.security.access.prepost.PreAuthorize;
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.*;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PutMapping;
|
|
||||||
import org.springframework.web.bind.annotation.DeleteMapping;
|
|
||||||
import org.springframework.web.bind.annotation.PathVariable;
|
|
||||||
import org.springframework.web.bind.annotation.RequestBody;
|
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
|
||||||
import com.ruoyi.common.annotation.Log;
|
import com.ruoyi.common.annotation.Log;
|
||||||
import com.ruoyi.common.core.controller.BaseController;
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
import com.ruoyi.common.core.domain.AjaxResult;
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
@ -45,6 +40,9 @@ public class OrderController extends BaseController
|
|||||||
@Autowired
|
@Autowired
|
||||||
private ICartItemService cartItemService;
|
private ICartItemService cartItemService;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private IVipItemService vipItemService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 查询订单列表列表
|
* 查询订单列表列表
|
||||||
*/
|
*/
|
||||||
@ -120,7 +118,7 @@ public class OrderController extends BaseController
|
|||||||
return toAjax(orderService.deleteOrderByIds(ids));
|
return toAjax(orderService.deleteOrderByIds(ids));
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/create")
|
@PostMapping("/create-normal")
|
||||||
public AjaxResult createUserOrder(@RequestBody Order order) {
|
public AjaxResult createUserOrder(@RequestBody Order order) {
|
||||||
List<CartItem> items = cartItemService.selectCartItemListById(SecurityUtils.getUserId());
|
List<CartItem> items = cartItemService.selectCartItemListById(SecurityUtils.getUserId());
|
||||||
List<OrderItem> orderItemList = items.stream().map(item -> {
|
List<OrderItem> orderItemList = items.stream().map(item -> {
|
||||||
@ -138,4 +136,18 @@ public class OrderController extends BaseController
|
|||||||
order.setOrderItemList(orderItemList);
|
order.setOrderItemList(orderItemList);
|
||||||
return toAjax(orderService.insertOrder(order));
|
return toAjax(orderService.insertOrder(order));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostMapping("/create-vip")
|
||||||
|
public AjaxResult createUserVipOrder(@RequestBody Order order,
|
||||||
|
@RequestParam Long id) {
|
||||||
|
VipItem vipItem = vipItemService.selectVipItemById(id);
|
||||||
|
OrderItem orderItem = new OrderItem();
|
||||||
|
BeanUtils.copyProperties(vipItem, orderItem, "id");
|
||||||
|
orderItem.setCount(1L);
|
||||||
|
order.setUid(SecurityUtils.getUserId());
|
||||||
|
order.setTime(new Date());
|
||||||
|
order.setPirce(vipItem.getPrice().doubleValue());
|
||||||
|
order.setOrderItemList(List.of(orderItem));
|
||||||
|
return toAjax(orderService.insertOrder(order));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,103 @@
|
|||||||
|
package com.ruoyi.system.controller;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
import org.springframework.security.access.prepost.PreAuthorize;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import com.ruoyi.common.annotation.Log;
|
||||||
|
import com.ruoyi.common.core.controller.BaseController;
|
||||||
|
import com.ruoyi.common.core.domain.AjaxResult;
|
||||||
|
import com.ruoyi.common.enums.BusinessType;
|
||||||
|
import com.ruoyi.system.domain.VipItem;
|
||||||
|
import com.ruoyi.system.service.IVipItemService;
|
||||||
|
import com.ruoyi.common.utils.poi.ExcelUtil;
|
||||||
|
import com.ruoyi.common.core.page.TableDataInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员等级Controller
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-11-11
|
||||||
|
*/
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/system/vip")
|
||||||
|
public class VipItemController extends BaseController
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private IVipItemService vipItemService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询会员等级列表
|
||||||
|
*/
|
||||||
|
@GetMapping("/list")
|
||||||
|
public TableDataInfo list(VipItem vipItem)
|
||||||
|
{
|
||||||
|
startPage();
|
||||||
|
List<VipItem> list = vipItemService.selectVipItemList(vipItem);
|
||||||
|
return getDataTable(list);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 导出会员等级列表
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:vip:export')")
|
||||||
|
@Log(title = "会员等级", businessType = BusinessType.EXPORT)
|
||||||
|
@PostMapping("/export")
|
||||||
|
public void export(HttpServletResponse response, VipItem vipItem)
|
||||||
|
{
|
||||||
|
List<VipItem> list = vipItemService.selectVipItemList(vipItem);
|
||||||
|
ExcelUtil<VipItem> util = new ExcelUtil<VipItem>(VipItem.class);
|
||||||
|
util.exportExcel(response, list, "会员等级数据");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取会员等级详细信息
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:vip:query')")
|
||||||
|
@GetMapping(value = "/{id}")
|
||||||
|
public AjaxResult getInfo(@PathVariable("id") Long id)
|
||||||
|
{
|
||||||
|
return success(vipItemService.selectVipItemById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增会员等级
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:vip:add')")
|
||||||
|
@Log(title = "会员等级", businessType = BusinessType.INSERT)
|
||||||
|
@PostMapping
|
||||||
|
public AjaxResult add(@RequestBody VipItem vipItem)
|
||||||
|
{
|
||||||
|
return toAjax(vipItemService.insertVipItem(vipItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改会员等级
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:vip:edit')")
|
||||||
|
@Log(title = "会员等级", businessType = BusinessType.UPDATE)
|
||||||
|
@PutMapping
|
||||||
|
public AjaxResult edit(@RequestBody VipItem vipItem)
|
||||||
|
{
|
||||||
|
return toAjax(vipItemService.updateVipItem(vipItem));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除会员等级
|
||||||
|
*/
|
||||||
|
@PreAuthorize("@ss.hasPermi('system:vip:remove')")
|
||||||
|
@Log(title = "会员等级", businessType = BusinessType.DELETE)
|
||||||
|
@DeleteMapping("/{ids}")
|
||||||
|
public AjaxResult remove(@PathVariable Long[] ids)
|
||||||
|
{
|
||||||
|
return toAjax(vipItemService.deleteVipItemByIds(ids));
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,66 @@
|
|||||||
|
package com.ruoyi.system.domain;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringBuilder;
|
||||||
|
import org.apache.commons.lang3.builder.ToStringStyle;
|
||||||
|
import com.ruoyi.common.annotation.Excel;
|
||||||
|
import com.ruoyi.common.core.domain.BaseEntity;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员等级对象 db_vip_item
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-11-11
|
||||||
|
*/
|
||||||
|
public class VipItem extends BaseEntity
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
/** 会员商品ID */
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
/** 会员等级名称 */
|
||||||
|
@Excel(name = "会员等级名称")
|
||||||
|
private String title;
|
||||||
|
|
||||||
|
/** 会员价格 */
|
||||||
|
@Excel(name = "会员价格")
|
||||||
|
private BigDecimal price;
|
||||||
|
|
||||||
|
public void setId(Long id)
|
||||||
|
{
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getId()
|
||||||
|
{
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
public void setTitle(String title)
|
||||||
|
{
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle()
|
||||||
|
{
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
public void setPrice(BigDecimal price)
|
||||||
|
{
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public BigDecimal getPrice()
|
||||||
|
{
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new ToStringBuilder(this,ToStringStyle.MULTI_LINE_STYLE)
|
||||||
|
.append("id", getId())
|
||||||
|
.append("title", getTitle())
|
||||||
|
.append("price", getPrice())
|
||||||
|
.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.system.mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.ruoyi.system.domain.VipItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员等级Mapper接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-11-11
|
||||||
|
*/
|
||||||
|
public interface VipItemMapper
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询会员等级
|
||||||
|
*
|
||||||
|
* @param id 会员等级主键
|
||||||
|
* @return 会员等级
|
||||||
|
*/
|
||||||
|
public VipItem selectVipItemById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询会员等级列表
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 会员等级集合
|
||||||
|
*/
|
||||||
|
public List<VipItem> selectVipItemList(VipItem vipItem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增会员等级
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertVipItem(VipItem vipItem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改会员等级
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateVipItem(VipItem vipItem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除会员等级
|
||||||
|
*
|
||||||
|
* @param id 会员等级主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteVipItemById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除会员等级
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的数据主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteVipItemByIds(Long[] ids);
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.ruoyi.system.service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import com.ruoyi.system.domain.VipItem;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员等级Service接口
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-11-11
|
||||||
|
*/
|
||||||
|
public interface IVipItemService
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 查询会员等级
|
||||||
|
*
|
||||||
|
* @param id 会员等级主键
|
||||||
|
* @return 会员等级
|
||||||
|
*/
|
||||||
|
public VipItem selectVipItemById(Long id);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询会员等级列表
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 会员等级集合
|
||||||
|
*/
|
||||||
|
public List<VipItem> selectVipItemList(VipItem vipItem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增会员等级
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int insertVipItem(VipItem vipItem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改会员等级
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int updateVipItem(VipItem vipItem);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除会员等级
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的会员等级主键集合
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteVipItemByIds(Long[] ids);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除会员等级信息
|
||||||
|
*
|
||||||
|
* @param id 会员等级主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
public int deleteVipItemById(Long id);
|
||||||
|
}
|
@ -0,0 +1,93 @@
|
|||||||
|
package com.ruoyi.system.service.impl;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import com.ruoyi.system.mapper.VipItemMapper;
|
||||||
|
import com.ruoyi.system.domain.VipItem;
|
||||||
|
import com.ruoyi.system.service.IVipItemService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 会员等级Service业务层处理
|
||||||
|
*
|
||||||
|
* @author ruoyi
|
||||||
|
* @date 2024-11-11
|
||||||
|
*/
|
||||||
|
@Service
|
||||||
|
public class VipItemServiceImpl implements IVipItemService
|
||||||
|
{
|
||||||
|
@Autowired
|
||||||
|
private VipItemMapper vipItemMapper;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询会员等级
|
||||||
|
*
|
||||||
|
* @param id 会员等级主键
|
||||||
|
* @return 会员等级
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public VipItem selectVipItemById(Long id)
|
||||||
|
{
|
||||||
|
return vipItemMapper.selectVipItemById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 查询会员等级列表
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 会员等级
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<VipItem> selectVipItemList(VipItem vipItem)
|
||||||
|
{
|
||||||
|
return vipItemMapper.selectVipItemList(vipItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 新增会员等级
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int insertVipItem(VipItem vipItem)
|
||||||
|
{
|
||||||
|
return vipItemMapper.insertVipItem(vipItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 修改会员等级
|
||||||
|
*
|
||||||
|
* @param vipItem 会员等级
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int updateVipItem(VipItem vipItem)
|
||||||
|
{
|
||||||
|
return vipItemMapper.updateVipItem(vipItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 批量删除会员等级
|
||||||
|
*
|
||||||
|
* @param ids 需要删除的会员等级主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteVipItemByIds(Long[] ids)
|
||||||
|
{
|
||||||
|
return vipItemMapper.deleteVipItemByIds(ids);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 删除会员等级信息
|
||||||
|
*
|
||||||
|
* @param id 会员等级主键
|
||||||
|
* @return 结果
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int deleteVipItemById(Long id)
|
||||||
|
{
|
||||||
|
return vipItemMapper.deleteVipItemById(id);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
<?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.ruoyi.system.mapper.VipItemMapper">
|
||||||
|
|
||||||
|
<resultMap type="VipItem" id="VipItemResult">
|
||||||
|
<result property="id" column="id" />
|
||||||
|
<result property="title" column="title" />
|
||||||
|
<result property="price" column="price" />
|
||||||
|
</resultMap>
|
||||||
|
|
||||||
|
<sql id="selectVipItemVo">
|
||||||
|
select id, title, price from db_vip_item
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<select id="selectVipItemList" parameterType="VipItem" resultMap="VipItemResult">
|
||||||
|
<include refid="selectVipItemVo"/>
|
||||||
|
<where>
|
||||||
|
<if test="title != null and title != ''"> and title = #{title}</if>
|
||||||
|
<if test="price != null "> and price = #{price}</if>
|
||||||
|
</where>
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<select id="selectVipItemById" parameterType="Long" resultMap="VipItemResult">
|
||||||
|
<include refid="selectVipItemVo"/>
|
||||||
|
where id = #{id}
|
||||||
|
</select>
|
||||||
|
|
||||||
|
<insert id="insertVipItem" parameterType="VipItem" useGeneratedKeys="true" keyProperty="id">
|
||||||
|
insert into db_vip_item
|
||||||
|
<trim prefix="(" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="title != null">title,</if>
|
||||||
|
<if test="price != null">price,</if>
|
||||||
|
</trim>
|
||||||
|
<trim prefix="values (" suffix=")" suffixOverrides=",">
|
||||||
|
<if test="title != null">#{title},</if>
|
||||||
|
<if test="price != null">#{price},</if>
|
||||||
|
</trim>
|
||||||
|
</insert>
|
||||||
|
|
||||||
|
<update id="updateVipItem" parameterType="VipItem">
|
||||||
|
update db_vip_item
|
||||||
|
<trim prefix="SET" suffixOverrides=",">
|
||||||
|
<if test="title != null">title = #{title},</if>
|
||||||
|
<if test="price != null">price = #{price},</if>
|
||||||
|
</trim>
|
||||||
|
where id = #{id}
|
||||||
|
</update>
|
||||||
|
|
||||||
|
<delete id="deleteVipItemById" parameterType="Long">
|
||||||
|
delete from db_vip_item where id = #{id}
|
||||||
|
</delete>
|
||||||
|
|
||||||
|
<delete id="deleteVipItemByIds" parameterType="String">
|
||||||
|
delete from db_vip_item where id in
|
||||||
|
<foreach item="id" collection="array" open="(" separator="," close=")">
|
||||||
|
#{id}
|
||||||
|
</foreach>
|
||||||
|
</delete>
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user