mirror of
https://gitee.com/coder-xiaomo/flashsale
synced 2025-01-25 10:50:27 +08:00
商品销量中增加
This commit is contained in:
parent
42888a2d8a
commit
4ecd497e00
@ -100,6 +100,7 @@
|
||||
success: function (data) {
|
||||
if (data.status == "success") {
|
||||
alert("下单成功");
|
||||
window.location.reload();
|
||||
} else {
|
||||
alert("下单失败,原因为" + data.data.errMsg);
|
||||
if (data.data.errCode == "20003") {
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.cxyxiaomo.flashsale.dao;
|
||||
|
||||
import com.cxyxiaomo.flashsale.dataobject.ItemDO;
|
||||
import org.apache.ibatis.annotations.Param;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@ -54,4 +55,6 @@ public interface ItemDOMapper {
|
||||
* @mbg.generated Thu Mar 03 13:12:13 CST 2022
|
||||
*/
|
||||
int updateByPrimaryKey(ItemDO record);
|
||||
|
||||
int increaseSales(@Param("id") Integer id, @Param("amount") Integer amount);
|
||||
}
|
@ -15,5 +15,9 @@ public interface ItemService {
|
||||
// 商品详情浏览
|
||||
ItemModel getItemById(Integer id);
|
||||
|
||||
// 库存扣减
|
||||
boolean decreaseStock(Integer itemId, Integer amount) throws BusinessException;
|
||||
|
||||
// 商品销量增加
|
||||
void increaseSales(Integer itemId, Integer amount);
|
||||
}
|
||||
|
@ -116,6 +116,12 @@ public class ItemServiceImpl implements ItemService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public void increaseSales(Integer itemId, Integer amount) {
|
||||
itemDOMapper.increaseSales(itemId, amount);
|
||||
}
|
||||
|
||||
private ItemModel convertModelFromDataObject(ItemDO itemDO, ItemStockDO itemStockDO) {
|
||||
ItemModel itemModel = new ItemModel();
|
||||
BeanUtils.copyProperties(itemDO, itemModel);
|
||||
|
@ -70,12 +70,15 @@ public class OrderServiceImpl implements OrderService {
|
||||
orderModel.setItemPrice(itemModel.getPrice());
|
||||
orderModel.setOrderPrice(itemModel.getPrice().multiply(new BigDecimal(amount)));
|
||||
|
||||
// 生成交易流水号,订单号
|
||||
// 生成交易流水号(订单号)
|
||||
orderModel.setId(generateOrderNo());
|
||||
|
||||
OrderDO orderDO = convertFromOrderModel(orderModel);
|
||||
orderDOMapper.insertSelective(orderDO);
|
||||
|
||||
// 商品销量增加
|
||||
itemService.increaseSales(itemId, amount);
|
||||
|
||||
// 4. 返回前端
|
||||
return orderModel;
|
||||
}
|
||||
|
@ -28,7 +28,7 @@
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
This element was generated on Thu Mar 03 13:12:13 CST 2022.
|
||||
-->
|
||||
select
|
||||
select
|
||||
<include refid="Base_Column_List" />
|
||||
from item_info
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
@ -48,10 +48,10 @@
|
||||
This element is automatically generated by MyBatis Generator, do not modify.
|
||||
This element was generated on Thu Mar 03 13:12:13 CST 2022.
|
||||
-->
|
||||
insert into item_info (id, title, price,
|
||||
insert into item_info (id, title, price,
|
||||
description, sales, img_url
|
||||
)
|
||||
values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
|
||||
values (#{id,jdbcType=INTEGER}, #{title,jdbcType=VARCHAR}, #{price,jdbcType=DECIMAL},
|
||||
#{description,jdbcType=VARCHAR}, #{sales,jdbcType=INTEGER}, #{imgUrl,jdbcType=VARCHAR}
|
||||
)
|
||||
</insert>
|
||||
@ -149,4 +149,9 @@
|
||||
from item_info
|
||||
order by sales DESC
|
||||
</select>
|
||||
<update id="increaseSales">
|
||||
update item_info
|
||||
set sales = sales + #{amount}
|
||||
where id = #{id,jdbcType=INTEGER}
|
||||
</update>
|
||||
</mapper>
|
Loading…
x
Reference in New Issue
Block a user