/// <summary> /// 解析推广二维码, 获取推广的公众号或小程序的相关信息, 同时二维码访问次数+1 /// </summary> /// <param name="viewModel"></param> /// <returns></returns> public ReturnValueModel AnalyzeAdQRCode(string id) { ReturnValueModel rvm = new ReturnValueModel(); if (string.IsNullOrEmpty(id)) { rvm.Success = false; rvm.Msg = "The parameter 'Id' is required."; return(rvm); } AdQRCode model = _rep.FirstOrDefault <AdQRCode>(s => s.IsDeleted != 1 && s.Id == id); if (model == null) { rvm.Success = false; rvm.Msg = "Invalid Id."; return(rvm); } model.VisitAmount += 1; _rep.Update(model); _rep.SaveChanges(); rvm.Success = true; rvm.Msg = "success"; rvm.Result = new { model.AppName, model.AppUrl, model.BuName }; return(rvm); }
/// <summary> /// 删除推广二维码信息 /// </summary> /// <param name="viewModel"></param> /// <param name="workUser"></param> /// <returns></returns> public ReturnValueModel DeleteAdQRCode(AdQRCode viewModel, WorkUser workUser) { ReturnValueModel rvm = new ReturnValueModel(); if (string.IsNullOrEmpty(viewModel?.Id)) { rvm.Success = false; rvm.Msg = "The parameter 'Id' is required."; return(rvm); } AdQRCode model = _rep.FirstOrDefault <AdQRCode>(s => s.IsDeleted != 1 && s.Id == viewModel.Id); if (model == null) { rvm.Success = false; rvm.Msg = "Invalid Id."; return(rvm); } model.IsDeleted = 1; _rep.Update(model); _rep.SaveChanges(); rvm.Success = true; rvm.Msg = "success"; return(rvm); }
/// <summary> /// 新增或修改推广二维码信息 /// </summary> /// <param name="viewModel"></param> /// <param name="workUser"></param> /// <returns></returns> public ReturnValueModel AddOrUpdateAdQRCode(AdQRCode viewModel, WorkUser workUser) { ReturnValueModel rvm = new ReturnValueModel(); if (viewModel == null) { rvm.Success = false; rvm.Msg = "Invalid parameters."; return(rvm); } //推广二维码中转H5页面地址 string AdQRCodeHandlerPage = ConfigurationManager.AppSettings["AdQRCodeHandlerPage"]; if (!string.IsNullOrEmpty(AdQRCodeHandlerPage)) { if (VirtualPathUtility.IsAppRelative(AdQRCodeHandlerPage)) { Uri requestUri = HttpContext.Current.Request.Url; string host = requestUri.AbsoluteUri.Replace(requestUri.AbsolutePath, ""); AdQRCodeHandlerPage = host + VirtualPathUtility.ToAbsolute(AdQRCodeHandlerPage); } } AdQRCode model = null; if (!string.IsNullOrEmpty(viewModel.Id)) { model = _rep.FirstOrDefault <AdQRCode>(s => s.IsDeleted != 1 && s.Id == viewModel.Id); } bool isNew = model == null; if (isNew) { model = new AdQRCode(); model.Id = Guid.NewGuid().ToString(); string query = "?id=" + model.Id; model.QRCodePicUrl = GenerateQRCode(AdQRCodeHandlerPage + query); model.VisitAmount = 0; model.CreateTime = DateTime.Now; model.CreateUser = workUser.User.Id; } else { model.UpdateTime = DateTime.Now; model.UpdateUser = workUser.User.Id; } model.AppName = viewModel.AppName; model.AppUrl = viewModel.AppUrl; model.BuName = viewModel.BuName; if (isNew) { _rep.Insert(model); } else { _rep.Update(model); } _rep.SaveChanges(); rvm.Success = true; rvm.Msg = "success"; rvm.Result = model; return(rvm); }
public IHttpActionResult DeleteAdQRCode(AdQRCode viewModel) { var ret = _QRCodeService.DeleteAdQRCode(viewModel, WorkUser); return(Ok(ret)); }