Ejemplo n.º 1
0
        /// <summary>
        /// 支付v点
        /// </summary>
        /// <param name="nodeid"></param>
        /// <param name="amonut"></param>
        /// <param name="reason"></param>
        /// <param name="remarks"></param>
        /// <returns></returns>
        private bool Transfer_PayV(int nodeid, decimal amonut, int reason, string remarks)
        {
            var vp     = new VPHelper();
            var result = vp.SetV(new VPChargeVDian
            {
                Amount     = -amonut,
                Nodeid     = nodeid,
                Reason     = reason,
                Remark     = remarks,
                Transferid = Guid.NewGuid().ToString()
            });

            return(result.Result > 0 ? true : false);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 发布信友圈信息
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public bool CreateMsg(ReqPxinMessage req)
        {
            TnetReginfo  regInfo      = PxinCache.GetRegInfo(req.Nodeid);
            TpxinMessage tpxinMessage = new TpxinMessage
            {
                Infoid     = db.GetPrimaryKeyValue <TpxinMessage>(),
                Nodeid     = req.Nodeid,
                Price      = req.Price,
                Content    = req.Content,
                Picurl     = req.Picurl,
                Sound      = req.Sound,
                Video      = req.Video,
                Createtime = DateTime.Now,
                Remarks    = "",
                Status     = 1,
                Up         = 0,
                Down       = 0,
                Commentnum = 0
            };

            try
            {
                db.BeginTransaction();
                //添加信友圈信息
                db.TpxinMessageSet.Add(tpxinMessage);

                //发布信息扣一个v点
                //1.添加v点历史
                db.TpxinPayhisSet.Add(new TpxinPayhis
                {
                    Nodeid     = req.Nodeid,
                    Tonodeid   = 0,
                    Createtime = DateTime.Now,
                    Infoid     = tpxinMessage.Infoid,
                    Price      = -1,
                    Remarks    = "发布文章",
                    Typeid     = 2
                });
                //2.扣掉信友圈信息表的V点数量
                //TpxinUserinfo userinfo = db.TpxinUserinfoSet.FirstOrDefault(a => a.Nodeid == req.Nodeid);
                //userinfo.V -= 1;
                //if (userinfo.V < 0)
                //{
                //    Alert("发布信友圈失败,V点不足", -100);
                //    return false;
                //}
                ////添加金额变化记录
                //var amountChangeHis = CreateAmountChangeHis(req.Nodeid, 1, -1, (int)AmountChangeReason.PublishArticle, Guid.NewGuid().ToString(), "发布文章");
                //db.TpxinAmountChangeHisSet.Add(amountChangeHis);

                #region 由VP服务来处理V点P点操作
                if (db.SaveChanges() <= 0)
                {
                    Alert("发布信友圈失败");
                    log.Error("发布信友圈失败,提交db失败:" + db.Message);
                    db.Rollback();
                    return(false);
                }
                var vp     = new VPHelper();
                var result = vp.SetV(new VPChargeVDian
                {
                    Nodeid     = req.Nodeid,
                    Amount     = -1,
                    Reason     = (int)AmountChangeReason.PublishArticle,
                    Remark     = "发布文章",
                    Transferid = tpxinMessage.Infoid.ToString(),
                });
                if (result.Result <= 0)
                {
                    Alert(result.Message, result.Result);
                    db.Rollback();
                    return(false);
                }
                db.Commit();
                #endregion
            }
            catch (Exception ex)
            {
                log.Error("发布信友圈失败,原因" + ex);
                Alert("发布信友圈失败");
                db.Rollback();
                return(false);
            }
            Alert("发布信友圈成功", 1);
            PxinSerivce.EnqueueMsg(tpxinMessage.Infoid);
            return(true);
        }
Ejemplo n.º 3
0
        /// <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);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 支付V点流程
        /// </summary>
        /// <param name="regInfo"></param>
        /// <param name="Price"></param>
        /// <returns></returns>
        public bool ChargeVDian_Pro(TnetReginfo regInfo, decimal Price)
        {
            TpxinUserinfo userinfo = db.TpxinUserinfoSet.FirstOrDefault(a => a.Nodeid == regInfo.Nodeid);

            if (userinfo == null)
            {
                userinfo = new TpxinUserinfo
                {
                    Nodeid     = regInfo.Nodeid,
                    Backpic    = "",
                    Createtime = DateTime.Now,
                    Up         = 0,
                    Down       = 0,
                    P          = 0,
                    V          = 0,
                    Remarks    = ""
                };
                db.TpxinUserinfoSet.Add(userinfo);
            }
            //1.添加 信友圈付费V点历史表 TPXIN_PAYHIS
            TpxinPayhis payhis = new TpxinPayhis
            {
                Createtime = DateTime.Now,
                Infoid     = 0,
                Typeid     = 1,
                Nodeid     = regInfo.Nodeid,
                Tonodeid   = 0,
                Price      = Price,
                Remarks    = "充值V点"
            };

            //2.修改用户信息表的v点
            db.TpxinPayhisSet.Add(payhis);
            //userinfo.V += Price;
            //3.添加金额变化记录
            //var amountChangeHis = CreateAmountChangeHis(regInfo.Nodeid, 1, Price, (int)AmountChangeReason.ChargeVDian, Guid.NewGuid().ToString(), "充值V点");
            //db.TpxinAmountChangeHisSet.Add(amountChangeHis);
            if (db.SaveChanges() <= 0)
            {
                Alert("充值V点失败");
                return(false);
            }
            //由VP服务处理V点
            var vp     = new VPHelper();
            var result = vp.SetV(new VPChargeVDian
            {
                Amount     = Price,
                Nodeid     = regInfo.Nodeid,
                Reason     = (int)AmountChangeReason.ChargeVDian,
                Remark     = "充值V点",
                Transferid = payhis.Hisid.ToString(),
            });

            if (result.Result <= 0)
            {
                Alert("充值V点失败");
                log.Error("充值V点失败:" + result.Message);
                return(false);
            }
            _businessID = payhis.Hisid;
            return(true);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// 打赏
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public bool CreateReward(ReqCreateReward req)
        {
            if (req.Reward > 100)
            {
                Alert("打赏金额不能超过100V");
                return(false);
            }
            TnetReginfo  regInfo      = PxinCache.GetRegInfo(req.Nodeid);
            TpxinMessage tpxinMessage = db.TpxinMessageSet.FirstOrDefault(a => a.Infoid == req.Infoid && a.Status == 1);

            if (tpxinMessage == null)
            {
                Alert("信友圈信息不存在");
                return(false);
            }
            if (regInfo.Nodeid == tpxinMessage.Nodeid)
            {
                Alert("不能自己给自己打赏");
                return(false);
            }
            if (tpxinMessage.Price > 0)
            {
                TpxinPayhis tpxinPayhis = db.TpxinPayhisSet.FirstOrDefault(a => a.Infoid == tpxinMessage.Infoid && a.Nodeid == req.Nodeid && a.Typeid == 3);
                if (tpxinPayhis == null)
                {
                    Alert("请支付V点查看后点赞或踩");
                    return(false);
                }
            }
            TpxinPraise tpxinPraise = db.TpxinPraiseSet.FirstOrDefault(a => a.Infoid == req.Infoid && a.Fromnodeid == req.Nodeid);

            if (tpxinPraise != null && tpxinPraise.Reward > 0)
            {
                Alert("一个文章只能打赏一次");
                return(false);
            }
            #region 由VP服务设置V点
            try
            {
                db.BeginTransaction();
                if (tpxinPraise == null)
                {
                    //添加打赏用户踩赞历史表
                    tpxinPraise = new TpxinPraise
                    {
                        Infoid     = req.Infoid,
                        Createtime = DateTime.Now,
                        Fromnodeid = req.Nodeid,
                        Tonodeid   = tpxinMessage.Nodeid,
                        Remarks    = "",
                        Reward     = req.Reward,
                        Status     = 0
                    };
                    db.TpxinPraiseSet.Add(tpxinPraise);
                }
                else
                {
                    tpxinPraise.Reward = req.Reward;
                }

                var tpxinMsgUser = PxinCache.GetRegInfo(tpxinMessage.Nodeid);
                if (db.SaveChanges() <= 0)
                {
                    Alert("打赏失败");
                    log.Error("打赏失败,提交db失败:" + db.Message);
                    db.Rollback();
                    return(false);
                }
                var vp     = new VPHelper();
                var result = vp.SetV(new VPPayVDian
                {
                    FromNodeid = req.Nodeid,
                    FromRemark = $"打赏-{Helper.FilterChar(tpxinMsgUser.Nodename)}",
                    ToNodeid   = tpxinMessage.Nodeid,
                    ToRemark   = $"赏金-{Helper.FilterChar(regInfo.Nodename)}",
                    Amount     = req.Reward,
                    Reason     = (int)AmountChangeReason.Reward,
                    Transferid = tpxinPraise.Hisid.ToString(),
                });
                if (result.Result <= 0)
                {
                    Alert(result.Message, result.Result);
                    db.Rollback();
                    return(false);
                }
                db.Commit();
            }
            catch (Exception ex)
            {
                Alert("打赏失败");
                log.Error("打赏失败,异常:" + ex);
                db.Rollback();
                return(false);
            }
            #endregion
            Alert("打赏成功", 1);
            return(true);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// V点扣除
        /// </summary>
        /// <param name="nodecode">用户账号</param>
        /// <param name="amount">金额</param>
        /// <param name="subject">商品名</param>
        /// <returns></returns>
        private bool Transfer_VD(string nodecode, decimal amount, string subject)
        {
            if (!CheckSign())
            {
                return(false);
            }

            //TssoOpenUser openUser = db.TssoOpenUserSet.Where(d => d.Openid == nodecode && d.Opentype == 4).FirstOrDefault();
            //if (openUser == null)
            //{
            //    Alert("没有绑定PCN账号");
            //    return false;
            //}
            TnetReginfo reginfo = db.TnetReginfoSet.FirstOrDefault(c => c.Nodecode == nodecode || c.Mobileno == nodecode);

            if (reginfo == null)
            {
                Alert("用户账号不存在");
                return(false);
            }
            var user = db.TpxinUserinfoSet.Where(c => c.Nodeid == reginfo.Nodeid).FirstOrDefault();

            if (user == null)
            {
                Alert("用户不存在");
                return(false);
            }

            //if (user.V < amount * 10)
            //{
            //    Alert("余额不足");
            //    return false;
            //}

            //比例1:10
            //decimal before = user.V;
            //user.V -= amount * 10;
            ////添加金额变化记录
            //var amountChangeHis = new TpxinAmountChangeHis()
            //{
            //    Nodeid = user.Nodeid,
            //    Typeid = 1,
            //    Amount = -amount * 10,
            //    Reason = 9,
            //    Transferid = Guid.NewGuid().ToString(),
            //    Createtime = DateTime.Now,
            //    Remarks = subject,
            //    Amountbefore = before,
            //    Amountafter = user.V
            //};
            //db.TpxinAmountChangeHisSet.Add(amountChangeHis);
            //if (db.SaveChanges() <= 0)
            //{
            //    Alert("V点失败");
            //    return false;
            //}

            //TransferId = amountChangeHis.Hisid;
            #region 调用VP接口扣除V点
            var id  = db.GetPrimaryKeyValue <TpxinAmountChangeHis>();
            var req = new VPChargeVDian()
            {
                Amount     = -amount * 10,
                Nodeid     = user.Nodeid,
                Reason     = 9,
                Remark     = subject,
                Transferid = id.ToString(),
            };
            var vp     = new VPHelper();
            var result = vp.SetV(req);
            if (result.Result <= 0)
            {
                Alert(result.Message);
                log.Error($"Transfer_VD扣减V点失败,Nodeid:{user.Nodeid};原因:{result.Message}");
                return(false);
            }
            TransferId = id;
            #endregion
            return(true);
        }