mitao
2024-06-06 3d2b51ea4520533de5e78f88dddf5b5c7dce4247
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
<?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.sinata.rest.modular.member.dao.MemMerchantMapper">
 
    <!-- 通用查询映射结果 -->
    <resultMap id="BaseResultMap" type="com.sinata.rest.modular.member.model.MemMerchant">
        <id column="id" property="id" />
        <result column="create_time" property="createTime" />
        <result column="merchant_name" property="merchantName" />
        <result column="linkman" property="linkman" />
        <result column="link_phone" property="linkPhone" />
        <result column="user_id" property="userId" />
        <result column="business_license" property="businessLicense" />
        <result column="other_details" property="otherDetails" />
        <result column="apply_des" property="applyDes" />
        <result column="state" property="state" />
        <result column="audit_state" property="auditState" />
        <result column="audit_time" property="auditTime" />
        <result column="audit_mark" property="auditMark" />
        <result column="is_delete" property="isDelete" />
        <result column="logo" property="logo" />
    </resultMap>
 
    <select id="merchantInfoByGoodsId" parameterType="java.lang.Integer" resultType="com.sinata.rest.modular.member.controller.common.vo.VoGoodsMerchantInfo">
        SELECT m.*
        FROM mem_merchant m
        WHERE m.id = #{id}
    </select>
 
    <select id="getMerchantUserScore" parameterType="java.lang.Integer" resultType="java.lang.Double">
        SELECT IFNULL(SUM(ue.score)/count(ue.id), 0) userScore
        FROM mall_goods g
              RIGHT JOIN mall_user_evaluation ue ON g.id = ue.goods_id
        WHERE g.merchant_id = #{id} AND g.is_delete = 0 AND ue.is_delete = 0
    </select>
 
    <select id="selectInfo" resultType="com.sinata.rest.modular.member.controller.common.vo.VoGoodsMerchantInfo">
        SELECT * FROM mem_merchant WHERE user_id = #{userId}
    </select>
 
    <select id="getMerchantParentUser" resultType="com.sinata.rest.modular.member.model.MemUserRelation">
        SELECT o.id, o.parent_id FROM mem_user_relation o
        LEFT JOIN mem_merchant m ON o.id = m.user_id
        WHERE m.id = #{merchantId}
    </select>
 
    <select id="queryMerchantList" resultType="com.sinata.rest.modular.member.model.MemMerchant">
        SELECT
            mt.id,
            mt.merchant_name,mt.address,
            mt.`work_end_time`  ,
            mt.`work_start_time`  ,
            mt.`work_end_date` ,
            mt.`work_start_date`  ,
            mt.link_phone
        FROM
            mem_merchant mt
                LEFT JOIN sys_area_city ac on ac.id = mt.city_id
        where mt.is_delete = 0
        <if test="level != null and level == 1 ">
            and ac.province_code = #{cityCode}
        </if>
        <if test="level != null and level == 2 ">
            and ac.city_code = #{cityCode}
        </if>
        <if test="level != null and level == 3 ">
            and ac.county_code = #{cityCode}
        </if>
        order by mt.id desc
 
    </select>
 
    <select id="getMerchantCount" resultType="com.sinata.rest.modular.member.model.MemMerchant">
        SELECT
        ac.county_code,
        ac.county_name,
        count(1) merchantCount
        FROM
        mem_merchant mt
        LEFT JOIN sys_area_city ac on ac.id = mt.city_id
        where mt.is_delete = 0
        <if test="level != null and level == 1 ">
            and ac.province_code = #{cityCode}
        </if>
        <if test="level != null and level == 2 ">
            and ac.city_code = #{cityCode}
        </if>
        <if test="level != null and level == 3 ">
            and ac.county_code = #{cityCode}
        </if>
        group by ac.county_code
        order by mt.id desc
 
    </select>
 
    <select id="getMerchantMallGoods" resultType="com.sinata.rest.modular.mall.model.MallGoodsSku">
        SELECT
            md.goods_name,
            md.buy_count,
            md.goods_image,
            mk.*
        FROM
            `mall_goods_sku` mk
        LEFT JOIN mall_goods md ON md.id = mk.goods_id
        WHERE
            mk.merchant_id = #{merchantId}
            AND mk.state = 1
        GROUP BY
            mk.goods_id
        ORDER BY
            md.buy_count DESC
    </select>
 
    <select id="getMerchantListByGoodsId" resultType="com.sinata.rest.modular.member.model.MemMerchant">
        SELECT * FROM mem_merchant o
        WHERE id IN (
            SELECT merchant_id FROM mall_goods_sku
            WHERE state = 1
            and is_delete = 0
            <if test="goodsId != null">
                AND goods_id = #{goodsId}
            </if>
            <if test="cityCode != null and cityCode != ''">
                AND county_code = #{cityCode}
            </if>
        )
    </select>
 
    <select id="getMerchantOrderList" resultType="com.sinata.rest.modular.mall.controller.vo.VoMallOrder">
        SELECT
            mo.*,
            md.goods_image goodsImage, md.use_time,
            ms.goods_name
        FROM
            mall_order mo
            Left JOIN `mall_order_detail` md ON md.order_no = mo.order_no
            Left JOIN mall_goods ms ON ms.id = md.goods_id
        WHERE mo.is_delete = 0 and mo.state in (1,2,3)
        <if test="merchantId != null">
            and (mo.merchant_id =  #{merchantId})
        </if>
        <if test="condition != null and condition != ''">
            and (mo.order_no =#{condition} or  mo.phone =#{condition} or ms.goods_name like CONCAT('%', #{condition},'%')  )
        </if>
        <if test="isUse !=null and isUse">
            and mo.state = 3
            group by mo.order_no
            order by md.use_time desc
        </if>
        <if test="isUse !=null and !isUse">
            and mo.state &lt;> 3
            group by mo.order_no
            order by mo.order_no desc
        </if>
    </select>
 
    <select id="getMemMerchant" resultType="com.sinata.rest.modular.member.model.MemMerchant">
        select  *,(select GROUP_CONCAT(name) from my_store_service where FIND_IN_SET(id,service_ids)) serviceName from mem_merchant where id =#{merchantId}
    </select>
 
    <select id="getMerchantService" resultType="java.lang.String">
        SELECT `name` FROM `my_store_service` where  is_delete = 0
        and id in
        <foreach collection="list" item="id" open="("  close=")" separator=",">
            #{id}
        </foreach>
    </select>
 
</mapper>