using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
namespace CouponsMg.Coupons
{
public enum Period
{
/// <summary>
/// 1小時(shí)
/// </summary>
[Description("1小時(shí)")]
OneHour = 1,
/// <summary>
/// 2小時(shí)
/// </summary>
[Description("2小時(shí)")]
TwoHours = 2,
/// <summary>
/// 3小時(shí)
/// </summary>
[Description("3小時(shí)")]
ThreeHours = 3,
/// <summary>
/// 4小時(shí)
/// </summary>
[Description("4小時(shí)")]
FourHours = 4,
/// <summary>
///5小時(shí)
/// </summary>
[Description("5小時(shí)")]
FiveHours = 5,
/// <summary>
/// 6小時(shí)
/// </summary>
[Description("6小時(shí)")]
SixHours = 6,
/// <summary>
/// 8小時(shí)
/// </summary>
[Description("8小時(shí)")]
EightHours = 8,
/// <summary>
/// 9小時(shí)
/// </summary>
[Description("9小時(shí)")]
TenHours = 9,
/// <summary>
/// 12小時(shí)
/// </summary>
[Description("12小時(shí)")]
TwelveHours = 12,
/// <summary>
/// 1天
/// </summary>
[Description("1天")]
OneDay = 24,
/// <summary>
/// 2天
/// </summary>
[Description("2天")]
TwoDays = OneDay * 2,
/// <summary>
///3天
/// </summary>
[Description("3天")]
ThreeDays = OneDay * 3,
/// <summary>
/// 5天
/// </summary>
[Description("5天")]
FiveDays = OneDay * 5,
/// <summary>
/// 7天
/// </summary>
[Description("7天")]
SevenDays = OneDay * 7,
/// <summary>
/// 14天
/// </summary>
[Description("14天")]
FourteenDays = OneDay * 14,
/// <summary>
/// 1個(gè)月
/// </summary>
[Description("1個(gè)月")]
OneMonth = OneDay * 30,
/// <summary>
/// 3個(gè)月
/// </summary>
[Description("3個(gè)月")]
ThreeMonths = OneMonth *3,
/// <summary>
/// 6個(gè)月
/// </summary>
[Description("6個(gè)月")]
SixMounths = OneMonth *6,
/// <summary>
/// 1年
/// </summary>
[Description("1年")]
OneYear = OneMonth *12,
}
public abstract class CouponsBaseModel : INotifyPropertyChanged
{
#region Property Changed
public event PropertyChangedEventHandler PropertyChanged;
public void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
#region 屬性
#region 領(lǐng)取時(shí)間段
/// <summary>
/// 可領(lǐng)取優(yōu)惠券期限范圍類型荐类。默認(rèn)為7天
/// </summary>
public Period CanPickupPeriodType { get; set; } = Period.SevenDays;
private DateTime canPickUpStartTime = DateTime.Now;
/// <summary>
/// 優(yōu)惠券可領(lǐng)取開(kāi)始日期 默認(rèn)為 當(dāng)前日期
/// </summary>
public DateTime CanPickUpStartTime
{
get { return canPickUpStartTime; }
set
{
if (value == null)
{
return;
}
canPickUpStartTime = value;
CanPickUpEndTime = canPickUpStartTime.AddHours((int)CanPickupPeriodType);
OnPropertyChanged(nameof(CanPickUpStartTime));
}
}
private DateTime canPickUpEndTime = DateTime.Now.AddDays(7);
/// <summary>
/// 優(yōu)惠券可領(lǐng)取的截止日期 默認(rèn)為當(dāng)前日期后7天
/// </summary>
public DateTime CanPickUpEndTime
{
get { return canPickUpEndTime; }
set
{
if (value == null)
{
return;
}
if (CanPickUpStartTime > value)
{
throw new ArgumentOutOfRangeException("優(yōu)惠券可領(lǐng)取開(kāi)始日期不能大于截止日期");
}
canPickUpEndTime = value;
OnPropertyChanged(nameof(CanPickUpEndTime));
}
}
#endregion
#region 有效期時(shí)間段
/// <summary>
/// 優(yōu)惠券有效期時(shí)間段類型怖现,默認(rèn)為7天
/// </summary>
public Period EffectivePeriodType { get; set; } = Period.SevenDays;
private DateTime effectiveDate = DateTime.Now;
/// <summary>
/// 優(yōu)惠券生效日期. 默認(rèn)為當(dāng)前日期
/// </summary>
public DateTime EffectiveDate
{
get { return effectiveDate; }
set
{
if (value == null)
{
return;
}
effectiveDate = value;
ExpireDate = effectiveDate.AddHours((int)EffectivePeriodType);
OnPropertyChanged(nameof(EffectiveDate));
}
}
private DateTime expireDate = DateTime.Now.AddDays(7);
/// <summary>
/// 優(yōu)惠券失效日期 默認(rèn)為當(dāng)前日期后7天
/// </summary>
public DateTime ExpireDate
{
get { return expireDate; }
set
{
if (value == null)
{
return;
}
if (effectiveDate > expireDate)
{
throw new ArgumentOutOfRangeException("優(yōu)惠券生效日期不能大于失效日期");
}
expireDate = value;
OnPropertyChanged(nameof(ExpireDate));
}
}
#endregion
private double thresholdAmount = 0;
/// <summary>
/// 優(yōu)惠券使用門檻。<=0 為無(wú)門檻. 默認(rèn)為無(wú)門檻
/// </summary>
public double ThresholdAmount
{
get { return thresholdAmount; }
set
{
if (value <= 0)
{
thresholdAmount = 0;
}
else
{
thresholdAmount = value;
}
OnPropertyChanged(nameof(ThresholdAmount));
}
}
private bool isStackable = false;
/// <summary>
/// 優(yōu)惠券是否可疊加使用. 默認(rèn)為不可疊加使用
/// </summary>
public bool IsStackable
{
get { return isStackable; }
set
{
isStackable = value;
OnPropertyChanged(nameof(IsStackable));
}
}
private bool isAutoPickUp = false;
/// <summary>
/// 是否可自動(dòng)領(lǐng)取. 默認(rèn)為不可自動(dòng)領(lǐng)取
/// </summary>
public bool IsAutoPickUp
{
get { return isAutoPickUp; }
set
{
isAutoPickUp = value;
if (isAutoPickUp)
{
IsPickedUp = true;
}
OnPropertyChanged(nameof(IsAutoPickUp));
}
}
private bool isPickedUp = false;
/// <summary>
/// 是否已領(lǐng)取
/// </summary>
public bool IsPickedUp
{
get { return isPickedUp; }
set
{
isAutoPickUp = value;
OnPropertyChanged(nameof(IsPickedUp));
}
}
//是否過(guò)期
public bool IsExpired => IsPickedUp && ExpireDate < EffectiveDate;
private bool isAvailable = true;
/// <summary>
/// 是否可用。 如為否屈嗤,則不可領(lǐng)取潘拨,不可使用
/// </summary>
public bool IsAvailable
{
get { return isAvailable; }
set
{
isAvailable = value;
OnPropertyChanged(nameof(IsAvailable));
}
}
/// <summary>
/// 是否可領(lǐng)取
/// </summary>
public bool CanPickUp { get; set; }
#endregion
public void PickUp()
{
bool canPickup = CheckCouponsIsInAvailablePickupPeriod();
if (canPickup)
{
IsPickedUp = true;
EffectiveDate = DateTime.Now;
}
}
/// <summary>
/// 檢查優(yōu)惠券是否在可領(lǐng)取日期范圍內(nèi)
/// </summary>
/// <returns></returns>
private bool CheckCouponsIsInAvailablePickupPeriod()
{
if (CanPickUpStartTime == null || CanPickUpEndTime == null)
{
return false;
}
DateTime now = DateTime.Now;
//還未到可領(lǐng)取事件,不可領(lǐng)取
if (now < CanPickUpStartTime)
{
return false;
}
//已過(guò)領(lǐng)取事件饶号,不可領(lǐng)取
if (now >= CanPickUpEndTime)
{
return false;
}
return true;
}
/// <summary>
/// 檢查優(yōu)惠券可領(lǐng)取狀態(tài)
/// </summary>
/// <returns></returns>
private bool CheckCouponsCanPickableState()
{
if (IsPickedUp)
{
return false;
}
//是否在可領(lǐng)取日期范圍內(nèi)
bool isInAvailablePickupPeriod = CheckCouponsIsInAvailablePickupPeriod();
return isInAvailablePickupPeriod;
}
private bool CheckCouponsAvailableState()
{
//優(yōu)惠券已領(lǐng)取
if (IsPickedUp)
{
if (EffectiveDate == null || ExpireDate == null)
{
return false;
}
DateTime now = DateTime.Now;
//已過(guò)有效期
if (now >= CanPickUpEndTime)
{
return false;
}
return true;
}
else
{
//是否在可領(lǐng)取日期范圍內(nèi)
bool isInAvailablePickupPeriod = CheckCouponsIsInAvailablePickupPeriod();
//已過(guò)可領(lǐng)取日期
if (!isInAvailablePickupPeriod)
{
return false;
}
}
return true;
}
}
}
WPF優(yōu)惠券設(shè)計(jì)
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
- 文/潘曉璐 我一進(jìn)店門艾船,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人高每,你說(shuō)我怎么就攤上這事屿岂。” “怎么了鲸匿?”我有些...
- 文/不壞的土叔 我叫張陵爷怀,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我带欢,道長(zhǎng)霉撵,這世上最難降的妖魔是什么? 我笑而不...
- 正文 為了忘掉前任洪囤,我火速辦了婚禮,結(jié)果婚禮上撕氧,老公的妹妹穿的比我還像新娘瘤缩。我一直安慰自己,他們只是感情好伦泥,可當(dāng)我...
- 文/花漫 我一把揭開(kāi)白布剥啤。 她就那樣靜靜地躺著,像睡著了一般不脯。 火紅的嫁衣襯著肌膚如雪府怯。 梳的紋絲不亂的頭發(fā)上,一...
- 那天防楷,我揣著相機(jī)與錄音牺丙,去河邊找鬼。 笑死,一個(gè)胖子當(dāng)著我的面吹牛冲簿,可吹牛的內(nèi)容都是我干的粟判。 我是一名探鬼主播,決...
- 文/蒼蘭香墨 我猛地睜開(kāi)眼峦剔,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼档礁!你這毒婦竟也來(lái)了?” 一聲冷哼從身側(cè)響起吝沫,我...
- 序言:老撾萬(wàn)榮一對(duì)情侶失蹤呻澜,失蹤者是張志新(化名)和其女友劉穎,沒(méi)想到半個(gè)月后惨险,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體羹幸,經(jīng)...
- 正文 獨(dú)居荒郊野嶺守林人離奇死亡,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
- 正文 我和宋清朗相戀三年平道,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了睹欲。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
- 正文 年R本政府宣布,位于F島的核電站诽嘉,受9級(jí)特大地震影響蔚出,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜虫腋,卻給世界環(huán)境...
- 文/蒙蒙 一骄酗、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧悦冀,春花似錦趋翻、人聲如沸。這莊子的主人今日做“春日...
- 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)。三九已至历等,卻和暖如春讨惩,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背寒屯。 一陣腳步聲響...
- 正文 我出身青樓靴患,卻偏偏與公主長(zhǎng)得像仍侥,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子鸳君,可洞房花燭夜當(dāng)晚...
推薦閱讀更多精彩內(nèi)容
- 優(yōu)惠券對(duì)于大家來(lái)說(shuō)應(yīng)該都不會(huì)陌生农渊,甚至大家都有使用過(guò)乏沸。不知道大家在得到優(yōu)惠券的時(shí)候會(huì)不會(huì)有一種要消費(fèi)的沖動(dòng)渡讼,拿到的...
- 優(yōu)惠券是一種常見(jiàn)的促銷方式,在規(guī)定的周期內(nèi)購(gòu)買對(duì)應(yīng)商品類型和額度的商品時(shí)讹躯,結(jié)算時(shí)滿足一定條件會(huì)減免一定金額囱挑。通過(guò)發(fā)...
- 第一篇中已經(jīng)梳理了優(yōu)惠券的幾種基本類型醉顽,同時(shí)發(fā)現(xiàn)從運(yùn)營(yíng)效果的角度,只是把營(yíng)銷活動(dòng)“券化”并不比直接使用營(yíng)銷活動(dòng)有更...
- 本文將從優(yōu)惠券設(shè)計(jì)用戶端平挑,需求端游添,業(yè)務(wù)流程全方案解析優(yōu)惠券設(shè)計(jì)方案 小編比較懶,懶得做流程圖通熄,全文都是文字 為什么...
- 電商優(yōu)惠券邏輯唆涝,優(yōu)惠券的玩法很多,主要講一下比較常見(jiàn)的優(yōu)惠券: 一唇辨、新人紅包(滿減) 第一次登錄注冊(cè)某平臺(tái)廊酣,登錄成...