`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`
where 1 = 1
and `id` = #{id}
and `tenant_id` = #{tenantId}
and `c_user_id` = #{cUserId}
and `credit_amount` = #{creditAmount}
and `credit_num` = #{creditNum}
and `credit_type` = #{creditType}
and `receipt_url` like concat('%', #{receiptUrl},'%')
and `operator_type` = #{operatorType}
and `operator_id` = #{operatorId}
and `merchant_id` = #{merchantId}
and `coupon_id` = #{couponId}
and `business_id` = #{businessId}
and `spend` = #{spend}
and `change_purpose` = #{changePurpose}
and ticket_number like concat('%', #{ticketNumber},'%')
and `buser_id` = #{buserId}
and id in
#{idItem}
order by ${sortColumns}
where 1 = 1
and basic.nick_name like concat('%', #{name},'%')
and basic.phone like concat('%', #{phone},'%')
and credit.create_date >= #{startTime}
and credit.create_date < #{endTime}
and credit.`tenant_id` = #{tenantId}
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 merchant.name like concat('%', #{merchantName},'%')
and credit.ticket_number like concat('%', #{ticketNumber},'%')
and credit.buser_id = #{buserId}
select from wx_credit_history where id =#{id} and tenant_id = #{tenantId}
select from wx_credit_history
SELECT
credit.id creditId,
case when basic.nick_name is null then basic.name else basic.nick_name end name,
basic.phone phone,
basic.sex sex,
credit.tenant_id tenantId,
credit.c_user_id cUserId,
credit.credit_amount creditAmount,
credit.credit_num creditNum,
credit.create_date createDate,
credit.credit_type creditType,
credit.receipt_url receiptUrl,
credit.operator_type operatorType,
credit.operator_id operatorId,
merchant.NAME merchantName,
credit.merchant_id merchantId,
credit.ticket_number ticketNumber,
case when credit.operator_type=4 then (select name from mall_user_info where id=credit.operator_id)
when credit.operator_type=3 then (select name from wx_merchant_b_user where id=credit.operator_id)
when credit.operator_type=2 then (select nick_name from wx_c_user_basic_info where id=credit.operator_id)
else '' end operator,
credit.change_purpose changePurpose
FROM
wx_c_user_basic_info basic
INNER JOIN wx_credit_history credit ON basic.id = credit.c_user_id
LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
ORDER BY
credit.create_date desc,credit.id DESC
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 `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 id 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.amount),0) amount from (
select basic.credit as amount,credit.c_user_id from wx_credit_history credit
INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
group by credit.c_user_id
) credit
select ifnull(sum(credit.credit_num),0) amount from wx_credit_history credit
INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
and credit.credit_num>0
select ABS(ifnull(sum(credit.credit_num),0)) amount from wx_credit_history credit
INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
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(1) people from (
select count(*) people from wx_credit_history credit
INNER JOIN wx_c_user_basic_info basic ON basic.id = credit.c_user_id
LEFT JOIN wx_merchant merchant ON credit.merchant_id = merchant.id
group by credit.c_user_id
) credit
delete from wx_credit_history where id = #{id} and tenant_id = #{tenantId}
{call user_credit_clear(#{cutOffDate},#{finalTableIndex})}
select wm.id merchantId,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,name from wx_merchant
where is_del = 0
and `tenant_id` = #{tenantId}
and `parent_tenant_id` = #{parentTenantId}
) wm
left join
(
select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix}
where merchant_id is not null and merchant_id != -1 and credit_num > 0
and create_date >= #{startTime}
and create_date < #{endTime}
GROUP BY merchant_id
) a on a.merchant_id = wm.id
left join
(
select merchant_id,sum(credit_num) sum_credit_num from wx_credit_history${shardFinalTableSuffix}
where merchant_id is not null and merchant_id != -1 and credit_num < 0
and create_date >= #{startTime}
and create_date < #{endTime}
GROUP BY merchant_id
) b on b.merchant_id = wm.id
left join
(
select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix}
where merchant_id is not null and merchant_id != -1 and credit_num > 0
and create_date >= #{startTime}
and create_date < #{endTime}
GROUP BY merchant_id
) c on c.merchant_id = wm.id
left join
(
select merchant_id,count(distinct c_user_id) count_c_user_id from wx_credit_history${shardFinalTableSuffix}
where merchant_id is not null and merchant_id != -1 and credit_num < 0
and create_date >= #{startTime}
and create_date < #{endTime}
GROUP BY merchant_id
) d on d.merchant_id = wm.id
ORDER BY sumAddCredit desc