| | |
| | | if (status != null) { sql.append(" and status = ?"); countSql.append(" and status = ?"); args.add(status); } |
| | | if (publishStart != null && !publishStart.isBlank()) { sql.append(" and date(publish_time) >= ?"); countSql.append(" and date(publish_time) >= ?"); args.add(publishStart); } |
| | | if (publishEnd != null && !publishEnd.isBlank()) { sql.append(" and date(publish_time) <= ?"); countSql.append(" and date(publish_time) <= ?"); args.add(publishEnd); } |
| | | // 置顶优先,置顶组内按置顶时间倒序(越后置顶越靠前);非置顶按排序值倒序。 |
| | | sql.append(" order by is_top desc, case when is_top = 1 then top_time end desc, sort_no desc, publish_time desc, id desc"); |
| | | // 置顶优先;置顶组内按“修改时间”倒序(最新修改的排前面,和人才端人才资讯一致),非置顶按排序值倒序。 |
| | | sql.append(" order by is_top desc, case when is_top = 1 then updated_at end desc, sort_no desc, publish_time desc, id desc"); |
| | | return page(sql.toString(), countSql.toString(), page, size, args.toArray()); |
| | | } |
| | | |
| | |
| | | select p.id, p.id as product_id, p.merchant_id, m.merchant_name, m.merchant_type, m.merchant_type_code, m.contact_mobile, |
| | | p.product_no, p.product_type, p.product_name, p.subtitle, p.cover_url, |
| | | p.original_price, p.sale_price, p.subsidy_amount, p.is_government_subsidy, |
| | | p.stock, p.sales_count, p.detail_text, p.benefit_desc, p.purchase_notice, |
| | | p.stock, %s, p.detail_text, p.benefit_desc, p.purchase_notice, |
| | | p.valid_start_time, p.valid_end_time, p.product_images, p.rights_config, |
| | | p.audit_status, p.audit_remark, p.status, p.sort_no, p.submit_time, p.created_at, p.updated_at |
| | | from merchant_product p |
| | | left join merchant m on m.id = p.merchant_id |
| | | where p.deleted = 0 and p.merchant_id = ? |
| | | """); |
| | | """.formatted(salesCountSelect("p.id", "p"))); |
| | | StringBuilder countSql = new StringBuilder(""" |
| | | select count(*) |
| | | from merchant_product p |
| | |
| | | select r.id, r.product_id, r.merchant_id, m.merchant_name, m.merchant_type, m.merchant_type_code, m.contact_mobile, |
| | | r.product_no, r.product_type, r.product_name, |
| | | r.subtitle, r.cover_url, r.original_price, r.sale_price, r.subsidy_amount, |
| | | r.is_government_subsidy, r.stock, r.sales_count, r.detail_text, r.benefit_desc, |
| | | r.is_government_subsidy, r.stock, %s, r.detail_text, r.benefit_desc, |
| | | r.purchase_notice, r.valid_start_time, r.valid_end_time, r.product_images, r.rights_config, |
| | | r.audit_status, r.audit_remark, r.audit_by, r.audit_time, r.submit_time, |
| | | r.source_created_at as created_at, p.status |
| | |
| | | left join merchant_product p on p.id = r.product_id |
| | | left join merchant m on m.id = r.merchant_id |
| | | where r.deleted = 0 |
| | | """); |
| | | """.formatted(salesCountSelect("r.product_id", "p"))); |
| | | StringBuilder countSql = new StringBuilder(""" |
| | | select count(*) |
| | | from merchant_product_audit_record r |
| | |
| | | select p.id, p.merchant_id, m.merchant_name, m.merchant_type, m.merchant_type_code, m.contact_mobile, |
| | | p.product_no, p.product_type, p.product_name, |
| | | p.subtitle, p.cover_url, p.original_price, p.sale_price, p.subsidy_amount, |
| | | p.is_government_subsidy, p.stock, p.sales_count, p.detail_text, p.benefit_desc, |
| | | p.is_government_subsidy, p.stock, %s, p.detail_text, p.benefit_desc, |
| | | p.purchase_notice, p.valid_start_time, p.valid_end_time, p.product_images, p.rights_config, |
| | | p.audit_status, p.audit_remark, p.status, p.sort_no, p.submit_time, p.created_at, p.updated_at |
| | | from merchant_product p |
| | | left join merchant m on m.id = p.merchant_id |
| | | where p.deleted = 0 and p.id = ? |
| | | """, id); |
| | | """.formatted(salesCountSelect("p.id", "p")), id); |
| | | } |
| | | |
| | | @Transactional(readOnly = true) |
| | |
| | | select r.id, r.product_id, r.merchant_id, m.merchant_name, m.merchant_type, m.merchant_type_code, m.contact_mobile, |
| | | r.product_no, r.product_type, r.product_name, r.subtitle, r.cover_url, |
| | | r.original_price, r.sale_price, r.subsidy_amount, r.is_government_subsidy, |
| | | r.stock, r.sales_count, r.detail_text, r.benefit_desc, r.purchase_notice, |
| | | r.stock, %s, r.detail_text, r.benefit_desc, r.purchase_notice, |
| | | r.valid_start_time, r.valid_end_time, r.product_images, r.rights_config, |
| | | r.audit_status, r.audit_remark, r.audit_by, r.audit_time, r.submit_time, |
| | | r.source_created_at as created_at, p.status |
| | |
| | | left join merchant_product p on p.id = r.product_id |
| | | left join merchant m on m.id = r.merchant_id |
| | | where r.deleted = 0 and r.id = ? |
| | | """, auditRecordId); |
| | | """.formatted(salesCountSelect("r.product_id", "p")), auditRecordId); |
| | | } |
| | | |
| | | @Transactional |
| | |
| | | return Boolean.TRUE.equals(value == null ? defaultValue : value) ? (byte) 1 : (byte) 0; |
| | | } |
| | | |
| | | /** |
| | | * 团单销量 = 该商品的有效订单数(已支付,且未取消/未退款)。 |
| | | * |
| | | * 商品表上的 sales_count 只在部分流程(如酒店房型预约)里累加,普通团单下单后一直是 0, |
| | | * 后台列表就统计不出销量。这里直接按订单算,同时保留 sales_count 作为下限,兼容历史数据。 |
| | | */ |
| | | String salesCountSelect(String productIdExpression, String productAlias) { |
| | | return "greatest(coalesce(" + productAlias + ".sales_count, 0), (select count(*) from benefit_order bo" |
| | | + " where bo.deleted = 0 and bo.product_id = " + productIdExpression |
| | | + " and bo.order_status = 1 and (bo.refund_status is null or bo.refund_status = 0))) as sales_count"; |
| | | } |
| | | |
| | | private List<Long> couponProductIds(Long couponId) { |
| | | return jdbcTemplate.queryForList( |
| | | "select product_id from merchant_coupon_product where coupon_id = ? order by id", |
| | |
| | | |
| | | private List<Map<String, Object>> couponProducts(Long couponId) { |
| | | return DatabaseRows.normalize(jdbcTemplate.queryForList(""" |
| | | select p.id, p.product_name, p.cover_url, p.sale_price, p.sales_count, p.submit_time, p.created_at, |
| | | select p.id, p.product_name, p.cover_url, p.sale_price, %s, p.submit_time, p.created_at, |
| | | p.audit_status, p.status |
| | | from merchant_coupon_product cp |
| | | join merchant_product p on p.id = cp.product_id |
| | | where cp.coupon_id = ? and p.deleted = 0 |
| | | order by cp.id |
| | | """, couponId)); |
| | | """.formatted(salesCountSelect("p.id", "p")), couponId)); |
| | | } |
| | | |
| | | private void syncCouponProducts(Long couponId, List<Long> productIds, String productScope) { |