Class: Sap::Customer
- Inherits:
-
SapAnywhereInterface
- Object
- SapAnywhereInterface
- Sap::Customer
- Defined in:
- lib/resource/sap/customer.rb
Instance Method Summary collapse
- #convert_to_sap_customer(order) ⇒ Object
-
#find(id) ⇒ Object
通过接口获得单个数据.
-
#initialize(source) ⇒ Customer
constructor
对象初始化方法(初始化来源).
-
#list ⇒ Object
通过接口获得一堆数据.
- #query(params = nil, id = nil) ⇒ Object
-
#request_name ⇒ Object
获取请求路径的请求名.
-
#upload(customer_order) ⇒ Object
将客户数据从云店家上传到sap.
Methods inherited from SapAnywhereInterface
#check_access_token, #check_function_and_shop, #convert_payment_type, #convert_price_unit, #delete, #get, #get_access_token, #get_access_token_url, #handle_response, #patch, #post
Constructor Details
#initialize(source) ⇒ Customer
Note:
对象初始化方法(初始化来源)
对象初始化方法(初始化来源)
9 10 11 |
# File 'lib/resource/sap/customer.rb', line 9 def initialize(source) @source = source end |
Instance Method Details
#convert_to_sap_customer(order) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/resource/sap/customer.rb', line 77 def convert_to_sap_customer(order) sap_customer = yhash sap_customer.customerType = 'INDIVIDUAL_CUSTOMER' sap_customer.stage = 'CUSTOMER' sap_customer.status = 'ACTIVE' sap_customer.marketingStatus = 'UNKNOWN' sap_customer.firstName = order.try(:consignee_name) # sap_customer.firstName = 'zxy' sap_customer.mobile = order.try(:consignee_phone) sap_customer.phone = order.try(:consignee_phone) sap_customer end |
#find(id) ⇒ Object
Note:
通过接口获得单个数据
通过接口获得单个数据
24 25 26 27 |
# File 'lib/resource/sap/customer.rb', line 24 def find(id) a = get(query(id)) # Rails.logger.info "a的class#{a.present?}" end |
#list ⇒ Object
Note:
通过接口获得一堆数据
通过接口获得一堆数据
17 18 19 |
# File 'lib/resource/sap/customer.rb', line 17 def list get(query) end |
#query(params = nil, id = nil) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/resource/sap/customer.rb', line 41 def query(params = nil, id = nil) # Rails.logger.info "#{params.class}" # 第一个判断是用于find(id)这种情况,第二个是针对update的情况 request_names = if params.class == Fixnum # Rails.logger.info "走的是第一个" "#{request_name}/#{params}?expand=*&" elsif id.class == Fixnum # Rails.logger.info "走的是第二个" "#{request_name}/#{id}?expand=*&" elsif params.class == String # Rails.logger.info "走的是第三个" "#{request_name}?expand=*&filter=(mobile+eq+'#{params}')&" else # Rails.logger.info "走的是第四个" "#{request_name}?expand=*&" end post_params = { source: @source, request_name: request_names } # p "params是#{params}" # p "id是#{id}" if params.class != Fixnum && params.class != String && params.present? post_params.merge!(customer: convert_to_sap_customer(params)) # p "post_params#{post_params}" end # Rails.logger.info "++++++++#{convert_to_sap_order(params)}" # if params[:user_id].present? # post_params.merge!(order: convert_to_sap_order(params)) # Rails.logger.info "post_params#{post_params}" # end post_params.merge(id: id) if id.class == Fixnum # p "当前参数#{post_params}" post_params end |
#request_name ⇒ Object
Note:
获取请求路径的请求名
获取请求路径的请求名
37 38 39 |
# File 'lib/resource/sap/customer.rb', line 37 def request_name 'Customers' end |
#upload(customer_order) ⇒ Object
将客户数据从云店家上传到sap
31 32 33 |
# File 'lib/resource/sap/customer.rb', line 31 def upload(customer_order) customer_id = post(query(customer_order)) end |