zoukankan      html  css  js  c++  java
  • NopCommerce 4.2 之微信小程序

            /// <summary>
            /// 调用接口自动签到,并返回签到结果
            /// </summary>
            /// <returns></returns>
            [Route("index")]
            [APIFilter(true, true)]
            public APIResult<object> index()
            {
                //设置为驼峰命名(即将实体全部首字母小写处理)
                var serializerSettings = new JsonSerializerSettings
                {
                    ContractResolver = new CamelCasePropertyNamesContractResolver()
                };
    
                SignInDetailModel model = new SignInDetailModel();
                //配置信息需要传递
                model.Config = new SignInDetailModel.ConfigModel()
                {
                    DayIntegral = _customerSignInSettings.DayIntegral,
                    DurationReward = _customerSignInSettings.DurationReward,
                    DurationCycle = _customerSignInSettings.DurationCycle,
                    IsEnable = _customerSignInSettings.IsEnable
                };
                if (model.Config.IsEnable)
                {
                    return Success(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(model, Formatting.None, serializerSettings)), "");
                }
    
                model.IsCurSign = false;
                var signday = false;//是否当天签到
                if (CanSignInByToday(_workContext.CurrentCustomer.Id))
                {
                    //签到
                    var signinfo = GetCustomerSignIn(_workContext.CurrentCustomer.Id);
                    DateTime oldlastsigntime = signinfo.LastSignTime.HasValue? signinfo.LastSignTime.Value:DateTime.UtcNow.AddYears(-1);//给一个默认的时间点(这里就给一个一年前的时间点)
                    signinfo.LastSignTime = DateTime.UtcNow;
                    signinfo.SignDaySum += 1;//签到的次数(单纯统计使用)
                    //处理积分
                    int needAddIntegral = _customerSignInSettings.DayIntegral;  //需要增加的各分
                    bool isReward = false;
    
    
                    //连续登录
                    if (oldlastsigntime.Date == (DateTime.UtcNow.AddDays(-1).Date))
                    {
                        //连续签到
                        signinfo.DurationDaySum += 1;
    
                        if (_customerSignInSettings.DurationCycle > 0)
                        {
                            signinfo.DurationDay += 1;
                            if (signinfo.DurationDay > _customerSignInSettings.DurationCycle)
                            {
                          
                                signinfo.DurationDay = 1;
                            }
                        
                            if (signinfo.DurationDay == _customerSignInSettings.DurationCycle)
                            {
                                needAddIntegral += _customerSignInSettings.DurationReward;
                                isReward = true;
                            }
                        }
                        else
                        {
                            signinfo.DurationDay = 1;
                        }
                    }
                    else
                    {
                        //没有连续签到,从一天开始签到
                        signinfo.DurationDay = 1;
                        signinfo.DurationDaySum = 1;
                    }
                    //签到送积分
                    if (_rewardPointsSettings.Enabled)
                    {
                        var rewardPoints = needAddIntegral;
                        var customer = _customerService.GetCustomerById(_workContext.CurrentCustomer.Id);
                        _rewardPointService.AddRewardPointsHistoryEntry(customer, rewardPoints, _storeContext.CurrentStore.Id,
                        _localizationService.GetResource("RewardPoints.Message.PointsForCustomerSignIn"));
                    }
    
                    //当前签到
                    signday = true;
    
                }
                //当天签到
                if (signday)
                {
                    model.IsCurSign = true;
                }
               
                var customerSigninfo = GetCustomerSignIn(_workContext.CurrentCustomer.Id);
                model.CurSignDurationDay = customerSigninfo.DurationDay;
                model.CurSignDaySum = customerSigninfo.SignDaySum;
                //用户信息
                model.CustomerId = _workContext.CurrentCustomer.Id;
                model.CustomerName = _workContext.CurrentCustomer.Username;
                //获取当前用户的可用积分
                int rewardPointsBalance = _rewardPointService.GetRewardPointsBalance(_workContext.CurrentCustomer.Id, _storeContext.CurrentStore.Id);
                decimal rewardPointsAmountBase = _orderTotalCalculationService.ConvertRewardPointsToAmount(rewardPointsBalance);//将积分转换为价值
                decimal rewardPointsAmount = _currencyService.ConvertFromPrimaryStoreCurrency(rewardPointsAmountBase, _workContext.WorkingCurrency);
                model.RewardPointsBalance = rewardPointsBalance;//
                model.RewardPointsAmount = _priceFormatter.FormatPrice(rewardPointsAmount, true, false);//价值格式化为本地货币
    
                return Success(JsonConvert.DeserializeObject(JsonConvert.SerializeObject(model, Formatting.None, serializerSettings)), "");
    
    
    
            }
    
  • 相关阅读:
    DeepLearning.ai学习笔记(二)改善深层神经网络:超参数调试、正则化以及优化--Week2优化算法
    DeepLearning.ai学习笔记(二)改善深层神经网络:超参数调试、正则化以及优化--Week1深度学习的实用层面
    通俗理解决策树中的熵&条件熵&信息增益
    KNN实现手写数字识别
    softmax分类算法原理(用python实现)
    DeepLearning.ai学习笔记(一)神经网络和深度学习--Week4深层神经网络
    博客园自定义皮肤扁平化设计
    神经网络权重初始化问题
    OpenVirteX 安装
    从个人的角度谈谈本次GNTC大会的收获
  • 原文地址:https://www.cnblogs.com/chenyuxi/p/11952852.html
Copyright © 2011-2022 走看看