/// <summary> /// 添加分润项 /// </summary> /// <param name="entity">业务实体</param> public int ProfitAdd(ProfitSharing entity) { //添加对象,并设置排序号 object obj = Gateway.Default.Max <ProfitSharing>(ProfitSharing._.Ps_Level, ProfitSharing._.Ps_PID == entity.Ps_PID); int tax = obj is int?(int)obj : 0; entity.Ps_Level = tax + 1; entity.Ps_IsTheme = false; //验证资金分润比例之合,是否大于100 object objm = Gateway.Default.Sum <ProfitSharing>(ProfitSharing._.Ps_Moneyratio, ProfitSharing._.Ps_PID == entity.Ps_PID); int summ = objm is int?(int)objm : 0; if ((summ + entity.Ps_Moneyratio) > 100) { throw new Exception("资金分润比例之合,不得大于100"); } //验证卡券分润比例之合,是否大于100 object objc = Gateway.Default.Sum <ProfitSharing>(ProfitSharing._.Ps_Moneyratio, ProfitSharing._.Ps_PID == entity.Ps_PID); int sumc = objc is int?(int)objc : 0; if ((sumc + entity.Ps_Couponratio) > 100) { throw new Exception("卡券分润比例之合,不得大于100"); } Gateway.Default.Save <ProfitSharing>(entity); return(entity.Ps_ID); }
/// <summary> /// 机构的分润方案 /// </summary> /// <param name="orgid">机构id</param> /// <returns></returns> public ProfitSharing ThemeCurrent(int orgid) { //课程所在机构 Organization org = Business.Do <IOrganization>().OrganSingle(orgid); if (org == null) { return(null); } //所属机构等级 OrganLevel olevel = Business.Do <IOrganization>().LevelSingle(org.Olv_ID); if (olevel == null) { return(null); } //分润方案 ProfitSharing psTheme = this.ThemeSingle(olevel.Ps_ID); if (psTheme == null) { return(null); //如果没有设置分润方案 } if (!psTheme.Ps_IsUse) { return(null); //如果分润方案没有启用 } return(psTheme); }
public ProfitSharing[] Clac(Course cou, double money, double coupon) { if (cou == null) { return(null); } //分润方案 ProfitSharing psTheme = this.ThemeCurrent(cou.Org_ID); if (psTheme == null) { return(null); //如果没有设置分润方案 } if (!psTheme.Ps_IsUse) { return(null); //如果分润方案没有启用 } ProfitSharing[] profits = this.ProfitAll(psTheme.Ps_ID, true); if (profits.Length < 1) { return(null); } //计算 for (int i = 0; i < profits.Length; i++) { profits[i].Ps_MoneyValue = (decimal)profits[i].Ps_Moneyratio * ((decimal)money / 100); profits[i].Ps_CouponValue = (int)Math.Floor(profits[i].Ps_Couponratio * ((double)coupon) / 100); } return(profits); }
/// <summary> /// 添加分润主题 /// </summary> /// <param name="entity">业务实体</param> public int ThemeAdd(ProfitSharing entity) { //添加对象,并设置排序号 object obj = Gateway.Default.Max <ProfitSharing>(ProfitSharing._.Ps_Level, ProfitSharing._.Ps_IsTheme == true); int tax = obj is int?(int)obj : 0; entity.Ps_Level = tax + 1; entity.Ps_IsTheme = true; Gateway.Default.Save <ProfitSharing>(entity); return(entity.Ps_ID); }
public ProfitSharing[] Clac(Course cou, double money, double coupon) { if (cou == null) { return(null); } //课程所在机构 Organization org = Business.Do <IOrganization>().OrganSingle(cou.Org_ID); if (org == null) { return(null); } //所属机构等级 OrganLevel olevel = Business.Do <IOrganization>().LevelSingle(org.Olv_ID); if (olevel == null) { return(null); } //分润方案 ProfitSharing psTheme = this.ThemeSingle(olevel.Ps_ID); if (psTheme == null) { return(null); //如果没有设置分润方案 } if (!psTheme.Ps_IsUse) { return(null); //如果分润方案没有启用 } ProfitSharing[] profits = this.ProfitAll(olevel.Ps_ID, true); if (profits.Length < 1) { return(null); } //计算 for (int i = 0; i < profits.Length; i++) { profits[i].Ps_MoneyValue = (decimal)profits[i].Ps_Moneyratio * ((decimal)money / 100); profits[i].Ps_CouponValue = (int)Math.Floor(profits[i].Ps_Couponratio * ((double)coupon) / 100); } return(profits); }
/// <summary> /// 修改 /// </summary> /// <param name="entity">业务实体</param> public void ProfitSave(ProfitSharing entity) { //验证资金分润比例之合,是否大于100 object objm = Gateway.Default.Sum <ProfitSharing>(ProfitSharing._.Ps_Moneyratio, ProfitSharing._.Ps_PID == entity.Ps_PID && ProfitSharing._.Ps_ID != entity.Ps_ID); int summ = objm is int?(int)objm : 0; if ((summ + entity.Ps_Moneyratio) > 100) { throw new Exception("资金分润比例之合,不得大于100"); } //验证卡券分润比例之合,是否大于100 object objc = Gateway.Default.Sum <ProfitSharing>(ProfitSharing._.Ps_Moneyratio, ProfitSharing._.Ps_PID == entity.Ps_PID && ProfitSharing._.Ps_ID != entity.Ps_ID); int sumc = objc is int?(int)objc : 0; if ((sumc + entity.Ps_Couponratio) > 100) { throw new Exception("卡券分润比例之合,不得大于100"); } //保存 Gateway.Default.Save <ProfitSharing>(entity); }
/// <summary> /// 将当前项目向下移动; /// </summary> /// <param name="id"></param> /// <returns>如果已经处于顶端,则返回false;移动成功,返回true</returns> public bool ProfitRemoveDown(int id) { //当前对象 ProfitSharing current = Gateway.Default.From <ProfitSharing>().Where(ProfitSharing._.Ps_ID == id).ToFirst <ProfitSharing>(); //当前对象排序号 int orderValue = (int)current.Ps_Level; //下一个对象,即弟弟对象; ProfitSharing down = Gateway.Default.From <ProfitSharing>().Where(ProfitSharing._.Ps_PID == current.Ps_PID && ProfitSharing._.Ps_Level > orderValue) .OrderBy(ProfitSharing._.Ps_Level.Asc).ToFirst <ProfitSharing>(); //如果弟对象不存在,则表示当前节点在兄弟中是老幺;即是最底端; if (down == null) { return(false); } //交换排序号 current.Ps_Level = down.Ps_Level; down.Ps_Level = orderValue; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save <ProfitSharing>(current); tran.Save <ProfitSharing>(down); tran.Commit(); return(true); } catch { tran.Rollback(); throw; } finally { tran.Close(); } } }
/// <summary> /// 将当前项目向上移动; /// </summary> /// <param name="id"></param> /// <returns>如果已经处于顶端,则返回false;移动成功,返回true</returns> public bool ProfitRemoveUp(int id) { //当前对象 ProfitSharing current = Gateway.Default.From <ProfitSharing>().Where(ProfitSharing._.Ps_ID == id).ToFirst <ProfitSharing>(); //当前对象排序号 int orderValue = (int)current.Ps_Level; //上一个对象,即兄长对象; ProfitSharing up = Gateway.Default.From <ProfitSharing>().Where(ProfitSharing._.Ps_PID == current.Ps_PID && ProfitSharing._.Ps_Level < orderValue) .OrderBy(ProfitSharing._.Ps_Level.Desc).ToFirst <ProfitSharing>(); //如果兄长对象不存在,则表示当前节点在兄弟中是老大;即是最顶点; if (up == null) { return(false); } //交换排序号 current.Ps_Level = up.Ps_Level; up.Ps_Level = orderValue; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { tran.Save <ProfitSharing>(current); tran.Save <ProfitSharing>(up); tran.Commit(); return(true); } catch { tran.Rollback(); throw; } finally { tran.Close(); } } }
/// <summary> /// 删除 /// </summary> /// <param name="entity">业务实体</param> public void ThemeDelete(ProfitSharing entity) { this.ThemeDelete(entity.Ps_ID); }
/// <summary> /// 修改 /// </summary> /// <param name="entity">业务实体</param> public void ThemeSave(ProfitSharing entity) { Gateway.Default.Save <ProfitSharing>(entity); }
/// <summary> /// 删除 /// </summary> /// <param name="entity">业务实体</param> public void ProfitDelete(ProfitSharing entity) { Gateway.Default.Delete <ProfitSharing>(entity); }