`id`,`tenant_id`,`parent_tenant_id`,`coupon_id`,`title`,`send_type`,`conditions`,`status`,`create_date`,`update_date`,`send_sms`,`operator_id`,
cs.conditions -> '$.merchantSend' as merchantSend,
cs.conditions -> '$.merchantLnventory' as merchantLnventory,
cs.conditions -> '$.merchantRemain' as merchantRemain
where 1 = 1
and cs.id = #{id}
and cs.`tenant_id` = #{tenantId}
and cs.`parent_tenant_id` = #{parentTenantId}
and cs.coupon_id = #{couponId}
and cs.title like concat('%', #{title},'%')
and cs.send_type = #{sendType}
and cs.status = #{status}
and cs.create_date = #{createDate}
and cs.update_date = #{updateDate}
and cs.conditions -> '$.title' like concat('%',#{merchantName},'%')
and cs.conditions->'$.id' = concat(#{merchantId},'')
and cs.conditions -> '$.merchantRemain'> #{merchantRemain}
and cs.coupon_id in
#{couponIdItem}
and cs.id in
#{idItem}
and cs.send_sms = #{sendSms}
order by ${sortColumns}
order by ${sortCol}
delete from wx_coupon_send cs where cs.id = #{id} and cs.tenant_id = #{tenantId}
update wx_coupon_send set status=#{status}
where coupon_id=#{couponId}
and `tenant_id` = #{tenantId}
and `parent_tenant_id` = #{parentTenantId}
update wx_coupon_send
set conditions=#{conditions},update_date = #{updateDate}
where send_type = #{sendType}
and tenant_id = #{tenantId}
update wx_coupon_send cs, wx_coupon c
set cs.status=1, cs.update_date = now()
where c.id = cs.coupon_id and cs.status = 0 and cs.tenant_id = #{tenantId} and
((c.status = 1) or (c.valid_type = 1 and c.valid_end_date < now()))
update wx_coupon_send
SET conditions = JSON_SET(conditions, '$.merchantRemain', #{merchantRemain} - #{number} , '$.merchantSend',
#{merchantSend} + #{number})
where id = #{id}
and conditions -> '$.merchantRemain' = #{merchantRemain}
update wx_coupon_send
SET conditions = JSON_SET(conditions, '$.merchantRemain', #{merchantRemain} + #{number} , '$.merchantSend',
#{merchantSend} - #{number})
where id = #{id}
and conditions -> '$.merchantRemain' = #{merchantRemain}