blsm-vd-core 0.9.5 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8483c659e2aa1e69e0841c2d46b53329a2a40054
4
- data.tar.gz: 5d81f228f47615695f647208f93cd0475e1b838b
3
+ metadata.gz: 506ed800cbf0a0ad0ebbf04eb1866d08bc4bacfd
4
+ data.tar.gz: aaf8d8a4bc560b21c0983e93348e95087cc8b2b0
5
5
  SHA512:
6
- metadata.gz: b3f4810648009a763b42960a02c52d7c14c481e6fc733aafbc7b1fa0630d6869f6b6df7b278fcb9e44060c3058246177a63bb1d05ae4c9208fd907c4d2d9d331
7
- data.tar.gz: 24aed0b491940194353a944d29fc87ec08142cb339e68ef722895ca3cf9c20246fce8a93f8cd10b49c275dae5c323e5aa42545bbc5b8f498ab578c6915372a4d
6
+ metadata.gz: 9bc1318738a9ec678774d8ef350bffbcd038f059e9ba601cf6f611a37ff2929872b7ce187e8bf9bf49e53689e75970730ed6a9cbea44202f7f19448ed8b65051
7
+ data.tar.gz: 19f367c2be4f0c7654035efd559470ce0db8d9774b903d504a571323f796022dae5f9a2685182a95352b9ee06049e264306b2ce41dca267e87eac3257a45808b
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blsm-vd-core (0.9.5)
4
+ blsm-vd-core (0.9.7)
5
5
 
6
6
  GEM
7
7
  remote: https://ruby.taobao.org/
data/lib/blsm-vd-core.rb CHANGED
@@ -29,6 +29,9 @@ require 'blsm-vd-core/model/user_spread'
29
29
  require 'blsm-vd-core/model/shippingorder'
30
30
  require 'blsm-vd-core/model/vd_free_post'
31
31
  require 'blsm-vd-core/model/vd_purchase_fee_log'
32
+ require 'blsm-vd-core/model/vd_invite_reward'
33
+ require 'blsm-vd-core/model/vd_week_order_sale'
34
+ require 'blsm-vd-core/model/vd_week_sale'
32
35
  require 'faraday'
33
36
  require 'blsm-mp-wx'
34
37
 
@@ -510,7 +513,7 @@ module BlsmVdCore
510
513
  })
511
514
  seller_info.update_attributes(:purchase_fee => (seller_info.purchase_fee - earn_amount))
512
515
  #进货费变动记录
513
- VdPurchaseFeeLog.create(:user_id=>seller.id,:purchase_fee=>-earn_amount,:description=>"订单完成,系统扣除",:admin_user_id=>3)
516
+ VdPurchaseFeeLog.create(:user_id => seller.id, :purchase_fee => -earn_amount, :description => "订单完成,系统扣除", :admin_user_id => 3)
514
517
  #通知用户
515
518
  fee_content = "亲爱的店主#{seller.username}:订单已经签收成功,您的优店管家—店主信息—进货费#{franchise_price}元,抵扣#{earn_amount},时间#{Time.now.strftime("%F %H:%M:%S")}"
516
519
  if !seller.rc_user.blank?
@@ -537,8 +540,8 @@ module BlsmVdCore
537
540
 
538
541
  # 给邀请人奖励
539
542
  inviter = User.where(:invication_code => seller.invicated_from).first if seller.invicated_from
540
- #被邀请人,金牌店主以下,渠道邀请,邀请人不为空,一个订单只能有一个结算项
541
- if inviter && seller_info.distribute_sum < 1500 && seller_info.channel == "market_invite"
543
+ #【旧版邀请】被邀请人,金牌店主以下,渠道邀请,邀请人不为空,一个订单只能有一个结算项
544
+ if inviter && seller_info.created_at.to_s < Setting.old_invite_reward_expired_at && seller_info.distribute_sum < 1500 && seller_info.channel == "market_invite"
542
545
 
543
546
  #发送给邀请人微信提醒
544
547
  content = "您邀请的店主 #{seller.username}(注册电话号为#{seller.phone})与#{Time.now.strftime("%Y-%m-%d %H:%M:%S")}成功成交一笔订单,订单金额为#{order.total_fee.to_f}元, 您将同步获取邀请奖励#{(order.total_fee.to_f * 0.1).round(2)}元,特此通知"
@@ -573,7 +576,6 @@ module BlsmVdCore
573
576
  end
574
577
  end
575
578
 
576
-
577
579
  #安全库录入信息
578
580
  VdInfoSec.committed(vd_transaction)
579
581
 
@@ -702,4 +704,118 @@ module BlsmVdCore
702
704
 
703
705
  end
704
706
 
707
+
708
+ #结算项变为物流返款时调用此方法
709
+ def on_clearing_item_cash_back(clearing_item_id)
710
+ clearing_item = ClearingItem.where(id: clearing_item_id).first
711
+ return ERROR_CODES[0] if !clearing_item || clearing_item.state!='CASH_BACK' || clearing_item.earn_amount.to_f < 0
712
+ order = clearing_item.order
713
+ return ERROR_CODES[0] if !order || order.ubox_order?
714
+ invitee = clearing_item.user
715
+ return ERROR_CODES[0] unless invitee
716
+ inviter = invitee.sq_inviter
717
+
718
+ return ERROR_CODES[4010] if VdInviteReward.where(order_id: order.id).first
719
+
720
+ vd_transaction = "clearing_item_cash_back_#{clearing_item_id}"
721
+ return ERROR_CODES[4010] if VdInfoSec.dangerous?(vd_transaction)
722
+
723
+ reward = 0
724
+ LineItem.where(:order_id => order.id).each do |line_item|
725
+ product_prop = line_item.product_prop
726
+ reward += line_item.quantity*product_prop.inviter_reward if !product_prop.blank?
727
+ end
728
+
729
+ if reward > 0
730
+ week = current_week_period_str #物流返款按自然周返款统计奖金金额
731
+ VdInviteReward.create({inviter_id: inviter.id, invitee_id: invitee.id, order_id: order.id, reward: reward, week: week})
732
+ end
733
+
734
+ #安全库录入信息
735
+ VdInfoSec.committed(vd_transaction)
736
+
737
+ ERROR_CODES[200]
738
+ end
739
+
740
+
741
+ #订单发货以后(通过首趣码邀请的回调)
742
+ def sq_invite_on_order_delivering(seller_id, order_id)
743
+ seller = User.where(id: seller_id).first
744
+ order = Order.where(id: order_id).first
745
+ clearing_item = ClearingItem.where(order_id: order_id).first
746
+
747
+ return ERROR_CODES[4045] unless seller
748
+ return ERROR_CODES[0] if !order || order.ubox_order? || order.shippingorder_id.to_i <= 0
749
+ return ERROR_CODES[0] unless clearing_item
750
+
751
+ vd_transaction = "on_order_delivering_#{seller_id}_#{order_id}"
752
+ return ERROR_CODES[4010] if VdInfoSec.dangerous?(vd_transaction)
753
+
754
+ wday = Time.now.wday #今天星期几,上一周确认的订单,并且在周二凌晨前发货的订单 上一周销售额 否则算下一周 销售额
755
+ week = wday==1 && clearing_item.created_at < (Time.now - 7.day).at_end_of_week ? last_week_period_str : current_week_period_str
756
+
757
+
758
+ os = VdWeekOrderSale.where(order_id: order.id).first
759
+ os.update_attributes({user_id: seller.id, week: week, sale_sum: order.total_fee}) if os
760
+ VdWeekOrderSale.create({order_id: order.id, user_id: seller.id, week: week, sale_sum: order.total_fee}) unless os
761
+
762
+ ws = VdWeekSale.where(user_id: seller.id, week: week).first
763
+ ws.update_attributes({sale_sum: VdWeekOrderSale.where(week: week, user_id: seller_id).sum(:sale_sum)}) if ws
764
+ VdWeekSale.create({user_id: seller.id, week: week, sale_sum: VdWeekOrderSale.where(week: week, user_id: seller_id).sum(:sale_sum)}) unless ws
765
+
766
+ #安全库录入信息
767
+ VdInfoSec.committed(vd_transaction)
768
+
769
+ ERROR_CODES[200]
770
+ end
771
+
772
+ #订单拒签以后(通过首趣码邀请的回调)
773
+ def sq_invite_on_order_rejecting(seller_id, order_id)
774
+ seller = User.where(id: seller_id).first
775
+ order = Order.where(id: order_id).first
776
+ clearing_item = ClearingItem.where(order_id: order_id).first
777
+
778
+ return ERROR_CODES[4045] unless seller
779
+ return ERROR_CODES[0] if !order || order.ubox_order?
780
+ return ERROR_CODES[0] unless clearing_item
781
+
782
+ vd_transaction = "on_order_rejecting_#{seller_id}_#{order_id}"
783
+ return ERROR_CODES[4010] if VdInfoSec.dangerous?(vd_transaction)
784
+
785
+ wday = Time.now.wday #今天星期几,上一周确认的订单,并且在周二凌晨前拒签的订单 上一周销售额 否则算下一周 销售额
786
+ week = wday==1 && clearing_item.created_at < (Time.now - 7.day).at_end_of_week ? last_week_period_str : current_week_period_str
787
+
788
+ os = VdWeekOrderSale.where(order_id: order.id, reject: 0).first #非拒签记录
789
+ os2 = VdWeekOrderSale.where(order_id: order.id, reject: 1).first #拒签记录
790
+
791
+ if os || (os2 && os2.sale_sum>0)
792
+ VdWeekOrderSale.create({order_id: order.id, user_id: seller.id, week: week, sale_sum: -order.total_fee, reject: 1})
793
+ elsif !os && !os2
794
+ VdWeekOrderSale.create({order_id: order.id, user_id: seller.id, week: week, sale_sum: 0, reject: 1})
795
+ end
796
+
797
+ ws = VdWeekSale.where(user_id: seller.id, week: week).first
798
+ ws.update_attributes({sale_sum: VdWeekOrderSale.where(week: week, user_id: seller_id).sum(:sale_sum)}) if ws
799
+ VdWeekSale.create({user_id: seller.id, week: week, sale_sum: VdWeekOrderSale.where(week: week, user_id: seller_id).sum(:sale_sum)}) unless ws
800
+
801
+ #安全库录入信息
802
+ VdInfoSec.committed(vd_transaction)
803
+
804
+ ERROR_CODES[200]
805
+ end
806
+
807
+
808
+ #上一周
809
+ def last_week_period_str
810
+ t = Time.now - 7.day
811
+ "#{t.strftime('%Y')}-#{t.at_beginning_of_week.strftime("%m%d")}-#{t.at_end_of_week.strftime("%m%d")}"
812
+ end
813
+
814
+ #这一周
815
+ def current_week_period_str
816
+ t = Time.now
817
+ "#{t.strftime('%Y')}-#{t.at_beginning_of_week.strftime("%m%d")}-#{t.at_end_of_week.strftime("%m%d")}"
818
+ end
819
+
820
+
705
821
  end
@@ -6,6 +6,8 @@ module BlsmVdCore
6
6
  belongs_to :order, class_name: "::BlsmVdCore::Order"
7
7
  belongs_to :clearing, class_name: "::BlsmVdCore::Clearing"
8
8
 
9
+ after_update :keep_commit_changes
10
+ after_commit :after_clearing_item_changed
9
11
  #物流服务费
10
12
  def express_service_fee
11
13
  if self.pay_type=='CODPAY'
@@ -47,5 +49,19 @@ module BlsmVdCore
47
49
  update_params[:real_amount] = ((self.order.toggle_delivery_deposit && self.order.pay_type.to_i==1) ? (self.order.actual_total.to_f+self.order.payment_total.to_f) : self.order.actual_total)
48
50
  self.update_attributes(update_params)
49
51
  end
52
+
53
+
54
+ #发生改变之后,记住状态的变化
55
+ def keep_commit_changes
56
+ @committed_changes = self.changes
57
+ end
58
+
59
+ #订单发生变化
60
+ def after_clearing_item_changed
61
+ if @committed_changes && !@committed_changes.empty?
62
+ BlsmVdCore.on_clearing_item_cash_back(self.id) if @committed_changes.has_key?('state') #物流返款等信息
63
+ @committed_changes.clear
64
+ end
65
+ end
50
66
  end
51
67
  end
@@ -14,14 +14,19 @@ module BlsmVdCore
14
14
 
15
15
  public
16
16
  def get_vd_score(role)
17
- column = "black" == role ? "black_belt_rate" : "ordinary_rate"
18
17
  fee = 0.0
19
- self.line_items.each do |item|
20
- next if item.product_prop.nil?
21
- rate = item.product_prop.send(column)
22
- rate = VdUserScore::SCORES[:SALE_OUT_DIRECT] if rate.nil? && "normal" == role
23
- rate = VdUserScore::SCORES[:SALE_OUT_INDIRECT] if rate.nil? && "black" == role
24
- fee += ((item.quantity * item.franchise_price.to_f) * rate)
18
+ if "black" == role
19
+ self.line_items.each do |item|
20
+ next if item.product_prop.nil?
21
+ fee += item.quantity * item.product_prop.black_integral
22
+ end
23
+ else
24
+ self.line_items.each do |item|
25
+ next if item.product_prop.nil?
26
+ rate = item.product_prop.ordinary_rate
27
+ rate = VdUserScore::SCORES[:SALE_OUT_DIRECT] if rate.nil? && "normal" == role
28
+ fee += ((item.quantity * item.franchise_price.to_f) * rate)
29
+ end
25
30
  end
26
31
  sprintf('%0.2f', fee.to_f).to_f
27
32
  end
@@ -11,5 +11,10 @@ module BlsmVdCore
11
11
  array = setting.split('|')
12
12
  {order_money: array[0].to_i, reward_money: array[1].to_i}
13
13
  end
14
+
15
+ #老版的邀请奖励
16
+ def self.old_invite_reward_expired_at
17
+ Setting.where(name: 'vd_old_invite_reward_expired_at').pluck(:value)[0].to_s
18
+ end
14
19
  end
15
20
  end
@@ -7,6 +7,7 @@ module BlsmVdCore
7
7
  has_many :clearings, class_name: "::BlsmVdCore::Clearing"
8
8
  has_one :vd_user_info, class_name: "::BlsmVdCore::VdUserInfo"
9
9
  belongs_to :rc_user, class_name: "::BlsmVdCore::RcUser"
10
+ belongs_to :sq_inviter, class_name: '::BlsmVdCore::User', foreign_key: 'sq_from', primary_key: 'sq_code'
10
11
 
11
12
  def create_vd_user_info
12
13
  unless self.vd_user_info
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ module BlsmVdCore
3
+ class VdInviteReward < BlsmVdCore::BaseRecord
4
+ self.table_name='vd_invite_rewards'
5
+ belongs_to :inviter, foreign_key: 'inviter_id', class_name: '::BlsmVdCore::User'
6
+ belongs_to :invitee, foreign_key: 'invitee_id', class_name: '::BlsmVdCore::User'
7
+ belongs_to :order, class_name: "::BlsmVdCore::Order"
8
+ belongs_to :clearing_item, class_name: "::BlsmVdCore::ClearingItem"
9
+
10
+ #week 格式:2017-0220-0226
11
+ before_create :generate_week
12
+
13
+ private
14
+
15
+ #默认生成上一周的week开始日+结束日
16
+ def generate_week
17
+ unless self.week
18
+ t = Time.now - 7.day
19
+ self.week = "#{t.strftime('%Y')}-#{t.at_beginning_of_week.strftime("%m%d")}-#{t.at_end_of_week.strftime("%m%d")}"
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ module BlsmVdCore
3
+ class VdWeekOrderSale < BlsmVdCore::BaseRecord
4
+ self.table_name='vd_week_order_sales'
5
+ belongs_to :order
6
+ before_create :generate_week
7
+ #week 格式:2017-0220-0226
8
+
9
+ private
10
+
11
+ #默认生成上一周的week开始日+结束日
12
+ def generate_week
13
+ unless self.week
14
+ t = Time.now - 7.day
15
+ self.week = "#{t.strftime('%Y')}-#{t.at_beginning_of_week.strftime("%m%d")}-#{t.at_end_of_week.strftime("%m%d")}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ module BlsmVdCore
3
+ class VdWeekSale < BlsmVdCore::BaseRecord
4
+ self.table_name='vd_week_sales'
5
+ belongs_to :user, class_name: "::BlsmVdCore::User"
6
+ before_create :generate_week
7
+ #week 格式:2017-0220-0226
8
+
9
+ private
10
+
11
+ #默认生成上一周的week开始日+结束日
12
+ def generate_week
13
+ unless self.week
14
+ t = Time.now - 7.day
15
+ self.week = "#{t.strftime('%Y')}-#{t.at_beginning_of_week.strftime("%m%d")}-#{t.at_end_of_week.strftime("%m%d")}"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -1,3 +1,3 @@
1
1
  module BlsmVdCore
2
- VERSION = "0.9.5"
2
+ VERSION = "0.9.7"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blsm-vd-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.5
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-02-21 00:00:00.000000000 Z
12
+ date: 2017-02-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -201,11 +201,14 @@ files:
201
201
  - lib/blsm-vd-core/model/user_spread.rb
202
202
  - lib/blsm-vd-core/model/vd_free_post.rb
203
203
  - lib/blsm-vd-core/model/vd_info_sec.rb
204
+ - lib/blsm-vd-core/model/vd_invite_reward.rb
204
205
  - lib/blsm-vd-core/model/vd_mp_msg.rb
205
206
  - lib/blsm-vd-core/model/vd_purchase_fee_log.rb
206
207
  - lib/blsm-vd-core/model/vd_rc_msg_notify.rb
207
208
  - lib/blsm-vd-core/model/vd_user_info.rb
208
209
  - lib/blsm-vd-core/model/vd_user_score.rb
210
+ - lib/blsm-vd-core/model/vd_week_order_sale.rb
211
+ - lib/blsm-vd-core/model/vd_week_sale.rb
209
212
  - lib/blsm-vd-core/model/vd_wx_pay.rb
210
213
  - lib/blsm-vd-core/version.rb
211
214
  homepage: https://bitbucket.org/Xiaopuzhu/blsm-vd-core