You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

199 lines
8.6 KiB

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="cc.hiver.mall.dao.mapper.MallOrderMapper">
<!-- 通用结果映射 -->
<resultMap id="mallOrderVOMap" type="cc.hiver.mall.pojo.vo.MallOrderVO">
<id column="id" property="id"/>
<result column="user_id" property="userId"/>
<result column="shop_id" property="shopId"/>
<result column="order_type" property="orderType"/>
<result column="delivery_type" property="deliveryType"/>
<result column="status" property="status"/>
<result column="total_amount" property="totalAmount"/>
<result column="goods_amount" property="goodsAmount"/>
<result column="delivery_fee" property="deliveryFee"/>
<result column="package_fee" property="packageFee"/>
<result column="address_id" property="addressId"/>
<result column="remark" property="remark"/>
<result column="receiver_name" property="receiverName"/>
<result column="receiver_phone" property="receiverPhone"/>
<result column="receiver_address" property="receiverAddress"/>
<result column="shop_name" property="shopName"/>
<result column="shop_phone" property="shopPhone"/>
<result column="shop_address" property="shopAddress"/>
<result column="create_time" property="createTime"/>
<result column="pay_time" property="payTime"/>
<result column="number_code" property="numberCode"/>
<result column="region_id" property="regionId"/>
<result column="settlement_status" property="settlementStatus"/>
<result column="shop_make_time" property="shopMakeTime"/>
<result column="other_order" property="otherOrder"/>
<result column="user_require_make" property="userRequireMake"/>
</resultMap>
<!-- 公共查询条件:店铺ID -->
<sql id="commonShopIdWhere">
WHERE shop_id = #{shopId}
</sql>
<!-- 统计不同业务类型的订单数量 -->
<select id="selectOrderStatusCount" parameterType="string" resultType="java.util.Map">
SELECT
COUNT(*) AS count,
CASE
WHEN (`status` = 3 AND delivery_type = 1) THEN 'daiqu'
WHEN (`status` = 4 AND delivery_type = 1) THEN 'daisong'
WHEN (`status` = 3 AND delivery_type = 2 AND user_require_make IS NULL) THEN 'daixiaofei'
WHEN (`status` = 3 AND delivery_type = 2 AND user_require_make = 1) THEN 'daichucan'
END AS counttype
FROM mall_order
<include refid="commonShopIdWhere"/>
GROUP BY counttype
</select>
<!-- 统计营业额和订单量 (带时间范围) -->
<select id="selectOrderRevenueAndCount" parameterType="java.util.Map" resultType="java.util.Map">
SELECT
COUNT(*) as count,
SUM(goods_amount + package_fee) as amount
FROM mall_order
<include refid="commonShopIdWhere"/>
AND `status` IN (5, 12)
<if test="startTime != null">
AND create_time BETWEEN #{startTime} AND #{endTime}
</if>
</select>
<!-- 统计待回复的差评数量 -->
<select id="selectPendingBadReviewCount" parameterType="string" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM t_comment
<include refid="commonShopIdWhere"/>
AND level = 0
AND has_answer IS NULL
AND score &lt; 4
</select>
<!-- 统计待处理的退款和售后数量 -->
<select id="selectRefundCount" parameterType="string" resultType="java.lang.Integer">
SELECT COUNT(*)
FROM mall_refund_record
where link_id = #{shopId}
AND status in (0,3)
</select>
<!-- 分页查询订单(不挂载商品明细,由Service层补填) -->
<select id="selectPageVO" resultMap="mallOrderVOMap">
SELECT
o.id, o.user_id, o.shop_id, o.order_type, o.delivery_type,
o.status, o.total_amount, o.goods_amount, o.delivery_fee,
o.package_fee, o.address_id, o.remark, o.create_time, o.pay_time,
o.receiver_name, o.receiver_phone, o.receiver_address,
o.shop_name, o.shop_phone, o.shop_address,o.number_code,o.region_id,
o.settlement_status,o.shop_make_time,o.other_order,o.user_require_make
FROM mall_order o
<where>
<if test="q.userId != null and q.userId != ''">
AND o.user_id = #{q.userId}
</if>
<if test="q.shopName != null and q.shopName != ''">
and (
o.shop_name like concat('%',#{q.shopName},'%')
)
</if>
<if test="q.shopId != null and q.shopId != ''">
AND o.shop_id = #{q.shopId} and o.status not in (0,10,2)
</if>
<if test="q.regionId != null and q.regionId != ''">
AND o.region_id = #{q.regionId}
</if>
<if test="q.status != null">
AND o.status = #{q.status}
</if>
<if test="q.orderType != null">
AND o.order_type = #{q.orderType}
</if>
<if test="q.searchType != null and q.searchType == 1">
AND o.order_type in (1,2,3) AND o.other_order is null
</if>
<if test="q.searchType != null and q.searchType == 2">
AND o.other_order = 1
</if>
<if test="q.searchType != null and q.searchType == 3">
AND o.other_order = 2
</if>
<if test="q.searchStatus != null and q.searchStatus == 0">
AND o.status = 0
</if>
<if test="q.searchStatus != null and q.searchStatus == 1">
AND o.status = 10
</if>
<if test="q.searchStatus != null and q.searchStatus == 2">
AND o.status = 3 and o.delivery_type = 2
</if>
<if test="q.searchStatus != null and q.searchStatus == 3">
AND o.status = 2
</if>
<if test="q.searchStatus != null and q.searchStatus == 4">
AND o.status = 3 and o.delivery_type = 1 and o.shop_make_time is not null
</if>
<if test="q.searchStatus != null and q.searchStatus == 5">
AND o.status = 4
</if>
<if test="q.searchStatus != null and q.searchStatus == 6">
AND o.status = 5
</if>
<if test="q.searchStatus != null and q.searchStatus == 7">
AND o.status = 7
</if>
<if test="q.searchStatus != null and q.searchStatus == 8">
AND o.status = 8
</if>
<if test="q.searchStatus != null and q.searchStatus == 9">
AND o.status = 6
</if>
<if test="q.searchStatus != null and q.searchStatus == 11">
AND o.status = 11
</if>
<if test="q.searchStatus != null and q.searchStatus == 12">
AND o.status = 12
</if>
<if test="q.searchStatus != null and q.searchStatus == 13">
AND (
(o.status = 3 AND o.delivery_type = 1 AND o.shop_make_time is null)
OR
(o.user_require_make = 1 AND o.delivery_type = 2 AND o.status = 3)
)
</if>
<if test="q.deliveryType != null">
AND o.delivery_type = #{q.deliveryType}
</if>
<if test="q.startDate != null and q.startDate != ''">
AND DATE(o.create_time) &gt;= #{q.startDate}
</if>
<if test="q.endDate != null and q.endDate != ''">
AND DATE(o.create_time) &lt;= #{q.endDate}
</if>
</where>
ORDER BY o.create_time DESC
</select>
<select id="selectMallOrderByGroupId" resultMap="mallOrderVOMap">
SELECT
o.id, o.user_id, o.shop_id, o.order_type, o.delivery_type,
o.status, o.total_amount, o.goods_amount, o.delivery_fee,
o.package_fee, o.address_id, o.remark, o.create_time, o.pay_time,
o.receiver_name, o.receiver_phone, o.receiver_address,
o.shop_name, o.shop_phone, o.shop_address,o.number_code,o.region_id,o.settlement_status,o.shop_make_time,o.other_order,o.user_require_make
FROM mall_order o LEFT JOIN mall_order_group og ON o.id = og.head_order_id
<where>
<if test="groupId != null and groupId != ''">
AND og.id = #{groupId}
</if>
</where>
</select>
</mapper>