Skip to content

Commit

Permalink
add meger
Browse files Browse the repository at this point in the history
  • Loading branch information
gilbertz committed Jun 25, 2015
2 parents 29d940b + 073827e commit b719d83
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 900 deletions.
1 change: 0 additions & 1 deletion app/api/customer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class Root < Grape::API
def current_user
p "User.current_user = #{User.current_user.to_json}"
User.by_openid(request.headers["Wps"])
User.find_by(7)
end

def current_material
Expand Down
58 changes: 53 additions & 5 deletions app/api/material/customer_teamwork_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def self_in_teamwork(user_id,matterial_id)
def reset_teamwork_partners(teamwork,matterial_id)
if teamwork
arr = teamwork.partners
arr.each { |item| $redis.set(teamwork_key(item.to_i,matterial_id),nil) }
arr.each { |item| $redis.del(teamwork_key(item.to_i,matterial_id)) }
end
end

Expand Down Expand Up @@ -50,6 +50,46 @@ def teamwork_can_json?(teamwork)
false
end

def join_teamwork_time_key(teamwork_id,user_id)
"join_teamwork_time_key_#{teamwork_id}_#{user_id}"
end

def get_join_teamwork_time(teamwork_id,user_id)
$redis.get(join_teamwork_time_key(teamwork_id,user_id))
end

def set_join_teamwork_time(teamwork_id,user_id)
i = Time.now.to_i
$redis.set(join_teamwork_time_key(teamwork_id,user_id),i)
end


def deal_expire_user(teamwork_id,user_id)
teamwork = Teamwork.find_by_id(teamwork_id)
p "teamwork = #{teamwork.to_json}"
if teamwork.is_over? == false
arr = teamwork.partners
u = arr.last.to_i
if (teamwork.get_result_percent(arr.last)).to_f <= 0.0 && u != user_id.to_i && u != teamwork.sponsor.to_i
last_time = get_join_teamwork_time(teamwork.id,u)
now_time = Time.now.to_i
p "last_time = #{last_time}"
if last_time != nil && now_time - last_time.to_i > 60
teamwork.set_result_percent(u,0)
arr.pop
teamwork.partner = arr.join(',')
if teamwork.save
p "now teamwork = #{teamwork}"
$redis.del(teamwork_key(u,current_material.id))
$redis.del(last_teamwork_key(u, current_material.id))
return teamwork
end
end
end

end
end

end

#------------------resources material------------------
Expand Down Expand Up @@ -80,6 +120,10 @@ def teamwork_can_json?(teamwork)
if from_user && from_user.id != current_user.id
@flag = 1
@teamwork = self_in_teamwork(from_user.id,@material.id)
x = deal_expire_user(@teamwork.id,current_user.id)
if x
@teamwork = x
end
# 访问排重
lock_key = $redis.get(teamwork_lock_key(@teamwork.id,@material.id))
p "fromuser = #{from_user.to_json} can join #{teamwork_can_json?(@teamwork)}"
Expand All @@ -90,12 +134,13 @@ def teamwork_can_json?(teamwork)
$redis.set(last_teamwork_key(current_user.id, @material.id),@teamwork.id)
$redis.set(teamwork_key(current_user.id, @material.id),@teamwork.id)
@partner_users = @teamwork.partner_users
set_join_teamwork_time(@teamwork.id,current_user.id)
end
# teamwork 已经不存在了
else
@flag = 3
end
$redis.set(teamwork_lock_key(@teamwork.id,@material.id),nil)
$redis.del(teamwork_lock_key(@teamwork.id,@material.id))
#自己创建一个
else
@flag = 2
Expand Down Expand Up @@ -129,9 +174,13 @@ def teamwork_can_json?(teamwork)
# 团队协作类型的模版
if @category.game_type_id = 17
team_id = $redis.get(last_teamwork_key(current_user.id,@material.id))
if team_id
@exist_teamwork = Teamwork.find_by_id(team_id)
if team_id && team_id.to_i > 0
@exist_teamwork = Teamwork.find_by_id(team_id.to_i)
if @exist_teamwork
t = deal_expire_user(@exist_teamwork.id,current_user.id)
if t
@exist_teamwork = t
end
@partner_users = @exist_teamwork.partner_users
@ower = current_user
end
Expand Down Expand Up @@ -197,7 +246,6 @@ def teamwork_can_json?(teamwork)
end
end


end

end
Expand Down
5 changes: 2 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,13 @@ def set_weixin_config

if params[:token]
#p "last current_user = #{User.current_user.to_json}"
unless current_user
# unless current_user
au = Authentication.find_by_uid(params[:token])
user = User.find au.user_id if au
sign_in user

User.current_user = user
# p "set_weixin_config User.current_user = #{User.current_user.to_json}"
end
# end
end
# end
end
Expand Down
14 changes: 8 additions & 6 deletions app/controllers/weitest_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -231,15 +231,17 @@ def game_report
t_num = 4
if current_user and current_user.social_value(@beacon.id) == 0
Record.create(:user_id => current_user.id, :from_user_id => params[:from_user_id], :beaconid=>@beacon.id, :game_id => params[:game_id], :sn=>params[:sn], :score => params[:score], :remark=>params[:remark])
from_user = User.find_by_id( params[:from_user_id] )
if params[:score].to_i >= t_score
if current_user.social_value(@beacon.id) <= 0
current_user.incr_social(@beacon.id)
current_user.update_records(@beacon.id)
if params[:from_user_id]
from_user = User.find_by_id( params[:from_user_id] )
if params[:score].to_i >= t_score
if current_user.social_value(@beacon.id) <= 0
current_user.incr_social(@beacon.id)
current_user.update_records(@beacon.id)
end
from_user.resend_redpack(params[:game_id], @beacon.id)
end
from_user.resend_redpack(params[:game_id], @beacon.id)
end
from_user.resend_redpack(params[:game_id], @beacon.id)
end
render nothing: true
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/teamwork.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,10 @@ def set_result_percent(user_id,percent)


def rand_result_percent(user_id,num,is_sponsor = false)
p = self.probability
material= self.material
p = material.probability
up = (get_user_percent(user_id)).to_f
interval = (1.0 / self.team_persons * 0.9)
interval = (1.0 / material.team_persons * 0.9)
min = up - up * interval
max = up + up * interval
num = 1000 - rand(100) if num < 1000
Expand All @@ -181,7 +182,7 @@ def rand_result_percent(user_id,num,is_sponsor = false)
def get_result_percent(user_id)
if user_id
index = partners.index user_id.to_s
p "partners = #{partners} and index = #{index}"
# p "partners = #{partners} and index = #{index}"
r = results
if r && index
r[index]
Expand Down
19 changes: 19 additions & 0 deletions app/workers/teamwork_send_redpack_work.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require File.expand_path('../base_worker',__FILE__)

class TeamworkSendRedpackWork < BaseWorker

def perform(teamwork)
return unless teamwork
return if teamwork.is_successful? == false
#发钱
material = teamwork.material
money = material.team_reward / material.team_persons
arr = teamwork.partner_users
for i in 0...arr.count


end

end

end
2 changes: 1 addition & 1 deletion config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# Use a different logger for distributed setups.
# config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new)
#config.logger = Logger.new("#{Rails.root}/log/#{Rails.env}-#{Date.today.to_s}.log", "daily")
config.log_level = :info
config.log_level = :debug

# Use a different cache store in production.
# config.cache_store = :mem_cache_store
Expand Down
4 changes: 2 additions & 2 deletions config/initializers/weixin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@


WX_DOMAIN = 'dapeimishu.com'
WX_APPID = 'wx456ffb04ee140d84'
WX_SECRET= 'd1481d1ff0f05d0234a391cfc1c2a4b3'
WX_APPID = 'wx629a5ad4f3fc5f63'
WX_SECRET= '843d5cb0b87561e54c644327bd297f10'

else
#摇生意
Expand Down
Loading

0 comments on commit b719d83

Please sign in to comment.