1.點(diǎn)擊用以扣分的房號(hào)
2.在后臺(tái)生成訂單,并調(diào)用扣除積分的方法
int gId = Convert.ToInt32(gid);
string GName = "";
var good = db.S_Goods.SingleOrDefault(p=>p.GID == gId);
if (good != null)
{
GName = good.GName;
}
//計(jì)算價(jià)格
int a = Convert.ToInt32(gcount);//數(shù)量
double b = Convert.ToDouble(UNitePrice);
var price = a * b;
S_Order pl = new S_Order();
pl.SPID = Convert.ToInt32(gid);
pl.OCount = Convert.ToInt32(gcount);
pl.OPeople = uname;
pl.Otel = uphone;
pl.OUSERID = Convert.ToInt32(uid);
pl.OCreatTime = DateTime.Now;
pl.OState = "0";//初始為未支付
pl.SPrice = Convert.ToInt32(price);
pl.SPName = GName;
string UseTime = DateTime.Now.Year + "-12-31 23:59:59";
pl.UseTime = Convert.ToDateTime(UseTime);
db.S_Order.Add(pl);
db.SaveChanges();
int ID1 = Convert.ToInt32(IDs);//房號(hào)
Jifen.JFDel(ID1,Convert.ToDecimal(price), Convert.ToInt32(uid),pl.OrderID); //扣積分的方法
3 積分扣除方法
//積分扣除
public static void JFDel(int id,decimal price,int MID,int OrderId)
{
Entities db = new Entities();
decimal Ms = new decimal();//扣分過程中已扣的分
int ID1 = Convert.ToInt32(id);//房號(hào)
DateTime Now = DateTime.Now;
DateTime Now1 = Now.AddDays(-1);
var Sml = db.S_MoneyLog.Where(p => p.HID == ID1 && p.State1 == 1 && p.State2 == 1 && p.State3 == 1 && p.State4 == 1 && p.State5 == 1&&Now>=p.StartTime&&Now1<p.EndTime);//積分卷
Sml= Sml.OrderBy(p=>p.EndTime);//按結(jié)束日期排序,先扣快過期的積分卷
foreach (var i1 in Sml)
{
if (Ms>=price) {
return;
}
var Smd = db.S_MoneyDel.Where(p => p.SMLID == i1.Id);//積分卷的扣分記錄
decimal M1 = new decimal();
foreach (var i2 in Smd)
{
M1 += Convert.ToDecimal(i2.Money); //積分卷以往扣除的積分
}
if (M1 < i1.Money) //如果還有分
{
decimal M2 = Convert.ToDecimal(i1.Money) - M1;//積分卷剩余積分
if (M2 > (Convert.ToDecimal(price)-Ms)) //判斷是否足夠
{
S_MoneyDel smd1 = new S_MoneyDel();
smd1.SGID = OrderId;
smd1.Time = DateTime.Now;
smd1.MID = MID;
smd1.Money = Convert.ToDecimal(price)-Ms;
smd1.SMLID = i1.Id;
db.S_MoneyDel.Add(smd1);
db.SaveChanges();
Ms += Convert.ToDecimal(price);
return;
}
else //不夠全扣掉
{
S_MoneyDel smd1 = new S_MoneyDel();
smd1.SGID = OrderId;
smd1.Time = DateTime.Now;
smd1.MID = MID;
smd1.Money = M2;
smd1.SMLID = i1.Id;
db.S_MoneyDel.Add(smd1);
db.SaveChanges();
Ms += M2;
}
}
}
}