From 139a7931ee5b374f0cd25ec2d34b20d5deb49d56 Mon Sep 17 00:00:00 2001 From: txz Date: Thu, 7 Apr 2016 16:39:04 +0800 Subject: [PATCH] =?UTF-8?q?=E7=82=B9=E8=B5=9E=E5=8A=9F=E8=83=BD=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/api/mobile/apis/praise.rb | 15 ++-- public/assets/wechat/activities.html | 28 +++---- public/assets/wechat/blog_detail.html | 4 +- public/assets/wechat/course_discussion.html | 4 +- public/assets/wechat/course_notice.html | 4 +- public/assets/wechat/homework_detail.html | 4 +- public/assets/wechat/issue_detail.html | 4 +- public/assets/wechat/jour_message_detail.html | 4 +- public/assets/wechat/project_discussion.html | 4 +- public/javascripts/wechat/app.js | 74 +++++++++++++++++-- 10 files changed, 103 insertions(+), 42 deletions(-) diff --git a/app/api/mobile/apis/praise.rb b/app/api/mobile/apis/praise.rb index b3bc8f466..57dbd0729 100644 --- a/app/api/mobile/apis/praise.rb +++ b/app/api/mobile/apis/praise.rb @@ -15,20 +15,21 @@ module Mobile obj_id = params[:id] obj_type = params[:type] user = UserWechat.find_by_openid(params[:openid]).user - obj = PraiseTreadCache.find_object_by_type_and_id(obj_id,obj_type) - pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id) - if pts.empty? + pts = PraiseTread.where("praise_tread_object_id=? and praise_tread_object_type=? and user_id=?",obj_id,obj_type.to_s,user.id).first + if pts.blank? praise_or_cancel(obj_type,obj_id,user,1) - num = get_activity_praise_num(obj) + obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first + num = get_activity_praise_num(obj) if !obj.blank? else - pts.delete if !pts.empty? + pts.destroy if !pts.blank? #再更新praise_tread_cache表 使相应的记录减1 当为0时删除 ptc = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first - ptc.praise_minus(1) if !ptc.nil? + ptc.praise_minus(1) if !ptc.blank? if ptc.praise_num == 0 ptc.delete end - num = get_activity_praise_num(obj) + obj = PraiseTreadCache.where("object_id=? and object_type=?",obj_id,obj_type.to_s).first + num = !obj.blank? ? get_activity_praise_num(obj) : 0 end present :data, num diff --git a/public/assets/wechat/activities.html b/public/assets/wechat/activities.html index c99c9ee09..b3c8f1b99 100644 --- a/public/assets/wechat/activities.html +++ b/public/assets/wechat/activities.html @@ -23,8 +23,8 @@
回复 ({{act.reply_count}})
-
赞 ({{act.activity_praise_count}})
-
已赞 ({{act.activity_praise_count}})
+
赞 ({{act.praise_count}})
+
已赞 ({{act.praise_count}})
@@ -49,8 +49,8 @@
回复 ({{act.reply_count}})
-
赞 ({{act.activity_praise_count}})
-
已赞 ({{act.activity_praise_count}})
+
赞 ({{act.praise_count}})
+
已赞 ({{act.praise_count}})
@@ -73,8 +73,8 @@
回复 ({{act.reply_count}})
-
赞 ({{act.activity_praise_count}})
-
已赞 ({{act.activity_praise_count}})
+
赞 ({{act.praise_count}})
+
已赞 ({{act.praise_count}})
@@ -118,8 +118,8 @@
回复 ({{act.reply_count}})
-
赞 ({{act.activity_praise_count}})
-
已赞 ({{act.activity_praise_count}})
+
赞 ({{act.praise_count}})
+
已赞 ({{act.praise_count}})
@@ -144,8 +144,8 @@
回复 ({{act.reply_count}})
-
赞 ({{act.activity_praise_count}})
-
已赞 ({{act.activity_praise_count}})
+
赞 ({{act.praise_count}})
+
已赞 ({{act.praise_count}})
@@ -182,8 +182,8 @@
回复 ({{act.reply_count}})
-
赞 ({{act.activity_praise_count}})
-
已赞 ({{act.activity_praise_count}})
+
赞 ({{act.praise_count}})
+
已赞 ({{act.praise_count}})
@@ -207,8 +207,8 @@
回复 ({{act.reply_count}})
-
赞 ({{act.activity_praise_count}})
-
已赞 ({{act.activity_praise_count}})
+
赞 ({{act.praise_count}})
+
已赞 ({{act.praise_count}})
diff --git a/public/assets/wechat/blog_detail.html b/public/assets/wechat/blog_detail.html index a2cb70650..3c5c30945 100644 --- a/public/assets/wechat/blog_detail.html +++ b/public/assets/wechat/blog_detail.html @@ -16,8 +16,8 @@
回复 ({{blog.comments_count}})
-
已赞 ({{blog.blog_praise_count}})
-
赞 ({{blog.blog_praise_count}})
+
已赞 ({{blog.praise_count}})
+
赞 ({{blog.praise_count}})
diff --git a/public/assets/wechat/course_discussion.html b/public/assets/wechat/course_discussion.html index 416cfaa22..680e92f5d 100644 --- a/public/assets/wechat/course_discussion.html +++ b/public/assets/wechat/course_discussion.html @@ -16,8 +16,8 @@
回复 ({{discussion.replies_count}})
-
已赞 ({{discussion.message_praise_count}})
-
赞 ({{discussion.message_praise_count}})
+
已赞 ({{discussion.praise_count}})
+
赞 ({{discussion.praise_count}})
diff --git a/public/assets/wechat/course_notice.html b/public/assets/wechat/course_notice.html index 737728d95..6bc5a790c 100644 --- a/public/assets/wechat/course_notice.html +++ b/public/assets/wechat/course_notice.html @@ -16,8 +16,8 @@
回复 ({{news.comments_count}})
-
已赞 ({{news.news_praise_count}})
-
赞 ({{news.news_praise_count}})
+
已赞 ({{news.praise_count}})
+
赞 ({{news.praise_count}})
diff --git a/public/assets/wechat/homework_detail.html b/public/assets/wechat/homework_detail.html index 5926727e1..abc92f133 100644 --- a/public/assets/wechat/homework_detail.html +++ b/public/assets/wechat/homework_detail.html @@ -18,8 +18,8 @@
回复 ({{homework.whomework_journal_count}})
-
已赞 ({{homework.whomework_praise_count}})
-
赞 ({{homework.whomework_praise_count}})
+
已赞 ({{homework.praise_count}})
+
赞 ({{homework.praise_count}})
diff --git a/public/assets/wechat/issue_detail.html b/public/assets/wechat/issue_detail.html index 3be9d0d21..fc9591692 100644 --- a/public/assets/wechat/issue_detail.html +++ b/public/assets/wechat/issue_detail.html @@ -18,8 +18,8 @@
回复 ({{issue.journals_count}})
-
已赞 ({{issue.issue_praise_count}})
-
赞 ({{issue.issue_praise_count}})
+
已赞 ({{issue.praise_count}})
+
赞 ({{issue.praise_count}})
diff --git a/public/assets/wechat/jour_message_detail.html b/public/assets/wechat/jour_message_detail.html index 990055b56..cdc817941 100644 --- a/public/assets/wechat/jour_message_detail.html +++ b/public/assets/wechat/jour_message_detail.html @@ -13,8 +13,8 @@
回复 ({{message.reply_count}})
-
已赞 ({{message.message_praise_count}})
-
赞 ({{message.message_praise_count}})
+
已赞 ({{message.praise_count}})
+
赞 ({{message.praise_count}})
diff --git a/public/assets/wechat/project_discussion.html b/public/assets/wechat/project_discussion.html index 6c06b95e9..3fa7b0949 100644 --- a/public/assets/wechat/project_discussion.html +++ b/public/assets/wechat/project_discussion.html @@ -16,8 +16,8 @@
回复 ({{discussion.replies_count}})
-
已赞 ({{discussion.message_praise_count}})
-
赞 ({{discussion.message_praise_count}})
+
已赞 ({{discussion.praise_count}})
+
赞 ({{discussion.praise_count}})
diff --git a/public/javascripts/wechat/app.js b/public/javascripts/wechat/app.js index 0d79caaed..57003f9e1 100644 --- a/public/javascripts/wechat/app.js +++ b/public/javascripts/wechat/app.js @@ -96,12 +96,12 @@ app.controller('ActivityController',function($scope, $http, auth, rms, common){ $scope.addPraise = function(act){ console.log(act); common.addCommonPraise(act); - } + }; $scope.decreasePraise = function(act){ console.log(act); common.decreaseCommonPraise(act); - } + }; }); @@ -140,7 +140,7 @@ app.factory('common', function($http, auth, $routeParams){ }; var addCommonPraise = function(act){ - act.activity_praise_count += 1; + act.praise_count += 1; act.has_praise = true; $http({ @@ -155,7 +155,7 @@ app.factory('common', function($http, auth, $routeParams){ }; var decreaseCommonPraise = function(act){ - act.activity_praise_count -= 1; + act.praise_count -= 1; act.has_praise = false; $http({ @@ -163,7 +163,7 @@ app.factory('common', function($http, auth, $routeParams){ url: apiUrl + "praise/" + act.act_id, data:{openid:auth.openid(),type:act.act_type} }).then(function successCallback(response) { - console.log("取消赞成功"); + console.log(response.data); }, function errorCallback(response) { }); }; @@ -192,6 +192,16 @@ app.controller('IssueController', function($scope, $http, $routeParams, auth, co }); }; + + $scope.addPraise = function(act){ + console.log(act); + common.addCommonPraise(act); + }; + + $scope.decreasePraise = function(act){ + console.log(act); + common.decreaseCommonPraise(act); + }; }); app.controller('HomeworkController', function($scope, $http, $routeParams, auth, common){ @@ -214,6 +224,16 @@ app.controller('HomeworkController', function($scope, $http, $routeParams, auth, loadData($routeParams.id); }); }; + + $scope.addPraise = function(act){ + console.log(act); + common.addCommonPraise(act); + }; + + $scope.decreasePraise = function(act){ + console.log(act); + common.decreaseCommonPraise(act); + }; }); app.controller('CourseNoticeController', function($scope, $http, $routeParams, auth, common){ @@ -235,7 +255,17 @@ app.controller('CourseNoticeController', function($scope, $http, $routeParams, a $scope.formData = {comment: ''}; loadData($routeParams.id); }); - } + }; + + $scope.addPraise = function(act){ + console.log(act); + common.addCommonPraise(act); + }; + + $scope.decreasePraise = function(act){ + console.log(act); + common.decreaseCommonPraise(act); + }; }); app.controller('DiscussionController', function($scope, $http, $routeParams, auth, common){ @@ -257,7 +287,17 @@ app.controller('DiscussionController', function($scope, $http, $routeParams, aut $scope.formData = {comment: ''}; loadData($routeParams.id); }); - } + }; + + $scope.addPraise = function(act){ + console.log(act); + common.addCommonPraise(act); + }; + + $scope.decreasePraise = function(act){ + console.log(act); + common.decreaseCommonPraise(act); + }; }); app.controller('JournalsController', function($scope, $http, $routeParams, auth, common){ @@ -280,6 +320,16 @@ app.controller('JournalsController', function($scope, $http, $routeParams, auth, loadData($routeParams.id); }); }; + + $scope.addPraise = function(act){ + console.log(act); + common.addCommonPraise(act); + }; + + $scope.decreasePraise = function(act){ + console.log(act); + common.decreaseCommonPraise(act); + }; }); app.controller('BlogController', function($scope, $http, $routeParams, auth, common){ @@ -302,6 +352,16 @@ app.controller('BlogController', function($scope, $http, $routeParams, auth, com loadData($routeParams.id); }); }; + + $scope.addPraise = function(act){ + console.log(act); + common.addCommonPraise(act); + }; + + $scope.decreasePraise = function(act){ + console.log(act); + common.decreaseCommonPraise(act); + }; }); app.filter('safeHtml', function ($sce) {