package com.yeshi.fanli.controller.client;
|
|
import java.io.PrintWriter;
|
import java.util.ArrayList;
|
import java.util.List;
|
import java.util.Map;
|
|
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 com.yeshi.fanli.entity.accept.AcceptData;
|
import com.yeshi.fanli.entity.bus.homemodule.SwiperPicture;
|
import com.yeshi.fanli.exception.user.UserSystemCouponException;
|
import com.yeshi.fanli.service.inter.config.ConfigService;
|
import com.yeshi.fanli.service.inter.homemodule.SwiperPictureService;
|
import com.yeshi.fanli.service.inter.order.CommonOrderService;
|
import com.yeshi.fanli.service.inter.user.UserSystemCouponService;
|
import com.yeshi.fanli.util.Constant;
|
import com.yeshi.fanli.vo.user.UserSystemCouponRecordVO;
|
import com.yeshi.fanli.vo.user.UserSystemCouponVO;
|
|
import net.sf.json.JSONObject;
|
|
/**
|
* 福利中心
|
* @author Administrator
|
*
|
*/
|
@Controller
|
@RequestMapping("api/v1/user/coupon")
|
public class UserCouponController {
|
|
@Resource
|
private ConfigService configService;
|
|
@Resource
|
private UserSystemCouponService UserSystemCouponService;
|
|
@Resource
|
private SwiperPictureService swiperPictureService;
|
|
@Resource
|
private CommonOrderService commonOrderService;
|
|
/**
|
* 用户券列表查询
|
* @param acceptData
|
* @param page
|
* @param uid
|
* @param out
|
*/
|
@RequestMapping(value = "getCouponList", method = RequestMethod.POST)
|
public void getCouponList(AcceptData acceptData, Integer page, Long uid, PrintWriter out) {
|
if (uid == null) {
|
out.print(JsonUtil.loadFalseResult("用户未登录"));
|
return;
|
}
|
|
try {
|
if (page == null || page < 1) {
|
page = 1;
|
}
|
|
// 福利中心图片
|
String topPicture = null;
|
if(page == 1) {
|
List<SwiperPicture> listswiper = swiperPictureService.getByBannerCard("welfare_top");
|
if (listswiper != null && listswiper.size() > 0) {
|
topPicture = listswiper.get(0).getSrc();
|
}
|
}
|
|
long count = 0;
|
List<UserSystemCouponVO> resultList = UserSystemCouponService.getUserCouponVOList((page - 1) * Constant.PAGE_SIZE,
|
Constant.PAGE_SIZE, uid );
|
|
if (resultList != null && resultList.size() > 0) {
|
count = UserSystemCouponService.countUserCouponList(uid);
|
} else if (resultList == null) {
|
resultList = new ArrayList<UserSystemCouponVO>();
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("topPicture", topPicture);
|
data.put("count", count);
|
data.put("result_list", JsonUtil.getApiCommonGson().toJson(resultList));
|
|
out.print(JsonUtil.loadTrueResult(data));
|
|
} catch (UserSystemCouponException e) {
|
out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(1, "查询失败"));
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 用户奖励券
|
* @param acceptData
|
* @param page
|
* @param uid
|
* @param out
|
*/
|
@RequestMapping(value = "getGoodsCouponList", method = RequestMethod.POST)
|
public void getGoodsCouponList(AcceptData acceptData, Long uid, PrintWriter out) {
|
if (uid == null) {
|
out.print(JsonUtil.loadFalseResult("用户未登录"));
|
return;
|
}
|
|
try {
|
List<UserSystemCouponVO> resultList = UserSystemCouponService.getGoodsCouponList(uid);
|
|
if (resultList == null ) {
|
resultList =new ArrayList<UserSystemCouponVO>();
|
}
|
|
JSONObject dataTip = new JSONObject();
|
dataTip.put("content", configService.get("free_coupon_tip"));
|
dataTip.put("fontColor", "#F14242");
|
|
JSONObject data = new JSONObject();
|
data.put("helpLink", configService.get("free_coupon_help"));
|
data.put("tip", dataTip);
|
data.put("count", resultList.size());
|
data.put("result_list", JsonUtil.getApiCommonGson().toJson(resultList));
|
|
out.print(JsonUtil.loadTrueResult(data));
|
|
} catch (UserSystemCouponException e) {
|
out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(1, "查询失败"));
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 免单券使用记录 以及状态修改
|
* @param acceptData
|
* @param page
|
* @param uid
|
* @param out
|
*/
|
@RequestMapping(value = "useFreeCoupon", method = RequestMethod.POST)
|
public void useFreeCoupon(AcceptData acceptData, Long uid, Long cid, Long goodId, PrintWriter out) {
|
if (uid == null) {
|
out.print(JsonUtil.loadFalseResult("用户未登录"));
|
return;
|
}
|
|
try {
|
UserSystemCouponService.useGoodsCoupon(uid, cid, goodId);
|
out.print(JsonUtil.loadTrueResult("使用成功"));
|
} catch (UserSystemCouponException e) {
|
out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(1, "使用失败"));
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 用户奖励券
|
* @param acceptData
|
* @param page
|
* @param uid
|
* @param out
|
*/
|
@RequestMapping(value = "getOrderCouponList", method = RequestMethod.POST)
|
public void getOrderCouponList(AcceptData acceptData, Long uid, PrintWriter out) {
|
|
if (uid == null) {
|
out.print(JsonUtil.loadFalseResult("用户未登录"));
|
return;
|
}
|
|
try {
|
List<UserSystemCouponVO> resultList = UserSystemCouponService.getOrderCouponList(uid);
|
|
if (resultList == null ) {
|
resultList =new ArrayList<UserSystemCouponVO>();
|
}
|
|
JSONObject data = new JSONObject();
|
data.put("helpLink", configService.get("reward_coupon_help"));
|
data.put("count", resultList.size());
|
data.put("result_list", JsonUtil.getApiCommonGson().toJson(resultList));
|
|
out.print(JsonUtil.loadTrueResult(data));
|
|
} catch (UserSystemCouponException e) {
|
out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(1, "查询失败"));
|
e.printStackTrace();
|
}
|
}
|
|
|
/**
|
* 免单券使用记录 以及状态修改
|
* @param acceptData
|
* @param page
|
* @param uid
|
* @param out
|
*/
|
@RequestMapping(value = "useRewardCoupon", method = RequestMethod.POST)
|
public void useRewardCoupon(AcceptData acceptData, Long uid, Long cid, String orderNo, PrintWriter out) {
|
|
if (uid == null) {
|
out.print(JsonUtil.loadFalseResult("用户未登录"));
|
return;
|
}
|
|
try {
|
UserSystemCouponService.useOrderCoupon(uid, cid, orderNo);
|
|
JSONObject data = commonOrderService.getRewardJumpInfo(orderNo);
|
|
out.print(JsonUtil.loadTrueResult(data));
|
|
} catch (UserSystemCouponException e) {
|
out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(1, "使用失败"));
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 订单-奖励进度详情
|
* @param acceptData
|
* @param orderNo 订单号
|
* @param out
|
*/
|
@RequestMapping(value = "getRewardRecord", method = RequestMethod.POST)
|
public void getRewardCounponRecord(AcceptData acceptData, String orderNo, PrintWriter out) {
|
|
try {
|
|
UserSystemCouponRecordVO rewardRecord = UserSystemCouponService.getRewardCouponRecord(orderNo);
|
|
JSONObject data = new JSONObject();
|
data.put("rewardRecord", rewardRecord);
|
|
out.print(JsonUtil.loadTrueResult(data));
|
|
} catch (UserSystemCouponException e) {
|
out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(1, "查询失败"));
|
e.printStackTrace();
|
}
|
}
|
|
/**
|
* 订单-奖励进度详情
|
* @param acceptData
|
* @param orderNo 订单号
|
* @param out
|
*/
|
@RequestMapping(value = "getFreeCounponRecord", method = RequestMethod.POST)
|
public void getFreeCounponRecord(AcceptData acceptData, String orderNo, PrintWriter out) {
|
|
try {
|
|
UserSystemCouponRecordVO rewardRecord = UserSystemCouponService.getFreeCouponRecord(orderNo);
|
|
JSONObject data = new JSONObject();
|
data.put("frreCouponRecord", rewardRecord);
|
|
out.print(JsonUtil.loadTrueResult(data));
|
|
} catch (UserSystemCouponException e) {
|
out.print(JsonUtil.loadFalseResult(e.getCode(), e.getMsg()));
|
} catch (Exception e) {
|
out.print(JsonUtil.loadFalseResult(1, "查询失败"));
|
e.printStackTrace();
|
}
|
}
|
|
}
|