Ejemplo n.º 1
0
        /// <summary>
        /// 调用Vp接口
        /// </summary>
        /// <param name="nodeid"></param>
        /// <param name="amount"></param>
        /// <param name="remark"></param>
        /// <param name="transferid"></param>
        /// <returns></returns>
        private VPRespbase AuctionVP(int nodeid, decimal amount, string remark, string transferid)
        {
            var vp     = new VPHelper();
            var result = vp.SetP(new VPAuction
            {
                Nodeid     = nodeid,
                Amount     = -amount,
                Reason     = 2000,
                Remark     = remark,
                Transferid = transferid,
            });

            return(result);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 点赞或踩
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public bool CreateAttitude(ReqCreateAttitude req)
        {
            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 (req.Isupdown != -1 && req.Isupdown != 1)
            {
                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.Status != 0)
            {
                Alert("一个文章只能点赞或踩一次");
                return(false);
            }
            try
            {
                db.BeginTransaction();
                if (tpxinPraise == null)
                {
                    //添加信友圈踩赞历史表
                    tpxinPraise = new TpxinPraise
                    {
                        Infoid     = req.Infoid,
                        Createtime = DateTime.Now,
                        Fromnodeid = req.Nodeid,
                        Tonodeid   = tpxinMessage.Nodeid,
                        Remarks    = "",
                        Reward     = 0,
                        Status     = req.Isupdown
                    };
                    db.TpxinPraiseSet.Add(tpxinPraise);
                }
                else
                {
                    tpxinPraise.Status = req.Isupdown;
                }
                //查询法比用户信息
                TpxinUserinfo userinfo = db.TpxinUserinfoSet.FirstOrDefault(a => a.Nodeid == tpxinMessage.Nodeid);
                if (userinfo == null)
                {
                    Alert("用户不存在");
                    db.Rollback();
                    return(false);
                }
                if (req.Isupdown == 1)
                {
                    //添加文章表的赞的次数
                    tpxinMessage.Up += 1;
                    //增加一个用户p点
                    userinfo.Up += 1;
                }
                else
                {
                    //添加文章表的踩的次数
                    tpxinMessage.Down += 1;
                    //减去一个用户p点
                    userinfo.Down += 1;
                }
                ////添加金额变化记录
                //var amount = req.Isupdown == 1 ? 1 : -1;
                //var reason = req.Isupdown == 1 ? AmountChangeReason.PraiseArticle : AmountChangeReason.TreadArticle;
                ////var tpxinMsgUser = PxinCache.GetRegInfo(userinfo.Nodeid);//db.TchatUserSet.First(c => c.Nodeid == userinfo.Nodeid);//

                //var remarks = (req.Isupdown == 1 ? "赞-" : "踩-") + regInfo.Nodename;
                //var amountChangeHis = CreateAmountChangeHis(tpxinMessage.Nodeid, 2, amount, (int)reason, Guid.NewGuid().ToString(), remarks);
                //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.SetP(new VPAuction
                {
                    Nodeid     = tpxinMessage.Nodeid,
                    Reason     = (int)(req.Isupdown == 1 ? AmountChangeReason.PraiseArticle : AmountChangeReason.TreadArticle),
                    Remark     = (req.Isupdown == 1 ? "赞-" : "踩-") + regInfo.Nodename,
                    Amount     = req.Isupdown == 1 ? 1 : -1,
                    Transferid = tpxinPraise.Hisid.ToString(),
                });
                if (result.Result <= 0)
                {
                    Alert(result.Message, result.Result);
                    db.Rollback();
                    return(false);
                }
                db.Commit();
                #endregion
            }
            catch (Exception ex)
            {
                log.Info("点赞或踩失败,原因:" + ex);
                Alert("操作失败");
                db.Rollback();
                return(false);
            }
            Alert("操作成功", 1);
            return(true);
        }