<?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="cn.superdesk.uniorder.dao.mapper.marketing.UnifiedStatisticsVirtMapperCommon">



    <sql id="queryVirtGoodsStatisticalTest">
        SELECT
            uo.purchase_virt_id as virt_id,
            uo.service_no,

            count(uog.id) as quantity,

            sum(uog.price * uog.quantity) as goods_amount,
            sum(uog.cost_price * uog.quantity) as goods_cost_amount,
            -- sum(transport_amount) as goods_transport_amount,

            YEAR(uo.create_time) as s_year,
            MONTH(uo.create_time) as s_month,
            DAYOFMONTH(uo.create_time) as s_day

        FROM
            unified_order uo
            LEFT JOIN unified_order_goods uog ON uo.order_sn = uog.order_sn
        <where>
            and uo.complet_state != 3
            <if test="year != null and year != ''">
                and YEAR(uo.create_time) = #{year}
            </if>
            <if test="month != null and month != ''">
                and MONTH(uo.create_time) = #{month}
            </if>
            <if test="dayOfMonth != null and dayOfMonth != ''">
                and DAYOFMONTH(create_time)=#{dayOfMonth}
            </if>
            and uo.purchase_virt_id is not null
        </where>
        GROUP BY uo.purchase_virt_id,uo.service_no
    </sql>

    <sql id="queryVirtGoodsStatisticalOneSqlOk">
        SELECT

            uo.service_no,
            uo.purchase_virt_id as virt_id,
            uo.project_id as org_id,


            count(uo.id) as quantity,

            IFNULL(sum(uo.amount),0) order_amount,
            IFNULL(sum(uo.cost_amount),0) order_cost_amount,

            IFNULL(sum(uo.transport_amount),0) order_transport_amount,

            IFNULL(sum(uor.order_refund_amount),0) order_refund_amount,
            IFNULL(sum(uor.order_refund_cost_amount),0) order_refund_cost_amount,

            ifnull(sum(uog1.goods_amount),0) as goods_amount,
            ifnull(sum(uog1.goods_cost_amount),0) as goods_cost_amount,

            ifnull(sum(uog2.goods_amount),0) as goods_refund_amount,
            ifnull(sum(uog2.goods_cost_amount),0) as goods_refund_cost_amount,
            ifnull(sum(uog0.goods_amount),0) as goods_transport_amount,

            YEAR(uo.create_time) as s_year,
            MONTH(uo.create_time) as s_month,
            DAYOFMONTH(uo.create_time) as s_day
        from
            unified_order uo
            LEFT JOIN (
                SELECT
                    sum(price * quantity) as goods_amount,
                    sum(cost_price * quantity) as goods_cost_amount,
                    order_sn
                FROM
                    unified_order_goods
                <where>
                    AND direction = 1
                    AND goods_id != 0
                </where>
                GROUP by order_sn
            ) uog1 on uo.order_sn = uog1.order_sn

            LEFT JOIN (
                SELECT
                    sum(price * quantity) as goods_amount,
                    sum(cost_price * quantity) as goods_cost_amount,
                    order_sn
                FROM
                    unified_order_goods
                <where>
                    AND direction = -1
                </where>
                GROUP by order_sn
            ) uog2 on uo.order_sn = uog2.order_sn
            LEFT JOIN (
                SELECT
                    sum(price * quantity) as goods_amount,
                    sum(cost_price * quantity) as goods_cost_amount,
                    order_sn
                FROM
                    unified_order_goods
                <where>
                    AND direction = 1
                    AND goods_id = 0
                </where>
                GROUP by order_sn
            ) uog0 on uo.order_sn = uog0.order_sn
            LEFT JOIN (
                SELECT
                    sum(amount) as order_refund_amount,
                    0 as order_refund_cost_amount,
                    order_sn
                from
                    unified_order_return
                GROUP BY order_sn
            ) uor on uo.order_sn = uor.order_sn
        <where>
            and uo.complet_state != 3
            <if test="year != null and year != ''">
                and YEAR(uo.create_time) = #{year}
            </if>
            <if test="month != null and month != ''">
                and MONTH(uo.create_time) = #{month}
            </if>
            <if test="dayOfMonth != null and dayOfMonth != ''">
                and DAYOFMONTH(create_time)=#{dayOfMonth}
            </if>
            and uo.purchase_virt_id is not null
        </where>
        GROUP BY uo.service_no, uo.purchase_virt_id, uo.project_id
    </sql>

    <!-- mark by linjinyu at 20201125 重构 -->
    <!-- mark by linjinyu at 20210906 重构 -->
    <!-- 订单维度 -->
    <sql id="queryVirtOrderStatistical">

        SELECT
            ta.*,
            IFNULL(tb.payable_amount,0) payable_amount
        from
        (
            SELECT
                purchase_virt_id as virt_id,
                service_no,

                count(id) as quantity,

                sum(amount) as order_amount,
                sum(cost_amount) as order_cost_amount,
                sum(transport_amount) as order_transport_amount,

                YEAR(create_time) as s_year,
                MONTH(create_time) as s_month,
                DAYOFMONTH(create_time) as s_day
            from
                unified_order
            <where>
                and complet_state != 3
                <if test="year != null and year != ''">
                    and YEAR(create_time)=#{year}
                </if>
                <if test="month != null and month != ''">
                    and MONTH(create_time)=#{month}
                </if>
                <if test="dayOfMonth != null and dayOfMonth != ''">
                    and DAYOFMONTH(create_time)=#{dayOfMonth}
                </if>
                and purchase_virt_id is not null
            </where>
            GROUP BY purchase_virt_id,service_no
        ) ta LEFT JOIN
        (
            SELECT
                purchase_virt_id as virt_id,
                service_no,
                sum(amount) as payable_amount
            from
                unified_order
            <where>
                and complet_state != 3
                <if test="year != null and year != ''">
                    and YEAR(create_time)=#{year}
                </if>
                <if test="month != null and month != ''">
                    and MONTH(create_time)=#{month}
                </if>
                <if test="dayOfMonth != null and dayOfMonth != ''">
                    and DAYOFMONTH(create_time)=#{dayOfMonth}
                </if>
                and purchase_virt_id is not null
                and pay_state = 2
            </where>
            GROUP BY purchase_virt_id,service_no
        ) tb on ta.virt_id = tb.virt_id and ta.service_no = tb.service_no
    </sql>

    <select id="getVirtOrderReturnStatistical" resultMap="cn.superdesk.uniorder.dao.mapper.marketing.UnifiedStatisticsVirtMapper.BaseResultMap">
        SELECT
            a.amount as order_refund_amount,
            b.purchase_virt_id as virt_id,
            b.service_no
        from
            unified_order_return a
            INNER JOIN unified_order b on a.order_sn=b.order_sn
        <where>
            <if test="year != null and year != ''">
                and YEAR(a.create_time) = #{year}
            </if>
            <if test="month != null and month != ''">
                and MONTH(a.create_time) = #{month}
            </if>
            <if test="dayOfMonth != null and dayOfMonth != ''">
                and DAYOFMONTH(create_time) = #{dayOfMonth}
            </if>
            and b.complet_state != 3
            and a.complet_state != 3
        </where>
        GROUP BY b.purchase_virt_id,b.service_no

    </select>

    <select id="selectByModel" resultMap="cn.superdesk.uniorder.dao.mapper.marketing.UnifiedStatisticsVirtMapper.BaseResultMap">
        select
        <include refid="cn.superdesk.uniorder.dao.mapper.marketing.UnifiedStatisticsVirtMapper.Base_Column_List"/>
        from
            unified_statistics_virt
        <where>
            <if test="sYear != null and sYear != ''">
                and s_year= #{sYear}
            </if>
            <if test="sMonth != null and sMonth != ''">
                and s_month = #{sMonth}
            </if>
            <if test="virtId != null and virtId != ''">
                and virt_id=#{virtId}
            </if>
            <if test="serviceNo != null and serviceNo != ''">
                and service_no=#{serviceNo}
            </if>
        </where>
    </select>

    <select id="findAll" resultMap="cn.superdesk.uniorder.dao.mapper.marketing.UnifiedStatisticsVirtMapper.BaseResultMap">
        select
        <include refid="cn.superdesk.uniorder.dao.mapper.marketing.UnifiedStatisticsVirtMapper.Base_Column_List"/>
        from
            unified_statistics_virt
        <where>
        <if test="sYear != null and sYear != ''">
            and s_year= #{sYear}
        </if>
        <if test="sMonth != null and sMonth != ''">
            and s_month = #{sMonth}
        </if>
        <if test="virtId != null and virtId != ''">
            and virt_id=#{virtId}
        </if>
        </where>
    </select>

    <!-- mark by linjinyu at 20201125 重构 -->
    <resultMap id="SumResultMap" type="cn.superdesk.uniorder.dto.vo.unified.UnifiedStatisticsVirtSum">

        <result column="quantity" property="quantity" jdbcType="INTEGER"/>

        <result column="order_amount" jdbcType="DECIMAL" property="orderAmount" />
        <result column="order_cost_amount" jdbcType="DECIMAL" property="orderCostAmount" />
        <result column="order_refund_amount" jdbcType="DECIMAL" property="orderRefundAmount" />
        <result column="order_refund_cost_amount" jdbcType="DECIMAL" property="orderRefundCostAmount" />
        <result column="order_transport_amount" jdbcType="DECIMAL" property="orderTransportAmount" />

        <result column="goods_amount" jdbcType="DECIMAL" property="goodsAmount" />
        <result column="goods_cost_amount" jdbcType="DECIMAL" property="goodsCostAmount" />
        <result column="goods_refund_amount" jdbcType="DECIMAL" property="goodsRefundAmount" />
        <result column="goods_refund_cost_amount" jdbcType="DECIMAL" property="goodsRefundCostAmount" />
        <result column="goods_transport_amount" jdbcType="DECIMAL" property="goodsTransportAmount" />

        <result column="payable_amount" property="payableAmount" jdbcType="DECIMAL"/>


    </resultMap>

    <!-- mark by linjinyu at 20201125 重构 -->
    <select id="getStatisticsSum" resultMap="SumResultMap">
        SELECT
            IFNULL(sum(quantity),0) quantity,

            IFNULL(sum(order_amount),0) order_amount,
            IFNULL(sum(order_cost_amount),0) order_cost_amount,
            IFNULL(sum(order_refund_amount),0) order_refund_amount,
            IFNULL(sum(order_refund_cost_amount),0) order_refund_cost_amount,
            IFNULL(sum(order_transport_amount),0) order_transport_amount,

            IFNULL(sum(goods_amount),0) goods_amount,
            IFNULL(sum(goods_cost_amount),0) goods_cost_amount,
            IFNULL(sum(goods_refund_amount),0) goods_refund_amount,
            IFNULL(sum(goods_refund_cost_amount),0) goods_refund_cost_amount,
            IFNULL(sum(goods_transport_amount),0) goods_transport_amount,

            IFNULL(sum(payable_amount),0) payable_amount
        FROM
            unified_statistics_virt
        <where>
        <if test="syear != null and syear != ''">
            and s_year= #{syear}
        </if>
        <if test="smonth != null and smonth != ''">
            and s_month = #{smonth}
        </if>
        <if test="areaId != null and areaId != ''">
            and virt_id in (
                SELECT virt_id from unified_area_city_virt where area_city_id in (
                    SELECT id from unified_area_city where FIND_IN_SET(#{areaId},area_full_ids)
                )
            )
        </if>
        </where>
    </select>

    <select id="getReturnAmount" resultType="java.math.BigDecimal">
        SELECT
        	sum(a.amount) order_refund_amount
        from
        	unified_order_return a
        	INNER JOIN unified_order b on a.order_sn=b.order_sn
        <where>
        <if test="year != null and year != ''">
            and YEAR(b.create_time)= #{year}
        </if>
        <if test="month != null and month != ''">
            and MONTH(b.create_time) = #{month}
        </if>
        <if test="virtid != null and virtid != ''">
            and b.purchase_virt_id=#{virtid}
        </if>
        <if test="serviceNo != null and serviceNo != ''">
            and b.service_no=#{serviceNo}
        </if>
        <if test="lastmonth != null and lastmonth== 1">
            and b.create_time > DATE_SUB(CURDATE(),INTERVAL 30 day)
        </if>
        <if test="isdaide != null and isdaide == 1">
            and b.purchase_virt_id in (SELECT id from temp_daide)
        </if>
            and b.complet_state != 3
            and a.complet_state != 3
        </where>
    </select>


    <!-- mark by linjinyu at 20201125 重构 -->
    <resultMap id="VoResultMap" type="cn.superdesk.uniorder.dto.vo.unified.UnifiedStatisticsVirtVo">
        <id column="id" property="id" jdbcType="BIGINT"/>

        <result column="virt_id" property="virtId" jdbcType="BIGINT"/>
        <result column="virt_name" property="virtName" jdbcType="VARCHAR"/>

        <result column="s_year" property="sYear" jdbcType="INTEGER"/>
        <result column="s_month" property="sMonth" jdbcType="INTEGER"/>

        <result column="quantity" property="quantity" jdbcType="INTEGER"/>

        <result column="order_amount" jdbcType="DECIMAL" property="orderAmount" />
        <result column="order_cost_amount" jdbcType="DECIMAL" property="orderCostAmount" />
        <result column="order_refund_amount" jdbcType="DECIMAL" property="orderRefundAmount" />
        <result column="order_refund_cost_amount" jdbcType="DECIMAL" property="orderRefundCostAmount" />
        <result column="order_transport_amount" jdbcType="DECIMAL" property="orderTransportAmount" />

        <result column="goods_amount" jdbcType="DECIMAL" property="goodsAmount" />
        <result column="goods_cost_amount" jdbcType="DECIMAL" property="goodsCostAmount" />
        <result column="goods_refund_amount" jdbcType="DECIMAL" property="goodsRefundAmount" />
        <result column="goods_refund_cost_amount" jdbcType="DECIMAL" property="goodsRefundCostAmount" />
        <result column="goods_transport_amount" jdbcType="DECIMAL" property="goodsTransportAmount" />

        <result column="payable_amount" property="payableAmount" jdbcType="DECIMAL"/>

        <result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
    </resultMap>

    <!-- mark by linjinyu at 20201125 重构 -->
    <select id="findAllVo" resultMap="VoResultMap">
        SELECT
            a.id,
            a.virt_id,
            a.quantity,

            a.order_amount,
            a.order_cost_amount,
            a.order_refund_amount,
            a.order_refund_cost_amount,
            a.order_transport_amount,

            a.goods_amount,
            a.goods_cost_amount,
            a.goods_refund_amount,
            a.goods_refund_cost_amount,
            a.goods_transport_amount,

            a.payable_amount,

            a.s_year,
            a.s_month,
            a.create_time,

            b.enterprise_name virt_name
        FROM
            unified_statistics_virt AS a
            LEFT JOIN sys_enterprise AS b ON a.virt_id = b.enterprise_id
        <where>

        <if test="sYear != null and sYear != ''">
            and a.s_year= #{sYear}
        </if>
        <if test="sMonth != null and sMonth != ''">
            and a.s_month = #{sMonth}
        </if>
        <if test="virtId != null and virtId != ''">
            and a.virt_id=#{virtId}
        </if>
        <if test="virtIds != null and virtIds != ''">
            and a.virt_id in
            <foreach collection="virtIds" index="index" item="id" open="(" close=")" separator=",">
                #{id}
            </foreach>
        </if>
            and a.virt_id in ( SELECT id from temp_daide)
        </where>

    </select>

    <resultMap id="LastMonthResultMap" type="cn.superdesk.uniorder.dto.vo.unified.UnifiedOrderLastMonth">
        <result column="order_total" property="orderTotal" jdbcType="INTEGER"/>
        <result column="payable_amount" property="payableAmount" jdbcType="DECIMAL"/>
    </resultMap>

    <!-- 戴 -->
    <select id="getlastmonth" resultMap="LastMonthResultMap">
        SELECT
            COUNT(id) as order_total,
            SUM(amount) as payable_amount
        from
            unified_order
        <where>
            and create_time > DATE_SUB(CURDATE(),INTERVAL 30 day)
            and complet_state != 3
            and service_no in ('QYNGZZ','QYNGDK')
            and purchase_virt_id in (SELECT id from temp_daide)
        </where>
    </select>

    <select id="getundzamount" resultType="java.math.BigDecimal">
        SELECT
            sum(amount)
        from
            unified_order
        <where>
            and accounting_state_customer=2
            and complet_state != 3
            and service_no in ('QYNGZZ','QYNGDK')
            <if test="isdaide != null and isdaide == 1">
                and purchase_virt_id in (SELECT id from temp_daide)
            </if>
        </where>
    </select>

    <select id="getuninvamount" resultType="java.math.BigDecimal">
        SELECT
            sum(amount)
        from
            unified_order
        <where>
            and accounting_state_customer = 1
            and inv_state = 2
            and complet_state != 3
            and service_no in ('QYNGZZ','QYNGDK')
            <if test="isdaide != null and isdaide == 1">
                and purchase_virt_id in (SELECT id from temp_daide)
            </if>
        </where>
    </select>

    <select id="getunpaymoney" resultType="java.math.BigDecimal">
        SELECT
            sum(amount)
        from
            unified_order
        <where>
            and pay_state = 2
            and inv_state = 1
            and complet_state != 3
            and service_no in ('QYNGZZ','QYNGDK')
            <if test="isdaide != null and isdaide == 1">
                and purchase_virt_id in (SELECT id from temp_daide)
            </if>
        </where>
    </select>

    <!-- 市场管理 - 区域管理 - 历史指标 -->
    <select id="getOrderAmountByAreaItem" resultType="java.math.BigDecimal">
        SELECT
            sum(order_amount) as order_amount
        from
            unified_statistics_virt
        <where>
            and s_year=#{syear}
            and s_month=#{smonth}
            and virt_id in (
                SELECT
                    virt_id
                from
                    unified_area_city_virt
                <where>
                    and area_city_id = #{areaItemId}
                </where>
            )
        </where>
    </select>

    <select id="getOrderCostAmount" resultType="java.math.BigDecimal">
        SELECT
            sum(cost_price * quantity) as cost_price
        from
            unified_order_goods
        <where>
        <if test="cost == 1">
            and quantity &gt; 0
        </if>
        <if test="cost == 2">
            and quantity &lt; 0
        </if>
        <if test="virtId != null and virtId != ''">
            and order_sn in (
                SELECT
                    order_sn
                from
                    unified_order
                <where>
                    and complet_state != 3
                    and purchase_virt_id = #{virtId}
                    and order_sn in (
                        SELECT
                            order_sn
                        from
                            unified_order_return
                        <where>
                            and complet_state != 3
                            and YEAR(create_time) = #{sYear}
                            and MONTH(create_time) = #{sMonth}
                        </where>
                    )
                </where>
            )
        </if>
        <if test="areaId != null and areaId != ''">
            and order_sn in (
                SELECT
                    order_sn
                from
                    unified_order
                <where>
                    complet_state != 3
                    and purchase_virt_id in (
                        SELECT
                            virt_id
                        from
                            unified_area_city_virt
                        <where>
                            area_city_id in (
                                SELECT
                                    id
                                from
                                    unified_area_city
                                <where>
                                    FIND_IN_SET(#{areaId},area_full_ids)
                                </where>
                            )
                        </where>
                    )
                    and order_sn in (
                        SELECT
                            order_sn
                        from
                            unified_order_return
                        <where>
                            and complet_state != 3
                            and YEAR(create_time)=#{sYear}
                            and MONTH(create_time)=#{sMonth}
                        </where>
                    )
                </where>
            )
        </if>
        </where>
    </select>

    <select id="getreturnAmountByAreaItem" resultType="java.math.BigDecimal">
        SELECT
        	sum(order_refund_amount) as order_refund_amount
        from
        	unified_statistics_virt
        <where>
            and s_year = #{syear}
            and s_month = #{smonth}
            and virt_id in (
            	SELECT virt_id from unified_area_city_virt where area_city_id=#{areaItemId}
            )
        </where>
    </select>

    <resultMap id="VirtBillResultMap" type="cn.superdesk.uniorder.dto.vo.wechat.WxBillVirt">
        <result column="virt_id" property="virtId" jdbcType="BIGINT"/>
        <result column="upayamount" property="upayamount" jdbcType="DECIMAL"/>
        <result column="amount" property="amount" jdbcType="DECIMAL"/>
    </resultMap>

    <select id="getVirtBill" resultMap="VirtBillResultMap">
        SELECT
			sum(order_amount) amount,
			sum(payable_amount) upayamount,
			virt_id
        from
        	unified_statistics_virt
        <where>
            <if test="virtId != null and virtId != ''">
                and virt_id=#{virtId}
            </if>
            <if test="syear != null and syear != ''">
                and s_year=#{syear}
            </if>
        </where>
    </select>

    <resultMap id="VirtBillItemResultMap" type="cn.superdesk.uniorder.dto.vo.wechat.WxBillVirtItem">
        <result column="virt_id" property="virtId" jdbcType="BIGINT"/>
        <result column="upayamount" property="upayamount" jdbcType="DECIMAL"/>
        <result column="amount" property="amount" jdbcType="DECIMAL"/>
    </resultMap>

    <select id="getVirtItemBill" resultMap="VirtBillItemResultMap">
        SELECT
			#{syear} as `year`,
			a.id as `month`,
			b.order_amount as amount,
			b.payable_amount as upayamount
        from
			unified_month a
			LEFT JOIN unified_statistics_virt b on a.id= b.s_month and b.s_year=#{syear} and b.virt_id=#{virtId}
        <where>

        </where>
    </select>

    <!-- mark by linjinyu at 20201125 重构 -->
    <resultMap id="TjVirtResultMap" type="cn.superdesk.uniorder.dto.vo.unified.UnifiedCustomerTJ">

        <result column="virt_id" property="virtId" jdbcType="BIGINT"/>

        <result column="s_year" property="sYear" jdbcType="INTEGER"/>
        <result column="s_month" property="sMonth" jdbcType="INTEGER"/>

        <result column="service_no" property="serviceNo" jdbcType="VARCHAR"/>

        <result column="order_amount" jdbcType="DECIMAL" property="orderAmount" />
        <result column="order_cost_amount" jdbcType="DECIMAL" property="orderCostAmount" />
        <result column="order_refund_amount" jdbcType="DECIMAL" property="orderRefundAmount" />
        <result column="order_refund_cost_amount" jdbcType="DECIMAL" property="orderRefundCostAmount" />
        <result column="order_transport_amount" jdbcType="DECIMAL" property="orderTransportAmount" />

        <result column="goods_amount" jdbcType="DECIMAL" property="goodsAmount" />
        <result column="goods_cost_amount" jdbcType="DECIMAL" property="goodsCostAmount" />
        <result column="goods_refund_amount" jdbcType="DECIMAL" property="goodsRefundAmount" />
        <result column="goods_refund_cost_amount" jdbcType="DECIMAL" property="goodsRefundCostAmount" />
        <result column="goods_transport_amount" jdbcType="DECIMAL" property="goodsTransportAmount" />

        <result column="payable_amount" jdbcType="DECIMAL" property="payableAmount" />
    </resultMap>

    <!-- mark by linjinyu at 20201125 重构 -->
    <select id="getData" resultMap="TjVirtResultMap">
        select
			virt_id,
            service_no,
            s_year,
            s_month,

			order_amount,
            order_cost_amount,
			order_refund_amount,
            order_refund_cost_amount,
            order_transport_amount,

            goods_amount,
            goods_cost_amount,
            goods_refund_amount,
            goods_refund_cost_amount,
            goods_transport_amount,

            payable_amount

        from
        	unified_statistics_virt
        <where>
        <if test="yearly != null and yearly != ''">
            and s_year= #{yearly}
        </if>
        <if test="monthly != null and monthly != ''">
            and s_month = #{monthly}
        </if>
        <if test="virtId != null and virtId != ''">
            and virt_id=#{virtId}
        </if>
        <if test="areaId != null and areaItemId == null">
            and virt_id in (
            	SELECT
            		virt_id
            	from
            		unified_area_city_virt
            	where
            		area_city_id =#{areaId}
            )
        </if>

        <if test="customerId != null and customerId != ''">
            AND virt_id in (
				SELECT
					virt_id
				from
					unified_area_city_virt
				where
					area_city_id in (
					SELECT
					    id
					from
					    unified_area_city
					where
					    FIND_IN_SET(#{customerId},customer_users)
				)
            )
        </if>
        <if test="purchaseId != null and purchaseId != ''">
            AND virt_id in (
				SELECT
				    virt_id
				from
				    unified_area_city_virt
				where area_city_id in (
					SELECT
					    id
					from
					    unified_area_city
					where
					    FIND_IN_SET(#{purchaseId},purchase_users)
				)
            )
        </if>
		</where>
    </select>

</mapper>