Class: Trade::Admin::GoodsController
- Inherits:
-
BaseController
- Object
- BaseController
- Trade::Admin::GoodsController
- Defined in:
- app/controllers/trade/admin/goods_controller.rb
Instance Method Summary collapse
- #buy ⇒ Object
- #index ⇒ Object
- #item ⇒ Object
- #market ⇒ Object
- #produce ⇒ Object
- #search ⇒ Object
- #show ⇒ Object
- #taxon ⇒ Object
- #wiki ⇒ Object
Instance Method Details
#buy ⇒ Object
85 86 87 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 85 def buy redirect_to @good.buy_link end |
#index ⇒ Object
4 5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 4 def index @goods = Good.page(params[:page]).per(params[:per]) @menus = List..joins(:items).where(items: {node_type: Item.node_types[:node_top]}) respond_to do |format| format.html format.html.phone format.json { render json: @goods } end end |
#item ⇒ Object
21 22 23 24 25 26 27 28 29 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 21 def item @item = Item.includes(:goods).find params[:id] @menus = List.joins(:items).where(items: {node_type: Item.node_types[:node_top]}) respond_to do |format| format.html format.json { render json: @item } end end |
#market ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 55 def market @market = Market.find(params[:id]) # 相关产品 needs = @market.needs.map { |i| i.id } items = ItemNeed.select(:item_id).where(:need_id => needs).map { |i| i.item_id } items.uniq! groups = GoodItem.where(:item_id => items).map { |i| i.good_id } a1 = groups.group_by { |i| i } a2 = a1.sort_by { |k, v| v.count } a3 = a2.reverse.map { |i| i[0] } @groups = Good.find a3.slice(0..9) @items = Item.find items end |
#produce ⇒ Object
77 78 79 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 77 def produce @produces = @good.good_produces end |
#search ⇒ Object
15 16 17 18 19 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 15 def search @goods = params[:good_type].constantize.default_where('') @buyers = RailsTrade.buyer_class.default_where('name-like': params[:q]) render json: { results: @buyers.as_json(only: [:id], methods: [:name_detail]) } end |
#show ⇒ Object
73 74 75 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 73 def show end |
#taxon ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 31 def taxon @taxon = Item.find params[:id] @items = @taxon.children @goods = Good.joins(:good_items).where('good_items.item_id' => @items) if params[:area_id].to_i > 0 @area = Area.find params[:area_id] @goods = @goods.where(:provider_id => @area.providers) end if params[:provider_id].to_i > 0 @provider = Provider.find params[:provider_id] @goods = @goods.where(:provider_id => params[:provider_id]) end @goods = @goods.page(params[:page]) @goods = @goods.order("price #{params[:price_order]}") unless params[:price_order].nil? respond_to do |format| format.html format.json { render json: @goods } end end |
#wiki ⇒ Object
81 82 83 |
# File 'app/controllers/trade/admin/goods_controller.rb', line 81 def wiki @post = @good.producer.posts.where(:channel_id => Setting.wiki_channel).first end |