Пример #1
0
        /// <summary>
        /// 如果是新客户的第一张订单,为推荐人增加经验值
        /// </summary>
        /// <param name="soInfo">订单</param>
        /// <param name="customerInfo">订单客户</param>
        public void AddExperienceByRecommend(SOInfo soInfo)
        {
            SOBaseInfo soBaseInfo = soInfo.BaseInfo;

            ECCentral.BizEntity.Customer.CustomerBasicInfo customerInfo = ExternalDomainBroker.GetCustomerInfo(soBaseInfo.CustomerSysNo.Value).BasicInfo;

            string companyCode = soInfo.CompanyCode;

            // 对象为空
            if (customerInfo == null || soInfo == null)
            {
                return;
            }

            // 该客户没有推荐人
            if (!customerInfo.RecommendedByCustomerSysNo.HasValue || customerInfo.RecommendedByCustomerSysNo.Value == 0)
            {
                return;
            }

            // 判断订单是否是该客户的第一张成功出库的订单
            if (!SODA.IsFirstSO(soInfo.SysNo.Value, soBaseInfo.CustomerSysNo.Value))
            {
                return;
            }


            // 获取推荐人信息
            ECCentral.BizEntity.Customer.CustomerBasicInfo rmdCustomerInfo = ExternalDomainBroker.GetCustomerInfo(customerInfo.RecommendedByCustomerSysNo.Value).BasicInfo;

            // 没有相应的推荐人信息
            if (rmdCustomerInfo == null)
            {
                return;
            }

            // 推荐人不能是客户自己
            if (customerInfo.CustomerSysNo == rmdCustomerInfo.CustomerSysNo)
            {
                return;
            }

            // 如果推荐人被禁用,不对其增加经验值
            if (rmdCustomerInfo.Status.Value == BizEntity.Customer.CustomerStatus.InValid)
            {
                return;
            }

            // 订单金额
            decimal soAmount = soBaseInfo.CashPay + soBaseInfo.PayPrice.Value + soBaseInfo.ShipPrice.Value + soBaseInfo.PremiumAmount.Value + soBaseInfo.PromotionAmount.Value;
            // 推荐人经验值的增加数量为订单金额的10%
            decimal rate          = AppSettingHelper.RecommendExperienceRatio;
            decimal addExperience = decimal.Round(soAmount * rate, 0); // 应该增加的经验值,4舍5入到整数

            // 如果增加值<1,
            if (addExperience > 0)
            {
                string logMemo = string.Format("SO#{0}:引荐新用户,首次购物成功,加经验值。", soInfo.SysNo);
                ExternalDomainBroker.AdjustCustomerExperience(rmdCustomerInfo.CustomerSysNo.Value, addExperience, BizEntity.Customer.ExperienceLogType.Recommend, logMemo);
                ObjectFactory <SOSendMessageProcessor> .Instance.RecommendCustomerAddExperienceSendMail(rmdCustomerInfo, customerInfo.CustomerID, addExperience);
            }
        }