diff --git a/app/api/mobile/entities/blog_comment.rb b/app/api/mobile/entities/blog_comment.rb index cd7902097..3f58e901f 100644 --- a/app/api/mobile/entities/blog_comment.rb +++ b/app/api/mobile/entities/blog_comment.rb @@ -75,14 +75,27 @@ module Mobile has_praise end + expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| + parents_reply = [] + parents_reply = get_reply_parents_no_root(parents_reply, instance) + parents_reply.count + end + expose :parents_reply_bottom, using:Mobile::Entities::BlogComment do |c,opt| if c.is_a? (::BlogComment) #取二级回复的底楼层 - if (opt[:type] == 1 && !opt[:bottom]) - opt[:bottom] = true - parents_reply = [] - parents_reply = c.parent.nil? ? [] : parents_reply << c.parent #get_reply_parents_no_root(parents_reply, c)[0] - parents_reply + parents_reply = [] + parents_reply = get_reply_parents_no_root(parents_reply, c) + if parents_reply.count > 0 && !opt[:bottom] + if opt[:type] == 1 + # opt[:bottom] = true + # parents_reply[opt[:page]..opt[:page]] + else + opt[:bottom] = true + parents_reply[0..0] + end + else + [] end end end @@ -90,26 +103,34 @@ module Mobile expose :parents_reply_top, using:Mobile::Entities::BlogComment do |c,opt| if c.is_a? (::BlogComment) #取二级回复的顶楼层 - if (opt[:type] == 1 && !opt[:top]) - opt[:top] = true + parents_reply = [] + parents_reply = get_reply_parents_no_root(parents_reply, c) + if parents_reply.count > 0 && !opt[:top] + if opt[:type] == 1 + opt[:bottom] = true + tStart = (opt[:page]-1)*5+2 + tEnd = (opt[:page])*5+2 - 1 - parents_reply = [] - parents_reply = get_reply_parents_no_root(parents_reply, c) + if tEnd >= parents_reply.count - 1 + tEnd = parents_reply.count - 2 + end - tStart = opt[:page]*2 - tEnd = (opt[:page]+1)*2 - 1 - - parents_reply = parents_reply.reverse[tStart,tEnd] - parents_reply + if tStart <= parents_reply.count - 2 + parents_reply = parents_reply.reverse[tStart..tEnd] + parents_reply.reverse + else + [] + end + else + opt[:top] = true + parents_reply = parents_reply.reverse[0..1] + parents_reply.reverse + end + else + [] end end end - - expose :parents_count, if: lambda { |instance, options| options[:user] } do |instance, options| - parents_reply = [] - parents_reply = get_reply_parents_no_root(parents_reply, instance) - parents_reply.count - end end end end \ No newline at end of file diff --git a/app/controllers/wechats_controller.rb b/app/controllers/wechats_controller.rb index c72e04e14..e596042d9 100644 --- a/app/controllers/wechats_controller.rb +++ b/app/controllers/wechats_controller.rb @@ -221,8 +221,8 @@ class WechatsController < ActionController::Base raise CoursesService::JoinCourseError.message(status[:state]) end - news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!', - content: "课程名称: #{course.name}\n班级名称: #{course.name}\n任课老师: #{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} } + news = (1..1).each_with_object([]) { |n, memo| memo << { title: '恭喜您成功加入班级,开始学习吧!', + content: "课程名称:#{course.name}\n班级名称:#{course.name}\n任课老师:#{course.teacher.show_name}\n进入班级,和小伙伴愉快的学习吧!"} } return request.reply.news(news) do |article, n, index| # article is return object url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=#{Wechat.config.appid}&redirect_uri=#{ROOT_URL+'/wechat/user_activities#/class?id='+course.id.to_s}&response_type=code&scope=snsapi_base&state=myclass#wechat_redirect" pic_url = "#{ROOT_URL}/images/wechat/class.jpg" diff --git a/app/services/syllabuses_service.rb b/app/services/syllabuses_service.rb index d5dec9f88..fcb70653b 100644 --- a/app/services/syllabuses_service.rb +++ b/app/services/syllabuses_service.rb @@ -71,8 +71,8 @@ class SyllabusesService count = ShieldWechatMessage.where("container_type='User' and container_id=#{user.id} and shield_type='Course' and shield_id=#{course.id}").count if count == 0 ws = WechatService.new - title = "恭喜您创建班级成功" - ws.create_class_notice user.id, "create_course_notice", course.id,title, course.name, user.show_name, 0, "点击查看班级详情" + title = "恭喜您创建班级成功。" + ws.create_class_notice user.id, "create_course_notice", course.id,title, course.name, user.show_name, 0, "点击查看班级详情。" end end diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index aabea2532..d18575b94 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -42,11 +42,61 @@