/vpsys

VIP積分系統,主要是為了方便管理積分,增加銷售額...

Primary LanguageRuby

== Welcome to VPSYS

一.VIP會員模板 --> will_paginate
ruby script/generate scaffold Viper 
bndid:string 
cardtype:string 
cardno:string 
cmpid:string 
ctrid:string 
shop:string 
cname:string 
cname:string 
ename:string 
ename:string 
gender:string 
bdate:datetime 
idcard:string 
city:string 
marr:string 
degree:string 
occup:string 
income:string 
address1:text 
address2:text 
address:text 
hometel:string 
offitel:string 
bpno:string 
email:string 
grade:string 
adate:datetime 



二.權限認證模板-->restful-authentication + declarative authorization

ruby script/generate authenticated user sessions
rake db:migrate

ruby script/generate migration AddRolesToUsers roles:text

class AddRolesToUsers < ActiveRecord::Migration
  def self.up
    add_column :users, :roles, :string, :default => "qsguy"
  end

  def self.down
    remove_column :users, :roles
  end
end

rake db:migrate

config/authorization_rules.rb

authorization do
  role :guest do
    has_permission_on :users, :to => [:read_index,:create]
  end
 
  role :qsguy do
    includes :guest
    has_permission_on :users, :to => [:read_show,:update] do
      if_attribute :id => is {user.id}
    end
  end
 
  role :firefly do
    has_permission_on :users, :to => :manage
  end
end
 
privileges do
  privilege :manage, :includes => [:create, :read, :update, :delete]
  privilege :read, :includes => [:index, :show]
  privilege :read_index, :includes => :index
  privilege :read_show, :includes => :show
  privilege :create, :includes => :new
  privilege :update, :includes => :edit
  privilege :delete, :includes => :destroy
end

#为了实现授权规则与业务逻辑相分离,declarative authorization指定把所有的授权规则都定义到一个配置文件中,
#并为我们提供专门的DSL来编写授权规则.
#首先,我们得把\vendor \plugins\declarative_authorization目录下的样本authorization_rules.dist.rb复制到 config目录下,
#并更名为authorization_rules.rb.打开authorization_rules.rb,去掉注释

#整个代码分为两大块,授权块与特权块.

#先看特权块,已给定了五个特权,四个简单的特权(:read,:update,:create,:delete)和一个复合特权 (:manage).
#include 后面的就是controller的action的名字.看下图,在rails的应用中,我们要对某个资源进行操作,必須经过action.
#而对于某些 action,它是以另一个action为前提.如update action,必然先经过edit action,通过edit action渲染出视图,再有edit.html上的表单提交到到达update action.
#因此,那四个简单特权就构建index、show、edit、update和destroy这五个restful风格的action的访问控制上就行.如果不满意的话,也可以自定义action,再对其进行访问控制.

#再看授权块,它是用来分配权限.注意,是权限(Permission),不是特权(Privilege).就在我们刚说完的特权块中,
#那些特权都是光指对某些资源的控制器的action进行访问控制,但并没有指定具体的资源类别,这里我们就要把这些特权转化为权限了.
#既然说是权限,那么“限”谁呢?嗯,不难看出,是限制到某个角色,限制到某种资源,只有特定角色才能对特定资源进行特定操作,而且还要满足一定的要求
#(如控制器中开启属性检查.具体的检查方法就是在这里定义的).一个流行公式是这样的:权限 =  资源 + 操作。这里得变通一下,操作都封装在特权里,
#一个特权可能拥有N个操作,而且还有属性检举查这样条件,因此 权限 = 资源 * 特权 if 条件.而一个角色或许能对多种资源进行操作,因此,从某种意义上讲,
#角色就是一定数量的权限的集合.了解完这些,让我们编写些授权规则吧.在默认情况下,已经为我们分配了一个guest角色.它将在请求和任何用户都没有关联或当一个用户没有任何角色时被调用.
#因此,如果我们的应用程序有一些公共页面,可以用guest来让那些没有登录的用户实现访问.现在我们的应用还很小很小,只有两个资源(User与 Session).为了让用户自由登录,我们不应该在Session中设置授权控制.
#User资源,我们打算让index可以让任何人访问,show与 edit只有该用户才能访问到——这当然要求登录成为wikier,要求基本不能进行属性检查以判断其是否同一个人!

三.建立积分机制
由于前台问题还没协商,因此此部分只增加了三个字段:
point | discount | tolamount
具体开发计划推迟到前台协商清楚后...

四.增加分类与Tag

1.目前分类已经处理完,如下:

/models/viper.rb
    named_scope :reward, :select => "id,cname,point",:limit=> 10,:order =>"point DESC"
    named_scope :latest, :select => "id,cname,updated_at",:limit=> 10,:order =>"updated_at DESC"
    named_scope :hot, :select => "id,cname,tolamount",:limit=> 10,:order =>"tolamount DESC"
(备注:此部分的设定是暂时的,因为急需一个大概的版面,具体的修改会根据用户进一步需求...)
/views/vipers/index.rhtml
<% title "我的VIP客戶"  %>
<table class="columns" >
  <tr>
    <td>
      <h3>最新客戶</h3>
      <ul class="poker">
        <% @vipers = Viper.latest.each do |viper| %>
          <li><%= link_to viper.cname,viper %></li>
        <% end %>
      </ul>
    </td>
    <td>
      <h3>消费排名</h3>
      <ul class="poker">
        <% @vipers = Viper.hot.each do |viper| %>
          <li><%= link_to viper.cname+ "(累计消费额:#{viper.tolamount})",viper %></li>
        <% end %>
      </ul>
    </td>
  </tr>
  <tr>
    <td>
      <h3>高分客戶</h3>
      <ul class="poker">
        <% @vipers = Viper.reward.each do |viper| %>
          <li><%= link_to viper.cname+ "(積分:#{viper.point})" ,viper %></li>
        <% end %>
      </ul>
    </td>
    </tr>
 <div>
  <%#= tag_cloud @tags %>
</div>
<hr>
<%= link_to '新增VIP客户 ', new_viper_path %>
<%# keywords @tags.to_sentence  %>
<% #description "RailsKiller fireflyman, rails版的微型维基" %>

2.标签Tag功能
这部分功能准备用插件-->acts_as_taggable_on_steroids来开发,具体参考:
http://www.cnblogs.com/rubylouvre/archive/2009/07/01/1511559.html

不过在进一步分析后,发现Tag可能对该项目的开发没多发作用,因此目前处于后备任务..

五.搜索功能开发
目前正在选型中:acts_as_ferret或者thinking sphinx

初步确认ferret是不准备使用的了...研究thinking sphinx的用法