`id`,`tenant_id`,`merchant_id`,`coupon_id`,`coupon_status`,`type`,`title`,`target_ad`,`business`,`begin_time`,`end_time`,`status`,`create_date`,`update_date`,`sub_target_id`
where 1 = 1
and `id` = #{id}
and `tenant_id` like concat('%', #{tenantId},'%')
and `merchant_id` = #{merchantId}
and `coupon_id` = #{couponId}
and `type` = #{type}
and `title` like concat('%', #{title},'%')
and `target_ad` = #{targetAd}
and JSON_CONTAINS(`business`->'$',JSON_ARRAY('0'))
and (JSON_CONTAINS(`business`->'$',JSON_ARRAY('0')) or (JSON_CONTAINS(`business`->'$',JSON_ARRAY(#{business}))))
and `begin_time` = #{beginTime}
and `end_time` = #{endTime}
and `status` = #{status}
and `create_date` = #{createDate}
and `update_date` = #{updateDate}
and `sub_target_id` = #{subTargetId}
and id in
#{idItem}
and coupon_id in
#{couponIdsItem}
order by ${sortColumns}
update wx_coupon_channel set status=#{status} where tenant_id=#{tenantId} and coupon_id=#{couponId}
update wx_coupon_channel SET status = 1, update_date = now()
where status = 0 and end_time < now()
update wx_coupon_channel cc, wx_coupon c SET cc.status = 1, cc.update_date = now()
where cc.status = 0 and cc.coupon_id = c.id and c.valid_type = 1 and valid_end_date < now()
update wx_coupon_channel cc, wx_coupon c SET cc.status = 1, cc.update_date = now()
where cc.status = 0 and cc.coupon_id = c.id and c.status = 1