
class Sku{
function __construct($quantity){
$this->quantity = $quantity;
}
};
class DateInfo{
function __construct($type, $arg0, $arg1 = null)
{
if (!is_int($type) )
exit("DateInfo.type must be integer");
$this->type = $type;
if ( $type == 1 ) //固定日期区间
{
if (!is_int($arg0) || !is_int($arg1))
exit("begin_timestamp and end_timestamp must be integer");
$this->begin_timestamp = $arg0;
$this->end_timestamp = $arg1;
}
else if ( $type == 2 ) //固定时长(自领取后多少天内有效)
{
if (!is_int($arg0))
exit("fixed_term must be integer");
$this->fixed_term = $arg0;
}else
exit("DateInfo.tpye Error");
}
};
class ba
function __construct($logo_url, $brand_name, $code_type, $ti
$desc
{
if (! $date_info instanceof DateInfo )
exit("date_info Error");
if (! $sku instanceof Sku )
exit("sku Error");
if (! is_int($code_type) )
exit("code_type must be integer");
$this->logo_url = $logo_url;
$this->brand_name = $brand_name;
$this->code_type = $code_type;
$this->ti
$this->color = $color;
$this->notice = $notice;
$this->service_phone = $service_phone;
$this->desc
$this->date_info = $date_info;
$this->sku = $sku;
}
function set_sub_ti
$this->sub_ti
}
function set_use_limit($use_limit){
if (! is_int($use_limit) )
exit("use_limit must be integer");
$this->use_limit = $use_limit;
}
function set_get_limit($get_limit){
if (! is_int($get_limit) )
exit("get_limit must be integer");
$this->get_limit = $get_limit;
}
function set_use_custom_code($use_custom_code){
$this->use_custom_code = $use_custom_code;
}
function set_bind_openid($bind_openid){
$this->bind_openid = $bind_openid;
}
function set_can_share($can_share){
$this->can_share = $can_share;
}
function set_location_id_list($location_id_list){
$this->location_id_list = $location_id_list;
}
function set_url_name_type($url_name_type){
if (! is_int($url_name_type) )
exit( "url_name_type must be int" );
$this->url_name_type = $url_name_type;
}
function set_custom_url($custom_url){
$this->custom_url = $custom_url;
}
};
class Cardba
public function __construct($ba
$this->ba
}
};
class GeneralCoupon extends Cardba
function set_default_detail($default_detail){
$this->default_detail = $default_detail;
}
};
class Groupon extends Cardba
function set_deal_detail($deal_detail){
$this->deal_detail = $deal_detail;
}
};
class Discount extends Cardba
function set_discount($discount){
$this->discount = $discount;
}
};
class Gift extends Cardba
function set_gift($gift){
$this->gift = $gift;
}
};
class Cash extends Cardba
function set_least_cost($least_cost){
$this->least_cost = $least_cost;
}
function set_reduce_cost($reduce_cost){
$this->reduce_cost = $reduce_cost;
}
};
class MemberCard extends Cardba
function set_supply_bonus($supply_bonus){
$this->supply_bonus = $supply_bonus;
}
function set_supply_balance($supply_balance){
$this->supply_balance = $supply_balance;
}
function set_bonus_cleared($bonus_cleared){
$this->bonus_cleared = $bonus_cleared;
}
function set_bonus_rules($bonus_rules){
$this->bonus_rules = $bonus_rules;
}
function set_balance_rules($balance_rules){
$this->balance_rules = $balance_rules;
}
function set_prerogative($prerogative){
$this->prerogative = $prerogative;
}
function set_bind_old_card_url($bind_old_card_url){
$this->bind_old_card_url = $bind_old_card_url;
}
function set_activate_url($activate_url){
$this->activate_url = $activate_url;
}
};
class ScenicTicket extends Cardba
function set_ticket_class($ticket_class){
$this->ticket_class = $ticket_class;
}
function set_guide_url($guide_url){
$this->guide_url = $guide_url;
}
};
class MovieTicket extends Cardba
function set_detail($detail){
$this->detail = $detail;
}
};
class Card{ //工厂
private $CARD_TYPE = Array("GENERAL_COUPON",
"GROUPON", "DISCOUNT",
"GIFT", "CASH", "MEMBER_CARD",
"SCENIC_TICKET", "MOVIE_TICKET" );
function __construct($card_type, $ba
{
if (!in_array($card_type, $this->CARD_TYPE))
exit("CardType Error");
if (! $ba
exit("ba
$this->card_type = $card_type;
switch ($card_type)
{
case $this->CARD_TYPE[0]:
$this->general_coupon = new GeneralCoupon($ba
break;
case $this->CARD_TYPE[1]:
$this->groupon = new Groupon($ba
break;
case $this->CARD_TYPE[2]:
$this->discount = new Discount($ba
break;
case $this->CARD_TYPE[3]:
$this->gift = new Gift($ba
break;
case $this->CARD_TYPE[4]:
$this->cash = new Cash($ba
break;
case $this->CARD_TYPE[5]:
$this->member_card = new MemberCard($ba
break;
case $this->CARD_TYPE[6]:
$this->scenic_ticket = new ScenicTicket($ba
break;
case $this->CARD_TYPE[8]:
$this->movie_ticket = new MovieTicket($ba
break;
default:
exit("CardType Error");
}
return true;
}
function get_card()
{
switch ($this->card_type)
{
case $this->CARD_TYPE[0]:
return $this->general_coupon;
case $this->CARD_TYPE[1]:
return $this->groupon;
case $this->CARD_TYPE[2]:
return $this->discount;
case $this->CARD_TYPE[3]:
return $this->gift;
case $this->CARD_TYPE[4]:
return $this->cash;
case $this->CARD_TYPE[5]:
return $this->member_card;
case $this->CARD_TYPE[6]:
return $this->scenic_ticket;
case $this->CARD_TYPE[8]:
return $this->movie_ticket;
default:
exit("GetCard Error");
}
}
function toJson()
{
return "{ \"card\":" . json_encode($this) . "}";
}
};
最佳答案
