437 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			XML
		
	
	
	
		
		
			
		
	
	
			437 lines
		
	
	
		
			16 KiB
		
	
	
	
		
			XML
		
	
	
	
|  | <?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.hzs.activity.pick.mapper.AcPickMapper"> | ||
|  | 
 | ||
|  |     <!-- 通用查询映射结果 --> | ||
|  |     <resultMap id="BaseResultMap" type="com.hzs.common.domain.activity.pick.AcPick"> | ||
|  |         <id column="PK_ID" property="pkId"/> | ||
|  |         <result column="DEL_FLAG" property="delFlag"/> | ||
|  |         <result column="CREATION_TIME" property="creationTime"/> | ||
|  |         <result column="PK_CREATOR" property="pkCreator"/> | ||
|  |         <result column="MODIFIED_TIME" property="modifiedTime"/> | ||
|  |         <result column="PK_MODIFIED" property="pkModified"/> | ||
|  |         <result column="PK_COUNTRY" property="pkCountry"/> | ||
|  |         <result column="PK_MEMBER" property="pkMember"/> | ||
|  |         <result column="PICK_TYPE" property="pickType"/> | ||
|  |         <result column="PK_BASE_CONFIG" property="pkBaseConfig"/> | ||
|  |         <result column="PK_DATA_ID" property="pkDataId"/> | ||
|  |         <result column="SPECS_NAME" property="specsName"/> | ||
|  |         <result column="SPECS_NAME_ID" property="specsNameId"/> | ||
|  |         <result column="USABLE_QUANTITY" property="usableQuantity"/> | ||
|  |         <result column="USED_QUANTITY" property="usedQuantity"/> | ||
|  |         <result column="PICK_COVER" property="pickCover"/> | ||
|  |         <result column="RECEIVE_TIME" property="receiveTime"/> | ||
|  |         <result column="IS_FREE_MAIL" property="isFreeMail"/> | ||
|  |         <result column="PK_POSTAGE" property="pkPostage"/> | ||
|  |         <result column="BASE_QUANTITY" property="baseQuantity"/> | ||
|  |         <result column="PK_BASE_ID" property="pkBaseId"/> | ||
|  |     </resultMap> | ||
|  | 
 | ||
|  |     <!-- 更新提货数量 --> | ||
|  |     <update id="addQuantityByActivity"> | ||
|  |         update AC_PICK ap | ||
|  |         set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY + #{quantity}, | ||
|  |         <if test="receiveTime != null"> | ||
|  |             ap.RECEIVE_TIME = #{receiveTime}, | ||
|  |         </if> | ||
|  |         <choose> | ||
|  |             <when test="pkPostage != null"> | ||
|  |                 ap.IS_FREE_MAIL = 1, | ||
|  |                 ap.PK_POSTAGE = #{pkPostage}, | ||
|  |             </when> | ||
|  |             <otherwise> | ||
|  |                 ap.PK_POSTAGE = 0, | ||
|  |             </otherwise> | ||
|  |         </choose> | ||
|  |         ap.pk_modified = #{pkModified}, | ||
|  |         ap.modified_time = sysdate | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.PICK_TYPE = #{pickType} | ||
|  |         <if test="pkBaseConfig != null"> | ||
|  |             and ap.PK_BASE_CONFIG = #{pkBaseConfig} | ||
|  |         </if> | ||
|  |         and ap.PK_DATA_ID = #{pkDataId} | ||
|  |         and ap.PK_MEMBER = #{pkMember} | ||
|  |         and ap.USABLE_QUANTITY + #{quantity} > 0 | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 批量更新使用数量 --> | ||
|  |     <update id="updatePickUseBatch"> | ||
|  |         merge into ac_pick ap | ||
|  |         using ( | ||
|  |         <foreach collection="list" item="item" separator=" union "> | ||
|  |             select | ||
|  |             #{item.pkId} PK_ID, | ||
|  |             #{item.pkMember} PK_MEMBER | ||
|  |             from dual | ||
|  |         </foreach> | ||
|  |         ) tmp | ||
|  |         on (tmp.PK_ID = ap.PK_ID) | ||
|  |         WHEN MATCHED THEN | ||
|  |         update | ||
|  |         set ap.USABLE_QUANTITY = USABLE_QUANTITY - #{quantity}, | ||
|  |         ap.USED_QUANTITY = USED_QUANTITY + #{quantity}, | ||
|  |         ap.pk_modified = tmp.pk_member, | ||
|  |         ap.modified_time = sysdate | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 批量更新使用数量 --> | ||
|  |     <update id="updatePickUseCouponBatch"> | ||
|  |         merge into ac_pick ap | ||
|  |         using ( | ||
|  |         select pk_id,pk_member,sum(used_quantity) used_quantity from ( | ||
|  |         <foreach collection="list" item="item" separator=" union all "> | ||
|  |             select | ||
|  |             #{item.pkId} PK_ID, | ||
|  |             #{item.pkMember} PK_MEMBER, | ||
|  |             #{item.usedQuantity} used_quantity | ||
|  |             from dual | ||
|  |         </foreach>) | ||
|  |         group by pk_id,pk_member | ||
|  |         ) tmp | ||
|  |         on (tmp.PK_ID = ap.PK_ID) | ||
|  |         WHEN MATCHED THEN | ||
|  |         update | ||
|  |         set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY - tmp.used_quantity, | ||
|  |         ap.USED_QUANTITY = ap.USED_QUANTITY + tmp.used_quantity, | ||
|  |         ap.pk_modified = tmp.pk_member, | ||
|  |         ap.modified_time = sysdate | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 根据提货ID更新使用数量 --> | ||
|  |     <update id="updatePickUseById"> | ||
|  |         update AC_PICK ap | ||
|  |         set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY - #{quantity}, | ||
|  |             ap.USED_QUANTITY   = ap.USED_QUANTITY + #{quantity}, | ||
|  |             ap.pk_modified     = #{pkModified}, | ||
|  |             ap.modified_time   = sysdate | ||
|  |         where ap.del_flag = 0 | ||
|  |           and ap.pk_id = #{pkId} | ||
|  |           and ap.USABLE_QUANTITY - #{quantity} >= 0 | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 根据会员和类型回退使用数量 --> | ||
|  |     <update id="updatePickUsableByMember"> | ||
|  |         update ac_pick ap | ||
|  |         set ap.modified_time = sysdate, | ||
|  |         ap.pk_modified = #{pkModified}, | ||
|  |         ap.usable_quantity = ap.usable_quantity + #{quantity}, | ||
|  |         ap.used_quantity = ap.used_quantity - #{quantity} | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.pk_member = #{pkMember} | ||
|  |         and ap.pick_type = #{pickType} | ||
|  |         <if test="null != pkBaseConfig"> | ||
|  |             and ap.pk_base_config = #{pkBaseConfig} | ||
|  |         </if> | ||
|  |         <if test="null != pkDataId"> | ||
|  |             and ap.pk_data_id = #{pkDataId} | ||
|  |         </if> | ||
|  |         and ap.used_quantity - #{quantity} >= 0 | ||
|  |     </update> | ||
|  | 
 | ||
|  | 
 | ||
|  |     <!-- 根据会员和活动类型回退使用数量 --> | ||
|  |     <update id="updatePickUsableByMemberAndActivityType"> | ||
|  |         update ac_pick ap | ||
|  |         set ap.modified_time = sysdate, | ||
|  |         ap.pk_modified = #{pkModified}, | ||
|  |         ap.usable_quantity = ap.usable_quantity - #{quantity}, | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.pk_member = #{pkMember} | ||
|  |         and ap.pick_type = #{pickType} | ||
|  |         <if test="null != pkBaseConfig"> | ||
|  |             and ap.pk_base_config = #{pkBaseConfig} | ||
|  |         </if> | ||
|  |         <if test="null != pkDataId"> | ||
|  |             and ap.pk_data_id = #{pkDataId} | ||
|  |         </if> | ||
|  |         and ap.usable_quantity - #{quantity} >= 0 | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 根据主键更新提货数量 --> | ||
|  |     <update id="updatePickQuantityByPkId"> | ||
|  |         update AC_PICK ap | ||
|  |         set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY + #{acPick.usableQuantity}, | ||
|  |         ap.pk_modified = #{acPick.pkModified}, | ||
|  |         ap.modified_time = sysdate | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.PK_ID = #{acPick.pkId} | ||
|  |         and ap.RECEIVE_TIME = #{acPick.receiveTime} | ||
|  |         <if test="acPick.isFreeMail != null"> | ||
|  |             and ap.IS_FREE_MAIL = #{acPick.isFreeMail} | ||
|  |         </if> | ||
|  |         and ap.PK_POSTAGE = #{acPick.pkPostage} | ||
|  |         and ap.USABLE_QUANTITY + #{acPick.usableQuantity} > 0 | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 根据主键更新提货数据 --> | ||
|  |     <update id="updatePickByPkId"> | ||
|  |         update AC_PICK ap | ||
|  |         set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY + #{acPick.usableQuantity}, | ||
|  |         <if test="null != acPick.receiveTime"> | ||
|  |             ap.receive_time = #{acPick.receiveTime}, | ||
|  |         </if> | ||
|  |         <if test="null != acPick.isFreeMail"> | ||
|  |             ap.is_free_mail = #{acPick.isFreeMail}, | ||
|  |             <choose> | ||
|  |                 <when test="1 == acPick.isFreeMail"> | ||
|  |                     <!-- 不包邮,需要更新邮费模板 --> | ||
|  |                     ap.pk_postage = #{acPick.pkPostage}, | ||
|  |                 </when> | ||
|  |                 <otherwise> | ||
|  |                     <!-- 包邮,清空运费模板 --> | ||
|  |                     ap.pk_postage = null, | ||
|  |                 </otherwise> | ||
|  |             </choose> | ||
|  |         </if> | ||
|  |         <if test="null != acPick.baseQuantity"> | ||
|  |             ap.BASE_QUANTITY = #{acPick.baseQuantity}, | ||
|  |         </if> | ||
|  |         ap.pk_modified = #{acPick.pkModified}, | ||
|  |         ap.modified_time = sysdate | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.PK_ID = #{acPick.pkId} | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!--    删除充值提货卡--> | ||
|  |     <update id="removePickByPkId"> | ||
|  |         update AC_PICK ap | ||
|  |         set ap.del_flag      = 1, | ||
|  |             ap.pk_modified   = #{acPick.pkModified}, | ||
|  |             ap.modified_time = sysdate | ||
|  |         where ap.del_flag = 0 | ||
|  |           and ap.PK_ID = #{acPick.pkId} | ||
|  |     </update> | ||
|  | 
 | ||
|  | 
 | ||
|  |     <update id="updateBackPickUseBatch"> | ||
|  |         merge into ac_pick ap | ||
|  |         using ( | ||
|  |         select pk_member,pk_pick,sum(PICK_QUANTITY) PICK_QUANTITY from( | ||
|  |         <foreach collection="list" item="item" separator=" union all"> | ||
|  |             select | ||
|  |             #{item.pkMember} PK_MEMBER, | ||
|  |             #{item.pkPick} PK_PICK, | ||
|  |             #{item.pickQuantity} PICK_QUANTITY | ||
|  |             from dual | ||
|  |         </foreach>) | ||
|  |         group by pk_member,pk_pick | ||
|  |         ) tmp | ||
|  |         on (tmp.PK_PICK = ap.PK_ID) | ||
|  |         WHEN MATCHED THEN | ||
|  |         update | ||
|  |         set ap.USABLE_QUANTITY = ap.USABLE_QUANTITY + tmp.PICK_QUANTITY, | ||
|  |         ap.USED_QUANTITY = ap.USED_QUANTITY -tmp.PICK_QUANTITY, | ||
|  |         ap.pk_modified = tmp.pk_member, | ||
|  |         ap.modified_time = sysdate | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 查询提货列表 --> | ||
|  |     <select id="queryList" resultType="com.hzs.common.domain.activity.pick.ext.AcPickExt"> | ||
|  |         SELECT ap.*, | ||
|  |         cm.member_code, | ||
|  |         cm.member_name, | ||
|  |         nvl(bp.retail_price, 0) retail_price, | ||
|  |         bp.product_name || nvl2(ap.specs_name, '(' || ap.specs_name || ')', '') AS product_name, | ||
|  |         abc.act_name | ||
|  |         FROM AC_PICK ap | ||
|  |         INNER JOIN cu_member cm ON cm.pk_id = ap.pk_member | ||
|  |         LEFT JOIN bd_product bp ON bp.pk_id = ap.pk_data_id AND ap.pick_type in (0, 1, 5, 7, 8) | ||
|  |         left join ac_base_config abc on abc.pk_id = ap.pk_base_id | ||
|  |         WHERE ap.del_flag = 0 | ||
|  |         and ap.pk_country = #{pkCountry} | ||
|  |         <if test="param.pkMember != null "> | ||
|  |             and ap.pk_member=#{param.pkMember} | ||
|  |         </if> | ||
|  |         <if test="param.memberCode != null and param.memberCode != ''"> | ||
|  |             and cm.member_code like #{param.memberCode} || '%' | ||
|  |         </if> | ||
|  |         <if test="param.memberName != null and param.memberName != ''"> | ||
|  |             and cm.member_name like #{param.memberName} || '%' | ||
|  |         </if> | ||
|  |         <if test="param.pickType != null"> | ||
|  |             and ap.pick_type = #{param.pickType} | ||
|  |         </if> | ||
|  |         <if test="param.creationTime != null"> | ||
|  |             and ap.creation_time >= #{param.creationTime[0]} | ||
|  |             and #{param.creationTime[1]} >= ap.creation_time | ||
|  |         </if> | ||
|  |         <if test="param.modifiedTime != null"> | ||
|  |             and ap.modified_time >= #{param.modifiedTime[0]} | ||
|  |             and #{param.modifiedTime[1]} >= ap.modified_time | ||
|  |         </if> | ||
|  |         <if test="param.receiveTime != null"> | ||
|  |             and ap.receive_time >= #{param.receiveTime[0]} | ||
|  |             and #{param.receiveTime[1]} >= ap.receive_time | ||
|  |         </if> | ||
|  |         order by ap.creation_time desc | ||
|  |     </select> | ||
|  | 
 | ||
|  |     <!-- 查询提货详情 --> | ||
|  |     <select id="queryDetail" resultType="com.hzs.common.domain.activity.pick.ext.AcPickExt"> | ||
|  |         select ap.*, | ||
|  |                cm.member_code, | ||
|  |                cm.member_name, | ||
|  |                case | ||
|  |                    when ap.pick_type = 0 then | ||
|  |                        (select bp.product_name | ||
|  |                         from bd_product bp | ||
|  |                         where bp.pk_id = PK_DATA_ID) | ||
|  |                    end product_name | ||
|  |         from AC_PICK ap | ||
|  |                  inner join cu_member cm | ||
|  |                             on cm.pk_id = ap.pk_member | ||
|  |         where ap.del_flag = 0 | ||
|  |           and ap.pk_id = #{pkId} | ||
|  |           and ap.pk_country = #{pkCountry} | ||
|  |     </select> | ||
|  | 
 | ||
|  |     <!-- 会员提货列表 --> | ||
|  |     <select id="pickList" resultType="com.hzs.activity.pick.vo.ApiPickListVO"> | ||
|  |         <!-- 提货产品 --> | ||
|  |         select ap.pk_id, | ||
|  |         ap.pick_type, | ||
|  |         case | ||
|  |         when ap.pick_cover is not null then | ||
|  |         ap.pick_cover | ||
|  |         else | ||
|  |         (select bp.cover from bd_product bp where bp.pk_id = ap.pk_data_id) | ||
|  |         end pick_cover, | ||
|  |         ap.usable_quantity, | ||
|  |         ap.receive_time, | ||
|  |         0 pick_flag, | ||
|  |         1 IS_WHOLE, | ||
|  |         ap.base_quantity, | ||
|  |         ap.creation_time | ||
|  |         from AC_PICK ap | ||
|  |         inner join bd_product bp | ||
|  |         on bp.pk_id = ap.pk_data_id | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.pk_country = #{pkCountry} | ||
|  |         and ap.pk_member = #{pkMember} | ||
|  |         and ap.pick_type = 0 | ||
|  |         and ap.usable_quantity > 0 | ||
|  |         and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd') >= to_char(sysdate, 'yyyy-mm-dd')) | ||
|  |         <!-- 迁移抽奖、新抽奖 --> | ||
|  |         union all | ||
|  |         select ap.pk_id, | ||
|  |         ap.pick_type, | ||
|  |         case | ||
|  |         when ap.pick_cover is not null then | ||
|  |         ap.pick_cover | ||
|  |         else | ||
|  |         (select bp.cover from bd_product bp where bp.pk_id = ap.pk_data_id) | ||
|  |         end pick_cover, | ||
|  |         ap.usable_quantity, | ||
|  |         ap.receive_time, | ||
|  |         0 pick_flag, | ||
|  |         0 IS_WHOLE, | ||
|  |         ap.base_quantity, | ||
|  |         ap.creation_time | ||
|  |         from AC_PICK ap | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.pk_country = #{pkCountry} | ||
|  |         and ap.pk_member = #{pkMember} | ||
|  |         and ap.pick_type in (1, 17) | ||
|  |         and ap.usable_quantity > 0 | ||
|  |         and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd hh24:mi:ss') >= to_char(sysdate, 'yyyy-mm-dd hh24:mi:ss')) | ||
|  |         <!-- 迁移创客沙棘提货、复购提货 --> | ||
|  |         union all | ||
|  |         select ap.pk_id, | ||
|  |         ap.pick_type, | ||
|  |         case | ||
|  |         when ap.pick_cover is not null then | ||
|  |         ap.pick_cover | ||
|  |         else | ||
|  |         (select bp.cover from bd_product bp where bp.pk_id = ap.pk_data_id) | ||
|  |         end pick_cover, | ||
|  |         ap.usable_quantity, | ||
|  |         ap.receive_time, | ||
|  |         0 pick_flag, | ||
|  |         1 IS_WHOLE, | ||
|  |         ap.base_quantity, | ||
|  |         ap.creation_time | ||
|  |         from AC_PICK ap | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.pk_country = #{pkCountry} | ||
|  |         and ap.pk_member = #{pkMember} | ||
|  |         and ap.pick_type in (5, 7) | ||
|  |         and ap.usable_quantity > 0 | ||
|  |         and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd') >= to_char(sysdate, 'yyyy-mm-dd')) | ||
|  |         <!-- 迁移乐学易考代金券 --> | ||
|  |         union all | ||
|  |         select ap.pk_id, | ||
|  |         ap.pick_type, | ||
|  |         case | ||
|  |         when ap.pick_cover is not null then | ||
|  |         ap.pick_cover | ||
|  |         else | ||
|  |         (select bp.cover from bd_product bp where bp.pk_id = ap.pk_data_id) | ||
|  |         end pick_cover, | ||
|  |         ap.usable_quantity, | ||
|  |         ap.receive_time, | ||
|  |         1 pick_flag, | ||
|  |         0 IS_WHOLE, | ||
|  |         ap.base_quantity, | ||
|  |         ap.creation_time | ||
|  |         from AC_PICK ap | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.pk_country = #{pkCountry} | ||
|  |         and ap.pk_member = #{pkMember} | ||
|  |         and ap.pick_type = 8 | ||
|  |         and ap.usable_quantity > 0 | ||
|  |         and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd') >= to_char(sysdate, 'yyyy-mm-dd')) | ||
|  |         <!-- 消费赠送、直推赠送、超级工作室赠送、节日赠送 --> | ||
|  |         union all | ||
|  |         select ap.pk_id, | ||
|  |         ap.pick_type, | ||
|  |         ap.pick_cover, | ||
|  |         ap.usable_quantity, | ||
|  |         ap.receive_time, | ||
|  |         0 pick_flag, | ||
|  |         nvl(apuc.is_whole, 1) is_whole, | ||
|  |         ap.base_quantity, | ||
|  |         ap.creation_time | ||
|  |         from AC_PICK ap | ||
|  |         left join AC_PICK_UP_CONFIG apuc | ||
|  |         on apuc.pk_base_id = ap.pk_base_config | ||
|  |         and apuc.del_flag = 0 | ||
|  |         where ap.del_flag = 0 | ||
|  |         and ap.pk_country = #{pkCountry} | ||
|  |         and ap.pk_member = #{pkMember} | ||
|  |         and ap.pick_type in (12, 13, 14, 15) | ||
|  |         and ap.usable_quantity > 0 | ||
|  |         and (ap.receive_time is null or to_char(ap.receive_time, 'yyyy-mm-dd') >= to_char(sysdate, 'yyyy-mm-dd')) | ||
|  |         <!-- 排序 --> | ||
|  |         order by creation_time | ||
|  |     </select> | ||
|  | 
 | ||
|  |     <!-- 更新代言礼包提货数据 --> | ||
|  |     <update id="updateRepurchasePick"> | ||
|  |         update AC_PICK ap | ||
|  |         set ap.usable_quantity = nvl(ap.usable_quantity, 0) + #{usableQuantity}, | ||
|  |             ap.MODIFIED_TIME   = sysdate | ||
|  |         where ap.del_flag = 0 | ||
|  |           and ap.pick_type = 7 | ||
|  |           and ap.pk_base_config = 0 | ||
|  |           and ap.pk_data_id = #{pkProduct} | ||
|  |           and ap.pk_member = #{pkMember} | ||
|  |     </update> | ||
|  | 
 | ||
|  |     <!-- 撤单扣减乐学代金券 --> | ||
|  |     <update id="deductionsCouponByOrder"> | ||
|  |         update ac_pick ap | ||
|  |         set ap.usable_quantity = ap.usable_quantity - | ||
|  |                                  nvl((select sum(soi.quantity) | ||
|  |                                       from sa_order_items soi | ||
|  |                                       where soi.pk_order = #{pkOrder} | ||
|  |                                         and soi.is_gift = 0 | ||
|  |                                         and soi.pk_product = ap.pk_data_id), | ||
|  |                                      0) | ||
|  |         where ap.del_flag = 0 | ||
|  |           and ap.pk_member = #{pkMember} | ||
|  |           and ap.pick_type = 8 | ||
|  |     </update> | ||
|  | 
 | ||
|  | </mapper> |