protected override XResp Execute() { x_lottery ent = null; if (id > 0) { ent = DB.x_lottery.SingleOrDefault(o => o.lottery_id == id); if (ent == null) { throw new XExcep("0x0005"); } } if (ent == null) { ent = new x_lottery() { ctime = DateTime.Now } } ; ent.remark = desc; ent.sum = sum; ent.runtp = tp; ent.topic = topic; ent.status = 1; if (tp == 2) { ent.rules = ""; if (tj.Contains("[1]")) { ent.rules += "1-" + hc + ","; } if (tj.Contains("[2]")) { ent.rules += "2-" + oc + ","; } if (tj.Contains("[3]")) { ent.rules += "3-" + ac + ","; } ent.rules = ent.rules.TrimEnd(','); if (string.IsNullOrEmpty(ent.rules)) { throw new XExcep("T请选择至少一个条件"); } } if (id == 0) { DB.x_lottery.InsertOnSubmit(ent); } SubmitDBChanges(); return(new XResp()); } }
protected override XResp Execute() { x_lottery ent = DB.x_lottery.FirstOrDefault(o => o.lottery_id == id); if (ent == null) { throw new XExcep("T抽奖项目不存在"); } DB.x_lottery_item.DeleteAllOnSubmit(ent.x_lottery_item); DB.x_lottery_run.DeleteAllOnSubmit(ent.x_lottery_run); DB.x_lottery.DeleteOnSubmit(ent); SubmitDBChanges(); return(new XResp()); }
void RunLot(x_lottery lot, int m) { var lg = new x_lottery_run(); lg.ctime = DateTime.Now; lg.open = m + ""; lg.sum = lot.sum < 1 ? cfg.pool_lott * lot.sum : lot.sum; lg.title = lot.topic + DateTime.Now.ToString("yyyy-MM-dd") + "期开奖"; lot.x_lottery_run.Add(lg); SubmitDBChanges(); var us = new List <long?>(); foreach (var i in lot.x_lottery_item)//奖项 { if (i.count == 0) { continue; } for (var c = 0; c < i.count; c++)//份数 { var sc = DB.x_secode .Where(o => !us.Contains(o.user_id) && o.user_id > 0) .Select(o => o.user_id) .OrderBy(o => Guid.NewGuid().ToString()) .FirstOrDefault(); if (sc == null || sc == 0) { continue; } var u = DB.x_user.FirstOrDefault(o => o.user_id == sc); if (u == null) { continue; } var p = new x_user_prize() { isget = false, lottery_run_id = lg.lottery_run_id, prize = i.name, val = i.price < 1 ? lg.sum * i.price : i.price, remark = "", title = lg.title }; u.x_user_prize.Add(p); //积分记录 if (i.type == 1) { var v = p.val / cfg.credit; var ep = new x_exp_log() { ctime = DateTime.Now, remark = lg.title + "-" + i.name + "-" + v, val = v }; u.x_exp_log.Add(ep); u.exp += ep.val; } SubmitDBChanges(); } } }