/// <summary> /// 充值或扣费 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnAddMoney_Click(object sender, EventArgs e) { if (!Extend.LoginState.Admin.IsAdmin) { throw new Exception("非管理员无权此操作权限!"); } Song.Entities.Accounts st = Business.Do <IAccounts>().AccountsSingle(id); if (st == null) { throw new Exception("当前信息不存在!"); } //操作类型 int type = 2; int.TryParse(rblOpera.SelectedItem.Value, out type); //操作金额 int coupon = 0; int.TryParse(tbCoupon.Text, out coupon); //操作对象 Song.Entities.CouponAccount ca = new CouponAccount(); ca.Ca_Value = coupon; ca.Ca_Total = st.Ac_Coupon; //当前卡券总数 ca.Ca_Remark = tbRemark.Text.Trim(); ca.Ac_ID = st.Ac_ID; ca.Ca_Source = "管理员操作"; //充值方式,管理员充值 ca.Ca_From = 1; //操作者 Song.Entities.EmpAccount emp = Extend.LoginState.Admin.CurrentUser; try { string mobi = !string.IsNullOrWhiteSpace(emp.Acc_MobileTel) && emp.Acc_AccName != emp.Acc_MobileTel ? emp.Acc_MobileTel : ""; //如果是充值 if (type == 2) { ca.Ca_Info = string.Format("管理员{0}({1},{2})向您充值{3}个卡券", emp.Acc_Name, emp.Acc_AccName, mobi, coupon); Business.Do <IAccounts>().CouponAdd(ca); } //如果是转出 if (type == 1) { ca.Ca_Info = string.Format("管理员{0}({1},{2})扣除您{3}个卡券", emp.Acc_Name, emp.Acc_AccName, mobi, coupon); Business.Do <IAccounts>().CouponPay(ca); } Extend.LoginState.Accounts.Refresh(st.Ac_ID); Master.AlertCloseAndRefresh("操作成功!"); } catch (Exception ex) { this.Alert(ex.Message); } }
/// <summary> /// 分配利润 /// </summary> /// <param name="cou">当前课程</param> /// <param name="acc">当前学员账户</param> /// <param name="money">消费的资金数</param> /// <param name="coupon">消费的卡数</param> public void Distribution(Course cou, Accounts acc, double money, double coupon) { Accounts[] parents = Business.Do <IAccounts>().Parents(acc); if (parents.Length < 1) { return; } //计算分润 ProfitSharing[] ps = this.Clac(cou, money, coupon); if (ps == null) { return; } int len = ps.Length > parents.Length ? parents.Length : ps.Length; for (int i = 0; i < len; i++) { //写入资金分润 if (ps[i].Ps_MoneyValue > 0) { MoneyAccount ma = new MoneyAccount(); ma.Ma_Money = ps[i].Ps_MoneyValue; ma.Ac_ID = parents[i].Ac_ID; ma.Ma_Source = "分润"; ma.Ma_Info = string.Format("{0}({1})购买课程《{2}》,获取收益{3}", acc.Ac_Name, acc.Ac_AccName, cou.Cou_Name, ps[i].Ps_MoneyValue); ma.Ma_From = 5; // ma.Ma_IsSuccess = true; ma.Org_ID = parents[i].Org_ID; if (ma.Ma_Money > 0) { ma = Business.Do <IAccounts>().MoneyIncome(ma); } } //写入卡券分润 if (ps[i].Ps_CouponValue > 0) { Song.Entities.CouponAccount ca = new CouponAccount(); ca.Ac_ID = parents[i].Ac_ID; ca.Ca_Source = "分润"; ca.Ca_Value = ps[i].Ps_CouponValue; ca.Ca_Total = parents[i].Ac_Coupon; //当前卡券总数 ca.Ca_Info = string.Format("{0}({1})购买课程《{2}》,获取收益{3}", acc.Ac_Name, acc.Ac_AccName, cou.Cou_Name, ps[i].Ps_CouponValue); ca.Ca_From = 5; if (ca.Ca_Value > 0) { Business.Do <IAccounts>().CouponAdd(ca); } } } }
/// <summary> /// 使用该充值码 /// </summary> /// <param name="entity"></param> public void CouponUseCode(RechargeCode entity) { //是否被禁用 Song.Entities.RechargeSet set = Gateway.Default.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>(); if (set == null || set.Rs_IsEnable == false) { throw new Exception("该充值码已经被禁用"); } //是否过期 if (!(DateTime.Now > entity.Rc_LimitStart && DateTime.Now < entity.Rc_LimitEnd.Date.AddDays(1))) { throw new Exception("该充值码已经过期"); } //标注已经使用 entity.Rc_IsUsed = true; entity.Rc_UsedTime = DateTime.Now; //产生流水 CouponAccount ca = new CouponAccount(); ca.Ca_Value = entity.Rc_Price; ca.Ac_ID = entity.Ac_ID; ca.Ca_From = 2; ca.Rc_Code = entity.Rc_Code + "-" + entity.Rc_Pw; ca.Ca_Source = "充值码充值"; using (DbTrans tran = Gateway.Default.BeginTrans()) { try { Business.Do <IAccounts>().CouponAdd(ca); tran.Save <RechargeCode>(entity); RechargeSet setEnity = tran.From <RechargeSet>().Where(RechargeSet._.Rs_ID == entity.Rs_ID).ToFirst <RechargeSet>(); if (setEnity != null) { setEnity.Rs_UsedCount++; tran.Save <RechargeSet>(setEnity); } tran.Commit(); } catch (Exception ex) { tran.Rollback(); throw ex; } finally { tran.Close(); } } }