public Respbase <MessageDto> PayVDian(ReqPayVDian req) { FriFacade facade = new FriFacade(); MessageDto result = facade.PayVDian(req); return(new Respbase <MessageDto> { Result = facade.PromptInfo.Result, Message = facade.PromptInfo.Message, Data = result }); }
/// <summary> /// 支付V点(查看文章) /// </summary> /// <param name="req"></param> /// <returns></returns> public MessageDto PayVDian(ReqPayVDian req) { #region 数据验证 TnetReginfo regInfo = PxinCache.GetRegInfo(req.Nodeid); if (regInfo == null) { Alert("用户不存在"); return(null); } //检查支付密码 //if (!CheckPayPwd(regInfo, req.Pwd, false)) //{ // Alert("支付密码错误"); // return false; //} TpxinMessage tpxinMessage = db.TpxinMessageSet.FirstOrDefault(a => a.Infoid == req.InfoID && a.Status == 1); if (tpxinMessage == null) { Alert("文章不存在"); return(null); } if (tpxinMessage.Price == 0) { Alert("该文章不需要收费"); return(null); } if (tpxinMessage.Nodeid == regInfo.Nodeid) { Alert("不能给自己的文章付费"); return(null); } //TpxinUserinfo tpxinUserinfo = db.TpxinUserinfoSet.FirstOrDefault(a => a.Nodeid == regInfo.Nodeid); var vp = new VPHelper(); var vpDian = vp.GetTpxinUserinfo(regInfo.Nodeid); if (vpDian.VDianBalance < tpxinMessage.Price) { Alert("V点余额不足,请先充值"); return(null); } TpxinPayhis pay = db.TpxinPayhisSet.FirstOrDefault(a => a.Infoid == tpxinMessage.Infoid && a.Nodeid == regInfo.Nodeid && a.Typeid == 3); if (pay != null) { Alert("您已支付查看文章费用"); return(null); } #endregion try { db.BeginTransaction(); //添加查看用户v点支付历史 TpxinPayhis payhis = new TpxinPayhis() { Createtime = DateTime.Now, Infoid = tpxinMessage.Infoid, Typeid = 3, Nodeid = regInfo.Nodeid, Tonodeid = tpxinMessage.Nodeid, Price = tpxinMessage.Price, Remarks = "查看文章" }; db.TpxinPayhisSet.Add(payhis); //减去查看用户v点数量 //TpxinUserinfo userinfo = db.TpxinUserinfoSet.FirstOrDefault(a => a.Nodeid == regInfo.Nodeid); //if (userinfo.V <= 0) //{ // Alert("支付失败,V点不足"); // return null; //} //userinfo.V -= tpxinMessage.Price; //var transferId = Guid.NewGuid().ToString(); //增加发布用户v点数量 //TpxinUserinfo userinfo1 = db.TpxinUserinfoSet.FirstOrDefault(a => a.Nodeid == tpxinMessage.Nodeid); //userinfo1.V += tpxinMessage.Price; var tpxinMsgUser = PxinCache.GetRegInfo(tpxinMessage.Nodeid); var nodeName = tpxinMsgUser == null ? "" : tpxinMsgUser.Nodename; //添加金额变化记录 //var reduce = CreateAmountChangeHis(regInfo.Nodeid, 1, -tpxinMessage.Price, (int)AmountChangeReason.ViewArticle, transferId, $"查看付费-{nodeName}"); //db.TpxinAmountChangeHisSet.Add(reduce); //var add = CreateAmountChangeHis(tpxinMessage.Nodeid, 1, tpxinMessage.Price, (int)AmountChangeReason.ViewArticle, transferId, $"查看收款-{regInfo.Nodename}"); //db.TpxinAmountChangeHisSet.Add(add); if (db.SaveChanges() <= 0) { Alert("支付失败:" + db.Message); log.Error("查看文章,支付失败,db:" + db.Message); db.Rollback(); return(null); } //VP服务设置V点 var result = vp.SetV(new VPPayVDian { FromNodeid = regInfo.Nodeid, FromRemark = $"查看付费-{Helper.FilterChar(nodeName)}", ToNodeid = tpxinMessage.Nodeid, ToRemark = $"查看收款-{Helper.FilterChar(regInfo.Nodename)}", Amount = tpxinMessage.Price, Reason = (int)AmountChangeReason.ViewArticle, Transferid = payhis.Hisid.ToString(), }); if (result.Result <= 0) { Alert(result.Message, result.Result); db.Rollback(); return(null); } db.Commit(); } catch (Exception ex) { log.Info("查看文章,支付失败。原因:" + ex); Alert("支付失败"); db.Rollback(); return(null); } var query = from msg in db.VpxinMessageSet where msg.Infoid == req.InfoID select new MessageDto { Commentnum = msg.Commentnum, Nodeid = msg.Msgnodeid, Localnodeid = msg.Localnodeid, Content = msg.Content, Createtime = msg.Createtime, Down = msg.Down, Infoid = msg.Infoid, Ispay = msg.Ispay, Picurl = msg.Picurl, Price = msg.Price, Reward = msg.Reward, Sound = msg.Sound, Up = msg.Up, Video = msg.Video, IsDown = msg.IsDown, IsUp = msg.IsUp }; MessageDto msgModel = query.FirstOrDefault(); Alert("支付成功", 1); return(msgModel); }