<?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.gree.mall.manager.commonmapper.OrderShareReportMapper">
    <select id="queryReport" resultType="com.gree.mall.manager.bean.order.OrderShareReportBean">
        select od.order_id,
        CONCAT(od.goods_name, '(', od.goods_spec_value, ')') as goodsName,
        od.price,
        od.num,
        od.total_price,
        oi.order_status,
        oi.user_id,
        oi.create_time,
        oi.pay_amount,
        oi.pay_type,
        oi.freight,
        oi.pay_time,
        oi.remark,
        oi.rece_user_name,
        oi.rece_phone,
        CONCAT(oi.province,oi.city,oi.area,oi.street,oi.rece_address,oi.house_no) as address,
        oi.logistics_no,
        ec.name,
        ot.type,
        ot.name as tax_name,
        ot.content,
        ot.tax_no,
        ot.register_address,
        ot.register_phone,
        ot.bank,
        ot.account,
        ot.receiver_email,
        ot.receiver_phone,
        ot.receiver_name,
        ot.receiver_address,
        oi.discount_amount,
        oi.coupon_name,
        oi.transaction_id,
        os.order_share_id,
        os.status as shareStatus,
        os.work_user_name,
        aw.name as websitName,
        od.share_amount,
        od.main_number,
        os.amount,
        os.settle_time,
        eww.position
        from order_detail od
        left join order_info oi on od.order_id = oi.order_id
        LEFT JOIN order_share os on os.order_id = oi.order_id
        LEFT JOIN order_tax ot on ot.order_id = os.order_id
        LEFT JOIN enterprise_wechat_worker eww on eww.wechat_user_id = os.work_user_id
        LEFT JOIN admin_websit aw on eww.main_department = aw.id
        LEFT JOIN express_company ec on ec.code = oi.company_code
        where od.order_id in
        <foreach item="item" index="index" collection="orderIds" open="(" separator=","
                 close=")">
            #{item}
        </foreach>
        order by od.order_id desc

    </select>

    <select id="queryReport2" resultType="com.gree.mall.manager.bean.order.OrderShareReportBean">
        select
        os.order_share_id as orderShareId,
        os.order_id as orderId,
        oi.total_product_amount as totalPrice,
        oi.pay_amount as payAmount,
        oi.freight as freight,
        oi.order_status as orderStatus,
        oi.refund_flag as refundFlag,
        oi.user_id as userId,
        oi.create_time as createTime,
        oi.pay_type as payType,
        oi.pay_time as payTime,
        oi.remark as remark,
        oi.rece_user_name as receUserName,
        oi.rece_phone as recePhone,
        CONCAT(oi.province,oi.city,oi.area,oi.street,oi.rece_address,oi.house_no) as address,
        oi.logistics_no as logisticsNo,
        ec.name as name,
        ot.type as type,
        ot.name as taxName,
        ot.content as content,
        ot.tax_no as taxNo,
        ot.register_address as registerAddress,
        ot.register_phone as registerPhone,
        ot.bank as  bank,
        ot.account as account,
        ot.receiver_email as receiverEmail,
        ot.receiver_phone as receiverPhone,
        ot.receiver_name as receiverName,
        ot.receiver_address as receiverAddress,
        oi.discount_amount as discountAmount,
        oi.coupon_name as couponName,
        oi.transaction_id as transactionId,
        os.status as shareStatus ,
        os.work_user_name as workUserName,
        os.websit_id,
        os.amount as amount,
        os.settle_time as settleTime


        from order_share os
        left join order_info oi  on os.order_id = oi.order_id
        left JOIN order_tax ot on oi.order_id = ot.order_id


        left JOIN express_company ec on ec.code = oi.company_code
        where os.order_share_id in
        <foreach item="item" index="index" collection="orderShareIdList" open="(" separator=","
                 close=")">
            #{item}
        </foreach>
        group by os.order_share_id
        order by os.create_time desc ,ot.create_time desc

    </select>
</mapper>