<?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.MallOrderOrderMapper">

    <resultMap type="com.ruoyi.mall.domain.MallOrderOrder" id="MallOrderOrderResult">
        <result property="id"    column="id"    />
        <result property="orderNo"    column="order_no"    />
        <result property="userId"    column="user_id"    />
        <result property="postFee"    column="post_fee"    />
        <result property="orderPrice"    column="order_price"    />
        <result property="payment"    column="payment"    />
        <result property="status"    column="status"    />
        <result property="createAt"    column="create_at"    />
        <result property="payAt"    column="pay_at"    />
        <result property="payType"    column="pay_type"    />
        <result property="consignAt"    column="consign_at"    />
        <result property="enterAt"    column="enter_at"    />
        <result property="returnAt"    column="return_at"    />
        <result property="completeAt"    column="complete_at"    />
        <result property="shippingMark"    column="shipping_mark"    />
        <result property="shippingName"    column="shipping_name"    />
        <result property="shippingCode"    column="shipping_code"    />
        <result property="buyerMsg"    column="buyer_msg"    />
        <result property="isRefund"    column="is_refund"    />
        <result property="receiverName"    column="receiver_name"    />
        <result property="receiverPhone"    column="receiver_phone"    />
        <result property="receiverProvince"    column="receiver_province"    />
        <result property="receiverCity"    column="receiver_city"    />
        <result property="receiverArea"    column="receiver_area"    />
        <result property="receiverAddress"    column="receiver_address"    />
        <result property="year"    column="year"    />
        <result property="month"    column="month"    />
        <result property="day"    column="day"    />
        <result property="delFlag"    column="del_flag"    />
        <result property="isChangeAddress"    column="is_change_address"    />
        <result property="orderType"    column="order_type"    />
        <result property="discountPrice"    column="discount_price"    />
        <result property="salesmanId"    column="salesman_id"    />
        <result property="teamId"    column="team_id"    />
        <result property="deliveryType"    column="delivery_type"    />
        <result property="totalOrderSn"    column="total_order_sn"    />
        <result property="shopId"    column="shop_id"    />
        <result property="memberCouponId"    column="member_coupon_id"    />
        <result property="commissionPrice"    column="commission_price"    />
        <result property="orderStatus"    column="order_status"    />
        <result property="isPay"    column="is_pay"    />
        <result property="isProof"    column="is_proof"    />
        <result property="payProof"    column="pay_proof"    />
        <result property="isCar"    column="is_car"    />
        <result property="carVideo"    column="car_video"    />
        <result property="isExamine"    column="is_examine"    />
        <result property="examineAt"    column="examine_at"    />
        <result property="isFinance"    column="is_finance"    />
        <result property="financeExamineAt"    column="finance_examine_at"    />
        <result property="receiveAt"    column="receive_at"    />
        <result property="carAt"    column="car_at"    />
        <result property="companyManageId"    column="company_manage_id"    />
        <result property="warehouseManageId"    column="warehouseManageId"    />
        <result property="financeId"    column="financeId"    />
        <result property="remarks"    column="remarks"    />
        <result property="integral"    column="integral"    />
    </resultMap>

    <sql id="selectMallOrderOrderVo">
        select id, order_no, user_id, post_fee, order_price, order_type, payment, status, create_at, pay_at,
               pay_type, consign_at, enter_at, return_at, complete_at, shipping_mark, shipping_name, shipping_code,
               buyer_msg, is_refund, receiver_name, receiver_phone, receiver_province, receiver_city, receiver_area,
               receiver_address, `year`, `month`, `day`,is_change_address, del_flag
        ,salesman_id,team_id,delivery_type, total_order_sn, shop_id, member_coupon_id
        ,commission_price, order_status, is_pay, is_proof, pay_proof, is_car, car_video, is_examine, examine_at
               , is_finance, finance_examine_at, receive_at, car_at, company_manage_id, warehouse_manage_id, finance_id
        ,remarks,integral
        from mall_order_order
    </sql>

    <select id="orderTimeout" resultType="MallOrderOrder">
        SELECT id FROM mall_order_order
        WHERE `status` = '2'
            AND del_flag = '0'
            AND DATE_FORMAT(create_at, '%Y-%m-%d') &lt;= DATE_SUB(SYSDATE(), INTERVAL 1 DAY)
    </select>

    <select id="orderCancelList" resultType="MallOrderOrder">
        SELECT id FROM mall_order_order
        WHERE `status` = '0'
            AND del_flag = '0'
            AND create_at &lt; DATE_SUB(SYSDATE(), INTERVAL 20 MINUTE)
    </select>

    <select id="selectMallOrderOrderList" parameterType="MallOrderOrder" resultType="MallOrderOrder">
        select moo.id id, moo.order_no orderNo, moo.user_id userId, post_fee postFee, moo.order_price orderPrice, moo.order_type orderType,
                moo.payment payment, moo.status status, moo.create_at createAt, moo.pay_at payAt, moo.pay_type payType, moo.consign_at consignAt,
                moo.enter_at enterAt, moo.return_at returnAt, moo.complete_at completeAt, moo.shipping_mark shippingMark, moo.shipping_name shippingName,
                moo.shipping_code shippingCode, moo.buyer_msg buyerMsg, moo.is_refund isRefund, moo.receiver_name receiverName, moo.receiver_phone receiverPhone,
                moo.receiver_province receiverProvince, moo.receiver_city receiverCity, moo.receiver_area receiverArea,
                moo.receiver_address receiverAddress, moo.`year` `year`, moo.`month` `month`, moo.`day` `day`,moo.is_change_address isChangeAddress,
                moo.del_flag delFlag, mmu.name memberUserName, ms.name salesmanName
        , moo.team_id teamId, moo.salesman_id salesmanId, moo.delivery_type deliveryType,
               moo.total_order_sn totalOrderSn, moo.shop_id shopId, mss.shop_name shopName
        , moo.member_coupon_id memberCouponId
        ,moo.commission_price commissionPrice, moo.order_status orderStatus, moo.is_pay isPay, moo.is_proof isProof, moo.pay_proof payProof, moo.is_car isCar, moo.car_video carVideo, moo.is_examine isExamine, moo.examine_at examineAt
        , moo.is_finance isFinance, moo.finance_examine_at financeExamineAt, moo.receive_at receiveAt, moo.car_at carAt, moo.company_manage_id companyManageId, moo.warehouse_manage_id warehouseManageId, moo.finance_id financeId
        ,mmu.phone phone
        ,moo.remarks,moo.integral
        from mall_order_order moo
        LEFT JOIN mall_member_user mmu ON moo.`user_id` = mmu.`id`
        LEFT JOIN mall_salesman ms ON ms.id = moo.salesman_id
        LEFT JOIN mall_shop_shop mss on mss.shop_id = moo.shop_id
        <where>
            <if test="phone != null  and phone != ''"> and mmu.phone like concat('%', #{phone}, '%')</if>
            <if test="orderNo != null  and orderNo != ''"> and moo.order_no like concat('%', #{orderNo}, '%')</if>
            <if test="memberUserName != null  and memberUserName != ''"> and mmu.name like concat('%', #{memberUserName}, '%')</if>
            <if test="status != null  and status != ''"> and moo.status = #{status}</if>
            <if test="userId != null  and userId != ''"> and moo.user_id = #{userId}</if>
            <if test="createAt != null  and createAt != ''"> and moo.create_at = #{createAt}</if>
            <if test="salesmanId != null"> and moo.salesman_id = #{salesmanId}</if>
            <if test="deliveryType != null"> and moo.delivery_type = #{deliveryType}</if>
            <if test="memberUserId != null"> and mmu.id = #{memberUserId}</if>
            <if test="params.beginCreateAt != null and params.beginCreateAt != '' and params.endCreateAt != null and params.endCreateAt != ''">
              and #{params.beginCreateAt} &lt;= DATE_FORMAT(moo.`create_at`,'%Y-%m-%d')
              and #{params.endCreateAt} &gt;= DATE_FORMAT(moo.`create_at`,'%Y-%m-%d')
            </if>
            <if test="orderType != null"> and moo.order_type = #{orderType}</if>
            <if test="payType != null"> and moo.pay_type = #{payType}</if>
            <if test="shopId != null"> and moo.shop_id = #{shopId}</if>
            <if test="delFlag != null  and delFlag != ''"> and moo.del_flag = #{delFlag}</if>
        </where>
        order by moo.create_at desc
    </select>

    <select id="selectMallOrderOrderById" parameterType="Long" resultType="MallOrderOrder">

        select moo.id id, moo.order_no orderNo, moo.user_id userId, post_fee postFee, moo.order_price orderPrice, moo.order_type orderType,
               moo.payment payment, moo.status status, moo.create_at createAt, moo.pay_at payAt, moo.pay_type payType, moo.consign_at consignAt,
               moo.enter_at enterAt, moo.return_at returnAt, moo.complete_at completeAt, moo.shipping_mark shippingMark, moo.shipping_name shippingName,
               moo.shipping_code shippingCode, moo.buyer_msg buyerMsg, moo.is_refund isRefund, moo.receiver_name receiverName, moo.receiver_phone receiverPhone,
               moo.receiver_province receiverProvince, moo.receiver_city receiverCity, moo.receiver_area receiverArea,
               moo.receiver_address receiverAddress, moo.`year` `year`, moo.`month` `month`, moo.`day` `day`,moo.is_change_address isChangeAddress,
               moo.del_flag delFlag, mmu.name memberUserName, ms.name salesmanName, mmu.phone memberUserPhone
                , moo.team_id teamId, moo.salesman_id salesmanId, moo.delivery_type deliveryType, moo.total_order_sn totalOrderSn, moo.shop_id shopId,
               ms.phone salesmanPhone
                , moo.member_coupon_id memberCouponId,moo.integral
                ,moo.commission_price commissionPrice, moo.order_status orderStatus, moo.is_pay isPay, moo.is_proof isProof, moo.pay_proof payProof, moo.is_car isCar, moo.car_video carVideo, moo.is_examine isExamine, moo.examine_at examineAt
                , moo.is_finance isFinance, moo.finance_examine_at financeExamineAt, moo.receive_at receiveAt, moo.car_at carAt, moo.company_manage_id companyManageId, moo.warehouse_manage_id warehouseManageId, moo.finance_id financeId
                ,IFNULL(convert(moo.remarks, char), '') remarks
        from mall_order_order moo
                 LEFT JOIN mall_member_user mmu ON moo.`user_id` = mmu.`id`
                 LEFT JOIN mall_salesman ms ON ms.id = moo.salesman_id
        where moo.id = #{id}
    </select>
    <select id="queryByOrderSn" parameterType="String" resultMap="MallOrderOrderResult">
        select id, order_no, user_id, post_fee, order_price, order_type, payment, status, create_at, pay_at, pay_type,
        consign_at, enter_at, return_at, complete_at, shipping_mark, shipping_name, shipping_code,
        buyer_msg, is_refund, receiver_name, receiver_phone, receiver_province, receiver_city,
        receiver_area, receiver_address, year, month, day
        ,team_id, salesman_id, delivery_type, total_order_sn, shop_id
                , member_coupon_id
                ,remarks,integral
        from mall_order_order
        where order_no = #{orderNo}
    </select>

    <select id="selectOrderListByTotalOrderSn" parameterType="String" resultMap="MallOrderOrderResult">
        select id, order_no, user_id, post_fee, order_price, order_type, payment, status, create_at, pay_at, pay_type,
               consign_at, enter_at, return_at, complete_at, shipping_mark, shipping_name, shipping_code,
               buyer_msg, is_refund, receiver_name, receiver_phone, receiver_province, receiver_city,
               receiver_area, receiver_address, year, month, day
                ,team_id, salesman_id, delivery_type, total_order_sn, shop_id
                , member_coupon_id
                ,remarks,integral
        from mall_order_order
        where total_order_sn = #{totalOrderSn}
    </select>

    <select id="selectOrderListByShopId" parameterType="String" resultMap="MallOrderOrderResult">
        select id, order_no, user_id, post_fee, order_price, order_type, payment, status, create_at, pay_at, pay_type,
               consign_at, enter_at, return_at, complete_at, shipping_mark, shipping_name, shipping_code,
               buyer_msg, is_refund, receiver_name, receiver_phone, receiver_province, receiver_city,
               receiver_area, receiver_address, year, month, day
                ,team_id, salesman_id, delivery_type, total_order_sn, shop_id
                , member_coupon_id
                ,remarks,integral
        from mall_order_order
        where shop_id is null and del_flag = '0'
    </select>

    <select id="selectOrdersByStatus" resultMap="MallOrderOrderResult">
        select id, order_no, user_id, post_fee, order_price, order_type, payment, status, create_at, pay_at, pay_type,
        consign_at, enter_at, return_at, complete_at, shipping_mark, shipping_name, shipping_code,
        buyer_msg, is_refund, receiver_name, receiver_phone, receiver_province, receiver_city,
        receiver_area, receiver_address, year, month, day
                ,team_id,salesman_id,delivery_type, total_order_sn, shop_id
                , member_coupon_id
                ,remarks,integral
        from mall_order_order
        where status in ${type}
        and user_id = #{userId}
        order by create_at desc
    </select>

    <insert id="insertMallOrderOrder" parameterType="MallOrderOrder" useGeneratedKeys="true" keyProperty="id">
        insert into mall_order_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no,</if>
            <if test="userId != null">user_id,</if>
            <if test="postFee != null">post_fee,</if>
            <if test="orderPrice != null">order_price,</if>
            <if test="payment != null">payment,</if>
            <if test="status != null">status,</if>
            <if test="createAt != null">create_at,</if>
            <if test="payAt != null">pay_at,</if>
            <if test="payType != null">pay_type,</if>
            <if test="consignAt != null">consign_at,</if>
            <if test="enterAt != null">enter_at,</if>
            <if test="returnAt != null">return_at,</if>
            <if test="completeAt != null">complete_at,</if>
            <if test="shippingMark != null">shipping_mark,</if>
            <if test="shippingName != null">shipping_name,</if>
            <if test="shippingCode != null">shipping_code,</if>
            <if test="buyerMsg != null">buyer_msg,</if>
            <if test="isRefund != null">is_refund,</if>
            <if test="receiverName != null">receiver_name,</if>
            <if test="receiverPhone != null">receiver_phone,</if>
            <if test="receiverProvince != null">receiver_province,</if>
            <if test="receiverCity != null">receiver_city,</if>
            <if test="receiverArea != null">receiver_area,</if>
            <if test="receiverAddress != null">receiver_address,</if>
            <if test="year != null">year,</if>
            <if test="month != null">month,</if>
            <if test="day != null">day,</if>
            <if test="delFlag != null">del_flag,</if>
            <if test="isChangeAddress != null">is_change_address,</if>
            <if test="orderType != null">order_type,</if>
            <if test="discountPrice != null">discount_price,</if>
            <if test="salesmanId != null">salesman_id,</if>
            <if test="teamId != null">team_id,</if>
            <if test="deliveryType != null">delivery_type,</if>
            <if test="totalOrderSn != null">total_order_sn,</if>
            <if test="shopId != null">shop_id,</if>
            <if test="memberCouponId != null">member_coupon_id,</if>
            <if test="remarks != null">remarks,</if>
            <if test="integral != null">integral,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">#{orderNo},</if>
            <if test="userId != null">#{userId},</if>
            <if test="postFee != null">#{postFee},</if>
            <if test="orderPrice != null">#{orderPrice},</if>
            <if test="payment != null">#{payment},</if>
            <if test="status != null">#{status},</if>
            <if test="createAt != null">#{createAt},</if>
            <if test="payAt != null">#{payAt},</if>
            <if test="payType != null">#{payType},</if>
            <if test="consignAt != null">#{consignAt},</if>
            <if test="enterAt != null">#{enterAt},</if>
            <if test="returnAt != null">#{returnAt},</if>
            <if test="completeAt != null">#{completeAt},</if>
            <if test="shippingMark != null">#{shippingMark},</if>
            <if test="shippingName != null">#{shippingName},</if>
            <if test="shippingCode != null">#{shippingCode},</if>
            <if test="buyerMsg != null">#{buyerMsg},</if>
            <if test="isRefund != null">#{isRefund},</if>
            <if test="receiverName != null">#{receiverName},</if>
            <if test="receiverPhone != null">#{receiverPhone},</if>
            <if test="receiverProvince != null">#{receiverProvince},</if>
            <if test="receiverCity != null">#{receiverCity},</if>
            <if test="receiverArea != null">#{receiverArea},</if>
            <if test="receiverAddress != null">#{receiverAddress},</if>
            <if test="year != null">#{year},</if>
            <if test="month != null">#{month},</if>
            <if test="day != null">#{day},</if>
            <if test="delFlag != null">#{delFlag},</if>
            <if test="isChangeAddress != null">#{isChangeAddress},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="discountPrice != null">#{discountPrice},</if>
            <if test="salesmanId != null">#{salesmanId},</if>
            <if test="teamId != null">#{teamId},</if>
            <if test="deliveryType != null">#{deliveryType},</if>
            <if test="totalOrderSn != null">#{totalOrderSn},</if>
            <if test="shopId != null">#{shopId},</if>
            <if test="memberCouponId != null">#{memberCouponId},</if>
            <if test="remarks != null">#{remarks},</if>
            <if test="integral != null">#{integral},</if>
         </trim>
    </insert>

    <update id="updateMallOrderOrder" parameterType="MallOrderOrder">
        update mall_order_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="postFee != null">post_fee = #{postFee},</if>
            <if test="orderPrice != null">order_price = #{orderPrice},</if>
            <if test="payment != null">payment = #{payment},</if>
            <if test="status != null">status = #{status},</if>
            <if test="createAt != null">create_at = #{createAt},</if>
            <if test="payAt != null">pay_at = #{payAt},</if>
            <if test="payType != null">pay_type = #{payType},</if>
            <if test="consignAt != null">consign_at = #{consignAt},</if>
            <if test="enterAt != null">enter_at = #{enterAt},</if>
            <if test="returnAt != null">return_at = #{returnAt},</if>
            <if test="completeAt != null">complete_at = #{completeAt},</if>
            <if test="shippingMark != null">shipping_mark = #{shippingMark},</if>
            <if test="shippingName != null">shipping_name = #{shippingName},</if>
            <if test="shippingCode != null">shipping_code = #{shippingCode},</if>
            <if test="buyerMsg != null">buyer_msg = #{buyerMsg},</if>
            <if test="isRefund != null">is_refund = #{isRefund},</if>
            <if test="receiverName != null">receiver_name = #{receiverName},</if>
            <if test="receiverPhone != null">receiver_phone = #{receiverPhone},</if>
            <if test="receiverProvince != null">receiver_province = #{receiverProvince},</if>
            <if test="receiverCity != null">receiver_city = #{receiverCity},</if>
            <if test="receiverArea != null">receiver_area = #{receiverArea},</if>
            <if test="receiverAddress != null">receiver_address = #{receiverAddress},</if>
            <if test="year != null">year = #{year},</if>
            <if test="month != null">month = #{month},</if>
            <if test="day != null">day = #{day},</if>
            <if test="delFlag != null">del_flag = #{delFlag},</if>
            <if test="isChangeAddress != null">is_change_address = #{isChangeAddress},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="discountPrice != null">discount_price = #{discountPrice},</if>
            <if test="salesmanId != null">salesman_id = #{salesmanId},</if>
            <if test="teamId != null">team_id = #{teamId},</if>
            <if test="deliveryType != null">delivery_type = #{deliveryType},</if>
            <if test="totalOrderSn != null">total_order_sn = #{totalOrderSn},</if>
            <if test="shopId != null">shop_id = #{shopId},</if>
            <if test="memberCouponId != null">member_coupon_id = #{memberCouponId},</if>
            <if test="commissionPrice != null">commission_price = #{commissionPrice},</if>
            <if test="orderStatus != null">order_status = #{orderStatus},</if>
            <if test="isPay != null">is_pay = #{isPay},</if>
            <if test="isProof != null">is_proof = #{isProof},</if>
            <if test="payProof != null">pay_proof = #{payProof},</if>
            <if test="isCar != null">is_car = #{isCar},</if>
            <if test="carVideo != null">car_video = #{carVideo},</if>
            <if test="isExamine != null">is_examine = #{isExamine},</if>
            <if test="examineAt != null">examine_at = #{examineAt},</if>
            <if test="isFinance != null">is_finance = #{isFinance},</if>
            <if test="financeExamineAt != null">finance_examine_at = #{financeExamineAt},</if>
            <if test="receiveAt != null">receive_at = #{receiveAt},</if>
            <if test="carAt != null">car_at = #{carAt},</if>
            <if test="companyManageId != null">company_manage_id = #{companyManageId},</if>
            <if test="warehouseManageId != null">warehouse_manage_id = #{warehouseManageId},</if>
            <if test="financeId != null">finance_id = #{financeId},</if>
            <if test="remarks != null and remarks != ''">remarks = #{remarks},</if>
            <if test="integral != null and integral != ''">integral = #{integral},</if>
        </trim>
        where id = #{id}
    </update>
    <update id="taskCancleOrder" parameterType="string">
        update mall_order_order set status = '8'
        where status = '0'
        and create_at &lt;= #{compareTime}
    </update>

    <select id="selectMallOrderByTime" parameterType="String" resultMap="MallOrderOrderResult">
        <include refid="selectMallOrderOrderVo"/>
        where status = '0'
        and create_at &lt;= #{compareTime}
    </select>
    <select id="checkTotleCount" resultType="int">
        select count(1) from mall_order_order
        where status in ('1','2','3','4','5','6','7')
    </select>
    <select id="checkTotlePrice" resultType="java.math.BigDecimal">
        select sum(order_price) from mall_order_order
        where status in ('1','2','3','4','5','6','7')
    </select>
    <select id="checkYearDate" resultType="java.math.BigDecimal">
        select sum(order_price) from mall_order_order
        where status in ('1','2','3','4','5','6','7')
        and YEAR(create_at)=#{year}
    </select>
    <select id="checkYearAndMonth" resultType="java.math.BigDecimal">
        select sum(order_price) from mall_order_order
        where status in ('1','2','3','4','5','6','7')
        <if test="day != null  and day != ''"> and Day(create_at) = #{day}</if>
        <if test="month != null  and month != ''"> and Month(create_at) = #{month}</if>
        <if test="year != null  and year != ''"> and YEAR(create_at) = #{year}</if>
    </select>
    <select id="checkCountYearAndMonth" resultType="int">
        select count(1) from mall_order_order
        where status in ('1','2','3','4','5','6','7')
        <if test="day != null  and day != ''"> and Day(create_at) = #{day}</if>
        <if test="month != null  and month != ''"> and Month(create_at) = #{month}</if>
        <if test="year != null  and year != ''"> and YEAR(create_at) = #{year}</if>
    </select>

    <select id="salesmanOrderList" parameterType="map" resultMap="MallOrderOrderResult">
        select id, order_no, user_id, post_fee, order_price, order_type, payment, status, create_at, pay_at, pay_type,
               consign_at, enter_at, return_at, complete_at, shipping_mark, shipping_name, shipping_code,
               buyer_msg, is_refund, receiver_name, receiver_phone, receiver_province, receiver_city,
               receiver_area, receiver_address, year, month, day
        ,remarks,integral
        from mall_order_order
        <where>
            <if test="type != null and type != ''">and status in ${status}</if>
            and user_id IN
                (SELECT
                id
                FROM
                mall_member_user
                <where>
                    and salesman_id = #{salesmanId}
                    <if test="searchValue != null and searchValue != ''">
                        and (`name` like concat('%',#{searchValue},'%') or `phone` like concat('%',#{searchValue},'%'))
                    </if>
                </where>)
            <if test="timeBegin != null and timeBegin !='' and timeEnd!= null and timeEnd !=''">
                and DATE_FORMAT(`create_at`,'%Y-%m-%d') &gt;= DATE_FORMAT(#{timeBegin},'%Y-%m-%d')
                and DATE_FORMAT(`create_at`,'%Y-%m-%d') &lt;= DATE_FORMAT(#{timeEnd},'%Y-%m-%d')
            </if>
        </where>
        order by create_at desc
    </select>


    <delete id="deleteMallOrderOrderById" parameterType="Long">
        delete from mall_order_order where id = #{id}
    </delete>

    <delete id="deleteMallOrderOrderByIds" parameterType="String">
        delete from mall_order_order where id in
        <foreach item="id" collection="array" open="(" separator="," close=")">
            #{id}
        </foreach>
    </delete>

    <select id="selectByOrderIds" parameterType="integer" resultType="MallOrderOrder">
        <include refid="selectMallOrderOrderVo" />
        where id in
        <foreach item="orderId" collection="orderIds" open="(" separator="," close=")">
            #{orderId}
        </foreach>

    </select>

    <update id="deliveryByOrderIds" parameterType="long">
        update mall_order_order set `status` = 2 where id in
        <foreach item="orderId" collection="orderIds" open="(" separator="," close=")">
            #{orderId}
        </foreach>
    </update>

    <update id="updateMallOrderOrderInfo" parameterType="MallOrderOrder">
        update mall_order_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderNo != null and orderNo != ''">order_no = #{orderNo},</if>
            remarks = #{remarks},
        </trim>
        where id = #{id}
    </update>

    <select id="selectOrdersByreturnStatus" resultMap="MallOrderOrderResult">
        select id,
               order_no,
               user_id,
               post_fee,
               order_price,
               order_type,
               payment,
               status,
               create_at,
               pay_at,
               pay_type,
               consign_at,
               enter_at,
               return_at,
               complete_at,
               shipping_mark,
               shipping_name,
               shipping_code,
               buyer_msg,
               is_refund,
               receiver_name,
               receiver_phone,
               receiver_province,
               receiver_city,
               receiver_area,
               receiver_address,
               year,
               month,
               day
                ,
               team_id,
               salesman_id,
               delivery_type,
               total_order_sn,
               shop_id
                ,
               member_coupon_id
                ,
               remarks,
               integral
        from mall_order_order
        where (status in ${type} or status = '11')
          and user_id = #{userId}
        order by create_at desc
    </select>
    <select id="selectOrdersByUserid" resultMap="MallOrderOrderResult">
        select id,
               order_no,
               user_id,
               post_fee,
               order_price,
               order_type,
               payment,
               status,
               create_at,
               pay_at,
               pay_type,
               consign_at,
               enter_at,
               return_at,
               complete_at,
               shipping_mark,
               shipping_name,
               shipping_code,
               buyer_msg,
               is_refund,
               receiver_name,
               receiver_phone,
               receiver_province,
               receiver_city,
               receiver_area,
               receiver_address,
               year,
               month,
               day
                ,
               team_id,
               salesman_id,
               delivery_type,
               total_order_sn,
               shop_id
                ,
               member_coupon_id
                ,
               remarks,
               integral
        from mall_order_order
        where  user_id = #{userId}
        order by create_at desc
    </select>
</mapper>
