package com.yeshi.fanli.controller.client;
|
|
import java.io.PrintWriter;
|
import java.util.List;
|
|
import javax.annotation.Resource;
|
|
import org.springframework.stereotype.Controller;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMethod;
|
import org.yeshi.utils.JsonUtil;
|
import org.yeshi.utils.NumberUtil;
|
|
import com.google.gson.Gson;
|
import com.yeshi.fanli.entity.accept.AcceptData;
|
import com.yeshi.fanli.entity.bus.user.LostOrder;
|
import com.yeshi.fanli.service.inter.order.LostOrderService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.util.TimeUtil;
|
import com.yeshi.fanli.util.Utils;
|
|
import net.sf.json.JSONArray;
|
import net.sf.json.JSONObject;
|
|
/**
|
* 动态
|
*
|
* @author Administrator
|
*
|
*/
|
@Controller
|
@RequestMapping("api/v1/lostOrder")
|
public class LostOrderController {
|
|
@Resource
|
private LostOrderService lostOrderService;
|
|
/**
|
* 获取动态推荐
|
*
|
* @param acceptData
|
* @param page
|
* -页码
|
* @param out
|
*/
|
@RequestMapping(value = "getLostOrderList", method = RequestMethod.POST)
|
public void getLostOrderList(AcceptData acceptData, Long uid, int page, PrintWriter out) {
|
if (uid == null || uid <= 0) {
|
out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
return;
|
}
|
|
if (page < 1) {
|
out.print(JsonUtil.loadFalseResult(2, "页码必须大于0"));
|
return;
|
}
|
|
long count = lostOrderService.getLostOrderCountByUid(uid);
|
|
List<LostOrder> list = lostOrderService.getLostOrderListByUid(uid, page, Constant.PAGE_SIZE);
|
JSONArray data = new JSONArray();
|
Gson gson = new Gson();
|
if (list != null)
|
for (LostOrder order : list) {
|
order.setOrder(null);
|
order.setUserInfo(null);
|
JSONObject json = JSONObject.fromObject(gson.toJson(order));
|
json.remove("resultCode");
|
json.remove("remake");
|
json.remove("judge");
|
|
json.put("createTime", TimeUtil.getGernalTime(order.getCreateTime(), "yyyy-MM-dd HH:mm"));
|
if (order.getState() == 1 && order.getResultCode() == LostOrder.RESULT_CODE_SUCCESS) {
|
// 申诉成功
|
json.put("state", 1);
|
json.put("stateDesc", "申诉成功,请在订单列表中查看");
|
} else if (order.getState() == 2
|
|| (order.getState() == 1 && order.getResultCode() == LostOrder.RESULT_CODE_FAIL)) {
|
// 申诉失败
|
json.put("state", 2);
|
json.put("stateDesc", "申诉失败");
|
} else {
|
// 处理中
|
json.put("state", 0);
|
json.put("stateDesc", "审核中");
|
}
|
data.add(json);
|
}
|
|
JSONObject root = new JSONObject();
|
root.put("data", data);
|
root.put("count", count);
|
out.print(JsonUtil.loadTrueResult(root));
|
}
|
|
@RequestMapping(value = "deleteLostOrder", method = RequestMethod.POST)
|
public void deleteLostOrder(AcceptData acceptData, Long uid, long id, PrintWriter out) {
|
if (uid == null || uid <= 0) {
|
out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
return;
|
}
|
LostOrder lostOrder = lostOrderService.getOne(id);
|
if (lostOrder != null && lostOrder.getUserInfo().getId() == uid) {
|
lostOrderService.deleteLostOrder(id);
|
out.print(JsonUtil.loadTrueResult(""));
|
} else {
|
out.print(JsonUtil.loadFalseResult(1, "删除失败"));
|
}
|
}
|
|
@RequestMapping(value = "deleteAllLostOrder", method = RequestMethod.POST)
|
public void deleteAllLostOrder(AcceptData acceptData, Long uid, PrintWriter out) {
|
if (uid == null || uid <= 0) {
|
out.print(JsonUtil.loadFalseResult(1, "用户未登录"));
|
return;
|
}
|
lostOrderService.deleteLostOrderByUid(uid);
|
out.print(JsonUtil.loadTrueResult(""));
|
}
|
|
@RequestMapping("findLostOrder")
|
public void findLostOrder(AcceptData acceptData, LostOrder lostOrder, PrintWriter out) {
|
boolean orderNum = true;
|
|
if (!NumberUtil.isNumeric(lostOrder.getOrderId())) {
|
orderNum = false;
|
} else if (lostOrder.getOrderId().length() < 12 || lostOrder.getOrderId().length() > 20) {
|
orderNum = false;
|
} else
|
orderNum = Utils.isOrderNum(lostOrder.getOrderId());
|
|
if (lostOrder.getUserInfo() == null || lostOrder.getUserInfo().getId() == null
|
|| lostOrder.getUserInfo().getId() <= 0) {
|
out.print(JsonUtil.loadFalseResult(1, "用户尚未登录"));
|
return;
|
}
|
|
int state;
|
String stateInfo = "提交成功,请等待审核结果。";
|
if (!orderNum) {
|
state = -4;
|
stateInfo = "请提交标准的订单号";
|
} else {
|
state = lostOrderService.addLostOrder(lostOrder);
|
if (state == -3) {
|
stateInfo = "该订单已是返利订单。";
|
} else if (state == -2) {
|
stateInfo = "请勿重复提交,该订单已在审核中。";
|
} else if (state == -1) {
|
stateInfo = "该订单申诉已通过,请稍后查看。";
|
} else if (state == -5) {
|
stateInfo = "该订单为分享奖金订单";
|
}
|
}
|
JSONObject data = new JSONObject();
|
data.put("state", state);
|
data.put("info", stateInfo);
|
out.print(JsonUtil.loadTrueResult(data));
|
}
|
|
}
|