935090232@qq.com
2022-02-22 85dce973eb29eb2372c76d5b95b30354da9c41c8
zq-erp/src/main/resources/mybatis/mapper/hive/SysOrderDao.xml
@@ -14,22 +14,27 @@
        <result property="orderNo" column="ORDER_NO"/>
        <result property="activity" column="ACTIVITY"/>
        <result property="total" column="TOTAL"/>
        <result property="cashierName" column="cashierName"/>
        <result property="statu" column="STATU"/>
        <result property="zkTotal" column="ZK_TOTAL"/>
        <result property="shopId" column="SHOP_ID"/>
        <result property="companyId" column="company_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="orderType" column="orderType"/>
        <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="cashierId" column="cashier_id"/>
        <!-- 扩展字段 -->
        <result property="shopName" column="SHOP_NAME"/>
        <result property="shopShortName" column="SHOP_SHORT_NAME"/>
        <result property="vipPhone" column="PHONE"/>
@@ -59,7 +64,10 @@
      beatuyId,
      beatuyName,
      pay_time,
      company_id
      company_id,
      orderType,
        is_has_refund,
        cashier_id
      )
      VALUES (
      #{id},
@@ -81,14 +89,17 @@
      #{beatuyId},
      #{beatuyName},
      #{payTime},
      #{companyId}
      #{companyId},
      #{orderType},
      #{isHasRefund},
      #{cashierId}
      )
   </insert>
    <!-- 更新订单时间 -->
    <update id="updateOrderTime">
      UPDATE sys_order
      set  ORDER_TIME = #{orderTime}
      set  pay_time = #{payTime}
      WHERE id=#{id}
    </update>
@@ -138,11 +149,15 @@
            <if test="cashPay != null and cashPay  !='' ">
                cash_Pay = #{cashPay},
            </if>
            <if test="payTime != null  ">
                pay_time = #{payTime},
            </if>
            <if test="isHasRefund != null  ">
                is_has_refund = #{isHasRefund},
            </if>
            <if test="cashierId != null  ">
                cashier_id = #{cashierId},
            </if>
        </set>
        WHERE id=#{id}
    </update>
@@ -165,11 +180,12 @@
    <!-- 分页查询 -->
    <select id="selectInPage" resultMap="SysOrderMap">
        select
        a.*, b.VIP_NAME, c.su_name as STAFF_NAME,
        a.*, b.VIP_NAME, c.su_name as STAFF_NAME, e.su_name as cashierName,
        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_users e on e.su_id=a.cashier_id
        left JOIN sys_shop_info d on d.ID=a.SHOP_ID
        where 1=1
        <if test="record!=null">
@@ -200,6 +216,9 @@
            <if test="record.staffId != null and record.staffId !='' ">
                and a.STAFF_ID = #{record.staffId}
            </if>
            <if test="record.cashierId != null and record.cashierId !='' ">
                and a.cashier_id = #{record.cashierId}
            </if>
            <if test="record.isCross != null and record.isCross !='' ">
                and a.IS_CROSS = #{record.isCross}
            </if>
@@ -227,11 +246,14 @@
            <if test="(record.companyId!=null and record.companyId!='') ">
                and a.company_id = #{record.companyId}
            </if>
            <if test="(record.orderType!=null and record.orderType!='') ">
                and a.orderType = #{record.orderType}
            </if>
            <if test="record.beginTimeVo != null  ">
                and a.ORDER_TIME >= #{record.beginTimeVo}
                and a.pay_time >= #{record.beginTimeVo}
            </if>
            <if test="record.endTimeVo != null  ">
                <![CDATA[and a.ORDER_TIME <= #{record.endTimeVo}]]>
                <![CDATA[and a.pay_time <= #{record.endTimeVo}]]>
            </if>
        </if>
@@ -278,8 +300,14 @@
            <if test="record.staffId != null and record.staffId !='' ">
                and a.STAFF_ID = #{record.staffId}
            </if>
            <if test="record.cashierId != null and record.cashierId !='' ">
                and a.cashier_id = #{record.cashierId}
            </if>
            <if test="(record.companyId!=null and record.companyId!='') ">
                and a.company_id = #{record.companyId}
            </if>
            <if test="(record.orderType!=null and record.orderType!='') ">
                and a.orderType = #{record.orderType}
            </if>
            <if test="record.isCross != null and record.isCross !='' ">
                and a.IS_CROSS = #{record.isCross}
@@ -306,10 +334,10 @@
                and a.SHOP_ID = #{record.shopId}
            </if>
            <if test="record.beginTimeVo != null ">
                and a.ORDER_TIME >= #{record.beginTimeVo}
                and a.pay_time >= #{record.beginTimeVo}
            </if>
            <if test="record.endTimeVo != null   ">
                <![CDATA[and a.ORDER_TIME <= #{record.endTimeVo}]]>
                <![CDATA[and a.pay_time <= #{record.endTimeVo}]]>
            </if>
        </if>
    </select>
@@ -321,6 +349,7 @@
            a.*,
            c.su_name as STAFF_NAME,
            d.SHOP_NAME,
            d.shop_short_name,
            b.PHONE,
               b.VIP_NAME
        from sys_order a
@@ -369,6 +398,9 @@
            <if test="record.staffId != null and record.staffId !='' ">
                and a.STAFF_ID = #{record.staffId}
            </if>
            <if test="record.cashierId != null and record.cashierId !='' ">
                and a.cashier_id = #{record.cashierId}
            </if>
            <if test="record.isCross != null and record.isCross !='' ">
                and a.IS_CROSS = #{record.isCross}
            </if>
@@ -402,6 +434,9 @@
            <if test="(record.companyId!=null and record.companyId!='') ">
                and a.company_id = #{record.companyId}
            </if>
            <if test="(record.orderType!=null and record.orderType!='') ">
                and a.orderType = #{record.orderType}
            </if>
        </if>
    </sql>
@@ -422,6 +457,9 @@
            <if test="record.staffId != null and record.staffId !='' ">
                and a.STAFF_ID = #{record.staffId}
            </if>
            <if test="record.cashierId != null and record.cashierId !='' ">
                and a.cashier_id = #{record.cashierId}
            </if>
            <if test="record.isCross != null and record.isCross !='' ">
                and a.IS_CROSS = #{record.isCross}
            </if>
@@ -430,6 +468,9 @@
            </if>
            <if test="(record.companyId!=null and record.companyId!='') ">
                and a.company_id = #{record.companyId}
            </if>
            <if test="(record.orderType!=null and record.orderType!='') ">
                and a.orderType = #{record.orderType}
            </if>
            <if test="record.activity != null and record.activity !='' ">
                and a.ACTIVITY = #{record.activity}
@@ -467,18 +508,20 @@
    <select id="selectVipOrderInfoTotal" resultType="com.matrix.system.hive.bean.SysOrder">
        select
            sum(ZK_TOTAL) zkTotal,
            sum(amount) zkTotal,
            count(1) times,
            MAX(pay_time) payTime,
            GROUP_CONCAT(DISTINCT t2.shop_short_name) shopName
        from sys_order t1
        left join sys_order_flow b on t1.id=b.ORDER_ID and pay_method!='储值卡' and pay_method!='欠款'
        left join sys_shop_info t2 on t1.SHOP_ID=t2.ID
        where VIP_ID=#{vipId} and STATU='已付款';
        where t1.VIP_ID=#{vipId} and STATU='已付款';
    </select>
    <select id="selectApiOrderListInPage" resultType="com.matrix.system.app.vo.OrderDetailVo">
        select
           a.id orderId,
           a.VIP_ID vipId,
           a.ORDER_NO orderNo,
           a.ORDER_TIME orderTime,
           a.STATU orderStatus,
@@ -500,6 +543,9 @@
            </if>
            <if test="record.shopId != null">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.companyId != null">
                and a.company_id=#{record.companyId}
            </if>
        </where>
        <if test="pageVo !=null"><!-- 判断pageVo对象是否为空 -->
@@ -527,6 +573,144 @@
            <if test="record.shopId != null">
                and a.shop_id=#{record.shopId}
            </if>
            <if test="record.companyId != null">
                and a.company_id=#{record.companyId}
            </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>
    <select id="selectErpOrderList" resultType="com.matrix.system.shopXcx.api.vo.ErpOrderDetailVo">
            select
            a.id orderId,
            a.ORDER_NO orderNo,
            a.ORDER_TIME orderTime,
            a.STATU orderStatus,
            a.ZK_TOTAL needPay,
            a.TOTAL - a.ZK_TOTAL discount,
            (a.card_Pay + a.cash_Pay) realPay,
            a.arrears arrears,
            b.su_name staffName,
            d.shop_name as shopName
            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
            left join sys_shop_info d on d.id=a.shop_id
            <where>
                <if test="queryKey != null and queryKey != ''">
                    and instr(a.order_no, #{queryKey})
                </if>
                <if test="status != null and status != ''">
                    and a.statu = #{status}
                </if>
                <if test="vipId != null">
                    and a.vip_id=#{vipId}
                </if>
            </where>
            order by a.order_time desc
            limit #{offset},#{limit}
    </select>
    <select id="findUserOrderById" resultType="com.matrix.system.shopXcx.api.vo.ErpOrderDetailVo">
         select
            a.id orderId,
            a.ORDER_NO orderNo,
            a.ORDER_TIME orderTime,
            a.STATU orderStatus,
            a.ZK_TOTAL needPay,
            a.TOTAL - a.ZK_TOTAL discount,
            (a.card_Pay + a.cash_Pay) realPay,
            a.arrears arrears,
            b.su_name staffName,
            d.shop_name as shopName
            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
            left join sys_shop_info d on d.id=a.shop_id
            where a.id=#{orderId}
    </select>
    <select id="selectArrearsByVipId" resultType="java.math.BigDecimal">
        select sum(arrears) from sys_order
        where vip_id=#{vipId} and statu='欠款'
    </select>
</mapper>