| | |
| | | import com.google.gson.*; |
| | | import com.yeshi.buwan.domain.system.SystemConfig; |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.domain.vip.UserVIPInfo; |
| | | import com.yeshi.buwan.domain.vip.VIPOrderRecord; |
| | | import com.yeshi.buwan.domain.vip.VIPPrice; |
| | | import com.yeshi.buwan.domain.vip.VIPPriceType; |
| | | import com.yeshi.buwan.domain.vip.*; |
| | | import com.yeshi.buwan.exception.goldcorn.GoldCornException; |
| | | import com.yeshi.buwan.exception.order.OrderException; |
| | | import com.yeshi.buwan.exception.order.PayException; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.pptv.entity.VideoPPTVMap; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import com.yeshi.buwan.service.inter.order.OrderService; |
| | | import com.yeshi.buwan.service.inter.system.SystemConfigService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPPriceService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.lang.reflect.Type; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | | |
| | |
| | | private VIPService vipService; |
| | | |
| | | @Resource |
| | | private OrderService orderService; |
| | | |
| | | @Resource |
| | | private LoginUserService loginUserService; |
| | | |
| | | @Resource |
| | |
| | | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | @Resource |
| | | private PPTVService pptvService; |
| | | |
| | | |
| | | @RequestMapping("getVIPPriceList") |
| | |
| | | return JsonUtilV2.loadTrueJson(root.toString()); |
| | | } |
| | | |
| | | |
| | | @RequestMapping("getVIPOrderList") |
| | | @ResponseBody |
| | | public String getVIPOrderList(AcceptData acceptData, String loginUid, int page) { |
| | | Gson gson = new GsonBuilder().registerTypeAdapter(VIPPriceType.class, new JsonSerializer<VIPPriceType>() { |
| | | @Override |
| | | public JsonElement serialize(VIPPriceType value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive(""); |
| | | } else { |
| | | return new JsonPrimitive(value.getName()); |
| | | } |
| | | } |
| | | }).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive(""); |
| | | } else { |
| | | return new JsonPrimitive(TimeUtil.getGernalTime(value.getTime(), "yyyy.MM.dd HH:mm")); |
| | | } |
| | | } |
| | | }).create(); |
| | | JSONObject root = new JSONObject(); |
| | | |
| | | List<VIPOrderRecord> list = orderService.listOrderRecord(loginUid, null, page, Constant.pageCount); |
| | | for (VIPOrderRecord record : list) { |
| | | record.setIpInfo(null); |
| | | record.setUpdateTime(null); |
| | | } |
| | | long count = orderService.countOrderRecord(loginUid, null); |
| | | root.put("list", gson.toJson(list)); |
| | | root.put("count", count); |
| | | return JsonUtilV2.loadTrueJson(root.toString()); |
| | | } |
| | | |
| | | /** |
| | | * 生成订单 |
| | | * |
| | |
| | | */ |
| | | @RequestMapping("createOrder") |
| | | @ResponseBody |
| | | public String createOrder(AcceptData acceptData, HttpServletRequest request, String loginUid, String priceId, int payWay) { |
| | | public String createOrder(AcceptData acceptData, HttpServletRequest request, String loginUid, String priceId, String infoId, Integer goldCorn, int payWay) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(loginUid)) { |
| | | return JsonUtilV2.loadFalseJson("用户未登录"); |
| | |
| | | return JsonUtilV2.loadFalseJson(10001, "请绑定电话号码"); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(priceId) && StringUtil.isNullOrEmpty(infoId)) { |
| | | return JsonUtilV2.loadFalseJson("请选择购买类型"); |
| | | } |
| | | |
| | | OrderType orderType = OrderType.vip; |
| | | |
| | | if (!StringUtil.isNullOrEmpty(infoId)) { |
| | | orderType = OrderType.video; |
| | | } |
| | | |
| | | |
| | | String ip = IPUtil.getRemotIP(request); |
| | | VIPPrice vipPrice = vipPriceService.selectByPrimaryKey(priceId); |
| | | if (vipPrice == null) { |
| | | return JsonUtilV2.loadFalseJson("套餐不存在"); |
| | | |
| | | VIPPrice vipPrice = null; |
| | | if (orderType == OrderType.video) { |
| | | //视频 |
| | | VideoPPTVMap map = pptvService.selectVideoPPTVMapByInfoId(infoId); |
| | | if (map == null) { |
| | | return JsonUtilV2.loadFalseJson("影片不存在"); |
| | | } |
| | | } else { |
| | | vipPrice = vipPriceService.selectByPrimaryKey(priceId); |
| | | if (vipPrice == null) { |
| | | return JsonUtilV2.loadFalseJson("套餐不存在"); |
| | | } |
| | | } |
| | | |
| | | VIPOrderRecord record = new VIPOrderRecord(); |
| | | record.setUid(loginUid); |
| | | record.setType(vipPrice.getType()); |
| | | if (vipPrice != null) |
| | | record.setType(vipPrice.getType()); |
| | | |
| | | record.setOrderType(orderType); |
| | | record.setVideoInfoId(infoId); |
| | | record.setGoldCorn(goldCorn); |
| | | record.setMoney(vipPrice.getActualPrice()); |
| | | record.setPayWay(payWay); |
| | | record.setState(VIPOrderRecord.STATE_NOT_PAY); |
| | | record.setIpInfo(IPUtil.getRemotIP(request) + ":" + IPUtil.getRemotePort(request)); |
| | | try { |
| | | vipService.addVIPRecord(record); |
| | | } catch (VIPException e) { |
| | | orderService.createOrder(record); |
| | | } catch (OrderException e) { |
| | | logger.error("生成订单出错", e); |
| | | return JsonUtilV2.loadFalseJson("生成订单出错"); |
| | | } |
| | | |
| | | String orderNo = VIPOrderUtil.getOutOrderNo(record.getId()); |
| | | |
| | | try { |
| | | orderService.payOrder(record); |
| | | } catch (OrderException e) { |
| | | e.printStackTrace(); |
| | | } catch (GoldCornException e) { |
| | | e.printStackTrace(); |
| | | } catch (PayException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | String orderNo = VIPOrderUtil.getOutOrderNo(record.getOrderType(), record.getId()); |
| | | switch (payWay) { |
| | | case VIPOrderRecord |
| | | .PAY_WAY_ALIPAY: { |
| | |
| | | @ResponseBody |
| | | @RequestSerializableByKey(key = "'vip-checkPay-'+#id") |
| | | public String checkPay(AcceptData acceptData, String loginUid, String id) { |
| | | VIPOrderRecord record = vipService.getOrderRecord(id); |
| | | VIPOrderRecord record = orderService.getOrderRecord(id); |
| | | if (record == null || !record.getUid().equalsIgnoreCase(loginUid)) { |
| | | return JsonUtilV2.loadFalseJson("记录不存在/不是您的订单"); |
| | | } |
| | | |
| | | record = vipService.checkOrderPayState(id); |
| | | record = orderService.checkOrderPayState(id); |
| | | //未支付 |
| | | if (record != null && record.getState() != VIPOrderRecord.STATE_PAY) { |
| | | return JsonUtilV2.loadFalseJson(1, "支付未完成"); |