Exemple #1
0
        public object DelMerch(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg  = string.Empty;
                string merchId = dicParas.ContainsKey("merchId") ? dicParas["merchId"].ToString() : string.Empty;
                XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel];
                string createUserId = userTokenKeyModel.LogId;

                #region 验证参数

                if (string.IsNullOrWhiteSpace(merchId))
                {
                    errMsg = "商户编号不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(merchId) && merchId.Length > 11)
                {
                    errMsg = "商户编号不能超过11个字符";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                #endregion

                IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>();
                if (base_MerchantInfoService.Any(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)))
                {
                    var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                    if (base_MerchantInfoModel.CreateType == (int)CreateType.Agent && !base_MerchantInfoModel.CreateUserID.Equals(createUserId, StringComparison.OrdinalIgnoreCase)) //代理商创建
                    {
                        errMsg = "该商户只有所属代理商能删除";
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }

                    base_MerchantInfoModel.MerchStatus = (int)MerchState.Stop;
                    if (!base_MerchantInfoService.Update(base_MerchantInfoModel))
                    {
                        errMsg = "删除商户信息失败";
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }
                }
                else
                {
                    errMsg = "该商户信息不存在";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                //更新缓存
                MerchBusiness.Init();

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Exemple #2
0
        public object ResetPassword(Dictionary <string, object> dicParas)
        {
            try
            {
                string errMsg = string.Empty;
                //string mobil = dicParas.ContainsKey("mobil") ? dicParas["mobil"].ToString() : string.Empty;

                //if (string.IsNullOrEmpty(mobil))
                //{
                //    errMsg = "手机号不能为空";
                //    return ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg);
                //}

                //if (!Utils.CheckMobile(mobil))
                //{
                //    errMsg = "手机号不正确";
                //    return ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg);
                //}

                //bool isSMSTest = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["isSMSTest"].ToString());
                //string pwd = "123456";
                //if (!isSMSTest)
                //{
                //    //生成6位随机字母数字混合
                //    pwd = Utils.GetCheckCode(6);
                //    ResetPasswordCache.Add(mobil, pwd, CacheExpires.SMSCodeExpires);
                //    if (!SMSBusiness.SendSMSCode("3", mobil, pwd, out errMsg))
                //    {
                //        return ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg);
                //    }
                //}
                //else
                //{
                //    ResetPasswordCache.Add(mobil, pwd, CacheExpires.SMSCodeExpires);
                //}

                string openId = dicParas.ContainsKey("openId") ? dicParas["openId"].ToString() : string.Empty;

                if (string.IsNullOrEmpty(openId))
                {
                    errMsg = "openId不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                MerchInfoCacheModel merchInfoCacheModel = null;
                if (!MerchBusiness.IsEffectiveMerch(openId, out merchInfoCacheModel))
                {
                    errMsg = "该商户不存在";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                string merchId = merchInfoCacheModel.MerchID;
                string pwd     = Utils.GetCheckCode(6);
                IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>();
                var base_MerchantInfoModel = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                base_MerchantInfoModel.MerchPassword = Utils.MD5(pwd);
                if (!base_MerchantInfoService.Update(base_MerchantInfoModel))
                {
                    errMsg = "更新数据库失败";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                //推送微信消息
                ResetPasswordMessagePush(openId, base_MerchantInfoModel.MerchAccount, pwd);

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }
Exemple #3
0
        public object EditMerch(Dictionary <string, object> dicParas)
        {
            try
            {
                string   errMsg           = string.Empty;
                string   merchId          = dicParas.ContainsKey("merchId") ? dicParas["merchId"].ToString() : string.Empty;
                string   merchType        = dicParas.ContainsKey("merchType") ? dicParas["merchType"].ToString() : string.Empty;
                string   merchTag         = dicParas.ContainsKey("merchTag") ? dicParas["merchTag"].ToString() : string.Empty;
                string   merchStatus      = dicParas.ContainsKey("merchStatus") ? dicParas["merchStatus"].ToString() : string.Empty;
                string   merchAccount     = dicParas.ContainsKey("merchAccount") ? dicParas["merchAccount"].ToString() : string.Empty;
                string   merchName        = dicParas.ContainsKey("merchName") ? dicParas["merchName"].ToString() : string.Empty;
                string   openId           = dicParas.ContainsKey("openId") ? dicParas["openId"].ToString() : string.Empty;
                string   mobil            = dicParas.ContainsKey("mobil") ? dicParas["mobil"].ToString() : string.Empty;
                string   allowCreateSub   = dicParas.ContainsKey("allowCreateSub") ? dicParas["allowCreateSub"].ToString() : string.Empty;
                string   allowCreateCount = dicParas.ContainsKey("allowCreateCount") ? dicParas["allowCreateCount"].ToString() : string.Empty;
                string   comment          = dicParas.ContainsKey("comment") ? dicParas["comment"].ToString() : string.Empty;
                object[] merchFunction    = dicParas.ContainsKey("merchFunction") ? (object[])dicParas["merchFunction"] : null;
                XCCloudUserTokenModel userTokenKeyModel = (XCCloudUserTokenModel)dicParas[Constant.XCCloudUserTokenModel];
                string createUserId = userTokenKeyModel.LogId;
                int    logType      = userTokenKeyModel.LogType;

                #region 验证参数

                if (string.IsNullOrEmpty(merchId))
                {
                    errMsg = "商户编号不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrWhiteSpace(merchType))
                {
                    errMsg = "商户类型不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.isNumber(merchType))
                {
                    errMsg = "商户类别不是Int类型";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrWhiteSpace(merchStatus))
                {
                    errMsg = "商户状态不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.isNumber(merchStatus))
                {
                    errMsg = "商户状态不是Int类型";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrEmpty(merchTag))
                {
                    errMsg = "商户标签不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.isNumber(merchTag))
                {
                    errMsg = "商户标签不是Int类型";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrWhiteSpace(merchAccount))
                {
                    errMsg = "商户账号不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (merchAccount.Length > 100)
                {
                    errMsg = "商户账号不能超过100个字符";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrWhiteSpace(merchName))
                {
                    errMsg = "负责人不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (merchName.Length > 50)
                {
                    errMsg = "负责人名称不能超过50个字符";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrWhiteSpace(openId))
                {
                    errMsg = "请选择微信昵称";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (string.IsNullOrWhiteSpace(mobil))
                {
                    errMsg = "手机号不能为空";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!Utils.CheckMobile(mobil))
                {
                    errMsg = "手机号不正确";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(allowCreateSub) && !Utils.isNumber(allowCreateSub))
                {
                    errMsg = "是否允许创建子账号不是Int类型";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(allowCreateCount) && !Utils.isNumber(allowCreateCount))
                {
                    errMsg = "账号数量不是Int类型";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                if (!string.IsNullOrEmpty(comment) && comment.Length > 500)
                {
                    errMsg = "备注不能超过500个字符";
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                //获取用户基本信息
                string unionId = string.Empty;
                if (!TokenMana.GetUnionId(openId, out unionId, out errMsg))
                {
                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                }

                #endregion

                //开启EF事务
                using (TransactionScope ts = new TransactionScope())
                {
                    try
                    {
                        IBase_MerchantInfoService base_MerchantInfoService = BLLContainer.Resolve <IBase_MerchantInfoService>();
                        if (base_MerchantInfoService.GetCount(p => !p.MerchID.Equals(merchId) && p.MerchAccount.Equals(merchAccount, StringComparison.OrdinalIgnoreCase)) > 0)
                        {
                            errMsg = "该商户账号名称已存在";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        var base_MerchantInfo = base_MerchantInfoService.GetModels(p => p.MerchID.Equals(merchId)).FirstOrDefault();
                        base_MerchantInfo.MerchType        = Convert.ToInt32(merchType);
                        base_MerchantInfo.MerchStatus      = Convert.ToInt32(merchStatus);
                        base_MerchantInfo.MerchAccount     = merchAccount;
                        base_MerchantInfo.MerchName        = merchName;
                        base_MerchantInfo.Mobil            = mobil;
                        base_MerchantInfo.WxOpenID         = openId;
                        base_MerchantInfo.WxUnionID        = unionId;
                        base_MerchantInfo.AllowCreateSub   = !string.IsNullOrEmpty(allowCreateSub) ? Convert.ToInt32(allowCreateSub) : default(int?);
                        base_MerchantInfo.AllowCreateCount = !string.IsNullOrEmpty(allowCreateCount) ? Convert.ToInt32(allowCreateCount) : default(int?);
                        base_MerchantInfo.CreateUserID     = createUserId;
                        base_MerchantInfo.CreateType       = (logType == (int)RoleType.XcUser || logType == (int)RoleType.XcAdmin) ? (int)CreateType.Xc : (logType == (int)RoleType.MerchUser ? (int)CreateType.Agent : 0);
                        base_MerchantInfo.Comment          = comment;
                        base_MerchantInfo.MerchTag         = Convert.ToInt32(merchTag);

                        if (!base_MerchantInfoService.Update(base_MerchantInfo))
                        {
                            errMsg = "修改商户信息失败";
                            return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                        }

                        IBase_UserInfoService base_UserInfoService = BLLContainer.Resolve <IBase_UserInfoService>();
                        var base_UserInfo = base_UserInfoService.GetModels(p => p.OpenID.Equals(openId, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
                        if (base_UserInfo == null)
                        {
                            base_UserInfo          = new Base_UserInfo();
                            base_UserInfo.OpenID   = openId;
                            base_UserInfo.UserType = Convert.ToInt32(merchType);
                            if (!base_UserInfoService.Add(base_UserInfo))
                            {
                                errMsg = "添加商户负责人信息失败";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }
                        }

                        if (merchFunction != null && merchFunction.Count() >= 0)
                        {
                            //先删除已有数据,后添加
                            var dbContext = DbContextFactory.CreateByModelNamespace(typeof(Base_MerchFunction).Namespace);
                            var base_MerchFunctionList = dbContext.Set <Base_MerchFunction>().Where(p => p.MerchID.Equals(merchId, StringComparison.OrdinalIgnoreCase)).ToList();
                            foreach (var base_MerchFunction in base_MerchFunctionList)
                            {
                                dbContext.Entry(base_MerchFunction).State = EntityState.Deleted;
                            }


                            foreach (IDictionary <string, object> el in merchFunction)
                            {
                                if (el != null)
                                {
                                    var    dicPara    = new Dictionary <string, object>(el, StringComparer.OrdinalIgnoreCase);
                                    string functionId = dicPara.ContainsKey("functionId") ? dicPara["functionId"].ToString() : string.Empty;
                                    string functionEn = dicPara.ContainsKey("functionEn") ? dicPara["functionEn"].ToString() : string.Empty;
                                    if (string.IsNullOrEmpty(functionId))
                                    {
                                        errMsg = "功能编号不能为空";
                                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                                    }
                                    if (!Utils.isNumber(functionId))
                                    {
                                        errMsg = "功能编号不是Int类型";
                                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                                    }
                                    if (!string.IsNullOrEmpty(functionEn) && !Utils.isNumber(functionEn))
                                    {
                                        errMsg = "功能启停不是Int类型";
                                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                                    }
                                    var base_MerchFunction = new Base_MerchFunction();
                                    base_MerchFunction.MerchID                = merchId;
                                    base_MerchFunction.FunctionID             = Convert.ToInt32(functionId);
                                    base_MerchFunction.FunctionEN             = !string.IsNullOrEmpty(functionEn) ? Convert.ToInt32(functionEn) : default(int?);
                                    dbContext.Entry(base_MerchFunction).State = EntityState.Added;
                                }
                                else
                                {
                                    errMsg = "提交数据包含空对象";
                                    return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                                }
                            }

                            if (dbContext.SaveChanges() < 0)
                            {
                                errMsg = "保存商户功能菜单信息失败";
                                return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                            }
                        }

                        ts.Complete();
                    }
                    catch (Exception ex)
                    {
                        errMsg = ex.Message;
                        return(ResponseModelFactory.CreateFailModel(isSignKeyReturn, errMsg));
                    }
                }

                //更新缓存
                MerchBusiness.Init();

                return(ResponseModelFactory.CreateSuccessModel(isSignKeyReturn));
            }
            catch (Exception e)
            {
                return(ResponseModelFactory.CreateReturnModel(isSignKeyReturn, Return_Code.F, e.Message));
            }
        }