Esempio n. 1
0
        /// <summary>
        /// 根据银行美容记录查询服务码详情
        /// </summary>
        /// <param name="records"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <ServiceCodeDetail> > SearchBankMRActivityCodeDetailByRecords(IEnumerable <BankMRActivityCodeRecord> records)
        {
            var result = new List <ServiceCodeDetail>();

            if (records != null)
            {
                records = records.Where(s => !string.IsNullOrEmpty(s.ServiceCode));
                var roundIds = records.Select(t => t.ActivityRoundId).Distinct();
                var rounds   = new List <BankMRActivityRoundConfig>();
                foreach (var item in roundIds)
                {
                    var round = GetBankMRActivityRoundConfigByPKID(item);
                    if (round != null)
                    {
                        rounds.Add(round);
                    }
                }
                var activityIds = rounds.Select(t => t.ActivityId).Distinct();
                var activitys   = new List <BankMRActivityConfig>();
                foreach (var item in activityIds)
                {
                    var activity = TuhuGrouponDbScopeManagerReadOnly.Execute(conn => BankMRActivityDal.SelectBankMRActivityConfigByActivityId(conn, item));
                    activitys.Add(activity);
                }
                var serviceCodes       = records.Select(t => t.ServiceCode).Distinct();
                var serviceCodeDetails = await SearchCodeManager.GetServiceCodeDetailsByCodes(serviceCodes);

                var companyUsers = new List <SYS_CompanyUser>();
                var bankIds      = activitys.Select(t => t.BankId).Distinct();
                using (var client = new UserAccountClient())
                {
                    foreach (var item in bankIds)
                    {
                        var serviceResult = await client.SelectCompanyUserInfoAsync(item);

                        serviceResult.ThrowIfException(true);
                        var company = serviceResult.Result;
                        if (company != null)
                        {
                            companyUsers.Add(company);
                        }
                    }
                }
                var products = new List <BeautyProductModel>();
                foreach (var pid in activitys.Select(t => t.ServiceId).Distinct())
                {
                    var product = BeautyProductManager.GetBeautyProductByPid(pid);
                    if (product != null)
                    {
                        products.Add(product);
                    }
                }
                foreach (var re in records)
                {
                    var activityId = (rounds.FirstOrDefault(s => s.PKID == re.ActivityRoundId))?.ActivityId;
                    if (activityId != null)
                    {
                        var activity = activitys.FirstOrDefault(s => s.ActivityId == activityId);
                        if (activity != null && serviceCodeDetails != null)
                        {
                            var serviceCodeDetail = serviceCodeDetails.FirstOrDefault(s => string.Equals(s.Code, re.ServiceCode));
                            var product           = products.First(p => string.Equals(p.PID, activity.ServiceId));
                            if (serviceCodeDetail != null)
                            {
                                result.Add(
                                    new ServiceCodeDetail()
                                {
                                    //PackageDetailCodeId = packageDetailCode.PKID,
                                    ServiceCode        = re.ServiceCode,
                                    Status             = serviceCodeDetail?.Status.ToString(),
                                    VipCompanyName     = companyUsers.FirstOrDefault(t => t.UserId == activity.BankId)?.UserName,
                                    VerifyTime         = serviceCodeDetail?.VerifyTime,
                                    StartTime          = re.CreateTime,
                                    EndTime            = Convert.ToDateTime(serviceCodeDetail.OverdueTime),
                                    VipSettleMentPrice = activity.BankSettlementPrice,
                                    ShopCommission     = 0,
                                    PID             = activity.ServiceId,
                                    RestrictVehicle = BeautyProductManager.GetVehicleTypeDescription(product.RestrictVehicleType),
                                    Mobile          = re.Mobile,
                                    OrderNo         = !string.IsNullOrEmpty(serviceCodeDetail?.TuhuOrderId.ToString()) ? $"TH{serviceCodeDetail?.TuhuOrderId}" : null,
                                    VerifyShop      = serviceCodeDetail?.InstallShopId.ToString()
                                });
                            }
                        }
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// 根据服务码获取服务码详情信息,没有用户信息
        /// </summary>
        /// <param name="serviceCodes"></param>
        /// <returns></returns>
        public static async Task <IEnumerable <ServiceCodeDetail> > GetServiceCodeDetail(IEnumerable <string> serviceCodes)
        {
            IEnumerable <ServiceCodeDetail> result = null;

            if (serviceCodes != null && serviceCodes.Any())
            {
                var packageDetailCodes = GetBeautyServicePackageDetailCodesByCodes(serviceCodes);
                var serviceCodeDetails = await GetServiceCodeDetailsByCodes(serviceCodes);

                if (packageDetailCodes != null && serviceCodeDetails != null && serviceCodeDetails.Any())
                {
                    var packageDetailIds = packageDetailCodes.Select(t => t.PackageDetailId).Distinct();
                    var packageDetails   = BeautyServicePackageManager.GetBeautyServicePackageDetails(packageDetailIds);
                    if (packageDetails != null)
                    {
                        var pids     = packageDetails.Select(t => t.PID).Distinct();
                        var products = new List <BeautyProductModel>();
                        foreach (var pid in pids)
                        {
                            var product = BeautyProductManager.GetBeautyProductByPid(pid);
                            if (product != null)
                            {
                                products.Add(product);
                            }
                        }

                        result = serviceCodeDetails.Select(t =>
                        {
                            var packageDetailCode = packageDetailCodes.FirstOrDefault(h => string.Equals(h.ServiceCode, t.Code));
                            if (packageDetailCode != null)
                            {
                                var packageDetailId = packageDetailCode.PackageDetailId;
                                var packageDetail   = packageDetails.FirstOrDefault(d => d.PKID == packageDetailId);
                                if (packageDetail != null && products.Any())
                                {
                                    var bankManger    = new BankMRManager();
                                    var cooperateUser = bankManger.FetchMrCooperateUserConfigByPKID(packageDetail.CooperateId);
                                    var product       = products.FirstOrDefault(p => string.Equals(p.PID, packageDetail.PID));
                                    if (product != null)
                                    {
                                        return(new ServiceCodeDetail()
                                        {
                                            PackageDetailCodeId = packageDetailCode.PKID,
                                            BatchCode = string.IsNullOrEmpty(packageDetailCode.ImportBatchCode) ? packageDetailCode.PackageDetailId.ToString() :
                                                        packageDetailCode.ImportBatchCode,
                                            ServiceCode = t.Code,
                                            Status = string.Equals(t.Source, "VOLRevert") ? "Reverted" : t.Status.ToString(),
                                            VipCompanyName = cooperateUser?.CooperateName,
                                            VerifyTime = t.VerifyTime,
                                            StartTime = packageDetailCode.StartTime,
                                            EndTime = packageDetailCode.EndTime,
                                            VipSettleMentPrice = packageDetail.VipSettlementPrice,
                                            ShopCommission = packageDetail.ShopCommission,
                                            PID = packageDetail.PID,
                                            RestrictVehicle = BeautyProductManager.GetVehicleTypeDescription(product.RestrictVehicleType),
                                            OrderNo = t.TuhuOrderId > 0 ? $"TH{t.TuhuOrderId}" : null,
                                            VerifyShop = t.InstallShopId?.ToString(),
                                            Type = packageDetail.IsImportUser? "ImportUser": "******"
                                        });
                                    }
                                    else
                                    {
                                        return(new ServiceCodeDetail());
                                    }
                                }
                                else
                                {
                                    return(new ServiceCodeDetail());
                                }
                            }
                            else
                            {
                                return(new ServiceCodeDetail());
                            }
                        }).Where(s => !string.IsNullOrWhiteSpace(s.ServiceCode)).ToList();
                    }
                }
            }

            return(result);
        }