|
|
|
|
<?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.MallDeliveryOrderMapper">
|
|
|
|
|
|
|
|
|
|
<resultMap id="deliveryMap" type="cc.hiver.mall.entity.MallDeliveryOrder">
|
|
|
|
|
<id column="id" property="id"/>
|
|
|
|
|
<result column="order_id" property="orderId"/>
|
|
|
|
|
<result column="group_id" property="groupId"/>
|
|
|
|
|
<result column="worker_id" property="workerId"/>
|
|
|
|
|
<result column="shop_id" property="shopId"/>
|
|
|
|
|
<result column="get_area_id" property="getAreaId"/>
|
|
|
|
|
<result column="put_area_id" property="putAreaId"/>
|
|
|
|
|
<result column="delivery_fee" property="deliveryFee"/>
|
|
|
|
|
<result column="delivery_fee_marketplace" property="deliveryFeeMarketplace"/>
|
|
|
|
|
<result column="status" property="status"/>
|
|
|
|
|
<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="accept_time" property="acceptTime"/>
|
|
|
|
|
<result column="get_time" property="getTime"/>
|
|
|
|
|
<result column="must_finish_time" property="mustFinishTime"/>
|
|
|
|
|
<result column="finish_time" property="finishTime"/>
|
|
|
|
|
<result column="delivery_type" property="deliveryType"/>
|
|
|
|
|
<result column="number_code" property="numberCode"/>
|
|
|
|
|
<result column="region_id" property="regionId"/>
|
|
|
|
|
<result column="remark" property="remark"/>
|
|
|
|
|
<result column="all_count" property="allCount"/>
|
|
|
|
|
<result column="phone_number" property="phoneNumber"/>
|
|
|
|
|
<result column="get_codes" property="getCodes"/>
|
|
|
|
|
<result column="get_pictures" property="getPictures"/>
|
|
|
|
|
<result column="is_big" property="isBig"/>
|
|
|
|
|
<result column="is_return" property="isReturn"/>
|
|
|
|
|
<result column="worker_name" property="workerName"/>
|
|
|
|
|
<result column="arrive_time" property="arriveTime"/>
|
|
|
|
|
</resultMap>
|
|
|
|
|
|
|
|
|
|
<!-- 分页查询配送单,支持多条件过滤(抢单大厅:hallOnly=true时只查workerId为空的) -->
|
|
|
|
|
<select id="selectPageVO" resultMap="deliveryMap">
|
|
|
|
|
SELECT
|
|
|
|
|
d.id, d.order_id, d.group_id, d.worker_id, d.shop_id,
|
|
|
|
|
d.get_area_id, d.put_area_id, d.delivery_fee, d.delivery_fee_marketplace,
|
|
|
|
|
d.status, d.create_time, d.accept_time, d.get_time, d.must_finish_time, d.finish_time,
|
|
|
|
|
d.receiver_name, d.receiver_phone, d.receiver_address,
|
|
|
|
|
d.shop_name, d.shop_phone, d.shop_address, d.delivery_type, d.number_code,
|
|
|
|
|
d.region_id,d.remark, d.all_count, d.phone_number, d.get_codes, d.get_pictures, d.is_big,
|
|
|
|
|
d.is_return,d.worker_name, d.arrive_time
|
|
|
|
|
FROM mall_delivery_order d
|
|
|
|
|
<where>
|
|
|
|
|
<if test="q.regionId != null and q.regionId != ''">
|
|
|
|
|
AND d.region_id = #{q.regionId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.workerId != null and q.workerId != ''">
|
|
|
|
|
AND d.worker_id = #{q.workerId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.shopId != null and q.shopId != ''">
|
|
|
|
|
AND d.shop_id = #{q.shopId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.status != null">
|
|
|
|
|
AND d.status = #{q.status}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.getAreaId != null and q.getAreaId != ''">
|
|
|
|
|
AND d.get_area_id = #{q.getAreaId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.putAreaId != null and q.putAreaId != ''">
|
|
|
|
|
AND d.put_area_id = #{q.putAreaId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.hallOnly != null and q.hallOnly == true">
|
|
|
|
|
AND (d.worker_id IS NULL OR d.worker_id = '')
|
|
|
|
|
AND d.status = 0
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.startDate != null and q.startDate != ''">
|
|
|
|
|
AND DATE(d.create_time) >= #{q.startDate}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.endDate != null and q.endDate != ''">
|
|
|
|
|
AND DATE(d.create_time) <= #{q.endDate}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.deliveryType != null">
|
|
|
|
|
AND d.delivery_type = #{q.deliveryType}
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
ORDER BY
|
|
|
|
|
<if test="q.order != null and q.order == 'deliveryFee'">
|
|
|
|
|
d.delivery_fee DESC,
|
|
|
|
|
</if>
|
|
|
|
|
<if test="(q.waimaiData != null and q.waimaiData.size() > 0) or (q.kuaidiData != null and q.kuaidiData.size() > 0)">
|
|
|
|
|
(CASE
|
|
|
|
|
<if test="q.waimaiData != null and q.waimaiData.size() > 0">
|
|
|
|
|
<foreach collection="q.waimaiData" item="rule">
|
|
|
|
|
WHEN d.get_area_id = #{rule.getAreaId} AND d.put_area_id = #{rule.putAreaId} AND d.delivery_type = 1 THEN 1
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.kuaidiData != null and q.kuaidiData.size() > 0">
|
|
|
|
|
<foreach collection="q.kuaidiData" item="rule">
|
|
|
|
|
WHEN d.get_area_id = #{rule.getAreaId} AND d.put_area_id = #{rule.putAreaId} AND d.delivery_type = 2 THEN 1
|
|
|
|
|
</foreach>
|
|
|
|
|
</if>
|
|
|
|
|
ELSE 0
|
|
|
|
|
END) DESC,
|
|
|
|
|
</if>
|
|
|
|
|
(CASE WHEN d.must_finish_time IS NULL THEN 1 ELSE 0 END) ASC,
|
|
|
|
|
d.must_finish_time ASC,d.delivery_fee DESC
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="selectPageVOByStatus" resultMap="deliveryMap">
|
|
|
|
|
SELECT
|
|
|
|
|
d.id, d.order_id, d.group_id, d.worker_id, d.shop_id,
|
|
|
|
|
d.get_area_id, d.put_area_id, d.delivery_fee, d.delivery_fee_marketplace,
|
|
|
|
|
d.status, d.create_time, d.accept_time, d.get_time, d.must_finish_time, d.finish_time,
|
|
|
|
|
d.receiver_name, d.receiver_phone, d.receiver_address,
|
|
|
|
|
d.shop_name, d.shop_phone, d.shop_address, d.delivery_type, d.number_code,
|
|
|
|
|
d.region_id,d.remark, d.all_count, d.phone_number, d.get_codes, d.get_pictures, d.is_big,d.is_return,d.worker_name,d.arrive_time
|
|
|
|
|
FROM mall_delivery_order d
|
|
|
|
|
<where>
|
|
|
|
|
d.status not in (-1,4,0)
|
|
|
|
|
<if test="q.regionId != null and q.regionId != ''">
|
|
|
|
|
AND d.region_id = #{q.regionId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.workerId != null and q.workerId != ''">
|
|
|
|
|
AND d.worker_id = #{q.workerId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.shopId != null and q.shopId != ''">
|
|
|
|
|
AND d.shop_id = #{q.shopId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.status != null">
|
|
|
|
|
AND d.status = #{q.status}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.getAreaId != null and q.getAreaId != ''">
|
|
|
|
|
AND d.get_area_id = #{q.getAreaId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.putAreaId != null and q.putAreaId != ''">
|
|
|
|
|
AND d.put_area_id = #{q.putAreaId}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.hallOnly != null and q.hallOnly == true">
|
|
|
|
|
AND (d.worker_id IS NULL OR d.worker_id = '')
|
|
|
|
|
AND d.status = 0
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.startDate != null and q.startDate != ''">
|
|
|
|
|
AND DATE(d.create_time) >= #{q.startDate}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.endDate != null and q.endDate != ''">
|
|
|
|
|
AND DATE(d.create_time) <= #{q.endDate}
|
|
|
|
|
</if>
|
|
|
|
|
<if test="q.deliveryType != null">
|
|
|
|
|
AND d.delivery_type = #{q.deliveryType}
|
|
|
|
|
</if>
|
|
|
|
|
</where>
|
|
|
|
|
ORDER BY (CASE WHEN d.must_finish_time IS NULL THEN 1 ELSE 0 END) ASC
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<!--
|
|
|
|
|
统计配送员当前活跃单量
|
|
|
|
|
返回:waitPickup(待取货数)、delivering(配送中数)
|
|
|
|
|
-->
|
|
|
|
|
<select id="countActiveOrdersByWorker" resultType="map">
|
|
|
|
|
SELECT
|
|
|
|
|
SUM(CASE WHEN status = 1 THEN 1 ELSE 0 END) AS waitPickup,
|
|
|
|
|
SUM(CASE WHEN status = 2 THEN 1 ELSE 0 END) AS delivering
|
|
|
|
|
FROM mall_delivery_order
|
|
|
|
|
WHERE worker_id = #{workerId}
|
|
|
|
|
AND status IN (1, 2)
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
<select id="countOrdersByType" resultType="map">
|
|
|
|
|
SELECT delivery_type as deliveryType,count(*) as orderCount
|
|
|
|
|
FROM mall_delivery_order
|
|
|
|
|
WHERE region_id = #{regionId} and worker_id is null and status = 0 group by delivery_type
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<select id="countOrdersByStatus" resultType="map">
|
|
|
|
|
SELECT status ,count(*) as orderCount FROM `mall_delivery_order` where `status` in (0,1,2)
|
|
|
|
|
and worker_id = #{workerId} GROUP BY status
|
|
|
|
|
</select>
|
|
|
|
|
|
|
|
|
|
</mapper>
|