Merge branch 'dev_aliyun' of https://bdgit.educoder.net/Hjqreturn/educoder into dev_aliyun

dev_newshixunModel
hjm 5 years ago
commit 591685c296

@ -13,6 +13,7 @@
//= require bootstrap-datepicker
//= require bootstrap.viewer
//= require jquery.mloading
//= require jquery-confirm.min
//= require common
//= require echarts

@ -0,0 +1,12 @@
$(document).on('turbolinks:load', function(){
$(document).on('click', '.batch-all-check-box', function(){
var $checkAll = $(this);
$('.batch-check-box').prop('checked', $checkAll.is(':checked'));
})
$(document).on('click', '.batch-check-box', function(){
var allChecked = $('.batch-check-box:checked').length === $('.batch-check-box').length
$('.batch-all-check-box').prop('checked', allChecked);
})
});

@ -10,11 +10,41 @@ $(document).on('turbolinks:load', function() {
$searchFrom.find('select[name="status"]').val('processed');
if($link.data('value') === 'processed'){
$('.batch-action-container').hide();
$searchFrom.find('.status-filter').show();
} else {
$('.batch-action-container').show();
$searchFrom.find('.status-filter').hide();
$searchFrom.find('select[name="status"]').val('pending');
}
});
$('.batch-agree-btn').on('click', function(){
if($('.batch-check-box:checked').length === 0){
$.notify({ message: '请先选择数据' }, { type: 'info' });
return;
}
customConfirm({
content: '确认审核通过?',
ok: function(){
var ids = $('.batch-check-box:checked').map(function(_, e){ return $(e).val() }).get();
$.ajax({
url: '/admins/identity_authentications/batch_agree',
method: 'POST',
dataType: 'json',
data: { ids: ids },
success: function(data){
$.notify({ message: '操作成功' });
window.location.reload();
},
error: function(res){
$.notify({ message: res.responseJSON.message }, { type: 'danger' });
}
})
}
})
})
}
})

@ -10,11 +10,41 @@ $(document).on('turbolinks:load', function() {
$searchFrom.find('select[name="status"]').val('processed');
if($link.data('value') === 'processed'){
$('.batch-action-container').hide();
$searchFrom.find('.status-filter').show();
} else {
$('.batch-action-container').show();
$searchFrom.find('.status-filter').hide();
$searchFrom.find('select[name="status"]').val('pending');
}
});
$('.batch-agree-btn').on('click', function(){
if($('.batch-check-box:checked').length === 0){
$.notify({ message: '请先选择数据' }, { type: 'info' });
return;
}
customConfirm({
content: '确认审核通过?',
ok: function(){
var ids = $('.batch-check-box:checked').map(function(_, e){ return $(e).val() }).get();
$.ajax({
url: '/admins/professional_authentications/batch_agree',
method: 'POST',
dataType: 'json',
data: { ids: ids },
success: function(data){
$.notify({ message: '操作成功' });
window.location.reload();
},
error: function(res){
$.notify({ message: res.responseJSON.message }, { type: 'danger' });
}
})
}
})
})
}
})

@ -43,3 +43,25 @@ function resetFileInputFunc(file){
file.after(file.clone().val(""));
file.remove();
}
function customConfirm(opts){
var okCallback = opts.ok;
var cancelCallback = opts.cancel;
var defaultOpts = {
title: '提示',
buttons: {
ok: {
text: '确认',
btnClass: 'btn btn-primary',
action: okCallback
},
cancel: {
text: '取消',
btnClass: 'btn btn-secondary',
action: cancelCallback
},
}
}
return $.confirm($.extend({}, defaultOpts, opts))
}

File diff suppressed because one or more lines are too long

@ -6,6 +6,7 @@
@import "bootstrap-datepicker";
@import "bootstrap-datepicker.standalone";
@import "jquery.mloading";
@import "jquery-confirm.min";
@import "codemirror/lib/codemirror";
@import "editormd/css/editormd.min";

@ -110,5 +110,11 @@
.CodeMirror {
border: 1px solid #ced4da;
}
.batch-action-container {
margin-bottom: -15px;
padding: 10px 20px 0;
background: #fff;
}
}

File diff suppressed because one or more lines are too long

@ -1,6 +1,7 @@
class Admins::IdentityAuthenticationsController < Admins::BaseController
def index
params[:status] ||= 'pending'
params[:sort_direction] = params[:status] == 'pending' ? 'asc' : 'desc'
applies = Admins::ApplyUserAuthenticationQuery.call(params.merge(type: 1))
@ -18,6 +19,24 @@ class Admins::IdentityAuthenticationsController < Admins::BaseController
render_success_js
end
def batch_agree
ApplyUserAuthentication.real_name_auth.where(id: params[:ids]).each do |apply|
begin
Admins::IdentityAuths::AgreeApplyService.call(apply)
rescue => e
Util.logger_error(e)
end
end
render_ok
end
def revoke
Admins::IdentityAuths::RevokeApplyService.call(current_apply)
render_success_js
end
private
def current_apply

@ -1,6 +1,7 @@
class Admins::ProfessionalAuthenticationsController < Admins::BaseController
def index
params[:status] ||= 'pending'
params[:sort_direction] = params[:status] == 'pending' ? 'asc' : 'desc'
applies = Admins::ApplyUserAuthenticationQuery.call(params.merge(type: 2))
@ -18,6 +19,23 @@ class Admins::ProfessionalAuthenticationsController < Admins::BaseController
render_success_js
end
def batch_agree
ApplyUserAuthentication.professional_auth.where(id: params[:ids]).each do |apply|
begin
Admins::ProfessionalAuths::AgreeApplyService.call(apply)
rescue => e
Util.logger_error(e)
end
end
render_ok
end
def revoke
Admins::ProfessionalAuths::RevokeApplyService.call(current_apply)
render_success_js
end
private
def current_apply

@ -415,6 +415,20 @@ class SubjectsController < ApplicationController
order by ue_count desc limit 10")
end
# 预约报名
def appointment
tip_exception("还存在未结束的课堂") unless @subject.max_course_end_date.nil? || @subject.max_course_end_date < Date.today
tip_exception("无需重复报名") if @subject.subject_appointments.exists?(user_id: current_user.id)
ActiveRecord::Base.transaction do
@subject.subject_appointments << SubjectAppointment.new(user_id: current_user.id)
@subject.increment!(:participant_count)
if @subject.participant_count == @subject.student_count
@subject.start_course_notify
end
normal_status("预约成功")
end
end
private
def subject_params
tip_exception("实训路径名称不能为空") if params[:name].blank?

@ -384,4 +384,8 @@ module TidingDecorator
def public_course_start_content
I18n.t(locale_format) % [belong_container&.name, belong_container&.start_date&.strftime("%Y-%m-%d")]
end
def subject_start_course_content
I18n.t(locale_format) % belong_container&.name
end
end

@ -18,6 +18,10 @@ class ApplyUserAuthentication < ApplicationRecord
nil
end
def revoke!
update!(status: 3)
end
private
def send_tiding

@ -13,6 +13,8 @@ class Subject < ApplicationRecord
has_many :stage_shixuns, dependent: :destroy
has_many :shixuns, through: :stage_shixuns
has_many :subject_appointments, dependent: :destroy
has_many :subject_members, ->{ order("subject_members.position asc")}, dependent: :destroy
has_many :users, through: :subject_members
has_many :tidings, as: :container, dependent: :destroy
@ -44,6 +46,10 @@ class Subject < ApplicationRecord
courses.where("start_date <= '#{Date.today}' and end_date >= '#{Date.today}'").count > 0
end
def has_participate?
subject_appointments.exists?(user_id: User.current.id)
end
# 挑战过路径的成员数(金课统计去重后的报名人数)
def member_count
excellent ? CourseMember.where(role: 4, course_id: courses.pluck(:id)).pluck(:user_id).length : shixuns.pluck(:myshixuns_count).sum
@ -109,4 +115,10 @@ class Subject < ApplicationRecord
def learning? user_id
Myshixun.where(user_id: user_id, shixun_id: shixuns).exists?
end
def start_course_notify
Tiding.create(user_id: user_id, trigger_user_id: 0, container_id: id,
container_type: 'SubjectStartCourse', belong_container_id: id,
belong_container_type: 'Subject', tiding_type: 'System')
end
end

@ -0,0 +1,4 @@
class SubjectAppointment < ApplicationRecord
belongs_to :subject
belongs_to :user
end

@ -0,0 +1,26 @@
class Admins::IdentityAuths::RevokeApplyService < ApplicationService
attr_reader :apply, :user
def initialize(apply)
@apply = apply
@user = apply.user
end
def call
ActiveRecord::Base.transaction do
apply.revoke!
user.update!(authentication: false)
deal_tiding!
end
end
private
def deal_tiding!
Tiding.create!(user_id: apply.user_id, trigger_user_id: 0,
container_id: apply.id, container_type: 'CancelUserAuthentication',
belong_container_id: apply.user_id, belong_container_type: 'User',
status: 1, tiding_type: 'System')
end
end

@ -0,0 +1,26 @@
class Admins::ProfessionalAuths::RevokeApplyService < ApplicationService
attr_reader :apply, :user
def initialize(apply)
@apply = apply
@user = apply.user
end
def call
ActiveRecord::Base.transaction do
apply.revoke!
user.update!(professional_certification: false)
deal_tiding!
end
end
private
def deal_tiding!
Tiding.create!(user_id: apply.user_id, trigger_user_id: 0,
container_id: apply.id, container_type: 'CancelUserProCertification',
belong_container_id: apply.user_id, belong_container_type: 'User',
status: 1, tiding_type: 'System')
end
end

@ -25,6 +25,10 @@
<% end %>
</div>
<div class="batch-action-container">
<%= javascript_void_link '批量同意', class: 'btn btn-outline-primary btn-sm batch-agree-btn' %>
</div>
<div class="box identity-authentication-list-container">
<%= render(partial: 'admins/identity_authentications/shared/list', locals: { applies: @applies }) %>
</div>

@ -3,6 +3,12 @@
<table class="table table-hover text-center identity-authentication-list-table">
<thead class="thead-light">
<tr>
<% unless is_processed %>
<th width="4%">
<%= check_box_tag('all-check', 1, false, id: nil, class: 'batch-all-check-box',
data: { toggle: 'tooltip', title: '全选' }) %>
</th>
<% end %>
<th width="8%">头像</th>
<th width="10%">姓名</th>
<th width="14%">身份证号</th>
@ -14,12 +20,14 @@
<i class="fa fa-question-circle" data-toggle="tooltip" data-html="true" data-placement="top" title="审核完成后自动删除图片"></i>
</th>
<% end %>
<th width="16%">时间</th>
<% if is_processed %>
<th width="14%">拒绝原因</th>
<th width="10%">时间</th>
<th width="12%">拒绝原因</th>
<th width="8%">状态</th>
<th width="8%">操作</th>
<% else %>
<th width="20%">操作</th>
<th width="16%">时间</th>
<th width="16%">操作</th>
<% end %>
</tr>
</thead>
@ -28,6 +36,9 @@
<% applies.each do |apply| %>
<% user = apply.user %>
<tr class="identity-authentication-item identity-authentication-<%= apply.id %>">
<% unless is_processed %>
<td><%= check_box_tag('ids[]', apply.id, false, id: nil, class: 'batch-check-box') %></td>
<% end %>
<td>
<%= link_to "/users/#{user.login}", class: 'identity-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
@ -53,6 +64,11 @@
<% if is_processed %>
<td class="text-secondary"><%= overflow_hidden_span apply.remarks, width: 140 %></td>
<td><span class="apply-status-<%= apply.status %>"><%= apply.status_text %></span></td>
<td>
<% if apply.status == 1 %>
<%= agree_link '撤销', revoke_admins_identity_authentication_path(apply, element: ".identity-authentication-#{apply.id}"), 'data-confirm': '是否确认撤销认证??' %>
<% end %>
</td>
<% else %>
<td class="action-container">
<%= agree_link '同意', agree_admins_identity_authentication_path(apply, element: ".identity-authentication-#{apply.id}"), 'data-confirm': '确认审核通过?' %>

@ -25,6 +25,10 @@
<% end %>
</div>
<div class="batch-action-container">
<%= javascript_void_link '批量同意', class: 'btn btn-outline-primary btn-sm batch-agree-btn' %>
</div>
<div class="box professional-authentication-list-container">
<%= render(partial: 'admins/professional_authentications/shared/list', locals: { applies: @applies }) %>
</div>

@ -3,12 +3,18 @@
<table class="table table-hover text-center professional-authentication-list-table">
<thead class="thead-light">
<tr>
<% unless is_processed %>
<th width="4%">
<%= check_box_tag('all-check', 1, false, id: nil, class: 'batch-all-check-box',
data: { toggle: 'tooltip', title: '全选' }) %>
</th>
<% end %>
<th width="8%">头像</th>
<th width="14%">姓名</th>
<th width="28%">学校/单位</th>
<th width="20%">学校/单位</th>
<th width="12%">职称</th>
<% unless is_processed %>
<th width="10%">
<th width="14%">
照片
<i class="fa fa-question-circle" data-toggle="tooltip" data-html="true" data-placement="top" title="审核完成后自动删除图片"></i>
</th>
@ -17,8 +23,9 @@
<% if is_processed %>
<th width="14%">拒绝原因</th>
<th width="8%">状态</th>
<th width="8%">操作</th>
<% else %>
<th width="18%">操作</th>
<th width="22%">操作</th>
<% end %>
</tr>
</thead>
@ -27,6 +34,9 @@
<% applies.each do |apply| %>
<% user = apply.user %>
<tr class="professional-authentication-item professional-authentication-<%= apply.id %>">
<% unless is_processed %>
<td><%= check_box_tag('ids[]', apply.id, false, id: nil, class: 'batch-check-box') %></td>
<% end %>
<td>
<%= link_to "/users/#{user.login}", class: 'professional-authentication-avatar', target: '_blank', data: { toggle: 'tooltip', title: '个人主页' } do %>
<img src="/images/<%= url_to_avatar(user) %>" class="rounded-circle" width="40" height="40" />
@ -51,6 +61,11 @@
<% if is_processed %>
<td class="text-secondary"><%= overflow_hidden_span apply.remarks, width: 140 %></td>
<td><span class="apply-status-<%= apply.status %>"><%= apply.status_text %></span></td>
<td>
<% if apply.status == 1 %>
<%= agree_link '撤销', revoke_admins_professional_authentication_path(apply, element: ".professional-authentication-#{apply.id}"), 'data-confirm': '是否确认撤销认证??' %>
<% end %>
</td>
<% else %>
<td class="action-container">
<%= agree_link '同意', agree_admins_professional_authentication_path(apply, element: ".professional-authentication-#{apply.id}"), 'data-confirm': '确认审核通过?', 'data-disable-with': "提交中..." %>

@ -9,8 +9,10 @@ json.results do
# 去除开头标点符号
reg = /^[,。?:;‘’!“”—……、]/
highlights[:description]&.first&.sub!(reg, '')
highlights[:content]&.first&.sub!(reg, '')
# 附件的替换
atta_reg = /!\[\]\(\/api\/attachments\/\d+\)/
highlights[:description]&.first&.sub!(reg, '').sub!(atta_reg, '')
highlights[:content]&.first&.sub!(reg, '').sub!(atta_reg, '')
json.content highlights
end

@ -7,11 +7,13 @@ json.shixun_list do
# 去除开头标点符号
reg = /^[,。?:;‘’!“”—……、]/
highlights[:description]&.first&.sub!(reg, '')
highlights[:content]&.first&.sub!(reg, '')
# 附件的替换
atta_reg = /!\[\]\(\/api\/attachments\/\d+\)/
highlights[:description]&.first&.sub!(reg, '')&.sub!(atta_reg, '')
highlights[:content]&.first&.sub!(reg, '')&.sub!(atta_reg, '')
json.title highlights.delete(:name)&.join('...') || obj.searchable_title
json.description highlights[:description]&.join('...') || Util.extract_content(obj.description)[0..300]
json.description highlights[:description]&.join('...') || Util.extract_content(obj.description)[0..300]&.sub!(atta_reg, '')
json.content highlights
json.level level_to_s(obj.trainee)

@ -24,4 +24,10 @@ if @subject.excellent
json.course_identity @user.course_identity(course)
json.course_status subject_course_status course
end
if @subject.max_course_end_date.nil? || @subject.max_course_end_date < Date.today
json.student_count @subject.student_count
json.participant_count @subject.participant_count
json.has_participate @subject.has_participate?
end
end

@ -10,7 +10,7 @@
"2_1_end": "你提交的职业认证申请,审核已通过"
"2_2_end": "你提交的职业认证申请,审核未通过<br/><span>原因:%{reason}</span>"
CancelUserAuthentication_end: "取消了你的实名认证:%s %s"
CancelUserProCertification_end: "取消了你的实名认证:%s %s"
CancelUserProCertification_end: "取消了你的职业认证:%s %s"
JoinCourse:
"9_end": "申请加入课堂:%s教师"
"7_end": "申请加入课堂:%s助教"
@ -227,3 +227,4 @@
1_end: "你提交的发布视频申请:%s审核已通过"
2_end: "你提交的发布视频申请:%s审核未通过<br/><span>原因:%{reason}</span>"
PublicCourseStart_end: "你报名参与的开放课程:%s将于%s正式开课"
SubjectStartCourse_end: "您创建的开放课程:%s 已达到开课人数要求。您可以在24小时内自主开设新一期课程。如果超过24小时未开课平台将自动开课并复制您上一期的课程内容。"

@ -284,6 +284,7 @@ Rails.application.routes.draw do
post :up_member_position
post :down_member_position
get :right_banner
post :appointment
end
collection do
@ -879,12 +880,22 @@ Rails.application.routes.draw do
member do
post :agree
post :refuse
post :revoke
end
collection do
post :batch_agree
end
end
resources :professional_authentications, only: [:index] do
member do
post :agree
post :refuse
post :revoke
end
collection do
post :batch_agree
end
end
resources :shixun_authorizations, only: [:index] do

@ -0,0 +1,6 @@
class AddCourseMemberToSubjects < ActiveRecord::Migration[5.2]
def change
add_column :subjects, :student_count, :integer, :default => 0
add_column :subjects, :participant_count, :integer, :default => 0
end
end

@ -0,0 +1,10 @@
class CreateSubjectAppointments < ActiveRecord::Migration[5.2]
def change
create_table :subject_appointments do |t|
t.references :subject, index: true
t.references :user, index: true
t.timestamps
end
end
end

File diff suppressed because one or more lines are too long

@ -0,0 +1,5 @@
require 'rails_helper'
RSpec.describe SubjectAppointment, type: :model do
pending "add some examples to (or delete) #{__FILE__}"
end
Loading…
Cancel
Save