eric_weixin 0.2.3 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/app/controllers/eric_weixin/cms/weixin/xiaodian/orders_controller.rb +33 -0
- data/app/models/eric_weixin/public_account.rb +1 -0
- data/app/models/eric_weixin/redpack.rb +1 -0
- data/app/models/eric_weixin/reply_message_rule.rb +13 -2
- data/app/models/eric_weixin/weixin_user.rb +1 -0
- data/app/models/eric_weixin/xiaodian/category.rb +98 -0
- data/app/models/eric_weixin/xiaodian/order.rb +283 -0
- data/app/models/eric_weixin/xiaodian/product.rb +109 -0
- data/app/models/eric_weixin/xiaodian/product_sku_detail.rb +33 -0
- data/app/models/eric_weixin/xiaodian/sku_name.rb +23 -0
- data/app/models/eric_weixin/xiaodian/sku_value.rb +20 -0
- data/app/views/eric_weixin/cms/weixin/xiaodian/orders/index.html.erb +121 -0
- data/config/routes.rb +8 -0
- data/db/migrate/20151116085047_create_weixin_xiaodian_product.rb +10 -0
- data/db/migrate/20151116085215_create_weixin_xiaodian_order.rb +33 -0
- data/db/migrate/20151117015034_create_weixin_xiaodian_category.rb +9 -0
- data/db/migrate/20151117015049_create_weixin_xiaodian_sku_name.rb +9 -0
- data/db/migrate/20151117021415_create_weixin_xiaodian_sku_value.rb +9 -0
- data/db/migrate/20151117021429_create_weixin_xiaodian_category_product.rb +8 -0
- data/db/migrate/20151117021439_create_weixin_xiaodian_product_sku_detail.rb +15 -0
- data/db/migrate/20151119033354_add_status_to_weixin_xiaodian_product.rb +7 -0
- data/db/migrate/20151124113559_add_openid_to_weixin_xiaodian_order.rb +7 -0
- data/lib/eric_weixin/modules/pay.rb +7 -1
- data/lib/eric_weixin/version.rb +1 -1
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e06643833b5db46a39b5608626e49ac28492c9f
|
4
|
+
data.tar.gz: 44f84ed184d053f6048266aad4b656c21f24f64a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee04947763509c73525d8a87fdf30bbbea20cff05af608558727eeeae868879703f278d13f7dd68eac70a9799f673acbb93c95304e0df36c55d63002efe136c0
|
7
|
+
data.tar.gz: 0761238ebac8ad3972c6c8033db5f04c58809ad41e4fe997b5547dd6536d9e7192880df1e72bfe448781c93fca7c59c395f174e825166b9deda09d1b21adfbec
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class EricWeixin::Cms::Weixin::Xiaodian::OrdersController < EricWeixin::Cms::BaseController
|
2
|
+
def index
|
3
|
+
@orders = EricWeixin::Xiaodian::Order.all
|
4
|
+
@orders = @orders.where("order_create_time >= ?", params[:start_date].to_time.change(hour:0,min:0,sec:0).to_i) unless params[:start_date].blank?
|
5
|
+
@orders = @orders.where("order_create_time <= ?", params[:end_date].to_time.change(hour:23,min:59,sec:59).to_i) unless params[:end_date].blank?
|
6
|
+
@orders = @orders.order(order_create_time: :desc).paginate(per_page: params[:per_page]||6, page: params[:page]||1)
|
7
|
+
end
|
8
|
+
|
9
|
+
def save_delivery_info
|
10
|
+
begin
|
11
|
+
order = EricWeixin::Xiaodian::Order.find_by_id(params[:id])
|
12
|
+
if order.blank?
|
13
|
+
render text: 'order的ID不正确。'
|
14
|
+
return
|
15
|
+
end
|
16
|
+
options = {}
|
17
|
+
options["delivery_company"] = params[:delivery_company]
|
18
|
+
options["delivery_track_no"] = params[:delivery_track_no]
|
19
|
+
options["need_delivery"] = params[:need_delivery].to_i
|
20
|
+
options["is_others"] = params[:is_others].to_i
|
21
|
+
result = order.set_delivery options
|
22
|
+
render text: result ? '成功' : '失败'
|
23
|
+
rescue Exception=>e
|
24
|
+
dispose_exception e
|
25
|
+
render text: "保存失败: #{get_notice_str}"
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def download_orders
|
30
|
+
file_name = EricWeixin::Xiaodian::Order.get_excel_of_orders params.permit(:start_date, :end_date)
|
31
|
+
send_file file_name
|
32
|
+
end
|
33
|
+
end
|
@@ -7,6 +7,7 @@ class EricWeixin::PublicAccount < ActiveRecord::Base
|
|
7
7
|
has_one :access_token, :class_name => 'AccessToken', foreign_key: "public_account_id"
|
8
8
|
has_many :customs_service_records, class_name: 'CustomsServiceRecord', foreign_key: "weixin_public_account_id"
|
9
9
|
has_many :redpacks, foreign_key: "weixin_public_account_id"
|
10
|
+
has_many :orders, class_name: "::EricWeixin::PublicAccount", foreign_key: 'weixin_public_account_id'
|
10
11
|
|
11
12
|
#根据微信号名称获取微信账号相关信息
|
12
13
|
# ::EricWeixin::PublicAccount.get_public_account_by_name 'dfxt'
|
@@ -171,6 +171,7 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
|
|
171
171
|
if result == true
|
172
172
|
''
|
173
173
|
end
|
174
|
+
|
174
175
|
when /link~/
|
175
176
|
result = ::Weixin::Process.link_event receive_message
|
176
177
|
if result == true
|
@@ -179,7 +180,17 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
|
|
179
180
|
result
|
180
181
|
end
|
181
182
|
|
182
|
-
|
183
|
+
# 微信小店订单通知。
|
184
|
+
when /event~merchant_order/
|
185
|
+
EricWeixin::Xiaodian::Order.create_order receive_message
|
186
|
+
result = ::Weixin::Process.get_merchant_order receive_message
|
187
|
+
if result == true
|
188
|
+
''
|
189
|
+
else
|
190
|
+
result
|
191
|
+
end
|
192
|
+
|
193
|
+
# 群发发送图文推送后,微信服务器返回的结果
|
183
194
|
when /event~MASSSENDJOBFINISH/
|
184
195
|
::EricWeixin::MediaNews.update_media_news_after_sending receive_message
|
185
196
|
::Weixin::Process.message_send_job_finish receive_message
|
@@ -232,7 +243,7 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
|
|
232
243
|
break
|
233
244
|
end
|
234
245
|
end
|
235
|
-
if rule.key_word_type
|
246
|
+
if rule.key_word_type == 'regularexpr'
|
236
247
|
regexp = Regexp.new rule.key_word
|
237
248
|
result = regexp.match wx_key_word
|
238
249
|
unless result.blank?
|
@@ -3,6 +3,7 @@ class EricWeixin::WeixinUser < ActiveRecord::Base
|
|
3
3
|
self.table_name = 'weixin_users'
|
4
4
|
belongs_to :member_info
|
5
5
|
belongs_to :weixin_public_account, :class_name => '::EricWeixin::PublicAccount', :foreign_key => 'weixin_public_account_id'
|
6
|
+
has_many :orders, class_name: "::EricWeixin::Xiaodian::Order"
|
6
7
|
validates_uniqueness_of :openid, scope: :weixin_public_account_id
|
7
8
|
validates_presence_of :openid, :weixin_public_account_id
|
8
9
|
|
@@ -0,0 +1,98 @@
|
|
1
|
+
class EricWeixin::Xiaodian::Category < ActiveRecord::Base
|
2
|
+
self.table_name = 'weixin_xiaodian_categories'
|
3
|
+
belongs_to :parent, class_name: EricWeixin::Xiaodian::Category, foreign_key: :parent_id
|
4
|
+
has_and_belongs_to_many :products, :class_name => 'EricWeixin::Xiaodian::Product', :join_table => "weixin_xiaodian_category_products", :foreign_key => :weixin_xiaodian_category_id
|
5
|
+
|
6
|
+
validates_uniqueness_of :wx_category_id
|
7
|
+
require "rest-client"
|
8
|
+
|
9
|
+
# 把所有的产品类型导入数据库。
|
10
|
+
# public_account_name: 公众账号名称
|
11
|
+
# parent_id: 分类腾讯id#
|
12
|
+
# EricWeixin::Xiaodian::Category.import_all_categories 'rszx', 1
|
13
|
+
# EricWeixin::Xiaodian::Category.import_all_categories 'rszx', ['538088633','538071212'], 1 # 玩具、模型等, 食品/茶叶/特产/滋补品
|
14
|
+
def self.import_all_categories public_account_name, first_level_weixin_id = [], parent_id = 1
|
15
|
+
EricWeixin::Xiaodian::Category.transaction do
|
16
|
+
account = EricWeixin::PublicAccount.get_public_account_by_name public_account_name
|
17
|
+
token = ::EricWeixin::AccessToken.get_valid_access_token public_account_id: account.id
|
18
|
+
param = {:cate_id => parent_id}
|
19
|
+
response = RestClient.post "https://api.weixin.qq.com/merchant/category/getsub?access_token=#{token}", param.to_json
|
20
|
+
response = JSON.parse response.body
|
21
|
+
pp response
|
22
|
+
return if response['errcode'].to_i != 0
|
23
|
+
response['cate_list'].each do |category_info|
|
24
|
+
pid = if parent_id == 1
|
25
|
+
0
|
26
|
+
else
|
27
|
+
c = EricWeixin::Xiaodian::Category.where(wx_category_id: parent_id).first
|
28
|
+
c.id
|
29
|
+
end
|
30
|
+
if pid == 0
|
31
|
+
next unless first_level_weixin_id.include? category_info["id"]
|
32
|
+
end
|
33
|
+
EricWeixin::Xiaodian::Category.create_new_category name: category_info["name"],
|
34
|
+
wx_category_id: category_info["id"],
|
35
|
+
parent_id: pid
|
36
|
+
EricWeixin::Xiaodian::Category.import_all_categories public_account_name,[], category_info["id"]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# EricWeixin::Xiaodian::Category.update_sku_info 'rszx'
|
43
|
+
def self.update_sku_info public_account_name
|
44
|
+
EricWeixin::Xiaodian::Category.transaction do
|
45
|
+
account = EricWeixin::PublicAccount.get_public_account_by_name public_account_name
|
46
|
+
token = ::EricWeixin::AccessToken.get_valid_access_token public_account_id: account.id
|
47
|
+
EricWeixin::Xiaodian::Category.all.each do |category|
|
48
|
+
next if category.level < 4
|
49
|
+
pp '.....................'
|
50
|
+
param = {:cate_id => category.wx_category_id.to_i}
|
51
|
+
pp param.to_json
|
52
|
+
response = RestClient.post "https://api.weixin.qq.com/merchant/category/getsku?access_token=#{token}", param.to_json
|
53
|
+
pp 'xxxxxxxx 请求回来了'
|
54
|
+
response = JSON.parse response.body
|
55
|
+
pp response
|
56
|
+
next if response['errcode'] != 0
|
57
|
+
response['sku_table'].each do |sku_info|
|
58
|
+
name = EricWeixin::Xiaodian::SkuName.create_skuname wx_name_id: sku_info["id"],
|
59
|
+
name: sku_info["name"],
|
60
|
+
weixin_xiaodian_category_id: category.id
|
61
|
+
sku_info["value_list"].each do |value|
|
62
|
+
EricWeixin::Xiaodian::SkuValue.create_sku_value wx_value_id: value["id"],
|
63
|
+
name: value["name"],
|
64
|
+
weixin_xiaodian_sku_name_id: name.id
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def level
|
72
|
+
first_p = self.parent
|
73
|
+
return 1 if first_p.blank?
|
74
|
+
second_p = first_p.parent
|
75
|
+
return 2 if second_p.blank?
|
76
|
+
third_p = second_p.parent
|
77
|
+
return 3 if third_p.blank?
|
78
|
+
return 4
|
79
|
+
end
|
80
|
+
|
81
|
+
|
82
|
+
# 创建商品分类,参数为:名称,微信id, 父类id
|
83
|
+
# 父类id,如果不存在则为0
|
84
|
+
def self.create_new_category options
|
85
|
+
EricWeixin::Xiaodian::Category.transaction do
|
86
|
+
category = EricWeixin::Xiaodian::Category.where(wx_category_id: options[:wx_category_id]).first
|
87
|
+
if category.blank?
|
88
|
+
category = EricWeixin::Xiaodian::Category.new name: options[:name],
|
89
|
+
parent_id: options[:parent_id],
|
90
|
+
wx_category_id: options[:wx_category_id]
|
91
|
+
else
|
92
|
+
category.name = options[:name]
|
93
|
+
end
|
94
|
+
category.save!
|
95
|
+
return category
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,283 @@
|
|
1
|
+
class EricWeixin::Xiaodian::Order < ActiveRecord::Base
|
2
|
+
self.table_name = 'weixin_xiaodian_orders'
|
3
|
+
belongs_to :weixin_user, class_name: "::EricWeixin::WeixinUser"
|
4
|
+
belongs_to :product, class_name: "::EricWeixin::Xiaodian::Product", foreign_key: 'weixin_product_id'
|
5
|
+
belongs_to :weixin_public_account, class_name: "::EricWeixin::PublicAccount", foreign_key: 'weixin_public_account_id'
|
6
|
+
# 接收订单
|
7
|
+
DELIVERY_COMPANY = {
|
8
|
+
"Fsearch_code" => "邮政EMS",
|
9
|
+
"002shentong" => "申通快递",
|
10
|
+
"066zhongtong" => "中通速递",
|
11
|
+
"056yuantong" => "圆通速递",
|
12
|
+
"042tiantian" => "天天快递",
|
13
|
+
"003shunfeng" => "顺丰速运",
|
14
|
+
"059Yunda" => "韵达快运",
|
15
|
+
"064zhaijisong" => "宅急送",
|
16
|
+
"020huitong" => "汇通快运",
|
17
|
+
"zj001yixun" => "易迅快递"
|
18
|
+
}
|
19
|
+
|
20
|
+
def product_info
|
21
|
+
info = ""
|
22
|
+
list = self.sku_info.split(";")
|
23
|
+
list.each do |sku|
|
24
|
+
str = sku.split(":")[1]
|
25
|
+
if str.match /^\$/
|
26
|
+
info += str[1,str.size-1]
|
27
|
+
info += "、"
|
28
|
+
end
|
29
|
+
if str.match /^\d/
|
30
|
+
wx_value = ::EricWeixin::Xiaodian::SkuValue.find_by_wx_value_id(str)
|
31
|
+
unless wx_value.blank?
|
32
|
+
info += wx_value.name
|
33
|
+
info += "、"
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
info
|
38
|
+
end
|
39
|
+
|
40
|
+
# 创建订单
|
41
|
+
# 参数:
|
42
|
+
# OrderId 订单ID
|
43
|
+
# FromUserName 用户userid
|
44
|
+
# ToUserName 公众账号微信号
|
45
|
+
# ProductId
|
46
|
+
# CreateTime
|
47
|
+
# SkuInfo
|
48
|
+
# OrderStatus
|
49
|
+
#
|
50
|
+
def self.create_order options
|
51
|
+
order = EricWeixin::Xiaodian::Order.where(order_id: options[:OrderId]).first
|
52
|
+
unless order.blank?
|
53
|
+
order.get_info
|
54
|
+
return order
|
55
|
+
end
|
56
|
+
|
57
|
+
openid = options[:FromUserName]
|
58
|
+
user = EricWeixin::WeixinUser.where(openid: openid).first
|
59
|
+
|
60
|
+
to_user_name = options[:ToUserName]
|
61
|
+
account = EricWeixin::PublicAccount.where(weixin_number: to_user_name).first
|
62
|
+
|
63
|
+
product = EricWeixin::Xiaodian::Product.where(product_id: options[:ProductId]).first
|
64
|
+
if product.blank?
|
65
|
+
EricWeixin::Xiaodian::Product.get_all_products account.name
|
66
|
+
product = EricWeixin::Xiaodian::Product.where(product_id: options[:ProductId]).first
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
if user.blank?
|
71
|
+
account.rebuild_users_simple
|
72
|
+
user = EricWeixin::WeixinUser.where(openid: openid).first
|
73
|
+
end
|
74
|
+
|
75
|
+
user_id = user.blank? ? nil : user.id
|
76
|
+
|
77
|
+
order = EricWeixin::Xiaodian::Order.new order_id: options[:OrderId],
|
78
|
+
weixin_user_id: user_id,
|
79
|
+
order_create_time: options[:CreateTime],
|
80
|
+
order_status: options[:OrderStatus],
|
81
|
+
weixin_product_id: product.id,
|
82
|
+
sku_info: options[:SkuInfo],
|
83
|
+
weixin_public_account_id: account.id,
|
84
|
+
openid: openid
|
85
|
+
order.save!
|
86
|
+
|
87
|
+
order.get_info
|
88
|
+
|
89
|
+
order
|
90
|
+
end
|
91
|
+
|
92
|
+
|
93
|
+
# 根据订单ID获取订单详情
|
94
|
+
def get_info
|
95
|
+
token = ::EricWeixin::AccessToken.get_valid_access_token public_account_id: self.weixin_public_account_id
|
96
|
+
param = {order_id: self.order_id}
|
97
|
+
response = RestClient.post "https://api.weixin.qq.com/merchant/order/getbyid?access_token=#{token}", param.to_json
|
98
|
+
response = JSON.parse response.body
|
99
|
+
if response["errcode"] == 0
|
100
|
+
order_params = response["order"]
|
101
|
+
["receiver_zip", "product_id", "buyer_openid"].each do |a|
|
102
|
+
order_params.delete a
|
103
|
+
end
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
# 获取订单详情前,weixin_product_id、sku_info、weixin_user_id应该已经有了值
|
108
|
+
# weixin_product = EricWeixin::Xiaodian::Product.where( product_id: order_params["product_id"], weixin_public_account_id: self.weixin_public_account_id ).first
|
109
|
+
# order_params.merge!("weixin_product_id"=>weixin_product.id) unless weixin_product.blank?
|
110
|
+
# weixin_user = EricWeixin::WeixinUser.where(openid: order_params["buyer_openid"], weixin_public_account_id: self.weixin_public_account_id).first
|
111
|
+
# order_params.merge!("weixin_user_id"=>weixin_user.id) unless weixin_user.blank?
|
112
|
+
|
113
|
+
self.update_attributes order_params
|
114
|
+
else
|
115
|
+
pp response
|
116
|
+
return
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
# 根据订单状态/创建时间获取订单详情,并更新自身数据库
|
121
|
+
# EricWeixin::Xiaodian::Order.get_order_list_and_update nil, nil ,nil ,'rszx'
|
122
|
+
def self.get_order_list_and_update begin_time, end_time, status, public_account_name
|
123
|
+
account = EricWeixin::PublicAccount.get_public_account_by_name public_account_name
|
124
|
+
token = ::EricWeixin::AccessToken.get_valid_access_token public_account_id: account.id
|
125
|
+
|
126
|
+
param = {:a => 1}
|
127
|
+
if !begin_time.blank? and !end_time.blank?
|
128
|
+
param = {begintime: begin_time.to_i, endtime: end_time.to_i}
|
129
|
+
end
|
130
|
+
|
131
|
+
param.merge!(status: status) unless status.blank?
|
132
|
+
|
133
|
+
response = RestClient.post "https://api.weixin.qq.com/merchant/order/getbyfilter?access_token=#{token}", param.to_json
|
134
|
+
response = JSON.parse response.body
|
135
|
+
if response["errcode"] == 0
|
136
|
+
order_list = response["order_list"]
|
137
|
+
order_list.each do |order|
|
138
|
+
EricWeixin::Xiaodian::Order.create_order OrderId: order["order_id"],
|
139
|
+
FromUserName: order["buyer_openid"],
|
140
|
+
ToUserName: account.weixin_number,
|
141
|
+
ProductId: order["product_id"],
|
142
|
+
CreateTime: order["order_create_time"],
|
143
|
+
SkuInfo: order["product_sku"],
|
144
|
+
OrderStatus: order["order_status"]
|
145
|
+
end
|
146
|
+
else
|
147
|
+
pp response
|
148
|
+
return
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
# 设置订单发货信息
|
153
|
+
# 参数如下:
|
154
|
+
# {
|
155
|
+
# "delivery_company": "059Yunda",
|
156
|
+
# "delivery_track_no": "1900659372473",
|
157
|
+
# "need_delivery": 1,
|
158
|
+
# "is_others": 0
|
159
|
+
# }
|
160
|
+
#
|
161
|
+
# 参数解释如下:
|
162
|
+
#
|
163
|
+
# delivery_company
|
164
|
+
# 物流公司ID(参考《物流公司ID》;
|
165
|
+
# 当need_delivery为0时,可不填本字段;
|
166
|
+
# 当need_delivery为1时,该字段不能为空;
|
167
|
+
# 当need_delivery为1且is_others为1时,本字段填写其它物流公司名称)
|
168
|
+
#
|
169
|
+
# delivery_track_no
|
170
|
+
# 运单ID(
|
171
|
+
# 当need_delivery为0时,可不填本字段;
|
172
|
+
# 当need_delivery为1时,该字段不能为空;
|
173
|
+
# )
|
174
|
+
#
|
175
|
+
# need_delivery
|
176
|
+
# 商品是否需要物流(0-不需要,1-需要,无该字段默认为需要物流)
|
177
|
+
#
|
178
|
+
# is_others
|
179
|
+
# 是否为6.4.5表之外的其它物流公司(0-否,1-是,无该字段默认为不是其它物流公司)
|
180
|
+
|
181
|
+
def set_delivery options
|
182
|
+
pp options
|
183
|
+
if options["need_delivery"].to_s == "0"
|
184
|
+
options = {need_delivery: 0}
|
185
|
+
else
|
186
|
+
BusinessException.raise 'need_delivery不为0时,delivery_track_no字段必填' if options["delivery_track_no"].blank?
|
187
|
+
BusinessException.raise 'need_delivery不为0时,delivery_company字段不可以为空' if options["delivery_company"].blank?
|
188
|
+
if options["is_others"].to_s != "1"
|
189
|
+
BusinessException.raise 'need_delivery不为0且is_others不为1时,delivery_company字段必须是规定的快递公司ID' unless DELIVERY_COMPANY.include? options["delivery_company"]
|
190
|
+
end
|
191
|
+
end
|
192
|
+
token = ::EricWeixin::AccessToken.get_valid_access_token public_account_id: self.weixin_public_account_id
|
193
|
+
options.merge!("order_id" => self.order_id)
|
194
|
+
response = RestClient.post "https://api.weixin.qq.com/merchant/order/setdelivery?access_token=#{token}", options.to_json
|
195
|
+
response = JSON.parse response.body
|
196
|
+
if response["errcode"] == 0
|
197
|
+
true
|
198
|
+
if options["need_delivery"].to_s == "0"
|
199
|
+
self.update_attributes delivery_id: "", delivery_company: ""
|
200
|
+
else
|
201
|
+
self.update_attributes delivery_id: options["delivery_track_no"], delivery_company: options["delivery_company"]
|
202
|
+
end
|
203
|
+
else
|
204
|
+
false
|
205
|
+
end
|
206
|
+
end
|
207
|
+
|
208
|
+
def self.get_excel_of_orders options
|
209
|
+
orders = self.all
|
210
|
+
orders = orders.where("order_create_time >= ?", options[:start_date].to_time.change(hour:0,min:0,sec:0).to_i) unless options[:start_date].blank?
|
211
|
+
orders = orders.where("order_create_time <= ?", options[:end_date].to_time.change(hour:23,min:59,sec:59).to_i) unless options[:end_date].blank?
|
212
|
+
orders = orders.order(order_create_time: :desc)
|
213
|
+
|
214
|
+
Spreadsheet.client_encoding = 'UTF-8'
|
215
|
+
book = Spreadsheet::Workbook.new
|
216
|
+
|
217
|
+
sheet1 = book.create_worksheet name: '订单表'
|
218
|
+
sheet1.row(0)[0] = "id"
|
219
|
+
sheet1.row(0)[1] = "买家昵称"
|
220
|
+
sheet1.row(0)[2] = "订单ID"
|
221
|
+
sheet1.row(0)[3] = "产品名称"
|
222
|
+
sheet1.row(0)[4] = "sku"
|
223
|
+
sheet1.row(0)[5] = "订单状态"
|
224
|
+
sheet1.row(0)[6] = "总金额"
|
225
|
+
sheet1.row(0)[7] = "订单生成时间"
|
226
|
+
sheet1.row(0)[8] = "快递费"
|
227
|
+
sheet1.row(0)[9] = "昵称"
|
228
|
+
sheet1.row(0)[10] = "收货人"
|
229
|
+
sheet1.row(0)[11] = "省"
|
230
|
+
sheet1.row(0)[12] = "城市"
|
231
|
+
sheet1.row(0)[13] = "区"
|
232
|
+
sheet1.row(0)[14] = "地址"
|
233
|
+
sheet1.row(0)[15] = "移动电话"
|
234
|
+
sheet1.row(0)[16] = "固定电话"
|
235
|
+
sheet1.row(0)[17] = "产品名"
|
236
|
+
sheet1.row(0)[18] = "单价"
|
237
|
+
sheet1.row(0)[19] = "产品sku"
|
238
|
+
sheet1.row(0)[20] = "数量"
|
239
|
+
sheet1.row(0)[21] = "产品图片url"
|
240
|
+
sheet1.row(0)[22] = "运单ID"
|
241
|
+
sheet1.row(0)[23] = "快递公司"
|
242
|
+
sheet1.row(0)[24] = "交易ID"
|
243
|
+
sheet1.row(0)[25] = "openid"
|
244
|
+
sheet1.row(0)[26] = "公众号名称"
|
245
|
+
current_row = 1
|
246
|
+
orders.each do |order|
|
247
|
+
sheet1.row(current_row)[0] = order.id
|
248
|
+
sheet1.row(current_row)[1] = order.weixin_user.nickname rescue ''
|
249
|
+
sheet1.row(current_row)[2] = order.order_id
|
250
|
+
sheet1.row(current_row)[3] = order.product.name rescue ''
|
251
|
+
sheet1.row(current_row)[4] = order.product_info rescue ''
|
252
|
+
sheet1.row(current_row)[5] = order.order_status
|
253
|
+
sheet1.row(current_row)[6] = (order.order_total_price/100.0).round(2) rescue ''
|
254
|
+
sheet1.row(current_row)[7] = Time.at(order.order_create_time).strftime("%Y-%m-%d %H:%M:%S") rescue ''
|
255
|
+
sheet1.row(current_row)[8] = (order.order_express_price/100.0).round(2) rescue ''
|
256
|
+
sheet1.row(current_row)[9] = order.buyer_nick rescue ''
|
257
|
+
sheet1.row(current_row)[10] = order.receiver_name
|
258
|
+
sheet1.row(current_row)[11] = order.receiver_province
|
259
|
+
sheet1.row(current_row)[12] = order.receiver_city
|
260
|
+
sheet1.row(current_row)[13] = order.receiver_zone
|
261
|
+
sheet1.row(current_row)[14] = order.receiver_address
|
262
|
+
sheet1.row(current_row)[15] = order.receiver_mobile
|
263
|
+
sheet1.row(current_row)[16] = order.receiver_phone
|
264
|
+
sheet1.row(current_row)[17] = order.product_name
|
265
|
+
sheet1.row(current_row)[18] = (order.product_price/100.0).round(2) rescue ''
|
266
|
+
sheet1.row(current_row)[19] = order.product_sku
|
267
|
+
sheet1.row(current_row)[20] = order.product_count
|
268
|
+
sheet1.row(current_row)[21] = order.product_img
|
269
|
+
sheet1.row(current_row)[22] = order.delivery_id
|
270
|
+
sheet1.row(current_row)[23] = self::DELIVERY_COMPANY[order.delivery_company]||order.delivery_company rescue ''
|
271
|
+
sheet1.row(current_row)[24] = order.trans_id
|
272
|
+
sheet1.row(current_row)[25] = order.openid
|
273
|
+
sheet1.row(current_row)[26] = order.weixin_public_account.name
|
274
|
+
current_row += 1
|
275
|
+
end
|
276
|
+
dir = Rails.root.join('public', 'downloads')
|
277
|
+
Dir.mkdir dir unless Dir.exist? dir
|
278
|
+
file_path = File.join(dir,"#{Time.now.strftime("%Y%m%dT%H%M%S")}订单.xls")
|
279
|
+
book.write file_path
|
280
|
+
file_path
|
281
|
+
end
|
282
|
+
|
283
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
class EricWeixin::Xiaodian::Product < ActiveRecord::Base
|
2
|
+
self.table_name = 'weixin_xiaodian_products'
|
3
|
+
has_and_belongs_to_many :categories, :class_name => 'EricWeixin::Xiaodian::Category', :join_table => "weixin_xiaodian_category_products", :foreign_key => :weixin_xiaodian_product_id, association_foreign_key: :weixin_xiaodian_category_id
|
4
|
+
has_many :orders, class_name: "EricWeixin::Xiaodian::Order"
|
5
|
+
|
6
|
+
# 同步微信小店所有商品
|
7
|
+
# EricWeixin::Xiaodian::Product.get_all_products 'rszx'
|
8
|
+
def self.get_all_products public_account_name
|
9
|
+
account = EricWeixin::PublicAccount.get_public_account_by_name public_account_name
|
10
|
+
token = ::EricWeixin::AccessToken.get_valid_access_token public_account_id: account.id
|
11
|
+
|
12
|
+
param = {status: 0}
|
13
|
+
response = RestClient.post "https://api.weixin.qq.com/merchant/getbystatus?access_token=#{token}", param.to_json
|
14
|
+
response = JSON.parse response.body
|
15
|
+
if response["errcode"] == 0
|
16
|
+
response["products_info"].each do |product_info|
|
17
|
+
product = EricWeixin::Xiaodian::Product.create_product product_id: product_info["product_id"],
|
18
|
+
name: product_info["product_base"]["name"],
|
19
|
+
status: product_info["status"],
|
20
|
+
delivery_type: product_info["delivery_info"]["delivery_type"],
|
21
|
+
weixin_public_account_id: account.id,
|
22
|
+
sku_info: product_info["product_base"]["sku_info"],
|
23
|
+
properties: product_info["product_base"]["property"],
|
24
|
+
wx_category_id: product_info["product_base"]["category_id"]
|
25
|
+
|
26
|
+
(product_info["sku_list"]||[]).each do |sku|
|
27
|
+
EricWeixin::Xiaodian::ProductSkuDetail.create_sku_detail weixin_xiaodian_product_id: product.id,
|
28
|
+
sku_id: sku["sku_id"],
|
29
|
+
icon_url: sku["icon_url"],
|
30
|
+
price: sku["price"],
|
31
|
+
quantity: sku["quantity"],
|
32
|
+
product_code: sku["product_code"],
|
33
|
+
ori_price: sku["ori_price"]
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
else
|
38
|
+
pp response
|
39
|
+
return
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
#创建商品
|
45
|
+
def self.create_product options
|
46
|
+
EricWeixin::Xiaodian::Product.transaction do
|
47
|
+
product = EricWeixin::Xiaodian::Product.where(product_id: options[:product_id]).first
|
48
|
+
product = if product.blank?
|
49
|
+
EricWeixin::Xiaodian::Product.new product_id: options[:product_id],
|
50
|
+
name: options[:name],
|
51
|
+
status: options[:status],
|
52
|
+
delivery_type: options[:delivery_type],
|
53
|
+
sku_info: options[:sku_info],
|
54
|
+
properties: options[:properties],
|
55
|
+
weixin_public_account_id: options[:weixin_public_account_id]
|
56
|
+
else
|
57
|
+
product.name = options[:name]
|
58
|
+
product.status = options[:status]
|
59
|
+
product.delivery_type = options[:delivery_type]
|
60
|
+
product.sku_info= options[:sku_info]
|
61
|
+
product.properties= options[:properties]
|
62
|
+
product
|
63
|
+
end
|
64
|
+
product.save!
|
65
|
+
|
66
|
+
#更新分类信息
|
67
|
+
category_list = (product.categories.collect &:wx_category_id)
|
68
|
+
new_category_list = options["wx_category_id"]||[]
|
69
|
+
pp category_list
|
70
|
+
pp new_category_list
|
71
|
+
if not (category_list&new_category_list).length == category_list.length
|
72
|
+
product.categories.clear
|
73
|
+
options["wx_category_id"].each do |wx_category_id|
|
74
|
+
c = EricWeixin::Xiaodian::Category.where(wx_category_id: wx_category_id).first
|
75
|
+
product.categories << c
|
76
|
+
end
|
77
|
+
product.save!
|
78
|
+
end
|
79
|
+
product
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
__END__
|
84
|
+
{"errcode"=>0, "errmsg"=>"ok",
|
85
|
+
"products_info"=>[
|
86
|
+
{"product_base"=>{
|
87
|
+
"name"=>"探险活宝-手机壳",
|
88
|
+
"category_id"=>[537088786],
|
89
|
+
"img"=>[],
|
90
|
+
"detail"=>[],
|
91
|
+
"property"=>[{"id"=>"品牌", "vid"=>"探险活宝"}, {"id"=>"出售类型", "vid"=>"现货"}, {"id"=>"货号", "vid"=>"AT001"}, {"id"=>"礼盒包装", "vid"=>"否"}, {"id"=>"周边系列", "vid"=>"模型展示盒"}, {"id"=>"热门动漫系列", "vid"=>"探险活宝"}, {"id"=>"是否有导购视频", "vid"=>"无视频"}, {"id"=>"适用年龄", "vid"=>"6岁以上"}, {"id"=>"作品来源", "vid"=>"卡通"}, {"id"=>"按动漫来源", "vid"=>"欧美动漫"}],
|
92
|
+
"sku_info"=>[],
|
93
|
+
"buy_limit"=>0,
|
94
|
+
"main_img"=>"http://mmbiz.qpic.cn/mmbiz/PsD21Mpo7RU2qLuAFZZPemn9icG05gT5lPjmw3LxtGHznicCiaPFx13yaKrPiaOf5QULW1Vm9GJETPTeM3y9h6Wib3w/0?wx_fmt=jpeg",
|
95
|
+
"detail_html"=>""
|
96
|
+
},
|
97
|
+
"sku_list"=>[
|
98
|
+
{"sku_id"=>"", "price"=>5000, "icon_url"=>"", "quantity"=>100, "product_code"=>"", "ori_price"=>10000}
|
99
|
+
],
|
100
|
+
"delivery_info"=>{
|
101
|
+
"delivery_type"=>0, "template_id"=>0, "weight"=>0, "volume"=>0, "express"=>[{"id"=>10000027, "price"=>0}, {"id"=>10000028, "price"=>0}, {"id"=>10000029, "price"=>0}]
|
102
|
+
},
|
103
|
+
"product_id"=>"pE46BjpxJ_7k_H_LmIr4uWPQUI2Q",
|
104
|
+
"status"=>2,
|
105
|
+
"attrext"=>{"isPostFree"=>1, "isHasReceipt"=>1, "isUnderGuaranty"=>1, "isSupportReplace"=>0,
|
106
|
+
"location"=>{"country"=>"中国", "province"=>"云南", "city"=>"丽江", "address"=>""}}
|
107
|
+
}
|
108
|
+
]
|
109
|
+
}
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class EricWeixin::Xiaodian::ProductSkuDetail < ActiveRecord::Base
|
2
|
+
self.table_name = 'weixin_xiaodian_product_sku_details'
|
3
|
+
|
4
|
+
|
5
|
+
def self.create_sku_detail options
|
6
|
+
detail = EricWeixin::Xiaodian::ProductSkuDetail.where(weixin_xiaodian_product_id: options[:weixin_xiaodian_product_id],
|
7
|
+
sku_id: options[:sku_id]).first
|
8
|
+
if detail.blank?
|
9
|
+
detail = EricWeixin::Xiaodian::ProductSkuDetail.new weixin_xiaodian_product_id: options[:weixin_xiaodian_product_id],
|
10
|
+
sku_id: options[:sku_id]
|
11
|
+
end
|
12
|
+
[:price, :icon_url, :quantity, :product_code, :ori_price]
|
13
|
+
detail.price = options[:price]
|
14
|
+
detail.icon_url = options[:icon_url]
|
15
|
+
detail.quantity = options[:quantity]
|
16
|
+
detail.product_code = options[:product_code]
|
17
|
+
detail.save!
|
18
|
+
|
19
|
+
unless detail.sku_id.blank?
|
20
|
+
sku_wx_name_id, sku_wx_value_id = detail.sku_id.split(':')
|
21
|
+
name = EricWeixin::Xiaodian::SkuName.where(wx_name_id: sku_wx_name_id).first
|
22
|
+
value = EricWeixin::Xiaodian::SkuValue.where(wx_value_id: sku_wx_value_id).first
|
23
|
+
if !name.blank? and !value.blank?
|
24
|
+
detail.weixin_xiaodian_sku_name_id = name.id
|
25
|
+
detail.weixin_xiaodian_sku_value_id = value.id
|
26
|
+
detail.save!
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
|
33
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
class EricWeixin::Xiaodian::SkuName < ActiveRecord::Base
|
2
|
+
self.table_name = 'weixin_xiaodian_sku_names'
|
3
|
+
validates_uniqueness_of :wx_name_id, scope: :weixin_xiaodian_category_id
|
4
|
+
|
5
|
+
#创建sku name
|
6
|
+
# 接收参数: name weixin_name_id 类别id
|
7
|
+
def self.create_skuname options
|
8
|
+
name = EricWeixin::Xiaodian::SkuName.where(wx_name_id: options[:wx_name_id],
|
9
|
+
weixin_xiaodian_category_id: options[:weixin_xiaodian_category_id]).first
|
10
|
+
name = if name.blank?
|
11
|
+
name = EricWeixin::Xiaodian::SkuName.new name: options[:name],
|
12
|
+
weixin_xiaodian_category_id: options[:weixin_xiaodian_category_id],
|
13
|
+
wx_name_id: options[:wx_name_id]
|
14
|
+
else
|
15
|
+
name.name = options[:name]
|
16
|
+
name
|
17
|
+
end
|
18
|
+
name.save!
|
19
|
+
name
|
20
|
+
end
|
21
|
+
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class EricWeixin::Xiaodian::SkuValue < ActiveRecord::Base
|
2
|
+
self.table_name = 'weixin_xiaodian_sku_values'
|
3
|
+
|
4
|
+
#创建sku name
|
5
|
+
# 接收参数: name weixin_value_id 类别id
|
6
|
+
def self.create_sku_value options
|
7
|
+
v = EricWeixin::Xiaodian::SkuValue.where(wx_value_id: options[:wx_value_id],
|
8
|
+
weixin_xiaodian_sku_name_id: options[:weixin_xiaodian_sku_name_id]).first
|
9
|
+
v = if v.blank?
|
10
|
+
v = EricWeixin::Xiaodian::SkuValue.new name: options[:name],
|
11
|
+
weixin_xiaodian_sku_name_id: options[:weixin_xiaodian_sku_name_id],
|
12
|
+
wx_value_id: options[:wx_value_id]
|
13
|
+
else
|
14
|
+
v.name = options[:name]
|
15
|
+
v
|
16
|
+
end
|
17
|
+
v.save!
|
18
|
+
v
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
<div class="row">
|
2
|
+
<%= form_tag "/eric_weixin/cms/weixin/xiaodian/orders/", method: :get do %>
|
3
|
+
<div class="columns small-2">
|
4
|
+
<label class="inline text-right">订单时间区间</label>
|
5
|
+
</div>
|
6
|
+
<div class="columns small-3">
|
7
|
+
<%= date_field_tag :start_date, params[:start_date] %>
|
8
|
+
</div>
|
9
|
+
<div class="columns small-1 text-center">
|
10
|
+
<label class="inline center">至</label>
|
11
|
+
</div>
|
12
|
+
<div class="columns small-3">
|
13
|
+
<%= date_field_tag :end_date, params[:end_date] %>
|
14
|
+
</div>
|
15
|
+
<div class="columns small-3 text-left">
|
16
|
+
<%= submit_tag '查询', class: "button tiny" %>
|
17
|
+
</div>
|
18
|
+
<% end %>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<h3>订单列表</h3>
|
22
|
+
微信小店官方物流公司:邮政EMS、申通快递、中通速递、圆通速递、天天快递、顺丰速运、韵达快运、宅急送、汇通快运、易迅快递
|
23
|
+
<table>
|
24
|
+
<thead>
|
25
|
+
<th>订单ID</th>
|
26
|
+
|
27
|
+
<th>买家</th><th>购买时间</th><th>宝贝</th><th>宝贝信息</th><th>数量</th><th>收货人</th><th>收货地址</th><th>手机</th>
|
28
|
+
|
29
|
+
<th>是否需要物流</th><th>是否官方物流</th><th>快递公司</th><th>运单号</th><th>操作</th>
|
30
|
+
</thead>
|
31
|
+
<tbody>
|
32
|
+
<% @orders.each do |order| %>
|
33
|
+
<tr>
|
34
|
+
<td style="word-break:break-all"><%= order.order_id %></td>
|
35
|
+
<td style="word-break:break-all"><%= order.weixin_user.nickname %></td>
|
36
|
+
<td style="word-break:break-all"><%= Time.at(order.order_create_time).strftime("%Y-%m-%d %H:%M:%S") %></td>
|
37
|
+
<td style="word-break:break-all"><%= order.product.name %></td>
|
38
|
+
<td style="word-break:break-all"><%= order.product_info %></td>
|
39
|
+
<td style="word-break:break-all"><%= order.product_count %></td>
|
40
|
+
<td style="word-break:break-all"><%= order.receiver_name %></td>
|
41
|
+
<td style="word-break:break-all"><%= order.receiver_province + order.receiver_city + order.receiver_zone + order.receiver_address %></td>
|
42
|
+
<td style="word-break:break-all"><%= order.receiver_mobile %></td>
|
43
|
+
<td style="word-break:break-all">
|
44
|
+
<%= check_box_tag "order_#{order.id}_is_need_delivery", "1", true, onchange: "change_need_delivery(#{order.id})" %>
|
45
|
+
</td>
|
46
|
+
<td id="order_<%= order.id %>_is_xiaodian_delivery_td" style="word-break:break-all">
|
47
|
+
<% is_xiaodian_delivery = EricWeixin::Xiaodian::Order::DELIVERY_COMPANY.keys.include?(order.delivery_company) %>
|
48
|
+
<%= check_box_tag "order_#{order.id}_is_xiaodian_delivery", "1", is_xiaodian_delivery , onchange: "change_is_xiaodian_delivery(#{order.id})" %>
|
49
|
+
</td>
|
50
|
+
<td id="order_<%= order.id %>_delivery_company_td" style="word-break:break-all">
|
51
|
+
<% if is_xiaodian_delivery %>
|
52
|
+
<%= select_tag "order_#{order.id}_delivery_company", options_from_collection_for_select(EricWeixin::Xiaodian::Order::DELIVERY_COMPANY, 'first', 'second', order.delivery_company), prompt: '选择快递公司' %>
|
53
|
+
<% else %>
|
54
|
+
<%= text_field_tag "order_#{order.id}_delivery_company", order.delivery_company %>
|
55
|
+
<% end %>
|
56
|
+
</td>
|
57
|
+
<td id="order_<%= order.id %>_deliver_id_td" style="word-break:break-all">
|
58
|
+
<%= text_field_tag "order_#{order.id}_delivery_id", order.delivery_id %>
|
59
|
+
</td>
|
60
|
+
<td id="order_<%= order.id %>_action_td" style="word-break:break-all">
|
61
|
+
<%= link_to '保存', "javascript:save_delivery_info(#{order.id})", id: "order_#{order.id}_action", class: "button tiny" %>
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
<% end %>
|
65
|
+
</tbody>
|
66
|
+
</table>
|
67
|
+
<%= will_paginate @collection, renderer: FoundationPagination::Rails %>
|
68
|
+
<div class="row">
|
69
|
+
<div class="columns small-12 text-right">
|
70
|
+
<%= link_to '下载订单', "/eric_weixin/cms/weixin/xiaodian/orders/download_orders?start_time=#{params[:start_date]}&end_time=#{params[:end_date]}", class: 'button tiny' %>
|
71
|
+
</div>
|
72
|
+
</div>
|
73
|
+
|
74
|
+
<script language="javascript">
|
75
|
+
function change_need_delivery(order_id){
|
76
|
+
if(!$("#order_"+order_id+"_is_need_delivery")[0].checked){
|
77
|
+
$("#order_"+order_id+"_is_xiaodian_delivery")[0].style.display = "none";
|
78
|
+
$("#order_"+order_id+"_delivery_company")[0].style.display="none";
|
79
|
+
$("#order_"+order_id+"_delivery_id")[0].style.display="none";
|
80
|
+
} else {
|
81
|
+
$("#order_"+order_id+"_is_xiaodian_delivery")[0].style.display = "inline";
|
82
|
+
$("#order_"+order_id+"_delivery_company")[0].style.display="inline";
|
83
|
+
$("#order_"+order_id+"_delivery_id")[0].style.display="inline";
|
84
|
+
}
|
85
|
+
}
|
86
|
+
function change_is_xiaodian_delivery(order_id){
|
87
|
+
delivery_code = $("#order_"+order_id+"_delivery_company")[0].value;
|
88
|
+
if($("#order_"+order_id+"_is_xiaodian_delivery")[0].checked){
|
89
|
+
select_delivery_company_str = '<select name="order_'+order_id+'_delivery_company" id="order_'+order_id+'_delivery_company">';
|
90
|
+
select_delivery_company_str += '<option value="">选择快递公司</option>';
|
91
|
+
<% EricWeixin::Xiaodian::Order::DELIVERY_COMPANY.each do |dc| %>
|
92
|
+
selected_str = '';
|
93
|
+
if(delivery_code=='<%= dc[0] %>') {
|
94
|
+
selected_str = 'selected="selected"';
|
95
|
+
}
|
96
|
+
select_delivery_company_str += '<option '+selected_str+' value="'+ '<%= dc[0] %>' +'">'+'<%= dc[1] %>'+'</option>';
|
97
|
+
<% end %>
|
98
|
+
select_delivery_company_str += '</select>';
|
99
|
+
$("#order_"+order_id+"_delivery_company_td").html(select_delivery_company_str);
|
100
|
+
} else {
|
101
|
+
input_delivery_company_str = '<input type="text" name="order_'+order_id+'_delivery_company" id="order_'+order_id+'_delivery_company" value="">';
|
102
|
+
$("#order_"+order_id+"_delivery_company_td").html(input_delivery_company_str);
|
103
|
+
}
|
104
|
+
}
|
105
|
+
function save_delivery_info(order_id){
|
106
|
+
need_delivery = $("#order_"+order_id+"_is_need_delivery")[0].checked ? 1 : 0;
|
107
|
+
is_others = $("#order_"+order_id+"_is_xiaodian_delivery")[0].checked ? 0 : 1;
|
108
|
+
delivery_track_no = $("#order_"+order_id+"_delivery_id")[0].value;
|
109
|
+
delivery_company = $("#order_"+order_id+"_delivery_company")[0].value;
|
110
|
+
$.ajax({
|
111
|
+
url: '/eric_weixin/cms/weixin/xiaodian/orders/save_delivery_info',
|
112
|
+
type: 'post',
|
113
|
+
data: {id: order_id, need_delivery: need_delivery, is_others: is_others, delivery_track_no: delivery_track_no, delivery_company: delivery_company},
|
114
|
+
async: false
|
115
|
+
}).done(
|
116
|
+
function(result){
|
117
|
+
alert(result);
|
118
|
+
}
|
119
|
+
);
|
120
|
+
}
|
121
|
+
</script>
|
data/config/routes.rb
CHANGED
@@ -9,6 +9,14 @@ EricWeixin::Engine.routes.draw do
|
|
9
9
|
|
10
10
|
namespace :cms do
|
11
11
|
namespace :weixin do
|
12
|
+
namespace :xiaodian do
|
13
|
+
resources :orders do
|
14
|
+
collection do
|
15
|
+
post :save_delivery_info
|
16
|
+
get :download_orders
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
12
20
|
resources :public_accounts do
|
13
21
|
member do
|
14
22
|
get :rebuild_weixin_users
|
@@ -0,0 +1,10 @@
|
|
1
|
+
class CreateWeixinXiaodianProduct < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :weixin_xiaodian_products do |t|
|
4
|
+
t.string :product_id, :limit => 100
|
5
|
+
t.string :name, :limit => 200
|
6
|
+
t.text :properties
|
7
|
+
t.string :sku_info, :limit => 300
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class CreateWeixinXiaodianOrder < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :weixin_xiaodian_orders do |t|
|
4
|
+
t.integer :weixin_user_id
|
5
|
+
t.string :order_id
|
6
|
+
t.integer :weixin_product_id
|
7
|
+
t.string :sku_info, :limit => 1000
|
8
|
+
t.integer :order_status
|
9
|
+
t.integer :order_total_price
|
10
|
+
t.integer :order_create_time
|
11
|
+
t.integer :order_express_price
|
12
|
+
t.string :buyer_nick
|
13
|
+
t.string :receiver_name
|
14
|
+
t.string :receiver_province
|
15
|
+
t.string :receiver_city
|
16
|
+
t.string :receiver_zone
|
17
|
+
t.string :receiver_address
|
18
|
+
t.string :receiver_mobile
|
19
|
+
t.string :receiver_phone
|
20
|
+
t.string :product_name
|
21
|
+
t.integer :product_price
|
22
|
+
t.string :product_sku
|
23
|
+
t.integer :product_count
|
24
|
+
t.string :product_img
|
25
|
+
t.string :delivery_id
|
26
|
+
t.string :delivery_company
|
27
|
+
t.string :trans_id
|
28
|
+
t.integer :weixin_public_account_id
|
29
|
+
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateWeixinXiaodianProductSkuDetail < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :weixin_xiaodian_product_sku_details do |t|
|
4
|
+
t.integer :weixin_xiaodian_product_id
|
5
|
+
t.string :sku_id
|
6
|
+
t.integer :price
|
7
|
+
t.string :icon_url
|
8
|
+
t.integer :quantity
|
9
|
+
t.string :product_code
|
10
|
+
t.integer :ori_price
|
11
|
+
t.integer :weixin_xiaodian_sku_name_id
|
12
|
+
t.integer :weixin_xiaodian_sku_value_id
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,7 @@
|
|
1
|
+
class AddStatusToWeixinXiaodianProduct < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
add_column :weixin_xiaodian_products, :status, :integer
|
4
|
+
add_column :weixin_xiaodian_products, :weixin_public_account_id, :integer
|
5
|
+
add_column :weixin_xiaodian_products, :delivery_type, :integer
|
6
|
+
end
|
7
|
+
end
|
@@ -1,4 +1,6 @@
|
|
1
1
|
module EricWeixin::Pay
|
2
|
+
|
3
|
+
#
|
2
4
|
def self.generate_prepay_id options
|
3
5
|
required_field = %i(appid mch_id openid attach body out_trade_no total_fee spbill_create_ip notify_url trade_type)
|
4
6
|
query_options = {}
|
@@ -22,6 +24,7 @@ module EricWeixin::Pay
|
|
22
24
|
nil
|
23
25
|
end
|
24
26
|
|
27
|
+
# 产生签名
|
25
28
|
def self.generate_sign options, api_key
|
26
29
|
pp "**************** 签名参数 *********************"
|
27
30
|
pp options
|
@@ -33,7 +36,9 @@ module EricWeixin::Pay
|
|
33
36
|
Digest::MD5.hexdigest("#{query}&key=#{api_key}").upcase
|
34
37
|
end
|
35
38
|
|
36
|
-
#
|
39
|
+
#
|
40
|
+
# 发红包,直接调用。
|
41
|
+
# #参数
|
37
42
|
# wxappid
|
38
43
|
# re_openid
|
39
44
|
# total_amount
|
@@ -77,6 +82,7 @@ module EricWeixin::Pay
|
|
77
82
|
result['xml']
|
78
83
|
end
|
79
84
|
|
85
|
+
# 根据红包单号,获取红包基础数据。
|
80
86
|
# mch_billno
|
81
87
|
# mch_id
|
82
88
|
# appid
|
data/lib/eric_weixin/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eric_weixin
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- 刘晓琦
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-12-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- app/controllers/eric_weixin/cms/weixin/url_encodes_controller.rb
|
54
54
|
- app/controllers/eric_weixin/cms/weixin/users_controller.rb
|
55
55
|
- app/controllers/eric_weixin/cms/weixin/weixin_users_controller.rb
|
56
|
+
- app/controllers/eric_weixin/cms/weixin/xiaodian/orders_controller.rb
|
56
57
|
- app/controllers/eric_weixin/wz/pays_controller.rb
|
57
58
|
- app/controllers/eric_weixin/wz/weixin_controller.rb
|
58
59
|
- app/helpers/eric_weixin/application_helper.rb
|
@@ -80,6 +81,12 @@ files:
|
|
80
81
|
- app/models/eric_weixin/template_message_log.rb
|
81
82
|
- app/models/eric_weixin/two_dimension_code.rb
|
82
83
|
- app/models/eric_weixin/weixin_user.rb
|
84
|
+
- app/models/eric_weixin/xiaodian/category.rb
|
85
|
+
- app/models/eric_weixin/xiaodian/order.rb
|
86
|
+
- app/models/eric_weixin/xiaodian/product.rb
|
87
|
+
- app/models/eric_weixin/xiaodian/product_sku_detail.rb
|
88
|
+
- app/models/eric_weixin/xiaodian/sku_name.rb
|
89
|
+
- app/models/eric_weixin/xiaodian/sku_value.rb
|
83
90
|
- app/views/eric_weixin/cms/weixin/article_datas/_article_data.html.erb
|
84
91
|
- app/views/eric_weixin/cms/weixin/article_datas/edit.html.erb
|
85
92
|
- app/views/eric_weixin/cms/weixin/article_datas/index.html.erb
|
@@ -122,6 +129,7 @@ files:
|
|
122
129
|
- app/views/eric_weixin/cms/weixin/url_encodes/index.html.erb
|
123
130
|
- app/views/eric_weixin/cms/weixin/users/index.html.erb
|
124
131
|
- app/views/eric_weixin/cms/weixin/weixin_users/index.html.erb
|
132
|
+
- app/views/eric_weixin/cms/weixin/xiaodian/orders/index.html.erb
|
125
133
|
- app/views/eric_weixin/wz/pays/pay_fail.html.erb
|
126
134
|
- app/views/eric_weixin/wz/pays/pay_ok.html.erb
|
127
135
|
- app/views/eric_weixin/wz/pays/prepay.html.erb
|
@@ -161,6 +169,15 @@ files:
|
|
161
169
|
- db/migrate/20150911023948_create_weixin_redpack_orders.rb
|
162
170
|
- db/migrate/20150911062057_create_weixin_redpacks.rb
|
163
171
|
- db/migrate/20150914061051_create_jsapi_tickets.rb
|
172
|
+
- db/migrate/20151116085047_create_weixin_xiaodian_product.rb
|
173
|
+
- db/migrate/20151116085215_create_weixin_xiaodian_order.rb
|
174
|
+
- db/migrate/20151117015034_create_weixin_xiaodian_category.rb
|
175
|
+
- db/migrate/20151117015049_create_weixin_xiaodian_sku_name.rb
|
176
|
+
- db/migrate/20151117021415_create_weixin_xiaodian_sku_value.rb
|
177
|
+
- db/migrate/20151117021429_create_weixin_xiaodian_category_product.rb
|
178
|
+
- db/migrate/20151117021439_create_weixin_xiaodian_product_sku_detail.rb
|
179
|
+
- db/migrate/20151119033354_add_status_to_weixin_xiaodian_product.rb
|
180
|
+
- db/migrate/20151124113559_add_openid_to_weixin_xiaodian_order.rb
|
164
181
|
- lib/eric_weixin.rb
|
165
182
|
- lib/eric_weixin/engine.rb
|
166
183
|
- lib/eric_weixin/modules/analyze_data.rb
|