`id`,`tenant_id`,`type`,`cover_img`,`cover_picture`,`detail_picture`,`title`,`sub_title`,`sale_price`,`use_price`,`use_limit_quantity`,`send_type`,
`valid_type`,`valid_start_date`,`valid_end_date`,`valid_days`,`detail`,`price`,`unit`,`remain_inventory`,`inventory`,
`remark`,`status`,`create_date`,`update_date`,`business`,`sub_business`,`support_transfer`,`subsidy_num`,`subsidy_type`,
`press_limit_num`, `press_limit_hours`, `auto_refund`,`credit_price`,`credit_refund`,`put_apply_status`,`stock_apply_status`,`cancle_apply_status`,`conditions`,approval_type
where 1 = 1
and `id` = #{id}
and `tenant_id` = #{tenantId}
and `type` = #{type}
and `cover_img` like concat('%', #{coverImg},'%')
and `title` like concat('%', #{title},'%')
and `sub_title` like concat('%', #{subTitle},'%')
and `sale_price` = #{salePrice}
and `use_price` = #{usePrice}
and `use_limit_quantity` = #{useLimitQuantity}
and `send_type` = #{sendType}
and `valid_type` = #{validType}
and `valid_start_date` = #{validStartDate}
and `valid_end_date` = #{validEndDate}
and `valid_days` = #{validDays}
and `detail` like concat('%', #{detail},'%')
and `price` = #{price}
and `unit` = #{unit}
and `remain_inventory` = #{remainInventory}
and `inventory` = #{inventory}
and `remark` like concat('%', #{remark},'%')
and `status` = #{status}
and `create_date` between #{startdate} and #{enddate}
and `update_date` = #{updateDate}
and `business` = #{business}
and `sub_business` = #{subBusiness}
and `support_transfer` = #{supportTransfer}
and `subsidy_type` = #{subsidyType}
and `subsidy_num` = #{subsidyNum}
and `press_limit_num` = #{pressLimitNum}
and `press_limit_hours` = #{pressLimitHours}
and `auto_refund` = #{autoRefund}
and `credit_price` = #{creditPrice}
and `credit_refund` = #{creditRefund}
and `credit_refund` = #{creditRefund}
and id in
#{idItem}
and type not in
#{typeItem}
order by ${sortColumns}
update wx_coupon
SET
`remain_inventory` = #{remainInventory}, `inventory` = #{inventory},
`valid_type` = #{validType}, `valid_end_date` = #{validEndDate}, `valid_days` = #{validDays}
WHERE `tenant_id` = #{tenantId} and id = #{id} and `remain_inventory` = #{orgRemainInventory} and `inventory` = #{orgInventory}
where is_del = 0
and 0 = (select count(*) from wx_coupon_channel cc
where c.`id` = cc.coupon_id
and cc.status = 0
and cc.target_ad = #{targetAd})
and c.`id` = #{id}
and c.`tenant_id` = #{tenantId}
and c.`type` < 7
and c.`type` = #{type}
and c.`cover_img` like concat('%', #{coverImg},'%')
and c.`title` like concat('%', #{title},'%')
and c.`sub_title` like concat('%', #{subTitle},'%')
and c.`sale_price` = #{salePrice}
and c.`use_price` = #{usePrice}
and c.`use_limit_quantity` = #{useLimitQuantity}
and c.`send_type` = #{sendType}
and c.`valid_type` = #{validType}
and c.`valid_start_date` = #{validStartDate}
and c.`valid_end_date` = #{validEndDate}
and c.`valid_days` = #{validDays}
and c.`detail` like concat('%', #{detail},'%')
and c.`price` = #{price}
and c.`unit` = #{unit}
and c.`remain_inventory` = #{remainInventory}
and c.`inventory` = #{inventory}
and c.`remark` like concat('%', #{remark},'%')
and c.`status` = #{status}
and c.`create_date` between #{startdate} and #{enddate}
and c.`update_date` = #{updateDate}
and c.`business` = #{business}
and `sub_business` = #{subBusiness}
and c.`support_transfer` = #{supportTransfer}
and c.`subsidy_type` = #{subsidyType}
and c.`subsidy_num` = #{subsidyNum}
and c.`press_limit_num` = #{pressLimitNum}
and c.`press_limit_hours` = #{pressLimitHours}
and c.`auto_refund` = #{autoRefund}
and if(type=8,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}) ,1=1)
and if(type=9,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}),1=1)
and if(type=100,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}),1=1)
and if(type !=8 and type !=9 and type!=100,put_apply_status =2 or c.id in(select coupon_id from wx_coupon_channel where status=0 and tenant_id=#{tenantId}),1=1)
and c.id in
#{idItem}
and c.type in
#{typesItem}
order by ${sortColumns}
update wx_coupon SET remain_inventory = remain_inventory - #{number} where id = #{id} and remain_inventory>= #{number}
update wx_coupon SET remain_inventory = remain_inventory + #{number} where id = #{id} and remain_inventory>= #{remainInventory}
update wx_coupon SET status = 1, update_date = now()
where status = 0 and valid_type = 1 and valid_end_date < now()
update wx_coupon c
SET c.status = 1, c.update_date = now()
where c.status = 0 and
(select count(*) from wx_coupon_merchant cm, wx_merchant m
where m.id = cm.merchant_id
and c.id = cm.product_id
and cm.status = 0
and m.status = 1) = 0