blsm-vd-core 0.8.7 → 0.8.8

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: 7418901e98965d96d06917fc0791c9b568936b33
4
- data.tar.gz: bf33a84b4e5466e64c71206020b6bcd80305e442
3
+ metadata.gz: 96a09005b55e480864d0ccd8d14b34ee09fabe7d
4
+ data.tar.gz: 58369f32ba270c58accab9ffcf77e0577eb6328f
5
5
  SHA512:
6
- metadata.gz: 0fbe8d8b8fdd3f6582c84e92143294a9b03541de02d8579d645538e611600ee9c3893dd98a8b74ec132a3e83f563c10db60a23d3ce45767c73fe9287a1e1642b
7
- data.tar.gz: 17ccc1b148c6456bb1dad36b330b1180ee7396c7aca281465710b395b782684e633cdba00916b7ca2755e1ab17cb8a29fe5258360f00f2a56306cb32ef639346
6
+ metadata.gz: 79a11de11b20e13fc1e6db9aab3cd49d8b7a00d165f69acd6497405647985f18431064a4842104684aae546dfe9bbd1cd06fec9ef42cd3f404cb20b29a5b6330
7
+ data.tar.gz: bcb618402d988a7bf116b798844877b03f0b059001538824f36f353f5f2f4607d7e84e1168b0702b29f820a4a161a3f00ea6e1f22bb7806dbce32e85d9e873c8
@@ -8,6 +8,7 @@ module BlsmVdCore
8
8
  belongs_to :application, class_name: "::BlsmVdCore::Application", foreign_key: "application_id"
9
9
  belongs_to :shippingorder, class_name: "::BlsmVdCore::Shippingorder", foreign_key: "shippingorder_id"
10
10
  belongs_to :ubox_vm, class_name: "::BlsmVdCore::UboxVm", foreign_key: 'ubox_vmid', primary_key: 'ubox_vmid'
11
+ has_one :vd_free_post,class_name: "::BlsmVdCore::VdFreePost"
11
12
 
12
13
  encrypted_id key: 'bYqILlFMZn3xd8Cy'
13
14
 
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ module BlsmVdCore
3
+ class VdFreePost < BlsmVdCore::BaseRecord
4
+ self.table_name='vd_free_posts'
5
+ belongs_to :user, class_name: "::BlsmVdCore::User"
6
+ belongs_to :order, class_name: "::BlsmVdCore::Order"
7
+
8
+ DEFAULT_EXPIRE_AT = '2017-01-20 15:30'
9
+
10
+ before_validation :gen_expire_at
11
+
12
+ def expired?
13
+ return false unless self.expire_at
14
+ return true if Time.now.strftime('%Y-%m-%d %H:%M:%S')> self.expire_at.strftime('%Y-%m-%d %H:%M:%S')
15
+ false
16
+ end
17
+
18
+ private
19
+ def gen_expire_at
20
+ unless self.expire_at
21
+ self.expire_at = VdFreePost::DEFAULT_EXPIRE_AT
22
+ end
23
+ end
24
+ end
25
+ end
@@ -1,3 +1,3 @@
1
1
  module BlsmVdCore
2
- VERSION = "0.8.7"
2
+ VERSION = "0.8.8"
3
3
  end
data/lib/blsm-vd-core.rb CHANGED
@@ -27,6 +27,7 @@ require 'blsm-vd-core/model/setting'
27
27
  require 'blsm-vd-core/model/recharge_spread'
28
28
  require 'blsm-vd-core/model/user_spread'
29
29
  require 'blsm-vd-core/model/shippingorder'
30
+ require 'blsm-vd-core/model/vd_free_post'
30
31
  require 'faraday'
31
32
  require 'blsm-mp-wx'
32
33
 
@@ -44,6 +45,9 @@ module BlsmVdCore
44
45
  4043 => {code: 4043, msg: '空订单'},
45
46
  4044 => {code: 4044, msg: '订单没有所属微店主'},
46
47
  4045 => {code: 4045, msg: '用户不存在'},
48
+ 4046 => {code: 4046, msg: 'setting值不存在'},
49
+ 4047 => {code: 4047, msg: 'setting规则不匹配'},
50
+ 4048 => {code: 4048, msg: 'setting值为空'},
47
51
 
48
52
  200 => {code: 200, msg: '成功'}
49
53
  }
@@ -78,12 +82,12 @@ module BlsmVdCore
78
82
 
79
83
  #订单被拒签=>创建shippingorder 拒签的记录
80
84
  if order.state.to_s.include?('客户拒签,原件返回')
81
- shippingorder = Shippingorder.where(:id=>order.shippingorder_id).first
85
+ shippingorder = Shippingorder.where(:id => order.shippingorder_id).first
82
86
  if shippingorder.blank?
83
- shippingorder = Shippingorder.create(:refuse_at=>Time.now)
84
- order.update_attributes(:shippingorder_id=>shippingorder.id)
87
+ shippingorder = Shippingorder.create(:refuse_at => Time.now)
88
+ order.update_attributes(:shippingorder_id => shippingorder.id)
85
89
  else
86
- shippingorder.update_attributes(:refuse_at=>Time.now)
90
+ shippingorder.update_attributes(:refuse_at => Time.now)
87
91
  end
88
92
  return
89
93
  end
@@ -95,16 +99,28 @@ module BlsmVdCore
95
99
  if order.application
96
100
  on_order_sale_out(order.application.user_id, order_id)
97
101
  #订单完成, 发送融云消息, 给邀请人奖励
98
- user = order.application.user
102
+ user = order.application.user
99
103
  if !user.blank?
100
104
  #订单完成, 发送融云消息
101
105
  if !user.rc_user.blank?
102
106
  VdRcMsgNotify.create_order_finish_notify(user.username)
103
107
  end
108
+ # 包邮券返款
109
+ if order.vd_free_post
110
+ ClearingItem.create({
111
+ state: 'CASH_BACK',
112
+ pay_type: "ZXZF",
113
+ user_id: user.id,
114
+ order_id: -14,
115
+ rate_of_profit: 1,
116
+ earn_amount: order.shipping_charge
117
+ })
118
+ end
119
+
104
120
  # 进货费返还
105
121
  user_info = user.create_vd_user_info
106
122
  if !order.line_items.blank? && user_info.purchase_fee > 0
107
- franchise_price = order.line_items.inject(0){|result,item| result+item.franchise_price*item.quantity}
123
+ franchise_price = order.line_items.inject(0) { |result, item| result+item.franchise_price*item.quantity }
108
124
  earn_amount = franchise_price < user_info.purchase_fee ? franchise_price : user_info.purchase_fee
109
125
  #创建结算项
110
126
  ClearingItem.create({
@@ -115,10 +131,10 @@ module BlsmVdCore
115
131
  rate_of_profit: 1,
116
132
  earn_amount: earn_amount
117
133
  })
118
- user_info.update_attributes(:purchase_fee=> (user_info.purchase_fee - earn_amount))
134
+ user_info.update_attributes(:purchase_fee => (user_info.purchase_fee - earn_amount))
119
135
  end
120
136
  # 给邀请人奖励
121
- inviter = User.where(:invication_code=>user.invicated_from).first if user.invicated_from
137
+ inviter = User.where(:invication_code => user.invicated_from).first if user.invicated_from
122
138
  vd_transaction = "inviter_#{order.id}_reward"
123
139
  #被邀请人,金牌店主以下,渠道邀请,邀请人不为空,一个订单只能有一个结算项
124
140
  if user.vd_user_info.distribute_sum < 1500 && user.create_vd_user_info.channel == "market_invite" && !inviter.blank? && !BlsmVdCore::VdInfoSec.dangerous?(vd_transaction)
@@ -154,7 +170,7 @@ module BlsmVdCore
154
170
  content: content
155
171
  })
156
172
  end
157
- BlsmVdCore::VdInfoSec.committed(vd_transaction) #防止重复创建
173
+ BlsmVdCore::VdInfoSec.committed(vd_transaction) #防止重复创建
158
174
  end
159
175
  end
160
176
  end
@@ -186,6 +202,44 @@ module BlsmVdCore
186
202
  ERROR_CODES[200]
187
203
  end
188
204
 
205
+
206
+ #订单被导入到erp时
207
+ # 判断订单是否包含顺丰包邮商品,并根据此创建包邮券
208
+ def on_order_export_to_erp(order_id)
209
+ order = Order.where(id: order_id).first
210
+ settings = Setting.where(name: 'vd_free_post_products').first
211
+ seller = order.application.user if order && order.application
212
+
213
+ #数据校验
214
+ return ERROR_CODES[404] unless order
215
+ return ERROR_CODES[4043] unless order.line_items
216
+ return ERROR_CODES[4046] unless settings
217
+ return ERROR_CODES[4045] unless seller
218
+
219
+ product_ids = settings.value.to_s.split('|').map(&:to_i)
220
+
221
+ return ERROR_CODES[4048] if product_ids.size==0
222
+ return ERROR_CODES[4047] unless order.line_items.detect { |item| product_ids.include?(item.product_id) }
223
+
224
+ #安全校验
225
+ vd_transaction = "order_export_to_erp_handle_#{order_id}"
226
+ danger = VdInfoSec.dangerous?(vd_transaction)
227
+ return danger if danger
228
+ VdFreePost.create({user_id: seller.id})
229
+ content = '您获取到一张顺丰免费券,点击查看 http://w.url.cn/s/AQsuRun'
230
+ VdMpMsg.create!({
231
+ app_id: BlsmMpWx.APP_ID,
232
+ openid: seller.openid,
233
+ content: content,
234
+ msg_name: "custom",
235
+ template_msg: false,
236
+ status: 'none'
237
+ }) if seller.openid
238
+
239
+ VdInfoSec.committed(vd_transaction)
240
+ ERROR_CODES[200]
241
+ end
242
+
189
243
  #物流返款
190
244
  #==== Parameters
191
245
  # * +order_id+ - 订单id
@@ -461,7 +515,6 @@ module BlsmVdCore
461
515
  #店主销售额、分销额增加
462
516
  VdUserInfo.update_counters(seller_info.id, :sale_sum => order.total_fee.to_f)
463
517
  VdUserInfo.update_counters(seller_info.id, :distribute_sum => order.franchise_sum.to_f)
464
- VdUserInfo.find_by_id(seller_info.id) { |info| info.sync_shop_state }
465
518
 
466
519
  #分销额增加,更新未发出货物的(state=CREATE)分成比率
467
520
  seller.clearing_items.where(:state => "WAIT_TO_SURE").each do |item|
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.8.7
4
+ version: 0.8.8
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-01-03 00:00:00.000000000 Z
12
+ date: 2017-01-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -199,6 +199,7 @@ files:
199
199
  - lib/blsm-vd-core/model/ubox_vm.rb
200
200
  - lib/blsm-vd-core/model/user.rb
201
201
  - lib/blsm-vd-core/model/user_spread.rb
202
+ - lib/blsm-vd-core/model/vd_free_post.rb
202
203
  - lib/blsm-vd-core/model/vd_info_sec.rb
203
204
  - lib/blsm-vd-core/model/vd_mp_msg.rb
204
205
  - lib/blsm-vd-core/model/vd_rc_msg_notify.rb