jyy
2021-01-25 4d4805096b898a6e99f31794facb81794bd1fcf7
zq-erp/src/main/resources/mybatis/mapper/hive/AchieveNewDao.xml
@@ -48,7 +48,11 @@
      <result property="meiliao" column="meiliao" />
      <result property="zkTotal" column="zk_total" />
      <result property="arriveCnt" column="arrive_cnt" />
      <result property="goodsNo" column="goodsNo" />
      <result property="goodsName" column="goodsName" />
      <result property="zkPrice" column="zkPrice" />
   </resultMap>
@@ -113,8 +117,20 @@
            <if test="(record.endTime!=null  )">
               and a.datatime <![CDATA[ < ]]> #{record.endTime}
            </if>
            <if test="record.beaultId != null and record.beaultId !='' ">
               and   a.beault_id = #{record.beaultId}
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
               and   a.company_id = #{record.companyId}
            </if>
            <if test="record.beaultId != null and record.beaultId !='' ">
               and   a.beault_id = #{record.beaultId}
            </if>
            <if test="record.vipQueryKey != null and record.vipQueryKey != ''  ">
               and c.VIP_NAME like concat('%',#{record.vipQueryKey},'%')
               or (c.VIP_NO like concat('%',#{record.vipQueryKey},'%')
               or c.PHONE like concat('%',#{record.vipQueryKey},'%')
               )
            </if>
         </if>
      </where>
@@ -168,6 +184,15 @@
            </if>
            <if test="record.companyId != null and record.companyId !='' ">
               and   a.company_id = #{record.companyId}
            </if>
            <if test="record.beaultId != null and record.beaultId !='' ">
               and   a.beault_id = #{record.beaultId}
            </if>
            <if test="record.vipQueryKey != null and record.vipQueryKey != ''  ">
               and c.VIP_NAME like concat('%',#{record.vipQueryKey},'%')
               or (c.VIP_NO like concat('%',#{record.vipQueryKey},'%')
               or c.PHONE like concat('%',#{record.vipQueryKey},'%')
               )
            </if>
         </if>
      </where>
@@ -819,4 +844,245 @@
      where 1=1
      <include refid="where_sql"></include>
   </select>
   <select id="selectVipConsumeStatisticsList" resultMap="AchieveNewMap">
      select
         a.VIP_NAME,
         a.PHONE t9,
         GROUP_CONCAT(DISTINCT e.su_name) meiliao,
         d.cnt arrive_cnt,
         sum(b.buyConsume) goods_cash,
         sum(b.freeConsume) free_consume,
         sum(b.hisConsume) his_consume
      from sys_vip_info a
      inner join (
         select vip_id,datatime, sum(a.free_consume) freeConsume, sum(a.his_consume) hisConsume, sum(IFNULL(goods_cash, 0) + IFNULL(card_cash, 0)) buyConsume from achieve_new a group by vip_id
      ) b on a.ID = b.vip_id
      inner join (
         select vip_id, count(1) cnt from (
                               select vip_id, date_format(datatime, '%Y-%m-%d')
                               from achieve_new
                               group by date_format(datatime, '%Y-%m-%d'), vip_id
                            ) c group by vip_id
         ) d on a.ID=d.vip_id
      left join sys_users e on find_in_set(e.su_id, a.BEATUY_ID)
      where 1=1
      <if test="record.vipName != null and record.vipName !=''">
         and (a.vip_name like CONCAT(CONCAT('%', #{record.vipName}), '%') or a.vip_no=#{record.vipName} or a.phone = #{record.vipName})
      </if>
      <if test="record.shopId != null">
         and a.shop_id=#{record.shopId}
      </if>
      <if test="record.beginTime != null">
         and date_format(b.datatime, '%Y-%m-%d') >= date_format(#{record.beginTime}, '%Y-%m-%d')
      </if>
      <if test="record.endTime!=null">
         and date_format(b.datatime, '%Y-%m-%d') >= date_format(#{record.endTime}, '%Y-%m-%d')
      </if>
      <if test="record.beaultId != null and record.beaultId!=''">
         and FIND_IN_SET(#{record.beaultId}, a.BEATUY_ID)
      </if>
      <if test='record.t1 == "on"'>
         and a.BEATUY_ID is not null
      </if>
      group by a.PHONE
      <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="selectVipConsumeStatisticsTotal" resultType="java.lang.Integer">
      select count(1)
      from sys_vip_info a
      inner join (
      select vip_id,datatime, sum(a.free_consume) freeConsume, sum(a.his_consume) hisConsume, sum(IFNULL(goods_cash, 0) + IFNULL(card_cash, 0)) buyConsume from achieve_new a group by vip_id
      ) b on a.ID = b.vip_id
      inner join (
      select vip_id, count(1) cnt from (
      select vip_id, date_format(datatime, '%Y-%m-%d')
      from achieve_new
      group by date_format(datatime, '%Y-%m-%d'), vip_id
      ) c group by vip_id
      ) d on a.ID=d.vip_id
      left join sys_users e on find_in_set(e.su_id, a.BEATUY_ID)
      where 1=1
      <if test="record.vipName != null and record.vipName !=''">
         and (a.vip_name like CONCAT(CONCAT('%', #{record.vipName}), '%') or a.vip_no=#{record.vipName} or a.phone = #{record.vipName})
      </if>
      <if test="record.shopId != null">
         and a.shop_id=#{record.shopId}
      </if>
      <if test="record.beginTime != null">
         and date_format(b.datatime, '%Y-%m-%d') >= date_format(#{record.beginTime}, '%Y-%m-%d')
      </if>
      <if test="record.endTime!=null">
         and date_format(b.datatime, '%Y-%m-%d') >= date_format(#{record.endTime}, '%Y-%m-%d')
      </if>
      <if test="record.beaultId != null and record.beaultId!=''">
         and FIND_IN_SET(#{record.beaultId}, a.BEATUY_ID)
      </if>
      <if test='record.t1 == "on"'>
         and a.BEATUY_ID is not null
      </if>
   </select>
   <select id="selectUserAchieveByTime" resultType="com.matrix.system.app.vo.UserAchieveVo">
      select
         sale_id id,
         sum(case t3 when '现金业绩' then card_cash else 0 end) orderCash,
         sum(case t3 when '划扣业绩' then consume else 0 end) cash,
         sum(case order_type when '订单' then proj_percentage else 0 end) cardUse,
         sum(IFNULL(his_consume, 0)) hisConsume,
         sum(IFNULL(free_consume, 0)) freeConsume,
         sum(case order_type when '服务单' then proj_percentage else 0 end) projCommission
      from achieve_new a
      where a.beault_id=#{userId}
      and (date_format(datatime, '%Y-%m-%d') >= date_format(#{startTime}, '%Y-%m-%d') and date_format(#{endTime}, '%Y-%m-%d') >= date_format(datatime, '%Y-%m-%d'))
   </select>
   <select id="selectApiOrderItemAchieve" resultType="com.matrix.system.app.vo.OrderDetailAchieveItemVo">
      select
         b.su_name name,
         IFNULL(a.card_cash, 0) + IFNULL(a.proj_cash, 0) + IFNULL(a.goods_cash, 0) achieve
      from achieve_new a
      inner join sys_users b on (a.beault_id=b.su_id or a.sale_id = b.su_id)
      where a.order_item_id=#{itemId} and order_type = '订单'
   </select>
   <select id="selectShopConsumeAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
      select
         b.shop_short_name name,
         b.SHOP_IMAG photo,
         sum(IFNULL(a.free_consume,0) + IFNULL(a.his_consume,0)) amount
      from achieve_new a
      left join sys_shop_info b on a.shop_id=b.ID
      <where>
         <if test="record.companyId != null">
            and a.company_id=#{record.companyId}
         </if>
         <if test='record.t1 == "1" and record.datatime != null'>
            and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
         </if>
         <if test='record.t1 == "2" and record.datatime != null'>
            and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
         </if>
         <if test='record.t1 == "3" and record.datatime != null'>
            and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
         </if>
      </where>
      group by a.shop_id
      order by amount desc, a.shop_id
   </select>
   <select id="selectBeauticianConsumeAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
      select
         b.su_name name,
         b.su_id id,
         sum(IFNULL(a.free_consume,0) + IFNULL(a.his_consume, 0) + IFNULL(a.consume, 0)) amount,
         c.shop_short_name shopName
      from achieve_new a
      inner join sys_users b on a.beault_id=b.su_id
      left join sys_shop_info c on a.shop_id=c.ID
      <where>
         a.order_type='服务单'
         <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.t1 == "1" and record.datatime != null'>
            and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
         </if>
         <if test='record.t1 == "2" and record.datatime != null'>
            and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
         </if>
         <if test='record.t1 == "3" and record.datatime != null'>
            and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
         </if>
      </where>
      group by a.beault_id
      order by amount desc
   </select>
   <select id="selectOrderItemAchieveByOrderId" resultMap="AchieveNewMap">
      select
         a.*,
         b.code goodsNo,
         b.name goodsName,
         c.su_name meiliao,
         d.count*d.zk_price zk_total
      from achieve_new a
      left join shopping_goods b on a.shopping_goods_id=b.id
      left join sys_users c on a.beault_id=c.su_id
      left join sys_order_item d on a.order_item_id=d.id
      where a.order_id=#{orderId}
   </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(ifnull(card_cash,0)) amount,
      c.shop_short_name shopName
      from achieve_new a
      inner join sys_users b on a.beault_id=b.su_id
      inner join sys_shop_info c on a.SHOP_ID=c.ID
      <where>
         <if test="record.companyId != null">
            and b.company_id=#{record.companyId}
         </if>
         <if test="record.shopId != null">
            and b.shop_id=#{record.shopId}
         </if>
         <if test='record.type == "1" and record.datatime != null'>
            and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
         </if>
         <if test='record.type == "2" and record.datatime != null'>
            and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
         </if>
         <if test='record.type == "3" and record.datatime != null'>
            and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
         </if>
      </where>
      group by b.su_id
      order by amount desc, b.su_id
   </select>
   <select id="selectShopSaleAchieveRanking" resultType="com.matrix.system.app.vo.RankingVo">
      select
         b.shop_short_name name,
         b.SHOP_IMAG photo,
         sum(IFNULL(a.consume,0) + IFNULL(a.card_cash,0)) amount
      from achieve_new a
      left join sys_shop_info b on a.shop_id=b.ID
      <where>
         <if test="record.companyId != null">
            and a.company_id=#{record.companyId}
         </if>
         <if test='record.t1 == "1" and record.datatime != null'>
            and date_format(datatime, '%Y-%m-%d') = date_format(#{record.datatime}, '%Y-%m-%d')
         </if>
         <if test='record.t1 == "2" and record.datatime != null'>
            and date_format(datatime, '%Y-%m') = date_format(#{record.datatime}, '%Y-%m')
         </if>
         <if test='record.t1 == "3" and record.datatime != null'>
            and date_format(datatime, '%Y') = date_format(#{record.datatime}, '%Y')
         </if>
      </where>
      group by a.shop_id
      order by amount desc, a.shop_id
   </select>
</mapper>