<?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.yami.shop.seckill.comment.dao.SeckillSkuMapper">

  <resultMap id="seckillSkuMap" type="com.yami.shop.seckill.comment.model.SeckillSku">
    <id column="seckill_sku_id" property="seckillSkuId" />
    <result column="sku_id" property="skuId"/>
    <result column="seckill_id" property="seckillId"/>
    <result column="seckill_stocks" property="seckillStocks"/>
    <result column="seckill_price" property="seckillPrice"/>
  </resultMap>
    <update id="updateStocks">
      update tz_seckill_sku set seckill_stocks = seckill_stocks - #{prodCount}  where seckill_sku_id = #{seckillSkuId} and seckill_stocks &gt;= #{prodCount}

    </update>
    <update id="returnStocks">
      UPDATE tz_seckill_sku ss JOIN (
        SELECT so.seckill_sku_id,so.prod_count  FROM tz_seckill_order so JOIN
                                 tz_seckill s ON s.seckill_id = so.seckill_id and so.state = 0
                                   AND (UNIX_TIMESTAMP(NOW()) - UNIX_TIMESTAMP(so.`create_time`))/60 &gt; s.`max_cancel_time` ) t
        ON ss.seckill_sku_id = t.seckill_sku_id

      set ss.seckill_stocks = ss.seckill_stocks + t.prod_count

    </update>
    <update id="returnStocksByOrderNumber">
      UPDATE tz_seckill_sku ss JOIN (
        SELECT so.seckill_sku_id,so.prod_count  FROM tz_seckill_order so JOIN
                                                     tz_seckill s ON s.seckill_id = so.seckill_id and so.state = 0
                                                       AND so.order_number = #{orderNumber} ) t
        ON ss.seckill_sku_id = t.seckill_sku_id

      set ss.seckill_stocks = ss.seckill_stocks + t.prod_count
    </update>
</mapper>
