Skip to content

Instantly share code, notes, and snippets.

@yangxing-star
Created November 28, 2014 03:34
Show Gist options
  • Save yangxing-star/e684f283a3bee111f6d8 to your computer and use it in GitHub Desktop.
Save yangxing-star/e684f283a3bee111f6d8 to your computer and use it in GitHub Desktop.
修复绩效计算错误
Customer.where('import_at >= "2014-09-01 00:00:00"').each do |c|
ActiveRecord::Base.transaction do
create_date = c.created_at.strftime('%Y-%m-%d')
if (c.created_at..(c.created_at+1.day)).cover?(c.import_at)
AchievementRecord.create( user: c.user,
mobile: c.mobile,
status: c.status,
category: :newly,
created_at: c.import_at,
updated_at: c.import_at )
AchievementCount.incr(c.user, :newly_count, create_date)
else
if c.is_inactive_status?
AchievementRecord.create( user: c.user,
mobile: c.mobile,
status: c.status,
category: :info,
created_at: c.import_at,
updated_at: c.import_at )
AchievementCount.incr(c.user, :info_count, create_date)
end
end
if c.is_loss_status?
AchievementRecord.create( user: c.user,
mobile: c.mobile,
status: c.status,
category: :maintain,
maintain_type: 3,
created_at: c.import_at,
updated_at: c.import_at ) # 新录入
AchievementCount.incr(c.user, :maintain_count, create_date)
end
if c.is_active_status?
AchievementRecord.create( user: c.user,
mobile: c.mobile,
status: c.status,
category: :info,
created_at: c.import_at,
updated_at: c.import_at )
AchievementCount.incr(c.user, :info_count, create_date)
end
if c.career.owner?
if c.photos.count > 1
AchievementRecord.create( user: c.user,
mobile: c.mobile,
status: c.status,
category: :certificate,
created_at: c.import_at,
updated_at: c.import_at )
AchievementCount.incr(c.user, :certificate_count, create_date)
end
end
end
end
# ------------------------------------------------------------------------------
Communication.where('created_at >= "2014-09-01 00:00:00"').all.each do |c|
create_date = c.created_at.strftime('%Y-%m-%d')
# 查询出当天和客户的第一条沟通记录
first_communication = AchievementRecord.between_date(create_date, create_date)
.where(is_process: false, maintain_type: 1, mobile: c.mobile).first
maintain_type = first_communication.nil? ? 1 : 2
# 实时查询客户的状态,如果流失则增加维护记录
customer_status = begin
resp = Nestful.post "#{GATEWAY_URL}/crm/getLoginDate", { mobile: c.mobile, date: create_date }, { timeout: 3 }
resp.decoded['data']['status']
rescue Exception => e
nil
end
if customer_status == 0
ActiveRecord::Base.transaction do
AchievementRecord.create( user_id: c.user_id,
mobile: c.mobile,
status: :loss,
category: :maintain,
maintain_type: maintain_type,
created_at: c.created_at,
updated_at: c.updated_at )
AchievementCount.incr(c.user, :maintain_count, create_date)
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment