456 lines
		
	
	
		
			19 KiB
		
	
	
	
		
			XML
		
	
			
		
		
	
	
			456 lines
		
	
	
		
			19 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.hcy.common.mapper.order.OrderMapper">
 | |
|     <!-- 通用查询映射结果 -->
 | |
|     <resultMap id="BaseResultMap" type="com.hcy.common.entity.order.Order">
 | |
|         <!-- <id column="id" property="id"/>
 | |
|          <result column="create_id" property="createId"/>
 | |
|          <result column="create_time" property="createTime"/>
 | |
|          <result column="update_id" property="updateId"/>
 | |
|          <result column="update_time" property="updateTime"/>
 | |
|          <result column="company_id" property="companyId"/>
 | |
|          <result column="account_id" property="accountId"/>
 | |
|          <result column="account_chart_id" property="accountChartId"/>
 | |
|          <result column="is_add_next_level" property="isAddNextLevel"/>
 | |
|          <result column="is_reallocate" property="isReallocate"/>
 | |
|          <result column="tenant_id" property="tenantId"/>-->
 | |
|     </resultMap>
 | |
| 
 | |
|     <sql id="base_sql">
 | |
|         id,
 | |
|         sn,
 | |
|         user_id,
 | |
|         transaction_id,
 | |
|         staff_id,
 | |
|         order_type,
 | |
|         order_terminal,
 | |
|         order_status,
 | |
|         pay_status,
 | |
|         pay_way,
 | |
|         goods_price,
 | |
|         order_amount,
 | |
|         total_amount,
 | |
|         total_num,
 | |
|         user_remark,
 | |
|         order_remarks,
 | |
|         verification_code,
 | |
|         verification_status,
 | |
|         contact,
 | |
|         mobile,
 | |
|         province_id,
 | |
|         city_id,
 | |
|         district_id,
 | |
|         address,
 | |
|         is_dispatch,
 | |
|         create_time,
 | |
|         update_time,
 | |
|         pay_time,
 | |
|         delete_time,
 | |
|         cancel_time,
 | |
|         appoint_time_start,
 | |
|         appoint_time_end,
 | |
|         finish_time
 | |
|     </sql>
 | |
| 
 | |
|     <select id="page" resultType="com.hcy.common.dto.result.OrderPageResultDto">
 | |
|         select a.id,
 | |
|                a.sn,
 | |
|                a.user_id             as userId,
 | |
|                a.transaction_id      as transactionId,
 | |
|                a.staff_id            as staffId,
 | |
|                a.order_type          as orderType,
 | |
|                a.order_terminal      as orderTerminal,
 | |
|                a.order_status        as orderStatus,
 | |
|                a.pay_status          as payStatus,
 | |
|                a.pay_way             as payWay,
 | |
|                a.goods_price         as goodsPrice,
 | |
|                a.order_amount        as orderAmount,
 | |
|                a.total_amount        as totalAmount,
 | |
|                a.total_num           as totalNum,
 | |
|                a.user_remark         as userRemark,
 | |
|                a.order_remarks       as orderRemarks,
 | |
|                a.verification_code   as verificationCode,
 | |
|                a.verification_status as verificationStatus,
 | |
|                a.contact,
 | |
|                a.mobile,
 | |
|                a.province_id         as provinceId,
 | |
|                a.city_id             as cityId,
 | |
|                a.district_id         as districtId,
 | |
|                a.address,
 | |
|                a.is_dispatch         as isDispatch,
 | |
|                a.create_time         as createTime,
 | |
|                a.update_time         as updateTime,
 | |
|                a.pay_time            as payTime,
 | |
|                a.delete_time         as deleteTime,
 | |
|                a.cancel_time         as cancelTime,
 | |
|                a.appoint_time_start  as appointTimeStart,
 | |
|                a.appoint_time_end    as appointTimeEnd,
 | |
|                a.finish_time         as finishTime,
 | |
|                b.sn                  as userSn,
 | |
|                b.avatar,
 | |
|                b.nickname,
 | |
|                b.username,
 | |
|                c.goods_id            as goodsId,
 | |
|                c.goods_name          as goodsName,
 | |
|                c.unit_name           as unitName,
 | |
|                d.image               as goodsImage,
 | |
|                e.name                as staffName
 | |
|         from la_order a
 | |
|                      left join la_order_goods c on a.id = c.order_id
 | |
|                      left join la_user b on a.user_id = b.id
 | |
|                      left join la_goods d on c.goods_id = d.id
 | |
|                      left join la_staff e on a.staff_id = e.id
 | |
|         <where>
 | |
|             a.is_delete = 0
 | |
|             <if test="form.orderStatus != null and form.orderStatus == 4">
 | |
|                 and a.order_status in (4, 5)
 | |
|             </if>
 | |
|             <if test="form.orderStatus != null and form.orderStatus != 4">
 | |
|                 and a.order_status= #{form.orderStatus}
 | |
|             </if>
 | |
|             <if test="form.sn != null and form.sn != ''">
 | |
|                 and a.sn like concat('%', #{form.sn}, '%')
 | |
|             </if>
 | |
|             <if test="form.goodsName != null and form.goodsName != ''">
 | |
|                 and c.goods_name like concat('%', #{form.goodsName}, '%')
 | |
|             </if>
 | |
|             <if test="form.payStatus != null">
 | |
|                 and a.pay_status = #{form.payStatus}
 | |
|             </if>
 | |
|             <if test="form.isDispatch != null">
 | |
|                 and a.is_dispatch = #{form.isDispatch}
 | |
|             </if>
 | |
|             <if test="form.userInfo != null and form.userInfo != ''">
 | |
|                 and (b.nickname like concat('%', #{form.userInfo}, '%') or
 | |
|                      b.sn like concat('%', #{form.userInfo}, '%'))
 | |
|             </if>
 | |
|             <if test="form.orderTimeStart != null">
 | |
|                 and a.create_time >= #{form.orderTimeStart}
 | |
|             </if>
 | |
|             <if test="form.orderTimeEnd != null">
 | |
|                 and a.create_time <= #{form.orderTimeEnd}
 | |
|             </if>
 | |
|             <if test="form.staffInfo != null and form.staffInfo != ''">
 | |
|                 and e.name like concat('%', #{form.staffInfo}, '%') or
 | |
|                     e.sn like concat('%', #{form.staffInfo}, '%')
 | |
|             </if>
 | |
|         </where>
 | |
|         order by a.id desc
 | |
|     </select>
 | |
| 
 | |
|     <select id="listWaitComment" resultType="com.hcy.common.dto.result.OrderPageResultDto">
 | |
|         select a.id,
 | |
|                a.sn,
 | |
|                a.user_id             as userId,
 | |
|                a.transaction_id      as transactionId,
 | |
|                a.staff_id            as staffId,
 | |
|                a.order_type          as orderType,
 | |
|                a.order_terminal      as orderTerminal,
 | |
|                a.order_status        as orderStatus,
 | |
|                a.pay_status          as payStatus,
 | |
|                a.pay_way             as payWay,
 | |
|                a.goods_price         as goodsPrice,
 | |
|                a.order_amount        as orderAmount,
 | |
|                a.total_amount        as totalAmount,
 | |
|                a.total_num           as totalNum,
 | |
|                a.user_remark         as userRemark,
 | |
|                a.order_remarks       as orderRemarks,
 | |
|                a.verification_code   as verificationCode,
 | |
|                a.verification_status as verificationStatus,
 | |
|                a.contact,
 | |
|                a.mobile,
 | |
|                a.province_id         as provinceId,
 | |
|                a.city_id             as cityId,
 | |
|                a.district_id         as districtId,
 | |
|                a.address,
 | |
|                a.is_dispatch         as isDispatch,
 | |
|                a.create_time         as createTime,
 | |
|                a.update_time         as updateTime,
 | |
|                a.pay_time            as payTime,
 | |
|                a.delete_time         as deleteTime,
 | |
|                a.cancel_time         as cancelTime,
 | |
|                a.appoint_time_start  as appointTimeStart,
 | |
|                a.appoint_time_end    as appointTimeEnd,
 | |
|                a.finish_time         as finishTime,
 | |
|                c.goods_id            as goodsId,
 | |
|                c.goods_name          as goodsName,
 | |
|                c.unit_name           as unitName,
 | |
|                d.image               as goodsImage
 | |
|         from la_order a
 | |
|                      left join la_order_goods c on a.id = c.order_id
 | |
|                      left join la_goods d on c.goods_id = d.id
 | |
|         where a.is_delete = 0
 | |
|           and c.is_comment = 0
 | |
|           and a.user_id = #{form.userId}
 | |
|           and a.order_status = #{form.orderStatus}
 | |
|         order by a.id desc
 | |
|     </select>
 | |
| 
 | |
|     <select id="groupSalesAmount" resultType="com.hcy.common.dto.result.OrderGroupResultDto">
 | |
|         select from_unixtime(create_time, '%Y-%m-%d') as orderTime, sum(total_amount) as totalAmount
 | |
|         from la_order
 | |
|         where pay_status = #{form.payStatus}
 | |
|           and create_time <= #{form.endTime}
 | |
|           and create_time >= #{form.startTime}
 | |
|         group by from_unixtime(create_time, '%Y-%m-%d')
 | |
|         order by from_unixtime(create_time, '%Y-%m-%d') asc
 | |
|     </select>
 | |
| 
 | |
|     <select id="listFinishOrder" resultType="com.hcy.common.dto.result.OrderPageResultDto">
 | |
|         select a.id,
 | |
|                a.sn,
 | |
|                a.user_id             as userId,
 | |
|                a.transaction_id      as transactionId,
 | |
|                a.staff_id            as staffId,
 | |
|                a.order_type          as orderType,
 | |
|                a.order_terminal      as orderTerminal,
 | |
|                a.order_status        as orderStatus,
 | |
|                a.pay_status          as payStatus,
 | |
|                a.pay_way             as payWay,
 | |
|                a.goods_price         as goodsPrice,
 | |
|                a.order_amount        as orderAmount,
 | |
|                a.total_amount        as totalAmount,
 | |
|                a.total_num           as totalNum,
 | |
|                a.user_remark         as userRemark,
 | |
|                a.order_remarks       as orderRemarks,
 | |
|                a.verification_code   as verificationCode,
 | |
|                a.verification_status as verificationStatus,
 | |
|                a.contact,
 | |
|                a.mobile,
 | |
|                a.province_id         as provinceId,
 | |
|                a.city_id             as cityId,
 | |
|                a.district_id         as districtId,
 | |
|                a.address,
 | |
|                a.is_dispatch         as isDispatch,
 | |
|                a.create_time         as createTime,
 | |
|                a.update_time         as updateTime,
 | |
|                a.pay_time            as payTime,
 | |
|                a.delete_time         as deleteTime,
 | |
|                a.cancel_time         as cancelTime,
 | |
|                a.appoint_time_start  as appointTimeStart,
 | |
|                a.appoint_time_end    as appointTimeEnd,
 | |
|                a.finish_time         as finishTime,
 | |
|                c.is_comment          as isComment
 | |
|         from la_order a
 | |
|                      left join la_order_goods c on a.id = c.order_id
 | |
|         where a.is_delete = 0
 | |
|           and a.user_id = #{userId}
 | |
|           and a.order_status = 3
 | |
|     </select>
 | |
| 
 | |
|     <select id="pageDistributionOrder" resultType="com.hcy.common.dto.result.OrderDistributionResultDto">
 | |
|         select
 | |
|         a.sn,
 | |
|         a.total_amount        as totalAmount,
 | |
|         a.order_amount        as orderAmount,
 | |
|         a.total_num           as totalNum,
 | |
|         a.finish_time         as finishTime,
 | |
|         c.name                as goodsName,
 | |
|         d.name                as categoryName,
 | |
|         e.name                as distributorName,
 | |
|         e.dist_num            as distNum,
 | |
|         e.group_id          as groupId,
 | |
|         dc.goods_commission_rate as goodsCommissionRate,
 | |
|         dc.distributor_commission_rate as distributorCommissionRate,
 | |
|         dc.commission       as commission
 | |
|         from la_order a
 | |
|         left join la_order_goods b on a.id = b.order_id
 | |
|         left join la_goods c on b.goods_id = c.id
 | |
|         left join la_goods_category d on c.category_id = d.id
 | |
|         left join la_distributor e on a.distributor_id = e.id
 | |
|         left join la_distributor_commission dc on dc.order_id = a.id and e.id = dc.distributor_id
 | |
|         <where>
 | |
|             a.is_delete = 0
 | |
|             and a.order_status IN ( 1, 2, 3)
 | |
|             and a.distributor_id != 0
 | |
|             <if test="form.distributorName != null and form.distributorName != ''">
 | |
|                 and e.name like concat('%', #{form.distributorName}, '%')
 | |
|             </if>
 | |
|             <if test="form.distNum != null and form.distNum != ''">
 | |
|                 and e.dist_num like concat('%', #{form.distNum}, '%')
 | |
|             </if>
 | |
|             <if test="form.groupId != null and form.groupId != ''">
 | |
|                 and e.group_id = #{form.groupId}
 | |
|             </if>
 | |
|             <if test="form.categoryId != null">
 | |
|                 and d.id = #{form.categoryId}
 | |
|             </if>
 | |
|             <if test="form.finishStartTime != null">
 | |
|                 and a.finish_time >= #{form.finishStartTime}
 | |
|             </if>
 | |
|             <if test="form.finishEndTime != null">
 | |
|                 and a.finish_time <= #{form.finishEndTime}
 | |
|             </if>
 | |
|         </where>
 | |
|         order by a.id desc
 | |
|     </select>
 | |
| 
 | |
|     <select id="listDistributionOrder" resultType="com.hcy.common.dto.result.OrderDistributionResultDto">
 | |
|         select
 | |
|         a.sn,
 | |
|         a.order_amount        as orderAmount,
 | |
|         a.total_num           as totalNum,
 | |
|         a.finish_time         as finishTime,
 | |
|         c.name                as goodsName,
 | |
|         d.name                as categoryName,
 | |
|         e.name                as distributorName,
 | |
|         e.dist_num            as distNum,
 | |
|         e.group_id          as groupId,
 | |
|         a.total_amount      as totalAmount,
 | |
|         dc.goods_commission_rate as goodsCommissionRate,
 | |
|         dc.commission       as commission
 | |
|         from la_order a
 | |
|         left join la_order_goods b on a.id = b.order_id
 | |
|         left join la_goods c on b.goods_id = c.id
 | |
|         left join la_goods_category d on c.category_id = d.id
 | |
|         left join la_distributor e on a.distributor_id = e.id
 | |
|         left join la_distributor_commission as dc on dc.order_id = a.id and e.id = dc.distributor_id
 | |
|         <where>
 | |
|             a.is_delete = 0
 | |
|             and a.order_status = 3
 | |
|             and a.distributor_id != 0
 | |
|             <if test="form.distributorName != null and form.distNum != ''">
 | |
|                 and e.name like concat('%', #{form.distributorName}, '%')
 | |
|             </if>
 | |
|             <if test="form.distNum != null and form.distNum != ''">
 | |
|                 and e.dist_num like concat('%', #{form.distNum}, '%')
 | |
|             </if>
 | |
|             <if test="form.groupId != null and form.groupId != ''">
 | |
|                 and e.group_id = #{form.groupId}
 | |
|             </if>
 | |
|             <if test="form.categoryId != null">
 | |
|                 and d.id = #{form.categoryId}
 | |
|             </if>
 | |
|             <if test="form.finishStartTime != null">
 | |
|                 and a.finish_time >= #{form.finishStartTime}
 | |
|             </if>
 | |
|             <if test="form.finishEndTime != null">
 | |
|                 and a.finish_time <= #{form.finishEndTime}
 | |
|             </if>
 | |
|         </where>
 | |
|         order by a.id desc
 | |
|     </select>
 | |
| 
 | |
| 
 | |
|     <select id="sumAmountByDistribution" resultType="com.hcy.common.dto.OrderDto">
 | |
|         select
 | |
|         sum(a.total_amount ) as totalOrderAmount,
 | |
|         sum(a.order_amount ) as actualPaymentTotal,
 | |
|         sum(dc.commission ) as totalCommissionAmount
 | |
|         from la_order a
 | |
|         left join la_order_goods b on a.id = b.order_id
 | |
|         left join la_goods c on b.goods_id = c.id
 | |
|         left join la_goods_category d on c.category_id = d.id
 | |
|         left join la_distributor e on a.distributor_id = e.id
 | |
|         left join la_distributor_commission dc on a.id = dc.order_id
 | |
|         <where>
 | |
|             a.is_delete = 0
 | |
|             and a.order_status = 3
 | |
|             and a.distributor_id != 0
 | |
|             <if test="form.distributorName != null and form.distributorName != ''">
 | |
|                 and e.name like concat('%', #{form.distributorName}, '%')
 | |
|             </if>
 | |
|             <if test="form.distNum != null and form.distNum != ''">
 | |
|                 and e.dist_num like concat('%', #{form.distNum}, '%')
 | |
|             </if>
 | |
|             <if test="form.groupId != null and form.groupId != ''">
 | |
|                 and e.group_id = #{form.groupId}
 | |
|             </if>
 | |
|             <if test="form.categoryId != null">
 | |
|                 and d.id = #{form.categoryId}
 | |
|             </if>
 | |
|             <if test="form.finishStartTime != null">
 | |
|                 and a.finish_time >= #{form.finishStartTime}
 | |
|             </if>
 | |
|             <if test="form.finishEndTime != null">
 | |
|                 and a.finish_time <= #{form.finishEndTime}
 | |
|             </if>
 | |
|         </where>
 | |
|     </select>
 | |
| 
 | |
|     <select id="getGoodsNameAndGoodsCategoryNameByOrderId" resultType="com.hcy.common.dto.OrderDto">
 | |
|         SELECT
 | |
|             og.goods_name as goodsName,gc.`name` as goodsCategoryName
 | |
|         FROM
 | |
|             la_order_goods AS og
 | |
|             LEFT JOIN la_goods AS g ON g.id = og.goods_id
 | |
|             LEFT JOIN la_goods_category AS gc ON gc.id = g.category_id
 | |
|         WHERE
 | |
|             og.order_id = #{orderId}
 | |
|     </select>
 | |
| 
 | |
|     <select id="getOrderByStaffId" resultType="com.hcy.common.dto.OrderDto">
 | |
|         SELECT
 | |
|             o.*,og.goods_name as goodsName,og.staff_commission_rate as staffCommissionRate
 | |
|         FROM
 | |
|             la_order AS o
 | |
|             LEFT JOIN la_order_goods AS og ON o.id = og.order_id
 | |
|             LEFT JOIN la_goods AS g ON g.id = og.goods_id
 | |
|             AND g.is_delete = 0
 | |
|         WHERE
 | |
|             o.order_status = 1
 | |
|             AND o.is_delete = 0
 | |
|             AND o.staff_id IS NULL
 | |
|             <if test="cityId != null">
 | |
|                 AND o.city_id = #{cityId}
 | |
|             </if>
 | |
|             AND FIND_IN_SET(g.id,(SELECT goods_ids FROM la_staff WHERE id = #{staffId} AND is_delete = 0))
 | |
|     </select>
 | |
| 
 | |
|     <select id="getAllOrder" resultType="com.hcy.common.dto.OrderDto">
 | |
|         SELECT
 | |
|             o.*,og.goods_name as goodsName,og.staff_commission_rate as staffCommissionRate
 | |
|         FROM
 | |
|             la_order AS o
 | |
|             LEFT JOIN la_order_goods AS og ON o.id = og.order_id
 | |
|         WHERE
 | |
|             o.order_status = 1
 | |
|           AND o.is_delete = 0
 | |
|           AND o.staff_id IS NULL
 | |
|           <if test="cityId != null">
 | |
|               AND o.city_id = #{cityId}
 | |
|           </if>
 | |
|     </select>
 | |
| 
 | |
|     <select id="getOrderDetailByOrderId" resultType="com.hcy.common.dto.OrderDto">
 | |
|         SELECT
 | |
|             o.*,g.name as goodsName,g.staff_commission_rate as staffCommissionRate,og.id as orderGoodsId
 | |
|         FROM
 | |
|             la_order AS o
 | |
|                 LEFT JOIN la_order_goods AS og ON o.id = og.order_id
 | |
|                 LEFT JOIN la_goods AS g ON g.id = og.goods_id
 | |
|                 AND g.is_delete = 0
 | |
|         WHERE
 | |
|           o.is_delete = 0
 | |
|           AND o.id = #{orderId}
 | |
|     </select>
 | |
| 
 | |
|     <select id="getNoCommentOrder" resultType="com.hcy.common.dto.OrderDto">
 | |
|         SELECT
 | |
|             o.*,og.goods_id as goodsId,og.id as orderGoodsId
 | |
|         FROM
 | |
|             la_order AS o
 | |
|                 LEFT JOIN la_order_goods AS og ON o.id = og.order_id
 | |
|                 LEFT JOIN la_goods_comment AS gc ON og.id = gc.order_goods_id
 | |
|         WHERE
 | |
|             o.is_delete = 0
 | |
|           AND o.order_status = 3
 | |
|           AND gc.id is null
 | |
|     </select>
 | |
| 
 | |
|     <select id="getDistributorOrderNoByDate" resultType="com.hcy.common.dto.OrderDto">
 | |
|         SELECT
 | |
|             o.*
 | |
|         FROM
 | |
|             la_order AS o
 | |
|                 LEFT JOIN la_order_goods AS og ON og.order_id = o.id
 | |
|         WHERE
 | |
|             o.is_delete = 0
 | |
|           AND order_status IN ( 1, 2, 3, 4)
 | |
|           AND o.distributor_id = #{distributorId}
 | |
|           AND DATE_FORMAT( from_unixtime( o.create_time ), '%Y-%m' ) = #{date}
 | |
|         ORDER BY
 | |
|             from_unixtime( o.create_time ) DESC
 | |
|     </select>
 | |
| </mapper>
 |