コード例 #1
0
ファイル: Set.ashx.cs プロジェクト: 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);
        }
コード例 #2
0
ファイル: SetList.ashx.cs プロジェクト: uvbs/mmp
        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);
        }