Skip to content

Commit

Permalink
feat: add product
Browse files Browse the repository at this point in the history
  • Loading branch information
novohit committed Nov 6, 2023
1 parent 5ef332a commit db58764
Show file tree
Hide file tree
Showing 13 changed files with 280 additions and 12 deletions.
19 changes: 8 additions & 11 deletions cloudshare-frontend/src/views/pay/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,15 @@ import {ref} from 'vue'
const data = ref('')
const alipay = ()=>{
const productId = 1;
const buyNum = 1;
const actualPayAmount = 1;
userService.pay({
"token": "test_f334d0d47a83",
"product_id": 1,
"buy_num": 1,
"total_amount": 27.69,
"actual_pay_amount": 19,
"pay_type": "ALI_PAY_PC",
"bill_type": "test_ea304456dffc",
"bill_header": "test_02f56667b032",
"bill_content": "test_951a4562e602",
"bill_receiver_phone": "test_71398c1e670e",
"bill_receiver_email": "test_17b07498eadd"
productId: productId,
buyNum: buyNum,
actualPayAmount: actualPayAmount,
payType: "ALI_PAY_PC",
}, res => {
// 处理掉script标签的内容
const fragment = document.createElement('divform');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import com.cloudshare.server.common.constant.BizConstant;
import com.cloudshare.server.order.model.Product;
import com.cloudshare.server.order.repository.ProductRepository;
import com.cloudshare.server.user.enums.PlanLevel;
import com.cloudshare.server.user.model.User;
import com.cloudshare.server.user.repository.UserRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;

/**
* @author novo
Expand All @@ -18,8 +23,11 @@ public class DataGenerationRunner implements CommandLineRunner {

private final UserRepository userRepository;

public DataGenerationRunner(UserRepository userRepository) {
private final ProductRepository productRepository;

public DataGenerationRunner(UserRepository userRepository, ProductRepository productRepository) {
this.userRepository = userRepository;
this.productRepository = productRepository;
}

@Override
Expand All @@ -32,6 +40,10 @@ public void run(String... args) throws Exception {
if (userRepository.findByUsername(guest.getUsername()).isEmpty()) {
userRepository.save(guest);
}
Product product = genProduct();
if (CollectionUtils.isEmpty(productRepository.findAll())) {
productRepository.save(product);
}
}

private User genUser(String username, String password) {
Expand All @@ -47,4 +59,13 @@ private User genUser(String username, String password) {
user.setUsedQuota(0L);
return user;
}

private Product genProduct() {
Product product = new Product();
product.setTitle("Plus会员");
product.setDetail("Plus会员");
product.setPlan(PlanLevel.PLUS);
product.setAmount(BigDecimal.valueOf(9.9));
return product;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cloudshare.server.auth;

import com.cloudshare.server.user.enums.PlanLevel;

/**
* @author novo
* @since 2023/10/6
Expand All @@ -10,6 +12,7 @@ public record UserContext(
String phone,
String avatar,
Integer scope,
PlanLevel plan,
Long totalQuota,
Long usedQuota
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public boolean preHandle(HttpServletRequest request, HttpServletResponse respons
user.getPhone(),
user.getAvatar(),
1,
user.getPlan(),
user.getTotalQuota(),
user.getUsedQuota()
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.cloudshare.server.order.controller;

import com.cloudshare.server.order.model.Product;
import com.cloudshare.server.order.service.ProductService;
import com.cloudshare.web.response.Response;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
* @author novo
* @since 2023/11/6
*/
@RestController
@RequestMapping("/product")
public class ProductController {

private final ProductService productService;

public ProductController(ProductService productService) {
this.productService = productService;
}

@GetMapping("/list")
public Response<List<Product>> list() {
List<Product> resp = productService.list();
return Response.success(resp);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.cloudshare.server.order.enums;

/**
* @author novo
* @since 2023-09-20
*/
public enum PayStateEnum {

NEW,

PAID,

CANCEL,

;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.cloudshare.server.order.enums;

public enum PayType {

WECHAT,

ALI_PAY_PC,

BANK,

;
}
91 changes: 91 additions & 0 deletions server/src/main/java/com/cloudshare/server/order/model/Order.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package com.cloudshare.server.order.model;

import com.cloudshare.server.common.BaseModel;
import com.cloudshare.server.order.enums.PayStateEnum;
import com.cloudshare.server.order.enums.PayType;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Comment;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
* @author novo
* @since 2023-09-19
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "`order`")
public class Order extends BaseModel {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private Long orderId;

@Comment("商品标题")
private String productTitle;

@Comment("商品单价")
private BigDecimal productAmount;

@Comment("商品快照")
private String productSnapshot;

@Comment("购买数量")
private Integer buyNum;

@Comment("订单唯⼀标识")
private String outTradeNo;

@Comment("NEW未支付订单,PAY已经支付订单,CANCEL超时取消订单")
private PayStateEnum state;

@Comment("订单完成时间")
private LocalDateTime payTime;

@Comment("订单总⾦额")
private BigDecimal totalAmount;

@Comment("订单实际⽀付价格")
private BigDecimal actualPayAmount;

@Comment("支付类型,微信-银行卡-支付宝")
private PayType payType;

@Comment("账户名")
private String username;

private Long accountNo;

/**
* 发票类型:0->不开发票;1->电子发票;2->纸质发票
*/
private String billType;

/**
* 发票抬头
*/
private String billHeader;

/**
* 发票内容
*/
private String billContent;

/**
* 发票收票人电话
*/
private String billReceiverPhone;

/**
* 发票收票人邮箱
*/
private String billReceiverEmail;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.cloudshare.server.order.model;

import com.cloudshare.server.common.BaseModel;
import com.cloudshare.server.user.enums.PlanLevel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Comment;

import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import java.math.BigDecimal;

/**
* @author novo
* @since 2023/11/6
*/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity(name = "product")
public class Product extends BaseModel {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Comment("商品标题")
private String title;

@Comment("商品详情")
private String detail;

@Comment("商品价格")
private BigDecimal amount;

@Enumerated(value = EnumType.STRING)
private PlanLevel plan;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.cloudshare.server.order.repository;

import com.cloudshare.server.order.model.Product;
import org.springframework.data.jpa.repository.JpaRepository;

/**
* @author novo
* @since 2023/11/6
*/
public interface ProductRepository extends JpaRepository<Product, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.cloudshare.server.order.service;

import com.cloudshare.server.order.model.Product;

import java.util.List;

/**
* @author novo
* @since 2023/11/6
*/
public interface ProductService {

List<Product> list();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.cloudshare.server.order.service.impl;

import com.cloudshare.server.order.model.Product;
import com.cloudshare.server.order.repository.ProductRepository;
import com.cloudshare.server.order.service.ProductService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author novo
* @since 2023/11/6
*/
@Service
public class ProductServiceImpl implements ProductService {

private final ProductRepository productRepository;

public ProductServiceImpl(ProductRepository productRepository) {
this.productRepository = productRepository;
}

@Override
public List<Product> list() {
return productRepository.findAll();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.cloudshare.server.user.controller.request;

import com.cloudshare.server.user.enums.PlanLevel;

/**
* @author novo
* @since 2023/10/6
Expand All @@ -11,6 +13,7 @@ public record UserInfoRepVO(
String avatar,
Long rootId,
String rootName,
PlanLevel plan,
Long totalQuota,
Long usedQuota
) {
Expand Down

0 comments on commit db58764

Please sign in to comment.