diff --git a/.access_token b/.access_token
index 610b08d2e..2fb2e740f 100644
--- a/.access_token
+++ b/.access_token
@@ -1 +1 @@
-{"access_token":"oEEf8ZKAB8Y2G0o_xnTPkPJHKKk8iHkLC-f5ptvQ2nCMj9IpC86ivLD2-p38GfOkuG-HuQp3pWZqhs3NJXUMdPLWsr5k67hPZYuqg4ozLccx0xdLswapj0mn8ovZhK1tKIKiAFAOMO","expires_in":7200,"got_token_at":1467012449}
\ No newline at end of file
+{"access_token":"m8kGwb7G0laM6-0uHmPtxETR6WJk5PgR37te_h8aBwgqGXkml2ZZAvPUBldmzF5hDZsQBHEn8PUACSL60eDKlCWigwwUJReK2wB4UbXIc1UA-rrkpHuWl84H3rcswtlvHENjAHAZWF","expires_in":7200,"got_token_at":1467472907}
\ No newline at end of file
diff --git a/app/api/mobile/apis/courses.rb b/app/api/mobile/apis/courses.rb
index 42303b63d..cb1db09d8 100644
--- a/app/api/mobile/apis/courses.rb
+++ b/app/api/mobile/apis/courses.rb
@@ -107,7 +107,7 @@ module Mobile
status = cs.join_course({role: "10", openid: params[:openid], invite_code: params[:invite_code]}, current_user)
{
status: status[:state],
- messsge:CoursesService::JoinCourseError.message(status[:state])
+ message:CoursesService::JoinCourseError.message(status[:state])
}
end
diff --git a/app/api/mobile/apis/resources.rb b/app/api/mobile/apis/resources.rb
index fca94a642..c2fcfa754 100644
--- a/app/api/mobile/apis/resources.rb
+++ b/app/api/mobile/apis/resources.rb
@@ -46,10 +46,26 @@ module Mobile
end
+ desc '发送资源'
+ params do
+ requires :token, type: String
+ requires :course_ids, type: Array[Integer]
+ requires :send_id, type: Integer
+ end
+ post 'send' do
+ authenticate!
+
+ rs = ResourcesService.new
+ ori, flag, save_message = rs.send_resource_to_course(params)
+ if flag
+ present :status, 0
+ else
+ {status: -1, message: save_message.first}
+ end
+ end
+
end
-
-
end
end
end
\ No newline at end of file
diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb
index b7972ff6f..3bf582e23 100644
--- a/app/controllers/users_controller.rb
+++ b/app/controllers/users_controller.rb
@@ -1977,44 +1977,8 @@ class UsersController < ApplicationController
def add_exist_file_to_course
@flag = true
if params[:send_id].present?
- send_id = params[:send_id]
- @ori = Attachment.find_by_id(send_id)
- course_ids = params[:course_ids]
- if course_ids.nil?
- @flag = false
- end
- unless course_ids.nil?
- course_ids.each do |id|
- next if @ori.blank?
- @exist = false
- Course.find(id).attachments.each do |att| #如果课程中包含该资源
- if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from
- att.created_on = Time.now
- att.save
- @exist = true
- break
- end
- end
- next if @exist
- attach_copied_obj = @ori.copy
- attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联
- attach_copied_obj.container = Course.find(id)
- attach_copied_obj.created_on = Time.now
- attach_copied_obj.author_id = User.current.id
- attach_copied_obj.is_public = 0
- attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from
- if attach_copied_obj.attachtype == nil
- attach_copied_obj.attachtype = 4
- end
- if attach_copied_obj.save
- # 更新引用次数
- quotes = @ori.quotes.to_i + 1
- @ori.update_attribute(:quotes, quotes) unless @ori.nil?
- @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
- end
- @save_message = attach_copied_obj.errors.full_messages
- end
- end
+ rs = ResourcesService.new
+ @ori, @flag, @save_message = rs.send_resource_to_course(params)
elsif params[:send_ids].present?
send_ids = params[:send_ids].split(",")
course_ids = params[:course_ids]
diff --git a/app/services/courses_service.rb b/app/services/courses_service.rb
index dce3e1f18..e6143caec 100644
--- a/app/services/courses_service.rb
+++ b/app/services/courses_service.rb
@@ -324,7 +324,7 @@ class CoursesService
1, '密码错误',
2, '课程已过期 请联系课程管理员重启课程。',
3, '您已经加入了课程',
- 4, '您加入的课程不存在',
+ 4, '您的邀请码不正确',
5, '您还未登录',
6, '申请成功,请等待审核完毕',
7, '您已经发送过申请了,请耐心等待',
diff --git a/app/services/resources_service.rb b/app/services/resources_service.rb
new file mode 100644
index 000000000..827fc3efd
--- /dev/null
+++ b/app/services/resources_service.rb
@@ -0,0 +1,53 @@
+#coding=utf-8
+
+class ResourcesService
+
+ #发送资源到课程
+ def send_resource_to_course params
+ send_id = params[:send_id]
+ @ori = Attachment.find_by_id(send_id)
+ course_ids = params[:course_ids]
+ @flag = false
+ unless course_ids.nil?
+ course_ids.each do |id|
+ next if @ori.blank?
+ @exist = false
+ Course.find(id).attachments.each do |att| #如果课程中包含该资源
+ if att.id == @ori.id || (!att.copy_from.nil? && !@ori.copy_from.nil? && att.copy_from == @ori.copy_from) || att.copy_from == @ori.id || att.id == @ori.copy_from
+ att.created_on = Time.now
+ att.save
+ @exist = true
+ @flag = true
+ break
+ end
+ end
+ next if @exist
+ attach_copied_obj = @ori.copy
+ attach_copied_obj.tag_list.add(@ori.tag_list) # tag关联
+ attach_copied_obj.container = Course.find(id)
+ attach_copied_obj.created_on = Time.now
+ attach_copied_obj.author_id = User.current.id
+ attach_copied_obj.is_public = 0
+ attach_copied_obj.copy_from = @ori.copy_from.nil? ? @ori.id : @ori.copy_from #发送要添加copy_from
+ if attach_copied_obj.attachtype == nil
+ attach_copied_obj.attachtype = 4
+ end
+ if attach_copied_obj.save
+ # 更新引用次数
+ quotes = @ori.quotes.to_i + 1
+ @ori.update_attribute(:quotes, quotes) unless @ori.nil?
+ @ori.forwards << Forward.new(:to_type => attach_copied_obj.class.name, :to_id => attach_copied_obj.id,:created_at => Time.now)
+ @flag = true
+ else
+ @flag = false
+ @save_message = attach_copied_obj.errors.full_messages
+ break
+ end
+
+ end
+ end
+
+ [@ori, @flag, @save_message]
+ end
+
+end
\ No newline at end of file
diff --git a/app/services/users_service.rb b/app/services/users_service.rb
index 8df42fb41..ab1bb2ec4 100644
--- a/app/services/users_service.rb
+++ b/app/services/users_service.rb
@@ -319,4 +319,8 @@ class UsersService
my_jours_arr
end
+
+
+
+
end
diff --git a/app/views/wechats/user_activities.html.erb b/app/views/wechats/user_activities.html.erb
index 7b7cb95e5..ab1d18a8d 100644
--- a/app/views/wechats/user_activities.html.erb
+++ b/app/views/wechats/user_activities.html.erb
@@ -50,6 +50,7 @@
+