<?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.fs.store.mapper.FsStoreOrderMapper">

    <resultMap type="FsStoreOrder" id="FsStoreOrderResult">
        <result property="id"    column="id"    />
        <result property="orderCode"    column="order_code"    />
        <result property="extendOrderId"    column="extend_order_id"    />
        <result property="payOrderId"    column="pay_order_id"    />
        <result property="bankOrderId"    column="bank_order_id"    />
        <result property="userId"    column="user_id"    />
        <result property="realName"    column="real_name"    />
        <result property="userPhone"    column="user_phone"    />
        <result property="userAddress"    column="user_address"    />
        <result property="cartId"    column="cart_id"    />
        <result property="freightPrice"    column="freight_price"    />
        <result property="totalNum"    column="total_num"    />
        <result property="totalPrice"    column="total_price"    />
        <result property="totalPostage"    column="total_postage"    />
        <result property="payPrice"    column="pay_price"    />
        <result property="payPostage"    column="pay_postage"    />
        <result property="payDelivery"    column="pay_delivery"    />
        <result property="payMoney"    column="pay_money"    />
        <result property="deductionPrice"    column="deduction_price"    />
        <result property="couponId"    column="coupon_id"    />
        <result property="couponPrice"    column="coupon_price"    />
        <result property="paid"    column="paid"    />
        <result property="payTime"    column="pay_time"    />
        <result property="payType"    column="pay_type"    />
        <result property="createTime"    column="create_time"    />
        <result property="updateTime"    column="update_time"    />
        <result property="status"    column="status"    />
        <result property="refundStatus"    column="refund_status"    />
        <result property="refundReasonWapImg"    column="refund_reason_wap_img"    />
        <result property="refundReasonWapExplain"    column="refund_reason_wap_explain"    />
        <result property="refundReasonTime"    column="refund_reason_time"    />
        <result property="refundReasonWap"    column="refund_reason_wap"    />
        <result property="refundReason"    column="refund_reason"    />
        <result property="refundPrice"    column="refund_price"    />
        <result property="deliverySn"    column="delivery_sn"    />
        <result property="deliveryName"    column="delivery_name"    />
        <result property="deliveryType"    column="delivery_type"    />
        <result property="deliveryId"    column="delivery_id"    />
        <result property="gainIntegral"    column="gain_integral"    />
        <result property="useIntegral"    column="use_integral"    />
        <result property="payIntegral"    column="pay_integral"    />
        <result property="backIntegral"    column="back_integral"    />
        <result property="mark"    column="mark"    />
        <result property="isDel"    column="is_del"    />
        <result property="remark"    column="remark"    />
        <result property="cost"    column="cost"    />
        <result property="verifyCode"    column="verify_code"    />
        <result property="storeId"    column="store_id"    />
        <result property="shippingType"    column="shipping_type"    />
        <result property="isChannel"    column="is_channel"    />
        <result property="isRemind"    column="is_remind"    />
        <result property="isSysDel"    column="is_sys_del"    />
        <result property="isPrescribe"    column="is_prescribe"    />
        <result property="prescribeId"    column="prescribe_id"    />
        <result property="companyId"    column="company_id"    />
        <result property="companyUserId"    column="company_user_id"    />
        <result property="isPackage"    column="is_package"    />
        <result property="packageJson"    column="package_json"    />
        <result property="itemJson"    column="item_json"    />
        <result property="orderType"    column="order_type"    />
        <result property="packageId"    column="package_id"    />
        <result property="finishTime"    column="finish_time"    />
        <result property="deliveryStatus"    column="delivery_status"    />
        <result property="deliveryPayStatus"    column="delivery_pay_status"    />
        <result property="deliveryTime"    column="delivery_time"    />
        <result property="deliveryPayTime"    column="delivery_pay_time"    />
        <result property="deliveryPayMoney"    column="delivery_pay_money"    />
        <result property="tuiMoney"    column="tui_money"    />
        <result property="tuiMoneyStatus"    column="tui_money_status"    />
        <result property="deliveryImportTime"    column="delivery_import_time"    />
        <result property="tuiUserId"    column="tui_user_id"    />
        <result property="tuiUserMoneyStatus"    column="tui_user_money_status"    />
        <result property="orderCreateType"    column="order_create_type"    />
        <result property="storeHouseCode"    column="store_house_code"    />
        <result property="deptId"    column="dept_id"    />
        <result property="isEditMoney"    column="is_edit_money"    />
        <result property="customerId"    column="customer_id"    />
        <result property="isPayRemain"    column="is_pay_remain"    />
        <result property="deliverySendTime"    column="delivery_send_time"    />
        <result property="certificates"    column="certificates"    />
        <result property="scheduleId"    column="schedule_id"    />
        <result property="orderVisit"    column="order_visit"    />
        <result property="serviceFee"    column="service_fee"    />
    </resultMap>

    <sql id="selectFsStoreOrderVo">
        select id, order_code,service_fee, extend_order_id,pay_order_id,bank_order_id, user_id,order_visit, real_name, user_phone, user_address, cart_id, freight_price, total_num, total_price, total_postage, pay_price, pay_postage,pay_delivery,pay_money, deduction_price, coupon_id, coupon_price, paid, pay_time, pay_type, create_time, update_time, status, refund_status, refund_reason_wap_img, refund_reason_wap_explain, refund_reason_time, refund_reason_wap, refund_reason, refund_price, delivery_sn, delivery_name, delivery_type, delivery_id, gain_integral, use_integral, pay_integral, back_integral, mark, is_del, remark, cost, verify_code, store_id, shipping_type, is_channel, is_remind, is_sys_del,is_prescribe,prescribe_id ,company_id,company_user_id,is_package,package_json,item_json,order_type,package_id,finish_time,delivery_status,delivery_pay_status,delivery_time,delivery_pay_time,delivery_pay_money,tui_money,tui_money_status,delivery_import_time,tui_user_id,tui_user_money_status,order_create_type,store_house_code,dept_id,is_edit_money,customer_id,is_pay_remain,delivery_send_time,certificates,schedule_id from fs_store_order
    </sql>

    <select id="selectFsStoreOrderList" parameterType="FsStoreOrder" resultMap="FsStoreOrderResult">
        <include refid="selectFsStoreOrderVo"/>
        <where>
            <if test="orderCode != null  and orderCode != ''"> and order_code = #{orderCode}</if>
            <if test="extendOrderId != null  and extendOrderId != ''"> and extend_order_id = #{extendOrderId}</if>
            <if test="userId != null "> and user_id = #{userId}</if>
            <if test="realName != null  and realName != ''"> and real_name like concat('%', #{realName}, '%')</if>
            <if test="userPhone != null  and userPhone != ''"> and user_phone = #{userPhone}</if>
            <if test="userAddress != null  and userAddress != ''"> and user_address = #{userAddress}</if>
            <if test="cartId != null  and cartId != ''"> and cart_id = #{cartId}</if>
            <if test="freightPrice != null "> and freight_price = #{freightPrice}</if>
            <if test="totalNum != null "> and total_num = #{totalNum}</if>
            <if test="totalPrice != null "> and total_price = #{totalPrice}</if>
            <if test="totalPostage != null "> and total_postage = #{totalPostage}</if>
            <if test="payPrice != null "> and pay_price = #{payPrice}</if>
            <if test="payPostage != null "> and pay_postage = #{payPostage}</if>
            <if test="deductionPrice != null "> and deduction_price = #{deductionPrice}</if>
            <if test="couponId != null "> and coupon_id = #{couponId}</if>
            <if test="couponPrice != null "> and coupon_price = #{couponPrice}</if>
            <if test="paid != null "> and paid = #{paid}</if>
            <if test="payTime != null "> and pay_time = #{payTime}</if>
            <if test="payType != null  and payType != ''"> and pay_type = #{payType}</if>
            <if test="status != null "> and status = #{status}</if>
            <if test="refundStatus != null "> and refund_status = #{refundStatus}</if>
            <if test="refundReasonWapImg != null  and refundReasonWapImg != ''"> and refund_reason_wap_img = #{refundReasonWapImg}</if>
            <if test="refundReasonWapExplain != null  and refundReasonWapExplain != ''"> and refund_reason_wap_explain = #{refundReasonWapExplain}</if>
            <if test="refundReasonTime != null "> and refund_reason_time = #{refundReasonTime}</if>
            <if test="refundReasonWap != null  and refundReasonWap != ''"> and refund_reason_wap = #{refundReasonWap}</if>
            <if test="refundReason != null  and refundReason != ''"> and refund_reason = #{refundReason}</if>
            <if test="refundPrice != null "> and refund_price = #{refundPrice}</if>
            <if test="deliverySn != null  and deliverySn != ''"> and delivery_sn = #{deliverySn}</if>
            <if test="deliveryName != null  and deliveryName != ''"> and delivery_name like concat('%', #{deliveryName}, '%')</if>
            <if test="deliveryType != null  and deliveryType != ''"> and delivery_type = #{deliveryType}</if>
            <if test="deliveryId != null  and deliveryId != ''"> and delivery_id = #{deliveryId}</if>
            <if test="gainIntegral != null "> and gain_integral = #{gainIntegral}</if>
            <if test="useIntegral != null "> and use_integral = #{useIntegral}</if>
            <if test="payIntegral != null "> and pay_integral = #{payIntegral}</if>
            <if test="backIntegral != null "> and back_integral = #{backIntegral}</if>
            <if test="mark != null  and mark != ''"> and mark = #{mark}</if>
            <if test="isDel != null "> and is_del = #{isDel}</if>
            <if test="cost != null "> and cost = #{cost}</if>
            <if test="verifyCode != null  and verifyCode != ''"> and verify_code = #{verifyCode}</if>
            <if test="storeId != null "> and store_id = #{storeId}</if>
            <if test="shippingType != null "> and shipping_type = #{shippingType}</if>
            <if test="isChannel != null "> and is_channel = #{isChannel}</if>
            <if test="isRemind != null "> and is_remind = #{isRemind}</if>
            <if test="isSysDel != null "> and is_sys_del = #{isSysDel}</if>
            <if test="isPrescribe != null "> and is_prescribe = #{isPrescribe}</if>
            <if test="prescribeId != null "> and prescribe_id = #{prescribeId}</if>
            <if test="companyId != null "> and company_id = #{companyId}</if>
            <if test="companyUserId != null "> and company_user_id = #{companyUserId}</if>
            <if test="isPackage != null "> and is_package = #{isPackage}</if>
            <if test="orderType != null "> and order_type = #{orderType}</if>
            <if test="deliveryStatus != null "> and delivery_status = #{deliveryStatus}</if>
            <if test="deliveryPayStatus != null "> and delivery_pay_status = #{deliveryPayStatus}</if>
            <if test="deliveryTime != null "> and delivery_time = #{deliveryTime}</if>
            <if test="deliveryImportTime != null "> and delivery_import_time = #{deliveryImportTime}</if>
        </where>
    </select>

    <select id="selectFsStoreOrderById" parameterType="Long" resultMap="FsStoreOrderResult">
        <include refid="selectFsStoreOrderVo"/>
        where id = #{id}
    </select>

    <insert id="insertFsStoreOrder" parameterType="FsStoreOrder" useGeneratedKeys="true" keyProperty="id">
        insert into fs_store_order
        <trim prefix="(" suffix=")" suffixOverrides=",">
            <if test="orderCode != null and orderCode != ''">order_code,</if>
            <if test="extendOrderId != null">extend_order_id,</if>
            <if test="payOrderId != null">pay_order_id,</if>
            <if test="bankOrderId != null">bank_order_id,</if>
            <if test="userId != null">user_id,</if>
            <if test="realName != null and realName != ''">real_name,</if>
            <if test="userPhone != null and userPhone != ''">user_phone,</if>
            <if test="userAddress != null and userAddress != ''">user_address,</if>
            <if test="cartId != null and cartId != ''">cart_id,</if>
            <if test="freightPrice != null">freight_price,</if>
            <if test="totalNum != null">total_num,</if>
            <if test="totalPrice != null">total_price,</if>
            <if test="totalPostage != null">total_postage,</if>
            <if test="payPrice != null">pay_price,</if>
            <if test="payPostage != null">pay_postage,</if>
            <if test="payDelivery != null">pay_delivery,</if>
            <if test="payMoney != null">pay_money,</if>
            <if test="deductionPrice != null">deduction_price,</if>
            <if test="couponId != null">coupon_id,</if>
            <if test="couponPrice != null">coupon_price,</if>
            <if test="paid != null">paid,</if>
            <if test="payTime != null">pay_time,</if>
            <if test="payType != null and payType != ''">pay_type,</if>
            <if test="createTime != null">create_time,</if>
            <if test="updateTime != null">update_time,</if>
            <if test="status != null">status,</if>
            <if test="refundStatus != null">refund_status,</if>
            <if test="refundReasonWapImg != null">refund_reason_wap_img,</if>
            <if test="refundReasonWapExplain != null">refund_reason_wap_explain,</if>
            <if test="refundReasonTime != null">refund_reason_time,</if>
            <if test="refundReasonWap != null">refund_reason_wap,</if>
            <if test="refundReason != null">refund_reason,</if>
            <if test="refundPrice != null">refund_price,</if>
            <if test="deliverySn != null">delivery_sn,</if>
            <if test="deliveryName != null">delivery_name,</if>
            <if test="deliveryType != null">delivery_type,</if>
            <if test="deliveryId != null">delivery_id,</if>
            <if test="gainIntegral != null">gain_integral,</if>
            <if test="useIntegral != null">use_integral,</if>
            <if test="payIntegral != null">pay_integral,</if>
            <if test="backIntegral != null">back_integral,</if>
            <if test="mark != null and mark != ''">mark,</if>
            <if test="isDel != null">is_del,</if>
            <if test="remark != null">remark,</if>
            <if test="cost != null">cost,</if>
            <if test="verifyCode != null and verifyCode != ''">verify_code,</if>
            <if test="storeId != null">store_id,</if>
            <if test="shippingType != null">shipping_type,</if>
            <if test="isChannel != null">is_channel,</if>
            <if test="isRemind != null">is_remind,</if>
            <if test="isSysDel != null">is_sys_del,</if>
            <if test="isPrescribe != null">is_prescribe,</if>
            <if test="prescribeId != null">prescribe_id,</if>
            <if test="companyId != null">company_id,</if>
            <if test="companyUserId != null">company_user_id,</if>
            <if test="isPackage != null">is_package,</if>
            <if test="packageJson != null">package_json,</if>
            <if test="itemJson != null">item_json,</if>
            <if test="orderType != null">order_type,</if>
            <if test="packageId != null">package_id,</if>
            <if test="finishTime != null">finish_time,</if>
            <if test="deliveryStatus != null">delivery_status,</if>
            <if test="deliveryPayStatus != null">delivery_pay_status,</if>
            <if test="deliveryTime != null">delivery_time,</if>
            <if test="deliveryPayTime != null">delivery_pay_time,</if>
            <if test="deliveryPayMoney != null">delivery_pay_money,</if>
            <if test="tuiMoney != null">tui_money,</if>
            <if test="tuiMoneyStatus != null">tui_money_status,</if>
            <if test="deliveryImportTime != null">delivery_import_time,</if>
            <if test="tuiUserId != null">tui_user_id,</if>
            <if test="tuiUserMoneyStatus != null">tui_user_money_status,</if>
            <if test="orderCreateType != null">order_create_type,</if>
            <if test="storeHouseCode != null">store_house_code,</if>
            <if test="deptId != null">dept_id,</if>
            <if test="isEditMoney != null">is_edit_money,</if>
            <if test="customerId != null">customer_id,</if>
            <if test="isPayRemain != null">is_pay_remain,</if>
            <if test="deliverySendTime != null">delivery_send_time,</if>
            <if test="orderVisit != null">order_visit,</if>
            <if test="serviceFee != null">service_fee,</if>
         </trim>
        <trim prefix="values (" suffix=")" suffixOverrides=",">
            <if test="orderCode != null and orderCode != ''">#{orderCode},</if>
            <if test="extendOrderId != null">#{extendOrderId},</if>
            <if test="payOrderId != null">#{payOrderId},</if>
            <if test="bankOrderId != null">#{bankOrderId},</if>
            <if test="userId != null">#{userId},</if>
            <if test="realName != null and realName != ''">#{realName},</if>
            <if test="userPhone != null and userPhone != ''">#{userPhone},</if>
            <if test="userAddress != null and userAddress != ''">#{userAddress},</if>
            <if test="cartId != null and cartId != ''">#{cartId},</if>
            <if test="freightPrice != null">#{freightPrice},</if>
            <if test="totalNum != null">#{totalNum},</if>
            <if test="totalPrice != null">#{totalPrice},</if>
            <if test="totalPostage != null">#{totalPostage},</if>
            <if test="payPrice != null">#{payPrice},</if>
            <if test="payPostage != null">#{payPostage},</if>
            <if test="payDelivery != null">#{payDelivery},</if>
            <if test="payMoney != null">#{payMoney},</if>
            <if test="deductionPrice != null">#{deductionPrice},</if>
            <if test="couponId != null">#{couponId},</if>
            <if test="couponPrice != null">#{couponPrice},</if>
            <if test="paid != null">#{paid},</if>
            <if test="payTime != null">#{payTime},</if>
            <if test="payType != null and payType != ''">#{payType},</if>
            <if test="createTime != null">#{createTime},</if>
            <if test="updateTime != null">#{updateTime},</if>
            <if test="status != null">#{status},</if>
            <if test="refundStatus != null">#{refundStatus},</if>
            <if test="refundReasonWapImg != null">#{refundReasonWapImg},</if>
            <if test="refundReasonWapExplain != null">#{refundReasonWapExplain},</if>
            <if test="refundReasonTime != null">#{refundReasonTime},</if>
            <if test="refundReasonWap != null">#{refundReasonWap},</if>
            <if test="refundReason != null">#{refundReason},</if>
            <if test="refundPrice != null">#{refundPrice},</if>
            <if test="deliverySn != null">#{deliverySn},</if>
            <if test="deliveryName != null">#{deliveryName},</if>
            <if test="deliveryType != null">#{deliveryType},</if>
            <if test="deliveryId != null">#{deliveryId},</if>
            <if test="gainIntegral != null">#{gainIntegral},</if>
            <if test="useIntegral != null">#{useIntegral},</if>
            <if test="payIntegral != null">#{payIntegral},</if>
            <if test="backIntegral != null">#{backIntegral},</if>
            <if test="mark != null and mark != ''">#{mark},</if>
            <if test="isDel != null">#{isDel},</if>
            <if test="remark != null">#{remark},</if>
            <if test="cost != null">#{cost},</if>
            <if test="verifyCode != null and verifyCode != ''">#{verifyCode},</if>
            <if test="storeId != null">#{storeId},</if>
            <if test="shippingType != null">#{shippingType},</if>
            <if test="isChannel != null">#{isChannel},</if>
            <if test="isRemind != null">#{isRemind},</if>
            <if test="isSysDel != null">#{isSysDel},</if>
            <if test="isPrescribe != null">#{isPrescribe},</if>
            <if test="prescribeId != null">#{prescribeId},</if>
            <if test="companyId != null">#{companyId},</if>
            <if test="companyUserId != null">#{companyUserId},</if>
            <if test="isPackage != null">#{isPackage},</if>
            <if test="packageJson != null">#{packageJson},</if>
            <if test="orderType != null">#{orderType},</if>
            <if test="packageId != null">#{packageId},</if>
            <if test="finishTime != null">#{finishTime},</if>
            <if test="deliveryStatus != null">#{deliveryStatus},</if>
            <if test="deliveryPayStatus != null">#{deliveryPayStatus},</if>
            <if test="deliveryTime != null">#{deliveryTime},</if>
            <if test="deliveryPayTime != null">#{deliveryPayTime},</if>
            <if test="deliveryPayMoney != null">#{deliveryPayMoney},</if>
            <if test="tuiMoney != null">#{tuiMoney},</if>
            <if test="tuiMoneyStatus != null">#{tuiMoneyStatus},</if>
            <if test="deliveryImportTime != null">#{deliveryImportTime},</if>
            <if test="tuiUserId != null">#{tuiUserId},</if>
            <if test="tuiUserMoneyStatus != null">#{tuiUserMoneyStatus},</if>
            <if test="orderCreateType != null">#{orderCreateType},</if>
            <if test="storeHouseCode != null">#{storeHouseCode},</if>
            <if test="deptId != null">#{deptId},</if>
            <if test="isEditMoney != null">#{isEditMoney},</if>
            <if test="customerId != null">#{customerId},</if>
            <if test="isPayRemain != null">#{isPayRemain},</if>
            <if test="deliverySendTime != null">#{deliverySendTime},</if>
            <if test="orderVisit != null">#{orderVisit},</if>
            <if test="serviceFee != null">#{serviceFee},</if>
         </trim>
    </insert>

    <update id="updateFsStoreOrder" parameterType="FsStoreOrder">
        update fs_store_order
        <trim prefix="SET" suffixOverrides=",">
            <if test="orderCode != null and orderCode != ''">order_code = #{orderCode},</if>
            <if test="extendOrderId != null">extend_order_id = #{extendOrderId},</if>
            <if test="payOrderId != null">pay_order_id = #{payOrderId},</if>
            <if test="bankOrderId != null">bank_order_id = #{bankOrderId},</if>
            <if test="userId != null">user_id = #{userId},</if>
            <if test="realName != null and realName != ''">real_name = #{realName},</if>
            <if test="userPhone != null and userPhone != ''">user_phone = #{userPhone},</if>
            <if test="userAddress != null and userAddress != ''">user_address = #{userAddress},</if>
            <if test="cartId != null and cartId != ''">cart_id = #{cartId},</if>
            <if test="freightPrice != null">freight_price = #{freightPrice},</if>
            <if test="totalNum != null">total_num = #{totalNum},</if>
            <if test="totalPrice != null">total_price = #{totalPrice},</if>
            <if test="totalPostage != null">total_postage = #{totalPostage},</if>
            <if test="payPrice != null">pay_price = #{payPrice},</if>
            <if test="payPostage != null">pay_postage = #{payPostage},</if>
            <if test="payDelivery != null">pay_delivery = #{payDelivery},</if>
            <if test="payMoney != null">pay_money = #{payMoney},</if>
            <if test="deductionPrice != null">deduction_price = #{deductionPrice},</if>
            <if test="couponId != null">coupon_id = #{couponId},</if>
            <if test="couponPrice != null">coupon_price = #{couponPrice},</if>
            <if test="paid != null">paid = #{paid},</if>
            <if test="payTime != null">pay_time = #{payTime},</if>
            <if test="payType != null and payType != ''">pay_type = #{payType},</if>
            <if test="createTime != null">create_time = #{createTime},</if>
            <if test="updateTime != null">update_time = #{updateTime},</if>
            <if test="status != null">status = #{status},</if>
            <if test="refundStatus != null">refund_status = #{refundStatus},</if>
            <if test="refundReasonWapImg != null">refund_reason_wap_img = #{refundReasonWapImg},</if>
            <if test="refundReasonWapExplain != null">refund_reason_wap_explain = #{refundReasonWapExplain},</if>
            <if test="refundReasonTime != null">refund_reason_time = #{refundReasonTime},</if>
            <if test="refundReasonWap != null">refund_reason_wap = #{refundReasonWap},</if>
            <if test="refundReason != null">refund_reason = #{refundReason},</if>
            <if test="refundPrice != null">refund_price = #{refundPrice},</if>
            <if test="deliverySn != null">delivery_sn = #{deliverySn},</if>
            <if test="deliveryName != null">delivery_name = #{deliveryName},</if>
            <if test="deliveryType != null">delivery_type = #{deliveryType},</if>
            <if test="deliveryId != null">delivery_id = #{deliveryId},</if>
            <if test="gainIntegral != null">gain_integral = #{gainIntegral},</if>
            <if test="useIntegral != null">use_integral = #{useIntegral},</if>
            <if test="payIntegral != null">pay_integral = #{payIntegral},</if>
            <if test="backIntegral != null">back_integral = #{backIntegral},</if>
            <if test="mark != null and mark != ''">mark = #{mark},</if>
            <if test="isDel != null">is_del = #{isDel},</if>
            <if test="remark != null">remark = #{remark},</if>
            <if test="cost != null">cost = #{cost},</if>
            <if test="verifyCode != null and verifyCode != ''">verify_code = #{verifyCode},</if>
            <if test="storeId != null">store_id = #{storeId},</if>
            <if test="shippingType != null">shipping_type = #{shippingType},</if>
            <if test="isChannel != null">is_channel = #{isChannel},</if>
            <if test="isRemind != null">is_remind = #{isRemind},</if>
            <if test="isSysDel != null">is_sys_del = #{isSysDel},</if>
            <if test="isPrescribe != null">is_prescribe = #{isPrescribe},</if>
            <if test="prescribeId != null">prescribe_id = #{prescribeId},</if>
            <if test="companyId != null">company_id = #{companyId},</if>
            <if test="companyUserId != null">company_user_id = #{companyUserId},</if>
            <if test="isPackage != null">is_package = #{isPackage},</if>
            <if test="packageJson != null">package_json = #{packageJson},</if>
            <if test="itemJson != null">item_json = #{itemJson},</if>
            <if test="orderType != null">order_type = #{orderType},</if>
            <if test="packageId != null">package_id = #{packageId},</if>
            <if test="finishTime != null">finish_time = #{finishTime},</if>
            <if test="deliveryStatus != null">delivery_status = #{deliveryStatus},</if>
            <if test="deliveryPayStatus != null">delivery_pay_status = #{deliveryPayStatus},</if>
            <if test="deliveryTime != null">delivery_time = #{deliveryTime},</if>
            <if test="deliveryPayTime != null">delivery_pay_time = #{deliveryPayTime},</if>
            <if test="deliveryPayMoney != null">delivery_pay_money = #{deliveryPayMoney},</if>
            <if test="tuiMoney != null">tui_money = #{tuiMoney},</if>
            <if test="tuiMoneyStatus != null">tui_money_status = #{tuiMoneyStatus},</if>
            <if test="deliveryImportTime != null">delivery_import_time = #{deliveryImportTime},</if>
            <if test="tuiUserId != null">tui_user_id = #{tuiUserId},</if>
            <if test="tuiUserMoneyStatus != null">tui_user_money_status = #{tuiUserMoneyStatus},</if>
            <if test="orderCreateType != null">order_create_type = #{orderCreateType},</if>
            <if test="storeHouseCode != null">store_house_code = #{storeHouseCode},</if>
            <if test="deptId != null">dept_id = #{deptId},</if>
            <if test="isEditMoney != null">is_edit_money = #{isEditMoney},</if>
            <if test="customerId != null">customer_id = #{customerId},</if>
            <if test="isPayRemain != null">is_pay_remain = #{isPayRemain},</if>
            <if test="deliverySendTime != null">delivery_send_time = #{deliverySendTime},</if>
            <if test="scheduleId != null">schedule_id = #{scheduleId},</if>
            <if test="orderVisit != null">order_visit = #{orderVisit},</if>
            <if test="serviceFee != null">service_fee = #{serviceFee},</if>
        </trim>
        where id = #{id}
    </update>

    <delete id="deleteFsStoreOrderById" parameterType="Long">
        delete from fs_store_order where id = #{id}
    </delete>

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

    <select id="selectFsStoreOrderCounts" resultType="com.alibaba.fastjson.JSONObject">
        SELECT  count(t.id ) AS orderCount,  t.type, sum(IFNULL(t.pay_price,0)) as payPrice
        FROM
        (
        SELECT DATE_FORMAT( o.create_time, #{sqlDateFormat} ) AS type,  o.id,o.pay_price
        FROM
        fs_store_order  AS o
        WHERE
        o.status  &gt; 0 and
        (DATE_FORMAT(o.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
        <if test="userIds != null and userIds.length>0">
            AND o.company_user_id IN
            <foreach item="item" collection="userIds" open="(" separator="," close=")">
                #{item}
            </foreach>
        </if>
        <if test="companyId != null  ">
            AND o.company_id = #{companyId}
        </if>

        ) t
        GROUP BY t.type
    </select>
    <select id="selectTuiMoneyCounts" resultType="com.alibaba.fastjson.JSONObject">
        SELECT  count(1) as tuiMoneyCount ,sum(IFNULL(t.tuiMoney,0)) as tuiMoney,  t.type
        FROM
        (
        SELECT DATE_FORMAT( s.create_time, #{sqlDateFormat} ) AS type,s.tui_money as tuiMoney
        FROM
        fs_store_order  AS s
        WHERE
        (DATE_FORMAT(s.create_time,#{sqlDateFormat}) between #{beginTime} and #{finalTime})
        AND s.status>0
        AND s.company_user_id IN
        <foreach item="item" collection="userIds" open="(" separator="," close=")">
            #{item}
        </foreach>
        ) t
        GROUP BY t.type
    </select>
    <select id="selectDeliverPendingData" resultType="com.fs.store.domain.FsStoreOrder">
        select * from fs_store_order where extend_order_id is not null and `status`=1
    </select>
    <select id="selectFsOutDateOrder" resultType="com.fs.store.domain.FsStoreOrder">
        SELECT id
        FROM fs_store_order
        WHERE status = 0
        AND create_time &lt; DATE_SUB(NOW(), INTERVAL 1800 MINUTE);
    </select>
    <select id="selectFsStoreOrderListVO" resultType="com.fs.store.vo.FsStoreOrderVO">
        select o.`id`,
        o.`order_code`,
        o.`extend_order_id`,
        o.`pay_order_id`,
        o.`bank_order_id`,
        o.`user_id`,
        o.`real_name`,
        o.`user_phone`,
        o.`user_address`,
        o.`cart_id`,
        o.`freight_price`,
        o.`total_num`,
        o.`total_price`,
        o.`total_postage`,
        o.`pay_price`,
        o.`pay_postage`,
        o.`pay_delivery`,
        o.`pay_money`,
        o.`deduction_price`,
        o.`coupon_id`,
        o.`coupon_price`,
        o.`paid`,
        o.`pay_time`,
        o.`pay_type`,
        o.`create_time`,
        o.`update_time`,
        o.`status`,
        o.`refund_status`,
        o.`refund_reason_wap_img`,
        o.`refund_reason_wap_explain`,
        o.`refund_reason_time`,
        o.`refund_reason_wap`,
        o.`refund_reason`,
        o.`refund_price`,
        deliver.deliver_sn as `delivery_sn`,
        deliver.deliver_name as `delivery_name`,
        deliver.status as `delivery_status`,
        o.`delivery_type`,
        deliver.deliver_id as `delivery_id`,
        o.`gain_integral`,
        o.`use_integral`,
        o.`pay_integral`,
        o.`back_integral`,
        o.`mark`,
        o.`is_del`,
        o.`remark`,
        o.`cost`,
        o.`verify_code`,
        o.`store_id`,
        o.`shipping_type`,
        o.`is_channel`,
        o.`is_remind`,
        o.`is_sys_del`,
        o.`is_prescribe`,
        o.`prescribe_id`,
        o.`company_id`,
        o.`company_user_id`,
        o.`is_package`,
        o.`package_json`,
        o.`order_type`,
        o.`package_id`,
        o.`finish_time`,
        o.`delivery_status`,
        o.`delivery_pay_status`,
        o.`delivery_time`,
        o.`delivery_pay_time`,
        o.`delivery_pay_money`,
        o.`tui_money`,
        o.`tui_money_status`,
        o.`delivery_import_time`,
        o.`tui_user_id`,
        o.`tui_user_money_status`,
        o.`order_create_type`,
        o.`store_house_code`,
        o.`dept_id`,
        o.`is_edit_money`,
        o.`customer_id`,
        o.`is_pay_remain`,
        o.`delivery_send_time`,
        o.`certificates`,
        o.`upload_time`,
        o.`schedule_id`,
        o.`item_json`,
        o.`order_visit`,
        o.`service_fee`
               ,u.phone,u.register_code,u.register_date,
               u.source, c.company_name ,
               cu.nick_name as company_user_nick_name ,
               cu.phonenumber as company_usere_phonenumber
                from fs_store_order o
                left join fs_user u
                    on o.user_id=u.user_id
                left join company c
                    on c.company_id=o.company_id
                left join company_user cu
                    on cu.user_id=o.company_user_id
                left join fs_store_delivers deliver
                    on o.order_code=deliver.order_code
        <if test = 'maps.productName != null and  maps.productName !=  "" '>
            left join fs_store_order_item oi on o.id = oi.order_id
            left join fs_store_product fsp on fsp.product_id = oi.product_id
        </if>
        <where>
            <if test = 'maps.orderCode != null and  maps.orderCode !=""    '>
                and o.order_code like CONCAT(#{maps.orderCode},'%')
            </if>
            <if test = 'maps.isPayRemain != null      '>
                and o.is_pay_remain =#{maps.isPayRemain}
            </if>
            <if test = 'maps.userId != null      '>
                and o.user_id =#{maps.userId}
            </if>
            <if test = 'maps.deliveryId != null  and  maps.deliveryId !=""    '>
                and deliver.deliver_id =#{maps.deliveryId}
            </if>
            <if test = 'maps.nickname != null and  maps.nickname !=""     '>
                and u.nickname like CONCAT(#{maps.nickname},'%')
            </if>
            <if test = 'maps.realName != null and  maps.realName !=""     '>
                and o.real_name like CONCAT(#{maps.realName},'%')
            </if>
            <if test = 'maps.phone != null and  maps.phone !=""     '>
                and u.phone like CONCAT(#{maps.phone},'%')
            </if>
            <if test = 'maps.userPhone != null and  maps.userPhone !=""     '>
                and o.user_phone like CONCAT(#{maps.userPhone},'%')
            </if>
            <if test = 'maps.status != null    '>
                and o.status =#{maps.status}
            </if>
            <if test = 'maps.isUpload != null and maps.isUpload == 0    '>
                and o.certificates is null
            </if>
            <if test = 'maps.isUpload != null and maps.isUpload == 1    '>
                and o.certificates is not null
            </if>
            <if test = 'maps.deliveryStatus != null    '>
                and deliver.status =#{maps.deliveryStatus}
            </if>
            <if test = 'maps.deliveryPayStatus != null    '>
                and o.delivery_pay_status =#{maps.deliveryPayStatus}
            </if>
            <if test = 'maps.companyId != null    '>
                and o.company_id =#{maps.companyId}
            </if>
            <if test = 'maps.isHealth != null and maps.isHealth !=  ""  '>
                and o.company_id is null
            </if>
            <if test = 'maps.notHealth != null '>
                and o.company_id is not null
            </if>
            <if test = 'maps.companyUserId != null    '>
                and o.company_user_id =#{maps.companyUserId}
            </if>
            <if test = 'maps.companyUserNickName != null and  maps.companyUserNickName !=  "" '>
                and cu.nick_name like concat(#{maps.companyUserNickName}, '%')
            </if>
            <if test = 'maps.productName != null and  maps.productName !=  "" '>
                and fsp.product_name like concat(#{maps.productName}, '%')
            </if>
            <if test = 'maps.orderType != null    '>
                and o.order_type =#{maps.orderType}
            </if>
            <if test = 'maps.payType != null    '>
                and o.pay_type =#{maps.payType}
            </if>
            <if test = 'maps.scheduleId != null    '>
                and o.schedule_id =#{maps.scheduleId}
            </if>
            <if test = 'maps.createTimeList != null    '>
                AND date_format(o.create_time,'%y%m%d') &gt;= date_format(#{maps.createTimeList[0]},'%y%m%d')
                AND date_format(o.create_time,'%y%m%d') &lt;= date_format(#{maps.createTimeList[1]},'%y%m%d')
            </if>

            <if test = 'maps.deliverySendTimeList != null    '>
                AND date_format(o.delivery_send_time,'%y%m%d') &gt;= date_format(#{maps.deliverySendTimeList[0]},'%y%m%d')
                AND date_format(o.delivery_send_time,'%y%m%d') &lt;= date_format(#{maps.deliverySendTimeList[1]},'%y%m%d')
            </if>

            <if test = 'maps.payTimeList != null    '>
                AND date_format(o.pay_time,'%y%m%d') &gt;= date_format(#{maps.payTimeList[0]},'%y%m%d')
                AND date_format(o.pay_time,'%y%m%d') &lt;= date_format(#{maps.payTimeList[1]},'%y%m%d')
            </if>
            <if test = 'maps.deliveryImportTimeList != null    '>
                AND date_format(o.delivery_import_time,'%y%m%d') &gt;= date_format(#{maps.deliveryImportTimeList[0]},'%y%m%d')
                AND date_format(o.delivery_import_time,'%y%m%d') &lt;= date_format(#{maps.deliveryImportTimeList[1]},'%y%m%d')
            </if>
            <if test = 'maps.deptId != null    '>
                AND (o.dept_id = #{maps.deptId} OR o.dept_id IN ( SELECT t.dept_id FROM company_dept t WHERE find_in_set(#{maps.deptId}, ancestors) ))
            </if>
            ${maps.params.dataScope}
        </where>
        <if test = 'maps.productName != null and  maps.productName != "" '>
            group by o.id
        </if>
        order by o.id desc
    </select>

</mapper>
