| | |
| | | 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.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 javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.UUID; |
| | |
| | | |
| | | String ip = IPUtil.getRemotIP(request); |
| | | |
| | | OrderRecord record = new OrderRecord(); |
| | | |
| | | VIPPrice vipPrice = null; |
| | | |
| | | if (orderType == OrderType.video) { |
| | | //视频 |
| | | VideoPPTVMap map = pptvService.selectVideoPPTVMapByInfoId(infoId); |
| | | if (map == null) { |
| | | return JsonUtilV2.loadFalseJson("影片不存在"); |
| | | } |
| | | PPTVSeries pptvSeries = pptvService.selectSeriesByInfoId(infoId); |
| | | if (pptvSeries == 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.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()); |
| | | } |
| | | |
| | | 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)); |
| | | } |
| | | |
| | | /** |
| | |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.domain.vip.*; |
| | | import com.yeshi.buwan.dto.order.PPTVVideoPrice; |
| | | import com.yeshi.buwan.exception.goldcorn.GoldCornException; |
| | | import com.yeshi.buwan.exception.order.OrderException; |
| | | import com.yeshi.buwan.exception.order.PayException; |
| | |
| | | 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; |
| | | import java.util.*; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/v2/videoinfo") |
| | |
| | | |
| | | @Resource |
| | | private GoldCornManager goldCornManager; |
| | | |
| | | @Resource |
| | | private SystemConfigService systemConfigService; |
| | | |
| | | private String getDurationDesc(int duration) { |
| | | int h = duration / (60 * 60); |
| | |
| | | return JsonUtilV2.loadFalseJson("当前影片不能购买"); |
| | | } |
| | | |
| | | Set<String> typeSets = new HashSet<>(); |
| | | |
| | | try { |
| | | String[] sts = series.getProgramcategory().split(","); |
| | | for (String st : sts) { |
| | | typeSets.add(st.split("-")[0]); |
| | | } |
| | | typeSets.remove("好莱坞"); |
| | | typeSets.remove("院线"); |
| | | } catch (Exception e) { |
| | | } |
| | | |
| | | PPTVSimpleVideoInfo videoInfo = new PPTVSimpleVideoInfo(); |
| | | videoInfo.setInfoId(series.getInfoID()); |
| | | videoInfo.setName(series.getName()); |
| | | videoInfo.setPicture(series.getCover()); |
| | | videoInfo.setCategory(series.getProgramcategory().replace("-电视剧", "").replace("-电影", "").replace("-动漫", "").replace("-少儿", "")); |
| | | videoInfo.setCategory(com.yeshi.buwan.util.StringUtil.join(typeSets, " ")); |
| | | videoInfo.setActors(series.getActor()); |
| | | videoInfo.setDirectors(series.getDirector()); |
| | | if (series.getSeries() != null && series.getSeries().size() > 0 && !StringUtil.isNullOrEmpty(series.getSeries().get(0).getDuration())) |
| | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("video", gson.toJson(videoInfo)); |
| | | |
| | | PPTVVideoPrice price = new Gson().fromJson(systemConfigService.getConfigValueByKeyCache("videoPrice"), PPTVVideoPrice.class); |
| | | |
| | | //加载价格信息 |
| | | JSONObject priceInfo=new JSONObject(); |
| | | priceInfo.put("discount","6折"); |
| | | priceInfo.put("actualPrice","3.9"); |
| | | priceInfo.put("discount", price.getTag()); |
| | | priceInfo.put("actualPrice",price.getActualPrice()); |
| | | data.put("price", priceInfo); |
| | | |
| | | if (!StringUtil.isNullOrEmpty(loginUid)) { |
New file |
| | |
| | | package com.yeshi.buwan.dto.order; |
| | | |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * PPTV单片价格 |
| | | */ |
| | | public class PPTVVideoPrice { |
| | | //原价 |
| | | private BigDecimal price; |
| | | //真实价格 |
| | | private BigDecimal actualPrice; |
| | | //标签 |
| | | private String tag; |
| | | |
| | | public PPTVVideoPrice(BigDecimal price, BigDecimal actualPrice, String tag) { |
| | | this.price = price; |
| | | this.actualPrice = actualPrice; |
| | | this.tag = tag; |
| | | } |
| | | |
| | | public BigDecimal getPrice() { |
| | | return price; |
| | | } |
| | | |
| | | public void setPrice(BigDecimal price) { |
| | | this.price = price; |
| | | } |
| | | |
| | | public BigDecimal getActualPrice() { |
| | | return actualPrice; |
| | | } |
| | | |
| | | public void setActualPrice(BigDecimal actualPrice) { |
| | | this.actualPrice = actualPrice; |
| | | } |
| | | |
| | | public String getTag() { |
| | | return tag; |
| | | } |
| | | |
| | | public void setTag(String tag) { |
| | | this.tag = tag; |
| | | } |
| | | } |
| | |
| | | package com.yeshi.buwan.dto.order; |
| | | |
| | | public class PayWayInfoDTO { |
| | | //0-表示支付成功 |
| | | private int payWay; |
| | | private String payUrl; |
| | | |
| | |
| | | * @return |
| | | */ |
| | | public static boolean buyGoods(String openId, String orderNo, String goodsNo, Date orderTime) { |
| | | if (1 > 0) { |
| | | return false; |
| | | } |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("openId", openId); |
| | | params.put("canal", CHANNEL_ID); |
| | |
| | | return pptvSeriesDao.findOne(query); |
| | | } |
| | | |
| | | @Override |
| | | public PPTVSeries selectSeriesByInfoId(String infoId) { |
| | | return pptvSeriesDao.get(infoId); |
| | | } |
| | | |
| | | /** |
| | | * 删除剧集 |
| | | * |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public OrderRecord createOrder(OrderRecord record) throws OrderException { |
| | | if (record.getMoney() == null || record.getType() == null || record.getOrderType() == null || record.getUid() == null) { |
| | | if (record.getMoney() == null || (record.getType() == null && record.getVideoInfoId() == null) || record.getOrderType() == null || record.getUid() == null) { |
| | | throw new OrderException(1, "参数不完整"); |
| | | } |
| | | |
| | |
| | | if (record.getCreateTime() == null) { |
| | | record.setCreateTime(new Date()); |
| | | } |
| | | |
| | | if (record.getPayWay() == OrderRecord.PAY_WAY_WX) { |
| | | if (record.getGoldCorn() != null && record.getGoldCorn() > 0) { |
| | | if (record.getMoney().compareTo(new BigDecimal("0")) == 0) { |
| | | record.setPayWay(OrderRecord.PAY_WAY_GOLDCORN); |
| | | } else { |
| | | record.setPayWay(OrderRecord.PAY_WAY_WX_GOLDCORN); |
| | | } |
| | | } |
| | | } else if (record.getPayWay() == OrderRecord.PAY_WAY_ALIPAY) { |
| | | if (record.getGoldCorn() != null && record.getGoldCorn() > 0) { |
| | | if (record.getMoney().compareTo(new BigDecimal("0")) == 0) { |
| | | record.setPayWay(OrderRecord.PAY_WAY_GOLDCORN); |
| | | } else { |
| | | record.setPayWay(OrderRecord.PAY_WAY_ALIPAY_GOLDCORN); |
| | | } |
| | | } |
| | | } |
| | | |
| | | |
| | | record.setMoneyPay(false); |
| | | record.setGoldCornPay(false); |
| | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | // @GlobalTransactional(timeoutMills = 30000, name = "buwan-order", rollbackFor = Exception.class) |
| | | @Override |
| | | public PayWayInfoDTO payOrder(OrderRecord record) throws OrderException, GoldCornException, PayException { |
| | | //TODO 影视豆支付 |
| | | public PayWayInfoDTO payOrder(OrderRecord record) throws OrderException, GoldCornException, PayException, VIPException, PPTVException { |
| | | String orderNo = VIPOrderUtil.getOutOrderNo(record.getOrderType(), record.getId()); |
| | | switch (record.getPayWay()) { |
| | | case OrderRecord |
| | |
| | | } catch (Exception e) { |
| | | throw new GoldCornException(1, "影视豆扣除出错"); |
| | | } |
| | | paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); |
| | | |
| | | orderLogger.info("订单影视豆支付成功:id-{}", record.getId()); |
| | | case OrderRecord |
| | | .PAY_WAY_ALIPAY: { |
| | | if (record.getMoney() != null && record.getMoney().compareTo(new BigDecimal(0)) == 0) { |
| | | return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId())); |
| | | } |
| | | //生成支付宝支付订单 |
| | | String form = VipUtil.getVipChargeAlipayForm(record.getId(), orderNo, record.getMoney()); |
| | | String form = VipUtil.getVipChargeAlipayForm(record.getId(), record.getOrderType(), orderNo, record.getMoney()); |
| | | //暂存2分钟 |
| | | String id = StringUtil.Md5(UUID.randomUUID().toString() + "#" + System.currentTimeMillis()); |
| | | redisManager.cacheCommonString(id, form, 120); |
| | |
| | | .PAY_WAY_WX_GOLDCORN: |
| | | try { |
| | | goldCornManager.consumeGoldCorn(record, record.getGoldCorn()); |
| | | |
| | | } catch (Exception e) { |
| | | throw new GoldCornException(1, "影视豆扣除出错"); |
| | | } |
| | | paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); |
| | | orderLogger.info("订单影视豆支付成功:id-{} 类型-{}", record.getId(), record.getOrderType().name()); |
| | | case OrderRecord |
| | | .PAY_WAY_WX: { |
| | | if (record.getMoney() != null && record.getMoney().compareTo(new BigDecimal(0)) == 0) { |
| | | return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId())); |
| | | } |
| | | //生成微信支付订单 |
| | | try { |
| | | String title = ""; |
| | |
| | | case OrderRecord.PAY_WAY_GOLDCORN: { |
| | | try { |
| | | goldCornManager.consumeGoldCorn(record, record.getGoldCorn()); |
| | | orderLogger.info("订单影视豆支付成功:id-{}", record.getId()); |
| | | } catch (Exception e) { |
| | | throw new GoldCornException(1, "影视豆扣除出错"); |
| | | } |
| | | orderLogger.info("订单影视豆支付成功:id-{}", record.getId()); |
| | | paySuccess(record.getId(), OrderRecord.PAY_WAY_GOLDCORN, null, new Date()); |
| | | return new PayWayInfoDTO(0, VipUtil.getPaySuccessUrl(record.getId())); |
| | | } |
| | | break; |
| | | } |
| | | throw new OrderException(1, "支付方式不存在"); |
| | | } |
| | |
| | | //修改记录 |
| | | Query query = session.createSQLQuery("select * from wk_vip_order_record r where r.id=? for update").addEntity(OrderRecord.class).setCacheable(false).setParameter(0, id); |
| | | List<OrderRecord> list = query.list(); |
| | | if (list == null || list.size() == 0) |
| | | throw new VIPException(10, "订单不存在"); |
| | | |
| | | if (list != null && list.size() > 0) { |
| | | OrderRecord record = list.get(0); |
| | | if (record.getState() != OrderRecord.STATE_NOT_PAY) |
| | | throw new VIPException(1, "订单未处于待支付状态"); |
| | | |
| | | |
| | | if (record.getPayWay() != OrderRecord.PAY_WAY_GOLDCORN) { |
| | | if (payWay != OrderRecord.PAY_WAY_GOLDCORN) { |
| | | record.setPayMoney(payMoney); |
| | | record.setMoneyPay(true); |
| | | } else { |
| | |
| | | //已经支付成功 |
| | | if (record.getState() == OrderRecord.STATE_PAY) { |
| | | session.createSQLQuery("insert into wk_vip_order_pay_success(id,create_time) value(?,now())").setParameter(0, id).executeUpdate(); |
| | | |
| | | } |
| | | |
| | | if (record.getOrderType() == OrderType.vip) { |
| | |
| | | } |
| | | |
| | | return record; |
| | | } else { |
| | | throw new VIPException(10, "订单不存在"); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | public PPTVSeries selectSeriesBySeriesCode(String cid); |
| | | |
| | | |
| | | public PPTVSeries selectSeriesByInfoId(String infoId); |
| | | |
| | | } |
| | |
| | | * |
| | | * @param record |
| | | */ |
| | | public PayWayInfoDTO payOrder(OrderRecord record) throws OrderException, GoldCornException, PayException; |
| | | public PayWayInfoDTO payOrder(OrderRecord record) throws OrderException, GoldCornException, PayException, VIPException, PPTVException; |
| | | |
| | | |
| | | /** |
| | |
| | | @Reference(version = "1.0", check = false) |
| | | private GoldCornBalanceService goldCornBalanceService; |
| | | |
| | | public void init(String uid) throws Exception { |
| | | goldCornBalanceService.init(getAppCode(), getUid(uid)); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 获取金币系统的用户ID |
| | |
| | | public long getBalance(String uid) { |
| | | try { |
| | | Long count = goldCornBalanceService.getBalance(getAppCode(), getUid(uid)); |
| | | if (count == null) { |
| | | init(uid); |
| | | } |
| | | return count==null?0:count; |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.text.DateFormat; |
| | | import java.util.Collection; |
| | | import java.util.Date; |
| | | import java.util.Iterator; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | |
| | | return st; |
| | | } |
| | | |
| | | |
| | | public static String join(Collection srcList, String seperate) { |
| | | String st = ""; |
| | | for (Iterator<String> its = srcList.iterator(); its.hasNext(); ) { |
| | | st += its.next() + seperate; |
| | | } |
| | | if (st.endsWith(seperate)) { |
| | | st = st.substring(0, st.length() - seperate.length()); |
| | | } |
| | | return st; |
| | | } |
| | | |
| | | /** |
| | | * 随机码生成 |
| | | * |
| | |
| | | package com.yeshi.buwan.util.user; |
| | | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.yeshi.buwan.domain.vip.OrderType; |
| | | import com.yeshi.buwan.util.Constant; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.yeshi.utils.alipay.AlipayH5PayUtil; |
| | |
| | | * @param money |
| | | * @return |
| | | */ |
| | | public static String getVipChargeAlipayForm(String id, String orderNo, BigDecimal money) { |
| | | public static String getVipChargeAlipayForm(String id, OrderType orderType, String orderNo, BigDecimal money) { |
| | | try { |
| | | String goodsTitle = "影视大全会员充值"; |
| | | String returnUrl = "http://vip.ysdq.yeshitv.com/pay_success.html?id=" + id; |
| | | if (orderType == OrderType.video) { |
| | | goodsTitle = "影视大全单片购买"; |
| | | } |
| | | String returnUrl = getPaySuccessUrl(id); |
| | | String notifyUrl = Constant.HOST+ "/BuWan/alipay/pay"; |
| | | AlipayAppInfo appInfo = getAlipayApp(); |
| | | String form = AlipayH5PayUtil.createOrderForm(appInfo, orderNo, money, goodsTitle, returnUrl, notifyUrl); |
| | |
| | | } |
| | | |
| | | |
| | | public static String getPaySuccessUrl(String id) { |
| | | return "http://vip.ysdq.yeshitv.com/pay_success.html?id=" + id; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 微信下单 |
| | | * |
| | |
| | | <property name="videoInfoId" column="video_info_id" type="string"></property> |
| | | <property name="moneyPay" column="money_pay" type="boolean"></property> |
| | | <property name="goldCornPay" column="gold_corn_pay" type="boolean"></property> |
| | | <property name="remarks" column="remarks" type="string"></property> |
| | | |
| | | |
| | | </class> |
| | |
| | | import com.yeshi.buwan.domain.jump.JumpTypeEnum; |
| | | import com.yeshi.buwan.domain.system.DetailSystemConfig; |
| | | import com.yeshi.buwan.domain.system.SystemConfig; |
| | | import com.yeshi.buwan.dto.order.PPTVVideoPrice; |
| | | import com.yeshi.buwan.job.AdJob; |
| | | import com.yeshi.buwan.service.imp.DetailSystemConfigService; |
| | | import com.yeshi.buwan.service.inter.system.SystemConfigService; |
| | |
| | | |
| | | systemConfig = new SystemConfig(); |
| | | systemConfig.setBeizhu(""); |
| | | systemConfig.setKey("thirdUidPrefix"); |
| | | systemConfig.setName("第三方用户ID的前缀"); |
| | | systemConfig.setKey("videoPrice"); |
| | | systemConfig.setName("单片价格"); |
| | | try { |
| | | systemConfig.setValue("buwan-"); |
| | | systemConfig.setValue(new Gson().toJson(new PPTVVideoPrice(new BigDecimal("5"), new BigDecimal(3), "6折"))); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |