销售人员跟踪客户的新增局部刷新,销售人员和客户、院校的数据唯一性

sso
cxt 5 years ago
parent d6dc81692a
commit ba91e20f85

@ -58,7 +58,7 @@ $(document).on('turbolinks:load', function() {
$addMemberModal.modal('hide');
setTimeout(function(){
window.location.reload();
listForm();
}, 500);
},
error: function(res){
@ -70,5 +70,13 @@ $(document).on('turbolinks:load', function() {
$addMemberModal.modal('hide');
}
});
var listForm = function(){
$.ajax({
url: '/admins/salesman_customers?salesman_id='+ $salesmanIdInput.data("salesman-id"),
dataType: "script"
});
};
}
});

@ -15,7 +15,7 @@ class Admins::SalesmanChannelsController < Admins::BaseController
school_ids = params[:school_ids] - channel_ids
school_ids.each do |school_id|
school = School.find_by(id: school_id)
next if school.blank?
next if school.blank? || @salesman.salesman_channels.where(school_id: school.id).exists?
@salesman.salesman_channels.create!(school_id: school.id)
end
render_ok

@ -10,7 +10,7 @@ class Admins::SalesmanCustomersController < Admins::BaseController
user_ids = params[:user_ids] - customer_ids
user_ids.each do |user_id|
user = UserExtension.find_by(user_id: user_id)
next if user.blank?
next if user.blank? || @salesman.salesman_customers.where(user_id: user.user_id).exists?
@salesman.salesman_customers.create!(user_id: user.user_id, school_id: user.school_id)
end
render_ok

@ -1,6 +1,6 @@
class SalesmanCustomer < ApplicationRecord
belongs_to :salesman, :touch => true, counter_cache: true
belongs_to :school
belongs_to :school, optional: true
belongs_to :user
def name
@ -8,7 +8,7 @@ class SalesmanCustomer < ApplicationRecord
end
def school_name
school.name
school&.name
end
def courses_count

@ -0,0 +1 @@
$(".salesman-customer-list-container").html("<%= j(render partial: 'admins/salesman_customers/shared/list') %>")

@ -0,0 +1,10 @@
class AddUniqIndexToSalesmanChannel < ActiveRecord::Migration[5.2]
def change
sql = %Q(delete from salesman_channels where (salesman_id, school_id) in
(select * from (select salesman_id, school_id from salesman_channels group by salesman_id, school_id having count(*) > 1) a)
and id not in (select * from (select min(id) from salesman_channels group by salesman_id, school_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :salesman_channels, [:salesman_id, :school_id], unique: true
end
end

@ -0,0 +1,10 @@
class AddUniqIndexToSalesmanCustomer < ActiveRecord::Migration[5.2]
def change
sql = %Q(delete from salesman_customers where (salesman_id, user_id) in
(select * from (select salesman_id, user_id from salesman_customers group by salesman_id, user_id having count(*) > 1) a)
and id not in (select * from (select min(id) from salesman_customers group by salesman_id, user_id having count(*) > 1 order by id) b))
ActiveRecord::Base.connection.execute sql
add_index :salesman_customers, [:salesman_id, :user_id], unique: true
end
end
Loading…
Cancel
Save