2016-01-19 11:51:37 +08:00
|
|
|
class UserWechat < ActiveRecord::Base
|
2016-01-19 12:00:13 +08:00
|
|
|
attr_accessible :subscribe, :openid, :nickname, :sex, :language, :city, :province, :country,
|
2016-08-11 17:22:48 +08:00
|
|
|
:headimgurl, :subscribe_time, :unionid, :remark, :groupid, :user, :user_id, :bindtype
|
2016-01-19 12:00:13 +08:00
|
|
|
|
|
|
|
belongs_to :user
|
2016-08-13 14:39:15 +08:00
|
|
|
|
|
|
|
def real?
|
|
|
|
bindtype == 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def migrate_user(u)
|
|
|
|
self.bindtype = 0
|
|
|
|
old_user = user.id
|
|
|
|
self.user = u
|
|
|
|
self.save
|
|
|
|
|
|
|
|
## 主要是将comment 迁移
|
2016-08-14 10:56:38 +08:00
|
|
|
User.delete(old_user)
|
2016-08-13 14:39:15 +08:00
|
|
|
|
2016-08-14 11:18:23 +08:00
|
|
|
JournalsForMessage.where(user_id: old_user).update_all(user_id: u.id)
|
2016-08-13 14:39:15 +08:00
|
|
|
Journal.where(user_id: old_user).update_all(user_id: u.id)
|
|
|
|
Comment.where(author_id: old_user).update_all(author_id: u.id)
|
|
|
|
Message.where(author_id: old_user).update_all(author_id: u.id)
|
|
|
|
BlogComment.where(author_id: old_user).update_all(author_id: u.id)
|
2016-08-14 12:35:03 +08:00
|
|
|
UserActivity.where(user_id: old_user).update_all(user_id: u.id)
|
2016-08-13 14:39:15 +08:00
|
|
|
end
|
2016-12-12 10:55:19 +08:00
|
|
|
|
|
|
|
|
|
|
|
def unsubscribe!
|
|
|
|
self.delete
|
|
|
|
end
|
2016-01-19 11:51:37 +08:00
|
|
|
end
|