Class: SapModel::Order

Inherits:
Object
  • Object
show all
Defined in:
lib/sap_model/order.rb

Class Method Summary collapse

Class Method Details

.convert_status(status) ⇒ Object

Note:

将从sap接口获得的订单状态转换成云店家的相应订单状态

暂时使用不到所以没有写完 将从sap接口获得的订单状态转换成云店家的相应订单状态

Parameters:

  • status (string)

Returns:



58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/sap_model/order.rb', line 58

def self.convert_status(status)
  if status == CANCEL
    yun_status = Order::Status::Cancelled
  elsif status == OPEN
    yun_status = Order::Status::Awaiting_Payment
  elsif status == CLOSED
  elsif status == DRAFT
  elsif status == WAITING_APPROVAL
  elsif status == APPROVED
  end
  yun_status
end

.find_order(source, id) ⇒ Object

Note:

根据来源,id获得单个订单

根据来源,id获得单个订单

Parameters:

  • source (string)


18
19
20
# File 'lib/sap_model/order.rb', line 18

def self.find_order(source, id)
  Sap::Order.new(source).find(id)
end

.get_orders(source) ⇒ Object

Note:

根据来源获得所有订单

根据来源获得所有订单

Parameters:

  • source (string)


10
11
12
# File 'lib/sap_model/order.rb', line 10

def self.get_orders(source)
  Sap::Order.new(source).list
end

.new_or_update_all_orders_by_source(source) ⇒ Object

Note:

根据来源从sap接口获得的订单保存在云店家

根据来源从sap接口获得的订单保存在云店家

Parameters:

  • source (string)


74
75
76
77
78
79
80
# File 'lib/sap_model/order.rb', line 74

def self.new_or_update_all_orders_by_source(source)
  orders = Sap::Order.new(source).list
  orders.each do |order|
    options = self.query(order, source)
    self.new_or_update_order(source, order, options)
  end
end

.new_or_update_order(source, order, options) ⇒ Object

Note:

根据来源从sap接口获得的订单保存在云店家(子方法)

根据来源从sap接口获得的订单保存在云店家(子方法)

Parameters:

  • source (string)
  • sap_order (sap_order)


87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/sap_model/order.rb', line 87

def self.new_or_update_order(source, order, options)

  yun_order = ::Order.where(source: source, code: order.try(:code))
  if yun_order.present?
    yun_order.update!(options)
  else
    ::Order.create!(options)
  end

rescue => e
  yloge e, "更新' 订单 #{order.try(:code)}, 失败"
end

.query(order, source) ⇒ Object

Note:

为从sap接口获得的订单保存在云店家分装参数

暂时使用不到所以没有写完 为从sap接口获得的订单保存在云店家分装参数

Parameters:

  • sap_product (sap_product)


39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/sap_model/order.rb', line 39

def self.query(order, source)
  status = order.try(:status)
  # yun_status = Order::Status.group_by_usage(SystemStatusGroup::Usage.const_get("#{ :admin.to_s.upcase}_QUERY_LIST"), source)

  {
      order_number: order.try(:code),
      name: order.try(:name),
      total_price: order.try(:paidTotal),
      user_id: order.try(:customer).id,

  }

end

.upload_modified_order_to_sap(source, id, order) ⇒ Object

暂时使用不到所以没有写完 将云店家中订单状态有变化的订单上传至sap



29
30
31
32
33
# File 'lib/sap_model/order.rb', line 29

def self.upload_modified_order_to_sap(source, id, order)
  Rails.logger.info "id是#{id}"
  Rails.logger.info "order是#{order}"
  Sap::Order.new(source).update_order(order, id)
end

.upload_order(source, order, sap_customer_id) ⇒ Object

将云店家中生成的订单上传至sap



23
24
25
# File 'lib/sap_model/order.rb', line 23

def self.upload_order(source, order, sap_customer_id)
  order_id = Sap::Order.new(source).upload(order, sap_customer_id)
end