| | |
| | | import com.google.gson.*; |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | 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.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; |
| | |
| | | } |
| | | |
| | | |
| | | @RequestMapping("getVIPOrderList") |
| | | @RequestMapping("getOrderList") |
| | | @ResponseBody |
| | | public String getVIPOrderList(AcceptData acceptData, String loginUid, int page) { |
| | | 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) { |
| | |
| | | }).create(); |
| | | JSONObject root = new JSONObject(); |
| | | |
| | | List<OrderRecord> list = orderService.listOrderRecord(loginUid, OrderType.vip,null, page, Constant.pageCount); |
| | | 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) { |
| | | record.setIpInfo(null); |
| | | record.setUpdateTime(null); |
| | | voList.add(OrderInfoVO.create(record)); |
| | | } |
| | | long count = orderService.countOrderRecord(loginUid, OrderType.vip,null); |
| | | root.put("list", gson.toJson(list)); |
| | | 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, String infoId, Integer goldCorn, 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, "请绑定电话号码"); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(priceId) && StringUtil.isNullOrEmpty(infoId)) { |
| | | if (StringUtil.isNullOrEmpty(priceId) && StringUtil.isNullOrEmpty(cid)) { |
| | | return JsonUtilV2.loadFalseJson("请选择购买类型"); |
| | | } |
| | | |
| | | if (goldCorn == null) |
| | | goldCorn = 0; |
| | | |
| | | OrderType orderType = OrderType.vip; |
| | | |
| | | if (!StringUtil.isNullOrEmpty(infoId)) { |
| | | 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.selectVideoPPTVMapByInfoId(infoId); |
| | | 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) { |
| | |
| | | } |
| | | } |
| | | |
| | | OrderRecord record = new OrderRecord(); |
| | | |
| | | record.setUid(loginUid); |
| | | if (vipPrice != null) |
| | | 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.setVideoInfoId(infoId); |
| | | record.setVideoCid(cid); |
| | | record.setVideoVid(vid); |
| | | record.setGoldCorn(goldCorn); |
| | | record.setMoney(vipPrice.getActualPrice()); |
| | | record.setPayWay(payWay); |
| | | record.setState(OrderRecord.STATE_NOT_PAY); |
| | | record.setIpInfo(IPUtil.getRemotIP(request) + ":" + IPUtil.getRemotePort(request)); |
| | |
| | | } |
| | | |
| | | |
| | | PayWayInfoDTO payResult = null; |
| | | |
| | | try { |
| | | orderService.payOrder(record); |
| | | payResult = orderService.payOrder(record); |
| | | } catch (OrderException e) { |
| | | e.printStackTrace(); |
| | | 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("单片购买失败"); |
| | | } |
| | | |
| | | String orderNo = VIPOrderUtil.getOutOrderNo(record.getOrderType(), record.getId()); |
| | | switch (payWay) { |
| | | case OrderRecord |
| | | .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()); |
| | | } |
| | | |
| | | |
| | | case OrderRecord |
| | | .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("生成微信支付订单出错"); |
| | | } |
| | | } |
| | | } |
| | | |
| | | return JsonUtilV2.loadFalseJson("请选择支付方式"); |
| | | return JsonUtilV2.loadTrueJson(new Gson().toJson(payResult)); |
| | | } |
| | | |
| | | /** |