`id`,`tenant_id`,`c_user_id`,`credit_amount`,`credit_num`,`credit_type`,`create_date`,`receipt_url`,`operator_type`,`operator_id`,`merchant_id`,`coupon_id`,`business_id`,`spend`,`change_purpose`,`ticket_number`,`buser_id`
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
and credit.operator_type = #{operatorType}
and credit.operator_id = #{operatorId}
and credit.credit_type = #{creditType}
and credit.c_user_id = #{cUserId}
and credit.merchant_id = #{merchantId}
and credit.ticket_number like concat('%', #{ticketNumber},'%')
and credit.buser_id = #{buserId}
and credit.merchant_id in
#{merchantIdItem}
and credit.c_user_id in
#{cUserIdItem}
select from wx_credit_history where id =#{id} and tenant_id = #{tenantId}
select
from wx_credit_history credit
where `tenant_id` = #{tenantId}
SELECT
credit.id ,credit.tenant_id ,credit.c_user_id ,credit.credit_amount ,credit.credit_num,credit.create_date,credit.credit_type,credit.receipt_url ,
credit.operator_type,credit.operator_id,credit.merchant_id,credit.ticket_number,credit.change_purpose
FROM wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
ORDER BY credit.create_date DESC
limit #{begin}, #{limit}
select COUNT(0) from wx_credit_history
where 1=1
and `c_user_id` = #{cUserId}
and `credit_type` = #{creditType}
and DATEDIFF(`create_date`,now())=0
select COUNT(0) from wx_credit_history
where 1=1
and `c_user_id` = #{cUserId}
and `credit_type` = #{creditType}
and DATE_FORMAT(`create_date`,'%Y%m') = DATE_FORMAT(CURDATE(),'%Y%m');
select count(0)
from wx_credit_history
where 1=1
and `tenant_id` = #{tenantId}
and `c_user_id` = #{cUserId}
and `credit_type` = #{creditType}
and DATEDIFF(`create_date`,now())=0
SELECT credit_amount FROM wx_credit_history where c_user_id = #{cUserId} ORDER BY create_date desc limit 1
select count(0)
from wx_credit_history
where 1=1
and `tenant_id` = #{tenantId}
and `c_user_id` = #{cUserId}
and `credit_type` = #{creditType}
select ifnull(sum(credit.credit_num),0) amount
from wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
and credit.credit_num>0
select ABS(ifnull(sum(credit.credit_num),0)) amount
from wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
and credit.credit_num < 0
select ifnull(sum(credit.credit_num),0) amount
from wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
and credit.credit_num > 0 and credit.c_user_id = #{cUserId}
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
select ifnull(sum(credit.credit_num),0) amount
from wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
and credit.credit_num < 0
and credit.c_user_id = #{cUserId}
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
select count(distinct credit.c_user_id) people
from wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
delete from wx_credit_history where id = #{id} and tenant_id = #{tenantId}
{call user_credit_clear(#{cutOffDate},#{finalTableIndex})}
select wm.id merchantId,wm.tenant_id tenantId,wm.parent_tenant_id parentTenantId,wm.name merchantName,IFNULL(a.sum_credit_num,0) sumAddCredit,
IFNULL(b.sum_credit_num,0) sumLesCredit,IFNULL(c.count_c_user_id,0) countAddCreditUser,
IFNULL(d.count_c_user_id,0) countLesCreditUser
from
(
select id,tenant_id,parent_tenant_id,name from wx_merchant
where is_del = 0
and `tenant_id` = #{tenantId}
and `parent_tenant_id` = #{parentTenantId}
) wm
left join
(
select credit.merchant_id,sum(credit.credit_num) sum_credit_num
from wx_credit_history${shardFinalTableSuffix} credit
where credit.merchant_id is not null
and credit.merchant_id != -1 and credit.credit_num > 0
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
GROUP BY credit.merchant_id
) a on a.merchant_id = wm.id
left join
(
select credit.merchant_id,sum(credit.credit_num) sum_credit_num
from wx_credit_history${shardFinalTableSuffix} credit
where credit.merchant_id is not null
and credit.merchant_id != -1 and credit.credit_num < 0
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
GROUP BY credit.merchant_id
) b on b.merchant_id = wm.id
left join
(
select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id
from wx_credit_history${shardFinalTableSuffix} credit
where credit.merchant_id is not null
and credit.merchant_id != -1 and credit.credit_num > 0
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
GROUP BY credit.merchant_id
) c on c.merchant_id = wm.id
left join
(
select credit.merchant_id,count(distinct credit.c_user_id) count_c_user_id
from wx_credit_history${shardFinalTableSuffix} credit
where credit.merchant_id is not null
and credit.merchant_id != -1 and credit.credit_num < 0
and credit.create_date >= #{startTime}
and credit.create_date <= #{endTime}
GROUP BY credit.merchant_id
) d on d.merchant_id = wm.id
where (IFNULL(a.sum_credit_num,0) > 0 or IFNULL(b.sum_credit_num,0) < 0)
ORDER BY sumAddCredit desc
select credit.c_user_id cUserId,ifnull(sum(credit.credit_num),0) creditNum
from wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
and credit.credit_num > 0
and credit.`c_user_id` in
#{uItem}
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
GROUP BY credit.`c_user_id`
select credit.c_user_id cUserId,ifnull(sum(credit.credit_num),0) creditNum
from wx_credit_history credit
where credit.`tenant_id` = #{tenantId}
and credit.credit_num < 0
and credit.`c_user_id` in
#{uItem}
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
GROUP BY credit.`c_user_id`