diff --git a/app/controllers/admins/phenglei_users_controller.rb b/app/controllers/admins/phenglei_users_controller.rb
new file mode 100644
index 00000000..e1fbff7c
--- /dev/null
+++ b/app/controllers/admins/phenglei_users_controller.rb
@@ -0,0 +1,36 @@
+class Admins::PhengleiUsersController < Admins::BaseController
+ before_action :phenglei_project, only: [:index]
+
+ def index
+ if params[:keyword].present?
+ @phenglei_users = PhengleiUser.ransack(phone_cont: params[:keyword]).result
+ else
+ @phenglei_users = PhengleiUser
+ end
+ @phenglei_users = @phenglei_users.page(page).per(per_page)
+ end
+
+ def new
+ @phenglei_user = PhengleiUser.new
+ end
+
+ def create
+ @phenglei_user = PhengleiUser.new(phenglei_user_params)
+ if @phenglei_user.save
+ redirect_to admins_phenglei_users_path
+ flash[:success] = "创建成功"
+ else
+ redirect_to admins_phenglei_users_path
+ flash[:error] = "创建失败"
+ end
+ end
+
+ private
+ def phenglei_project
+ @phenglei_project = Project.find_by_id(EduSetting.get("sync_phenglei_user_project"))
+ end
+
+ def phenglei_user_params
+ params.require(:phenglei_user).permit(:phone)
+ end
+end
diff --git a/app/controllers/admins/projects_controller.rb b/app/controllers/admins/projects_controller.rb
index d71468c0..9e33b6ce 100644
--- a/app/controllers/admins/projects_controller.rb
+++ b/app/controllers/admins/projects_controller.rb
@@ -27,10 +27,10 @@ class Admins::ProjectsController < Admins::BaseController
def sync_phenglei_user
if @project.is_secret
SyncPhengleiUserJob.perform_later(@project.id)
- redirect_to admins_projects_path
+ redirect_to admins_phenglei_users_path
flash[:success] = "已开启后台同步任务"
else
- redirect_to admins_projects_path
+ redirect_to admins_phenglei_users_path
flash[:danger] = "非风雷协议项目"
end
end
diff --git a/app/jobs/sync_phenglei_user_job.rb b/app/jobs/sync_phenglei_user_job.rb
index 1e597ef8..4cf56e35 100644
--- a/app/jobs/sync_phenglei_user_job.rb
+++ b/app/jobs/sync_phenglei_user_job.rb
@@ -1,7 +1,8 @@
class SyncPhengleiUserJob < ApplicationJob
queue_as :default
- def perform(project_id)
+ def perform(project_id=nil)
+ project_id ||= EduSetting.get("sync_phenglei_user_project")
project = Project.find_by_id(project_id)
return if project.nil?
member_count, success_count, error_count, not_exsit_count = 0, 0, 0, 0
diff --git a/app/models/phenglei_user.rb b/app/models/phenglei_user.rb
new file mode 100644
index 00000000..5adcfac7
--- /dev/null
+++ b/app/models/phenglei_user.rb
@@ -0,0 +1,18 @@
+# == Schema Information
+#
+# Table name: phenglei_users
+#
+# id :integer not null, primary key
+# phone :string(255)
+# created_at :datetime not null
+# updated_at :datetime not null
+#
+
+class PhengleiUser < ApplicationRecord
+
+ validates :phone, uniqueness: true
+
+ def register
+ User.find_by(phone: self.phone)
+ end
+end
diff --git a/app/views/admins/phenglei_users/index.html.erb b/app/views/admins/phenglei_users/index.html.erb
new file mode 100644
index 00000000..7c964e08
--- /dev/null
+++ b/app/views/admins/phenglei_users/index.html.erb
@@ -0,0 +1,19 @@
+<% define_admin_breadcrumbs do %>
+ <% add_admin_breadcrumb('风雷意向用户管理', admins_phenglei_users_path) %>
+<% end %>
+
+
+ <%= form_tag(admins_phenglei_users_path, method: :get, class: 'form-inline search-form flex-1', remote: true) do %>
+ <%= text_field_tag(:keyword, params[:keyword], class: 'form-control col-sm-2 ml-3', placeholder: '手机号检索') %>
+
+ <%= submit_tag('搜索', class: 'btn btn-primary ml-3', 'data-disable-with': '搜索中...') %>
+ <%= link_to "同步", sync_phenglei_user_admins_project_path(@phenglei_project.id), method: :get, data: {confirm: "确认同步吗?"}, class: "btn btn-primary pull-right ml-3", "data-disabled-with":"...同步" %>
+ <% end %>
+ <%= link_to "新增", new_admins_phenglei_user_path, remote: true, class: "btn btn-primary ml-3", "data-disabled-with":"...新增" %>
+
+
+
+ <%= render partial: 'admins/phenglei_users/shared/list', locals: { phenglei_users: @phenglei_users } %>
+
+
+
\ No newline at end of file
diff --git a/app/views/admins/phenglei_users/index.js.erb b/app/views/admins/phenglei_users/index.js.erb
new file mode 100644
index 00000000..57c52106
--- /dev/null
+++ b/app/views/admins/phenglei_users/index.js.erb
@@ -0,0 +1 @@
+$('.phenglei-users-list-container').html("<%= j( render partial: 'admins/phenglei_users/shared/list', locals: { phenglei_users: @phenglei_users } ) %>");
\ No newline at end of file
diff --git a/app/views/admins/phenglei_users/new.js.erb b/app/views/admins/phenglei_users/new.js.erb
new file mode 100644
index 00000000..2829f93b
--- /dev/null
+++ b/app/views/admins/phenglei_users/new.js.erb
@@ -0,0 +1,2 @@
+$("#phenglei-users-modals").html("<%= j render(partial: 'admins/phenglei_users/shared/create_form_modal') %>")
+$(".phenglei-user-create-modal").modal('show');
\ No newline at end of file
diff --git a/app/views/admins/phenglei_users/shared/_create_form_modal.html.erb b/app/views/admins/phenglei_users/shared/_create_form_modal.html.erb
new file mode 100644
index 00000000..76198260
--- /dev/null
+++ b/app/views/admins/phenglei_users/shared/_create_form_modal.html.erb
@@ -0,0 +1,21 @@
+
+
+
+
+ <%= form_for @phenglei_user, url: {controller: "phenglei_users", action: 'create'} do |p| %>
+
+ <%= p.text_field :phone, class: "form-control input-lg",placeholder: "手机号",required: true, maxlength: 64%>
+
+
+ <% end %>
+
+
+
\ No newline at end of file
diff --git a/app/views/admins/phenglei_users/shared/_list.html.erb b/app/views/admins/phenglei_users/shared/_list.html.erb
new file mode 100644
index 00000000..1f64f044
--- /dev/null
+++ b/app/views/admins/phenglei_users/shared/_list.html.erb
@@ -0,0 +1,30 @@
+
+
+
+ 序号 |
+ 手机号码 |
+ 状态 |
+
+
+
+ <% if phenglei_users.present? %>
+ <% phenglei_users.each_with_index do |user, index| %>
+
+ <%= list_index_no((params[:page] || 1).to_i, index) %> |
+ <%= overflow_hidden_span display_text(user.phone), width: 100 %> |
+
+ <% if user.register.present? %>
+ <%= @phenglei_project.member?(user.register.id) ? "已同步" : "未同步" %>
+ <% else %>
+ 未注册
+ <% end %>
+ |
+
+ <% end %>
+ <% else %>
+ <%= render 'admins/shared/no_data_for_table' %>
+ <% end %>
+
+
+
+<%= render partial: 'admins/shared/paginate', locals: { objects: phenglei_users } %>
diff --git a/app/views/admins/projects/shared/_list.html.erb b/app/views/admins/projects/shared/_list.html.erb
index eafa4d79..d4fa5a42 100644
--- a/app/views/admins/projects/shared/_list.html.erb
+++ b/app/views/admins/projects/shared/_list.html.erb
@@ -39,9 +39,6 @@
<%= project.created_on&.strftime('%Y-%m-%d %H:%M') %> |
- <% if project.is_secret %>
- <%= link_to "同步", sync_phenglei_user_admins_project_path(project.id), method: :get, data:{confirm: "确认同步吗?"}, class: "sync-phenglei-user-project-action" %>
- <% end %>
<%= link_to "删除", admins_project_path(project.id), method: :delete, data:{confirm: "确认删除的吗?"}, class: "delete-project-action" %>
|
diff --git a/app/views/admins/shared/_sidebar.html.erb b/app/views/admins/shared/_sidebar.html.erb
index c72ce593..2524451c 100644
--- a/app/views/admins/shared/_sidebar.html.erb
+++ b/app/views/admins/shared/_sidebar.html.erb
@@ -17,6 +17,7 @@
<%= sidebar_item_group('#user-submenu', '用户', icon: 'user') do %>
<%= sidebar_item(admins_users_path, '用户列表', icon: 'user', controller: 'admins-users') %>
+ <%= sidebar_item(admins_phenglei_users_path, '风雷意向用户列表', icon: 'user', controller: 'admins-phenglei_users') %>
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index bd071f78..9ca12ef0 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -647,6 +647,7 @@ Rails.application.routes.draw do
post :reset_login_times
end
end
+ resources :phenglei_users, only: [:index, :new, :create]
resource :import_disciplines, only: [:create]
resource :import_users, only: [:create]
resource :import_course_members, only: [:create]
diff --git a/config/sidekiq_cron.yml b/config/sidekiq_cron.yml
index 3e807fa1..880843ce 100644
--- a/config/sidekiq_cron.yml
+++ b/config/sidekiq_cron.yml
@@ -2,3 +2,7 @@ sync_gitea_repo_update_time:
cron: "0 0 * * *"
class: "SyncRepoUpdateTimeJob"
queue: default
+sync_phenglei_user:
+ cron: "0 23 * * *"
+ class: "SyncPhengleiUserJob"
+ queue: default
\ No newline at end of file
diff --git a/db/migrate/20210310012914_create_phenglei_users.rb b/db/migrate/20210310012914_create_phenglei_users.rb
new file mode 100644
index 00000000..fee06520
--- /dev/null
+++ b/db/migrate/20210310012914_create_phenglei_users.rb
@@ -0,0 +1,15 @@
+class CreatePhengleiUsers < ActiveRecord::Migration[5.2]
+ def change
+ create_table :phenglei_users do |t|
+ t.string :phone
+
+ t.timestamps
+ end
+ doc = SimpleXlsxReader.open("#{Rails.root}/public/phenglei_user.xlsx")
+ data = doc.sheets.first.rows
+ data.each_with_index do |i, index|
+ next if index == 0 || i[1].nil?
+ PhengleiUser.find_or_create_by(phone: i[1])
+ end
+ end
+end
diff --git a/spec/models/phenglei_user_spec.rb b/spec/models/phenglei_user_spec.rb
new file mode 100644
index 00000000..9fa273fe
--- /dev/null
+++ b/spec/models/phenglei_user_spec.rb
@@ -0,0 +1,5 @@
+require 'rails_helper'
+
+RSpec.describe PhengleiUser, type: :model do
+ pending "add some examples to (or delete) #{__FILE__}"
+end