2026-07-07 16:04:02 +08:00
|
|
|
package com.linhelp.groupbuy;
|
|
|
|
|
|
|
|
|
|
import com.linhelp.common.api.ApiResponse;
|
|
|
|
|
import com.linhelp.common.security.AuthService;
|
|
|
|
|
import com.linhelp.common.security.CurrentUser;
|
|
|
|
|
import com.linhelp.common.security.RequireRole;
|
|
|
|
|
import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
import org.springframework.web.bind.annotation.PostMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.PutMapping;
|
|
|
|
|
import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
|
|
|
import javax.validation.Valid;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
@RestController
|
|
|
|
|
public class GroupBuyController {
|
|
|
|
|
private final GroupBuyService groupBuyService;
|
|
|
|
|
private final GroupBuyOrderService orderService;
|
|
|
|
|
private final AuthService authService;
|
|
|
|
|
|
|
|
|
|
public GroupBuyController(GroupBuyService groupBuyService,
|
|
|
|
|
GroupBuyOrderService orderService,
|
|
|
|
|
AuthService authService) {
|
|
|
|
|
this.groupBuyService = groupBuyService;
|
|
|
|
|
this.orderService = orderService;
|
|
|
|
|
this.authService = authService;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/api/admin/group-buys")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<List<GroupBuyResponse>> listAdmin() {
|
|
|
|
|
CurrentUser user = authService.currentUser();
|
|
|
|
|
return ApiResponse.ok(groupBuyService.listAdmin(user.getCommunityId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/api/admin/group-buys")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<GroupBuyResponse> create(@Valid @RequestBody GroupBuyRequest request) {
|
|
|
|
|
CurrentUser user = authService.currentUser();
|
|
|
|
|
request.setTenantId(user.getTenantId());
|
|
|
|
|
request.setCommunityId(user.getCommunityId());
|
|
|
|
|
return ApiResponse.ok(groupBuyService.create(request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/api/admin/group-buys/{id}")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<GroupBuyResponse> update(@PathVariable Long id, @Valid @RequestBody GroupBuyRequest request) {
|
|
|
|
|
CurrentUser user = authService.currentUser();
|
|
|
|
|
request.setTenantId(user.getTenantId());
|
|
|
|
|
request.setCommunityId(user.getCommunityId());
|
|
|
|
|
return ApiResponse.ok(groupBuyService.update(id, request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/api/admin/group-buys/{id}/start")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<GroupBuyResponse> start(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(groupBuyService.start(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/api/admin/group-buys/{id}/close")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<GroupBuyResponse> close(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(groupBuyService.close(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/api/admin/group-buys/{id}/complete")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<GroupBuyResponse> completeGroupBuy(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(groupBuyService.complete(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/api/admin/group-buys/{id}/orders")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<List<GroupBuyOrderResponse>> listOrders(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(orderService.listByGroupBuy(id));
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 17:45:31 +08:00
|
|
|
@PutMapping("/api/admin/group-buy-orders/{id}/confirm")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<GroupBuyOrderResponse> confirmOrder(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(orderService.confirm(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/api/admin/group-buy-orders/{id}/ready")
|
|
|
|
|
@RequireRole({"PLATFORM_ADMIN", "COMMUNITY_ADMIN", "MERCHANT"})
|
|
|
|
|
public ApiResponse<GroupBuyOrderResponse> markOrderReady(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(orderService.markReady(id));
|
|
|
|
|
}
|
|
|
|
|
|
2026-07-07 16:04:02 +08:00
|
|
|
@GetMapping("/api/mini/group-buys")
|
|
|
|
|
public ApiResponse<List<GroupBuyResponse>> listMini() {
|
|
|
|
|
CurrentUser user = authService.currentUser();
|
|
|
|
|
return ApiResponse.ok(groupBuyService.listMini(user.getCommunityId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/api/mini/group-buys/{id}")
|
|
|
|
|
public ApiResponse<GroupBuyResponse> detail(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(groupBuyService.detail(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PostMapping("/api/mini/group-buy-orders")
|
|
|
|
|
public ApiResponse<GroupBuyOrderResponse> createOrder(@Valid @RequestBody GroupBuyOrderRequest request) {
|
|
|
|
|
CurrentUser user = authService.currentUser();
|
|
|
|
|
request.setTenantId(user.getTenantId());
|
|
|
|
|
request.setCommunityId(user.getCommunityId());
|
|
|
|
|
return ApiResponse.ok(orderService.create(user.getUserId(), request));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/api/mini/group-buy-orders")
|
|
|
|
|
public ApiResponse<List<GroupBuyOrderResponse>> listMine() {
|
|
|
|
|
CurrentUser user = authService.currentUser();
|
|
|
|
|
return ApiResponse.ok(orderService.listMine(user.getUserId()));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@GetMapping("/api/mini/group-buy-orders/{id}")
|
|
|
|
|
public ApiResponse<GroupBuyOrderResponse> orderDetail(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(orderService.detail(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/api/mini/group-buy-orders/{id}/cancel")
|
|
|
|
|
public ApiResponse<GroupBuyOrderResponse> cancel(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(orderService.cancel(id));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@PutMapping("/api/mini/group-buy-orders/{id}/complete")
|
|
|
|
|
public ApiResponse<GroupBuyOrderResponse> completeOrder(@PathVariable Long id) {
|
|
|
|
|
return ApiResponse.ok(orderService.complete(id));
|
|
|
|
|
}
|
|
|
|
|
}
|