Commit 4b4890f9 by guanchen

合伙人 代理商 收入结算

parent 14660b73
...@@ -67,6 +67,7 @@ public class Constants { ...@@ -67,6 +67,7 @@ public class Constants {
*/ */
public static final int REWARD_STATUS_UNSETTLE = 100; public static final int REWARD_STATUS_UNSETTLE = 100;
public static final int REWARD_STATUS_SETTLE = 120; public static final int REWARD_STATUS_SETTLE = 120;
public static final int REWARD_STATUS_FAILED = 99;
/** /**
* 最小奖励金额 小于此不写入 * 最小奖励金额 小于此不写入
*/ */
......
...@@ -6,6 +6,7 @@ import com.lanren.huhu.partner.model.AgentResponse; ...@@ -6,6 +6,7 @@ import com.lanren.huhu.partner.model.AgentResponse;
import com.lanren.huhu.partner.model.ParentAgent; import com.lanren.huhu.partner.model.ParentAgent;
import com.lanren.huhu.partner.result.Result; import com.lanren.huhu.partner.result.Result;
import com.lanren.huhu.partner.schedule.AgentDailyExpandTask; import com.lanren.huhu.partner.schedule.AgentDailyExpandTask;
import com.lanren.huhu.partner.schedule.AgentSettleTask;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
...@@ -28,6 +29,8 @@ public class AgentController { ...@@ -28,6 +29,8 @@ public class AgentController {
AgentManager agentManager; AgentManager agentManager;
@Autowired @Autowired
AgentDailyExpandTask agentDailyExpandTask; AgentDailyExpandTask agentDailyExpandTask;
@Autowired
AgentSettleTask agentSettleTask;
@RequestMapping(value = "/level", method = RequestMethod.POST) @RequestMapping(value = "/level", method = RequestMethod.POST)
public Result<AgentResponse> getAgentLevel(@RequestBody @Valid Agent agent, @RequestHeader HttpHeaders headers) { public Result<AgentResponse> getAgentLevel(@RequestBody @Valid Agent agent, @RequestHeader HttpHeaders headers) {
...@@ -76,4 +79,15 @@ public class AgentController { ...@@ -76,4 +79,15 @@ public class AgentController {
} }
return agentManager.doFinanceSettle(agent.getAgentId()); return agentManager.doFinanceSettle(agent.getAgentId());
} }
/**
* 结算全部代理商
*/
@RequestMapping(value = "/finance", method = RequestMethod.GET)
public Result<String> doFinanceSettle(@RequestHeader HttpHeaders headers) {
agentSettleTask.runScheduledTask();
logger.info("============>" + Thread.currentThread().getName());
Result<String> result = new Result<String>();
result.setData("异步,正在执行刷新......");
return result;
}
} }
package com.lanren.huhu.partner.controller; import com.lanren.huhu.partner.manager.PartnerManager;import com.lanren.huhu.partner.model.Partner;import com.lanren.huhu.partner.model.PartnerResponse;import com.lanren.huhu.partner.result.Result;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.HttpHeaders;import org.springframework.web.bind.annotation.*; import javax.validation.Valid;import java.time.LocalDateTime; /** * @Author houseme * @Date 2019-06-26 11:00 * @Project partner * @Package com.lanren.huhu.partner.controller * @File: PartnerController */@RestController@RequestMapping("/v1/partner")public class PartnerController { private static Logger logger = LoggerFactory.getLogger(PartnerController.class); @Autowired private PartnerManager partnerManager; @RequestMapping(value = "/level", method = RequestMethod.POST) public Result<PartnerResponse> getPartnerLevel(@RequestBody @Valid Partner partner, @RequestHeader HttpHeaders headers) { if (logger.isInfoEnabled()) { logger.info("getPartnerLevel userId:{},header:{},time:{}", partner.getUserId(), headers.keySet().toArray(), LocalDateTime.now()); } return partnerManager.getPartnerLevel(partner.getUserId()); } /** * 测试使用 结算单个用户 */ @RequestMapping(value = "/finance", method = RequestMethod.POST) public Result<String> doFinanceSettle(@RequestBody @Valid Partner partner, @RequestHeader HttpHeaders headers) { if (logger.isInfoEnabled()) { logger.info("doFinanceSettle userId:{},header:{},time:{}", partner.getUserId(), headers.keySet().toArray(), LocalDateTime.now()); } return partnerManager.doFinanceSettle(partner.getUserId()); }} package com.lanren.huhu.partner.controller; import com.lanren.huhu.partner.manager.PartnerManager;import com.lanren.huhu.partner.model.Partner;import com.lanren.huhu.partner.model.PartnerResponse;import com.lanren.huhu.partner.result.Result;import com.lanren.huhu.partner.schedule.PartnerSettleTask;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.http.HttpHeaders;import org.springframework.web.bind.annotation.*; import javax.validation.Valid;import java.time.LocalDateTime; /** * @Author houseme * @Date 2019-06-26 11:00 * @Project partner * @Package com.lanren.huhu.partner.controller * @File: PartnerController */@RestController@RequestMapping("/v1/partner")public class PartnerController { private static Logger logger = LoggerFactory.getLogger(PartnerController.class); @Autowired private PartnerManager partnerManager; @Autowired private PartnerSettleTask partnerSettleTask; @RequestMapping(value = "/level", method = RequestMethod.POST) public Result<PartnerResponse> getPartnerLevel(@RequestBody @Valid Partner partner, @RequestHeader HttpHeaders headers) { if (logger.isInfoEnabled()) { logger.info("getPartnerLevel userId:{},header:{},time:{}", partner.getUserId(), headers.keySet().toArray(), LocalDateTime.now()); } return partnerManager.getPartnerLevel(partner.getUserId()); } /** * 测试使用 结算单个用户 */ @RequestMapping(value = "/finance", method = RequestMethod.POST) public Result<String> doFinanceSettle(@RequestBody @Valid Partner partner, @RequestHeader HttpHeaders headers) { if (logger.isInfoEnabled()) { logger.info("doFinanceSettle userId:{},header:{},time:{}", partner.getUserId(), headers.keySet().toArray(), LocalDateTime.now()); } return partnerManager.doFinanceSettle(partner.getUserId()); } /** * 结算全部用户 */ @RequestMapping(value = "/finance", method = RequestMethod.GET) public Result<String> doFinanceSettle(@RequestHeader HttpHeaders headers) { partnerSettleTask.runScheduledTask(); logger.info("============>" + Thread.currentThread().getName()); Result<String> result = new Result<String>(); result.setData("异步,正在执行刷新......"); return result; }}
\ No newline at end of file \ No newline at end of file
......
...@@ -2,10 +2,11 @@ package com.lanren.huhu.partner.dao; ...@@ -2,10 +2,11 @@ package com.lanren.huhu.partner.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lanren.huhu.partner.domain.AgentSalary; import com.lanren.huhu.partner.domain.AgentSalary;
import java.util.List;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper @Mapper
public interface AgentSalaryMapper extends BaseMapper<AgentSalary> { public interface AgentSalaryMapper extends BaseMapper<AgentSalary> {
int updateBatch(List<AgentSalary> list); int updateBatch(List<AgentSalary> list);
......
...@@ -2,10 +2,11 @@ package com.lanren.huhu.partner.dao; ...@@ -2,10 +2,11 @@ package com.lanren.huhu.partner.dao;
import com.baomidou.mybatisplus.core.mapper.BaseMapper; import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.lanren.huhu.partner.domain.OrdersActive; import com.lanren.huhu.partner.domain.OrdersActive;
import java.util.List;
import org.apache.ibatis.annotations.Mapper; import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param; import org.apache.ibatis.annotations.Param;
import java.util.List;
@Mapper @Mapper
public interface OrdersActiveMapper extends BaseMapper<OrdersActive> { public interface OrdersActiveMapper extends BaseMapper<OrdersActive> {
int updateBatch(List<OrdersActive> list); int updateBatch(List<OrdersActive> list);
...@@ -15,4 +16,6 @@ public interface OrdersActiveMapper extends BaseMapper<OrdersActive> { ...@@ -15,4 +16,6 @@ public interface OrdersActiveMapper extends BaseMapper<OrdersActive> {
int insertOrUpdate(OrdersActive record); int insertOrUpdate(OrdersActive record);
int insertOrUpdateSelective(OrdersActive record); int insertOrUpdateSelective(OrdersActive record);
OrdersActive selectOneByOrderSn(String type, String orderSn);
} }
\ No newline at end of file
...@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.annotation.IdType; ...@@ -4,10 +4,12 @@ import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableField; import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId; import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName; import com.baomidou.mybatisplus.annotation.TableName;
import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.time.LocalDateTime; import java.time.LocalDateTime;
import lombok.Data; import java.util.Date;
@Data @Data
@TableName(value = "agent_salary") @TableName(value = "agent_salary")
...@@ -28,6 +30,18 @@ public class AgentSalary implements Serializable { ...@@ -28,6 +30,18 @@ public class AgentSalary implements Serializable {
private Integer agentId; private Integer agentId;
/** /**
* 年份时间值
*/
@TableField(value = "yeartime")
private Integer yeartime;
/**
* 月份值
*/
@TableField(value = "monthtime")
private Integer monthtime;
/**
* 月份 * 月份
*/ */
@TableField(value = "month") @TableField(value = "month")
...@@ -70,6 +84,30 @@ public class AgentSalary implements Serializable { ...@@ -70,6 +84,30 @@ public class AgentSalary implements Serializable {
private BigDecimal taxBalance; private BigDecimal taxBalance;
/** /**
* 分享赚奖励
*/
@TableField(value = "share_balance")
private BigDecimal shareBalance;
/**
* 自购省奖励
*/
@TableField(value = "zigousheng_balance")
private BigDecimal zigoushengBalance;
/**
* 推荐分成奖励
*/
@TableField(value = "pingtui_balance")
private BigDecimal pingtuiBalance;
/**
* 技术服务费
*/
@TableField(value = "tech_charge")
private BigDecimal techCharge;
/**
* 姓名或许公司名称 * 姓名或许公司名称
*/ */
@TableField(value = "bank_account") @TableField(value = "bank_account")
...@@ -109,7 +147,7 @@ public class AgentSalary implements Serializable { ...@@ -109,7 +147,7 @@ public class AgentSalary implements Serializable {
* 创建时间 * 创建时间
*/ */
@TableField(value = "create_time") @TableField(value = "create_time")
private LocalDateTime createTime; private Date createTime;
/** /**
* 提现时间 * 提现时间
...@@ -132,6 +170,10 @@ public class AgentSalary implements Serializable { ...@@ -132,6 +170,10 @@ public class AgentSalary implements Serializable {
public static final String COL_AGENT_ID = "agent_id"; public static final String COL_AGENT_ID = "agent_id";
public static final String COL_YEARTIME = "yeartime";
public static final String COL_MONTHTIME = "monthtime";
public static final String COL_MONTH = "month"; public static final String COL_MONTH = "month";
public static final String COL_BALANCE = "balance"; public static final String COL_BALANCE = "balance";
...@@ -146,6 +188,14 @@ public class AgentSalary implements Serializable { ...@@ -146,6 +188,14 @@ public class AgentSalary implements Serializable {
public static final String COL_TAX_BALANCE = "tax_balance"; public static final String COL_TAX_BALANCE = "tax_balance";
public static final String COL_SHARE_BALANCE = "share_balance";
public static final String COL_ZIGOUSHENG_BALANCE = "zigousheng_balance";
public static final String COL_PINGTUI_BALANCE = "pingtui_balance";
public static final String COL_TECH_CHARGE = "tech_charge";
public static final String COL_BANK_ACCOUNT = "bank_account"; public static final String COL_BANK_ACCOUNT = "bank_account";
public static final String COL_BANK_CARD_NUMBER = "bank_card_number"; public static final String COL_BANK_CARD_NUMBER = "bank_card_number";
......
...@@ -110,7 +110,7 @@ public class AgentManager { ...@@ -110,7 +110,7 @@ public class AgentManager {
public Result<String> doFinanceSettle(int agentId) { public Result<String> doFinanceSettle(int agentId) {
Result<String> result = new Result<String>(); Result<String> result = new Result<String>();
if (agentSettleTask.doOneAgentSettle(agentId)) { if (agentSettleTask.doOneAgentSettle(agentId)) {
result.setCode(200); result.setCode(0);
} else { } else {
result.setCode(500); result.setCode(500);
} }
......
package com.lanren.huhu.partner.manager; import com.lanren.huhu.partner.domain.PartnerAccount;import com.lanren.huhu.partner.model.PartnerResponse;import com.lanren.huhu.partner.result.Result;import com.lanren.huhu.partner.schedule.PartnerSettleTask;import com.lanren.huhu.partner.service.PartnerAccountService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component; import java.time.LocalDateTime; /** * @author houseme * @date 2019-06-26 10:56 * @Project partner * @Package com.lanren.huhu.partner.manager * @File: PartnerAccountManager */@Componentpublic class PartnerManager { private static Logger logger = LoggerFactory.getLogger(PartnerManager.class); @Autowired private PartnerAccountService partnerAccountService; @Autowired private PartnerSettleTask partnerSettleTask; /*** * 获取合伙人账户信息 * @param userId * @return */ public Result<PartnerAccount> findByUserId(Integer userId) { Result<PartnerAccount> result = new Result<>(); if (logger.isDebugEnabled()) { logger.info("PartnerAccountManager findByUserId userId:{},time:{}", userId, LocalDateTime.now()); } PartnerAccount partnerAccount = partnerAccountService.getOneByUserId(userId); result.setData(partnerAccount); return result; } /*** * 获取合伙人等级 10 普通, 20 高级, 30 超级 * @param userId * @return */ public Result<PartnerResponse> getPartnerLevel(Integer userId) { if (logger.isDebugEnabled()) { logger.info("PartnerAccountManager getPartnerLevel userId:{},time:{}", userId, LocalDateTime.now()); } Result<PartnerResponse> result = new Result<>(); PartnerAccount partnerAccount = partnerAccountService.getOneByUserId(userId); if (null != partnerAccount) { int partnerLevel; if (partnerAccount.getIsSuperPartner() == 1) { partnerLevel = 30; } else { partnerLevel = partnerAccount.getPartnerLevel(); } result.setData(new PartnerResponse(partnerLevel)); } else { result.setCode(601); } return result; } public Result<String> doFinanceSettle(int userId) { Result<String> result = new Result<>(); if (partnerSettleTask.doOneUserSettle(userId)) { result.setCode(200); } else { result.setCode(500); } return result; }} package com.lanren.huhu.partner.manager; import com.lanren.huhu.partner.domain.PartnerAccount;import com.lanren.huhu.partner.model.PartnerResponse;import com.lanren.huhu.partner.result.Result;import com.lanren.huhu.partner.schedule.PartnerSettleTask;import com.lanren.huhu.partner.service.PartnerAccountService;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.stereotype.Component; import java.time.LocalDateTime; /** * @author houseme * @date 2019-06-26 10:56 * @Project partner * @Package com.lanren.huhu.partner.manager * @File: PartnerAccountManager */@Componentpublic class PartnerManager { private static Logger logger = LoggerFactory.getLogger(PartnerManager.class); @Autowired private PartnerAccountService partnerAccountService; @Autowired private PartnerSettleTask partnerSettleTask; /*** * 获取合伙人账户信息 * @param userId * @return */ public Result<PartnerAccount> findByUserId(Integer userId) { Result<PartnerAccount> result = new Result<>(); if (logger.isDebugEnabled()) { logger.info("PartnerAccountManager findByUserId userId:{},time:{}", userId, LocalDateTime.now()); } PartnerAccount partnerAccount = partnerAccountService.getOneByUserId(userId); result.setData(partnerAccount); return result; } /*** * 获取合伙人等级 10 普通, 20 高级, 30 超级 * @param userId * @return */ public Result<PartnerResponse> getPartnerLevel(Integer userId) { if (logger.isDebugEnabled()) { logger.info("PartnerAccountManager getPartnerLevel userId:{},time:{}", userId, LocalDateTime.now()); } Result<PartnerResponse> result = new Result<>(); PartnerAccount partnerAccount = partnerAccountService.getOneByUserId(userId); if (null != partnerAccount) { int partnerLevel; if (partnerAccount.getIsSuperPartner() == 1) { partnerLevel = 30; } else { partnerLevel = partnerAccount.getPartnerLevel(); } result.setData(new PartnerResponse(partnerLevel)); } else { result.setCode(601); } return result; } public Result<String> doFinanceSettle(int userId) { Result<String> result = new Result<>(); if (partnerSettleTask.doOneUserSettle(userId)) { result.setCode(0); } else { result.setCode(500); } return result; }}
\ No newline at end of file \ No newline at end of file
......
...@@ -12,6 +12,7 @@ import org.slf4j.Logger; ...@@ -12,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
...@@ -54,7 +55,12 @@ public class AgentSettleTask { ...@@ -54,7 +55,12 @@ public class AgentSettleTask {
AgentIncomeSummaryService agentIncomeSummaryService; AgentIncomeSummaryService agentIncomeSummaryService;
@Autowired @Autowired
AgentAccountLogService agentAccountLogService; AgentAccountLogService agentAccountLogService;
@Autowired
AgentBankCardService agentBankCardService;
@Autowired
AgentSalaryService agentSalaryService;
@Async
public void runScheduledTask() { public void runScheduledTask() {
logger.info("run AgentSettleTask"); logger.info("run AgentSettleTask");
try { try {
...@@ -65,6 +71,7 @@ public class AgentSettleTask { ...@@ -65,6 +71,7 @@ public class AgentSettleTask {
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
logger.info("run AgentSettleTask done");
} }
private void updateAll(long beginTs, long endTs) { private void updateAll(long beginTs, long endTs) {
...@@ -85,10 +92,12 @@ public class AgentSettleTask { ...@@ -85,10 +92,12 @@ public class AgentSettleTask {
if (agentSettleList != null && agentSettleList.size() > 0) { if (agentSettleList != null && agentSettleList.size() > 0) {
for (AgentSettle agentSettle : agentSettleList) { for (AgentSettle agentSettle : agentSettleList) {
errAgentSettle = agentSettle; errAgentSettle = agentSettle;
if (agentSettle != null) {
if (!doDbUpdate(agentSettle, beginTs, endTs)) { if (!doDbUpdate(agentSettle, beginTs, endTs)) {
logger.error("doDbUpdate failed for agent {}", agentSettle.getAgentId()); logger.error("doDbUpdate failed for agent {}", agentSettle.getAgentId());
} }
} }
}
pageNo++; pageNo++;
} else { } else {
break; break;
...@@ -165,6 +174,7 @@ public class AgentSettleTask { ...@@ -165,6 +174,7 @@ public class AgentSettleTask {
*/ */
long newRechargeTime = DateUtils.getNextMonth1stTimestamp(agentReward.getRechargeTime().getTime()); long newRechargeTime = DateUtils.getNextMonth1stTimestamp(agentReward.getRechargeTime().getTime());
agentReward.setRechargeTime(new Date(newRechargeTime)); agentReward.setRechargeTime(new Date(newRechargeTime));
agentReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
agentRewardService.updateById(agentReward); agentRewardService.updateById(agentReward);
continue; continue;
} else if (order.getStatus() == Constants.ORDER_STATE_SETTLED) { } else if (order.getStatus() == Constants.ORDER_STATE_SETTLED) {
...@@ -226,6 +236,7 @@ public class AgentSettleTask { ...@@ -226,6 +236,7 @@ public class AgentSettleTask {
*/ */
long newRechargeTime = DateUtils.getNextMonth1stTimestamp(agentReward.getRechargeTime().getTime()); long newRechargeTime = DateUtils.getNextMonth1stTimestamp(agentReward.getRechargeTime().getTime());
agentReward.setRechargeTime(new Date(newRechargeTime)); agentReward.setRechargeTime(new Date(newRechargeTime));
agentReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
agentRewardService.updateById(agentReward); agentRewardService.updateById(agentReward);
continue; continue;
} else if (subOrder.getOrderState() == Constants.ORDER_STATE_SETTLED) { } else if (subOrder.getOrderState() == Constants.ORDER_STATE_SETTLED) {
...@@ -267,6 +278,7 @@ public class AgentSettleTask { ...@@ -267,6 +278,7 @@ public class AgentSettleTask {
agentReward.setAmount(commission); agentReward.setAmount(commission);
agentReward.setCommission(commission); agentReward.setCommission(commission);
agentReward.setSettleState(Constants.SETTLE_STATE_DONE); agentReward.setSettleState(Constants.SETTLE_STATE_DONE);
agentReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
agentRewardService.updateById(agentReward); agentRewardService.updateById(agentReward);
} }
...@@ -284,7 +296,8 @@ public class AgentSettleTask { ...@@ -284,7 +296,8 @@ public class AgentSettleTask {
agentReward.setCommission(ZERO); agentReward.setCommission(ZERO);
agentReward.setCashCode("0"); agentReward.setCashCode("0");
agentReward.setSettleState(Constants.SETTLE_STATE_FAILED); agentReward.setSettleState(Constants.SETTLE_STATE_FAILED);
agentReward.setRewardStatus(Constants.REWARD_STATUS_SETTLE); agentReward.setRewardStatus(Constants.REWARD_STATUS_FAILED);
agentReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
agentRewardService.updateById(agentReward); agentRewardService.updateById(agentReward);
} }
...@@ -297,7 +310,12 @@ public class AgentSettleTask { ...@@ -297,7 +310,12 @@ public class AgentSettleTask {
updateOrderCommission(beginTs, endTs, 1, agentId); updateOrderCommission(beginTs, endTs, 1, agentId);
AgentSettle agentSettle = agentRewardService.selectAgentSettleByTsAndAgentId(beginTs, endTs, agentId); AgentSettle agentSettle = agentRewardService.selectAgentSettleByTsAndAgentId(beginTs, endTs, agentId);
errAgentSettle = agentSettle; errAgentSettle = agentSettle;
if (agentSettle != null) {
return doDbUpdate(agentSettle, beginTs, endTs); return doDbUpdate(agentSettle, beginTs, endTs);
} else {
logger.info("没有待奖励记录 跳过不处理, 代理商{}", agentId);
return true;
}
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
logger.error("agentId is {}, errAgentSettle is {}", agentId, errAgentSettle); logger.error("agentId is {}, errAgentSettle is {}", agentId, errAgentSettle);
...@@ -321,11 +339,11 @@ public class AgentSettleTask { ...@@ -321,11 +339,11 @@ public class AgentSettleTask {
/** /**
* 插入变更记录 * 插入变更记录
*/ */
insertIntoAgentAccountLog(agentSettle, agentAccount); AgentSalary agentSalary = insertAgentSalary(agentSettle, beginTs);
insertIntoAgentAccountLog(agentSettle, agentAccount, agentSalary, beginTs);
updateAgentAccount(agentSettle, agentAccount); updateAgentAccount(agentSettle, agentAccount);
updateAgentRewardStatus(agentSettle.getAgentId(), beginTs, endTs); updateAgentRewardStatus(agentSettle.getAgentId(), beginTs, endTs);
insertAgentIncomeSummary(agentSettle, beginTs); insertAgentIncomeSummary(agentSettle, beginTs);
insertAgentSalary(agentSettle);
/** /**
* 提交事务 * 提交事务
*/ */
...@@ -345,14 +363,46 @@ public class AgentSettleTask { ...@@ -345,14 +363,46 @@ public class AgentSettleTask {
} }
} }
private void insertAgentSalary(AgentSettle agentSettle) { private AgentSalary insertAgentSalary(AgentSettle agentSettle, long beginTs) {
}
private void insertAgentIncomeSummary(AgentSettle agentSettle, long beginTs) {
Date now = new Date(beginTs * 1000L); Date now = new Date(beginTs * 1000L);
int yeartime = Integer.parseInt(DateUtils.getYear(now)); int yeartime = Integer.parseInt(DateUtils.getYear(now));
int monthtime = Integer.parseInt(DateUtils.getMonth(now)); int monthtime = Integer.parseInt(DateUtils.getMonth(now));
AgentBankCard agentBankCard = agentBankCardService.getOneByAgentId(agentSettle.getAgentId());
AgentSalary agentSalary = new AgentSalary();
agentSalary.setUserId(agentSettle.getUserId());
agentSalary.setAgentId(agentSettle.getAgentId());
agentSalary.setYeartime(yeartime);
agentSalary.setMonthtime(monthtime);
agentSalary.setMonth(DateUtils.format(now, "yyyy-MM"));
agentSalary.setBalance(agentSettle.getBalance());
agentSalary.setOpencardBalance(agentSettle.getOpencardBalance());
agentSalary.setRechargeBalance(agentSettle.getRechargeBalance());
agentSalary.setUpgradeBalance(agentSettle.getUpgradeBalance());
agentSalary.setUpgradeSuperBalance(agentSettle.getUpgradeSuperBalance());
agentSalary.setTaxBalance(ZERO);
agentSalary.setShareBalance(agentSettle.getShareBalance());
agentSalary.setZigoushengBalance(agentSettle.getZigoushengBalance());
agentSalary.setPingtuiBalance(agentSettle.getPingtuiBalance());
agentSalary.setTechCharge(agentSettle.getTechCharge());
agentSalary.setBankAccount(agentBankCard == null ? "" : agentBankCard.getBankAccount());
agentSalary.setBankCardNumber(agentBankCard == null ? "" : agentBankCard.getBankCardNumber());
agentSalary.setBankName(agentBankCard == null ? "" : agentBankCard.getBankName());
agentSalary.setBranchName(agentBankCard == null ? "" : agentBankCard.getBranchName());
agentSalary.setReferenceId(agentBankCard == null ? 0 : agentBankCard.getId());
agentSalary.setStatus(10);
agentSalary.setCreateTime(now);
agentSalary.setModifyTime(null);
agentSalary.setCreatedAt(now.getTime() / 1000L);
agentSalary.setUpdatedAt(now.getTime() / 1000L);
agentSalaryService.insert(agentSalary);
return agentSalary;
}
private void insertAgentIncomeSummary(AgentSettle agentSettle, long beginTs) {
Date dat = new Date(beginTs * 1000L);
int now = (int) (System.currentTimeMillis() / 1000L);
int yeartime = Integer.parseInt(DateUtils.getYear(dat));
int monthtime = Integer.parseInt(DateUtils.getMonth(dat));
AgentIncomeSummary agentIncomeSummary = agentIncomeSummaryService.getOneByAgentidYearMonth(agentSettle.getAgentId(), yeartime, monthtime); AgentIncomeSummary agentIncomeSummary = agentIncomeSummaryService.getOneByAgentidYearMonth(agentSettle.getAgentId(), yeartime, monthtime);
if (null == agentIncomeSummary) { if (null == agentIncomeSummary) {
agentIncomeSummary = new AgentIncomeSummary(); agentIncomeSummary = new AgentIncomeSummary();
...@@ -363,9 +413,13 @@ public class AgentSettleTask { ...@@ -363,9 +413,13 @@ public class AgentSettleTask {
agentIncomeSummary.setIncome(ZERO); agentIncomeSummary.setIncome(ZERO);
agentIncomeSummary.setContent(""); agentIncomeSummary.setContent("");
agentIncomeSummary.setState(15); agentIncomeSummary.setState(15);
agentIncomeSummary.setCreatedAt(now);
agentIncomeSummary.setUpdatedAt(now);
agentIncomeSummary.setSettleTime(now);
agentIncomeSummaryService.save(agentIncomeSummary); agentIncomeSummaryService.save(agentIncomeSummary);
} else { } else {
agentIncomeSummary.setState(15); agentIncomeSummary.setState(15);
agentIncomeSummary.setUpdatedAt(now);
agentIncomeSummaryService.updateById(agentIncomeSummary); agentIncomeSummaryService.updateById(agentIncomeSummary);
} }
} }
...@@ -384,7 +438,8 @@ public class AgentSettleTask { ...@@ -384,7 +438,8 @@ public class AgentSettleTask {
agentAccountService.updateById(agentAccount); agentAccountService.updateById(agentAccount);
} }
private void insertIntoAgentAccountLog(AgentSettle agentSettle, AgentAccount agentAccount) { private void insertIntoAgentAccountLog(AgentSettle agentSettle, AgentAccount agentAccount, AgentSalary agentSalary, long beginTs) {
Date dat = new Date(beginTs * 1000L);
/** /**
* 月结发钱 * 月结发钱
*/ */
...@@ -397,26 +452,28 @@ public class AgentSettleTask { ...@@ -397,26 +452,28 @@ public class AgentSettleTask {
Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE, Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE,
changeNum, changeNum,
changedAmount, changedAmount,
Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE_REMARK, DateUtils.format(dat, "yyyy-MM") + Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE_REMARK,
snapshot.toString()); snapshot.toString(),
agentSalary.getId());
agentAccountLogService.save(log); agentAccountLogService.save(log);
/** /**
* 平台技术服务费 * 平台技术服务费
*/ */
if (agentSettle.getTechCharge().compareTo(ZERO) > 0) {
changeNum = agentSettle.getTechCharge().negate(); changeNum = agentSettle.getTechCharge().negate();
changedAmount = changedAmount.add(changeNum); changedAmount = changedAmount.add(changeNum);
if (changeNum.compareTo(ZERO) < 0) {
log = createNewAgentAccountLog(agentSettle, log = createNewAgentAccountLog(agentSettle,
Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE, Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE,
changeNum, changeNum,
changedAmount, changedAmount,
Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE_REMARK, DateUtils.format(dat, "yyyy-MM") + Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE_REMARK,
""); "",
agentSalary.getId());
agentAccountLogService.save(log); agentAccountLogService.save(log);
} }
} }
private AgentAccountLog createNewAgentAccountLog(AgentSettle agentSettle, int type, BigDecimal changeNum, BigDecimal changedAmount, String payRemark, String snapshot) { private AgentAccountLog createNewAgentAccountLog(AgentSettle agentSettle, int type, BigDecimal changeNum, BigDecimal changedAmount, String payRemark, String snapshot, long agentSalaryId) {
Date now = new Date(); Date now = new Date();
int yeartime = Integer.parseInt(DateUtils.getYear(now)); int yeartime = Integer.parseInt(DateUtils.getYear(now));
int monthtime = Integer.parseInt(DateUtils.getMonth(now)); int monthtime = Integer.parseInt(DateUtils.getMonth(now));
...@@ -433,6 +490,11 @@ public class AgentSettleTask { ...@@ -433,6 +490,11 @@ public class AgentSettleTask {
log.setMonthtime(monthtime); log.setMonthtime(monthtime);
log.setDaytime(daytime); log.setDaytime(daytime);
log.setSnapshot(snapshot); log.setSnapshot(snapshot);
log.setChangeTime((int)(now.getTime() / 1000));
log.setPayState(20);
log.setPayPlatform("hupay");
log.setPayInfo(payRemark);
log.setReferenceId(agentSalaryId + "");
return log; return log;
} }
} }
...@@ -12,6 +12,7 @@ import org.slf4j.Logger; ...@@ -12,6 +12,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus; import org.springframework.transaction.TransactionStatus;
...@@ -55,7 +56,7 @@ public class PartnerSettleTask { ...@@ -55,7 +56,7 @@ public class PartnerSettleTask {
@Autowired @Autowired
PartnerIncomeSummaryService partnerIncomeSummaryService; PartnerIncomeSummaryService partnerIncomeSummaryService;
// @Scheduled(fixedDelay = 30 * 24 * 60 * 60 * 1000L) @Async
public void runScheduledTask() { public void runScheduledTask() {
logger.info("run PartnerSettleTask"); logger.info("run PartnerSettleTask");
try { try {
...@@ -66,6 +67,7 @@ public class PartnerSettleTask { ...@@ -66,6 +67,7 @@ public class PartnerSettleTask {
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
} }
logger.info("run PartnerSettleTask done");
} }
private void updateAll(long beginTs, long endTs) { private void updateAll(long beginTs, long endTs) {
...@@ -82,10 +84,11 @@ public class PartnerSettleTask { ...@@ -82,10 +84,11 @@ public class PartnerSettleTask {
updateOrderCommission(beginTs, endTs, 1, userId); updateOrderCommission(beginTs, endTs, 1, userId);
PartnerSettle partnerSettle = partnerRewardService.selectPartnerSettleByTsAndUid(beginTs, endTs, userId); PartnerSettle partnerSettle = partnerRewardService.selectPartnerSettleByTsAndUid(beginTs, endTs, userId);
errPartnerSettle = partnerSettle; errPartnerSettle = partnerSettle;
if (setIncomeAndTax(partnerSettle)) { if (partnerSettle != null && setIncomeAndTax(partnerSettle)) {
return doDbUpdate(partnerSettle, beginTs, endTs); return doDbUpdate(partnerSettle, beginTs, endTs);
} else { } else {
return false; logger.info("没有待奖励记录 跳过不处理, 用户{}", userId);
return true;
} }
} catch (Exception e) { } catch (Exception e) {
logger.error(e.getMessage(), e); logger.error(e.getMessage(), e);
...@@ -107,7 +110,7 @@ public class PartnerSettleTask { ...@@ -107,7 +110,7 @@ public class PartnerSettleTask {
if (partnerSettleList != null && partnerSettleList.size() > 0) { if (partnerSettleList != null && partnerSettleList.size() > 0) {
for (PartnerSettle partnerSettle : partnerSettleList) { for (PartnerSettle partnerSettle : partnerSettleList) {
errPartnerSettle = partnerSettle; errPartnerSettle = partnerSettle;
if (setIncomeAndTax(partnerSettle)) { if (partnerSettle != null && setIncomeAndTax(partnerSettle)) {
if (!doDbUpdate(partnerSettle, beginTs, endTs)) { if (!doDbUpdate(partnerSettle, beginTs, endTs)) {
logger.error("doDbUpdate failed for user {}", partnerSettle.getUserId()); logger.error("doDbUpdate failed for user {}", partnerSettle.getUserId());
} }
...@@ -140,7 +143,7 @@ public class PartnerSettleTask { ...@@ -140,7 +143,7 @@ public class PartnerSettleTask {
/** /**
* 插入变更记录 * 插入变更记录
*/ */
insertIntoPartnerAccountLog(partnerSettle, partnerAccount); insertIntoPartnerAccountLog(partnerSettle, partnerAccount, beginTs);
updatePartnerAccount(partnerSettle, partnerAccount); updatePartnerAccount(partnerSettle, partnerAccount);
updatePartnerRewardStatus(partnerSettle.getUserId(), beginTs, endTs); updatePartnerRewardStatus(partnerSettle.getUserId(), beginTs, endTs);
insertPartnerIncomeSummary(partnerSettle.getUserId(), beginTs); insertPartnerIncomeSummary(partnerSettle.getUserId(), beginTs);
...@@ -164,9 +167,10 @@ public class PartnerSettleTask { ...@@ -164,9 +167,10 @@ public class PartnerSettleTask {
} }
private void insertPartnerIncomeSummary(int userId, long beginTs) { private void insertPartnerIncomeSummary(int userId, long beginTs) {
Date now = new Date(beginTs * 1000L); Date dat = new Date(beginTs * 1000L);
int yeartime = Integer.parseInt(DateUtils.getYear(now)); int now = (int) (System.currentTimeMillis() / 1000L);
int monthtime = Integer.parseInt(DateUtils.getMonth(now)); int yeartime = Integer.parseInt(DateUtils.getYear(dat));
int monthtime = Integer.parseInt(DateUtils.getMonth(dat));
PartnerIncomeSummary partnerIncomeSummary = partnerIncomeSummaryService.getOneByUidYearMonth(userId, yeartime, monthtime); PartnerIncomeSummary partnerIncomeSummary = partnerIncomeSummaryService.getOneByUidYearMonth(userId, yeartime, monthtime);
if (null == partnerIncomeSummary) { if (null == partnerIncomeSummary) {
partnerIncomeSummary = new PartnerIncomeSummary(); partnerIncomeSummary = new PartnerIncomeSummary();
...@@ -175,9 +179,14 @@ public class PartnerSettleTask { ...@@ -175,9 +179,14 @@ public class PartnerSettleTask {
partnerIncomeSummary.setMonthtime(monthtime); partnerIncomeSummary.setMonthtime(monthtime);
partnerIncomeSummary.setIncome(ZERO); partnerIncomeSummary.setIncome(ZERO);
partnerIncomeSummary.setState(15); partnerIncomeSummary.setState(15);
partnerIncomeSummary.setCreatedAt(now);
partnerIncomeSummary.setUpdatedAt(now);
partnerIncomeSummary.setSettleTime(now);
partnerIncomeSummary.setContent("");
partnerIncomeSummaryService.save(partnerIncomeSummary); partnerIncomeSummaryService.save(partnerIncomeSummary);
} else { } else {
partnerIncomeSummary.setState(15); partnerIncomeSummary.setState(15);
partnerIncomeSummary.setUpdatedAt(now);
partnerIncomeSummaryService.updateById(partnerIncomeSummary); partnerIncomeSummaryService.updateById(partnerIncomeSummary);
} }
} }
...@@ -190,8 +199,8 @@ public class PartnerSettleTask { ...@@ -190,8 +199,8 @@ public class PartnerSettleTask {
/** /**
* 更新合伙人账户金额 * 更新合伙人账户金额
*/ */
BigDecimal wxIncomeAdd = partnerSettle.getWxIncome().subtract(partnerSettle.getWxTax()); BigDecimal wxIncomeAdd = partnerSettle.getWxIncome();
BigDecimal bankIncomeAdd = partnerSettle.getBankIncome().subtract(partnerSettle.getBankTax()); BigDecimal bankIncomeAdd = partnerSettle.getBankIncome();
partnerAccount.setAllIncome(partnerAccount.getAllIncome().add(wxIncomeAdd).add(bankIncomeAdd)); partnerAccount.setAllIncome(partnerAccount.getAllIncome().add(wxIncomeAdd).add(bankIncomeAdd));
partnerAccount.setIncomeAfterTax(partnerAccount.getIncomeAfterTax().add(wxIncomeAdd).add(bankIncomeAdd)); partnerAccount.setIncomeAfterTax(partnerAccount.getIncomeAfterTax().add(wxIncomeAdd).add(bankIncomeAdd));
partnerAccount.setWxFreeBalance(partnerAccount.getWxFreeBalance().add(wxIncomeAdd)); partnerAccount.setWxFreeBalance(partnerAccount.getWxFreeBalance().add(wxIncomeAdd));
...@@ -199,7 +208,8 @@ public class PartnerSettleTask { ...@@ -199,7 +208,8 @@ public class PartnerSettleTask {
partnerAccountService.updateById(partnerAccount); partnerAccountService.updateById(partnerAccount);
} }
private void insertIntoPartnerAccountLog(PartnerSettle partnerSettle, PartnerAccount partnerAccount) { private void insertIntoPartnerAccountLog(PartnerSettle partnerSettle, PartnerAccount partnerAccount, long beginTs) {
Date dat = new Date(beginTs * 1000L);
/** /**
* 月结发钱 * 月结发钱
*/ */
...@@ -213,7 +223,7 @@ public class PartnerSettleTask { ...@@ -213,7 +223,7 @@ public class PartnerSettleTask {
Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE, Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE,
changeNum, changeNum,
changedAmount, changedAmount,
Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE_REMARK, DateUtils.format(dat, "yyyy-MM") + Constants.PARTNER_ACCOUNT_LOG_TYPE_SETTLE_REMARK,
snapshot.toString()); snapshot.toString());
partnerAccountLogService.save(log); partnerAccountLogService.save(log);
/** /**
...@@ -221,28 +231,32 @@ public class PartnerSettleTask { ...@@ -221,28 +231,32 @@ public class PartnerSettleTask {
*/ */
changeNum = partnerSettle.getTechCharge().negate(); changeNum = partnerSettle.getTechCharge().negate();
changedAmount = changedAmount.add(changeNum); changedAmount = changedAmount.add(changeNum);
if (changeNum.compareTo(ZERO) < 0) {
log = createNewPartnerAccountLog(partnerSettle.getUserId(), log = createNewPartnerAccountLog(partnerSettle.getUserId(),
Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE, Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE,
changeNum, changeNum,
changedAmount, changedAmount,
Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE_REMARK, DateUtils.format(dat, "yyyy-MM") + Constants.PARTNER_ACCOUNT_LOG_TYPE_TECH_CHARGE_REMARK,
""); "");
partnerAccountLogService.save(log); partnerAccountLogService.save(log);
}
/** /**
* 个人所得税 * 个人所得税
*/ */
changeNum = partnerSettle.getWxTax().add(partnerSettle.getBankTax()).negate(); changeNum = partnerSettle.getWxTax().add(partnerSettle.getBankTax()).negate();
changedAmount = changedAmount.add(changeNum); changedAmount = changedAmount.add(changeNum);
snapshot.setWxFreeBalance(snapshot.getWxFreeBalance().add(partnerSettle.getWxIncome())); snapshot.setWxFreeBalance(snapshot.getWxFreeBalance().add(partnerSettle.getWxIncome()).add(partnerSettle.getWxTax()));
snapshot.setBankFreeBalance(snapshot.getBankFreeBalance().add(partnerSettle.getBankIncome())); snapshot.setBankFreeBalance(snapshot.getBankFreeBalance().add(partnerSettle.getBankIncome()).add(partnerSettle.getBankTax()));
if (changeNum.compareTo(ZERO) < 0) {
log = createNewPartnerAccountLog(partnerSettle.getUserId(), log = createNewPartnerAccountLog(partnerSettle.getUserId(),
Constants.PARTNER_ACCOUNT_LOG_TYPE_TAX, Constants.PARTNER_ACCOUNT_LOG_TYPE_TAX,
changeNum, changeNum,
changedAmount, changedAmount,
Constants.PARTNER_ACCOUNT_LOG_TYPE_TAX_REMARK, DateUtils.format(dat, "yyyy-MM") + Constants.PARTNER_ACCOUNT_LOG_TYPE_TAX_REMARK,
snapshot.toString()); snapshot.toString());
partnerAccountLogService.save(log); partnerAccountLogService.save(log);
} }
}
private PartnerAccountLog createNewPartnerAccountLog(int userId, int type, BigDecimal changeNum, BigDecimal changedAmount, String payRemark,String snapshot) { private PartnerAccountLog createNewPartnerAccountLog(int userId, int type, BigDecimal changeNum, BigDecimal changedAmount, String payRemark,String snapshot) {
Date now = new Date(); Date now = new Date();
...@@ -260,6 +274,10 @@ public class PartnerSettleTask { ...@@ -260,6 +274,10 @@ public class PartnerSettleTask {
log.setMonthtime(monthtime); log.setMonthtime(monthtime);
log.setDaytime(daytime); log.setDaytime(daytime);
log.setSnapshot(snapshot.toString()); log.setSnapshot(snapshot.toString());
log.setPayState(20);
log.setPayPlatform("hupay");
log.setPayInfo(payRemark);
log.setChangeTime((int) (now.getTime() / 1000L));
return log; return log;
} }
...@@ -276,6 +294,7 @@ public class PartnerSettleTask { ...@@ -276,6 +294,7 @@ public class PartnerSettleTask {
BigDecimal commission = cash.multiply(partnerReward.getCommissionRate()); BigDecimal commission = cash.multiply(partnerReward.getCommissionRate());
partnerReward.setCommissionAcount(commission); partnerReward.setCommissionAcount(commission);
partnerReward.setSettleState(Constants.SETTLE_STATE_DONE); partnerReward.setSettleState(Constants.SETTLE_STATE_DONE);
partnerReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
partnerRewardService.updateById(partnerReward); partnerRewardService.updateById(partnerReward);
} }
/** /**
...@@ -288,7 +307,8 @@ public class PartnerSettleTask { ...@@ -288,7 +307,8 @@ public class PartnerSettleTask {
partnerReward.setCash(ZERO); partnerReward.setCash(ZERO);
partnerReward.setCommissionAcount(ZERO); partnerReward.setCommissionAcount(ZERO);
partnerReward.setSettleState(Constants.SETTLE_STATE_FAILED); partnerReward.setSettleState(Constants.SETTLE_STATE_FAILED);
partnerReward.setRewardStatus(Constants.REWARD_STATUS_SETTLE); partnerReward.setRewardStatus(Constants.REWARD_STATUS_FAILED);
partnerReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
partnerRewardService.updateById(partnerReward); partnerRewardService.updateById(partnerReward);
} }
...@@ -357,6 +377,7 @@ public class PartnerSettleTask { ...@@ -357,6 +377,7 @@ public class PartnerSettleTask {
*/ */
long newRechargeTime = DateUtils.getNextMonth1stTimestamp(partnerReward.getRechargeTime().getTime()); long newRechargeTime = DateUtils.getNextMonth1stTimestamp(partnerReward.getRechargeTime().getTime());
partnerReward.setRechargeTime(new Date(newRechargeTime)); partnerReward.setRechargeTime(new Date(newRechargeTime));
partnerReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
partnerRewardService.updateById(partnerReward); partnerRewardService.updateById(partnerReward);
continue; continue;
} else if (order.getStatus() == Constants.ORDER_STATE_SETTLED) { } else if (order.getStatus() == Constants.ORDER_STATE_SETTLED) {
...@@ -417,6 +438,7 @@ public class PartnerSettleTask { ...@@ -417,6 +438,7 @@ public class PartnerSettleTask {
*/ */
long newRechargeTime = DateUtils.getNextMonth1stTimestamp(partnerReward.getRechargeTime().getTime()); long newRechargeTime = DateUtils.getNextMonth1stTimestamp(partnerReward.getRechargeTime().getTime());
partnerReward.setRechargeTime(new Date(newRechargeTime)); partnerReward.setRechargeTime(new Date(newRechargeTime));
partnerReward.setUpdatedAt(System.currentTimeMillis() / 1000L);
partnerRewardService.updateById(partnerReward); partnerRewardService.updateById(partnerReward);
continue; continue;
} else if (subOrder.getOrderState() == Constants.ORDER_STATE_SETTLED) { } else if (subOrder.getOrderState() == Constants.ORDER_STATE_SETTLED) {
...@@ -448,6 +470,7 @@ public class PartnerSettleTask { ...@@ -448,6 +470,7 @@ public class PartnerSettleTask {
BigDecimal base = partnerSettle.getSumRedpack().add(partnerSettle.getSumOthers()); BigDecimal base = partnerSettle.getSumRedpack().add(partnerSettle.getSumOthers());
/** /**
* 订单收入全部计入微信 并且不计税 * 订单收入全部计入微信 并且不计税
* wxIncome 和 bankIncome 均为扣税后的收入
*/ */
BigDecimal wxIncome = partnerSettle.getSumOrderCommission(); BigDecimal wxIncome = partnerSettle.getSumOrderCommission();
BigDecimal wxTax = ZERO; BigDecimal wxTax = ZERO;
......
...@@ -23,4 +23,5 @@ public interface AgentBankCardService extends IService<AgentBankCard>{ ...@@ -23,4 +23,5 @@ public interface AgentBankCardService extends IService<AgentBankCard>{
int insertOrUpdateSelective(AgentBankCard record); int insertOrUpdateSelective(AgentBankCard record);
AgentBankCard getOneByAgentId(int agentId);
} }
...@@ -4,15 +4,16 @@ import com.baomidou.mybatisplus.extension.service.IService; ...@@ -4,15 +4,16 @@ import com.baomidou.mybatisplus.extension.service.IService;
import com.lanren.huhu.partner.domain.AgentSalary; import com.lanren.huhu.partner.domain.AgentSalary;
import java.util.List; import java.util.List;
/**
/**
* @author chen
* @title: ${NAME} * @title: ${NAME}
* @projectName partner * @projectName partner
* @description: 代理商收入 * @description: 代理商收入
* @author chen
* @package ${PACKAGE_NAME} * @package ${PACKAGE_NAME}
* @date 2019-07-02 15:57 * @date 2019-07-02 15:57
*/ */
public interface AgentSalaryService extends IService<AgentSalary>{ public interface AgentSalaryService extends IService<AgentSalary> {
int updateBatch(List<AgentSalary> list); int updateBatch(List<AgentSalary> list);
...@@ -23,4 +24,6 @@ public interface AgentSalaryService extends IService<AgentSalary>{ ...@@ -23,4 +24,6 @@ public interface AgentSalaryService extends IService<AgentSalary>{
int insertOrUpdateSelective(AgentSalary record); int insertOrUpdateSelective(AgentSalary record);
int insert(AgentSalary agentSalary);
} }
package com.lanren.huhu.partner.service.impl; package com.lanren.huhu.partner.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanren.huhu.partner.dao.AgentBankCardMapper; import com.lanren.huhu.partner.dao.AgentBankCardMapper;
import com.lanren.huhu.partner.domain.AgentBankCard; import com.lanren.huhu.partner.domain.AgentBankCard;
...@@ -34,4 +35,10 @@ public class AgentBankCardServiceImpl extends ServiceImpl<AgentBankCardMapper, A ...@@ -34,4 +35,10 @@ public class AgentBankCardServiceImpl extends ServiceImpl<AgentBankCardMapper, A
public int insertOrUpdateSelective(AgentBankCard record) { public int insertOrUpdateSelective(AgentBankCard record) {
return baseMapper.insertOrUpdateSelective(record); return baseMapper.insertOrUpdateSelective(record);
} }
@Override
public AgentBankCard getOneByAgentId(int agentId) {
QueryWrapper<AgentBankCard> wrapper = new QueryWrapper<AgentBankCard>();
wrapper.eq("agent_id", agentId).eq("is_default", 100);
return baseMapper.selectOne(wrapper);
}
} }
...@@ -4,34 +4,45 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; ...@@ -4,34 +4,45 @@ import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanren.huhu.partner.dao.AgentSalaryMapper; import com.lanren.huhu.partner.dao.AgentSalaryMapper;
import com.lanren.huhu.partner.domain.AgentSalary; import com.lanren.huhu.partner.domain.AgentSalary;
import com.lanren.huhu.partner.service.AgentSalaryService; import com.lanren.huhu.partner.service.AgentSalaryService;
import org.apache.ibatis.annotations.Options;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.List; import java.util.List;
/** /**
* @author chen
* @title: ${NAME} * @title: ${NAME}
* @projectName partner * @projectName partner
* @description: 代理商收入 * @description: 代理商收入
* @author chen
* @package ${PACKAGE_NAME} * @package ${PACKAGE_NAME}
* @date 2019-07-02 15:57 * @date 2019-07-02 15:57
*/ */
@Service @Service
public class AgentSalaryServiceImpl extends ServiceImpl<AgentSalaryMapper, AgentSalary> implements AgentSalaryService{ public class AgentSalaryServiceImpl extends ServiceImpl<AgentSalaryMapper, AgentSalary> implements AgentSalaryService {
@Override @Override
public int updateBatch(List<AgentSalary> list) { public int updateBatch(List<AgentSalary> list) {
return baseMapper.updateBatch(list); return baseMapper.updateBatch(list);
} }
@Override @Override
public int batchInsert(List<AgentSalary> list) { public int batchInsert(List<AgentSalary> list) {
return baseMapper.batchInsert(list); return baseMapper.batchInsert(list);
} }
@Override @Override
public int insertOrUpdate(AgentSalary record) { public int insertOrUpdate(AgentSalary record) {
return baseMapper.insertOrUpdate(record); return baseMapper.insertOrUpdate(record);
} }
@Override @Override
public int insertOrUpdateSelective(AgentSalary record) { public int insertOrUpdateSelective(AgentSalary record) {
return baseMapper.insertOrUpdateSelective(record); return baseMapper.insertOrUpdateSelective(record);
} }
@Override
@Options(useGeneratedKeys = true, keyProperty = "agentSalary", keyColumn = "id")
public int insert(AgentSalary agentSalary) {
return baseMapper.insert(agentSalary);
}
} }
package com.lanren.huhu.partner.service.impl; package com.lanren.huhu.partner.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lanren.huhu.partner.dao.OrdersActiveMapper; import com.lanren.huhu.partner.dao.OrdersActiveMapper;
import com.lanren.huhu.partner.domain.OrdersActive; import com.lanren.huhu.partner.domain.OrdersActive;
...@@ -38,8 +37,6 @@ public class OrdersActiveServiceImpl extends ServiceImpl<OrdersActiveMapper, Ord ...@@ -38,8 +37,6 @@ public class OrdersActiveServiceImpl extends ServiceImpl<OrdersActiveMapper, Ord
@Override @Override
public OrdersActive getOneByOrderSn(String type, String orderSn) { public OrdersActive getOneByOrderSn(String type, String orderSn) {
QueryWrapper<OrdersActive> wrapper = new QueryWrapper<OrdersActive>(); return baseMapper.selectOneByOrderSn(type, orderSn);
wrapper.eq("type", type).eq("order_sn", orderSn);
return baseMapper.selectOne(wrapper);
} }
} }
...@@ -679,7 +679,7 @@ ...@@ -679,7 +679,7 @@
SELECT SELECT
agent_id, agent_id,
SUM(amount) balance, SUM(amount) balance,
SUM(case when agent_level=4 then amount * 0.06 else 0 end) techCharge, SUM(case when agent_level=4 and reward_type in (50,740,60,760,300,750) then amount * 0.06 else 0 end) techCharge,
SUM(case when reward_type in (40) then amount else 0 end) opencardBalance, SUM(case when reward_type in (40) then amount else 0 end) opencardBalance,
SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance, SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance,
SUM(case when reward_type in (30,710,720) then amount else 0 end) upgradeBalance, SUM(case when reward_type in (30,710,720) then amount else 0 end) upgradeBalance,
...@@ -715,7 +715,7 @@ ...@@ -715,7 +715,7 @@
SELECT SELECT
agent_id, agent_id,
SUM(amount) balance, SUM(amount) balance,
SUM(case when agent_level=4 then amount * 0.06 else 0 end) techCharge, SUM(case when agent_level=4 and reward_type in (50,740,60,760,300,750) then amount * 0.06 else 0 end) techCharge,
SUM(case when reward_type in (40) then amount else 0 end) opencardBalance, SUM(case when reward_type in (40) then amount else 0 end) opencardBalance,
SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance, SUM(case when reward_type in (50,740) then amount else 0 end) rechargeBalance,
SUM(case when reward_type in (30,710,720) then amount else 0 end) upgradeBalance, SUM(case when reward_type in (30,710,720) then amount else 0 end) upgradeBalance,
......
...@@ -6,6 +6,8 @@ ...@@ -6,6 +6,8 @@
<id column="id" property="id" /> <id column="id" property="id" />
<result column="user_id" property="userId" /> <result column="user_id" property="userId" />
<result column="agent_id" property="agentId" /> <result column="agent_id" property="agentId" />
<result column="yeartime" property="yeartime" />
<result column="monthtime" property="monthtime" />
<result column="month" property="month" /> <result column="month" property="month" />
<result column="balance" property="balance" /> <result column="balance" property="balance" />
<result column="opencard_balance" property="opencardBalance" /> <result column="opencard_balance" property="opencardBalance" />
...@@ -13,6 +15,10 @@ ...@@ -13,6 +15,10 @@
<result column="upgrade_balance" property="upgradeBalance" /> <result column="upgrade_balance" property="upgradeBalance" />
<result column="upgrade_super_balance" property="upgradeSuperBalance" /> <result column="upgrade_super_balance" property="upgradeSuperBalance" />
<result column="tax_balance" property="taxBalance" /> <result column="tax_balance" property="taxBalance" />
<result column="share_balance" property="shareBalance" />
<result column="zigousheng_balance" property="zigoushengBalance" />
<result column="pingtui_balance" property="pingtuiBalance" />
<result column="tech_charge" property="techCharge" />
<result column="bank_account" property="bankAccount" /> <result column="bank_account" property="bankAccount" />
<result column="bank_card_number" property="bankCardNumber" /> <result column="bank_card_number" property="bankCardNumber" />
<result column="bank_name" property="bankName" /> <result column="bank_name" property="bankName" />
...@@ -27,8 +33,9 @@ ...@@ -27,8 +33,9 @@
</resultMap> </resultMap>
<sql id="Base_Column_List"> <sql id="Base_Column_List">
<!--@mbg.generated--> <!--@mbg.generated-->
id, user_id, agent_id, `month`, balance, opencard_balance, recharge_balance, upgrade_balance, id, user_id, agent_id, yeartime, monthtime, `month`, balance, opencard_balance, recharge_balance,
upgrade_super_balance, tax_balance, bank_account, bank_card_number, bank_name, branch_name, upgrade_balance, upgrade_super_balance, tax_balance, share_balance, zigousheng_balance,
pingtui_balance, tech_charge, bank_account, bank_card_number, bank_name, branch_name,
reference_id, `status`, create_time, modify_time, created_at, updated_at, deleted_at reference_id, `status`, create_time, modify_time, created_at, updated_at, deleted_at
</sql> </sql>
<update id="updateBatch" parameterType="java.util.List"> <update id="updateBatch" parameterType="java.util.List">
...@@ -45,6 +52,16 @@ ...@@ -45,6 +52,16 @@
when id = #{item.id} then #{item.agentId} when id = #{item.id} then #{item.agentId}
</foreach> </foreach>
</trim> </trim>
<trim prefix="yeartime = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.yeartime}
</foreach>
</trim>
<trim prefix="monthtime = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.monthtime}
</foreach>
</trim>
<trim prefix="`month` = case" suffix="end,"> <trim prefix="`month` = case" suffix="end,">
<foreach collection="list" index="index" item="item"> <foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.month} when id = #{item.id} then #{item.month}
...@@ -80,6 +97,26 @@ ...@@ -80,6 +97,26 @@
when id = #{item.id} then #{item.taxBalance} when id = #{item.id} then #{item.taxBalance}
</foreach> </foreach>
</trim> </trim>
<trim prefix="share_balance = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.shareBalance}
</foreach>
</trim>
<trim prefix="zigousheng_balance = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.zigoushengBalance}
</foreach>
</trim>
<trim prefix="pingtui_balance = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.pingtuiBalance}
</foreach>
</trim>
<trim prefix="tech_charge = case" suffix="end,">
<foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.techCharge}
</foreach>
</trim>
<trim prefix="bank_account = case" suffix="end,"> <trim prefix="bank_account = case" suffix="end,">
<foreach collection="list" index="index" item="item"> <foreach collection="list" index="index" item="item">
when id = #{item.id} then #{item.bankAccount} when id = #{item.id} then #{item.bankAccount}
...@@ -144,17 +181,19 @@ ...@@ -144,17 +181,19 @@
<insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true"> <insert id="batchInsert" keyColumn="id" keyProperty="id" parameterType="map" useGeneratedKeys="true">
<!--@mbg.generated--> <!--@mbg.generated-->
insert into agent_salary insert into agent_salary
(user_id, agent_id, `month`, balance, opencard_balance, recharge_balance, upgrade_balance, (user_id, agent_id, yeartime, monthtime, `month`, balance, opencard_balance, recharge_balance,
upgrade_super_balance, tax_balance, bank_account, bank_card_number, bank_name, upgrade_balance, upgrade_super_balance, tax_balance, share_balance, zigousheng_balance,
branch_name, reference_id, `status`, create_time, modify_time, created_at, updated_at, pingtui_balance, tech_charge, bank_account, bank_card_number, bank_name, branch_name,
deleted_at) reference_id, `status`, create_time, modify_time, created_at, updated_at, deleted_at
)
values values
<foreach collection="list" item="item" separator=","> <foreach collection="list" item="item" separator=",">
(#{item.userId}, #{item.agentId}, #{item.month}, #{item.balance}, #{item.opencardBalance}, (#{item.userId}, #{item.agentId}, #{item.yeartime}, #{item.monthtime}, #{item.month},
#{item.rechargeBalance}, #{item.upgradeBalance}, #{item.upgradeSuperBalance}, #{item.taxBalance}, #{item.balance}, #{item.opencardBalance}, #{item.rechargeBalance}, #{item.upgradeBalance},
#{item.bankAccount}, #{item.bankCardNumber}, #{item.bankName}, #{item.branchName}, #{item.upgradeSuperBalance}, #{item.taxBalance}, #{item.shareBalance}, #{item.zigoushengBalance},
#{item.referenceId}, #{item.status}, #{item.createTime}, #{item.modifyTime}, #{item.createdAt}, #{item.pingtuiBalance}, #{item.techCharge}, #{item.bankAccount}, #{item.bankCardNumber},
#{item.updatedAt}, #{item.deletedAt}) #{item.bankName}, #{item.branchName}, #{item.referenceId}, #{item.status}, #{item.createTime},
#{item.modifyTime}, #{item.createdAt}, #{item.updatedAt}, #{item.deletedAt})
</foreach> </foreach>
</insert> </insert>
<insert id="insertOrUpdate" keyColumn="id" keyProperty="id" parameterType="com.lanren.huhu.partner.domain.AgentSalary" useGeneratedKeys="true"> <insert id="insertOrUpdate" keyColumn="id" keyProperty="id" parameterType="com.lanren.huhu.partner.domain.AgentSalary" useGeneratedKeys="true">
...@@ -166,6 +205,8 @@ ...@@ -166,6 +205,8 @@
</if> </if>
user_id, user_id,
agent_id, agent_id,
yeartime,
monthtime,
`month`, `month`,
balance, balance,
opencard_balance, opencard_balance,
...@@ -173,6 +214,10 @@ ...@@ -173,6 +214,10 @@
upgrade_balance, upgrade_balance,
upgrade_super_balance, upgrade_super_balance,
tax_balance, tax_balance,
share_balance,
zigousheng_balance,
pingtui_balance,
tech_charge,
bank_account, bank_account,
bank_card_number, bank_card_number,
bank_name, bank_name,
...@@ -192,6 +237,8 @@ ...@@ -192,6 +237,8 @@
</if> </if>
#{userId}, #{userId},
#{agentId}, #{agentId},
#{yeartime},
#{monthtime},
#{month}, #{month},
#{balance}, #{balance},
#{opencardBalance}, #{opencardBalance},
...@@ -199,6 +246,10 @@ ...@@ -199,6 +246,10 @@
#{upgradeBalance}, #{upgradeBalance},
#{upgradeSuperBalance}, #{upgradeSuperBalance},
#{taxBalance}, #{taxBalance},
#{shareBalance},
#{zigoushengBalance},
#{pingtuiBalance},
#{techCharge},
#{bankAccount}, #{bankAccount},
#{bankCardNumber}, #{bankCardNumber},
#{bankName}, #{bankName},
...@@ -218,6 +269,8 @@ ...@@ -218,6 +269,8 @@
</if> </if>
user_id = #{userId}, user_id = #{userId},
agent_id = #{agentId}, agent_id = #{agentId},
yeartime = #{yeartime},
monthtime = #{monthtime},
`month` = #{month}, `month` = #{month},
balance = #{balance}, balance = #{balance},
opencard_balance = #{opencardBalance}, opencard_balance = #{opencardBalance},
...@@ -225,6 +278,10 @@ ...@@ -225,6 +278,10 @@
upgrade_balance = #{upgradeBalance}, upgrade_balance = #{upgradeBalance},
upgrade_super_balance = #{upgradeSuperBalance}, upgrade_super_balance = #{upgradeSuperBalance},
tax_balance = #{taxBalance}, tax_balance = #{taxBalance},
share_balance = #{shareBalance},
zigousheng_balance = #{zigoushengBalance},
pingtui_balance = #{pingtuiBalance},
tech_charge = #{techCharge},
bank_account = #{bankAccount}, bank_account = #{bankAccount},
bank_card_number = #{bankCardNumber}, bank_card_number = #{bankCardNumber},
bank_name = #{bankName}, bank_name = #{bankName},
...@@ -251,6 +308,12 @@ ...@@ -251,6 +308,12 @@
<if test="agentId != null"> <if test="agentId != null">
agent_id, agent_id,
</if> </if>
<if test="yeartime != null">
yeartime,
</if>
<if test="monthtime != null">
monthtime,
</if>
<if test="month != null"> <if test="month != null">
`month`, `month`,
</if> </if>
...@@ -272,6 +335,18 @@ ...@@ -272,6 +335,18 @@
<if test="taxBalance != null"> <if test="taxBalance != null">
tax_balance, tax_balance,
</if> </if>
<if test="shareBalance != null">
share_balance,
</if>
<if test="zigoushengBalance != null">
zigousheng_balance,
</if>
<if test="pingtuiBalance != null">
pingtui_balance,
</if>
<if test="techCharge != null">
tech_charge,
</if>
<if test="bankAccount != null"> <if test="bankAccount != null">
bank_account, bank_account,
</if> </if>
...@@ -317,6 +392,12 @@ ...@@ -317,6 +392,12 @@
<if test="agentId != null"> <if test="agentId != null">
#{agentId}, #{agentId},
</if> </if>
<if test="yeartime != null">
#{yeartime},
</if>
<if test="monthtime != null">
#{monthtime},
</if>
<if test="month != null"> <if test="month != null">
#{month}, #{month},
</if> </if>
...@@ -338,6 +419,18 @@ ...@@ -338,6 +419,18 @@
<if test="taxBalance != null"> <if test="taxBalance != null">
#{taxBalance}, #{taxBalance},
</if> </if>
<if test="shareBalance != null">
#{shareBalance},
</if>
<if test="zigoushengBalance != null">
#{zigoushengBalance},
</if>
<if test="pingtuiBalance != null">
#{pingtuiBalance},
</if>
<if test="techCharge != null">
#{techCharge},
</if>
<if test="bankAccount != null"> <if test="bankAccount != null">
#{bankAccount}, #{bankAccount},
</if> </if>
...@@ -383,6 +476,12 @@ ...@@ -383,6 +476,12 @@
<if test="agentId != null"> <if test="agentId != null">
agent_id = #{agentId}, agent_id = #{agentId},
</if> </if>
<if test="yeartime != null">
yeartime = #{yeartime},
</if>
<if test="monthtime != null">
monthtime = #{monthtime},
</if>
<if test="month != null"> <if test="month != null">
`month` = #{month}, `month` = #{month},
</if> </if>
...@@ -404,6 +503,18 @@ ...@@ -404,6 +503,18 @@
<if test="taxBalance != null"> <if test="taxBalance != null">
tax_balance = #{taxBalance}, tax_balance = #{taxBalance},
</if> </if>
<if test="shareBalance != null">
share_balance = #{shareBalance},
</if>
<if test="zigoushengBalance != null">
zigousheng_balance = #{zigoushengBalance},
</if>
<if test="pingtuiBalance != null">
pingtui_balance = #{pingtuiBalance},
</if>
<if test="techCharge != null">
tech_charge = #{techCharge},
</if>
<if test="bankAccount != null"> <if test="bankAccount != null">
bank_account = #{bankAccount}, bank_account = #{bankAccount},
</if> </if>
......
...@@ -829,4 +829,9 @@ ...@@ -829,4 +829,9 @@
</if> </if>
</trim> </trim>
</insert> </insert>
<select id="selectOneByOrderSn" resultMap="BaseResultMap">
SELECT * FROM orders_active
WHERE type=#{type} AND order_sn=#{orderSn}
LIMIT 1
</select>
</mapper> </mapper>
\ No newline at end of file
上线SQL:
ALTER TABLE `huhu`.`partner_account_log` ALTER TABLE `huhu`.`partner_account_log`
ADD COLUMN `snapshot` varchar(512) NULL COMMENT '变更前的快照' AFTER `modify_time`; ADD COLUMN `snapshot` varchar(512) NULL COMMENT '变更前的快照' AFTER `modify_time`;
ALTER TABLE `huhu`.`agent_salary`
MODIFY COLUMN `balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '总金额' AFTER `month`,
MODIFY COLUMN `opencard_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '开卡奖励金额' AFTER `balance`,
MODIFY COLUMN `recharge_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '充值奖励金额' AFTER `opencard_balance`,
MODIFY COLUMN `upgrade_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '购买VIP会员奖励金额' AFTER `recharge_balance`,
MODIFY COLUMN `upgrade_super_balance` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '购买超级VIP会员奖励金额' AFTER `upgrade_balance`,
ADD COLUMN `share_balance` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '分享赚奖励' AFTER `upgrade_super_balance`,
ADD COLUMN `zigousheng_balance` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '自购省奖励' AFTER `share_balance`,
ADD COLUMN `pingtui_balance` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '推荐分成奖励' AFTER `zigousheng_balance`,
ADD COLUMN `tech_charge` decimal(20, 6) NOT NULL COMMENT '技术服务费' AFTER `pingtui_balance`,
MODIFY COLUMN `tax_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '缴税金额' AFTER `upgrade_super_balance`;
ALTER TABLE `huhu`.`agent_reward` ALTER TABLE `huhu`.`agent_reward`
MODIFY COLUMN `reward_type` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '奖励类型 40 开卡奖励 50 充值奖励 30 购买VIP会员 20 购买超级VIP会员 60 分享赚 300 自购省 得的购买年-VIP; 720 城市代理商所得的购买半年-VIP; 730 城市代理商所得的购买超级VIP收益; 740 城市代理商的红包收益; 750 城市代理商的自购省收益; 760 城市代理商的分享赚收益 ' AFTER `user_id`; MODIFY COLUMN `reward_type` int(11) UNSIGNED NOT NULL DEFAULT 0 COMMENT '奖励类型 40 开卡奖励 50 充值奖励 30 购买VIP会员 20 购买超级VIP会员 60 分享赚 300 自购省 得的购买年-VIP; 720 城市代理商所得的购买半年-VIP; 730 城市代理商所得的购买超级VIP收益; 740 城市代理商的红包收益; 750 城市代理商的自购省收益; 760 城市代理商的分享赚收益 ' AFTER `user_id`;
ALTER TABLE `huhu`.`agent_account_log` ALTER TABLE `huhu`.`agent_account_log`
ADD COLUMN `snapshot` varchar(255) NOT NULL DEFAULT '' COMMENT '变更前的快照' AFTER `modify_time`; ADD COLUMN `snapshot` varchar(255) NOT NULL DEFAULT '' COMMENT '变更前的快照' AFTER `modify_time`;
ALTER TABLE `huhu`.`partner_account_log`
MODIFY COLUMN `change_num` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的金额 进账为正数 出账为负数' AFTER `type`,
MODIFY COLUMN `changed_amount` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的之后的金额' AFTER `change_num`;
ALTER TABLE `huhu`.`agent_account_log`
MODIFY COLUMN `change_num` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的金额 进账为正数 出账为负数' AFTER `type`,
MODIFY COLUMN `changed_amount` decimal(20, 6) NOT NULL DEFAULT 0 COMMENT '变化的之后的金额' AFTER `change_num`;
ALTER TABLE `huhu`.`agent_account`
MODIFY COLUMN `balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '账户总额' AFTER `account_type`,
MODIFY COLUMN `frozen_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '冻结余额' AFTER `balance`,
MODIFY COLUMN `income_freeze` decimal(20, 6) UNSIGNED NULL DEFAULT 0 COMMENT '收入冻结' AFTER `frozen_balance`,
MODIFY COLUMN `pay_freeze` decimal(20, 6) UNSIGNED NULL DEFAULT 0 COMMENT '出款冻结' AFTER `income_freeze`,
MODIFY COLUMN `free_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '可用余额' AFTER `pay_freeze`,
MODIFY COLUMN `income_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '账户收入总额' AFTER `free_balance`,
MODIFY COLUMN `recharge_income` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '在线充值收入' AFTER `income_balance`,
MODIFY COLUMN `opencard_income` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '账户开卡收入' AFTER `recharge_income`,
MODIFY COLUMN `withdraw_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '提现总额' AFTER `deleted_at`,
MODIFY COLUMN `consume_balance` decimal(20, 6) UNSIGNED NOT NULL DEFAULT 0 COMMENT '消费总额' AFTER `withdraw_balance`;
UPDATE agent_reward a
JOIN user_agent b ON a.agent_id=b.agent_id
SET a.agent_level=b.agent_level
WHERE a.recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59'
AND a.agent_level=0;
测试
select * from agent_salary where agent_id=29 and yeartime=2019 and monthtime=6;
select * from agent_account_log where agent_id=29;
select * from agent_reward where agent_id=29 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59';
select * from agent_income_summary where agent_id=29 and yeartime=2019 and monthtime=6;
delete from agent_salary where agent_id=29 and yeartime=2019 and monthtime=6;
delete from agent_account_log where agent_id=29;
update agent_reward set reward_status=100,settle_state=case when settle_state=300 then 200 else settle_state end where agent_id=29 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59' ;
delete from agent_income_summary where agent_id=29 and yeartime=2019 and monthtime=6;
select * from partner_account_log where user_id=89 order by id desc;
select * from partner_reward where user_id=89 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59';
select * from partner_income_summary where user_id=89 and yeartime=2019 and monthtime=6;
delete from partner_account_log where user_id=89 and yeartime=2019 and monthtime=6;
update partner_reward set reward_status=100,settle_state=case when settle_state=300 then 200 else settle_state end where user_id=89 and recharge_time BETWEEN '2019-06-01 00:00:00' and '2019-06-30 23:59:59' ;
delete from partner_income_summary where user_id=89 and yeartime=2019 and monthtime=6;
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment