| | |
| | | package com.yeshi.buwan.controller.api; |
| | | |
| | | 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.dto.order.PPTVVideoPrice; |
| | | import com.yeshi.buwan.dto.order.PayWayInfoDTO; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | 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.exception.vip.VideoBuyRecordException; |
| | | import com.yeshi.buwan.pptv.entity.PPTVSeries; |
| | | 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 com.yeshi.buwan.util.vip.VIPOrderUtil; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import com.yeshi.buwan.vo.client.user.UserInfoVO; |
| | | import com.yeshi.buwan.vo.order.OrderInfoVO; |
| | | import net.sf.json.JSONObject; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.ArrayList; |
| | | 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("getOrderList") |
| | | @ResponseBody |
| | | public String getOrderList(AcceptData acceptData, String loginUid, String type, 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<OrderRecord> list = orderService.listOrderRecord(loginUid, type == null ? null : OrderType.valueOf(type), null, page, Constant.pageCount); |
| | | |
| | | List<OrderInfoVO> voList = new ArrayList<>(); |
| | | for (OrderRecord record : list) { |
| | | voList.add(OrderInfoVO.create(record)); |
| | | } |
| | | long count = orderService.countOrderRecord(loginUid, type == null ? null : OrderType.valueOf(type), null); |
| | | root.put("list", gson.toJson(voList)); |
| | | 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 cid, String vid, Integer goldCorn, int payWay) { |
| | | |
| | | if (StringUtil.isNullOrEmpty(loginUid)) { |
| | | return JsonUtilV2.loadFalseJson("用户未登录"); |
| | |
| | | return JsonUtilV2.loadFalseJson(10001, "请绑定电话号码"); |
| | | } |
| | | |
| | | |
| | | String ip = IPUtil.getRemotIP(request); |
| | | VIPPrice vipPrice = vipPriceService.selectByPrimaryKey(priceId); |
| | | if (vipPrice == null) { |
| | | return JsonUtilV2.loadFalseJson("套餐不存在"); |
| | | if (StringUtil.isNullOrEmpty(priceId) && StringUtil.isNullOrEmpty(cid)) { |
| | | return JsonUtilV2.loadFalseJson("请选择购买类型"); |
| | | } |
| | | |
| | | VIPOrderRecord record = new VIPOrderRecord(); |
| | | if (goldCorn == null) |
| | | goldCorn = 0; |
| | | |
| | | OrderType orderType = OrderType.vip; |
| | | |
| | | if (!StringUtil.isNullOrEmpty(cid)) { |
| | | orderType = OrderType.video; |
| | | } |
| | | |
| | | |
| | | String ip = IPUtil.getRemotIP(request); |
| | | |
| | | OrderRecord record = new OrderRecord(); |
| | | |
| | | VIPPrice vipPrice = null; |
| | | |
| | | if (orderType == OrderType.video) { |
| | | PPTVSeries pptvSeries = pptvService.selectSeriesBySeriesCode(cid); |
| | | if (pptvSeries == null) { |
| | | return JsonUtilV2.loadFalseJson("影片不存在"); |
| | | } |
| | | //视频 |
| | | VideoPPTVMap map = pptvService.selectVideoPPTVMapByPPInfo(pptvSeries.getInfoID(), vid); |
| | | if (map == null) { |
| | | return JsonUtilV2.loadFalseJson("影片不存在"); |
| | | } |
| | | record.setRemarks(pptvSeries.getName()); |
| | | } else { |
| | | vipPrice = vipPriceService.selectByPrimaryKey(priceId); |
| | | if (vipPrice == null) { |
| | | return JsonUtilV2.loadFalseJson("套餐不存在"); |
| | | } |
| | | } |
| | | |
| | | |
| | | record.setUid(loginUid); |
| | | record.setType(vipPrice.getType()); |
| | | record.setMoney(vipPrice.getActualPrice()); |
| | | if (vipPrice != null) { |
| | | record.setType(vipPrice.getType()); |
| | | record.setMoney(vipPrice.getActualPrice()); |
| | | } else { |
| | | PPTVVideoPrice price = new Gson().fromJson(systemConfigService.getConfigValueByKeyCache("videoPrice"), PPTVVideoPrice.class); |
| | | record.setMoney(price.getActualPrice().subtract(new BigDecimal(goldCorn).divide(new BigDecimal(100), 2, RoundingMode.UP))); |
| | | } |
| | | |
| | | record.setOrderType(orderType); |
| | | record.setVideoCid(cid); |
| | | record.setVideoVid(vid); |
| | | record.setGoldCorn(goldCorn); |
| | | record.setPayWay(payWay); |
| | | record.setState(VIPOrderRecord.STATE_NOT_PAY); |
| | | record.setState(OrderRecord.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()); |
| | | switch (payWay) { |
| | | case VIPOrderRecord |
| | | .PAY_WAY_ALIPAY: { |
| | | //生成支付宝支付订单 |
| | | String form = VipUtil.getVipChargeAlipayForm(record.getId(), orderNo, record.getMoney()); |
| | | //暂存2分钟 |
| | | String id = StringUtil.Md5(UUID.randomUUID().toString() + "#" + System.currentTimeMillis()); |
| | | redisManager.cacheCommonString(id, form, 120); |
| | | org.json.JSONObject data = new org.json.JSONObject(); |
| | | data.put("payUrl", Constant.HOST + "/BuWan/alipay/printPayForm?formId=" + id); |
| | | data.put("payWay", payWay); |
| | | return JsonUtilV2.loadTrueJson(data.toString()); |
| | | } |
| | | |
| | | PayWayInfoDTO payResult = null; |
| | | |
| | | case VIPOrderRecord |
| | | .PAY_WAY_WX: { |
| | | //生成微信支付订单 |
| | | try { |
| | | String payUrl = VipUtil.createWXOrder(record.getId(), ip, orderNo, vipPrice.getActualPrice(), "影视大全VIP-" + vipPrice.getType().getName()); |
| | | org.json.JSONObject data = new org.json.JSONObject(); |
| | | data.put("payUrl", payUrl); |
| | | data.put("payWay", payWay); |
| | | return JsonUtilV2.loadTrueJson(data.toString()); |
| | | } catch (Exception e) { |
| | | logger.error("生成微信支付订单出错", e); |
| | | return JsonUtilV2.loadFalseJson("生成微信支付订单出错"); |
| | | } |
| | | } |
| | | try { |
| | | payResult = orderService.payOrder(record); |
| | | } catch (OrderException e) { |
| | | return JsonUtilV2.loadFalseJson(e.getMessage()); |
| | | } catch (GoldCornException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtilV2.loadFalseJson(e.getMessage()); |
| | | } catch (PayException e) { |
| | | e.printStackTrace(); |
| | | return JsonUtilV2.loadFalseJson(e.getMessage()); |
| | | } catch (VIPException e) { |
| | | return JsonUtilV2.loadFalseJson(e.getMessage()); |
| | | } catch (PPTVException e) { |
| | | return JsonUtilV2.loadFalseJson(e.getMessage()); |
| | | } catch (VideoBuyRecordException e) { |
| | | return JsonUtilV2.loadFalseJson("单片购买失败"); |
| | | } |
| | | |
| | | return JsonUtilV2.loadFalseJson("请选择支付方式"); |
| | | return JsonUtilV2.loadTrueJson(new Gson().toJson(payResult)); |
| | | } |
| | | |
| | | /** |
| | |
| | | @ResponseBody |
| | | @RequestSerializableByKey(key = "'vip-checkPay-'+#id") |
| | | public String checkPay(AcceptData acceptData, String loginUid, String id) { |
| | | VIPOrderRecord record = vipService.getOrderRecord(id); |
| | | OrderRecord 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) { |
| | | if (record != null && record.getState() != OrderRecord.STATE_PAY) { |
| | | return JsonUtilV2.loadFalseJson(1, "支付未完成"); |
| | | } |
| | | |