package com.taoke.autopay.controller.agent;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.TypeAdapter;
|
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonWriter;
|
import com.taoke.autopay.dao.KeyOrderMapper;
|
import com.taoke.autopay.dao.agent.ChannelAgentMapper;
|
import com.taoke.autopay.dto.ChannelOrderStatistic;
|
import com.taoke.autopay.entity.KeyOrder;
|
import com.taoke.autopay.entity.OrderChannelEnum;
|
import com.taoke.autopay.entity.SystemConfigKeyEnum;
|
import com.taoke.autopay.entity.agent.ChannelAgent;
|
import com.taoke.autopay.entity.agent.ChannelAgentSettings;
|
import com.taoke.autopay.entity.agent.ChannelAgentSharingRatio;
|
import com.taoke.autopay.exception.ChannelAgentException;
|
import com.taoke.autopay.factory.AgentFactory;
|
import com.taoke.autopay.factory.OrderFactory;
|
import com.taoke.autopay.service.KeyOrderService;
|
import com.taoke.autopay.service.SystemConfigService;
|
import com.taoke.autopay.service.agent.ChannelAgentService;
|
import com.taoke.autopay.service.agent.ChannelAgentSettingService;
|
import com.taoke.autopay.service.agent.ChannelAgentSharingRatioService;
|
import com.taoke.autopay.utils.Constant;
|
import com.taoke.autopay.utils.StringUtil;
|
import com.taoke.autopay.utils.TimeUtil;
|
import com.taoke.autopay.vo.AgentOrderFilter;
|
import com.taoke.autopay.vo.AgentOrderVO;
|
import com.taoke.autopay.vo.OrderFilter;
|
import com.taoke.autopay.vo.admin.AdminChannelAgentVO;
|
import com.taoke.autopay.vo.admin.AgentSearchVO;
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.ResponseBody;
|
import org.yeshi.utils.JsonUtil;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpSession;
|
import java.io.IOException;
|
import java.math.BigDecimal;
|
import java.util.*;
|
|
@Controller
|
@RequestMapping("/agentapi/admin")
|
public class AgentController {
|
|
private Gson gson = new GsonBuilder().registerTypeAdapter(Date.class, new TypeAdapter<Date>() {
|
@Override
|
public void write(JsonWriter out, Date value) throws IOException {
|
String desc = "";
|
if (value != null) {
|
// 判断是否是同一天
|
desc = TimeUtil.getGernalTime(value.getTime(), "yyyy-MM-dd HH:mm:ss");
|
out.value(desc);
|
} else {
|
out.value("");
|
}
|
}
|
|
@Override
|
public Date read(JsonReader in) throws IOException {
|
return new Date();
|
}
|
}).create();
|
|
@Resource
|
private ChannelAgentService channelAgentService;
|
|
|
@Resource
|
private KeyOrderService keyOrderService;
|
|
@Resource
|
private ChannelAgentSharingRatioService channelAgentSharingRatioService;
|
|
|
@ResponseBody
|
@RequestMapping("login")
|
public String login(String account, String pwd, HttpSession session) {
|
try {
|
ChannelAgent agent = channelAgentService.login(account, pwd);
|
agent.setPwd(null);
|
session.setAttribute(Constant.SESSION_KEY_AGENT, agent);
|
return JsonUtil.loadTrueResult(agent);
|
} catch (ChannelAgentException e) {
|
return JsonUtil.loadFalseResult(e.getMessage());
|
}
|
}
|
|
@ResponseBody
|
@RequestMapping("setAlipayAccount")
|
public String setAlipayAccount(String alipayAccount, String alipayName, HttpSession session) {
|
ChannelAgent agent = (ChannelAgent) session.getAttribute(Constant.SESSION_KEY_AGENT);
|
if (agent == null) {
|
return JsonUtil.loadFalseResult("尚未登录");
|
}
|
|
try {
|
channelAgentService.setAlipayAccount(agent.getId(), alipayName, alipayAccount);
|
return JsonUtil.loadTrueResult("");
|
} catch (ChannelAgentException e) {
|
return JsonUtil.loadFalseResult(e.getMessage());
|
}
|
}
|
|
|
@ResponseBody
|
@RequestMapping("orderList")
|
public String orderList(AgentOrderFilter filter, HttpSession session) {
|
ChannelAgent agent = (ChannelAgent) session.getAttribute(Constant.SESSION_KEY_AGENT);
|
KeyOrderMapper.DaoQuery query = new KeyOrderMapper.DaoQuery();
|
query.agentId = agent.getId();
|
if (!StringUtil.isNullOrEmpty(filter.getKey())) {
|
query.nickName = filter.getKey().trim();
|
}
|
query.start = (filter.getPage() - 1) * 20L;
|
query.count = 20;
|
|
long now = System.currentTimeMillis();
|
String nowDay = TimeUtil.getGernalTime(now, "yyyy-MM-dd");
|
switch (filter.getTimeIndex()) {
|
case 0:
|
query.oMinCreateTime = new Date(TimeUtil.convertToTimeTemp(nowDay, "yyyy-MM-dd"));
|
break;
|
case 1:
|
query.oMaxCreateTime = new Date(TimeUtil.convertToTimeTemp(nowDay, "yyyy-MM-dd"));
|
query.oMinCreateTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now - 24 * 60 * 60 * 1000L, "yyyy-MM-dd"), "yyyy-MM-dd"));
|
break;
|
case 2:
|
query.oMaxCreateTime = new Date(TimeUtil.convertToTimeTemp(nowDay, "yyyy-MM-dd"));
|
query.oMinCreateTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now - 24 * 60 * 60 * 1000L * 3, "yyyy-MM-dd"), "yyyy-MM-dd"));
|
case 3:
|
Calendar calendar = Calendar.getInstance();
|
calendar.setTime(new Date(now));
|
int day = calendar.get(Calendar.DAY_OF_WEEK);
|
day -= 1;
|
if (day == 0) {
|
// 星期天
|
day = 7;
|
}
|
query.oMinCreateTime = new Date(TimeUtil.convertToTimeTemp(TimeUtil.getGernalTime(now - 24 * 60 * 60 * 1000L * (day - 1), "yyyy-MM-dd"), "yyyy-MM-dd"));
|
break;
|
}
|
|
query.sortList = Arrays.asList(new String[]{"o.create_time desc"});
|
|
List<KeyOrder> list = keyOrderService.listWithUser(query);
|
long count = keyOrderService.countWithUser(query);
|
query.hasPayTime = true;
|
ChannelOrderStatistic statistic = keyOrderService.statisticWithUser(query);
|
|
List<AgentOrderVO> voList = new ArrayList<>();
|
Map<OrderChannelEnum, BigDecimal> shareMoneyMap = channelAgentSharingRatioService.getShareMoneyMap(agent.getId());
|
for (KeyOrder order : list) {
|
BigDecimal money = null;
|
for (OrderChannelEnum channel : OrderChannelEnum.values()) {
|
if (channel.getKey().equalsIgnoreCase(order.getOrderChannel())) {
|
money = shareMoneyMap.get(channel);
|
break;
|
}
|
}
|
if (money == null) {
|
money = new BigDecimal(0);
|
}
|
AgentOrderVO vo = OrderFactory.createAgentOrder(order, money);
|
voList.add(vo);
|
}
|
JSONObject data = new JSONObject();
|
data.put("list", voList);
|
data.put("count", count);
|
data.put("statistic", statistic);
|
return JsonUtil.loadTrueResult(data);
|
}
|
|
|
}
|