<?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.matrix.system.hive.dao.SysOrderDao">
|
|
<resultMap type="SysOrder" id="SysOrderMap">
|
<id property="id" column="ID"/>
|
<result property="vipId" column="VIP_ID"/>
|
<result property="orderTime" column="ORDER_TIME"/>
|
<result property="remark" column="REMARK"/>
|
<result property="staffId" column="STAFF_ID"/>
|
<result property="isCross" column="IS_CROSS"/>
|
<result property="orderNo" column="ORDER_NO"/>
|
<result property="activity" column="ACTIVITY"/>
|
<result property="total" column="TOTAL"/>
|
|
<result property="statu" column="STATU"/>
|
<result property="zkTotal" column="ZK_TOTAL"/>
|
<result property="shopId" column="SHOP_ID"/>
|
<result property="vipName" column="VIP_NAME"/>
|
<result property="vipNo" column="VIP_NO"/>
|
<result property="staffName" column="STAFF_NAME"/>
|
<result property="changeId" column="CHANGE_ID"/>
|
|
<result property="cashPay" column="cash_Pay"/>
|
<result property="cardPay" column="card_Pay"/>
|
<result property="arrears" column="arrears"/>
|
<result property="payTime" column="pay_time"/>
|
|
<!-- 扩展字段 -->
|
<result property="shopName" column="SHOP_NAME"/>
|
<result property="shopShortName" column="SHOP_SHORT_NAME"/>
|
<result property="vipPhone" column="PHONE"/>
|
|
|
</resultMap>
|
|
|
<!-- 插入方法 -->
|
<insert id="insert" parameterType="SysOrder" useGeneratedKeys="true"
|
keyProperty="id">
|
INSERT INTO sys_order (
|
ID,
|
VIP_ID,
|
ORDER_TIME,
|
REMARK,
|
STAFF_ID,
|
IS_CROSS,
|
ORDER_NO,
|
ACTIVITY,
|
TOTAL,
|
card_Pay,
|
STATU,
|
arrears,
|
ZK_TOTAL,
|
SHOP_ID,
|
CHANGE_ID,
|
cash_Pay,
|
beatuyId,
|
beatuyName,
|
pay_time,
|
company_id
|
)
|
VALUES (
|
#{id},
|
#{vipId},
|
#{orderTime},
|
#{remark},
|
#{staffId},
|
#{isCross},
|
#{orderNo},
|
#{activity},
|
#{total},
|
#{cardPay},
|
#{statu},
|
#{arrears},
|
#{zkTotal},
|
#{shopId},
|
#{changeId},
|
#{cashPay},
|
#{beatuyId},
|
#{beatuyName},
|
#{payTime},
|
#{companyId}
|
)
|
</insert>
|
|
<!-- 更新订单时间 -->
|
<update id="updateOrderTime">
|
UPDATE sys_order
|
set ORDER_TIME = #{orderTime}
|
WHERE id=#{id}
|
</update>
|
|
<!-- 根据id更新 部分更新 -->
|
<update id="update">
|
UPDATE sys_order
|
<set>
|
<if test="vipId != null and vipId !='' ">
|
VIP_ID = #{vipId},
|
</if>
|
<if test="orderTime != null ">
|
ORDER_TIME = #{orderTime},
|
</if>
|
<if test="remark != null and remark !='' ">
|
REMARK = #{remark},
|
</if>
|
<if test="staffId != null and staffId !='' ">
|
STAFF_ID = #{staffId},
|
</if>
|
<if test="isCross != null and isCross !='' ">
|
IS_CROSS = #{isCross},
|
</if>
|
<if test="orderNo != null and orderNo !='' ">
|
ORDER_NO = #{orderNo},
|
</if>
|
<if test="activity != null and activity !='' ">
|
ACTIVITY = #{activity},
|
</if>
|
<if test="total != null and total !='' ">
|
TOTAL = #{total},
|
</if>
|
<if test="cardPay != null and cardPay !='' ">
|
card_Pay = #{cardPay},
|
</if>
|
<if test="arrears ==0 or arrears != null and arrears !='' ">
|
arrears = #{arrears},
|
</if>
|
<if test="statu != null and statu !='' ">
|
STATU = #{statu},
|
</if>
|
<if test="zkTotal != null or zkTotal == 0 ">
|
ZK_TOTAL = #{zkTotal},
|
</if>
|
<if test="changeId != null and changeId !='' ">
|
CHANGE_ID = #{changeId},
|
</if>
|
<if test="cashPay != null and cashPay !='' ">
|
cash_Pay = #{cashPay},
|
</if>
|
|
<if test="payTime != null ">
|
pay_time = #{payTime},
|
</if>
|
|
</set>
|
WHERE id=#{id}
|
</update>
|
|
<!-- 批量删除 -->
|
<delete id="deleteByIds" parameterType="java.util.List">
|
delete from sys_order where ID in
|
<foreach collection="list" index="index" item="item" open="("
|
separator="," close=")">
|
#{item}
|
</foreach>
|
</delete>
|
|
<!-- 根据id删除 -->
|
<delete id="deleteById">
|
DELETE FROM sys_order
|
where ID=#{id}
|
</delete>
|
|
<!-- 分页查询 -->
|
<select id="selectInPage" resultMap="SysOrderMap">
|
select
|
a.*, b.VIP_NAME, c.su_name as STAFF_NAME,
|
d.SHOP_NAME, b.PHONE
|
from sys_order a
|
LEFT JOIN sys_vip_info b on b.ID=a.VIP_ID
|
left JOIN sys_users c on c.su_id=a.STAFF_ID
|
left JOIN sys_shop_info d on d.ID=a.SHOP_ID
|
where 1=1
|
<if test="record!=null">
|
<if test="record.keyWordVo != null and record.keyWordVo!='' ">
|
and (b.PHONE like concat('%',#{record.keyWordVo},'%')
|
or b.vip_no like concat('%',#{record.keyWordVo},'%')
|
or b.vip_name like concat('%',#{record.keyWordVo},'%') )
|
</if>
|
|
<if test="record.id != null and record.id !='' ">
|
and a.ID = #{record.id}
|
</if>
|
<if test="record.vipName != null and record.vipName !='' ">
|
and b.vip_name like concat('%',#{record.vipName},'%')
|
</if>
|
<if test="record.vipPhone != null and record.vipPhone !='' ">
|
and b.PHONE like concat('%',#{record.vipPhone},'%')
|
</if>
|
<if test="record.id != null and record.id !='' ">
|
and a.ID = #{record.id}
|
</if>
|
<if test="record.vipId != null and record.vipId !='' ">
|
and a.VIP_ID = #{record.vipId}
|
</if>
|
<if test="record.orderTime != null ">
|
and a.ORDER_TIME = #{record.orderTime}
|
</if>
|
<if test="record.staffId != null and record.staffId !='' ">
|
and a.STAFF_ID = #{record.staffId}
|
</if>
|
<if test="record.isCross != null and record.isCross !='' ">
|
and a.IS_CROSS = #{record.isCross}
|
</if>
|
<if test="record.orderNo != null and record.orderNo !='' ">
|
and a.ORDER_NO LIKE CONCAT('%',#{record.orderNo},'%')
|
</if>
|
<if test="record.activity != null and record.activity !='' ">
|
and a.ACTIVITY = #{record.activity}
|
</if>
|
<if test="record.cardPay != null and record.cardPay !='' ">
|
and a.card_Pay = #{record.cardPay}
|
</if>
|
<if test="record.arrears != null and record.arrears !='' ">
|
and a.arrears = #{record.arrears}
|
</if>
|
<if test="record.statu != null and record.statu !='' ">
|
and a.STATU = #{record.statu}
|
</if>
|
<if test="record.changeId != null and record.changeId !='' ">
|
and a.CHANGE_ID = #{record.changeId}
|
</if>
|
<if test="record.shopId != null and record.shopId !='' ">
|
and a.SHOP_ID = #{record.shopId}
|
</if>
|
<if test="(record.companyId!=null and record.companyId!='') ">
|
and a.company_id = #{record.companyId}
|
</if>
|
<if test="record.beginTimeVo != null ">
|
and a.ORDER_TIME >= #{record.beginTimeVo}
|
</if>
|
<if test="record.endTimeVo != null ">
|
<![CDATA[and a.ORDER_TIME <= #{record.endTimeVo}]]>
|
</if>
|
|
</if>
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
<if test="pageVo.sort !=null and pageVo.order !=null">
|
order by
|
${pageVo.sort} ${pageVo.order}
|
</if>
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
<select id="selectInPageCount" resultType="java.lang.Integer">
|
select count(*)
|
from sys_order a
|
LEFT JOIN sys_vip_info b on b.ID=a.VIP_ID
|
left JOIN sys_users c on c.su_id=a.STAFF_ID
|
left JOIN sys_shop_info d on d.ID=a.SHOP_ID
|
where 1=1
|
<if test="record!=null">
|
<if test="record.keyWordVo != null and record.keyWordVo!='' ">
|
and (b.PHONE like concat('%',#{record.keyWordVo},'%')
|
or b.vip_no like concat('%',#{record.keyWordVo},'%')
|
or b.vip_name like concat('%',#{record.keyWordVo},'%') )
|
</if>
|
<if test="record.vipName != null and record.vipName !='' ">
|
and b.vip_name like concat('%',#{record.vipName},'%')
|
</if>
|
<if test="record.vipPhone != null and record.vipPhone !='' ">
|
and b.PHONE like concat('%',#{record.vipPhone},'%')
|
</if>
|
<if test="record.id != null and record.id !='' ">
|
and a.ID = #{record.id}
|
</if>
|
<if test="record.vipId != null and record.vipId !='' ">
|
and a.VIP_ID = #{record.vipId}
|
</if>
|
<if test="record.orderTime != null ">
|
and a.ORDER_TIME = #{record.orderTime}
|
</if>
|
<if test="record.staffId != null and record.staffId !='' ">
|
and a.STAFF_ID = #{record.staffId}
|
</if>
|
<if test="(record.companyId!=null and record.companyId!='') ">
|
and a.company_id = #{record.companyId}
|
</if>
|
<if test="record.isCross != null and record.isCross !='' ">
|
and a.IS_CROSS = #{record.isCross}
|
</if>
|
<if test="record.orderNo != null and record.orderNo !='' ">
|
and a.ORDER_NO LIKE CONCAT('%',#{record.orderNo},'%')
|
</if>
|
<if test="record.activity != null and record.activity !='' ">
|
and a.ACTIVITY = #{record.activity}
|
</if>
|
<if test="record.cardPay != null and record.cardPay !='' ">
|
and a.card_Pay = #{record.cardPay}
|
</if>
|
<if test="record.arrears != null and record.arrears !='' ">
|
and a.arrears = #{record.arrears}
|
</if>
|
<if test="record.statu != null and record.statu !='' ">
|
and a.STATU = #{record.statu}
|
</if>
|
<if test="record.changeId != null and record.changeId !='' ">
|
and a.CHANGE_ID = #{record.changeId}
|
</if>
|
<if test="record.shopId != null and record.shopId !='' ">
|
and a.SHOP_ID = #{record.shopId}
|
</if>
|
<if test="record.beginTimeVo != null ">
|
and a.ORDER_TIME >= #{record.beginTimeVo}
|
</if>
|
<if test="record.endTimeVo != null ">
|
<![CDATA[and a.ORDER_TIME <= #{record.endTimeVo}]]>
|
</if>
|
</if>
|
</select>
|
|
|
<!-- 根据id查询 -->
|
<select id="selectById" resultMap="SysOrderMap">
|
select
|
a.*,
|
c.su_name as STAFF_NAME,
|
d.SHOP_NAME,
|
d.shop_short_name,
|
b.PHONE,
|
b.VIP_NAME
|
from sys_order a
|
LEFT JOIN sys_vip_info b on b.ID=a.VIP_ID
|
left JOIN sys_users c on c.su_id=a.STAFF_ID
|
left JOIN sys_shop_info d on d.ID=a.SHOP_ID
|
where a.id=#{id}
|
</select>
|
|
|
<!-- 根据对象查询 -->
|
<select id="selectByModel" resultMap="SysOrderMap">
|
<include refid="select"></include>
|
<include refid="from"></include>
|
<include refid="where"></include>
|
</select>
|
|
|
<sql id="select">
|
select
|
a.*,
|
c.su_name as STAFF_NAME,
|
d.SHOP_NAME,
|
b.PHONE
|
|
</sql>
|
<sql id="from">
|
from sys_order a
|
LEFT JOIN sys_vip_info b on b.ID=a.VIP_ID
|
left JOIN sys_users c on c.su_id=a.STAFF_ID
|
left JOIN sys_shop_info d on d.ID=a.SHOP_ID
|
</sql>
|
<sql id="where">
|
where 1=1
|
<if test="record!=null">
|
<if test="record.id != null and record.id !='' ">
|
and a.ID = #{record.id}
|
</if>
|
<if test="record.vipId != null and record.vipId !='' ">
|
and a.VIP_ID = #{record.vipId}
|
</if>
|
<if test="record.orderTime != null ">
|
and a.ORDER_TIME = #{record.orderTime}
|
</if>
|
|
<if test="record.staffId != null and record.staffId !='' ">
|
and a.STAFF_ID = #{record.staffId}
|
</if>
|
<if test="record.isCross != null and record.isCross !='' ">
|
and a.IS_CROSS = #{record.isCross}
|
</if>
|
<if test="record.orderNo != null and record.orderNo !='' ">
|
and a.ORDER_NO LIKE CONCAT('%',#{record.orderNo},'%')
|
</if>
|
<if test="record.activity != null and record.activity !='' ">
|
and a.ACTIVITY = #{record.activity}
|
</if>
|
<if test="record.cardPay != null and record.cardPay !='' ">
|
and a.card_Pay = #{record.cardPay}
|
</if>
|
<if test="record.arrears != null and record.arrears !='' ">
|
and a.arrears = #{record.arrears}
|
</if>
|
<if test="record.statu != null and record.statu !='' ">
|
and a.STATU = #{record.statu}
|
</if>
|
<if test="record.changeId != null and record.changeId !='' ">
|
and a.CHANGE_ID = #{record.changeId}
|
</if>
|
<if test="record.shopId != null and record.shopId !='' ">
|
and a.SHOP_ID = #{record.shopId}
|
</if>
|
<if test="record.beginTimeVo != null ">
|
and a.ORDER_TIME >= #{record.beginTimeVo}
|
</if>
|
<if test="record.endTimeVo != null ">
|
<![CDATA[and a.ORDER_TIME <= #{record.endTimeVo}]]>
|
</if>
|
<if test="(record.companyId!=null and record.companyId!='') ">
|
and a.company_id = #{record.companyId}
|
</if>
|
|
</if>
|
</sql>
|
|
<sql id="whereVo">
|
where 1=1
|
<if test="record!=null">
|
<if test="record.id != null and record.id !='' ">
|
and a.ID = #{record.id}
|
</if>
|
<if test="record.vipId != null and record.vipId !='' ">
|
and a.VIP_ID = #{record.vipId}
|
</if>
|
<if test="record.orderTime != null ">
|
and a.ORDER_TIME = #{record.orderTime}
|
</if>
|
|
<if test="record.staffId != null and record.staffId !='' ">
|
and a.STAFF_ID = #{record.staffId}
|
</if>
|
<if test="record.isCross != null and record.isCross !='' ">
|
and a.IS_CROSS = #{record.isCross}
|
</if>
|
<if test="record.orderNo != null and record.orderNo !='' ">
|
and a.ORDER_NO LIKE CONCAT('%',#{record.orderNo},'%')
|
</if>
|
<if test="(record.companyId!=null and record.companyId!='') ">
|
and a.company_id = #{record.companyId}
|
</if>
|
<if test="record.activity != null and record.activity !='' ">
|
and a.ACTIVITY = #{record.activity}
|
</if>
|
<if test="record.cardPay != null and record.cardPay !='' ">
|
and a.card_Pay = #{record.cardPay}
|
</if>
|
<if test="record.arrears != null and record.arrears !='' ">
|
and a.arrears = #{record.arrears}
|
</if>
|
<if test="record.statu != null and record.statu !='' ">
|
and a.STATU =#{record.statu}
|
</if>
|
<if test="record.vipPhone != null and record.vipPhone !='' ">
|
and b.PHONE like CONCAT('%',#{record.vipPhone},'%')
|
</if>
|
<if test="record.vipName != null and record.vipName !='' ">
|
and b.VIP_NAME like CONCAT('%',#{record.vipName},'%')
|
</if>
|
<if test="record.shopId != null and record.shopId !='' ">
|
and a.SHOP_ID =#{record.shopId}
|
</if>
|
<if test="record.changeId != null and record.changeId !='' ">
|
and a.CHANGE_ID = #{record.changeId}
|
</if>
|
<if test="record.beginTimeVo != null ">
|
and a.ORDER_TIME >= #{record.beginTimeVo}
|
</if>
|
<if test="record.endTimeVo != null ">
|
<![CDATA[and a.ORDER_TIME <= #{record.endTimeVo}]]>
|
</if>
|
</if>
|
</sql>
|
|
|
<select id="selectVipOrderInfoTotal" resultType="com.matrix.system.hive.bean.SysOrder">
|
select
|
sum(ZK_TOTAL) zkTotal,
|
count(1) times,
|
MAX(pay_time) payTime,
|
GROUP_CONCAT(DISTINCT t2.shop_short_name) shopName
|
from sys_order t1
|
left join sys_shop_info t2 on t1.SHOP_ID=t2.ID
|
where VIP_ID=#{vipId} and STATU='已付款';
|
</select>
|
|
<select id="selectApiOrderListInPage" resultType="com.matrix.system.app.vo.OrderDetailVo">
|
select
|
a.id orderId,
|
a.ORDER_NO orderNo,
|
a.ORDER_TIME orderTime,
|
a.STATU orderStatus,
|
a.ZK_TOTAL needPay,
|
(a.card_Pay + a.cash_Pay) realPay,
|
a.arrears arrears,
|
b.su_name staffName,
|
c.VIP_NAME vipName,
|
c.PHONE phone
|
from sys_order a
|
left join sys_users b on a.STAFF_ID = b.su_id
|
left join sys_vip_info c on c.id = a.VIP_ID
|
<where>
|
<if test="record.queryKey != null and record.queryKey != ''">
|
and (instr(c.vip_name, #{record.queryKey}) or instr(c.phone, #{record.queryKey}) or instr(a.order_no, #{record.queryKey}))
|
</if>
|
<if test="record.status != null and record.status != ''">
|
and a.statu = #{record.status}
|
</if>
|
<if test="record.shopId != null">
|
and a.shop_id=#{record.shopId}
|
</if>
|
</where>
|
<if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
|
order by a.order_time desc
|
<if test="pageVo.offset >=0 and pageVo.limit >0">
|
limit
|
#{pageVo.offset},#{pageVo.limit}
|
</if>
|
</if>
|
</select>
|
|
<select id="selectApiOrderListTotal" resultType="java.lang.Integer">
|
select
|
count(1)
|
from sys_order a
|
left join sys_users b on a.STAFF_ID = b.su_id
|
left join sys_vip_info c on c.id = a.VIP_ID
|
<where>
|
<if test="record.queryKey != null and record.queryKey != ''">
|
and (instr(c.vip_name, #{record.queryKey}) or instr(c.phone, #{record.queryKey}) or instr(a.order_no, #{record.queryKey}))
|
</if>
|
<if test="record.status != null and record.status != ''">
|
and a.statu = #{record.status}
|
</if>
|
<if test="record.shopId != null">
|
and a.shop_id=#{record.shopId}
|
</if>
|
</where>
|
</select>
|
|
<select id="selectApiOrderDetailById" resultType="com.matrix.system.app.vo.OrderDetailVo">
|
select
|
a.id orderId,
|
b.VIP_NAME vipName,
|
b.PHONE phone,
|
a.ORDER_NO orderNo,
|
c.su_name staffName,
|
a.cash_Pay cashPay,
|
a.card_Pay cardPay,
|
a.ZK_TOTAL needPay,
|
a.cash_Pay + a.card_Pay realPay,
|
a.arrears arrears,
|
a.TOTAL - a.ZK_TOTAL discount,
|
a.STATU orderStatus,
|
a.order_time orderTime
|
from sys_order a
|
inner join sys_vip_info b on a.VIP_ID=b.ID
|
left join sys_users c on a.STAFF_ID=c.su_id
|
where a.id=#{orderId}
|
</select>
|
|
<select id="selectShopAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
|
select
|
b.shop_short_name name,
|
b.SHOP_IMAG photo,
|
sum(IFNULL(a.ZK_TOTAL,0)) amount
|
from sys_order a
|
left join sys_shop_info b on a.SHOP_ID=b.ID
|
<where>
|
a.statu in ('已付款', '欠款')
|
<if test="record.companyId != null">
|
and a.company_id=#{record.companyId}
|
</if>
|
<if test='record.type == "1" and record.orderTime != null'>
|
and date_format(order_time, '%Y-%m-%d') = date_format(#{record.orderTime}, '%Y-%m-%d')
|
</if>
|
<if test='record.type == "2" and record.orderTime != null'>
|
and date_format(order_time, '%Y-%m') = date_format(#{record.orderTime}, '%Y-%m')
|
</if>
|
<if test='record.type == "3" and record.orderTime != null'>
|
and date_format(order_time, '%Y') = date_format(#{record.orderTime}, '%Y')
|
</if>
|
</where>
|
group by a.SHOP_ID
|
order by amount desc, a.shop_id
|
</select>
|
|
<select id="selectStaffSaleAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
|
select
|
b.su_name name,
|
b.su_id id,
|
b.su_photo photo,
|
sum(ZK_TOTAL) amount,
|
c.shop_short_name shopName
|
from sys_order a
|
left join sys_users b on a.STAFF_ID=b.su_id
|
left join sys_shop_info c on a.SHOP_ID=c.ID
|
<where>
|
a.statu in ('已付款', '欠款') and b.su_id is not null
|
<if test="record.companyId != null">
|
and a.company_id=#{record.companyId}
|
</if>
|
<if test="record.shopId != null">
|
and a.shop_id=#{record.shopId}
|
</if>
|
<if test='record.type == "1" and record.orderTime != null'>
|
and date_format(order_time, '%Y-%m-%d') = date_format(#{record.orderTime}, '%Y-%m-%d')
|
</if>
|
<if test='record.type == "2" and record.orderTime != null'>
|
and date_format(order_time, '%Y-%m') = date_format(#{record.orderTime}, '%Y-%m')
|
</if>
|
<if test='record.type == "3" and record.orderTime != null'>
|
and date_format(order_time, '%Y') = date_format(#{record.orderTime}, '%Y')
|
</if>
|
</where>
|
group by b.su_id
|
order by amount desc, b.su_id
|
</select>
|
</mapper>
|