/// <summary> /// 添加一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > AddAsync(ErpShops parm) { var res = new ApiResult <string>() { data = "1", statusCode = 200 }; try { //判断登录账号和店铺名是否存在 var isExt = ErpShopsDb.IsAny(m => m.LoginName == parm.LoginName && m.ShopName == parm.ShopName); if (isExt) { res.statusCode = (int)ApiEnum.ParameterError; res.message = "该商铺已存在~"; } else { parm.LoginPwd = DES3Encrypt.EncryptString(parm.LoginPwd); parm.Guid = Guid.NewGuid().ToString(); var dbres = ErpShopsDb.Insert(parm); if (!dbres) { res.statusCode = (int)ApiEnum.Error; res.message = "插入数据失败~"; } } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }
/// <summary> /// 根据账号密码登录 /// </summary> /// <returns></returns> public async Task <ApiResult <ShopBasicDto> > LoginAsync(StaffLoginDto parm) { var res = new ApiResult <ShopBasicDto> { statusCode = (int)ApiEnum.ParameterError }; //先查询员工账号是否可以登录,如果可以,根据员工的归属加盟商,在查询对应的加盟商 var staffModel = ErpStaffDb.GetSingle(m => m.LoginName == parm.loginName); if (staffModel == null) { res.message = "登录账号错误"; return(await Task.Run(() => res)); } //判断密码 parm.loginPwd = DES3Encrypt.EncryptString(parm.loginPwd); if (staffModel.LoginPwd != parm.loginPwd) { res.message = "密码错误"; return(await Task.Run(() => res)); } if (staffModel.Status != 0) { res.message = "账号被冻结,请联系管理员"; return(await Task.Run(() => res)); } //根据商铺ID查询店铺信息,以及修改账号登录信息 staffModel.LoginCount += 1; staffModel.LastLoginDate = DateTime.Now; staffModel.UpLoginDate = staffModel.LastLoginDate; staffModel.IsDevice = parm.isDevice; staffModel.DeviceName = parm.deviceName; staffModel.Token = parm.token; //修改员工信息 ErpStaffDb.Update(staffModel); //根据员工的关联的加盟商ID,查询加盟商信息 var shopModel = ErpShopsDb.GetSingle(m => m.Guid == staffModel.ShopGuid); if (shopModel == null) { res.message = "店铺不存在!"; return(await Task.Run(() => res)); } res.statusCode = (int)ApiEnum.Status; res.data = new ShopBasicDto() { StaffGuid = staffModel.Guid, ShopGuid = shopModel.Guid, ShopName = shopModel.ShopName, AdminName = staffModel.TrueName, Mobile = staffModel.Mobile }; return(await Task.Run(() => res)); }
/// <summary> /// 获得一条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <ErpShops> > GetByGuidAsync(string parm) { var model = ErpShopsDb.GetById(parm); var res = new ApiResult <ErpShops> { statusCode = 200, data = model ?? new ErpShops() { } }; return(await Task.Run(() => res)); }
/// <summary> /// 删除一条或多条数据 /// </summary> /// <returns></returns> public async Task <ApiResult <string> > DeleteAsync(string parm) { var res = new ApiResult <string>() { data = "1", statusCode = 200 }; try { var list = Utils.StrToListString(parm); var dbres = ErpShopsDb.Delete(m => list.Contains(m.Guid)); if (!dbres) { res.statusCode = (int)ApiEnum.Error; res.message = "删除数据失败~"; } } catch (Exception ex) { res.statusCode = (int)ApiEnum.Error; res.message = ApiEnum.Error.GetEnumText() + ex.Message; } return(await Task.Run(() => res)); }