package com.yeshi.fanli.controller.admin.user.vip;
|
|
import java.io.PrintWriter;
|
import java.lang.reflect.Type;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
import javax.servlet.http.HttpServletRequest;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.yeshi.utils.IPUtil;
|
import org.yeshi.utils.JsonUtil;
|
|
import com.google.gson.Gson;
|
import com.google.gson.GsonBuilder;
|
import com.google.gson.JsonElement;
|
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonSerializationContext;
|
import com.google.gson.JsonSerializer;
|
import com.yeshi.fanli.entity.bus.user.UserInfo;
|
import com.yeshi.fanli.entity.bus.user.vip.GiveVIPApplyInfo;
|
import com.yeshi.fanli.entity.bus.user.vip.UserLevelEnum;
|
import com.yeshi.fanli.entity.common.AdminUser;
|
import com.yeshi.fanli.exception.user.vip.GiveVIPApplyInfoException;
|
import com.yeshi.fanli.exception.user.vip.UserVIPPreInfoException;
|
import com.yeshi.fanli.log.LogHelper;
|
import com.yeshi.fanli.service.inter.user.UserInfoService;
|
import com.yeshi.fanli.service.inter.user.vip.GiveVIPApplyInfoService;
|
import com.yeshi.fanli.tag.PageEntity;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.StringUtil;
|
import com.yeshi.fanli.util.annotation.RequestSerializableByKey;
|
|
import net.sf.json.JSONObject;
|
|
@Controller
|
@RequestMapping("admin/new/api/v1/vip")
|
public class UserVipApplyAdminController {
|
|
@Resource
|
private GiveVIPApplyInfoService giveVIPApplyInfoService;
|
|
@Resource
|
private UserInfoService userInfoService;
|
|
/**
|
*
|
* @param callback
|
* @param pageIndex
|
* @param pageSize
|
* @param key 搜索:暂只提供uid
|
* @param state 状态:
|
* @param out
|
*/
|
@RequestMapping(value = "queryVip")
|
public void queryVip(String callback, Integer pageIndex, Integer pageSize, String key, Integer state,
|
PrintWriter out) {
|
try {
|
|
Long targetUid = null;
|
try {
|
targetUid = Long.parseLong(key);
|
} catch (Exception e) {
|
}
|
|
List<GiveVIPApplyInfo> list = giveVIPApplyInfoService.listByStateAndTargetUid(targetUid, state, pageIndex,
|
pageSize);
|
|
if (list == null || list.size() == 0) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("暂无数据"));
|
return;
|
}
|
|
for (GiveVIPApplyInfo info : list) {
|
// 组织用户信息
|
UserInfo userInfo = userInfoService.getUserById(info.getTargetUid());
|
UserInfo simpleInfo = new UserInfo(userInfo.getId());
|
simpleInfo.setNickName(userInfo.getNickName());
|
simpleInfo.setPortrait(userInfo.getPortrait());
|
info.setTargetUser(simpleInfo);
|
// 组织其他平台信息
|
if (info.getHasDoOtherPlatform() != null && info.getHasDoOtherPlatform()) {
|
String st = "平台:" + (StringUtil.isNullOrEmpty(info.getOtherPlatformName()) ? "未知"
|
: info.getOtherPlatformName());
|
st += "\n粉丝数:";
|
st += "直接粉丝数(" + (info.getOtherDirectTeams() == null ? "未知" : info.getOtherDirectTeams());
|
|
st += ") 间接粉丝数(" + (info.getOtherInDirectTeams() == null ? "未知" : info.getOtherInDirectTeams())
|
+ ")";
|
|
st += "\n平台等级:" + (StringUtil.isNullOrEmpty(info.getOtherLevel()) ? "未知" : info.getOtherLevel());
|
|
st += "\n月均收入:" + (StringUtil.isNullOrEmpty(info.getOtherMonthIncome()) ? "未知"
|
: info.getOtherMonthIncome());
|
|
info.setOtherPlatformInfo(st);
|
} else {
|
info.setOtherPlatformInfo("暂无");
|
}
|
|
}
|
|
long count = giveVIPApplyInfoService.countByStateAndTargetUid(targetUid, state);
|
int totalPage = (int) (count % pageSize == 0 ? count / pageSize : count / pageSize + 1);
|
PageEntity pe = new PageEntity(pageIndex, pageSize, count, totalPage);
|
|
GsonBuilder gsonBuilder = new GsonBuilder().registerTypeAdapter(UserLevelEnum.class,
|
new JsonSerializer<UserLevelEnum>() {
|
|
public JsonElement serialize(UserLevelEnum arg0, Type arg1, JsonSerializationContext arg2) {
|
return new JsonPrimitive(arg0.getName());
|
}
|
});
|
gsonBuilder.serializeNulls();
|
Gson gson = gsonBuilder.setDateFormat("yyyy/MM/dd HH:mm:ss").create();
|
|
JSONObject data = new JSONObject();
|
data.put("pe", pe);
|
data.put("result_list", gson.toJson(list));
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult(data));
|
} catch (Exception e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作异常"));
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 超级会员升级通过
|
* @param callback
|
* @param id
|
* @param out
|
* @param request
|
* @throws UserVIPPreInfoException
|
*/
|
@RequestSerializableByKey(key = "'passApplyVIP-' +#id")
|
@RequestMapping(value = "passVIP")
|
public void passVIP(String callback, String id, PrintWriter out, HttpServletRequest request) {
|
try {
|
/* 检验是否登陆 */
|
AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
|
if (admin == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("当前账户失效,请重新登陆。"));
|
return;
|
}
|
giveVIPApplyInfoService.pass(id, admin.getId());
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("操作成功"));
|
LogHelper.userInfo(
|
"[ip:" + IPUtil.getRemotIP(request) + "]" + admin.getName() + "通过了[id=" + id + "]的升级会员申请!");
|
} catch (GiveVIPApplyInfoException e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
return;
|
} catch (UserVIPPreInfoException e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
}
|
}
|
|
/**
|
* 超级会员升级拒绝
|
* @param callback
|
* @param id
|
* @param reason
|
* @param out
|
* @param request
|
*/
|
|
@RequestMapping(value = "rejectVIP")
|
public void rejectVIP(String callback, String id, String reason, PrintWriter out, HttpServletRequest request) {
|
try {
|
/* 检验是否登陆 */
|
AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
|
if (admin == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("当前账户失效,请重新登陆"));
|
return;
|
}
|
|
giveVIPApplyInfoService.reject(id, admin.getId(), reason);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("拒绝成功"));
|
LogHelper.userInfo("[ip:" + IPUtil.getRemotIP(request) + "][管理员:" + admin.getName() + "] 拒绝提现id=" + id
|
+ "的升级超级会员申请不存在!");
|
} catch (GiveVIPApplyInfoException e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
return;
|
} catch (Exception e) {
|
e.printStackTrace();
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
|
return;
|
}
|
}
|
|
@RequestMapping(value = "apply")
|
public void apply(String callback, Long uid, String level, String applyReason, PrintWriter out,
|
HttpServletRequest request) {
|
try {
|
/* 检验是否登陆 */
|
AdminUser admin = (AdminUser) request.getSession().getAttribute(Constant.SESSION_ADMIN);
|
if (admin == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("当前账户失效,请重新登陆"));
|
return;
|
}
|
|
UserInfo user = userInfoService.selectAvailableByPrimaryKey(uid);
|
if (user == null) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("用户不存在或已经被封禁"));
|
return;
|
}
|
|
GiveVIPApplyInfo info = new GiveVIPApplyInfo();
|
info.setApplyReason(applyReason);
|
info.setTargetUid(uid);
|
info.setSourceUid(uid);
|
info.setMark(String.format("管理员(%s)代为申请", admin.getName()));
|
info.setLevel(UserLevelEnum.valueOf(level));
|
giveVIPApplyInfoService.addGiveVIPApplyInfo(info);
|
JsonUtil.printMode(out, callback, JsonUtil.loadTrueResult("成功"));
|
} catch (GiveVIPApplyInfoException e) {
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult(e.getMsg()));
|
return;
|
} catch (Exception e) {
|
e.printStackTrace();
|
JsonUtil.printMode(out, callback, JsonUtil.loadFalseResult("操作失败"));
|
return;
|
}
|
}
|
|
}
|