Class: SapModel::SalesChannel

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

Class Method Summary collapse

Class Method Details

.get_sales_channels(source) ⇒ Object

Note:

获取sap所有渠道信息中云店家的sap_id

获取sap所有渠道信息中云店家的sap_id

Parameters:

  • source (string)


10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/sap_model/sales_channel.rb', line 10

def self.get_sales_channels(source)
  Rails.logger.info "source为#{source}"
  sales_channels = Sap::SalesChannel.new(source).list
  sap_id = nil
  if sales_channels.present?
    sales_channels.each do |sale_channel|
      if sale_channel.try('name') == '云店家' && sale_channel.try('status')  == 'ACTIVE'
       sap_id = sale_channel.id
     end
   end
  end
  return sap_id
end

.get_sku_yun(source) ⇒ Object

Note:

获取sap上云店家所有上架商品的信息

获取sap上云店家所有上架商品的信息

Parameters:

  • source (string)


27
28
29
30
# File 'lib/sap_model/sales_channel.rb', line 27

def self.get_sku_yun(source)
  sap_id = self.get_sales_channels(source)
  on_shelf_products = Sap::SalesChannel.new(source).find_sku(sap_id)
end

.update_products_status(source, shop_id) ⇒ Object

Note:

更新sap商品上架的信息(sap某个商品规格全部下架时yundianjia才下架)

更新sap商品上架的信息(sap某个商品规格全部下架时yundianjia才下架)

Parameters:

  • source (string)


35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/sap_model/sales_channel.rb', line 35

def self.update_products_status(source, shop_id)
  on_shelf_product_map = self.get_sku_yun(source).each_with_object({})  do |on_shelf_product, map|
    key = on_shelf_product.try(:code).split('-').first
    if map[key].blank?
      map[key] = 1
    else
      map[key] += 1
    end
  end
  on_shelf_product_art_codes = on_shelf_product_map.keys
  Rails.logger.info "on_shelf_product_codes#{on_shelf_product_art_codes}"
  sap_product_art_codes = ::Product.where(source: source).map(&:art_no)
  off_shelf_product_art_codes = sap_product_art_codes - on_shelf_product_art_codes
  on_shelf_product_art_codes.each do |key|
    self.update_yun_product_status(key, ::Product::Status::Published, source, shop_id)
  end
  off_shelf_product_art_codes.each do |key|
    self.update_yun_product_status(key, ::Product::Status::Closed, source, shop_id)
  end
end

.update_yun_product_status(key, status, source, shop_id) ⇒ Object

Note:

更新sap商品上架的信息(sap某个商品规格全部下架时yundianjia才下架)的子方法

更新sap商品上架的信息(sap某个商品规格全部下架时yundianjia才下架)的子方法

Parameters:

  • source (string)


59
60
61
62
63
64
65
# File 'lib/sap_model/sales_channel.rb', line 59

def self.update_yun_product_status(key, status, source, shop_id)
  sap_product = ::Product.where(source: source, art_no: key, shop_id: shop_id).last
  sap_product.status = status
  sap_product.save!
rescue => e
  yloge e, "更新' 商品状态 商品art_code #{key}, 失败"
end