108 lines
4.6 KiB
XML
108 lines
4.6 KiB
XML
<?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="com.nlshop.mapper.OrderMapper">
|
|
<resultMap id="BaseResultMap" type="com.nlshop.entity.Order">
|
|
<id column="id" property="id"/>
|
|
<result column="order_no" property="orderNo"/>
|
|
<result column="user_id" property="userId"/>
|
|
<result column="merchant_id" property="merchantId"/>
|
|
<result column="total_amount" property="totalAmount"/>
|
|
<result column="payment_method" property="paymentMethod"/>
|
|
<result column="payment_status" property="paymentStatus"/>
|
|
<result column="order_status" property="orderStatus"/>
|
|
<result column="address" property="address"/>
|
|
<result column="contact_phone" property="contactPhone"/>
|
|
<result column="create_time" property="createTime"/>
|
|
<result column="pay_time" property="payTime"/>
|
|
<result column="complete_time" property="completeTime"/>
|
|
<association property="merchant" javaType="com.nlshop.entity.Merchant">
|
|
<id column="m_id" property="id"/>
|
|
<result column="m_store_name" property="storeName"/>
|
|
</association>
|
|
</resultMap>
|
|
|
|
<insert id="insert" parameterType="com.nlshop.entity.Order" useGeneratedKeys="true" keyProperty="id">
|
|
INSERT INTO `order` (order_no, user_id, merchant_id, total_amount, payment_method,
|
|
payment_status, order_status, address, contact_phone, pay_time, complete_time)
|
|
VALUES (#{orderNo}, #{userId}, #{merchantId}, #{totalAmount}, #{paymentMethod},
|
|
#{paymentStatus}, #{orderStatus}, #{address}, #{contactPhone}, #{payTime}, #{completeTime})
|
|
</insert>
|
|
|
|
<select id="selectById" resultMap="BaseResultMap">
|
|
SELECT o.*, m.id as m_id, m.store_name as m_store_name
|
|
FROM `order` o
|
|
LEFT JOIN merchant m ON o.merchant_id = m.id
|
|
WHERE o.id = #{id}
|
|
</select>
|
|
|
|
<select id="selectByOrderNo" resultMap="BaseResultMap">
|
|
SELECT * FROM `order` WHERE order_no = #{orderNo}
|
|
</select>
|
|
|
|
<select id="selectByUserId" resultMap="BaseResultMap">
|
|
SELECT o.*, m.id as m_id, m.store_name as m_store_name
|
|
FROM `order` o
|
|
LEFT JOIN merchant m ON o.merchant_id = m.id
|
|
WHERE o.user_id = #{userId}
|
|
<if test="status != null and status != ''">
|
|
AND o.order_status = #{status}
|
|
</if>
|
|
ORDER BY o.create_time DESC
|
|
</select>
|
|
|
|
<select id="selectByMerchantId" resultMap="BaseResultMap">
|
|
SELECT o.*, m.id as m_id, m.store_name as m_store_name
|
|
FROM `order` o
|
|
LEFT JOIN merchant m ON o.merchant_id = m.id
|
|
WHERE o.merchant_id = #{merchantId}
|
|
<if test="status != null and status != ''">
|
|
AND o.order_status = #{status}
|
|
</if>
|
|
ORDER BY o.create_time DESC
|
|
</select>
|
|
|
|
<update id="update" parameterType="com.nlshop.entity.Order">
|
|
UPDATE `order`
|
|
<set>
|
|
<if test="totalAmount != null">total_amount = #{totalAmount},</if>
|
|
<if test="paymentMethod != null">payment_method = #{paymentMethod},</if>
|
|
<if test="paymentStatus != null">payment_status = #{paymentStatus},</if>
|
|
<if test="orderStatus != null">order_status = #{orderStatus},</if>
|
|
<if test="address != null">address = #{address},</if>
|
|
<if test="contactPhone != null">contact_phone = #{contactPhone},</if>
|
|
<if test="payTime != null">pay_time = #{payTime},</if>
|
|
<if test="completeTime != null">complete_time = #{completeTime},</if>
|
|
</set>
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
<update id="updateStatus">
|
|
UPDATE `order` SET order_status = #{status} WHERE id = #{id}
|
|
</update>
|
|
|
|
<update id="updatePayment">
|
|
UPDATE `order`
|
|
SET payment_status = #{paymentStatus},
|
|
payment_method = #{paymentMethod},
|
|
pay_time = NOW()
|
|
WHERE id = #{id}
|
|
</update>
|
|
|
|
<select id="selectStickyUsers" resultType="java.util.HashMap">
|
|
SELECT
|
|
u.id as userId,
|
|
u.username,
|
|
u.name,
|
|
COUNT(o.id) as orderCount,
|
|
SUM(o.total_amount) as totalAmount
|
|
FROM `order` o
|
|
INNER JOIN user u ON o.user_id = u.id
|
|
WHERE o.merchant_id = #{merchantId}
|
|
AND o.order_status = 'COMPLETED'
|
|
AND o.create_time >= DATE_SUB(NOW(), INTERVAL #{days} DAY)
|
|
GROUP BY u.id, u.username, u.name
|
|
HAVING COUNT(o.id) >= #{minOrders}
|
|
ORDER BY orderCount DESC, totalAmount DESC
|
|
</select>
|
|
</mapper>
|