You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

560 lines
26 KiB

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.demo.mapper.cash.CashCollectionMapper">
<insert id="add" parameterType="com.example.demo.domain.entity.CashRecord"
useGeneratedKeys="true" keyProperty="id">
insert into
cash_record_collection(order_type,jwcode,name,market,activity,
order_code,bank_code,goods_name,good_num,num_unit,permanent_gold,free_gold,
payment_currency,payment_amount,received_market,
pay_type,pay_time,status,submitter_id,submitter_market,payload,audit_time,
voucher,remark,wallet_id)
values(#{orderType},#{jwcode},#{name},#{market},#{activity},
#{orderCode},#{bankCode},#{goodsName},#{goodNum},#{numUnit},#{permanentGold},#{freeGold},#{paymentCurrency},
#{paymentAmount},#{receivedMarket},#{payType},#{payTime},
#{status},#{submitterId},#{submitterMarket},#{payload},#{auditTime},#{voucher},#{remark},#{walletId})
</insert>
<!-- <insert id="syncToCashRecord">
insert into cash_record(order_type,jwcode,name,market,activity,
order_code,goods_name,good_num,permanent_gold,free_gold,
payment_currency,payment_amount,received_market,
pay_type,pay_time,status,submitter_id,
voucher,remark)
values(1,#{jwcode},#{name},#{market},#{activity},
#{order_code},#{goods_name},#{good_num},#{permanent}
)
</insert>-->
<!--更新订单状态-->
<update id="updateStatus">
update cash_record_collection
set status=#{status}
where order_code=#{orderCode}
</update>
<!--更新订单-->
<update id="updateByOrderCode">
UPDATE cash_record_collection
<set>
jwcode = #{cashRecordCollection.jwcode},
name = #{cashRecordCollection.name},
market = #{cashRecordCollection.market},
activity = #{cashRecordCollection.activity},
goods_name = #{cashRecordCollection.goodsName},
good_num = #{cashRecordCollection.goodNum},
num_unit = #{cashRecordCollection.numUnit},
permanent_gold = #{cashRecordCollection.permanentGold},
free_gold = #{cashRecordCollection.freeGold},
payment_currency = #{cashRecordCollection.paymentCurrency},
payment_amount = #{cashRecordCollection.paymentAmount},
received_market = #{cashRecordCollection.receivedMarket},
pay_type = #{cashRecordCollection.payType},
pay_time = #{cashRecordCollection.payTime},
voucher = #{cashRecordCollection.voucher},
remark = #{cashRecordCollection.remark},
status = 0,
</set>
WHERE order_code = #{cashRecordCollection.orderCode}
AND status = 5
</update>
<!--补全手续费等字段-->
<update id="complete">
UPDATE cash_record_collection
<set>
handling_charge = #{cashRecordCollection.handlingCharge},
received_currency = #{cashRecordCollection.receivedCurrency},
<if test="cashRecordCollection.receivedAmount != 0">
received_amount = #{cashRecordCollection.receivedAmount},
</if>
received_time = #{cashRecordCollection.receivedTime},
payment_currency = #{cashRecordCollection.paymentCurrency},
<if test="cashRecordCollection.paymentAmount != 0">
payment_amount = #{cashRecordCollection.paymentAmount},
</if>
payment_currency_orig = #{cashRecordCollection.paymentCurrencyOrig},
<if test="cashRecordCollection.paymentAmountOrig != 0">
payment_amount_orig = #{cashRecordCollection.paymentAmountOrig},
</if>
<!-- 只有 这些字段全部非空才更新状态 -->
status = CASE
WHEN
handling_charge IS NOT NULL
AND received_currency IS NOT NULL AND received_currency != ''
AND received_amount IS NOT NULL
AND received_time IS NOT NULL
AND payment_currency IS NOT NULL AND payment_currency != ''
AND payment_amount IS NOT NULL
THEN 4
ELSE status
END
</set>
WHERE order_code = #{cashRecordCollection.orderCode}
AND status IN (1, 3)
</update>
<!--提交手续费时修改金币订单-->
<update id="updateGoldOrder">
UPDATE user_gold_record
<set>
rate_id=#{cashRecordCollection.paymentCurrency},
<if test="cashRecordCollection.paymentAmount != 0">
money = #{cashRecordCollection.paymentAmount}
</if>
</set>
WHERE order_code = #{cashRecordCollection.orderCode}
</update>
<!--设置gOrder订单为已同步-->
<update id="markSynced">
update g_order
set is_synced = 1
where id = #{orderId}
</update>
<!-- 检查用户是否存在 -->
<select id="checkUserExists" resultType="int">
SELECT COUNT(*)
FROM user
WHERE jwcode = #{jwcode}
</select>
<!--根据jwcode获取所属地区-->
<select id="getMarketByJwcode" resultType="java.lang.String">
select market from user where jwcode=#{jwcode}
</select>
<!--根据订单号获取订单id、状态、钱包id、永久金币数量、精网号和备注-->
<select id="selectByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
select id ,status, wallet_id, permanent_gold, jwcode, remark
from cash_record_collection
where order_code=#{orderCode}
</select>
<!--多条件查询收款订单列表-->
<select id="selectCollection1" resultType="com.example.demo.domain.vo.cash.CashCollection">
select cr.order_type, cr.id,cr.jwcode,cr.name,cr.market,
m1.name as marketName, ra.id as activityId,
ra.activity_name as activity,cr.order_code,cr.bank_code,
cr.goods_name,cr.good_num,
cr.num_unit,
cr.permanent_gold/100 as permanentGold,cr.free_gold/100 as freeGold,cr.payment_amount/100 as paymentAmount,
r1.rate_name as paymentCurrency,
r2.rate_name as receivedCurrency,
m2.name as receivedMarket,
cr.received_amount/100 as receivedAmount,cr.handling_charge/100 as handlingCharge,
cr.pay_type,cr.pay_time,cr.received_time,
cr.status,cr.submitter_id,cr.submitter_market,cr.voucher,cr.remark,cr.reject_reason,
cr.audit_id,cr.create_time,cr.update_time,cr.audit_time,
a1.admin_name as submitterName,
a2.admin_name as auditName
from cash_record_collection cr
left join admin a1 on cr.submitter_id = a1.id
left join admin a2 on cr.audit_id = a2.id
left join market m1 on m1.id = cr.market
left join market m2 on m2.id = cr.received_market
left join rate r1 on r1.id = cr.payment_currency
left join rate r2 on r2.id = cr.received_currency
left join recharge_activity ra on ra.id = cr.activity
<where>
1 = 1
<if test="cashCollection.market != null and cashCollection.market != ''">
AND cr.market = #{cashCollection.market}
</if>
<if test="cashCollection.jwcode != null and cashCollection.jwcode!=''">
AND cr.jwcode = #{cashCollection.jwcode}
</if>
<if test="cashCollection.name!=null and cashCollection.name !=''">
AND cr.name like concat('%',#{cashCollection.name},'%')
</if>
<if test="cashCollection.submitterId!=null and cashCollection.submitterId !=''">
AND cr.submitter_id = #{cashCollection.submitterId}
</if>
<!-- 其他原有条件不变 -->
<choose>
<when test="cashCollection.status != null and (cashCollection.status == 46||cashCollection.status == 13)">
<if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
AND (cr.received_market = #{cashCollection.receivedMarket}
<if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
OR cr.submitter_market = #{cashCollection.submitterMarket}
</if>
)
</if>
<if test="(cashCollection.receivedMarket == null or cashCollection.receivedMarket == '')
and cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
AND cr.submitter_market = #{cashCollection.submitterMarket}
</if>
</when>
<!-- 非 status=46 保持原逻辑:同时满足 -->
<otherwise>
<if test="cashCollection.receivedMarket != null and cashCollection.receivedMarket != ''">
AND cr.received_market = #{cashCollection.receivedMarket}
</if>
<if test="cashCollection.submitterMarket != null and cashCollection.submitterMarket != ''">
AND cr.submitter_market = #{cashCollection.submitterMarket}
</if>
</otherwise>
</choose>
<if test="cashCollection.activity!=null and cashCollection.activity!=''">
AND cr.activity =#{cashCollection.activity}
</if>
<if test="cashCollection.paymentCurrency!=null and cashCollection.paymentCurrency!=''">
AND cr.payment_currency like concat('%',#{cashCollection.paymentCurrency},'%')
</if>
<if test="cashCollection.goodsName!=null and cashCollection.goodsName!=''">
AND cr.goods_name like concat('%',#{cashCollection.goodsName},'%')
</if>
<if test="cashCollection.payType!=null and cashCollection.payType!=''">
AND cr.pay_type = #{cashCollection.payType}
</if>
<if test="cashCollection.status != null">
AND cr.status IN
<foreach collection="cashCollection.status.toString().toCharArray()" item="digit" open="(" separator="," close=")">
#{digit}
</foreach>
</if>
<if test="cashCollection.startTime!=null and cashCollection.endTime!=null">
AND cr.pay_time between #{cashCollection.startTime} and #{cashCollection.endTime}
</if>
and cr.order_type=1
</where>
<choose>
<when test="cashCollection.sortField != null and cashCollection.sortField.length > 0 or cashCollection.sortOrder != null and cashCollection.sortOrder.length > 0">
ORDER BY ${cashCollection.sortField} ${cashCollection.sortOrder}
</when>
<otherwise>
ORDER BY pay_time DESC
</otherwise>
</choose>
</select>
<select id="selectAuditByOrderCode" resultType="com.example.demo.domain.entity.CashRecord">
select crc.id,jwcode,name,market,ra.activity_name as activity,
order_code,bank_code,goods_name,good_num,num_unit,permanent_gold,free_gold,
payment_currency,payment_amount,pay_type,pay_time,crc.status,submitter_id,
voucher,remark,version,received_market
from cash_record_collection crc
left join recharge_activity ra on ra.id = crc.activity
where order_code=#{orderCode}
</select>
<!--根据精网号获取姓名-->
<select id="getNameByJwcode" resultType="java.lang.String">
select name from user where jwcode=#{jwcode}
</select>
<select id="getMarketNameByJwcode" resultType="java.lang.String">
select m.name from user u left join market m on u.market=m.id
where u.jwcode=#{jwcode}</select>
<select id="getActivityList" resultType="com.example.demo.domain.entity.RechargeActivity">
select ra.id,ra.activity_name,ra.business_belong,m.name as area,ra.status
from recharge_activity ra
left join market m on m.id=ra.area
where ra.flag=1 and ra.status=1 and #{now} between start_time and end_time
</select>
<!--查找未同步的订单-->
<select id="getUnSync" resultType="com.example.demo.domain.entity.GOrder">
select id,jwcode,order_no,type,price,count,pay_style,state,
success_time,ios_environment,ios_transaction_id,ios_receipt_data,firstdata_ipgTransactionId,
add_time,is_synced
from g_order
where is_synced=0 and state=1 and pay_style in(3,5,6,7,9,10,15)
and success_time>=1767196800
limit #{size}
</select>
<select id="selectById" resultType="com.example.demo.domain.vo.cash.CashCollection">
select cr.id,cr.jwcode,cr.name,cr.market,
cr.order_code,cr.bank_code,cr.goods_name,cr.good_num,cr.num_unit,cr.permanent_gold,cr.free_gold,
cr.payment_currency,cr.payment_amount,cr.received_currency,cr.received_amount,cr.handling_charge,
cr.pay_type,cr.received_market,cr.pay_time,cr.received_time,cr.audit_id,cr.status,cr.submitter_id,
cr.submitter_market,cr.voucher,cr.remark,cr.audit_time,a1.admin_name as submitterName,
a2.admin_name as auditName,ra.activity_name as activity
from cash_record_collection cr
left join admin a1 on cr.submitter_id = a1.id
left join admin a2 on cr.audit_id = a2.id
left join recharge_activity ra on ra.id = cr.activity
where cr.id=#{id}
</select>
<!--根据id查询收款订单-->
<select id="selectBatchIds" resultType="com.example.demo.domain.vo.cash.CashCollection">
select
cr.id, cr.jwcode, cr.name, cr.market,
cr.order_code, cr.bank_code, cr.goods_name, cr.good_num, cr.num_unit, cr.permanent_gold, cr.free_gold,
cr.payment_amount, cr.received_amount, cr.handling_charge,
cr.pay_type, cr.received_market, cr.pay_time, cr.received_time, cr.audit_id, cr.status, cr.submitter_id,
cr.submitter_market, cr.voucher, cr.remark, cr.audit_time,
a1.admin_name as submitterName,
a2.admin_name as auditName,
ra.activity_name as activity,
r1.rate_name as paymentCurrency,
r2.rate_name as receivedCurrency
from cash_record_collection cr
left join admin a1 on cr.submitter_id = a1.id
left join admin a2 on cr.audit_id = a2.id
left join recharge_activity ra on ra.id = cr.activity
left join rate r1 on r1.id = cr.payment_currency
left join rate r2 on r2.id = cr.received_currency
where 1 = 0
<if test="relatedIds != null and relatedIds.size() > 0">
OR cr.id IN
<foreach collection="relatedIds" item="id" open="(" separator="," close=")">
#{id}
</foreach>
</if>
</select>
<select id="selectByGoldCoinOrderCode" resultType="com.example.demo.domain.vo.cash.CashCollection">
select * from cash_record_collection where order_no=#{orderNo}
</select>
<!--根据glodcoin订单号更新收款订单-->
<update id="updateByGoldCoinOrderCode">
update cash_record_collection
<set>
received_time=#{time},
payment_currency=#{currency},
received_currency=#{currency},
payment_amount=#{order_amount},
received_amount=#{net_amount},
handling_charge=#{charge},
order_no_status=0
</set>
where order_code=#{merchant_reference}
</update>
<update id="updateOrderWithVersion">
UPDATE cash_record_collection
SET status = #{status},
audit_id = #{auditId},
version = version + 1
WHERE order_code = #{orderCode}
AND status = 0
AND version = #{version}
</update>
<select id="performanceSelect" resultType="com.example.demo.domain.vo.cash.PerformanceVO" parameterType="com.example.demo.domain.DTO.PerformanceDTO">
select cr.jwcode,cr.name,cr.market,m.name as marketName,cr.order_code,r1.rate_name as paymentCurrency,cr.payment_amount,r2.rate_name as receivedCurrency,cr.received_amount,cr.handling_charge
from cash_record_collection cr
left join market m on m.id = cr.market
left join rate r1 on r1.id = cr.payment_currency
left join rate r2 on r2.id = cr.received_currency
where order_type = 1 and status = 4
<!-- adminMarket筛选:如果adminMarket列表不为空且不包含研发部或总部,则筛选market表中的name等于adminMarket列表中的内容 -->
<if test="adminMarket != null and adminMarket.size() > 0">
<choose>
<when test="adminMarket.contains('研发部'.toString()) or adminMarket.contains('总部'.toString())">
<!-- 如果包含研发部或总部,则不筛选 -->
</when>
<otherwise>
AND m.name IN
<foreach collection="adminMarket" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</otherwise>
</choose>
</if>
<!-- customerMarket筛选:如果customerMarket列表不为空,则筛选cash_record_collection表中的market等于customerMarket列表中的内容 -->
<if test="customerMarket != null and customerMarket.size() > 0">
AND cr.market IN
<foreach collection="customerMarket" item="item" open="(" separator="," close=")">
#{item}
</foreach>
</if>
<!-- jwcode筛选:如果jwcode不为空,则筛选cash_record_collection表中的jwcode等于jwcode -->
<if test="jwcode != null and jwcode != ''">
AND cr.jwcode = #{jwcode}
</if>
<!-- 时间范围筛选:如果startTime和endTime不为空,则筛选cash_record_collection表中的pay_time在startTime和endTime之间 -->
<if test="startTime != null and endTime != null">
AND cr.pay_time BETWEEN #{startTime} AND #{endTime}
</if>
</select>
<select id="selectByBankCode" resultType="com.example.demo.domain.vo.cash.CashCollection">
select * from cash_record_collection where bank_code=#{bankCode}
</select>
<select id="selectFirstdataList" resultType="java.lang.String">
select bank_code from cash_record_collection where bank_code is not null and payload='FirstData' and order_no_status=1
</select>
<select id="selectStripeList" resultType="java.lang.String">
select order_code from cash_record_collection where payload='Stripe' and order_no_status=1
</select>
<select id="selectStripe2List" resultType="java.lang.String">
select order_code from cash_record_collection where payload='Stripe2' and order_no_status=1
</select>
<select id="selectPaymentList" resultType="java.lang.String">
select order_code from cash_record_collection where payload='PaymentAsia' and order_no_status=1
</select>
<select id="selectIpayList" resultType="com.example.demo.domain.vo.cash.CashCollection">
select order_code,permanent_gold from cash_record_collection where payload='Ipay88' and order_no_status=1
</select>
<!--根据订单号获取商品名称-->
<select id="selectGoodsNameByCode" resultType="java.lang.String">
select goods_name from cash_record_collection where order_code=#{orderCode}
</select>
<!-- 根据 jwcode 和 walletId 查询用户钱包 -->
<select id="selectUserWallet" resultType="com.example.demo.domain.entity.UserRegionWallet">
SELECT id, jwcode, wallet_id, current_permanent_gold, create_time, update_time
FROM user_region_wallet
WHERE jwcode = #{jwcode} AND wallet_id = #{walletId}
</select>
<!-- 增加用户钱包永久金币 -->
<update id="addUserWalletPermanentGold">
UPDATE user_region_wallet
SET current_permanent_gold = current_permanent_gold + #{amount},
update_time = NOW()
WHERE jwcode = #{jwcode} AND wallet_id = #{walletId}
</update>
<!-- 如果钱包记录不存在则插入 -->
<insert id="insertUserWallet" parameterType="com.example.demo.domain.entity.UserRegionWallet">
INSERT INTO user_region_wallet (jwcode, wallet_id, current_permanent_gold, create_time, update_time)
VALUES (#{jwcode}, #{walletId}, #{currentPermanentGold}, NOW(), NOW())
ON DUPLICATE KEY UPDATE
current_permanent_gold = current_permanent_gold + VALUES(current_permanent_gold),
update_time = NOW()
</insert>
<!-- 插入用户钱包明细记录 -->
<insert id="insertUserWalletRecord" parameterType="com.example.demo.domain.entity.UserWalletRecord">
INSERT INTO user_wallet_record (jwcode, wallet_id, type, amount, order_code, description, status, create_time)
VALUES (#{jwcode}, #{walletId}, #{type}, #{amount}, #{orderCode}, #{description}, #{status}, NOW())
</insert>
<!-- 根据精网号和钱包 ID 查询用户钱包明细列表 -->
<select id="selectWalletRecordsByJwcodeAndWalletId" resultType="com.example.demo.domain.vo.cash.UserWalletRecordVO">
SELECT
uwr.id,
uwr.jwcode,
u.name as userName,
u.market,
m.name as marketName,
uwr.wallet_id,
w.wallet_name as walletName,
uwr.type,
uwr.amount,
uwr.order_code as orderCode,
uwr.description,
uwr.status,
uwr.create_time as createTime
FROM user_wallet_record uwr
LEFT JOIN user u ON uwr.jwcode = u.jwcode
LEFT JOIN market m ON u.market = m.id
LEFT JOIN wallet w ON uwr.wallet_id = w.id
WHERE uwr.jwcode = #{jwcode}
<if test="walletId != null">
AND uwr.wallet_id = #{walletId}
</if>
ORDER BY uwr.create_time DESC
</select>
<!-- 根据精网号和地区查询用户的所有钱包 ID 和金币数量(包含用户名和地区) -->
<resultMap id="UserWalletVOResultMap" type="com.example.demo.domain.vo.cash.UserWalletVO">
<id property="jwcode" column="jwcode"/>
<result property="userName" column="userName"/>
<result property="market" column="market"/>
<result property="marketName" column="marketName"/>
<collection property="walletList" ofType="com.example.demo.domain.vo.cash.WalletItem">
<id property="walletId" column="walletId"/>
<result property="walletName" column="walletName"/>
<result property="currentPermanentGold" column="currentPermanentGold"/>
</collection>
</resultMap>
<select id="selectUserWallets" resultMap="UserWalletVOResultMap">
SELECT
u.jwcode,
u.name as userName,
u.market,
m.name as marketName,
wr.wallet_id as walletId,
w.wallet_name as walletName,
COALESCE(wr.current_permanent_gold, 0) as currentPermanentGold
FROM user u
LEFT JOIN market m ON u.market = m.id
LEFT JOIN user_region_wallet wr ON u.jwcode = wr.jwcode
LEFT JOIN wallet w ON wr.wallet_id = w.id
<where>
<if test="jwcode != null">
AND u.jwcode = #{jwcode}
</if>
<if test="market != null and market != ''">
AND u.market = #{market}
</if>
</where>
ORDER BY u.jwcode, wr.wallet_id
</select>
<!--根据OrderCode订单号更新收款订单-->
<update id="updateByGoldCoinOrderCodeByPayment">
update cash_record_collection
SET
received_time=#{time},
payment_currency='2',
received_currency='2',
payment_amount=#{order_amount},
received_amount=#{net_amount},
handling_charge=#{charge},
status=4,
order_no_status=0
where order_code=#{merchant_reference}
</update>
<!--根据OrderCode订单号更新收款订单-->
<update id="updateByGoldCoinOrderCodeByStripe">
update cash_record_collection
SET
received_time=#{availableOn},
payment_currency='2',
received_currency='2',
payment_amount=#{amount},
received_amount=#{net},
handling_charge=#{fee},
status=4,
order_no_status=0
where order_code=#{orderNo}
</update>
<!--根据OrderCode订单号更新收款订单-->
<update id="updateByGoldCoinOrderCodeByStripe2">
update cash_record_collection
SET
received_time=#{availableOn},
payment_currency='3',
received_currency='3',
payment_amount=#{amount},
received_amount=#{net},
handling_charge=#{fee},
status=4,
order_no_status=0
where order_code=#{orderNo}
</update>
<update id="updateByGoldCoinOrderCodeByFirstdata">
update cash_record_collection
SET
payment_currency='3',
received_currency='3',
payment_amount=#{amount},
received_amount=#{net},
handling_charge=#{fee},
status=4,
order_no_status=0
where order_code=#{orderId}
</update>
<update id="updateByGoldCoinOrderCodeByIpay88">
update cash_record_collection
SET
payment_currency='4',
received_currency='4',
payment_amount=#{amount},
received_amount=#{net},
handling_charge=#{fee},
status=4,
order_no_status=0
where order_code=#{orderNo}
</update>
<update id="updateMessageFlagByTypeIdAndType">
UPDATE message
SET flag = #{flag}
WHERE type_id = #{typeId} AND type = #{type}
</update>
</mapper>