<?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.diaoyun.zion.chinafrica.dao.TbCfPlatformOrderDao">
 
	<resultMap type="com.diaoyun.zion.chinafrica.vo.PlatformOrderVo" id="tbCfPlatformOrderMap">
		<result property="relativeId" column="relative_id"/>
		<result property="orderId" column="order_id"/>
		<result property="pOrderId" column="p_order_id"/>
		<result property="platformName" column="platform_name"/>
		<result property="platformCode" column="platform_code"/>
		<result property="pDeliveryAddress" column="p_delivery_address"/>
		<result property="userName" column="user_name"/>
		<result property="userId" column="user_id"/>
		<result property="createTime" column="create_time"/>
		<result property="realityPay" column="reality_pay"/>
		<result property="pExpressNumber" column="p_express_number"/>
	</resultMap>
	<!--查询代购信息-->
	<select id="queryObject" resultType="com.diaoyun.zion.chinafrica.vo.PlatformOrderVo">
		select
			p.relative_id,
			p.order_id,
			p.p_order_id,
			p.platform_name,
			p.platform_code,
			p.p_delivery_address,
			u.user_name,
			u.user_id,
			p.create_time,
			o.reality_pay,
			p.p_express_number
		from tb_cf_platform_order p
		left join tb_cf_order o on p.order_id=o.order_id
		left join sys_user u on p.user_id=u.user_id
		where p.relative_id =#{relativeId}
	</select>

	<!--<select id="queryList" resultType="com.diaoyun.zion.chinafrica.vo.PlatformOrderVo">
		select
    		`relative_id`,
    		p.order_id,
    		`p_order_id`,
    		`platform_name`,
    		`platform_code`,
    		`p_delivery_address`,
    		`agent_name`,
    		`agent_id`,
    		`create_time`,
    		`real_pay`,
    		`p_express_number`
		from tb_cf_platform_order p left join tb_cf_order o on p.order_id=o.order_id
		WHERE 1=1
		<if test="name != null and name.trim() != ''">
			AND name LIKE concat('%',#{name},'%')
		</if>
        <choose>
            <when test="sidx != null and sidx.trim() != ''">
                order by ${sidx} ${order}
            </when>
			<otherwise>
                order by relative_id desc
			</otherwise>
        </choose>
		<if test="offset != null and limit != null">
			limit #{offset}, #{limit}
		</if>
	</select>-->

	<!--
         <select id="queryTotal" resultType="int">
            select count(*) from tb_cf_platform_order
            WHERE 1=1
            <if test="name != null and name.trim() != ''">
                AND name LIKE concat('%',#{name},'%')
            </if>
        </select>
    -->
	<!--保存代购信息-->
	<insert id="save" parameterType="com.diaoyun.zion.chinafrica.vo.PlatformOrderVo">
		insert into tb_cf_platform_order(
			`relative_id`,
			`order_id`,
			`p_order_id`,
			`platform_name`,
			`platform_code`,
			`p_delivery_address`,
			`user_name`,
			`user_id`,
			`create_time`,
			`reality_pay`,
			`p_express_number`)
		values(
			#{relativeId},
			#{orderId},
			#{pOrderId},
			#{platformName},
			#{platformCode},
			#{pDeliveryAddress},
			#{userName},
			#{userId},
			#{createTime},
			#{realityPay},
			#{pExpressNumber})
	</insert>


	<!--<update id="update" parameterType="com.diaoyun.zion.chinafrica.vo.PlatformOrderVo">
		update tb_cf_platform_order
		<set>
			<if test="orderId != null">`order_id` = #{orderId}, </if>
			<if test="pOrderId != null">`p_order_id` = #{pOrderId}, </if>
			<if test="platformName != null">`platform_name` = #{platformName}, </if>
			<if test="platformCode != null">`platform_code` = #{platformCode}, </if>
			<if test="pDeliveryAddress != null">`p_delivery_address` = #{pDeliveryAddress}, </if>
			<if test="userName != null">`user_name` = #{userName}, </if>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="realityPay != null">`reality_pay` = #{realityPay}, </if>
			<if test="pExpressNumber != null">`p_express_number` = #{pExpressNumber}</if>
		</set>
		where relative_id = #{relativeId}
	</update>-->
	<!--更新代购信息-->
	<update id="updates" parameterType="com.diaoyun.zion.chinafrica.vo.PlatformOrderVo">
		update tb_cf_platform_order
		<set>
			<if test="orderId != null">`order_id` = #{orderId}, </if>
			<if test="pOrderId != null">`p_order_id` = #{pOrderId}, </if>
			<if test="platformName != null">`platform_name` = #{platformName}, </if>
			<if test="platformCode != null">`platform_code` = #{platformCode}, </if>
			<if test="pDeliveryAddress != null">`p_delivery_address` = #{pDeliveryAddress}, </if>
			<if test="userName != null">`user_name` = #{userName}, </if>
			<if test="userId != null">`user_id` = #{userId}, </if>
			<if test="createTime != null">`create_time` = #{createTime}, </if>
			<if test="realityPay != null">`reality_pay` = #{realityPay}, </if>
			<if test="pExpressNumber != null">`p_express_number` = #{pExpressNumber}</if>
		</set>
		where relative_id = #{relativeId}
	</update>

	<!--	<delete id="delete">
            delete from tb_cf_platform_order where relative_id = #{value}
        </delete>

        <delete id="deleteBatch">
            delete from tb_cf_platform_order where relative_id in
            <foreach item="relativeId" collection="array" open="(" separator="," close=")">
                #{relativeId}
            </foreach>
        </delete>-->

	<!--获取订单的代购信息-->
	<select id="getAgentInfo" resultType="com.diaoyun.zion.chinafrica.vo.PlatformOrderVo">
	    select
			p.relative_id,
			p.order_id,
			p.p_order_id,
			p.platform_name,
			p.platform_code,
			p.p_delivery_address,
			u.user_name,
			u.user_id,
			p.create_time,
			o.reality_pay,
			p.p_express_number
		from tb_cf_platform_order p
		left join tb_cf_order o on p.order_id=o.order_id
		left join sys_user u on p.user_id=u.user_id
		where p.order_id=#{order_id};
	</select>

</mapper>