| | |
| | | return |
| | | } |
| | | if (isApiConfigured() && /^\d+$/.test(merchantId.value) && !isMedicalMerchant.value && !isTransportMerchant.value) { |
| | | getProducts(merchantId.value, 1, 20, (data: any) => { |
| | | getProducts(merchantId.value, talentId.value, 1, 20, (data: any) => { |
| | | const records: any[] = data != null && data.records instanceof Array ? data.records as any[] : [] |
| | | const remotePackages: any[] = [] |
| | | for (let index = 0; index < records.length; index++) { |
| | |
| | | return request<any>({ path: getApiEndpoint('appMerchantDetail') + encodeURIComponent(merchantId), method: 'GET', skipAuth: true }, onSuccess, onError) |
| | | } |
| | | |
| | | export const getProducts = (merchantId: string, page: number, size: number, onSuccess: (data: any) => void, onError: (error: HttpError) => void): (() => void) => { |
| | | return request<any>({ path: getApiEndpoint('appProducts'), method: 'GET', skipAuth: true, data: { merchantId: merchantId, page: page, size: size } }, onSuccess, onError) |
| | | export const getProducts = (merchantId: string, talentId: string, page: number, size: number, onSuccess: (data: any) => void, onError: (error: HttpError) => void): (() => void) => { |
| | | const data: any = { merchantId: merchantId, page: page, size: size } |
| | | if (talentId != '') data.talentId = Number(talentId) |
| | | return request<any>({ path: getApiEndpoint('appProducts'), method: 'GET', skipAuth: true, data: data }, onSuccess, onError) |
| | | } |
| | | |
| | | export const getProductDetail = (productId: string, talentId: string, onSuccess: (data: any) => void, onError: (error: HttpError) => void): (() => void) => { |
| | |
| | | public ApiResponse<PageResult<Map<String, Object>>> products( |
| | | @RequestParam(required = false) Long merchantId, |
| | | @RequestParam(required = false) String type, |
| | | @RequestParam(required = false) Long talentId, |
| | | @RequestParam(defaultValue = "1") int page, |
| | | @RequestParam(defaultValue = "10") int size |
| | | ) { |
| | | return ApiResponse.success(portalService.products(merchantId, type, page, size)); |
| | | return ApiResponse.success(portalService.products(merchantId, type, talentId, page, size)); |
| | | } |
| | | |
| | | @GetMapping("/products/{id}") |
| | |
| | | } |
| | | |
| | | @Transactional(readOnly = true) |
| | | public PageResult<Map<String, Object>> products(Long merchantId, String type, int page, int size) { |
| | | public PageResult<Map<String, Object>> products(Long merchantId, String type, Long talentId, int page, int size) { |
| | | StringBuilder sql = new StringBuilder(""" |
| | | select id, merchant_id, product_no, product_type, product_name, subtitle, cover_url, |
| | | original_price, sale_price, subsidy_amount, stock, sales_count, benefit_desc |
| | |
| | | args.add(type); |
| | | } |
| | | sql.append(" order by sort_no desc, id desc"); |
| | | return page(sql.toString(), countSql.toString(), page, size, args.toArray()); |
| | | PageResult<Map<String, Object>> result = page(sql.toString(), countSql.toString(), page, size, args.toArray()); |
| | | List<Map<String, Object>> records = result.records().stream().map(product -> { |
| | | Map<String, Object> item = new LinkedHashMap<>(product); |
| | | BigDecimal originalPrice = decimal(item.get("originalPrice")); |
| | | if (originalPrice.signum() <= 0) originalPrice = decimal(item.get("salePrice")); |
| | | BigDecimal personalizedPrice = personalizedProductPrice(item, talentId); |
| | | item.put("originalPrice", originalPrice); |
| | | item.put("salePrice", personalizedPrice); |
| | | item.put("personalized", talentId != null && personalizedPrice.compareTo(decimal(product.get("salePrice"))) != 0); |
| | | item.put("discountText", discountText(personalizedPrice, originalPrice)); |
| | | return item; |
| | | }).toList(); |
| | | return new PageResult<>(records, result.page(), result.size(), result.total()); |
| | | } |
| | | |
| | | private Map<String, Object> orderCouponProduct(Long merchantId, Long productId, String orderId) { |