manual settle request

master
yixian 7 years ago
parent 4d2a27c2ca
commit de40d0d0ea

@ -11,6 +11,7 @@ import au.com.royalpay.payment.manage.bill.bean.QueryBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillOrderBean; import au.com.royalpay.payment.manage.bill.bean.QueryBillOrderBean;
import au.com.royalpay.payment.manage.bill.core.BillOrderService; import au.com.royalpay.payment.manage.bill.core.BillOrderService;
import au.com.royalpay.payment.manage.bill.core.BillService; import au.com.royalpay.payment.manage.bill.core.BillService;
import au.com.royalpay.payment.manage.settlement.core.ManualSettleSupport;
import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean; import au.com.royalpay.payment.manage.signin.beans.ChangePwdBean;
import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager;
import au.com.royalpay.payment.manage.system.core.ClientContractService; import au.com.royalpay.payment.manage.system.core.ClientContractService;
@ -22,6 +23,7 @@ import au.com.royalpay.payment.tools.http.HttpUtils;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.validation.Errors; import org.springframework.validation.Errors;
import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PathVariable;
@ -32,6 +34,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.text.ParseException;
import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -58,6 +62,8 @@ public class RetailAppController {
private AppActService appActService; private AppActService appActService;
@Resource @Resource
private ClientContractService clientContractService; private ClientContractService clientContractService;
@Resource
private ManualSettleSupport manualSettleSupport;
@RequestMapping(value = "/token", method = RequestMethod.PUT) @RequestMapping(value = "/token", method = RequestMethod.PUT)
public void updateDevToken(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject token) { public void updateDevToken(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject token) {
@ -346,8 +352,8 @@ public class RetailAppController {
} }
@RequestMapping(value = "/acts",method = RequestMethod.GET) @RequestMapping(value = "/acts", method = RequestMethod.GET)
public List<JSONObject> getIndexAct(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){ public List<JSONObject> getIndexAct(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) {
return appActService.listAppActs(); return appActService.listAppActs();
} }
@ -373,12 +379,31 @@ public class RetailAppController {
public JSONObject generateSourceAgreeFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) { public JSONObject generateSourceAgreeFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) {
JSONObject file = clientContractService.getSourceAgreement(device.getIntValue("client_id")); JSONObject file = clientContractService.getSourceAgreement(device.getIntValue("client_id"));
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("file_url",file.getString("file_value")); result.put("file_url", file.getString("file_value"));
return result; return result;
} }
@RequestMapping(value = "/file/agree/confirm", method = RequestMethod.POST) @RequestMapping(value = "/file/agree/confirm", method = RequestMethod.POST)
public void confirmSourceAgreeFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) { public void confirmSourceAgreeFile(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) {
clientContractService.confirmSourceAgreement(device.getIntValue("client_id"),device.getString("account_id"),"App"); clientContractService.confirmSourceAgreement(device.getIntValue("client_id"), device.getString("account_id"), "App");
}
@RequestMapping(value = "/manual_settle", method = RequestMethod.GET)
public JSONObject getManualSettleStatus(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) {
return manualSettleSupport.findCurrentSettle(device.getIntValue("client_id"), true);
}
@RequestMapping(value = "/manual_settle", method = RequestMethod.PUT)
public JSONObject requestManualSettle(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject data) {
String settleToStr = data.getString("settle_to");
if (settleToStr == null) {
throw new ParamInvalidException("settle_to", "error.payment.valid.param_missing");
}
try {
Date setteTo = DateUtils.parseDate(settleToStr, "yyyy-MM-dd");
return manualSettleSupport.requestManualSettle(setteTo, device.getString("account_id"));
} catch (ParseException e) {
throw new ParamInvalidException("settle_to", "error.payment.valid.invalid_time");
}
} }
} }

@ -0,0 +1,31 @@
package au.com.royalpay.payment.manage.mappers.payment;
import cn.yixblog.support.mybatis.autosql.annotations.AdvanceSelect;
import cn.yixblog.support.mybatis.autosql.annotations.AutoMapper;
import cn.yixblog.support.mybatis.autosql.annotations.AutoSql;
import cn.yixblog.support.mybatis.autosql.annotations.SqlType;
import com.alibaba.fastjson.JSONObject;
import org.apache.ibatis.annotations.Param;
import java.util.List;
/**
* Create by yixian at 2018-03-20 18:05
*/
@AutoMapper(tablename = "task_client_manual_settle", pkName = "task_id")
public interface TaskManualSettleMapper {
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "request_time>curdate()")
JSONObject findTodayTask(@Param("client_id") int clientId);
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "clearing_order is null")
List<JSONObject> listActiveTasks(@Param("client_id") int clientId);
@AutoSql(type = SqlType.INSERT)
void save(JSONObject task);
@AutoSql(type = SqlType.UPDATE)
void update(JSONObject task);
}

@ -128,4 +128,6 @@ public interface TransactionMapper {
List<JSONObject> getClientRank(@Param("begin") Date begin, @Param("end") Date end); List<JSONObject> getClientRank(@Param("begin") Date begin, @Param("end") Date end);
List<JSONObject> listClientUnsettleDataByDate(@Param("client_id") int clientId);
} }

@ -0,0 +1,16 @@
package au.com.royalpay.payment.manage.settlement.core;
import com.alibaba.fastjson.JSONObject;
import java.util.Date;
/**
* Create by yixian at 2018-03-20 17:42
*/
public interface ManualSettleSupport {
JSONObject requestManualSettle(Date settleTo, String accountId);
JSONObject findCurrentSettle(int clientId, boolean includingUnsettleData);
}

@ -0,0 +1,81 @@
package au.com.royalpay.payment.manage.settlement.core.impls;
import au.com.royalpay.payment.manage.mappers.log.ClearingLogMapper;
import au.com.royalpay.payment.manage.mappers.payment.TaskManualSettleMapper;
import au.com.royalpay.payment.manage.mappers.payment.TransactionMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
import au.com.royalpay.payment.manage.settlement.core.ManualSettleSupport;
import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
/**
* Create by yixian at 2018-03-20 17:44
*/
@Service
public class ManualSettleSupportImpl implements ManualSettleSupport {
@Resource
private MerchantInfoProvider merchantInfoProvider;
@Resource
private TransactionMapper transactionMapper;
@Resource
private TaskManualSettleMapper taskManualSettleMapper;
@Resource
private ClearingLogMapper clearingLogMapper;
@Resource
private ClientAccountMapper clientAccountMapper;
@Override
public JSONObject requestManualSettle(Date settleTo, String accountId) {
JSONObject account = clientAccountMapper.findById(accountId);
int clientId = account.getIntValue("client_id");
JSONObject client = merchantInfoProvider.getClientInfo(clientId);
if (!client.getBooleanValue("manual_settle")) {
throw new ForbiddenException("Manual Settlement Not Enabled");
}
if (DateUtils.isSameDay(new Date(), settleTo)) {
throw new BadRequestException("Cannot settle today's transactions");
}
JSONObject currentTask = findCurrentSettle(clientId, false);
String taskId = currentTask.getString("task_id");
currentTask.put("request_time", new Date());
currentTask.put("client_id", clientId);
currentTask.put("applier_id", account.getString("account_id"));
currentTask.put("applier_name", account.getString("display_name"));
currentTask.put("settle_to", settleTo);
if (taskId != null) {
taskManualSettleMapper.update(currentTask);
} else {
taskManualSettleMapper.save(currentTask);
}
return currentTask;
}
@Override
public JSONObject findCurrentSettle(int clientId, boolean includingUnsettleData) {
JSONObject todayTask = taskManualSettleMapper.findTodayTask(clientId);
if (todayTask != null) {
todayTask.put("settle_to", DateFormatUtils.format(todayTask.getDate("settle_to"), "yyyy-MM-dd"));
} else {
todayTask = new JSONObject();
}
List<JSONObject> settleLogs = clearingLogMapper.findByDate(new Date());
//今天未清算则锁定
todayTask.put("locked", settleLogs.isEmpty());
if (includingUnsettleData) {
List<JSONObject> unsettleReports = transactionMapper.listClientUnsettleDataByDate(clientId);
unsettleReports.parallelStream().forEach(report -> report.put("date_str", DateFormatUtils.format(report.getDate("trans_date"), "yyyy-MM-dd")));
todayTask.put("unsettle", unsettleReports);
}
return todayTask;
}
}

@ -0,0 +1,5 @@
/**
*
* Create by yixian at 2018-03-20 17:42
*/
package au.com.royalpay.payment.manage.settlement;

@ -31,7 +31,9 @@
<if test="trans_type==2">and t.refund_id is NOT NULL</if> <if test="trans_type==2">and t.refund_id is NOT NULL</if>
<if test="trans_type==3">and t.transaction_type='Debit' and t.refund_id is NULL</if> <if test="trans_type==3">and t.transaction_type='Debit' and t.refund_id is NULL</if>
<if test="channel!=null"> <if test="channel!=null">
and <foreach collection="channel" item="chan" open="(" close=")" separator=" or ">o.channel=#{chan}</foreach> and
<foreach collection="channel" item="chan" open="(" close=")" separator=" or ">o.channel=#{chan}
</foreach>
</if> </if>
</where> </where>
</select> </select>
@ -72,7 +74,9 @@
<if test="trans_type==2">and t.refund_id is NOT NULL</if> <if test="trans_type==2">and t.refund_id is NOT NULL</if>
<if test="trans_type==3">and t.transaction_type='Debit' and t.refund_id is NULL</if> <if test="trans_type==3">and t.transaction_type='Debit' and t.refund_id is NULL</if>
<if test="channel!=null"> <if test="channel!=null">
and <foreach collection="channel" item="chan" open="(" close=")" separator=" or ">o.channel=#{chan}</foreach> and
<foreach collection="channel" item="chan" open="(" close=")" separator=" or ">o.channel=#{chan}
</foreach>
</if> </if>
</where> </where>
order by t.transaction_time desc order by t.transaction_time desc
@ -95,14 +99,22 @@
sum(if(t.transaction_type='Debit' AND t.refund_id is NOT NULL and o.pre_authorization=1,t.clearing_amount,0)) sum(if(t.transaction_type='Debit' AND t.refund_id is NOT NULL and o.pre_authorization=1,t.clearing_amount,0))
pre_refund_fee, pre_refund_fee,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel != 'Settlement',t.settle_amount,if(t.channel != 'Settlement',-t.settle_amount,0))),0) total_settle_amount, ifnull(sum(if(t.transaction_type = 'Credit' and t.channel != 'Settlement',t.settle_amount,if(t.channel !=
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel != 'Settlement',t.royal_surcharge,if(t.channel != 'Settlement',-t.royal_surcharge,0))),0) total_royal_surcharge, 'Settlement',-t.settle_amount,0))),0) total_settle_amount,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel != 'Settlement',t.total_surcharge,if(t.channel != 'Settlement',-t.total_surcharge,0))),0) total_surcharge, ifnull(sum(if(t.transaction_type = 'Credit' and t.channel != 'Settlement',t.royal_surcharge,if(t.channel !=
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'Wechat',t.channel_surcharge,if(t.channel = 'Wechat',-t.channel_surcharge,0))),0) wechat_fee, 'Settlement',-t.royal_surcharge,0))),0) total_royal_surcharge,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'Alipay',t.channel_surcharge,if(t.channel = 'Alipay',-t.channel_surcharge,0))),0) alipay_fee, ifnull(sum(if(t.transaction_type = 'Credit' and t.channel != 'Settlement',t.total_surcharge,if(t.channel !=
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'jd',t.channel_surcharge,if(t.channel = 'jd',-t.channel_surcharge,0))),0) jd_fee, 'Settlement',-t.total_surcharge,0))),0) total_surcharge,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'Bestpay',t.channel_surcharge,if(t.channel = 'Bestpay',-t.channel_surcharge,0))),0) bestpay_fee, ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'Wechat',t.channel_surcharge,if(t.channel =
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'AlipayOnline',t.channel_surcharge,if(t.channel = 'AlipayOnline',-t.channel_surcharge,0))),0) alipay_online_fee 'Wechat',-t.channel_surcharge,0))),0) wechat_fee,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'Alipay',t.channel_surcharge,if(t.channel =
'Alipay',-t.channel_surcharge,0))),0) alipay_fee,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'jd',t.channel_surcharge,if(t.channel =
'jd',-t.channel_surcharge,0))),0) jd_fee,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'Bestpay',t.channel_surcharge,if(t.channel =
'Bestpay',-t.channel_surcharge,0))),0) bestpay_fee,
ifnull(sum(if(t.transaction_type = 'Credit' and t.channel = 'AlipayOnline',t.channel_surcharge,if(t.channel =
'AlipayOnline',-t.channel_surcharge,0))),0) alipay_online_fee
FROM pmt_transactions t FROM pmt_transactions t
left JOIN pmt_orders o on o.order_id=t.order_id left JOIN pmt_orders o on o.order_id=t.order_id
<where> <where>
@ -124,7 +136,9 @@
<if test="trans_type==2">and t.refund_id is NOT NULL</if> <if test="trans_type==2">and t.refund_id is NOT NULL</if>
<if test="trans_type==3">and t.transaction_type='Debit' and t.refund_id is NULL</if> <if test="trans_type==3">and t.transaction_type='Debit' and t.refund_id is NULL</if>
<if test="channel!=null"> <if test="channel!=null">
and <foreach collection="channel" item="chan" open="(" close=")" separator=" or ">o.channel=#{chan}</foreach> and
<foreach collection="channel" item="chan" open="(" close=")" separator=" or ">o.channel=#{chan}
</foreach>
</if> </if>
</where> </where>
</select> </select>
@ -172,12 +186,16 @@
<if test="to!=null">and t.transaction_time &lt; #{to}</if> <if test="to!=null">and t.transaction_time &lt; #{to}</if>
</select> </select>
<select id="listPreRefundClients" resultType="com.alibaba.fastjson.JSONObject"> <select id="listPreRefundClients" resultType="com.alibaba.fastjson.JSONObject">
select * SELECT *
from (select ifnull(sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)), 0) amount, c.client_id client_id,max(t.transaction_time) transation_time,c.client_moniker client_moniker FROM (SELECT
from pmt_transactions t INNER join sys_clients c ifnull(sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)), 0) amount,
on t.client_id = c.client_id and c.enable_refund_auth = 0 c.client_id client_id,
group by c.client_id) a max(t.transaction_time) transation_time,
where a.amount &lt; 0 c.client_moniker client_moniker
FROM pmt_transactions t INNER JOIN sys_clients c
ON t.client_id = c.client_id AND c.enable_refund_auth = 0
GROUP BY c.client_id) a
WHERE a.amount &lt; 0
</select> </select>
<select id="validAnalysis" resultType="com.alibaba.fastjson.JSONObject"> <select id="validAnalysis" resultType="com.alibaba.fastjson.JSONObject">
<![CDATA[ <![CDATA[
@ -279,7 +297,8 @@
<if test="to!=null">and t.transaction_time &lt; #{to}</if> <if test="to!=null">and t.transaction_time &lt; #{to}</if>
<if test="org_id!=null and org_ids==null">and c.org_id = #{org_id}</if> <if test="org_id!=null and org_ids==null">and c.org_id = #{org_id}</if>
<if test="org_ids!=null">and c.org_id in <if test="org_ids!=null">and c.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if> <foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
GROUP BY DATE(t.transaction_time) GROUP BY DATE(t.transaction_time)
order by t.clearing_time desc order by t.clearing_time desc
</select> </select>
@ -298,7 +317,8 @@
<if test="client_moniker!=null">and c.client_moniker=#{client_moniker}</if> <if test="client_moniker!=null">and c.client_moniker=#{client_moniker}</if>
<if test="org_id!=null and org_ids==null">and c.org_id = #{org_id}</if> <if test="org_id!=null and org_ids==null">and c.org_id = #{org_id}</if>
<if test="org_ids!=null">and c.org_id in <if test="org_ids!=null">and c.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if> <foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
GROUP BY c.client_id GROUP BY c.client_id
order by total desc order by total desc
</select> </select>
@ -317,7 +337,8 @@
<if test="client_moniker!=null">and c.client_moniker=#{client_moniker}</if> <if test="client_moniker!=null">and c.client_moniker=#{client_moniker}</if>
<if test="org_id!=null and org_ids==null">and c.org_id = #{org_id}</if> <if test="org_id!=null and org_ids==null">and c.org_id = #{org_id}</if>
<if test="org_ids!=null">and c.org_id in <if test="org_ids!=null">and c.org_id in
<foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach></if> <foreach collection="org_ids" item="org_id" open="(" close=")" separator=",">#{org_id}</foreach>
</if>
</select> </select>
<select id="getAusTracData" resultType="com.alibaba.fastjson.JSONObject"> <select id="getAusTracData" resultType="com.alibaba.fastjson.JSONObject">
@ -517,7 +538,7 @@
INNER JOIN sys_org so INNER JOIN sys_org so
ON c.referrer_id = so.org_id AND so.is_valid = 1 AND so.type = 1 AND so.commission = 1 ON c.referrer_id = so.org_id AND so.is_valid = 1 AND so.type = 1 AND so.commission = 1
WHERE year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} AND t.channel != 'Settlement' WHERE year(t.transaction_time) = #{year} AND month(t.transaction_time) = #{month} AND t.channel != 'Settlement'
GROUP BY so.org_id, trade_date,t.client_id GROUP BY so.org_id, trade_date, t.client_id
ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC ORDER BY c.org_id ASC, t.client_id ASC, trade_date ASC
</select> </select>
@ -676,7 +697,8 @@
select sum(if(t.transaction_type='Credit',settle_amount,-settle_amount)) settle_amount , select sum(if(t.transaction_type='Credit',settle_amount,-settle_amount)) settle_amount ,
DATE_FORMAT(t.transaction_time,'%Y%m%d') weekend DATE_FORMAT(t.transaction_time,'%Y%m%d') weekend
from pmt_transactions t from pmt_transactions t
INNER JOIN log_clearing_detail d on d.clear_detail_id=t.clearing_order and DAYOFWEEK(d.report_date)>2 and clear_days = 1 INNER JOIN log_clearing_detail d on d.clear_detail_id=t.clearing_order and DAYOFWEEK(d.report_date)>2 and
clear_days = 1
where (DAYOFWEEK(t.transaction_time)=1 or DAYOFWEEK(t.transaction_time) = 7) where (DAYOFWEEK(t.transaction_time)=1 or DAYOFWEEK(t.transaction_time) = 7)
<if test="begin!=null"> <if test="begin!=null">
and t.transaction_time &gt; #{begin} and t.transaction_time &gt; #{begin}
@ -722,5 +744,15 @@
and t.clearing_order is not NULL and t.clearing_order is not NULL
group by client_id group by client_id
</select> </select>
<select id="listClientUnsettleDataByDate" resultType="com.alibaba.fastjson.JSONObject">
SELECT
date(transaction_time) trans_date,
sum(if(transaction_type = 'Credit', clearing_amount, -clearing_amount)) clearing_amount,
sum(if(transaction_type = 'Credit', settle_amount, -settle_amount)) settle_amount
FROM pmt_transactions t
WHERE t.client_id = #{client_id} AND t.clearing_status = 0
GROUP BY trans_date
ORDER BY trans_date DESC
</select>
</mapper> </mapper>
Loading…
Cancel
Save