/// <summary> /// 保存备注 /// </summary> public async Task SaveRemarkAsync(WxUserDto dto) { using (var dapper = DapperFactory.Create()) { var item = await dapper.QueryOneAsync <WxUser>(new { Id = dto.Id }); if (item == null) { throw new KuDataNotFoundException("无法取得微信用户数据!"); } item.Remark = dto.Remark; //远程更新备注 //取得微信AccessToken var token = await _wxAccountService.GetAccessToken(item.AccountId); var rsp = await wcUserTool.UpdateUserRemark(token, item.OpenId, item.Remark); if (rsp.ErrCode != 0) { throw new KuArgNullException(rsp.ToString()); } await dapper.UpdateAsync <WxUser>(new { dto.Remark }, new { dto.Id }); } }
/// <summary> /// 保存数据 /// </summary> public async Task SaveAsync(WxQrcodeDto dto) { WxQrcode model = Mapper.Map <WxQrcode>(dto); if (model.Id == 0) { //新增 model.Id = ID.NewID(); model.CreateTime = DateTime.Now; model.IsDeleted = false; //取得新场景值 using (var dapper = DapperFactory.Create()) { var count = await dapper.QueryCountAsync <WxQrcode>(new { model.AccountId, model.PeriodType }); if (model.PeriodType == EmWxPeriodType.Temp) { model.SceneId = 100000 + count + 1; } else { model.SceneId = count + 1; } //取得微信AccessToken var token = await _wxAccountService.GetAccessToken(model.AccountId); //远程创建 if (model.PeriodType == EmWxPeriodType.Temp) { var rsp = await _wcQrcodeTool.CreateTemp(token, model.SceneId, model.ExpireSeconds); if (rsp.ErrCode != 0) { throw new KuArgNullException(rsp.ToString()); } model.Url = rsp.Data.Url; model.Ticket = rsp.Data.Ticket; model.ExpireSeconds = model.ExpireSeconds; } else { var rsp = await _wcQrcodeTool.Create(token, model.SceneId); if (rsp.ErrCode != 0) { throw new KuArgNullException(rsp.ToString()); } model.Url = rsp.Data.Url; model.Ticket = rsp.Data.Ticket; } await dapper.InsertAsync(model); } } else { //更新 using (var dapper = DapperFactory.Create()) { var item = new { //这里进行赋值 model.EventKey, model.Purpose }; await dapper.UpdateAsync <WxQrcode>(item, new { model.Id }); } } }
/// <summary> /// 保存数据 /// </summary> public async Task SaveAsync(WxUserTagDto dto) { WxUserTag model = Mapper.Map <WxUserTag>(dto); if (model.Id == 0) { //新增 model.Id = ID.NewID(); model.Count = 0; model.CreateTime = DateTime.Now; //远程添加 //取得AccessToken var token = await wxAccountService.GetAccessToken(model.AccountId); var rsp = await wcUserTool.CreateUserTag(token, model.Name); if (rsp.ErrCode != 0) { throw new KuDataNotFoundException(rsp.ToString()); } model.TagId = rsp.Data.Tag.Id; using (var dapper = DapperFactory.Create()) { await dapper.InsertAsync(model); } } else { //更新 using (var dapper = DapperFactory.Create()) { var item = await dapper.QueryOneAsync <WxUserTag>(new { model.Id }); if (item == null) { throw new KuDataNotFoundException("无法取得微信用户标签数据!"); } if (item.Name.Equals(model.Name)) { //没有变动 return; } //远程更新 //取得AccessToken var token = await wxAccountService.GetAccessToken(item.AccountId); var rsp = await wcUserTool.UpdateUserTag(token, item.TagId, model.Name); if (rsp.ErrCode != 0) { throw new KuDataNotFoundException(rsp.ToString()); } await dapper.UpdateAsync <WxUserTag>(new { model.Name }, new { model.Id }); } } }