NopCommerce 4.2 之微信小程序

摘要:
//////调用接口自动签到,并返回签到结果//////[Route("index")][APIFilter(true,true)]publicAPIResultindex(){//设置为驼峰命名(即将实体全部首字母小写处理)varserializerSettings=newJsonSerializerSe
        /// <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)), "");



        }

免责声明:文章转载自《NopCommerce 4.2 之微信小程序》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇Access和SQLServer的差距httprunner安装下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

随便看看

SpringBoot项目中@Async方法没有执行的问题分析

现象:1.明显的现象:在日志文件中找不到方法中的日志输出,并且没有错误报告(即,未执行@Async标记的方法,也没有错误报告)。2.分析现象:日志中某段时间后没有任务xxx线程的日志原因:@Async异步方法默认使用Spring创建ThreadPoolTaskExecutor(参考TaskExecutionAutoConfiguration),其中默认核心线...

element ui设置表格表头高度和每一行的高度

.el-table__headertr,.el-table__headerth{padding:0;height:30px;line-height:30px;}.el-table__bodytr,.el-table__bodytd{padding:0;height:30px;line-height:30px;}...

Uni-app v-on监听事件

使用标记上的v-on监视事件。缩写为@click common click events方法:方法:{Focus(){console.log;},blur(){console.log;},confirm(){console.log;},click(){console.log;},tap(){console.log;},longpress(){console....

CUPS

杯子:一个。工具1.hal设备管理器2.系统配置打印机3.Web管理器/etc/cups/ccups。conf/etc/cups/printer conf II。打印机本地安装和客户端安装1.在本地安装Linux打印机时,应选择postscript和pcl打印机。如果没有,则应将打印机设置为原始打印模式/etc/cups/printers。有限公司...

C#实现WebSocket协议客户端和服务器websocket sharp组件实例解析

接下来,我们将介绍websocket组件websocket sharp的相关内容。Websocket sharp是一个单组件dllWebsocket sharp是用MonoDevelop开发的。因此,建立它的一个简单方法是打开websocket sharp Sln,并使用MonoDevelop中的任何构建配置来运行websocket sharp项目的构建。W...

chrome浏览器更换favicon.ico后不更新缓存解决方案

Chrome浏览器在替换favicon.ico后不会更新缓存1。按ctrl+F5强制刷新或右键单击网页重新加载。...