<?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.ruoyi.mall.mapper.MallGoodsGoodsMapper">
    <resultMap type="com.ruoyi.mall.domain.MallGoodsGoods" id="MallGoodsGoodsResult">
        <result property="id" column="id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="goodsTitle" column="goods_title"/>
        <result property="classId" column="class_id"/>
        <result property="classIdtwo" column="class_idtwo"/>
        <result property="classIdthree" column="class_idthree"/>
        <result property="goodsImg" column="goods_img"/>
        <result property="postFee" column="post_fee"/>
        <result property="monthlySales" column="monthly_sales"/>
        <result property="stock" column="stock"/>
        <result property="spec" column="spec"/>
        <result property="param" column="param"/>
        <result property="hasSpec" column="has_spec"/>
        <result property="isRecommend" column="is_recommend"/>
        <result property="isHot" column="is_hot"/>
        <result property="status" column="status"/>
        <result property="shareImg" column="share_img"/>
        <result property="shareTitle" column="share_title"/>
        <result property="sort" column="sort"/>
        <result property="createAt" column="create_at"/>
        <result property="updateAt" column="update_at"/>
        <result property="delFlag" column="del_flag"/>
        <result property="tips" column="tips"/>
        <result property="tag" column="tag"/>
        <result property="goodsBrand" column="goods_brand"/>
        <result property="goodsOrigin" column="goods_origin"/>
        <result property="goodsContent" column="goods_content"/>
        <result property="goodsWarranty" column="goods_warranty"/>
        <result property="goodsStorage" column="goods_storage"/>
        <result property="shopId" column="shop_id"/>
        <result property="supplierId" column="supplier_id"/>
        <result property="supplierIdTwo" column="supplier_id_two"/>
        <result property="supplierIdThree" column="supplier_id_three"/>
        <result property="shopName" column="shopName"/>
        <result property="supplierName" column="supplierName"/>
        <result property="commission" column="commission"/>
        <result property="priceVip" column="price_vip"/>
        <result property="goodsVideo" column="goods_video"/>
        <result property="checkStatus" column="check_status"/>
        <result property="isCopy" column="is_copy"/>
        <result property="showStatus" column="show_status"/>
        <result property="copyId" column="copy_id"/>
        <result property="integral" column="integral"/>
        <result property="isWeb" column="is_web"/>
        <result property="kilograms" column="kilograms"/>
        <result property="halal" column="halal"/>
        <result property="pricingreference" column="pricingreference"/>
    </resultMap>

    <resultMap type="com.ruoyi.mall.domain.vo.IndexGoodsVO" id="IndexGoodsVOResult">
        <result property="id" column="id"/>
        <result property="goodsName" column="goods_name"/>
        <result property="goodsTitle" column="goods_title"/>
        <result property="classId" column="class_id"/>
        <result property="classIdtwo" column="class_idtwo"/>
        <result property="classIdthree" column="class_idthree"/>
        <result property="goodsImg" column="goods_img"/>
        <result property="postFee" column="post_fee"/>
        <result property="monthlySales" column="monthly_sales"/>
        <result property="stock" column="stock"/>
        <result property="spec" column="spec"/>
        <result property="param" column="param"/>
        <result property="shareImg" column="share_img"/>
        <result property="shareTitle" column="share_title"/>
        <result property="productName" column="product_name"/>
        <result property="price" column="price"/>
        <result property="priceN" column="price_n"/>
        <result property="tips" column="tips"/>
        <result property="tag" column="tag"/>
        <result property="goodsBrand" column="goods_brand"/>
        <result property="goodsOrigin" column="goods_origin"/>
        <result property="goodsContent" column="goods_content"/>
        <result property="goodsWarranty" column="goods_warranty"/>
        <result property="goodsStorage" column="goods_storage"/>
        <result property="priceVip" column="price_vip"/>
        <result property="shopId" column="shop_id"/>
        <result property="supplierId" column="supplier_id"/>
        <result property="goodsVideo" column="goods_video"/>
        <result property="goodsContent" column="goods_content"/>
        <result property="integral" column="integral"/>
        <result property="isWeb" column="is_web"/>
        <result property="kilograms" column="kilograms"/>
        <result property="halal" column="halal"/>
        <result property="pricingreference" column="pricingreference"/>
    </resultMap>

    <resultMap type="com.ruoyi.mall.domain.vo.MallGoodsGoodsExportVO" id="MallGoodsGoodsExportVOResult">
        <result property="goodsId" column="goodsId"/>
        <result property="goodsName" column="goodsName"/>
        <result property="productName" column="productName"/>
        <result property="className" column="className"/>
        <result property="supplierName" column="supplierName"/>
        <result property="commission" column="commission"/>
        <result property="price" column="price"/>
        <result property="priceVip" column="priceVip"/>
    </resultMap>

    <sql id="selectMallGoodsGoodsVo">
        select id
             , goods_name
             , goods_title
             , class_id
             , class_idtwo
             , class_idthree
             , goods_img
             , post_fee
             , monthly_sales
             , stock
             , spec
             , param
             , has_spec
             , is_recommend
             , is_hot
             , status
             , share_img
             , share_title
             , tips
             , sort
             , create_at
             , update_at
             , del_flag
             , tag
             , shop_id
             , supplier_id
             , goods_video
             , commission
             , check_status
             , is_copy
             , show_status
             , copy_id
             , integral
             , is_web
             , kilograms
             , halal
             , pricingreference
        from mall_goods_goods
    </sql>

    <select id="selectMallGoodsGoodsListIndex" parameterType="MallGoodsGoods" resultMap="IndexGoodsVOResult">
        select mgg.id, mgg.goods_name, mgg.goods_title, mgg.class_id, mgg.class_idtwo, mgg.class_idthree, mgg.goods_img,
        mgg.post_fee, mgg.monthly_sales, mgg.stock, mgg.spec,
        mgg.param, mgg.has_spec, mgg.is_recommend, mgg.is_hot, mgg.status, mgg.share_img, mgg.share_title, mgg.sort,
        mgp.price,mgg.tips, mgp.price_n, mgp.price_m, mgp.stock, mgp.num_sale,
        mgp.product_name,mgg.create_at,mgg.tag,mgg.integral,mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
        left join mall_goods_product mgp on mgg.id = mgp.goods_id
        <where>
            <if test="goodsName != null  and goodsName != ''">
                and mgg.goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="isRecommend != null  and isRecommend != ''">
                and mgg.is_recommend = #{isRecommend}
            </if>
            <if test="isHot != null  and isHot != ''">
                and mgg.is_hot = #{isHot}
            </if>
            <if test="status != null  and status != ''">
                and mgg.status = #{status}
            </if>
            <if test="classId != null  and classId != ''">
                and (mgg.class_id = #{classId} or mgg.class_idtwo = #{classId} or mgg.class_idthree = #{classId} )
            </if>
            <if test="tag != null  and tag != ''">
                and mgg.tag = #{tag}
            </if>
            and mgp.is_default = 1
            and mgg.del_flag = '0'
        </where>
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
    </select>

    <!--,
        mgp.price, mgp.price_n, mgp.price_m, mgp.stock, mgp.num_sale, mgp.product_name,mgg.create_at left join mall_goods_product mgp on mgg.id = mgp.goods_id-->
    <select id="selectMallGoodsGoodsList" parameterType="MallGoodsGoods" resultMap="MallGoodsGoodsResult">
        select mgg.id, mgg.goods_name, mgg.goods_title, mgg.goods_brand, mgg.goods_origin, mgg.goods_content,
        mgg.goods_warranty,mgg.goods_storage, mgg.class_id, mgg.class_idtwo, mgg.class_idthree,mgc.name className,
        mgg.goods_img, mgg.post_fee,
        mgg.monthly_sales, mgg.stock,
        mgg.spec, mgg.param,mgg.tips, mgg.has_spec, mgg.is_recommend, mgg.is_hot, mgg.status, mgg.share_img,
        mgg.share_title,mgg.kilograms,mgg.halal,mgg.pricingreference,
        mgg.sort, mgg.create_at, mgg.tag,mgg.integral,mgg.is_web ,mgg.commission, mgg.check_status, mgg.is_copy
        ,mgg.show_status,mgg.shop_id , CASE mgg.shop_id
        WHEN 0 THEN "管理员"
        ELSE mss.shop_name
        END as shopName
        ,mgg.supplier_id
        , CASE mgg.supplier_id
        WHEN -1 THEN mss.shop_name
        WHEN 0 THEN "管理员"
        ELSE mssu.supplier_name
        END as supplierName,

        mgp.price as displayprice,
        mgp.price_vip as displaypriceVip,
        mgp.purchase_price as displaypurchasePrice

        from mall_goods_goods mgg
        left join mall_goods_product mgp on mgg.id = mgp.goods_id and mgp.is_default =1
        left join mall_goods_class mgc on mgc.id = mgg.class_id
        left join mall_shop_shop mss on mss.shop_id = mgg.shop_id
        left join mall_shop_supplier mssu on mgg.supplier_id = mssu.supplier_id
        <where>
            <if test="goodsName != null  and goodsName != ''">
                and mgg.goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="isRecommend != null  and isRecommend != ''">
                and mgg.is_recommend = #{isRecommend}
            </if>
            <if test="isHot != null  and isHot != ''">
                and mgg.is_hot = #{isHot}
            </if>
            <if test="status != null  and status != ''">
                and mgg.status = #{status}
            </if>
            <if test="classId != null  and classId != ''">
                and (mgg.class_id = #{classId} or mgg.class_idtwo = #{classId} or mgg.class_idthree = #{classId} )
            </if>
            <if test="shopId != null  and shopId != ''">
                and mgg.shop_id = #{shopId}
            </if>
            <if test="supplierId != null  and supplierId != ''">
                and mgg.supplier_id = #{supplierId}
            </if>
            <if test="supplierIdTwo != null  and supplierIdTwo != ''">
                and mgg.supplier_id_two = #{supplierIdTwo}
            </if>
            <if test="supplierIdThree != null  and supplierIdThree != ''">
                and mgg.supplier_id_three = #{supplierIdThree}
            </if>
            <if test="shopName != null  and shopName != ''">
                and mss.shop_name = #{shopName}
            </if>
            <if test="tag != null  and tag != ''">
                and mgg.tag = #{tag}
            </if>
            <if test="checkStatus != null ">
                and mgg.check_status = #{checkStatus}
            </if>
            <if test="stockStart != null ">
                and mgg.stock &gt;= #{stockStart}
            </if>
            <if test="stockEnd != null ">
                and mgg.stock &lt;= #{stockEnd}
            </if>
            <if test="isCopy != null ">
                and mgg.is_copy = #{isCopy}
            </if>
            <if test="isWeb != null ">
                and mgg.is_web = #{isWeb}
            </if>
            <if test="kilograms != null ">
                and mgg.kilograms = #{kilograms}
            </if>
            <if test="halal != null ">
                and mgg.halal = #{halal}
            </if>
            <if test="pricingreference != null  and pricingreference != ''">
                and mgg.pricingreference = #{pricingreference}
            </if>
            and mgg.del_flag = '0'
        </where>
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
    </select>

    <select id="selectOtherGoodsList" parameterType="MallGoodsGoods" resultMap="MallGoodsGoodsResult">
        SELECT
        mgg.id,
        mgg.goods_name,
        mgg.goods_title,
        mgg.goods_brand,
        mgg.goods_origin,
        mgg.goods_content,
        mgg.goods_warranty,
        mgg.goods_storage,
        mgg.class_id, mgg.class_idtwo, mgg.class_idthree,
        mgc.`name` className,
        mgg.goods_img,
        mgg.post_fee,
        mgg.monthly_sales,
        mgg.stock,
        mgg.spec,
        mgg.param,
        mgg.tips,
        mgg.has_spec,
        mgg.is_recommend,
        mgg.is_hot,
        mgg.`status`,
        mgg.share_img,
        mgg.share_title,
        mgg.sort,
        mgg.create_at,
        mgg.tag,
        mgg.commission,
        mgg.check_status,
        mgg.is_copy,
        mgg.show_status,
        mgg.shop_id,
        mgg.integral,mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        CASE
        mgg.shop_id
        WHEN 0 THEN
        "管理员" ELSE mss.shop_name
        END AS shopName,
        mgg.supplier_id,
        CASE
        mgg.supplier_id
        WHEN - 1 THEN
        mss.shop_name
        WHEN 0 THEN
        "管理员" ELSE mssu.supplier_name
        END AS supplierName
        FROM
        mall_goods_goods mgg
        LEFT JOIN mall_goods_class mgc ON mgc.id = mgg.class_id
        LEFT JOIN mall_shop_shop mss ON mss.shop_id = mgg.shop_id
        LEFT JOIN mall_shop_supplier mssu ON mgg.supplier_id = mssu.supplier_id
        <where>
            <if test="shopId != null  and shopId != '' ">
                and mgg.shop_id not in (#{shopId})
            </if>
            <if test="supplierId != null  and supplierId != ''">
                and mgg.supplier_id not in (#{supplierId})
            </if>
            <if test="goodsName != null  and goodsName != ''">
                and mgg.goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="classId != null  and classId != ''">
                and (mgg.class_id = #{classId} or mgg.class_idtwo = #{classId} or mgg.class_idthree = #{classId} )
            </if>
            <if test="checkStatus != null  and checkStatus != ''">
                and mgg.check_status = #{checkStatus}
            </if>

            and mgg.del_flag = '0'
            and mgg.shop_id = 12
            and mgg.is_copy = '0'
        </where>
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
    </select>

    <select id="selectMallGoodsGoodsById" parameterType="Long" resultMap="MallGoodsGoodsResult">
        select mgg.id
             , mgg.goods_name
             , mgg.goods_title
             , mgg.goods_brand
             , mgg.goods_origin
             , mgg.goods_content
             , mgg.goods_warranty
             , mgg.goods_storage
             , mgg.class_id
             , mgg.class_idtwo
             , mgg.class_idthree
             , mgg.goods_img
             , mgg.post_fee
             , mgg.monthly_sales
             , mgg.stock
             , mgg.spec
             , mgg.param
             , mgg.tips
             , mgg.has_spec
             , mgg.is_recommend
             , mgg.is_hot
             , mgg.status
             , mgg.share_img
             , mgg.share_title
             , mgg.sort
             , mgg.tag
             , mgg.integral
             , mgg.is_web
             , mgp.price
             , mgp.price_n
             , mgp.price_m
             , mgp.stock
             , mgp.num_sale
             , mgp.product_name
             , mgg.shop_id
             , mgg.supplier_id
             , mgg.commission
             , mgg.goods_video
             , mgg.check_status
             , mgg.is_copy
             , mgg.show_status,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
                 left join mall_goods_product mgp on mgg.id = mgp.goods_id and mgp.is_default = '1'
        where mgg.id = #{id}
          and mgg.del_flag = '0';
    </select>

    <select id="selectGoodsById" parameterType="Long" resultMap="MallGoodsGoodsResult">
        select mgg.id
             , mgg.goods_name
             , mgg.goods_title
             , mgg.goods_brand
             , mgg.goods_origin
             , mgg.goods_content
             , mgg.goods_warranty
             , mgg.goods_storage
             , mgg.class_id
             , mgg.class_idtwo
             , mgg.class_idthree
             , mgg.goods_img
             , mgg.post_fee
             , mgg.monthly_sales
             , mgg.stock
             , mgg.spec
             , mgg.param
             , mgg.tips
             , mgg.has_spec
             , mgg.is_recommend
             , mgg.is_hot
             , mgg.status
             , mgg.share_img
             , mgg.share_title
             , mgg.sort
             , mgg.tag
             , mgg.shop_id
             , mgg.supplier_id
             , mgg.commission
             , mgg.goods_video
             , mgg.check_status
             , mgg.is_copy
             , mgg.show_status
             , mgg.integral
             , mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
        where mgg.id = #{id}
    </select>

    <select id="selectMallGoodsBySales" resultMap="IndexGoodsVOResult">
        select mgg.id,
               mgg.goods_name,
               mgg.goods_title,
               mgg.class_id,
               mgg.class_idtwo,
               mgg.class_idthree,
               mgg.goods_img,
               mgg.goods_video,
               mgg.post_fee,
               mgg.monthly_sales,
               mgg.stock,
               mgg.spec,
               mgg.param,
               mgg.tips,
               mgg.has_spec,
               mgg.is_recommend,
               mgg.is_hot,
               mgg.status,
               mgg.share_img,
               mgg.share_title,
               mgg.sort,
               mgg.tag,
               mgp.price,
               mgp.price_n,
               mgp.price_m,
               mgp.stock,
               mgp.num_sale,
               mgp.product_name,
               mgg.integral,
               mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
                 left join mall_goods_product mgp on mgg.id = mgp.goods_id
        where mgp.is_default = '1'
          and mgg.del_flag = '0'
          and mgg.status = '0'
        order by mgp.num_sale desc
        limit 4
    </select>
    <select id="selectMallGoodsByCreatTime" resultMap="IndexGoodsVOResult">
        select mgg.id,
               mgg.goods_name,
               mgg.goods_title,
               mgg.class_id,
               mgg.class_idtwo,
               mgg.class_idthree,
               mgg.goods_img,
               mgg.goods_video,
               mgg.post_fee,
               mgg.monthly_sales,
               mgg.stock,
               mgg.spec,
               mgg.param,
               mgg.tips,
               mgg.has_spec,
               mgg.is_recommend,
               mgg.is_hot,
               mgg.status,
               mgg.share_img,
               mgg.share_title,
               mgg.sort,
               mgg.tag,
               mgp.price,
               mgp.price_n,
               mgp.price_m,
               mgp.stock,
               mgp.num_sale,
               mgp.product_name,
               mgg.integral,
               mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
                 left join mall_goods_product mgp on mgg.id = mgp.goods_id
        where mgp.is_default = '1'
          and mgg.del_flag = '0'
          and mgg.status = '0'
        order by mgg.create_at desc
        limit 4
    </select>
    <select id="selectMallGoodsByhot" resultMap="IndexGoodsVOResult">
        select mgg.id,
               mgg.goods_name,
               mgg.goods_title,
               mgg.class_id,
               mgg.class_idtwo,
               mgg.class_idthree,
               mgg.goods_img,
               mgg.goods_video,
               mgg.post_fee,
               mgg.monthly_sales,
               mgg.stock,
               mgg.spec,
               mgg.param,
               mgg.tips,
               mgg.has_spec,
               mgg.is_recommend,
               mgg.is_hot,
               mgg.status,
               mgg.share_img,
               mgg.share_title,
               mgg.sort,
               mgg.tag,
               mgp.price,
               mgp.price_n,
               mgp.price_m,
               mgp.stock,
               mgp.num_sale,
               mgp.product_name,
               mgg.integral,
               mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
                 left join mall_goods_product mgp on mgg.id = mgp.goods_id
        where mgp.is_default = '1'
          and mgg.is_hot = '1'
          and mgg.del_flag = '0'
          and mgg.status = '0'
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
    </select>
    <select id="selectMallGoodsByTag" parameterType="integer" resultMap="IndexGoodsVOResult">
        select mgg.id,
               mgg.goods_name,
               mgg.goods_title,
               mgg.class_id,
               mgg.class_idtwo,
               mgg.class_idthree,
               mgg.goods_img,
               mgg.goods_video,
               mgg.post_fee,
               mgg.monthly_sales,
               mgg.stock,
               mgg.spec,
               mgg.param,
               mgg.tips,
               mgg.has_spec,
               mgg.is_recommend,
               mgg.is_hot,
               mgg.status,
               mgg.share_img,
               mgg.share_title,
               mgg.sort,
               mgg.tag,
               mgp.price,
               mgp.price_n,
               mgp.price_m,
               mgp.stock,
               mgp.num_sale,
               mgp.product_name,
               mgg.integral,
               mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
                 left join mall_goods_product mgp on mgg.id = mgp.goods_id
        where mgp.is_default = '1'
          and mgg.tag = #{tagId}
          and mgg.del_flag = '0'
          and mgg.status = '0'
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
    </select>
    <select id="selectIndexMallGoodsByTag" resultMap="IndexGoodsVOResult">
        SELECT mgg.id,
               mgg.goods_name,
               mgg.goods_title,
               mgg.class_id,
               mgg.class_idtwo,
               mgg.class_idthree,
               mgg.goods_img,
               mgg.goods_video,
               mgg.post_fee,
               mgg.monthly_sales,
               mgg.stock,
               mgg.spec,
               mgg.param,
               mgg.tips,
               mgg.has_spec,
               mgg.is_recommend,
               mgg.is_hot,
               mgg.status,
               mgg.share_img,
               mgg.share_title,
               mgg.sort,
               mgg.tag,
               mgp.price,
               mgp.price_n,
               mgp.price_m,
               mgp.stock,
               mgp.num_sale,
               mgp.product_name,
               mgg.shop_id,
               mgg.supplier_id,
               mgg.integral,
               mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        FROM mall_goods_goods mgg
                 LEFT JOIN mall_goods_product mgp ON mgg.id = mgp.goods_id
        WHERE mgp.is_default = '1'
          AND mgg.tag = #{tagId}
          AND mgg.del_flag = '0'
          AND mgg.status = '0'
          and mgg.show_status = 0
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
        LIMIT #{pageSize}
    </select>

    <select id="selectMallGoodsGoodsListVO" parameterType="MallGoodsGoods" resultMap="IndexGoodsVOResult">
        SELECT
        mgg.id,
        mgg.goods_name,
        mgg.goods_title,
        mgg.class_id, mgg.class_idtwo, mgg.class_idthree,
        mgg.goods_img,
        mgg.goods_video,
        mgg.post_fee,
        mgg.monthly_sales,
        mgg.stock,
        mgg.spec,
        mgg.param,
        mgg.tips,
        mgg.has_spec,
        mgg.is_recommend,
        mgg.is_hot,
        mgg.`status`,
        mgg.share_img,
        mgg.share_title,
        mgg.sort,
        mgg.tag,
        mgp.price,
        mgp.price_vip,
        mgp.price_n,
        mgp.price_m,
        mgp.num_sale,
        mgp.product_name,
        mgg.shop_id,
        mgg.supplier_id,
        mgg.goods_content,
        mgg.integral,mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        FROM
        mall_goods_goods mgg
        LEFT JOIN mall_goods_product mgp ON mgg.id = mgp.goods_id
        LEFT JOIN mall_goods_class mgc ON mgg.class_id = mgc.id
        <where>
            <if test="goodsName != null  and goodsName != ''">
                and mgg.goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="isRecommend != null  and isRecommend != ''">
                and mgg.is_recommend = #{isRecommend}
            </if>
            <if test="isHot != null  and isHot != ''">
                and mgg.is_hot = #{isHot}
            </if>
            <if test="status != null  and status != ''">
                and mgg.status = #{status}
            </if>
            <if test="classId != null  and classId != 62 and classId != 63 ">
                and (FIND_IN_SET( #{classId}, mgg.class_id) or mgc.parent_id = #{classId})
            </if>
            <if test="shopId != null ">
                and mgg.shop_id = #{shopId}
            </if>
            <if test="tag != null  and tag != ''">
                and mgg.tag = #{tag}
            </if>
            <if test="classId != null and classId == 62">
                and mgg.tag = 2
            </if>
            <if test="classId != null and classId == 63">
                and mgg.tag = 3
            </if>
            and mgp.is_default = '1'
            and mgg.del_flag = '0'
            and mgg.status = '0'
            and mgg.check_status = '1'
            and mgg.show_status = 0
        </where>
        order by
        <choose>
            <when test="sortType != null and sortType == 0">
                mgg.monthly_sales desc,mgp.price desc
            </when>
            <when test="sortType != null and sortType == 1">
                mgg.monthly_sales asc
            </when>
            <when test="sortType != null and sortType == 2">
                mgg.monthly_sales desc
            </when>
            <when test="sortType != null and sortType == 3">
                mgp.price asc
            </when>
            <when test="sortType != null and sortType == 4">
                mgp.price desc
            </when>
            <when test="sortType != null and sortType == 5">
                mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
            </when>
            <otherwise>
                mgg.create_at desc
            </otherwise>
        </choose>
    </select>

    <select id="commonGoodsList" parameterType="MallGoodsGoods" resultMap="IndexGoodsVOResult">
        SELECT mgg.id,
               mgg.goods_name,
               mgg.goods_title,
               mgg.class_id,
               mgg.class_idtwo,
               mgg.class_idthree,
               mgg.goods_img,
               mgg.goods_video,
               mgg.post_fee,
               mgg.monthly_sales,
               mgg.stock,
               mgg.spec,
               mgg.param,
               mgg.tips,
               mgg.has_spec,
               mgg.is_recommend,
               mgg.is_hot,
               mgg.status,
               mgg.share_img,
               mgg.share_title,
               mgg.sort,
               mgg.tag,
               mgp.price,
               mgp.price_n,
               mgp.price_m,
               mgp.stock,
               mgp.num_sale,
               mgp.product_name,
               mgp.price_vip,
               mgg.integral,
               mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        FROM mall_goods_goods mgg
                 LEFT JOIN mall_goods_product mgp
                           ON mgg.id = mgp.goods_id
                 LEFT JOIN
             (SELECT goods_id,
                     COUNT(goods_id) `count`
              FROM mall_order_goods
              WHERE order_id IN
                    (SELECT id
                     FROM mall_order_order
                     WHERE user_id = #{userId}
                       AND del_flag = '0')
              GROUP BY goods_id
              ORDER BY `count` DESC) tmp
             ON tmp.goods_id = mgg.id
        WHERE mgg.id = tmp.goods_id
          and mgp.is_default = '1'
          and mgg.del_flag = '0'
          and mgg.status = '0'
          and mgg.check_status = '1'
    </select>

    <select id="selectMallGoodsGoodsByIdVO" parameterType="Long" resultMap="IndexGoodsVOResult">
        select mgg.id,
               mgg.goods_name,
               mgg.goods_title,
               mgg.goods_brand,
               mgg.goods_origin,
               mgg.goods_content,
               mgg.goods_warranty,
               mgg.goods_storage,
               mgg.class_id, mgg.class_idtwo, mgg.class_idthree,
               mgg.goods_img,
               mgg.goods_video,
               mgg.post_fee,
               mgg.monthly_sales,
               mgg.stock,
               mgg.spec,
               mgg.param,
               mgg.tips,
               mgg.has_spec,
               mgg.share_img,
               mgg.share_title,
               mgg.sort,
               mgg.tag,
               mgp.price,
               mgp.price_vip,
               mgp.price_n,
               mgp.stock,
               mgp.num_sale,
               mgp.product_name,
               mgg.integral,
               mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        from mall_goods_goods mgg
                 left join mall_goods_product mgp on mgg.id = mgp.goods_id
        where mgg.id = #{aLong}
          and mgp.is_default = '1'
          and mgg.del_flag = '0'
          and mgg.status = '0'
          and mgg.check_status = '1'
        limit 1
    </select>

    <insert id="insertMallGoodsGoods" parameterType="MallGoodsGoods" useGeneratedKeys="true" keyProperty="id">
        insert into mall_goods_goods
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="goodsName != null">
                goods_name,
            </if>
            <if test="goodsTitle != null">
                goods_title,
            </if>
            <if test="classId != null">
                class_id,
            </if>
            <if test="classIdtwo != null">
                class_idtwo,
            </if>
            <if test="classIdthree != null">
                class_idthree,
            </if>
            <if test="goodsImg != null">
                goods_img,
            </if>
            <if test="postFee != null">
                post_fee,
            </if>
            <if test="monthlySales != null">
                monthly_sales,
            </if>
            <if test="stock != null">
                stock,
            </if>
            <if test="spec != null">
                spec,
            </if>
            <if test="param != null">
                param,
            </if>
            <if test="hasSpec != null">
                has_spec,
            </if>
            <if test="isRecommend != null">
                is_recommend,
            </if>
            <if test="isHot != null">
                is_hot,
            </if>
            <if test="status != null">
                status,
            </if>
            <if test="shareImg != null">
                share_img,
            </if>
            <if test="shareTitle != null">
                share_title,
            </if>
            <if test="sort != null">
                sort,
            </if>
            <if test="createAt != null">
                create_at,
            </if>
            <if test="updateAt != null">
                update_at,
            </if>
            <if test="delFlag != null">
                del_flag,
            </if>
            <if test="tips != null">
                tips,
            </if>
            <if test="tag != null">
                tag,
            </if>
            <if test="goodsBrand != null and goodsBrand != ''">
                goods_brand,
            </if>
            <if test="goodsOrigin != null and goodsOrigin != ''">
                goods_origin,
            </if>
            <if test="goodsContent != null and goodsContent != ''">
                goods_content,
            </if>
            <if test="goodsWarranty != null and goodsWarranty != ''">
                goods_warranty,
            </if>
            <if test="goodsStorage != null and goodsStorage != ''">
                goods_storage,
            </if>
            <if test="shopId != null">
                shop_id,
            </if>
            <if test="supplierId != null">
                supplier_id,
            </if>
            <if test="commission != null">
                commission,
            </if>
            <if test="goodsVideo != null">
                goods_video,
            </if>
            <if test="checkStatus != null">
                check_status,
            </if>
            <if test="isCopy != null">
                is_copy,
            </if>
            <if test="showStatus != null">
                show_status,
            </if>
            <if test="copyId != null">
                copy_id,
            </if>
            <if test="integral != null">
                integral,
            </if>
            <if test="isWeb != null">
                is_web,
            </if>
            <if test="kilograms != null">
                kilograms,
            </if>
            <if test="halal != null">
                halal,
            </if>
            <if test="pricingreference != null and pricingreference != ''">
                pricingreference,
            </if>
        </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="goodsName != null">
                #{goodsName},
            </if>
            <if test="goodsTitle != null">
                #{goodsTitle},
            </if>
            <if test="classId != null">
                #{classId},
            </if>
            <if test="classIdtwo != null">
                #{classIdtwo},
            </if>
            <if test="classIdthree != null">
                #{classIdthree},
            </if>
            <if test="goodsImg != null">
                #{goodsImg},
            </if>
            <if test="postFee != null">
                #{postFee},
            </if>
            <if test="monthlySales != null">
                #{monthlySales},
            </if>
            <if test="stock != null">
                #{stock},
            </if>
            <if test="spec != null">
                #{spec},
            </if>
            <if test="param != null">
                #{param},
            </if>
            <if test="hasSpec != null">
                #{hasSpec},
            </if>
            <if test="isRecommend != null">
                #{isRecommend},
            </if>
            <if test="isHot != null">
                #{isHot},
            </if>
            <if test="status != null">
                #{status},
            </if>
            <if test="shareImg != null">
                #{shareImg},
            </if>
            <if test="shareTitle != null">
                #{shareTitle},
            </if>
            <if test="sort != null">
                #{sort},
            </if>
            <if test="createAt != null">
                #{createAt},
            </if>
            <if test="updateAt != null">
                #{updateAt},
            </if>
            <if test="delFlag != null">
                #{delFlag},
            </if>
            <if test="tips != null">
                #{tips},
            </if>
            <if test="tag != null">
                #{tag},
            </if>
            <if test="goodsBrand != null and goodsBrand != ''">
                #{goodsBrand},
            </if>
            <if test="goodsOrigin != null and goodsOrigin != ''">
                #{goodsOrigin},
            </if>
            <if test="goodsContent != null and goodsContent != ''">
                #{goodsContent},
            </if>
            <if test="goodsWarranty != null and goodsWarranty != ''">
                #{goodsWarranty},
            </if>
            <if test="goodsStorage != null and goodsStorage != ''">
                #{goodsStorage},
            </if>
            <if test="shopId != null">
                #{shopId},
            </if>
            <if test="supplierId != null">
                #{supplierId},
            </if>
            <if test="commission != null">
                #{commission},
            </if>
            <if test="goodsVideo != null">
                #{goodsVideo},
            </if>
            <if test="checkStatus != null">
                #{checkStatus},
            </if>
            <if test="isCopy != null">
                #{isCopy},
            </if>
            <if test="showStatus != null">
                #{showStatus},
            </if>
            <if test="copyId != null">
                #{copyId},
            </if>
            <if test="integral != null">
                #{integral},
            </if>
            <if test="isWeb != null">
                #{isWeb},
            </if>
            <if test="kilograms != null">
                #{kilograms},
            </if>
            <if test="halal != null">
                #{halal},
            </if>
            <if test="pricingreference != null and pricingreference != ''">
                #{pricingreference},
            </if>
        </trim>
    </insert>

    <update id="updateMallGoodsGoods" parameterType="MallGoodsGoods">
        update mall_goods_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsName != null">
                goods_name = #{goodsName},
            </if>
            <if test="goodsTitle != null">
                goods_title = #{goodsTitle},
            </if>
            <if test="classId != null">
                class_id = #{classId},
            </if>
            <if test="classIdtwo != null">
                class_idtwo = #{classIdtwo},
            </if>
            <if test="classIdthree != null">
                class_idthree = #{classIdthree},
            </if>
            <if test="goodsImg != null">
                goods_img = #{goodsImg},
            </if>
            <if test="postFee != null">
                post_fee = #{postFee},
            </if>
            <if test="monthlySales != null">
                monthly_sales = #{monthlySales},
            </if>
            <if test="stock != null">
                stock = #{stock},
            </if>
            <if test="spec != null">
                spec = #{spec},
            </if>
            <if test="param != null">
                param = #{param},
            </if>
            <if test="hasSpec != null">
                has_spec = #{hasSpec},
            </if>
            <if test="isRecommend != null">
                is_recommend = #{isRecommend},
            </if>
            <if test="isHot != null">
                is_hot = #{isHot},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="shareImg != null">
                share_img = #{shareImg},
            </if>
            <if test="shareTitle != null">
                share_title = #{shareTitle},
            </if>
            <if test="sort != null">
                sort = #{sort},
            </if>
            <if test="createAt != null">
                create_at = #{createAt},
            </if>
            <if test="updateAt != null">
                update_at = #{updateAt},
            </if>
            <if test="delFlag != null and delFlag != ''">
                del_flag = #{delFlag},
            </if>
            <if test="tips != null">
                tips = #{tips},
            </if>
            tag = #{tag},
            <if test="goodsBrand != null and goodsBrand != ''">
                goods_brand = #{goodsBrand},
            </if>
            <if test="goodsOrigin != null and goodsOrigin != ''">
                goods_origin = #{goodsOrigin},
            </if>
            <if test="goodsContent != null and goodsContent != ''">
                goods_content = #{goodsContent},
            </if>
            <if test="goodsWarranty != null and goodsWarranty != ''">
                goods_warranty = #{goodsWarranty},
            </if>
            <if test="goodsStorage != null and goodsStorage != ''">
                goods_storage = #{goodsStorage},
            </if>
            <if test="shopId != null">
                shop_id = #{shopId},
            </if>
            <if test="supplierId != null">
                supplier_id = #{supplierId},
            </if>
            <if test="supplierIdTwo != null">
                supplier_id_two = #{supplierIdTwo},
            </if>
            <if test="supplierIdThree != null">
                supplier_id_three = #{supplierIdThree},
            </if>
            <if test="supplierIds != null">
                supplier_ids = #{supplierIds},
            </if>
            <if test="commission != null">
                commission = #{commission},
            </if>
            <if test="goodsVideo != null">
                goods_video = #{goodsVideo},
            </if>
            <if test="checkStatus != null">
                check_status = #{checkStatus},
            </if>
            <if test="isCopy != null">
                is_copy = #{isCopy},
            </if>
            <if test="showStatus != null">
                show_status = #{showStatus},
            </if>
            <if test="copyId != null">
                copy_id = #{copyId},
            </if>
            <if test="integral != null">
                integral = #{integral},
            </if>
            <if test="isWeb != null">
                is_web = #{isWeb},
            </if>
            <if test="supplierIds != null">
                supplier_ids = #{supplierIds},
            </if>
            <if test="kilograms != null">
                kilograms = #{kilograms},
            </if>
            <if test="halal != null">
                halal = #{halal},
            </if>
            <if test="pricingreference != null and pricingreference != ''">
                pricingreference = #{pricingreference},
            </if>
        </trim>
        where id = #{id}
    </update>

    <update id="updateMallGoodsGoodsSaleNum" parameterType="MallGoodsGoods">
        update mall_goods_goods
        set monthly_sales = monthly_sales + #{count}
        where id = #{goodsId}
    </update>

    <update id="updateMallGoodsGoodsStock" parameterType="MallGoodsGoods">
        update mall_goods_goods
        set stock = stock - #{count}
        where id = #{goodsId}
    </update>

    <delete id="deleteMallGoodsGoodsById" parameterType="Long">
        delete
        from mall_goods_goods
        where id = #{id}
    </delete>

    <delete id="deleteMallGoodsGoodsByIds" parameterType="String">
        update mall_goods_goods SET del_flag = '1' where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="getSalesmanAllGoodsList" resultType="map">
        select MGG.id goodsId, MGG.goods_img goodsImg, MGG.goods_name goodsName, MGG.spec, MGG.commission
        ,(
        select MGP.price from mall_goods_product MGP
        where MGG.id = MGP.goods_id
        and MGP.del_flag = '0'
        order by MGP.price
        limit 1
        ) price
        from mall_goods_goods MGG
        <where>
            <if test="goodsId != null ">
                and MGG.id = #{goodsId}
            </if>
            <if test="goodsName != null  and goodsName != ''">
                and MGG.goods_name like concat('%', #{goodsName}, '%')
            </if>
            and MGG.del_flag = '0' and MGG.check_status = '1' and MGG.status = '0'
        </where>
        <choose>
            <when test="sort == null or sort == '' or sort == 0">
                order by MGG.commission desc, MGG.create_at desc
            </when>
            <when test="sort == 1">
                order by price desc, MGG.create_at desc
            </when>
            <when test="sort == 2">
                order by price asc, MGG.create_at desc
            </when>
            <when test="sort == 3">
                order by MGG.commission desc, MGG.create_at desc
            </when>
            <when test="sort == 4">
                order by MGG.commission asc, MGG.create_at desc
            </when>
            <otherwise>
                order by MGG.commission desc, MGG.create_at desc
            </otherwise>
        </choose>
    </select>

    <update id="updateGoodsStock">
        update mall_goods_goods
        set stock         = stock + #{total},
            monthly_sales = monthly_sales - #{total}
        where id = #{goodsId}
    </update>

    <select id="selectExportScreenGoodsList" parameterType="MallGoodsGoods" resultMap="MallGoodsGoodsExportVOResult">
        select
        mgg.id goodsId,
        mgg.goods_name goodsName,
        mgp.product_name productName,
        mgc.name className,
        CASE mgg.supplier_id
        WHEN -1 THEN mss.shop_name
        WHEN 0 THEN "管理员"
        ELSE mssu.supplier_name
        END as supplierName,
        mgg.commission,
        mgp.price,
        mgp.price_vip priceVip,
        CASE mgg.shop_id
        WHEN 0 THEN "管理员"
        ELSE mss.shop_name
        END as shopName
        from mall_goods_goods mgg
        left join mall_goods_class mgc on mgc.id = mgg.class_id
        left join mall_goods_product mgp on mgp.goods_id = mgg.id
        left join mall_shop_shop mss on mss.shop_id = mgg.shop_id
        left join mall_shop_supplier mssu on mgg.supplier_id = mssu.supplier_id
        <where>
            <if test="goodsName != null  and goodsName != ''">
                and mgg.goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="isRecommend != null  and isRecommend != ''">
                and mgg.is_recommend = #{isRecommend}
            </if>
            <if test="isHot != null  and isHot != ''">
                and mgg.is_hot = #{isHot}
            </if>
            <if test="status != null  and status != ''">
                and mgg.status = #{status}
            </if>
            <if test="classId != null  and classId != ''">
                and (mgg.class_id = #{classId} or mgg.class_idtwo = #{classId} or mgg.class_idthree = #{classId} )
            </if>
            <if test="shopId != null  and shopId != ''">
                and mgg.shop_id = #{shopId}
            </if>
            <if test="supplierId != null  and supplierId != ''">
                and mgg.supplier_id = #{supplierId}
            </if>
            <if test="shopName != null  and shopName != ''">
                and mss.shop_name = #{shopName}
            </if>
            <if test="tag != null  and tag != ''">
                and mgg.tag = #{tag}
            </if>
            <if test="checkStatus != null ">
                and mgg.check_status = #{checkStatus}
            </if>
            <if test="stockStart != null ">
                and mgg.stock &gt;= #{stockStart}
            </if>
            <if test="stockEnd != null ">
                and mgg.stock &lt;= #{stockEnd}
            </if>
            and mgg.del_flag = '0'
            and mgp.del_flag = '0'
        </where>
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
    </select>

    <select id="selectExportCheckGoodsList" parameterType="MallGoodsGoods" resultMap="MallGoodsGoodsExportVOResult">
        select
        mgg.id goodsId,
        mgg.goods_name goodsName,
        mgp.product_name productName,
        mgc.name className,
        CASE mgg.supplier_id
        WHEN -1 THEN mss.shop_name
        WHEN 0 THEN "管理员"
        ELSE mssu.supplier_name
        END as supplierName,
        mgg.commission,
        mgp.price,
        mgp.price_vip priceVip,
        CASE mgg.shop_id
        WHEN 0 THEN "管理员"
        ELSE mss.shop_name
        END as shopName
        from mall_goods_goods mgg
        left join mall_goods_class mgc on mgc.id = mgg.class_id
        left join mall_goods_product mgp on mgp.goods_id = mgg.id
        left join mall_shop_shop mss on mss.shop_id = mgg.shop_id
        left join mall_shop_supplier mssu on mgg.supplier_id = mssu.supplier_id
        where mgg.id in
        <foreach item="goodsId" collection="array" open="(" separator="," close=")">
            #{goodsId}
        </foreach>
        and mgg.del_flag = '0'
        and mgp.del_flag = '0'
        ORDER BY mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
    </select>

    <update id="updateXcxReviewHiddenGoods">
        UPDATE mall_goods_goods
        SET show_status =
                CASE
                    WHEN #{showStatus} = 1 and id = 199 THEN 0
                    WHEN #{showStatus} = 1 and id != 199 THEN 1
                    WHEN #{showStatus} = 0 and id = 199 THEN 1
                    WHEN #{showStatus} = 0 and id != 199 THEN 0
                    ELSE 0
                    END
    </update>

    <update id="updateXcxReviewHiddenGoodsClass">
        UPDATE mall_goods_class
        SET show_status =
                CASE
                    WHEN #{showStatus} = 1 and (id = 131 or id = 132) THEN 0
                    WHEN #{showStatus} = 1 and (id != 131 or id != 132) THEN 1
                    WHEN #{showStatus} = 0 and (id = 131 or id = 132) THEN 1
                    WHEN #{showStatus} = 0 and (id != 131 or id != 132) THEN 0
                    ELSE 0
                    END
    </update>

    <select id="selectMallGoodsGoodsListByCopyId" resultMap="MallGoodsGoodsResult">
        select *
        from mall_goods_goods
        where copy_id = #{copyId}
          and del_flag = '0'
        ORDER BY create_at desc
    </select>

    <update id="updateCopyMallGoodsGoods" parameterType="MallGoodsGoods">
        update mall_goods_goods
        <trim prefix="SET" suffixOverrides=",">
            <if test="goodsName != null">
                goods_name = #{goodsName},
            </if>
            <if test="goodsTitle != null">
                goods_title = #{goodsTitle},
            </if>
            <if test="goodsBrand != null and goodsBrand != ''">
                goods_brand = #{goodsBrand},
            </if>
            <if test="goodsOrigin != null and goodsOrigin != ''">
                goods_origin = #{goodsOrigin},
            </if>
            <if test="goodsContent != null and goodsContent != ''">
                goods_content = #{goodsContent},
            </if>
            <if test="goodsWarranty != null and goodsWarranty != ''">
                goods_warranty = #{goodsWarranty},
            </if>
            <if test="goodsStorage != null and goodsStorage != ''">
                goods_storage = #{goodsStorage},
            </if>
            <if test="classId != null">
                class_id = #{classId},
            </if>
            <if test="classIdtwo != null">
                class_idtwo = #{classIdtwo},
            </if>
            <if test="classIdthree != null">
                class_idthree = #{classIdthree},
            </if>
            <if test="goodsImg != null">
                goods_img = #{goodsImg},
            </if>
            <if test="goodsVideo != null and goodsVideo != ''">
                goods_video = #{goodsVideo},
            </if>
            <if test="postFee != null">
                post_fee = #{postFee},
            </if>
            <if test="monthlySales != null">
                monthly_sales = #{monthlySales},
            </if>
            <if test="stock != null">
                stock = #{stock},
            </if>
            <if test="spec != null and spec != ''">
                spec = #{spec},
            </if>
            <if test="isRecommend != null">
                is_recommend = #{isRecommend},
            </if>
            <if test="isHot != null">
                is_hot = #{isHot},
            </if>
            <if test="status != null">
                status = #{status},
            </if>
            <if test="tips != null">
                tips = #{tips},
            </if>
            tag = #{tag},
            <if test="commission != null">
                commission = #{commission},
            </if>
            <if test="showStatus != null">
                show_status = #{showStatus},
            </if>
            <if test="integral != null">
                integral = #{integral},
            </if>
            <if test="isWeb != null">
                is_web = #{isWeb},
            </if>
            <if test="kilograms != null">
                kilograms = #{kilograms},
            </if>
            <if test="isWeb != null">
                halal = #{halal},
            </if>
            <if test="pricingreference != null and pricingreference != ''">
                pricingreference = #{pricingreference},
            </if>
        </trim>
        where copy_id = #{copyId}
    </update>

    <select id="selectMallGoodsGoodsListCopyIdIsNull" resultMap="MallGoodsGoodsResult">
        SELECT mggc.id
             , mggc.tag
             , (SELECT mgg.id
                FROM mall_goods_goods mgg
                WHERE mgg.goods_name = mggc.goods_name
                  AND mgg.is_copy = 0
                order by mgg.create_at asc
                limit 1) copy_id
             , (SELECT mgg.stock
                FROM mall_goods_goods mgg
                WHERE mgg.goods_name = mggc.goods_name
                  AND mgg.is_copy = 0
                order by mgg.create_at asc
                limit 1) stock

        FROM mall_goods_goods mggc
        WHERE mggc.is_copy = 1
          AND (mggc.copy_id = 0 or mggc.copy_id is null)
          AND mggc.del_flag = '0'
    </select>

    <update id="batchUpdateCopyMallGoodsGoods">
        <foreach collection="list" item="item" separator=";">
            update mall_goods_goods
            <trim prefix="SET" suffixOverrides=",">
                <if test="item.stock != null and item.stock != ''">
                    stock = #{item.stock},
                </if>
                <if test="item.copyId != null and item.copyId != ''">
                    copy_id = #{item.copyId},
                </if>
                <if test="item.updateAt != null and item.updateAt != ''">
                    update_at = #{item.updateAt},
                </if>
            </trim>
            where id = #{item.id}
        </foreach>
    </update>

    <delete id="deleteCopyMallGoodsGoodsByCopyIds" parameterType="String">
        update mall_goods_goods SET del_flag = '1' where copy_id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectMallGoodsGoodsListDTO" parameterType="MallGoodsGoods" resultMap="IndexGoodsVOResult">
        SELECT
        mgg.id,
        mgg.goods_name,
        mgg.goods_title,
        mgg.class_id, mgg.class_idtwo, mgg.class_idthree,
        mgg.goods_img,
        mgg.goods_video,
        mgg.post_fee,
        mgg.monthly_sales,
        mgg.stock,
        mgg.spec,
        mgg.param,
        mgg.tips,
        mgg.has_spec,
        mgg.is_recommend,
        mgg.is_hot,
        mgg.`status`,
        mgg.share_img,
        mgg.share_title,
        mgg.sort,
        mgg.tag,
        mgp.price,
        mgp.price_vip,
        mgp.price_n,
        mgp.price_m,
        mgp.num_sale,
        mgp.product_name,
        mgg.shop_id,
        mgg.supplier_id,
        mgg.goods_content,
        mgg.integral,mgg.is_web,mgg.kilograms,mgg.halal,mgg.pricingreference
        FROM
        mall_goods_goods mgg
        LEFT JOIN mall_goods_product mgp ON mgg.id = mgp.goods_id
        LEFT JOIN mall_goods_class mgc ON mgg.class_id = mgc.id
        <where>
            <if test="goodsName != null  and goodsName != ''">
                and mgg.goods_name like concat('%', #{goodsName}, '%')
            </if>
            <if test="isRecommend != null  and isRecommend != ''">
                and mgg.is_recommend = #{isRecommend}
            </if>
            <if test="isHot != null  and isHot != ''">
                and mgg.is_hot = #{isHot}
            </if>
            <if test="status != null  and status != ''">
                and mgg.status = #{status}
            </if>
            <if test="classId != null  and classId != 62 and classId != 63 ">
                and ((FIND_IN_SET( #{classId}, mgg.class_id) or FIND_IN_SET( #{classId}, mgg.class_idtwo) or FIND_IN_SET( #{classId}, mgg.class_idthree)) or mgc.parent_id = #{classId})
            </if>
            <if test="shopId != null and shopId != ''">
                and mgg.shop_id = #{shopId}
            </if>
            <if test="tag != null  and tag != ''">
                and mgg.tag = #{tag}
            </if>
            <if test="classId != null and classId == 62">
                and mgg.tag = 2
            </if>
            <if test="classId != null and classId == 63">
                and mgg.tag = 3
            </if>
            <if test="isWeb != null">
                and mgg.is_web = '1'
            </if>
            and mgp.is_default = '1'
            and mgg.del_flag = '0'
            and mgg.status = '0'
            and mgg.check_status = '1'
            and mgg.show_status = 0
        </where>
        order by
        <choose>
            <when test="sortType != null and sortType == 0">
                mgg.monthly_sales desc,mgp.price desc
            </when>
            <when test="sortType != null and sortType == 1">
                mgg.monthly_sales asc
            </when>
            <when test="sortType != null and sortType == 2">
                mgg.monthly_sales desc
            </when>
            <when test="sortType != null and sortType == 3">
                mgp.price asc
            </when>
            <when test="sortType != null and sortType == 4">
                mgp.price desc
            </when>
            <when test="sortType != null and sortType == 5">
                mgg.sort asc, mgg.create_at desc, mgg.monthly_sales DESC
            </when>
            <otherwise>
                mgg.create_at desc
            </otherwise>
        </choose>
    </select>

    <select id="selectgoodssort" resultType="int">
        SELECT MAX(id) AS max_id
        FROM mall_goods_goods;
    </select>

    <select id="selectallGoods" parameterType="MallAppGoodsVo" resultMap="MallAppGoodsVoResult">
        SELECT id ,goods_name
        FROM mall_goods_goods GROUP BY  id,goods_name
    </select>
    <resultMap type="com.ruoyi.mall.domain.MallAppGoodsVo" id="MallAppGoodsVoResult">
    <result property="id" column="id"/>
    <result property="goodsName" column="goods_name"/>
    </resultMap>
</mapper>
