Ejemplo n.º 1
0
        public void ProcessRequest(HttpContext context)
        {
            int rows        = Convert.ToInt32(context.Request["rows"]);
            int page        = Convert.ToInt32(context.Request["page"]);
            int field_count = Convert.ToInt32(context.Request["field_count"]);

            if (field_count == 0)
            {
                apiResp.code   = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.status = false;
                apiResp.msg    = "请传入字段数";
                apiResp.result = new
                {
                    totalcount = 0,
                    list       = new List <string>()
                };
                bll.ContextResponse(context, apiResp);
                return;
            }
            rows = rows * field_count;
            string phone        = context.Request["phone"];
            string websiteOwner = bll.WebsiteOwner;
            string searchUserId = "";

            if (!string.IsNullOrWhiteSpace(phone))
            {
                UserInfo searchUser = bll.GetColByKey <UserInfo>("Phone", phone, "AutoID,UserID", websiteOwner: websiteOwner);
                searchUserId = searchUser == null ? "" : searchUser.UserID;
            }
            JArray resultList = new JArray();
            int    total      = bll.GetSetCount(websiteOwner, searchUserId);
            List <TeamPerformanceSet> userSetList = new List <TeamPerformanceSet>();

            if (total > 0)
            {
                userSetList = bll.GetSetList(rows, page, websiteOwner, searchUserId);
            }
            if (userSetList.Count > 0)
            {
                List <string>   userIdList = userSetList.Select(p => p.UserId).Distinct().ToList();
                string          userIds    = ZentCloud.Common.MyStringHelper.ListToStr(userIdList, "'", ",");
                List <UserInfo> userList   = bll.GetColMultListByKey <UserInfo>(int.MaxValue, 1, "UserID", userIds, "AutoID,UserID,TrueName,Phone");
                foreach (string userId in userIdList)
                {
                    UserInfo user = userList.FirstOrDefault(p => p.UserID == userId);

                    JObject jItem = new JObject();
                    jItem["user_id"] = userId;

                    if (userId == websiteOwner)
                    {
                        jItem["user_phone"]   = "";
                        jItem["user_name"]    = "系统";
                        jItem["is_sys"]       = 1;
                        jItem["user_auto_id"] = user.AutoID;
                    }
                    else
                    {
                        jItem["user_phone"]   = user == null ? "" : user.Phone;
                        jItem["user_name"]    = user == null ? "" : user.TrueName;
                        jItem["is_sys"]       = 0;
                        jItem["user_auto_id"] = 0;
                    }
                    foreach (TeamPerformanceSet item in userSetList.Where(p => p.UserId == userId))
                    {
                        jItem["p" + Convert.ToInt64(item.Performance)] = Convert.ToInt32(item.RewardRate) + "%";
                    }
                    resultList.Add(jItem);
                }
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.msg    = "管理奖设置列表";
            apiResp.result = new
            {
                totalcount = total / field_count,
                list       = resultList
            };
            bll.ContextResponse(context, apiResp);
        }
Ejemplo n.º 2
0
Archivo: Set.ashx.cs Proyecto: uvbs/mmp
        public void ProcessRequest(HttpContext context)
        {
            string   user_auto_id = context.Request["user_auto_id"];
            string   keys         = context.Request["keys"];
            string   keynames     = context.Request["keynames"];
            string   websiteOwner = bll.WebsiteOwner;
            UserInfo user         = bll.GetColByKey <UserInfo>("AutoID", user_auto_id, "AutoID,UserID", websiteOwner: websiteOwner);

            if (user == null)
            {
                apiResp.code   = (int)APIErrCode.OperateFail;
                apiResp.status = false;
                apiResp.msg    = "会员未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            List <string> keyList     = keys.Split(',').ToList();
            List <string> keyNameList = keynames.Split(',').ToList();
            Dictionary <decimal, decimal> dicPerformance = new Dictionary <decimal, decimal>();
            Dictionary <decimal, string>  dicName        = new Dictionary <decimal, string>();

            for (int i = 0; i < keyList.Count; i++)
            {
                string  keyString   = keyList[i];
                string  keyName     = keyNameList[i];
                string  valueString = context.Request[keyString];
                decimal key         = Convert.ToDecimal(keyString.Substring(1));
                decimal value       = Convert.ToDecimal(valueString);
                dicPerformance.Add(key, value);
                dicName.Add(key, keyName);
            }
            List <TeamPerformanceSet> userSetList = bll.GetSetList(int.MaxValue, 1, websiteOwner, user.UserID);
            BLLTransaction            tran        = new BLLTransaction();

            foreach (TeamPerformanceSet item in userSetList.Where(p => dicPerformance.ContainsKey(p.Performance)))
            {
                item.RewardRate = dicPerformance[item.Performance];
                if (!bll.Update(item, tran))
                {
                    tran.Rollback();
                    apiResp.code   = (int)APIErrCode.OperateFail;
                    apiResp.status = false;
                    apiResp.msg    = item.Name + "更新错误";
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            foreach (var item in dicPerformance.Where(p => !userSetList.Exists(pi => pi.Performance == p.Key)))
            {
                TeamPerformanceSet set = new TeamPerformanceSet();
                set.UserId       = user.UserID;
                set.WebsiteOwner = websiteOwner;
                set.Name         = dicName[item.Key];
                set.Performance  = item.Key;
                set.RewardRate   = item.Value;
                if (!bll.Add(set, tran))
                {
                    tran.Rollback();
                    apiResp.code   = (int)APIErrCode.OperateFail;
                    apiResp.status = false;
                    apiResp.msg    = set.Name + "新增错误";
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            tran.Commit();
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.msg    = "设置成功";
            bll.ContextResponse(context, apiResp);
        }
Ejemplo n.º 3
0
        public void ProcessRequest(HttpContext context)
        {
            BLLJIMP.Model.API.User.PayRegisterUser requestUser = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayRegisterUser>(new BLLJIMP.Model.API.User.PayRegisterUser());
            string websiteOwner = bll.WebsiteOwner;

            WebsiteInfo website = bllUser.GetWebsiteInfoModelFromDataBase(websiteOwner);

            if (string.IsNullOrWhiteSpace(requestUser.level.ToString()))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请选择会员级别";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入手机号码";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.spreadid))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入推荐人编号";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.PhoneNumLogicJudge(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "手机号码格式不正确";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.IsIDCard(requestUser.idcard))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "身份证号码必须如实填写";
                bll.ContextResponse(context, apiResp);
                return;
            }
            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUser.level.ToString());

            if (levelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (levelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止注册";
                bll.ContextResponse(context, apiResp);
                return;
            }
            UserInfo spreadUser = bllUser.GetSpreadUser(requestUser.spreadid, websiteOwner);

            if (spreadUser == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "推荐人未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.spreadid = spreadUser.UserID; //推荐人
            UserInfo regUser = bllUser.GetUserInfoByPhone(requestUser.phone, websiteOwner);

            if (regUser != null && regUser.MemberLevel >= 10)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该手机已注册会员";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (regUser != null && regUser.MemberLevel >= requestUser.level)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该会员有更高级别";
                bll.ContextResponse(context, apiResp);
                return;
            }
            string configV1CouponId = ZentCloud.Common.ConfigHelper.GetConfigString("YGBV1CouponId");
            string configV2CouponId = ZentCloud.Common.ConfigHelper.GetConfigString("YGBV2CouponId");
            string v1LevelNumber    = ZentCloud.Common.ConfigHelper.GetConfigString("V1LevelNumber");
            string v2LevelNumber    = ZentCloud.Common.ConfigHelper.GetConfigString("V2LevelNumber");

            string couponId = string.Empty;

            CardCoupons   cardModel    = null;
            MyCardCoupons myCardCoupon = null;

            if (requestUser.vType == "V1")
            {
                if (string.IsNullOrEmpty(configV1CouponId))
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "V1优惠券未配置";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                couponId     = configV1CouponId;
                cardModel    = bllCardCoupon.GetCardCoupon(Convert.ToInt32(couponId));
                myCardCoupon = bllCardCoupon.GetMyCardCouponMainId(Convert.ToInt32(couponId), regUser.UserID);
                if (cardModel == null || myCardCoupon == null)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不存在";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                if (requestUser.level.ToString() != v1LevelNumber)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不能用于此升级";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (requestUser.vType == "V2")
            {
                if (string.IsNullOrEmpty(configV2CouponId))
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "V2优惠券未配置";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                couponId     = configV2CouponId;
                cardModel    = bllCardCoupon.GetCardCoupon(Convert.ToInt32(couponId));
                myCardCoupon = bllCardCoupon.GetMyCardCouponMainId(Convert.ToInt32(couponId), regUser.UserID);
                if (cardModel == null || myCardCoupon == null)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不存在";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                if (requestUser.level.ToString() != v2LevelNumber)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不能用于此升级";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
            }


            if (regUser == null)
            {
                regUser               = new UserInfo();
                regUser.UserID        = string.Format("ZYUser{0}{1}", DateTime.Now.ToString("yyyyMMdd"), Guid.NewGuid().ToString("N").ToUpper());
                regUser.UserType      = 2;
                regUser.WebsiteOwner  = websiteOwner;
                regUser.Regtime       = DateTime.Now;
                regUser.LastLoginDate = DateTime.Parse("1970-01-01");
            }
            regUser.TrueName          = requestUser.truename;
            regUser.DistributionOwner = requestUser.spreadid;
            regUser.Phone             = requestUser.phone;
            regUser.MemberLevel       = requestUser.level;
            regUser.MemberApplyTime   = DateTime.Now;
            regUser.MemberStartTime   = DateTime.Now;
            regUser.MemberApplyStatus = 9;
            regUser.IdentityCard      = requestUser.idcard;
            regUser.Province          = requestUser.province;
            regUser.City         = requestUser.city;
            regUser.District     = requestUser.district;
            regUser.Town         = requestUser.town;
            regUser.ProvinceCode = requestUser.provinceCode;
            regUser.CityCode     = requestUser.cityCode;
            regUser.DistrictCode = requestUser.districtCode;
            regUser.TownCode     = requestUser.townCode;
            regUser.RegIP        = context.Request.UserHostAddress;//ip
            regUser.Password     = ZentCloud.Common.Rand.Number(6);
            regUser.RegUserID    = CurrentUserInfo.UserID;
            regUser.EmptyBill    = 0;
            regUser.RegisterWay  = "线上";
            regUser.IsDisable    = 0;

            int disLevel = 1;

            if (website.DistributionLimitLevel > 1)
            {
                disLevel = website.DistributionLimitLevel;
            }

            StringBuilder     sbSql                  = new StringBuilder();
            UserInfo          upUserLevel1           = null; //分销上一级
            UserInfo          upUserLevel2           = null; //分销上二级
            UserInfo          upUserLevel3           = null; //分销上三级
            UserLevelConfig   levelConfig1           = null; //分销上一级规则
            UserLevelConfig   levelConfig2           = null; //分销上二级规则
            UserLevelConfig   levelConfig3           = null; //分销上三级规则
            ProjectCommission modelLevel1            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel1Info    = new ScoreLockInfo();
            ProjectCommission modelLevel1ex1         = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel1ex1Info = new ScoreLockInfo();
            ProjectCommission modelLevel2            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel2Info    = new ScoreLockInfo();
            ProjectCommission modelLevel3            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel3Info    = new ScoreLockInfo();

            string projectId = bll.GetGUID(TransacType.PayRegisterOrder);

            //计算分佣
            bll.ComputeTransfers(disLevel, regUser, projectId, decimal.Parse(cardModel.Ex3), websiteOwner, "优惠券注册", ref sbSql, ref upUserLevel1,
                                 ref upUserLevel2, ref upUserLevel3, ref levelConfig1, ref levelConfig2, ref levelConfig3, ref modelLevel1, ref scoreLockLevel1Info,
                                 ref modelLevel1ex1, ref scoreLockLevel1ex1Info, ref modelLevel2, ref scoreLockLevel2Info, ref modelLevel3, ref scoreLockLevel3Info,
                                 levelConfig.LevelString);

            BLLTransaction tran = new BLLTransaction();

            #region 注册会员

            if (regUser.AutoID == 0)
            {
                regUser.AutoID = Convert.ToInt32(bllUser.AddReturnID(regUser, tran));
                if (regUser.AutoID <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "注册用户出错";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            else
            {
                if (!bllUser.Update(regUser, tran))
                {
                    tran.Rollback();
                    apiResp.msg  = "注册用户出错";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            #endregion
            #region  更新优惠券状态
            myCardCoupon.UseDate = DateTime.Now;
            myCardCoupon.Status  = 1;
            if (!bllCardCoupon.Update(myCardCoupon, tran))
            {
                tran.Rollback();
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "更新优惠券状态失败";
                bll.ContextResponse(context, apiResp);
                return;
            }
            #endregion

            #region 注册账号余额明细
            //自己的消费记录
            if (bllUser.AddScoreDetail(regUser.UserID, websiteOwner, double.Parse(cardModel.Ex3),
                                       string.Format("优惠券抵扣{0}元", double.Parse(cardModel.Ex3)),
                                       "TotalAmount", double.Parse(cardModel.Ex3),
                                       "", "注册会员", "", "", double.Parse(cardModel.Ex3), 0, regUser.UserID,
                                       tran, ex3: levelConfig.LevelNumber.ToString(), ex4: levelConfig.LevelString) <= 0)
            {
                tran.Rollback();
                apiResp.msg  = "积分明细添加失败";
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }
            #endregion
            bool hasProjectCommission = false;
            #region 记录分佣信息
            if (modelLevel1.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel1Id = Convert.ToInt32(bll.AddReturnID(modelLevel1, tran));
                if (modelLevel1Id <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel1Info.ForeignkeyId2 = modelLevel1Id.ToString();
                scoreLockLevel1Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel1Info, tran));
                if (scoreLockLevel1Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel1.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel1Info.UserId, websiteOwner, (double)scoreLockLevel1Info.Score,
                                           scoreLockLevel1Info.Memo, "TotalAmount", (double)(upUserLevel1.TotalAmount + scoreLockLevel1Info.Score),
                                           scoreLockLevel1Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel1.SourceAmount, (double)modelLevel1.DeductAmount,
                                           modelLevel1.CommissionUserId,
                                           tran, ex3: levelConfig.LevelNumber.ToString(), ex4: levelConfig.LevelString,
                                           ex5: modelLevel1.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel1ex1.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel1ex1Id = Convert.ToInt32(bll.AddReturnID(modelLevel1ex1, tran));
                if (modelLevel1ex1Id <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返购房补助失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel1ex1Info.ForeignkeyId2 = modelLevel1ex1Id.ToString();

                scoreLockLevel1ex1Info.AutoId = Convert.ToInt32(bll.AddReturnID(scoreLockLevel1ex1Info, tran));
                if (scoreLockLevel1ex1Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返购房补助冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel1ex1.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel1ex1Info.UserId, websiteOwner, (double)scoreLockLevel1ex1Info.Score,
                                           scoreLockLevel1ex1Info.Memo, "TotalAmount", (double)(upUserLevel1.TotalAmount + scoreLockLevel1ex1Info.Score),
                                           scoreLockLevel1ex1Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel1ex1.SourceAmount, (double)modelLevel1ex1.DeductAmount,
                                           modelLevel1ex1.CommissionUserId,
                                           tran, ex3: levelConfig.LevelNumber.ToString(), ex4: levelConfig.LevelString,
                                           ex5: modelLevel1ex1.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返购房补助明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel2.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel2Id = Convert.ToInt32(bll.AddReturnID(modelLevel2, tran));
                if (modelLevel2Id <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "二级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel2Info.ForeignkeyId2 = modelLevel2Id.ToString();

                scoreLockLevel2Info.AutoId = Convert.ToInt32(bll.AddReturnID(scoreLockLevel2Info, tran));
                if (scoreLockLevel2Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "二级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel2.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel2Info.UserId, websiteOwner, (double)scoreLockLevel2Info.Score,
                                           scoreLockLevel2Info.Memo, "TotalAmount", (double)(upUserLevel2.TotalAmount + scoreLockLevel2Info.Score),
                                           scoreLockLevel2Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel2.SourceAmount, (double)modelLevel2.DeductAmount,
                                           modelLevel2.CommissionUserId,
                                           tran, ex3: levelConfig.LevelNumber.ToString(), ex4: levelConfig.LevelString,
                                           ex5: modelLevel2.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "二级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel3.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel3Id = Convert.ToInt32(bll.AddReturnID(modelLevel3, tran));
                if (!bll.Add(modelLevel3, tran))
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel3Info.ForeignkeyId2 = modelLevel3Id.ToString();
                scoreLockLevel3Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel3Info, tran));
                if (scoreLockLevel3Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel3.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel3Info.UserId, websiteOwner, (double)scoreLockLevel3Info.Score,
                                           scoreLockLevel3Info.Memo, "TotalAmount", (double)(upUserLevel3.TotalAmount + scoreLockLevel3Info.Score),
                                           scoreLockLevel3Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel3.SourceAmount, (double)modelLevel3.DeductAmount,
                                           modelLevel3.CommissionUserId,
                                           tran, ex3: levelConfig.LevelNumber.ToString(), ex4: levelConfig.LevelString,
                                           ex5: modelLevel3.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (hasProjectCommission)
            {
                if (BLLBase.ExecuteSql(sbSql.ToString(), tran) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = string.Format("更新分佣账面{0}出错", website.TotalAmountShowName);
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            #endregion

            #region 记录业绩明细
            TeamPerformanceDetails perDetail = new TeamPerformanceDetails();
            perDetail.AddType           = "注册";
            perDetail.AddNote           = "注册" + levelConfig.LevelString;
            perDetail.AddTime           = DateTime.Now;
            perDetail.DistributionOwner = regUser.DistributionOwner;
            perDetail.UserId            = regUser.UserID;
            perDetail.UserName          = regUser.TrueName;
            perDetail.UserPhone         = regUser.Phone;
            perDetail.Performance       = decimal.Parse(cardModel.Ex3);
            string yearMonthString = perDetail.AddTime.ToString("yyyyMM");
            int    yearMonth       = Convert.ToInt32(yearMonthString);
            perDetail.YearMonth    = yearMonth;
            perDetail.WebsiteOwner = websiteOwner;

            if (!bllUser.Add(perDetail, tran))
            {
                tran.Rollback();
                apiResp.msg  = "记录业绩明细失败";
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }
            #endregion

            tran.Commit();

            if (hasProjectCommission)
            {
                //异步修改积分明细表
                Thread th1 = new Thread(delegate()
                {
                    //计算相关业绩
                    bll.BuildCurMonthPerformanceByUserID(websiteOwner, regUser.UserID);
                });
                th1.Start();
            }


            string msg = "";

            #region 短信发送密码
            BLLSMS bllSms    = new BLLSMS("");
            bool   smsBool   = false;
            string smsString = string.Format("恭喜您成功注册为天下华商月供宝:{1},您的初始密码为:{0}。您可关注公众号:songhetz,登录账户修改密码,并设置支付密码。", regUser.Password, levelConfig.LevelString);
            bllSms.SendSmsMisson(regUser.Phone, smsString, "", website.SmsSignature, out smsBool, out msg);
            #endregion

            if (string.IsNullOrWhiteSpace(msg))
            {
                msg = "注册成功";
            }
            apiResp.msg    = msg;
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                password = regUser.Password
            };
            bll.ContextResponse(context, apiResp);
        }
Ejemplo n.º 4
0
        public void ProcessRequest(HttpContext context)
        {
            int    rows         = Convert.ToInt32(context.Request["rows"]);
            int    page         = Convert.ToInt32(context.Request["page"]);
            int    yearMonth    = Convert.ToInt32(context.Request["yearmonth"]);
            string up_member    = context.Request["up_member"];
            string member       = context.Request["member"];
            string sum          = context.Request["sum"];
            string websiteOwner = bll.WebsiteOwner;
            string userIds      = "";

            #region 查出userIds
            //List<string> mList = new List<string>();
            if (!string.IsNullOrWhiteSpace(member))
            {
                userIds = bllUser.GetSpreadUserIds(member, websiteOwner);
                //string members = bllUser.GetSpreadUserIds(member, websiteOwner);
                //mList = members.Split(',').ToList();
            }
            string parentIds = "";
            if (!string.IsNullOrWhiteSpace(up_member))
            {
                parentIds = bllUser.GetSpreadUserIds(up_member, websiteOwner);
            }
            //List<string> uList = new List<string>();
            //if (!string.IsNullOrWhiteSpace(up_member))
            //{
            //    string parentIds = bllUser.GetSpreadUserIds(up_member, websiteOwner);
            //    uList = parentIds.Split(',').ToList();
            //    //bool hasChild = true;
            //    //while (hasChild)
            //    //{
            //    //    List<UserInfo> nextList = bll.GetChildrenIdList(parentIds, websiteOwner, true, "AutoID,UserID");
            //    //    if (nextList.Count == 0) break;
            //    //    List<string> nList = nextList.Select(p => p.UserID).ToList();
            //    //    parentIds = ZentCloud.Common.MyStringHelper.ListToStr(nList, "", ",");
            //    //    uList.AddRange(nList);
            //    //}
            //}
            //if (!string.IsNullOrWhiteSpace(member) && !string.IsNullOrWhiteSpace(up_member))
            //{
            //    List<string> tList = uList.Intersect(mList).ToList();
            //    if (tList.Count > 0) {
            //        userIds = ZentCloud.Common.MyStringHelper.ListToStr(tList, "", ",");
            //    }
            //    else
            //    {
            //        userIds = "-1";
            //    }
            //}
            //else if (!string.IsNullOrWhiteSpace(up_member))
            //{
            //    if (uList.Count > 0)
            //    {
            //        userIds = ZentCloud.Common.MyStringHelper.ListToStr(uList, "", ",");
            //    }
            //    else
            //    {
            //        userIds = "-1";
            //    }
            //}
            //else if (!string.IsNullOrWhiteSpace(member))
            //{
            //    userIds = ZentCloud.Common.MyStringHelper.ListToStr(mList, "", ",");
            //}
            #endregion 查出userIds

            int total = bll.GetChildPerformanceCount(parentIds, websiteOwner, yearMonth, userIds);
            List <TeamPerformance> performanceList = new List <TeamPerformance>();
            if (total > 0)
            {
                performanceList = bll.GetChildPerformanceList(rows, page, parentIds,
                                                              websiteOwner, yearMonth, userIds, "AutoID,UserId,UserName,UserPhone,YearMonth,Performance,Reward,Status");
            }
            decimal sumPerformance = 0;
            if (sum == "1")
            {
                sumPerformance = bll.GetPerformanceSum(parentIds, websiteOwner, yearMonth, userIds);
            }
            List <dynamic> rList = new List <dynamic>();
            if (performanceList.Count > 0)
            {
                string          pUserIds = ZentCloud.Common.MyStringHelper.ListToStr(performanceList.Select(p => p.UserId).Distinct().ToList(), "'", ",");
                List <UserInfo> uList    = bllUser.GetColMultListByKey <UserInfo>(int.MaxValue, 1, "UserID", pUserIds, "AutoID,WXNickname,TrueName,Phone,UserID,IntelligenceCertificateBusiness", websiteOwner: websiteOwner);
                foreach (var item in performanceList)
                {
                    UserInfo u = uList.FirstOrDefault(p => p.UserID == item.UserId);
                    rList.Add(new{
                        id          = item.AutoID,
                        name        = u == null? item.UserName: bllUser.GetUserDispalyName(u),
                        phone       = u == null? item.UserPhone: u.Phone,
                        business    = u == null? " ": u.IntelligenceCertificateBusiness,
                        yearmonth   = item.YearMonth,
                        performance = item.Performance,
                        reward      = item.Reward,
                        status      = item.Status
                    });
                }
            }
            apiResp.msg    = "获取业绩列表";
            apiResp.result = new
            {
                totalcount = total,
                sum        = Convert.ToDouble(sumPerformance),
                list       = rList
            };
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            bll.ContextResponse(context, apiResp);
        }
Ejemplo n.º 5
0
        public void ProcessRequest(HttpContext context)
        {
            decimal amount = Convert.ToDecimal(context.Request["amount"]);

            if (amount <= 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "金额必须大于0";
                bll.ContextResponse(context, apiResp);
                return;
            }
            string websiteOwner = bll.WebsiteOwner;

            if (string.IsNullOrWhiteSpace(CurrentUserInfo.WXOpenId))
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "请先绑定微信";
                bll.ContextResponse(context, apiResp);
                return;
            }
            PayConfig payConfig = bllPay.GetPayConfig();

            if (payConfig == null || string.IsNullOrEmpty(payConfig.WXAppId) || string.IsNullOrEmpty(payConfig.WXMCH_ID) || string.IsNullOrEmpty(payConfig.WXPartnerKey))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户微信支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付充值";
            orderPay.Total_Fee    = amount;
            orderPay.Type         = "4";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = CurrentUserInfo.UserID;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            string appId     = payConfig.WXAppId;                                                                             //微信AppId
            string mchId     = payConfig.WXMCH_ID;                                                                            //商户号
            string key       = payConfig.WXPartnerKey;                                                                        //api密钥
            string openId    = CurrentUserInfo.WXOpenId;                                                                      //openid
            string ip        = context.Request.UserHostAddress;                                                               //ip
            string notifyUrl = string.Format("http://{0}/WxPayNotify/PayRechargeNotify.aspx", context.Request.Url.Authority); //支付充值通知地址
            string body      = "";                                                                                            //订单内容

            string payReqStr = bllPay.GetBrandWcPayRequest(orderPay.OrderId, orderPay.Total_Fee, appId, mchId, key, openId, ip, notifyUrl, body);

            BllPay.WXPayReq payReqModel = ZentCloud.Common.JSONHelper.JsonToModel <BllPay.WXPayReq>(payReqStr);
            if (string.IsNullOrEmpty(payReqModel.paySign))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "构造支付信息失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_req = payReqModel
            };
            bllUser.ContextResponse(context, apiResp);
        }
Ejemplo n.º 6
0
        public void ProcessRequest(HttpContext context)
        {
            BLLJIMP.Model.API.User.PayUpgrade requestUpgrade = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayUpgrade>(new BLLJIMP.Model.API.User.PayUpgrade());
            string websiteOwner = bll.WebsiteOwner;

            requestUpgrade.level = CurrentUserInfo.MemberLevel;
            WebsiteInfo     website     = bllUser.GetWebsiteInfoModelFromDataBase(websiteOwner);
            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUpgrade.level.ToString());

            if (levelConfig == null)
            {
                requestUpgrade.userTotalAmount = 0;
            }
            else
            {
                requestUpgrade.userTotalAmount = Convert.ToDecimal(levelConfig.FromHistoryScore);
            }
            UserLevelConfig toLevelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUpgrade.toLevel.ToString());

            if (toLevelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员等级未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (toLevelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止升级";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUpgrade.needAmount = Convert.ToDecimal(toLevelConfig.FromHistoryScore);
            requestUpgrade.amount     = requestUpgrade.needAmount - requestUpgrade.userTotalAmount;
            if (requestUpgrade.amount < 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "暂时不支持降级";
                bll.ContextResponse(context, apiResp);
                return;
            }

            string configV1CouponId = ZentCloud.Common.ConfigHelper.GetConfigString("YGBV1CouponId");
            string configV2CouponId = ZentCloud.Common.ConfigHelper.GetConfigString("YGBV2CouponId");
            string v1LevelNumber    = ZentCloud.Common.ConfigHelper.GetConfigString("V1LevelNumber");
            string v2LevelNumber    = ZentCloud.Common.ConfigHelper.GetConfigString("V2LevelNumber");

            string couponId = string.Empty;

            CardCoupons   cardModel    = null;
            MyCardCoupons myCardCoupon = null;

            if (requestUpgrade.vType == "V1")
            {
                if (string.IsNullOrEmpty(configV1CouponId))
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "V1优惠券未配置";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                couponId     = configV1CouponId;
                cardModel    = bllCardCoupon.GetCardCoupon(Convert.ToInt32(couponId));
                myCardCoupon = bllCardCoupon.GetMyCardCouponMainId(Convert.ToInt32(couponId), CurrentUserInfo.UserID);
                if (cardModel == null || myCardCoupon == null)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不存在";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                if (requestUpgrade.toLevel.ToString() != v1LevelNumber)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不匹配";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (requestUpgrade.vType == "V2")
            {
                if (string.IsNullOrEmpty(configV2CouponId))
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "V2优惠券未配置";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                couponId     = configV2CouponId;
                cardModel    = bllCardCoupon.GetCardCoupon(Convert.ToInt32(couponId));
                myCardCoupon = bllCardCoupon.GetMyCardCouponMainId(Convert.ToInt32(couponId), CurrentUserInfo.UserID);
                if (cardModel == null || myCardCoupon == null)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不存在";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
                if (requestUpgrade.toLevel.ToString() != v2LevelNumber)
                {
                    apiResp.code = (int)APIErrCode.ContentNotFound;
                    apiResp.msg  = "优惠券不能用于此升级";
                    bllUser.ContextResponse(context, apiResp);
                    return;
                }
            }

            BLLTransaction tran = new BLLTransaction();

            StringBuilder     sbSql                  = new StringBuilder();
            UserInfo          upUserLevel1           = null; //分销上一级
            UserInfo          upUserLevel2           = null; //分销上二级
            UserInfo          upUserLevel3           = null; //分销上三级
            UserLevelConfig   levelConfig1           = null; //分销上一级规则
            UserLevelConfig   levelConfig2           = null; //分销上二级规则
            UserLevelConfig   levelConfig3           = null; //分销上三级规则
            ProjectCommission modelLevel1            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel1Info    = new ScoreLockInfo();
            ProjectCommission modelLevel1ex1         = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel1ex1Info = new ScoreLockInfo();
            ProjectCommission modelLevel2            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel2Info    = new ScoreLockInfo();
            ProjectCommission modelLevel3            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel3Info    = new ScoreLockInfo();

            int disLevel = 1;

            if (website.DistributionLimitLevel > 1)
            {
                disLevel = website.DistributionLimitLevel;
            }

            string projectId = bll.GetGUID(TransacType.PayRegisterOrder);

            CurrentUserInfo.MemberLevel       = requestUpgrade.toLevel;
            CurrentUserInfo.MemberApplyStatus = 9;

            //计算分佣
            bll.ComputeTransfers(disLevel, CurrentUserInfo, projectId, requestUpgrade.amount, websiteOwner, "余额升级", ref sbSql, ref upUserLevel1,
                                 ref upUserLevel2, ref upUserLevel3, ref levelConfig1, ref levelConfig2, ref levelConfig3, ref modelLevel1, ref scoreLockLevel1Info,
                                 ref modelLevel1ex1, ref scoreLockLevel1ex1Info, ref modelLevel2, ref scoreLockLevel2Info, ref modelLevel3, ref scoreLockLevel3Info,
                                 toLevelConfig.LevelString);

            if (bll.Update(CurrentUserInfo, string.Format(" MemberLevel={0},IsDisable=0,MemberApplyStatus=9 ", CurrentUserInfo.MemberLevel), string.Format(" AutoId='{0}' ", CurrentUserInfo.AutoID), tran) <= 0)
            {
                tran.Rollback();
                apiResp.msg  = "更新用户等级失败";
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }

            bool hasProjectCommission = false;

            #region 记录分佣信息
            if (modelLevel1.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel1Id = Convert.ToInt32(bll.AddReturnID(modelLevel1, tran));
                if (modelLevel1Id <= 0)
                {
                    apiResp.msg  = "一级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel1Info.ForeignkeyId2 = modelLevel1Id.ToString();
                scoreLockLevel1Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel1Info, tran));
                if (scoreLockLevel1Info.AutoId <= 0)
                {
                    apiResp.msg  = "一级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel1.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel1Info.UserId, websiteOwner, (double)scoreLockLevel1Info.Score,
                                           scoreLockLevel1Info.Memo, "TotalAmount", (double)(upUserLevel1.TotalAmount + scoreLockLevel1Info.Score),
                                           scoreLockLevel1Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel1.SourceAmount, (double)modelLevel1.DeductAmount,
                                           modelLevel1.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel1.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel1ex1.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel1ex1Id = Convert.ToInt32(bll.AddReturnID(modelLevel1ex1, tran));
                if (modelLevel1ex1Id <= 0)
                {
                    apiResp.msg  = "一级返购房补助失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel1ex1Info.ForeignkeyId2 = modelLevel1ex1Id.ToString();
                scoreLockLevel1ex1Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel1ex1Info, tran));
                if (scoreLockLevel1ex1Info.AutoId <= 0)
                {
                    apiResp.msg  = "一级返购房补助冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel1ex1.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel1ex1Info.UserId, websiteOwner, (double)scoreLockLevel1ex1Info.Score,
                                           scoreLockLevel1ex1Info.Memo, "TotalAmount", (double)(upUserLevel1.TotalAmount + scoreLockLevel1ex1Info.Score),
                                           scoreLockLevel1ex1Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel1ex1.SourceAmount, (double)modelLevel1ex1.DeductAmount,
                                           modelLevel1ex1.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel1ex1.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返购房补助明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel2.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel2Id = Convert.ToInt32(bll.AddReturnID(modelLevel2, tran));
                if (modelLevel2Id <= 0)
                {
                    apiResp.msg  = "二级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel2Info.ForeignkeyId2 = modelLevel2Id.ToString();
                scoreLockLevel2Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel2Info, tran));
                if (scoreLockLevel2Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "二级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel2.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel2Info.UserId, websiteOwner, (double)scoreLockLevel2Info.Score,
                                           scoreLockLevel2Info.Memo, "TotalAmount", (double)(upUserLevel2.TotalAmount + scoreLockLevel2Info.Score),
                                           scoreLockLevel2Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel2.SourceAmount, (double)modelLevel2.DeductAmount,
                                           modelLevel2.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel2.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "二级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel3.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel3Id = Convert.ToInt32(bll.AddReturnID(modelLevel3, tran));
                if (!bll.Add(modelLevel3, tran))
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel3Info.ForeignkeyId2 = modelLevel3Id.ToString();
                scoreLockLevel3Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel3Info, tran));
                if (scoreLockLevel3Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel3.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel3Info.UserId, websiteOwner, (double)scoreLockLevel3Info.Score,
                                           scoreLockLevel3Info.Memo, "TotalAmount", (double)(upUserLevel3.TotalAmount + scoreLockLevel3Info.Score),
                                           scoreLockLevel3Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel3.SourceAmount, (double)modelLevel3.DeductAmount,
                                           modelLevel3.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel3.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            #endregion

            #region 更新分佣账面金额
            if (hasProjectCommission)
            {
                if (BLLBase.ExecuteSql(sbSql.ToString(), tran) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = string.Format("更新分佣账面{0}出错", website.TotalAmountShowName);
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            #endregion

            #region 记录余额明细
            //自己的消费记录
            if (bllUser.AddScoreDetail(CurrentUserInfo.UserID, websiteOwner, (double)(0 - requestUpgrade.amount),
                                       string.Format("{1}为{0}", toLevelConfig.LevelString, "升级"), "TotalAmount", (double)(CurrentUserInfo.TotalAmount - requestUpgrade.amount),
                                       "", "升级会员", "", "", (double)requestUpgrade.amount, 0, "",
                                       tran, ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                       ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString) <= 0)
            {
                tran.Rollback();
                apiResp.msg  = "升级会员明细出错";
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }

            #endregion

            #region 修改优惠券 更新支付状态
            myCardCoupon.UseDate = DateTime.Now;
            myCardCoupon.Status  = 1;
            if (!bllCardCoupon.Update(myCardCoupon, tran))
            {
                tran.Rollback();
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "更新优惠券状态失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            #endregion

            #region 记录业绩明细
            TeamPerformanceDetails perDetail = new TeamPerformanceDetails();
            perDetail.AddType           = "升级";
            perDetail.AddNote           = "由" + levelConfig.LevelString + "升级" + toLevelConfig.LevelString;
            perDetail.AddTime           = DateTime.Now;
            perDetail.DistributionOwner = CurrentUserInfo.DistributionOwner;
            perDetail.UserId            = CurrentUserInfo.UserID;
            perDetail.UserName          = CurrentUserInfo.TrueName;
            perDetail.UserPhone         = CurrentUserInfo.Phone;
            perDetail.Performance       = requestUpgrade.amount;
            string yearMonthString = perDetail.AddTime.ToString("yyyyMM");
            int    yearMonth       = Convert.ToInt32(yearMonthString);
            perDetail.WebsiteOwner = websiteOwner;
            perDetail.YearMonth    = yearMonth;

            if (!bllUser.Add(perDetail, tran))
            {
                tran.Rollback();
                apiResp.msg  = "记录业绩明细失败";
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }
            #endregion

            tran.Commit();
            if (hasProjectCommission)
            {
                //异步修改积分明细表
                Thread th1 = new Thread(delegate()
                {
                    //计算相关业绩
                    bll.BuildCurMonthPerformanceByUserID(websiteOwner, CurrentUserInfo.UserID);
                });
                th1.Start();
            }
            apiResp.msg    = "升级完成";
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;

            bll.ContextResponse(context, apiResp);
        }
Ejemplo n.º 7
0
        public void ProcessRequest(HttpContext context)
        {
            if (CurrentUserInfo.IsLock == 1)
            {
                apiResp.code = (int)APIErrCode.NoPms;
                apiResp.msg  = "账号已被锁定";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            if (CurrentUserInfo.MemberApplyStatus != 9)
            {
                apiResp.code = (int)APIErrCode.NoPms;
                apiResp.msg  = "您的账号正在审核中";
                bllUser.ContextResponse(context, apiResp);
                return;
            }
            BLLJIMP.Model.API.User.PayUpgrade requestUpgrade = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayUpgrade>(new BLLJIMP.Model.API.User.PayUpgrade());
            string websiteOwner = bll.WebsiteOwner;

            requestUpgrade.level = CurrentUserInfo.MemberLevel;
            WebsiteInfo     website     = bllUser.GetWebsiteInfoModelFromDataBase(websiteOwner);
            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUpgrade.level.ToString());

            if (levelConfig == null)
            {
                requestUpgrade.userTotalAmount = 0;
            }
            else
            {
                requestUpgrade.userTotalAmount = Convert.ToDecimal(levelConfig.FromHistoryScore);
            }
            UserLevelConfig toLevelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUpgrade.toLevel.ToString());

            if (toLevelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员等级未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (toLevelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止升级";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUpgrade.needAmount = Convert.ToDecimal(toLevelConfig.FromHistoryScore);
            requestUpgrade.amount     = requestUpgrade.needAmount - requestUpgrade.userTotalAmount;
            if (requestUpgrade.amount < 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "暂时不支持降级";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (CurrentUserInfo.TotalAmount < requestUpgrade.amount)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = string.Format("您的可用{0}不足", website.TotalAmountShowName);
                bll.ContextResponse(context, apiResp);
                return;
            }

            BLLTransaction tran = new BLLTransaction();

            StringBuilder     sbSql                  = new StringBuilder();
            UserInfo          upUserLevel1           = null; //分销上一级
            UserInfo          upUserLevel2           = null; //分销上二级
            UserInfo          upUserLevel3           = null; //分销上三级
            UserLevelConfig   levelConfig1           = null; //分销上一级规则
            UserLevelConfig   levelConfig2           = null; //分销上二级规则
            UserLevelConfig   levelConfig3           = null; //分销上三级规则
            ProjectCommission modelLevel1            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel1Info    = new ScoreLockInfo();
            ProjectCommission modelLevel1ex1         = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel1ex1Info = new ScoreLockInfo();
            ProjectCommission modelLevel2            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel2Info    = new ScoreLockInfo();
            ProjectCommission modelLevel3            = new ProjectCommission();
            ScoreLockInfo     scoreLockLevel3Info    = new ScoreLockInfo();

            int disLevel = 1;

            if (website.DistributionLimitLevel > 1)
            {
                disLevel = website.DistributionLimitLevel;
            }

            string projectId = bll.GetGUID(TransacType.PayRegisterOrder);

            CurrentUserInfo.MemberLevel       = requestUpgrade.toLevel;
            CurrentUserInfo.MemberApplyStatus = 9;
            //计算分佣
            bll.ComputeTransfers(disLevel, CurrentUserInfo, projectId, requestUpgrade.amount, websiteOwner, "余额升级", ref sbSql, ref upUserLevel1,
                                 ref upUserLevel2, ref upUserLevel3, ref levelConfig1, ref levelConfig2, ref levelConfig3, ref modelLevel1, ref scoreLockLevel1Info,
                                 ref modelLevel1ex1, ref scoreLockLevel1ex1Info, ref modelLevel2, ref scoreLockLevel2Info, ref modelLevel3, ref scoreLockLevel3Info,
                                 toLevelConfig.LevelString);


            bool hasProjectCommission = false;

            #region 记录分佣信息
            if (modelLevel1.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel1Id = Convert.ToInt32(bll.AddReturnID(modelLevel1, tran));
                if (modelLevel1Id <= 0)
                {
                    apiResp.msg  = "一级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel1Info.ForeignkeyId2 = modelLevel1Id.ToString();
                scoreLockLevel1Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel1Info, tran));
                if (scoreLockLevel1Info.AutoId <= 0)
                {
                    apiResp.msg  = "一级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel1.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel1Info.UserId, websiteOwner, (double)scoreLockLevel1Info.Score,
                                           scoreLockLevel1Info.Memo, "TotalAmount", (double)(upUserLevel1.TotalAmount + scoreLockLevel1Info.Score),
                                           scoreLockLevel1Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel1.SourceAmount, (double)modelLevel1.DeductAmount,
                                           modelLevel1.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel1.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel1ex1.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel1ex1Id = Convert.ToInt32(bll.AddReturnID(modelLevel1ex1, tran));
                if (modelLevel1ex1Id <= 0)
                {
                    apiResp.msg  = "一级返购房补助失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel1ex1Info.ForeignkeyId2 = modelLevel1ex1Id.ToString();
                scoreLockLevel1ex1Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel1ex1Info, tran));
                if (scoreLockLevel1ex1Info.AutoId <= 0)
                {
                    apiResp.msg  = "一级返购房补助冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel1ex1.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel1ex1Info.UserId, websiteOwner, (double)scoreLockLevel1ex1Info.Score,
                                           scoreLockLevel1ex1Info.Memo, "TotalAmount", (double)(upUserLevel1.TotalAmount + scoreLockLevel1ex1Info.Score),
                                           scoreLockLevel1ex1Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel1ex1.SourceAmount, (double)modelLevel1ex1.DeductAmount,
                                           modelLevel1ex1.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel1ex1.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "一级返购房补助明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel2.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel2Id = Convert.ToInt32(bll.AddReturnID(modelLevel2, tran));
                if (modelLevel2Id <= 0)
                {
                    apiResp.msg  = "二级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel2Info.ForeignkeyId2 = modelLevel2Id.ToString();
                scoreLockLevel2Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel2Info, tran));
                if (scoreLockLevel2Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "二级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel2.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel2Info.UserId, websiteOwner, (double)scoreLockLevel2Info.Score,
                                           scoreLockLevel2Info.Memo, "TotalAmount", (double)(upUserLevel2.TotalAmount + scoreLockLevel2Info.Score),
                                           scoreLockLevel2Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel2.SourceAmount, (double)modelLevel2.DeductAmount,
                                           modelLevel2.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel2.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "二级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            if (modelLevel3.Amount > 0)
            {
                hasProjectCommission = true;
                int modelLevel3Id = Convert.ToInt32(bll.AddReturnID(modelLevel3, tran));
                if (!bll.Add(modelLevel3, tran))
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                scoreLockLevel3Info.ForeignkeyId2 = modelLevel3Id.ToString();
                scoreLockLevel3Info.AutoId        = Convert.ToInt32(bll.AddReturnID(scoreLockLevel3Info, tran));
                if (scoreLockLevel3Info.AutoId <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利冻结失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
                string scoreDetailEvent = modelLevel3.ProjectName.Contains("购房补助") ? "返购房补助" : "返利";
                if (bllUser.AddScoreDetail(scoreLockLevel3Info.UserId, websiteOwner, (double)scoreLockLevel3Info.Score,
                                           scoreLockLevel3Info.Memo, "TotalAmount", (double)(upUserLevel3.TotalAmount + scoreLockLevel3Info.Score),
                                           scoreLockLevel3Info.AutoId.ToString(), scoreDetailEvent, "", projectId, (double)modelLevel3.SourceAmount, (double)modelLevel3.DeductAmount,
                                           modelLevel3.CommissionUserId, tran,
                                           ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                           ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString,
                                           ex5: modelLevel3.CommissionLevel) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = "三级返利明细记录失败";
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            #endregion

            #region 更新分佣账面金额
            if (hasProjectCommission)
            {
                if (BLLBase.ExecuteSql(sbSql.ToString(), tran) <= 0)
                {
                    tran.Rollback();
                    apiResp.msg  = string.Format("更新分佣账面{0}出错", website.TotalAmountShowName);
                    apiResp.code = (int)APIErrCode.OperateFail;
                    bll.ContextResponse(context, apiResp);
                    return;
                }
            }
            #endregion

            #region 记录余额明细
            //自己的消费记录
            if (bllUser.AddScoreDetail(CurrentUserInfo.UserID, websiteOwner, (double)(0 - requestUpgrade.amount),
                                       string.Format("{1}为{0}", toLevelConfig.LevelString, "升级"), "TotalAmount", (double)(CurrentUserInfo.TotalAmount - requestUpgrade.amount),
                                       "", "升级会员", "", "", (double)requestUpgrade.amount, 0, "",
                                       tran, ex1: levelConfig.LevelNumber.ToString(), ex2: levelConfig.LevelString,
                                       ex3: toLevelConfig.LevelNumber.ToString(), ex4: toLevelConfig.LevelString) <= 0)
            {
                tran.Rollback();
                apiResp.msg  = "升级会员明细出错";
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }

            #endregion

            #region 修改金额 更新支付状态

            if (BLLBase.ExecuteSql(string.Format("UPDATE ZCJ_UserInfo SET MemberLevel={0},IsDisable=0,MemberApplyStatus=9,TotalAmount=ISNULL(TotalAmount,0)-{3},AccountAmountEstimate=ISNULL(AccountAmountEstimate,0)-{3} FROM ZCJ_UserInfo WHERE UserID='{1}' And WebsiteOwner='{2}' And ISNULL(TotalAmount,0)-{3}>=0 ;",
                                                 requestUpgrade.toLevel, CurrentUserInfo.UserID, websiteOwner, requestUpgrade.amount),
                                   tran) <= 0)
            {
                tran.Rollback();
                apiResp.msg  = string.Format("扣除用户可用{0}出错", website.TotalAmountShowName);
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }
            #endregion

            #region 记录业绩明细
            TeamPerformanceDetails perDetail = new TeamPerformanceDetails();
            perDetail.AddType           = "升级";
            perDetail.AddNote           = "由" + levelConfig.LevelString + "升级" + toLevelConfig.LevelString;
            perDetail.AddTime           = DateTime.Now;
            perDetail.DistributionOwner = CurrentUserInfo.DistributionOwner;
            perDetail.UserId            = CurrentUserInfo.UserID;
            perDetail.UserName          = CurrentUserInfo.TrueName;
            perDetail.UserPhone         = CurrentUserInfo.Phone;
            perDetail.Performance       = requestUpgrade.amount;
            string yearMonthString = perDetail.AddTime.ToString("yyyyMM");
            int    yearMonth       = Convert.ToInt32(yearMonthString);
            perDetail.WebsiteOwner = websiteOwner;
            perDetail.YearMonth    = yearMonth;

            if (!bllUser.Add(perDetail, tran))
            {
                tran.Rollback();
                apiResp.msg  = "记录业绩明细失败";
                apiResp.code = (int)APIErrCode.OperateFail;
                bll.ContextResponse(context, apiResp);
                return;
            }
            #endregion

            tran.Commit();
            if (hasProjectCommission)
            {
                //异步修改积分明细表
                Thread th1 = new Thread(delegate()
                {
                    //计算相关业绩
                    bll.BuildCurMonthPerformanceByUserID(websiteOwner, CurrentUserInfo.UserID);
                });
                th1.Start();
            }
            apiResp.msg    = "升级完成";
            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;

            bll.ContextResponse(context, apiResp);
        }
Ejemplo n.º 8
0
        public void BuildOrder(HttpContext context, int payType)
        {
            BLLJIMP.Model.API.User.PayRegisterUser requestUser = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayRegisterUser>(new BLLJIMP.Model.API.User.PayRegisterUser());
            string websiteOwner = bll.WebsiteOwner;

            if (string.IsNullOrWhiteSpace(requestUser.level.ToString()))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请选择会员级别";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.spreadid))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入推荐人编号";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入手机号码";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.PhoneNumLogicJudge(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "手机号码格式不正确";
                bll.ContextResponse(context, apiResp);
                return;
            }

            if (!ZentCloud.Common.MyRegex.IsIDCard(requestUser.idcard))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "身份证号码必须如实填写";
                bll.ContextResponse(context, apiResp);
                return;
            }
            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUser.level.ToString());

            if (levelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (levelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止注册";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.levelname = levelConfig.LevelString;
            UserInfo spreadUser = bllUser.GetSpreadUser(requestUser.spreadid, websiteOwner);

            if (spreadUser == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "推荐人未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.spreadid = spreadUser.UserID; //推荐人
            UserInfo oldUserInfo = bllUser.GetUserInfoByPhone(requestUser.phone, websiteOwner);

            if (oldUserInfo != null && oldUserInfo.MemberLevel > 0)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该手机已注册会员";
                bll.ContextResponse(context, apiResp);
                return;
            }

            PayConfig payConfig = bllPay.GetPayConfig();

            if (payType == 1 && !bllPay.IsAliPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户支付宝支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            else if (payType == 2 && !bllPay.IsJDPay(payConfig))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户京东支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (oldUserInfo != null)
            {
                requestUser.userid = oldUserInfo.UserID;
            }
            else
            {
                requestUser.userid = string.Format("ZYUser{0}{1}", DateTime.Now.ToString("yyyyMMdd"), Guid.NewGuid().ToString("N").ToUpper());
            }
            requestUser.regIP    = context.Request.UserHostAddress;//ip
            requestUser.password = ZentCloud.Common.Rand.Number(6);

            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付注册会员";
            orderPay.Total_Fee    = Convert.ToDecimal(levelConfig.FromHistoryScore);
            orderPay.Type         = "5";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = requestUser.userid;
            orderPay.Ex1          = JsonConvert.SerializeObject(requestUser);
            orderPay.Ex2          = requestUser.phone;
            orderPay.PayType      = payType;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_order_id = orderPay.OrderId
            };
            bllUser.ContextResponse(context, apiResp);
        }
Ejemplo n.º 9
0
        public void ProcessRequest(HttpContext context)
        {
            BLLJIMP.Model.API.User.PayRegisterUser requestUser = bll.ConvertRequestToModel <BLLJIMP.Model.API.User.PayRegisterUser>(new BLLJIMP.Model.API.User.PayRegisterUser());
            string websiteOwner = bll.WebsiteOwner;

            if (context.Session["currWXOpenId"] == null)
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "仅支持微信注册";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (string.IsNullOrWhiteSpace(requestUser.spreadid))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入推荐人编号";
                bll.ContextResponse(context, apiResp);
                return;
            }
            string currWXOpenId = context.Session["currWXOpenId"].ToString();

            if (string.IsNullOrWhiteSpace(requestUser.level.ToString()))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请选择会员级别";
                bll.ContextResponse(context, apiResp);
                return;
            }

            if (string.IsNullOrWhiteSpace(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.PrimaryKeyIncomplete;
                apiResp.msg  = "请输入手机号码";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.PhoneNumLogicJudge(requestUser.phone))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "手机号码格式不正确";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (!ZentCloud.Common.MyRegex.IsIDCard(requestUser.idcard))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "身份证号码必须如实填写";
                bll.ContextResponse(context, apiResp);
                return;
            }
            UserLevelConfig levelConfig = bll.QueryUserLevel(websiteOwner, "DistributionOnLine", requestUser.level.ToString());

            if (levelConfig == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (levelConfig.IsDisable == 1)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "会员级别禁止注册";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.levelname = levelConfig.LevelString;
            UserInfo spreadUser = spreadUser = bllUser.GetSpreadUser(requestUser.spreadid, websiteOwner);

            if (spreadUser == null)
            {
                apiResp.code = (int)APIErrCode.IsNotFound;
                apiResp.msg  = "推荐人未找到";
                bll.ContextResponse(context, apiResp);
                return;
            }
            requestUser.spreadid = spreadUser.UserID; //推荐人
            UserInfo oldUserInfo = bllUser.GetUserInfoByPhone(requestUser.phone, websiteOwner);

            if (oldUserInfo != null && oldUserInfo.MemberLevel >= 10)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该手机已注册会员";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (oldUserInfo != null && oldUserInfo.MemberLevel > requestUser.level)
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该会员有更高级别";
                bll.ContextResponse(context, apiResp);
                return;
            }

            PayConfig payConfig = bllPay.GetPayConfig();

            if (payConfig == null || string.IsNullOrEmpty(payConfig.WXAppId) || string.IsNullOrEmpty(payConfig.WXMCH_ID) || string.IsNullOrEmpty(payConfig.WXPartnerKey))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "该商户微信支付还没有配置";
                bll.ContextResponse(context, apiResp);
                return;
            }
            if (oldUserInfo != null)
            {
                requestUser.userid = oldUserInfo.UserID;
            }
            else
            {
                requestUser.userid = string.Format("ZYUser{0}{1}", DateTime.Now.ToString("yyyyMMdd"), Guid.NewGuid().ToString("N").ToUpper());
            }
            requestUser.regIP    = context.Request.UserHostAddress;//ip
            requestUser.password = ZentCloud.Common.Rand.Number(6);

            OrderPay orderPay = new OrderPay();

            orderPay.OrderId      = bll.GetGUID(TransacType.PayRegisterOrder);
            orderPay.InsertDate   = DateTime.Now;
            orderPay.Subject      = "支付注册会员";
            orderPay.Total_Fee    = Convert.ToDecimal(levelConfig.FromHistoryScore);
            orderPay.Type         = "5";
            orderPay.WebsiteOwner = websiteOwner;
            orderPay.UserId       = requestUser.userid;
            orderPay.Ex1          = JsonConvert.SerializeObject(requestUser);
            orderPay.Ex2          = requestUser.phone;
            if (!bll.Add(orderPay))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "生成支付订单失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            string appId     = payConfig.WXAppId;                                                                             //微信AppId
            string mchId     = payConfig.WXMCH_ID;                                                                            //商户号
            string key       = payConfig.WXPartnerKey;                                                                        //api密钥
            string openId    = currWXOpenId;                                                                                  //openid
            string notifyUrl = string.Format("http://{0}/WxPayNotify/PayRegisterNotify.aspx", context.Request.Url.Authority); //支付注册通知地址
            string body      = "";                                                                                            //订单内容

            string payReqStr = bllPay.GetBrandWcPayRequest(orderPay.OrderId, orderPay.Total_Fee, appId, mchId, key, openId, requestUser.regIP, notifyUrl, body);

            BllPay.WXPayReq payReqModel = ZentCloud.Common.JSONHelper.JsonToModel <BllPay.WXPayReq>(payReqStr);
            if (string.IsNullOrEmpty(payReqModel.paySign))
            {
                apiResp.code = (int)APIErrCode.OperateFail;
                apiResp.msg  = "构造支付信息失败";
                bll.ContextResponse(context, apiResp);
                return;
            }

            apiResp.code   = (int)APIErrCode.IsSuccess;
            apiResp.status = true;
            apiResp.result = new
            {
                pay_req = payReqModel
            };
            bllUser.ContextResponse(context, apiResp);
        }