public async Task <APIResultDto> SubmitShopEvaluationAsync(ShopEvaluation input) { //新增评价 var result = input.MapTo <ShopEvaluation>(); result.Id = Guid.NewGuid(); await _shopevaluationRepository.InsertAsync(result); //修改店铺评价 var shopEntity = _shopRepository.GetAll().Where(s => s.Id == input.ShopId).FirstOrDefault(); var evaluationIds = shopEntity.Evaluation.Split(','); int[] intEvaluationIds = Array.ConvertAll <string, int>(evaluationIds, s => int.Parse(s)); if (input.Evaluation == ScoreLevelEmun.好) { intEvaluationIds[0]++; } else if (input.Evaluation == ScoreLevelEmun.中) { intEvaluationIds[1]++; } else { intEvaluationIds[2]++; } string evaluation = intEvaluationIds[0].ToString() + ',' + intEvaluationIds[1].ToString() + ',' + intEvaluationIds[2].ToString(); shopEntity.Evaluation = evaluation; await _shopRepository.UpdateAsync(shopEntity); //更新购买记录 var record = _purchaserecordRepository.GetAll().Where(pr => pr.Id == input.PurchaseRecordId).FirstOrDefault(); record.IsEvaluation = true; await _purchaserecordRepository.UpdateAsync(record); //新增积分详情 var config = await GetIntegralConfig(input.TenantId); var user = await _wechatuserRepository.GetAll().Where(u => u.OpenId == input.OpenId).FirstOrDefaultAsync(); var intDetail = new IntegralDetail(); intDetail.InitialIntegral = user.IntegralTotal; intDetail.Integral = int.Parse(config); intDetail.FinalIntegral = user.IntegralTotal + intDetail.Integral; intDetail.OpenId = user.OpenId; intDetail.RefId = result.Id.ToString(); intDetail.TenantId = input.TenantId; intDetail.Type = IntegralTypeEnum.评价店铺赠送; intDetail.Desc = "评价店铺赠送"; await _integraldetailRepository.InsertAsync(intDetail); //更新用户总积分 user.IntegralTotal = intDetail.FinalIntegral.Value; await _wechatuserRepository.UpdateAsync(user); return(new APIResultDto() { Code = 0, Msg = "提交成功,您的评价已生效" }); }
public async Task <APIResultDto> ExchangeIntegralAsync(ExchangeIntegralDto input) { using (CurrentUnitOfWork.SetTenantId(input.TenantId)) { //获取积分配置 var config = await GetIntegralConfig(input.TenantId); int? xintegral = 0; //消费者获得积分 int? rintegral = 0; //零售客户获得积分 string refIds = string.Empty; foreach (var item in input.ShopProductList) { //购买记录 var purchaseRecord = input.MapTo <PurchaseRecord>(); purchaseRecord.Integral = (int)(item.Price * item.Num * config[DeployCodeEnum.商品购买]); purchaseRecord.Quantity = item.Num; purchaseRecord.ProductId = item.Id; purchaseRecord.Specification = item.Specification; purchaseRecord.Remark = string.Format("数量{0}*指导零售价{1}*兑换比例{2}=积分{3}", item.Num, item.Price, config[DeployCodeEnum.商品购买], purchaseRecord.Integral); await _purchaserecordRepository.InsertAsync(purchaseRecord); await CurrentUnitOfWork.SaveChangesAsync(); refIds += purchaseRecord.Id.ToString() + ","; xintegral += purchaseRecord.Integral; rintegral += ((int)(item.Price * item.Num * config[DeployCodeEnum.店铺扫码兑换])); } if (refIds.Length > 0) { refIds = refIds.Substring(0, refIds.Length - 1); } //更新消费者总积分 和 积分明细 if (xintegral > 0) { var user = await _weChatUserRepository.GetAll().Where(u => u.OpenId == input.OpenId).FirstOrDefaultAsync(); var intDetail = new IntegralDetail(); intDetail.InitialIntegral = user.IntegralTotal; intDetail.Integral = xintegral; intDetail.FinalIntegral = user.IntegralTotal + xintegral; intDetail.OpenId = user.OpenId; intDetail.RefId = refIds; intDetail.TenantId = input.TenantId; intDetail.Type = IntegralTypeEnum.购买商品兑换; intDetail.Desc = "店铺购买商品兑换"; await _integralDetailRepository.InsertAsync(intDetail); //await CurrentUnitOfWork.SaveChangesAsync(); user.IntegralTotal = intDetail.FinalIntegral.Value; await _weChatUserRepository.UpdateAsync(user); //发送微信模板通知-消费者 await PurchaseSendWXMesssageToCust(user.OpenId, input.host, user.MemberBarCode, intDetail.FinalIntegral, intDetail.Integral); } //更新店铺管理员总积分 和 积分明细 if (rintegral > 0) { //获取零售客户 店铺管理员 var shopKeeper = await _weChatUserRepository.GetAll().Where(w => w.UserId == input.RetailerId && w.UserType == UserTypeEnum.零售客户 && w.IsShopkeeper == true).FirstOrDefaultAsync(); if (shopKeeper != null) { var intDetail = new IntegralDetail(); intDetail.InitialIntegral = shopKeeper.IntegralTotal; intDetail.Integral = rintegral; intDetail.FinalIntegral = shopKeeper.IntegralTotal + rintegral; intDetail.OpenId = shopKeeper.OpenId; intDetail.RefId = refIds; intDetail.TenantId = input.TenantId; intDetail.Type = IntegralTypeEnum.扫码积分赠送; intDetail.Desc = "店铺消费者购买商品赠送"; await _integralDetailRepository.InsertAsync(intDetail); shopKeeper.IntegralTotal = intDetail.FinalIntegral.Value; await _weChatUserRepository.UpdateAsync(shopKeeper); //发送微信模板通知-店铺管理员 await PurchaseSendWXMesssageToShopKeeper(shopKeeper.OpenId, input.host, shopKeeper.MemberBarCode, intDetail.FinalIntegral, intDetail.Integral); } } //更新店铺销量 var shop = await _shopRepository.GetAsync(input.ShopId.Value); shop.ReadTotal++; //人气增加 await AddSingleTotalAsync(input.OpenId, input.ShopId); // 店铺人气查重改写 shop.SaleTotal++; //销量增加 await _shopRepository.UpdateAsync(shop); //发送积分微信通知 APIResultDto result = new APIResultDto(); result.Code = 0; result.Msg = "积分兑换成功"; result.Data = new { RetailerIntegral = rintegral, UserIntegral = xintegral }; return(result); } }