add customer order summary
This commit is contained in:
@@ -49,6 +49,76 @@
|
||||
ORDER BY o.`purchased_at` DESC, o.`created_at` DESC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<select id="selectSummaryByQuery" resultType="com.imyeyu.api.modules.gao.vo.GaoSalesOrderReceivableStatView">
|
||||
SELECT
|
||||
COUNT(1) AS `orderCount`,
|
||||
COALESCE(SUM(o.`sale_amount`), 0) AS `saleAmount`,
|
||||
COALESCE(SUM(o.`paid_amount`), 0) AS `paidAmount`,
|
||||
COALESCE(SUM(o.`pending_paid_amount`), 0) AS `pendingPaidAmount`,
|
||||
COALESCE(SUM(o.`sale_amount` - o.`paid_amount`), 0) AS `unpaidAmount`,
|
||||
COALESCE(SUM(o.`refunded_amount`), 0) AS `refundedAmount`,
|
||||
COALESCE(SUM(o.`paid_amount` - o.`refunded_amount`), 0) AS `netPaidAmount`
|
||||
FROM `gao_sales_order` o LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id`
|
||||
WHERE <include refid="queryWhere"/>
|
||||
</select>
|
||||
<sql id="customerProductWhere">
|
||||
i.`deleted_at` IS NULL
|
||||
AND o.`deleted_at` IS NULL
|
||||
AND o.`store_id` = #{storeId}
|
||||
AND o.`status` <> 'CANCELLED'
|
||||
<if test="customerId != null and customerId != ''">AND o.`customer_id` = #{customerId}</if>
|
||||
<if test="customerIdList != null and customerIdList.size() > 0">
|
||||
AND o.`customer_id` IN
|
||||
<foreach collection="customerIdList" item="customerIdItem" open="(" separator="," close=")">
|
||||
#{customerIdItem}
|
||||
</foreach>
|
||||
</if>
|
||||
<if test="itemType != null">AND i.`item_type` = #{itemType}</if>
|
||||
<if test="keyword != null and keyword.trim() != ''">
|
||||
AND (
|
||||
c.`name` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR c.`code` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR o.`order_no` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR i.`product_name_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR i.`sku_name_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR i.`sku_code_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
||||
OR i.`spec_summary_snapshot` LIKE CONCAT('%', #{keyword}, '%')
|
||||
)
|
||||
</if>
|
||||
</sql>
|
||||
<select id="countCustomerProductCustomerByQuery" resultType="long">
|
||||
SELECT COUNT(DISTINCT o.`customer_id`)
|
||||
FROM `gao_sales_order_item` i
|
||||
JOIN `gao_sales_order` o ON o.`id` = i.`sales_order_id`
|
||||
LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id`
|
||||
WHERE <include refid="customerProductWhere"/>
|
||||
</select>
|
||||
<select id="selectCustomerProductCustomerByQuery" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerProductCustomerRow">
|
||||
SELECT o.`customer_id`, c.`code` AS `customer_code`, c.`name` AS `customer_name`, COUNT(DISTINCT o.`id`) AS `order_count`
|
||||
FROM `gao_sales_order_item` i
|
||||
JOIN `gao_sales_order` o ON o.`id` = i.`sales_order_id`
|
||||
LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id`
|
||||
WHERE <include refid="customerProductWhere"/>
|
||||
GROUP BY o.`customer_id`, c.`code`, c.`name`
|
||||
ORDER BY c.`name` ASC, c.`code` ASC, o.`customer_id` ASC
|
||||
LIMIT #{offset}, #{limit}
|
||||
</select>
|
||||
<select id="selectCustomerProductByQuery" resultType="com.imyeyu.api.modules.gao.vo.GaoCustomerProductView">
|
||||
SELECT i.`id`, i.`sales_order_id`, o.`customer_id`, c.`code` AS `customer_code`, c.`name` AS `customer_name`,
|
||||
o.`order_no`, o.`order_type`, o.`status` AS `order_status`, o.`purchased_at`,
|
||||
i.`item_type`, i.`gifted`, i.`sku_id`, i.`sku_unit_id`, i.`product_name_snapshot`, i.`product_id_snapshot`,
|
||||
i.`sku_code_snapshot`, i.`sku_name_snapshot`, i.`spec_summary_snapshot`, i.`unit_snapshot`, base_unit.`name` AS `base_unit_name`,
|
||||
i.`base_quantity_per_unit_snapshot`, i.`quantity`, i.`base_quantity`, i.`reserved_base_quantity`,
|
||||
i.`fulfilled_base_quantity`,
|
||||
COALESCE(i.`base_quantity`, 0) - COALESCE(i.`fulfilled_base_quantity`, 0) AS `remaining_base_quantity`,
|
||||
COALESCE(i.`base_quantity`, 0) - COALESCE(i.`reserved_base_quantity`, 0) - COALESCE(i.`fulfilled_base_quantity`, 0) AS `available_base_quantity`
|
||||
FROM `gao_sales_order_item` i
|
||||
JOIN `gao_sales_order` o ON o.`id` = i.`sales_order_id`
|
||||
LEFT JOIN `gao_customer` c ON c.`id` = o.`customer_id`
|
||||
LEFT JOIN `gao_product_sku_unit` base_unit ON base_unit.`sku_id` = i.`sku_id` AND base_unit.`is_base` = 1 AND base_unit.`deleted_at` IS NULL
|
||||
WHERE <include refid="customerProductWhere"/>
|
||||
ORDER BY o.`purchased_at` DESC, o.`created_at` DESC, i.`sort` ASC, i.`created_at` ASC
|
||||
</select>
|
||||
<update id="updatePayment">
|
||||
UPDATE `gao_sales_order`
|
||||
SET `pending_paid_amount` = #{pendingPaidAmount}, `paid_amount` = #{paidAmount}, `paid_at` = #{paidAt}, `refunded_amount` = #{refundedAmount},
|
||||
|
||||
Reference in New Issue
Block a user