`id`,`tenant_id`,`parent_tenant_id`,`coupon_id`,`title`,`send_type`,`conditions`,`status`,`create_date`,`update_date`,`send_sms`,`operator_id`
cs.id,cs.tenant_id,cs.parent_tenant_id,cs.coupon_id,cs.title,cs.send_type,cs.conditions,cs.status,cs.create_date,cs.update_date,
cs.conditions -> '$.merchantSend' as merchantSend,
cs.conditions -> '$.merchantLnventory' as merchantLnventory,
cs.conditions -> '$.merchantRemain' as merchantRemain,
(case when
(select count(*) from wx_coupon_merchant xcm where xcm.product_id = cs.coupon_id and xcm.status = 0)=1
then
(select m.name from wx_merchant m, wx_coupon_merchant cm where m.id = cm.merchant_id and cm.product_id=cs.coupon_id and cm.status = 0)
else
'[多商户通用]'
end) as merchant_name,
c.remain_inventory, c.use_limit_rule,c.use_limit_quantity, c.inventory, c.valid_start_date, c.valid_end_date,c.valid_type,cs.send_sms,c.valid_days
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.id in
#{idItem}
and cs.send_sms = #{sendSms}
order by ${sortColumns}
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}