123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432 |
- <?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.chelvc.cloud.vehicle.server.dao.MerchantMapper">
- <sql id="BASIC_MERCHANT_SELECT">
- select mt.id, mt.user_id, mt.name, mt.logo, mt.banners, mt.liaison, mt.mobile, mt.opening, mt.address,mt.business_status,
- mt.score, mt.sale, mt.good_review,mt.region, mt.longitude, mt.latitude, mt.recommend, mt.status, mt.creator,
- mt.create_time,mt.updater, mt.update_time,mt.main_business,mt.ancillary_business
- from `merchant` mt
- </sql>
- <select id="listNearbyMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
- select mt.id, mt.name, mt.logo, mt.score, mt.sale,mt.opening, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
- round(st_distance_sphere(
- point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
- )) distance
- from `merchant` mt left join category c on mt.main_business = c.id
- where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE'
- order by distance asc limit #{size}
- </select>
- <select id="listNearbyMerchantPaging" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
- select mt.id, mt.name, mt.logo, mt.score, mt.sale,mt.opening, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
- round(st_distance_sphere(
- point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
- )) distance
- from `merchant` mt left join category c on mt.main_business = c.id
- where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE'
- order by distance asc
- </select>
- <select id="listRecommendMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
- select mt.id, mt.name, mt.logo, mt.score,mt.opening, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
- round(st_distance_sphere(
- point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
- )) distance
- from `merchant` mt left join category c on mt.main_business = c.id
- where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE' and mt.recommend = 1
- order by distance asc limit #{size}
- </select>
- <select id="listRecommendMerchantPaging" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
- select mt.id, mt.name, mt.logo, mt.score, mt.opening,mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
- round(st_distance_sphere(
- point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
- )) distance
- from `merchant` mt left join category c on mt.main_business = c.id
- where mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE' and mt.recommend = 1
- order by distance asc
- </select>
- <select id="merchantPagingList" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
- select mt.id, mt.name, mt.logo, mt.score,mt.opening, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
- round(st_distance_sphere(
- point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
- )) distance
- from `merchant` mt left join category c on mt.main_business = c.id
- <where>
- mt.region between #{param.code} and #{param.boundary} and mt.status = 'ONLINE'
- <if test="param.keyword != null and !param.keyword.isEmpty()">
- and (mt.name like concat('%', #{param.keyword}, '%')
- or mt.id in (select gds.merchant_id from goods gds where gds.name like concat('%', #{param.keyword}, '%')
- or gds.description like concat('%', #{keyword}, '%')
- )
- or c.name like concat('%', #{keyword}, '%')
- )
- </if>
- <if test="param.categoryId != null">
- and (mt.main_business = #{param.categoryId} or mt.ancillary_business like concat('%',#{param.categoryId} , '%'))
- </if>
- </where>
- <if test="param.sort != null and param.sort.name == 'SYNTHESE'">
- order by mt.recommend desc
- </if>
- <if test="param.sort != null and param.sort.name == 'NEAREST'">
- order by distance desc
- </if>
- <if test="param.sort != null and param.sort.name == 'FAVORITE'">
- order by mt.score desc
- </if>
- <if test="param.sort != null and param.sort.name == 'BESTSELLING'">
- order by mt.sale desc
- </if>
- </select>
- <select id="listSimpleMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantDTO">
- select mt.id, mt.name, mt.logo, mt.score,mt.opening, mt.sale, mt.address,mt.business_status,c.name as mainBusinessName,mt.main_business,
- round(st_distance_sphere(
- point(mt.longitude, mt.latitude), point(#{longitude}, #{latitude})
- )) distance
- from `merchant` mt left join category c on mt.main_business = c.id
- <where>
- <if test="offset != null">
- mt.id > #{offset}
- </if>
- mt.region between #{code} and #{boundary} and mt.status = 'ONLINE'
- <if test="keyword != null and !keyword.isEmpty()">
- and (mt.name like concat('%', #{keyword}, '%')
- or mt.id in (select gds.merchant_id from goods gds where gds.name like concat('%', #{keyword}, '%')
- or gds.description like concat('%', #{keyword}, '%')
- )
- or c.name like concat('%', #{keyword}, '%')
- )
- </if>
- <if test="categoryId != null">
- and (mt.main_business = #{categoryId} or mt.ancillary_business like concat('%',#{categoryId} , '%'))
- </if>
- </where>
- <if test="sort != null and sort.name == 'SYNTHESE'">
- order by mt.recommend desc
- </if>
- <if test="sort != null and sort.name == 'NEAREST'">
- order by distance desc
- </if>
- <if test="sort != null and sort.name == 'FAVORITE'">
- order by mt.score desc
- </if>
- <if test="sort != null and sort.name == 'BESTSELLING'">
- order by mt.sale desc
- </if>
- limit #{size}
- </select>
- <select id="getMerchantById" resultType="com.chelvc.cloud.vehicle.server.entity.Merchant">
- select mt.id, mt.user_id as userId, mt.name, mt.logo, mt.banners, mt.liaison, mt.mobile,
- mt.opening, mt.address, mt.score, mt.sale, mt.good_review as goodReview,mt.region, mt.longitude,
- mt.latitude, mt.recommend, mt.status, mt.creator,mt.business_status,mt.main_business,mt.ancillary_business,
- mt.create_time as createTime,
- round(st_distance_sphere(
- point(mt.longitude, mt.latitude), point(#{param.longitude}, #{param.latitude})
- )) distance
- from `merchant` mt
- where mt.id = #{id}
- </select>
- <select id="merchantFavorite" resultType="java.lang.Integer">
- SELECT
- count(*)
- FROM
- favorite
- WHERE
- type = 'MERCHANT'
- AND content_id = #{merchantId}
- AND user_id = #{userId}
- </select>
- <select id="listRankMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantRankDTO">
- SELECT
- mt.id,
- mt.user_id as userId,
- mt.NAME,
- mt.logo,
- mt.score,
- mt.sale,
- mt.status,
- mt.address,
- SUM( om.pay_amount ) amount,
- count( om.id ) orderNum,
- round(
- st_distance_sphere ( POINT ( mt.longitude, mt.latitude ), POINT ( #{param.longitude}, #{param.latitude}) )) distance
- FROM
- `merchant` mt
- LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
- WHERE
- mt.main_business = #{categoryId}
- and om.STATUS = 4
- <if test="level == 1">
- and mt.province = #{regionId}
- </if>
- <if test="level == 2">
- and mt.city = #{regionId}
- </if>
- <if test="level == 3">
- and mt.district = #{regionId}
- </if>
- AND om.create_time >= #{monthStartLocalTime}
- GROUP BY
- mt.id
- ORDER BY
- amount DESC
- limit 10
- </select>
- <select id="getMerchantIds" resultType="java.lang.Long">
- select m.id from merchant m left join oms_cart_item ca on m.id = ca.merchant_id
- where ca.id is not null and ca.user_id = #{userId} and ca.delete_status = '0'
- </select>
- <update id="updateMerchantBusinessStatus">
- update merchant set business_status = #{businessStatus} ,automatic = #{automatic}
- where id = #{merchantId}
- </update>
- <select id="rankMerchants" resultType="com.chelvc.cloud.vehicle.client.dto.MerchantRankCountDTO">
- SELECT
- mt.id,
- mt.user_id as userId,
- SUM( om.pay_amount ) amount
- FROM
- `merchant` mt
- LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
- WHERE
- mt.main_business = #{categoryId}
- and om.STATUS = 4
- <if test="level == 1">
- and mt.province = #{regionId}
- </if>
- <if test="level == 2">
- and mt.city = #{regionId}
- </if>
- <if test="level == 3">
- and mt.district = #{regionId}
- </if>
- AND (om.create_time between #{monthStartLocalTime} and #{monthEndLocalTime})
- GROUP BY
- mt.id
- ORDER BY
- amount DESC
- limit #{limit}
- </select>
- <select id="queryTotalCommissionAmountByLastMonth" resultType="java.math.BigDecimal">
- SELECT
- SUM( r.reality_amount ) amount
- FROM
- `merchant` mt
- LEFT JOIN oms_order om ON mt.user_id = om.merchant_id
- LEFT JOIN currency_record r ON r.order_id = om.id
- WHERE
- mt.main_business = #{categoryId}
- and om.STATUS = 4
- and r.source_type = 3
- <if test="level == 1">
- and mt.province = #{regionId}
- </if>
- <if test="level == 2">
- and mt.city = #{regionId}
- </if>
- <if test="level == 3">
- and mt.district = #{regionId}
- </if>
- AND (om.create_time between #{monthStartLocalTime} and #{monthEndLocalTime})
- </select>
- <select id="operatConditions" resultType="java.util.Map">
- SELECT
- ( SELECT count( 0 ) FROM reservation WHERE DATE_FORMAT( create_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>) todayresevation,
- (
- SELECT
- count( 0 )
- FROM
- reservation
- WHERE
- DATE_FORMAT( create_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>) yesterresevation,
- ( SELECT count( 0 ) FROM oms_order WHERE DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>) todayorder,
- (
- SELECT
- count( 0 )
- FROM
- oms_order
- WHERE
- DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>) yesterorder,
- ( SELECT sum( pay_amount ) FROM oms_order WHERE DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE(), '%Y%m%d' )
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>) todayamount,
- (
- SELECT
- sum( pay_amount )
- FROM
- oms_order
- WHERE
- DATE_FORMAT( payment_time, '%Y%m%d' ) = DATE_FORMAT( CURDATE()- 1, '%Y%m%d' )
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>) yesteramount,
- (select
- sum(pay_amount)
- from
- oms_order where 1=1
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>) totalAmount
- FROM
- DUAL
- </select>
- <select id="operatReportByYear" resultType="java.util.Map">
- SELECT
- t.*
- FROM
- (
- SELECT MONTH
- ( payment_time ) MONTH,
- sum( pay_amount ) monthAmount,
- YEAR ( payment_time ) YEAR,
- count( 0 ) orderCount
- FROM
- oms_order
- where 1=1
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>
- GROUP BY
- MONTH ( payment_time ),
- YEAR ( payment_time )) t
- WHERE
- t.YEAR = #{year}
- order by t.`MONTH`
- </select>
- <select id="operatReportByMonth" resultType="java.util.Map">
- SELECT
- t.*
- FROM
- (
- SELECT MONTH
- ( payment_time ) MONTH,
- sum( pay_amount ) monthAmount,
- YEAR ( payment_time ) YEAR,
- DAY ( payment_time ) day,
- count( 0 ) orderCount
- FROM
- oms_order
- where 1=1
- <if test="merchantId != null">
- and merchant_id = #{merchantId}
- </if>
- GROUP BY
- MONTH ( payment_time ),
- DAY ( payment_time ),
- YEAR ( payment_time )) t
- WHERE
- t.YEAR = #{year}
- and t.month = #{month}
- order by t.`day`
- </select>
- <select id="getAddMerchantReportByYear" resultType="java.util.Map">
- SELECT
- t.*
- FROM
- (
- SELECT MONTH
- ( create_time ) MONTH,
- YEAR ( create_time ) YEAR,
- count( 0 ) registerCount
- FROM
- merchant
- where 1=1
- GROUP BY
- MONTH ( create_time ),
- YEAR ( create_time )) t
- WHERE
- t.YEAR = #{year}
- order by t.`MONTH`
- </select>
- <select id="getAddMerchantReportByMonth" resultType="java.util.Map">
- SELECT
- t.*
- FROM
- (
- SELECT MONTH
- ( create_time ) MONTH,
- YEAR ( create_time ) YEAR,
- DAY ( create_time ) day,
- count( 0 ) registerCount
- FROM
- merchant
- where 1=1
- GROUP BY
- MONTH ( create_time ),
- DAY ( create_time ),
- YEAR ( create_time )) t
- WHERE
- t.YEAR = #{year}
- and t.month = #{month}
- order by t.`day`
- </select>
- <select id="getAddMerchantReport" resultType="java.util.Map">
- SELECT
- count( 1) registerCount
- FROM
- merchant
- WHERE
- YEAR ( create_time ) = #{year}
- <if test="month != null">
- AND MONTH ( create_time ) = #{month}
- </if>
- <if test="day != null">
- AND DAY ( create_time ) = #{day}
- </if>
- GROUP BY
- YEAR ( create_time )
- <if test="month != null">
- ,MONTH ( create_time )
- </if>
- <if test="day != null">
- ,DAY ( create_time )
- </if>
- </select>
- </mapper>
|