admin
2018-12-26 f4b0bb5dfda8f21409b9eb0b2ee6e436c87475e3
fanli/src/main/java/com/yeshi/fanli/mapping/order/CommonOrderMapper.xml
@@ -71,7 +71,7 @@
   </resultMap>
   <sql id="Base_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_create_time,co_update_time
   <sql id="Base_Column_List">co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,cog_create_time,cog_update_time
   </sql>
   <select id="selectByPrimaryKey" resultMap="BaseResultMap"
      parameterType="java.lang.Long">
@@ -79,11 +79,16 @@
      <include refid="Base_Column_List" />
      from yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}
   </select>
   <select id="countByOrderNOAndOrderType" resultType="java.lang.Integer">
      select
      count(co_id) from yeshi_ec_common_order where co_order_no=#{orderNO}
      and co_source_type=#{orderType}
   </select>
   <delete id="deleteByPrimaryKey" parameterType="java.lang.Long">delete from
      yeshi_ec_common_order where co_id = #{id,jdbcType=BIGINT}</delete>
   <insert id="insert" parameterType="com.yeshi.fanli.entity.order.CommonOrder"
      useGeneratedKeys="true" keyProperty="id">insert into yeshi_ec_common_order
      (co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,co_create_time,co_update_time)
      (co_id,co_uid,co_order_no,co_source_type,co_source_position,co_order_goods_id,co_count,co_state,co_estimate,co_eIncome,co_payment,co_settlement,co_third_create_time,co_settle_time,cog_create_time,cog_update_time)
      values
      (#{id,jdbcType=BIGINT},#{userInfo.id,jdbcType=BIGINT},#{orderNo,jdbcType=VARCHAR},#{sourceType,jdbcType=INTEGER},#{sourcePosition,jdbcType=VARCHAR},#{commonOrderGoods.id,jdbcType=BIGINT},#{count,jdbcType=INTEGER},#{state,jdbcType=INTEGER},#{estimate,jdbcType=DECIMAL},#{eIncome,jdbcType=DECIMAL},#{payment,jdbcType=DECIMAL},#{settlement,jdbcType=DECIMAL},#{thirdCreateTime,jdbcType=TIMESTAMP},#{settleTime,jdbcType=TIMESTAMP},#{createTime,jdbcType=TIMESTAMP},#{updateTime,jdbcType=TIMESTAMP})
   </insert>
@@ -105,8 +110,8 @@
         <if test="settlement != null">co_settlement,</if>
         <if test="thirdCreateTime != null">co_third_create_time,</if>
         <if test="settleTime != null">co_settle_time,</if>
         <if test="createTime != null">co_create_time,</if>
         <if test="updateTime != null">co_update_time,</if>
         <if test="createTime != null">cog_create_time,</if>
         <if test="updateTime != null">cog_update_time,</if>
      </trim>
      values
      <trim prefix="(" suffix=")" suffixOverrides=",">
@@ -142,8 +147,8 @@
      #{payment,jdbcType=DECIMAL},co_settlement =
      #{settlement,jdbcType=DECIMAL},co_third_create_time =
      #{thirdCreateTime,jdbcType=TIMESTAMP},co_settle_time =
      #{settleTime,jdbcType=TIMESTAMP},co_create_time =
      #{createTime,jdbcType=TIMESTAMP},co_update_time =
      #{settleTime,jdbcType=TIMESTAMP},cog_create_time =
      #{createTime,jdbcType=TIMESTAMP},cog_update_time =
      #{updateTime,jdbcType=TIMESTAMP} where co_id = #{id,jdbcType=BIGINT}
   </update>
   <update id="updateByPrimaryKeySelective" parameterType="com.yeshi.fanli.entity.order.CommonOrder">
@@ -165,8 +170,8 @@
         <if test="thirdCreateTime != null">co_third_create_time=#{thirdCreateTime,jdbcType=TIMESTAMP},
         </if>
         <if test="settleTime != null">co_settle_time=#{settleTime,jdbcType=TIMESTAMP},</if>
         <if test="createTime != null">co_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
         <if test="updateTime != null">co_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
         <if test="createTime != null">cog_create_time=#{createTime,jdbcType=TIMESTAMP},</if>
         <if test="updateTime != null">cog_update_time=#{updateTime,jdbcType=TIMESTAMP},</if>
      </set>
      where co_id = #{id,jdbcType=BIGINT}
   </update>
@@ -181,8 +186,14 @@
      LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = #{uid}
      <if test="state != null">
         AND th.hb_state = #{state}
      <if test="state != null and state == 1">  <!-- 未到账 -->
         AND (th.hb_state = 1 or th.hb_state = 2)
      </if>
      <if test="state != null and state == 2"> <!-- 已到账 -->
         AND th.hb_state = 3
      </if>
      <if test="state != null and state == 3">  <!-- 红包已失效 -->
         AND th.hb_state =4
      </if>
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
@@ -196,22 +207,39 @@
      <if test="orderNo != null">
         AND tc.co_order_no = #{orderNo}
      </if>
      <if test="orderState != null and orderState ==  1">
         AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
      </if>
      <if test="orderState != null and orderState ==  2">
         AND tc.co_state = 3 <!-- 维权订单 -->
      </if>
      <if test="orderState != null and orderState ==  3">
         AND tc.co_state = 4 <!-- 失效订单 -->
      </if>
      <if test="startTime != null">
         AND <![CDATA[tc.co_create_time >= #{startTime}]]>
      </if>
      <if test="endTime != null">
         AND <![CDATA[tc.co_create_time < #{endTime}]]>
      </if>
      GROUP BY tc.`co_order_no`
      <if test="day != null and day == 1"> <!-- 今天 -->
         AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      <if test="day != null and day == 2">  <!-- 昨天 -->
         AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
      </if>
      <if test="day != null and day == 3">  <!-- 本月 -->
         AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
         DATE_FORMAT(CURDATE(),'%Y%m')
      </if>
      <if test="day != null and day == 4">  <!-- 上月 -->
         AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
         DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
      </if>
      GROUP BY tc.`co_order_no`,tc.co_source_type
      ORDER BY tc.co_create_time DESC
      LIMIT #{start},#{count}
      LIMIT ${start},${count}
   </select>
   <select id="countByOrderNOAndOrderType" resultType="java.lang.Integer">
      select count(co_id) from yeshi_ec_common_order where co_order_no=#{orderNO} and co_source_type=#{orderType}
   </select>
   <select id="countGroupOrderNoByUid" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0)
@@ -220,8 +248,14 @@
      LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = #{uid}
      <if test="state != null">
         AND th.hb_state = #{state}
      <if test="state != null and state == 1">  <!-- 未到账 -->
         AND (th.hb_state = 1 or th.hb_state = 2)
      </if>
      <if test="state != null and state == 2">  <!-- 已到账 -->
         AND th.hb_state = 3
      </if>
      <if test="state != null and state == 3"> <!-- 红包已失效 -->
         AND th.hb_state =4
      </if>
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
@@ -232,6 +266,17 @@
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="orderState != null and orderState = 1">
         AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
      </if>
      <if test="orderState != null and orderState = 2">
         AND tc.co_state = 3 <!-- 维权订单 -->
      </if>
      <if test="orderState != null and orderState = 3">
         AND tc.co_state = 4 <!-- 失效订单 -->
      </if>
      <if test="orderNo != null">
         AND tc.co_order_no = #{orderNo}
      </if>
@@ -240,6 +285,20 @@
      </if>
      <if test="endTime != null">
         AND <![CDATA[tc.co_create_time < #{endTime}]]>
      </if>
      <if test="day != null and day == 1"> <!-- 今天 -->
         AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      <if test="day != null and day == 2">  <!-- 昨天 -->
         AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
      </if>
      <if test="day != null and day == 3">  <!-- 本月 -->
         AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
         DATE_FORMAT(CURDATE(),'%Y%m')
      </if>
      <if test="day != null and day == 4">  <!-- 上月 -->
         AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
         DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
      </if>
   </select>
@@ -249,7 +308,7 @@
      totalSettlement,COALESCE(SUM(tc.`co_count`),0)AS
      totalCount,tc.`co_source_type`,tc.`co_order_no`,tg.*
      FROM yeshi_ec_common_order_goods tg
      LEFT JOIN yeshi_ec_common_order tc ON tc.`co_order_goods_id` = tg.`co_id`
      LEFT JOIN yeshi_ec_common_order tc ON tc.`co_order_goods_id` = tg.`cog_id`
      WHERE
      <foreach collection="list" item="item" separator=" OR ">
         (tc.`co_source_type` = #{item.sourceType,jdbcType=INTEGER} AND
@@ -311,36 +370,6 @@
      )A
   </select>
   <select id="countOrder" resultType="java.lang.Long">
      SELECT IFNULL(COUNT(DISTINCT tc.`co_order_no`,tc.`co_source_type`),0)
      FROM yeshi_ec_common_order tc
      LEFT JOIN yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
      LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE 1=1
      <if test="uid != null">
         AND th.`hb_uid` = ${uid}
      </if>
      <if test="isToday == 1">
         AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
   </select>
   <select id="countOrderMoney" resultType="java.lang.Long">
      SELECT IFNULL(SUM(th.`hb_money`),0)AS totalmoney FROM
      yeshi_ec_common_order tc
      LEFT JOIN yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
      LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = ${uid}
      AND <![CDATA[tc.`co_state` <> 4]]>
      <if test="isToday == 1">
         AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      GROUP BY tc.`co_order_no`,tc.`co_source_type`
   </select>
   <select id="countByUidAndOrderState" resultType="java.util.HashMap">
      SELECT SUM(valid)AS totalValid, SUM(proces)AS totalProces
      ,SUM(Invalid)AS totalInvite
@@ -353,8 +382,14 @@
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = #{uid} AND
      (tc.`co_state` = 1 OR tc.`co_state` = 2)
      <if test="type != null">
         AND th.hb_type = #{type}
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
      </if>
      <if test="type != null and type == 2"> <!-- 分享订单 -->
         AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
      </if>
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="startTime != null">
         AND <![CDATA[tc.co_create_time >= #{startTime}]]>
@@ -374,8 +409,14 @@
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = #{uid} AND
      tc.`co_state` =3
      <if test="type != null">
         AND th.hb_type = #{type}
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
      </if>
      <if test="type != null and type == 2"> <!-- 分享订单 -->
         AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
      </if>
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="startTime != null">
         AND <![CDATA[tc.co_create_time >= #{startTime}]]>
@@ -395,8 +436,14 @@
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid`= #{uid} AND
      tc.`co_state` = 4
      <if test="type != null">
         AND th.hb_type = #{type}
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
      </if>
      <if test="type != null and type == 2"> <!-- 分享订单 -->
         AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
      </if>
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="startTime != null">
         AND <![CDATA[tc.co_create_time >= #{startTime}]]>
@@ -407,4 +454,123 @@
      )A
   </select>
   <select id="countBonusOrder" resultType="java.lang.Long">
      SELECT COALESCE(COUNT(DISTINCT
      tc.`co_order_no`,tc.`co_source_type`),0) FROM yeshi_ec_common_order tc
      LEFT JOIN yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
      LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id`
      OR th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE 1=1
      <if test="uid != null">
         AND th.`hb_uid` = ${uid}
      </if>
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
      </if>
      <if test="type != null and type == 2"> <!-- 分享订单 -->
         AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
      </if>
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="day != null and day == 1"> <!-- 今天 -->
         AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      <if test="day != null and day == 2">  <!-- 昨天 -->
         AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
      </if>
      <if test="day != null and day == 3">  <!-- 本月 -->
         AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
         DATE_FORMAT(CURDATE(),'%Y%m')
      </if>
      <if test="day != null and day == 4">  <!-- 上月 -->
         AND PERIOD_DIFF(DATE_FORMAT(NOW(), '%Y%m'),
         DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
      </if>
   </select>
   <select id="countBonusOrderMoney" resultType="java.math.BigDecimal">
      SELECT COALESCE(SUM(th.`hb_money`),0)AS totalmoney FROM
      yeshi_ec_common_order tc
      LEFT JOIN yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
      LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE <![CDATA[tc.`co_state` <> 4]]>
      <if test="uid != null">
         AND th.`hb_uid` = ${uid}
      </if>
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
      </if>
      <if test="type != null and type == 2"> <!-- 分享订单 -->
         AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
      </if>
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="day != null and day == 1"> <!-- 今天 -->
         AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      <if test="day != null and day == 2">  <!-- 昨天 -->
         AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
      </if>
      <if test="day != null and day == 3">  <!-- 本月 -->
         AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
         DATE_FORMAT(CURDATE(),'%Y%m')
      </if>
      <if test="day != null and day == 4">  <!-- 上月 -->
         AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
         DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
      </if>
   </select>
   <select id="listBonusOrder" resultMap="ResultMap">
      SELECT COALESCE(SUM(th.`hb_money`),0)AS totalMoney,tc.*,th.hb_state AS
      hongBaoState, th.hb_type AS hongBaoType,
      th.hb_get_time AS accountTime,th.hb_get_time AS accountTime,th.hb_pre_get_time AS
      preAccountTime
      FROM yeshi_ec_common_order tc
      LEFT JOIN yeshi_ec_hongbao_order tr ON tr.`ho_order_id` = tc.`co_id`
      LEFT JOIN yeshi_ec_hongbao_v2 th ON (tr.`ho_hongbao_id` = th.`hb_id` OR
      th.`hb_pid` = tr.`ho_hongbao_id` )
      WHERE th.`hb_uid` = #{uid}
      <if test="type != null and type == 1"> <!-- 自购订单 -->
         AND (th.hb_type =1 or th.hb_type =2)
      </if>
      <if test="type != null and type == 2"> <!-- 分享订单 -->
         AND (th.`hb_type` = 20 OR th.`hb_type` = 21 OR th.`hb_type` = 22)
      </if>
      <if test="type != null and type == 3"> <!-- 邀请订单 -->
         AND (th.`hb_type` = 5 OR th.`hb_type` = 6 OR th.`hb_type` = 7)
      </if>
      <if test="orderState != null and orderState == 1">
         AND (tc.co_state = 1 or tc.co_state = 2) <!-- 有效订单 -->
      </if>
      <if test="orderState != null and orderState == 2">
         AND tc.co_state = 3 <!-- 维权订单 -->
      </if>
      <if test="orderState != null and orderState == 3">
         AND tc.co_state = 4 <!-- 失效订单 -->
      </if>
      <if test="day != null and day == 1"> <!-- 今天 -->
         AND TO_DAYS(tc.`co_create_time`) = TO_DAYS(NOW())
      </if>
      <if test="day != null and day == 2">  <!-- 昨天 -->
         AND TO_DAYS(NOW()) - TO_DAYS(tc.`co_create_time`) = 1
      </if>
      <if test="day != null and day == 3">  <!-- 本月 -->
         AND DATE_FORMAT(tc.`co_create_time`,'%Y%m') =
         DATE_FORMAT(CURDATE(),'%Y%m')
      </if>
      <if test="day != null and day == 4">  <!-- 上月 -->
         AND PERIOD_DIFF( DATE_FORMAT(NOW(), '%Y%m'),
         DATE_FORMAT(tc.`co_create_time`, '%Y%m')) = 1
      </if>
      GROUP BY tc.`co_order_no`,tc.co_source_type
      ORDER BY tc.co_create_time DESC
      LIMIT ${start},${count}
   </select>
</mapper>