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)), "");

        }

原文地址:https://www.cnblogs.com/chenyuxi/p/11952852.html

时间: 2024-08-30 02:47:25

NopCommerce 4.2 之微信小程序 - 每日签到功能的相关文章

微信小程序开发-蓝牙功能开发

0. 前言 这两天刚好了解了一下微信小程序的蓝牙功能.主要用于配网功能.发现微信的小程序蓝牙API已经封装的很好了.编程起来很方便.什么蓝牙知识都不懂的情况下,不到两天就晚上数据的收发了,剩下的就是数据帧格式的定义,当然这部分就不是本次博客的重点.1. 准备硬件 这里我准备了CH341SER这个作为USB转串口.用sscom5.13.1 串口工具.由于我不太懂硬件开发.硬件部分都是由公司其他人开发的.我只是负责把环境搭建起来.然后负责我的微信小程序开发. 2. 开发小程序简单讲解 onLoad

一号旺铺微信小程序三大新功能:可相互跳转、批量管理门店

可相互跳转.批量管理门店,小程序是抓住零售新机会的一把利器吗?一号旺铺专业.专注开发小程序,就微信小程序的三个功能与大家分享. 同一个公众号下关联的 10 个同主体小程序和 3 个非同主体小程序之间,可以调用接口直接相互跳转. 微信小程序新动向:可相互跳转.批量管理门店 可相互跳转.批量管理门店,小程序是抓住零售新机会的一把利器吗? 小程序到底能不能抓住零售新机会,成效还在验证中.不过为了实现这一目标,小程序又释放了一个重大功能. 6 月 21 日深夜,微信官方表示,与同一公众号关联的小程序之间

微信小程序实现支付功能

小程序支付,没有封装支付代码:直接上一段可用的流程代码吧:微信小程序支付官网文档有详细的说明,这里我就不再赘述啦:客户端js: wx.request({ url:'https://www.xxxx.com/api/payfee.php',//改成你自己的链接 header:{ 'Content-Type':'application/x-www-form-urlencoded' }, method:'POST', success:function(res){ console.log(res.dat

微信小程序人脸识别功能

本文档以微信小程序为例,微信小程序开发人脸核身功能需要两个申请:腾讯云申请人脸识别服务和小程序申请人脸识别服务(注意:只有符合以下条件的机构才能在小程序端申请) 政务:政府机构或事业单位金融:银行.保险医疗:公立医疗机构运营商:电信运营商教育:公立教育机构交通:航空.客运.网约车.交通卡.共享交通.轨道交通.租车旅游:酒店物流:快递.邮政.物流 主要参考文档: 1.腾讯云人脸核身文档 :https://cloud.tencent.com/product/faceid/developer 2.腾讯

微信小程序 五星评价功能

要实现的效果:点击到第几颗星,就要显示到第几颗星,///////////////// 接下来直接查看源码: <view class="l-evalbox row"> <text class="l-evaltxt">满意度:</text> <view class="l-evalist flex-1" bindtap="chooseicon"> <icon class=&quo

微信小程序评论/留言功能,附:前端+后端代码+视频讲解!

前端界面: 演示: <!-- 表单 --> <form bindsubmit="formSubmit"> <input type="text" name="liuyantext" placeholder='输入留言内容' class="input-style"/> <button formType="submit" class="btn" wx:

微信小程序源码下载(200多个)

微信小程序源码下载汇总,点击标题进入对应的微信小程序下载页面. 最新 demo源码(点击标题进入帖子下载) 描述 1 微信小程序 会议室预定小程序 微信小程序 会议室预定小程序**** 本内容被作者隐藏 **** 2 微信小程序-双人五子棋小游戏 微信小程序-双人五子棋小游戏**** 本内容被作者隐藏 **** 3 打卡签到小程序 用微信小程序实现的一个简单的打卡签到的小程序拒绝 4 微信小程序---左滑删除 微信小程序---左滑删除**** 本内容被作者隐藏 **** 5 一个借钱的记事本的微

微信小程序小应用资源汇总整理

微信小应用资源汇总整理 开源项目 WeApp - 微信小程序版的微信 wechat-weapp-redux-todos - 微信小程序集成Redux实现的Todo list wechat-weapp-gank - 微信小程序版Gank客户端 wechat-dribbble - 微信小程序-Dribbble wechatApp-demo - 微信小程序 DEMO weapp-ide-crack - 微信小应用资源破解 API - API 文档 weapp-quick - 微信小应用示例代码 wea

微信小程序(应用号)开发资源汇总整理 - 一直更新中

开源项目 wechat-weapp-gank - 微信小程序版Gank客户端 wechat-dribbble - 微信小程序-Dribbble wechatApp-demo - 微信小程序 DEMO weapp-ide-crack - 微信小应用资源破解 API - API 文档 weapp-quick - 微信小应用示例代码 weapp-gold - 掘金主页 微信小应用示例 weapp-douban - 豆瓣电影 微信小程序 wechat-app-zhihudaily - 微信小程序版的知乎