예제 #1
0
파일: BLLUserScore.cs 프로젝트: uvbs/mmp
        //给用户增加积分(负值为减积分),同时写入积分历史,返回修改的delta分值
        public double UpdateUserScore(UserScore userScore)
        {
            try
            {
                ZentCloud.ZCBLLEngine.BLLTransaction bllTransaction = new ZentCloud.ZCBLLEngine.BLLTransaction();

                //记录加减分历史
                if (userScore.Score != 0)
                {
                    if (SaveScoreRecord(userScore, bllTransaction) == 0)
                    {
                        bllTransaction.Rollback();
                        return(0);
                    }
                }

                userInfo.TotalScore += userScore.Score;
                if (userScore.Score > 0) //减分不计入累计积分
                {
                    userInfo.HistoryTotalScore += userScore.Score;
                }
                if (this.Update(userInfo, string.Format(" TotalScore={0},HistoryTotalScore={1}", userInfo.TotalScore, userInfo.HistoryTotalScore), string.Format(" AutoID={0}", userInfo.AutoID), bllTransaction) < 1) //更改用户积分
                {
                    bllTransaction.Rollback();
                    return(0);
                }

                bllTransaction.Commit();
                return(userScore.Score);
            }
            catch (Exception ex)
            {
                return(0);
            }
        }
예제 #2
0
        /// <summary>
        /// 冻结积分结算
        /// </summary>
        /// <param name="orderInfo"></param>
        /// <returns></returns>
        public bool SettlementOrderLockScore(WXMallOrderInfo orderInfo, out string msg)
        {
            BLLMall bllMall = new BLLMall();
            BLLWebsiteDomainInfo bllWebsiteDomain = new BLLWebsiteDomainInfo();
            BLLWeixin            bllWeixin        = new BLLWeixin();

            msg = "";
            var lockModel = GetLockScoreByOrder(orderInfo.OrderID);

            int addScore = (int)lockModel.Score;

            if (addScore > 0)
            {
                UserInfo orderUserInfo = bllUser.GetUserInfo(orderInfo.OrderUserID, orderInfo.WebsiteOwner);
                if (orderUserInfo == null)
                {
                    return(false);
                }
                WebsiteInfo websiteInfo = bllMall.Get <WebsiteInfo>(string.Format(" WebsiteOwner='{0}'", orderInfo.WebsiteOwner));

                ZentCloud.ZCBLLEngine.BLLTransaction tran = new ZentCloud.ZCBLLEngine.BLLTransaction();
                try
                {
                    UserScoreDetailsInfo scoreRecord = new UserScoreDetailsInfo();
                    scoreRecord.AddTime      = DateTime.Now;
                    scoreRecord.Score        = addScore;
                    scoreRecord.TotalScore   = orderUserInfo.TotalScore;
                    scoreRecord.ScoreType    = "OrderSuccess";
                    scoreRecord.UserID       = orderInfo.OrderUserID;
                    scoreRecord.AddNote      = "微商城-交易成功获得积分";
                    scoreRecord.WebSiteOwner = orderInfo.WebsiteOwner;
                    scoreRecord.RelationID   = orderInfo.OrderID;

                    if (!bllMall.Add(scoreRecord, tran))
                    {
                        tran.Rollback();
                        return(false);
                    }
                    if (bllUser.Update(orderUserInfo, string.Format(" TotalScore+={0},HistoryTotalScore+={0}", addScore), string.Format(" AutoID={0}", orderUserInfo.AutoID), tran) <= 0)
                    {
                        tran.Rollback();
                        return(false);
                    }

                    #region 宏巍加积分
                    if (websiteInfo.IsUnionHongware == 1)
                    {
                        Open.HongWareSDK.Client hongWareClient = new Open.HongWareSDK.Client(orderInfo.WebsiteOwner);
                        var hongWareMemberInfo = hongWareClient.GetMemberInfo(orderUserInfo.WXOpenId);
                        if (hongWareMemberInfo.member != null)
                        {
                            if (!hongWareClient.UpdateMemberScore(hongWareMemberInfo.member.mobile, orderUserInfo.WXOpenId, addScore))
                            {
                                tran.Rollback();
                                return(false);
                            }
                        }
                    }
                    #endregion

                    //积分解冻
                    if (!string.IsNullOrWhiteSpace(lockModel.Memo))
                    {
                        lockModel.Memo += ";交易成功获得积分解冻";
                    }
                    else
                    {
                        lockModel.Memo = "交易成功获得积分解冻";
                    }

                    if (Update(
                            new ScoreLockInfo(),
                            string.Format(" Memo+='{0}',LockStatus=1,UnLockTime=GETDATE() ", lockModel.Memo),
                            string.Format(" ForeignkeyId='{0}' AND LockType = 1 ", orderInfo.OrderID),
                            tran
                            ) > 0)
                    {
                        #region 微信通知
                        try
                        {
                            string url = string.Format("http://{0}/customize/shop/?v=1.0&ngroute=/myscores#/myscores", bllWebsiteDomain.GetWebsiteDoMain(orderInfo.WebsiteOwner));
                            bllWeixin.SendTemplateMessageNotifyCommTask(orderUserInfo.WXOpenId, "您有一笔积分已经到账", string.Format("积分:{0}分", (int)lockModel.Score), url, "", "", "", orderInfo.WebsiteOwner);
                        }
                        catch
                        {
                        }
                        #endregion
                    }
                    else
                    {
                        msg = string.Format("处理即将到账积分失败!订单号:{0}", orderInfo.OrderID);
                        tran.Rollback();
                        return(false);
                    }
                }
                catch (Exception ex)
                {
                    msg = ex.Message;
                    tran.Rollback();
                    return(false);
                }

                tran.Commit();
            }

            return(true);
        }