308 lines
12 KiB
C#
308 lines
12 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Linq;
|
|||
|
|
using System.Text;
|
|||
|
|
using System.Threading.Tasks;
|
|||
|
|
using dccdc.Models;
|
|||
|
|
using Dapper;
|
|||
|
|
|
|||
|
|
namespace dccdc.DAL
|
|||
|
|
{
|
|||
|
|
public class JmsqDal
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
/// 减免申请操作
|
|||
|
|
/// </summary>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public bool Add(JmsqModel model, List<JmmxModel> al)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|||
|
|
{
|
|||
|
|
string sql = @"INSERT INTO [dbo].[jmsq]
|
|||
|
|
([ymdjid]
|
|||
|
|
,[xm]
|
|||
|
|
,[sqrid]
|
|||
|
|
,[sqrxm]
|
|||
|
|
,[sqsj]
|
|||
|
|
,[lx]
|
|||
|
|
,[shsj]
|
|||
|
|
,[shrid],jmlx)
|
|||
|
|
VALUES
|
|||
|
|
(@ymdjid
|
|||
|
|
,@xm
|
|||
|
|
,@sqrid
|
|||
|
|
,@sqrxm
|
|||
|
|
,@sqsj
|
|||
|
|
,@lx
|
|||
|
|
,@shsj
|
|||
|
|
,@shrid,@jmlx) SELECT SCOPE_IDENTITY()";
|
|||
|
|
int id = conn.ExecuteScalar<int>(sql, model);
|
|||
|
|
List<JmmxModel> al1 = new List<JmmxModel>();
|
|||
|
|
foreach (JmmxModel m in al)
|
|||
|
|
{
|
|||
|
|
m.jmsqid = id;
|
|||
|
|
al1.Add(m);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
string sql1 = @"INSERT INTO [dbo].[jmmx]
|
|||
|
|
([jmsqid]
|
|||
|
|
,[sfxmid]
|
|||
|
|
,[jmsl]
|
|||
|
|
,[jmdj],detailid)
|
|||
|
|
VALUES
|
|||
|
|
(@jmsqid
|
|||
|
|
,@sfxmid
|
|||
|
|
,@jmsl
|
|||
|
|
,@jmdj,@detailid)";
|
|||
|
|
int type = conn.Execute(sql1, al1);
|
|||
|
|
return type != 0;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
public object delJMSQ(int id, ERPUser user)
|
|||
|
|
{
|
|||
|
|
//throw new NotImplementedException();
|
|||
|
|
string sql = "select * from jmsq where id=@id";
|
|||
|
|
using (var conn = CommHelper.GetSqlConnection())
|
|||
|
|
{
|
|||
|
|
var jmsq = conn.Query<Models.JmsqModel>(sql, new { id }).FirstOrDefault();
|
|||
|
|
if (jmsq == null)
|
|||
|
|
{
|
|||
|
|
return new
|
|||
|
|
{
|
|||
|
|
State = 0,
|
|||
|
|
Message = "没有你要删除的数据!"
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
if (jmsq.sqrid != user.ID)
|
|||
|
|
{
|
|||
|
|
return new { State = 0, Message = "不能删除非自己的申请!" };
|
|||
|
|
}
|
|||
|
|
if (jmsq.lx != 0)
|
|||
|
|
{
|
|||
|
|
return new { State = 0, Message = "不能删除已经审核的数据!" };
|
|||
|
|
}
|
|||
|
|
sql = "delete from jmsq where id=@id";
|
|||
|
|
int c = conn.Execute(sql, new { id });
|
|||
|
|
if (c != 0)
|
|||
|
|
{
|
|||
|
|
return new { State = 1, Message = "删除成功!" };
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
return new { State = 0, Message = "没有要删除的数据!" };
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// 获取申请列表
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="lx"></param>
|
|||
|
|
/// <param name="jmlx"></param>
|
|||
|
|
/// <param name="xm"></param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public List<JmsqModel> GetJmsqList(string lx, string jmlx, string xm, string sqsjb, string sqsje)
|
|||
|
|
{
|
|||
|
|
StringBuilder u = new StringBuilder("select a.*,b.chargeid from jmsq a join YMDJ b on a.ymdjid=b.id where 1=1");
|
|||
|
|
if (jmlx != "-1")
|
|||
|
|
{
|
|||
|
|
u.Append(" and a.jmlx=@jmlx");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(lx))
|
|||
|
|
{
|
|||
|
|
u.Append(" and a.lx=@lx");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(xm))
|
|||
|
|
{
|
|||
|
|
u.Append(" and a.xm like @xm");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(sqsjb))
|
|||
|
|
{
|
|||
|
|
u.Append(" and a.sqsj >'" + sqsjb + "'");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(sqsje))
|
|||
|
|
{
|
|||
|
|
u.Append(" and a.sqsj <'" + sqsje + "'");
|
|||
|
|
}
|
|||
|
|
u.Append(" order by a.sqsj desc");
|
|||
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|||
|
|
{
|
|||
|
|
return conn.Query<JmsqModel>(u.ToString(), new { lx, jmlx, xm = "%" + xm + "%" }).ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public List<JmsqModel> GetJmsqList2(string xm, string shrid)
|
|||
|
|
{
|
|||
|
|
StringBuilder u = new StringBuilder("select a.*,b.chargeid from jmsq a join YMDJ b on a.ymdjid=b.id where 1=1");
|
|||
|
|
if (!string.IsNullOrEmpty(xm))
|
|||
|
|
{
|
|||
|
|
u.Append(" and a.xm like @xm");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(shrid))
|
|||
|
|
{
|
|||
|
|
u.Append(" and a.shrid = @shrid");
|
|||
|
|
}
|
|||
|
|
u.Append(" order by a.sqsj desc");
|
|||
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|||
|
|
{
|
|||
|
|
return conn.Query<JmsqModel>(u.ToString(), new { xm = "%" + xm + "%", shrid = shrid }).ToList();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public DataTable expJMJL(string lx, string jmlx, string xm, string sqsjb, string sqsje)
|
|||
|
|
{
|
|||
|
|
StringBuilder u = new StringBuilder("select * from jmsq where 1=1");
|
|||
|
|
DataTable dt = new DataTable();
|
|||
|
|
dt.Columns.Add("申请人");
|
|||
|
|
dt.Columns.Add("申请时间");
|
|||
|
|
dt.Columns.Add("审核人");
|
|||
|
|
dt.Columns.Add("审核时间");
|
|||
|
|
dt.Columns.Add("减免内容");
|
|||
|
|
dt.Columns.Add("减免金额");
|
|||
|
|
if (jmlx != "-1")
|
|||
|
|
{
|
|||
|
|
u.Append(" and jmlx=@jmlx");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(lx))
|
|||
|
|
{
|
|||
|
|
u.Append(" and lx=@lx");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(xm))
|
|||
|
|
{
|
|||
|
|
u.Append(" and xm like @xm");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(sqsjb))
|
|||
|
|
{
|
|||
|
|
u.Append(" and sqsj >'" + sqsjb + "'");
|
|||
|
|
}
|
|||
|
|
if (!string.IsNullOrEmpty(sqsje))
|
|||
|
|
{
|
|||
|
|
u.Append(" and sqsj <'" + sqsje + "'");
|
|||
|
|
}
|
|||
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|||
|
|
{
|
|||
|
|
var list = conn.Query<JmsqModel>(u.ToString(), new { lx, jmlx, xm = "%" + xm + "%" }).ToList();
|
|||
|
|
foreach (var v in list)
|
|||
|
|
{
|
|||
|
|
DataRow dr = dt.NewRow();
|
|||
|
|
dr["申请人"] = v.sqrxm;
|
|||
|
|
dr["申请时间"] = v.sqsj;
|
|||
|
|
dr["审核人"] = v.shr;
|
|||
|
|
dr["审核时间"] = v.shsj;
|
|||
|
|
string sql = "select a.jmdj,a.jmsl,b.charge_project_name from jmmx a join charge_project_maintain b on a.sfxmid=b.id where a.jmsqid=" + v.id;
|
|||
|
|
var jmmxlist = conn.Query(sql).ToList();
|
|||
|
|
string jmnr = "";
|
|||
|
|
decimal jmje = 0;
|
|||
|
|
for (int i = 0; i < jmmxlist.Count; i++)
|
|||
|
|
{
|
|||
|
|
jmnr += jmmxlist[i].charge_project_name + ";";
|
|||
|
|
jmje += jmmxlist[i].jmsl * jmmxlist[i].jmdj;
|
|||
|
|
}
|
|||
|
|
dr["减免内容"] = jmnr;
|
|||
|
|
dr["减免金额"] = jmje;
|
|||
|
|
dt.Rows.Add(dr);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
return dt;
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// 根据主键修改减免申请状态
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="id"></param>
|
|||
|
|
/// <param name="lx">0:申请,1:通过,2:未通过</param>
|
|||
|
|
/// <returns></returns>
|
|||
|
|
public Models.DTO.ymshjg Updatelx(string id, string lx, ERPUser erpUser)
|
|||
|
|
{
|
|||
|
|
using (IDbConnection conn = CommHelper.GetSqlConnection())
|
|||
|
|
{
|
|||
|
|
string sql = @"update jmsq set lx=@lx,shsj=convert(varchar(50),getdate(),121),shrid=@shrid,shr=@shr where id=@id";
|
|||
|
|
Models.DTO.ymshjg ym = new Models.DTO.ymshjg();
|
|||
|
|
|
|||
|
|
if (lx == "1")
|
|||
|
|
{
|
|||
|
|
string sql1 = "";
|
|||
|
|
|
|||
|
|
sql1 = "select * from jmsq where id=@id";
|
|||
|
|
var jmsq = conn.Query<Models.JmsqModel>(sql1, new { id = id }).FirstOrDefault();
|
|||
|
|
ym.jz = jmsq.xm;
|
|||
|
|
sql1 = "select sum(jmsl*jmdj) from jmmx where jmsqid=@id";
|
|||
|
|
decimal jmje = conn.ExecuteScalar<decimal>(sql1, new { id });
|
|||
|
|
sql1 = " select money from charge where id = ( select j.chargeid from jmsq q inner join YMDJ j on q.ymdjid=j.id and q.id=@id) ";
|
|||
|
|
decimal yjje = conn.ExecuteScalar<decimal>(sql1, new { id });
|
|||
|
|
ym.yj = yjje.ToString();
|
|||
|
|
if (jmsq.jmlx == 1)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
sql1 = @"select count(1) from jmsq q inner join YMDJ j on q.ymdjid=j.id join charge_detail c on c.chargeid=j.chargeid
|
|||
|
|
where q.id =@id";
|
|||
|
|
int jydjc = conn.ExecuteScalar<int>(sql1, new { id = id });
|
|||
|
|
sql1 = " select count(1) from jmmx where jmsqid = @id";
|
|||
|
|
int jmc = conn.ExecuteScalar<int>(sql1, new { id = id });
|
|||
|
|
if (jmc == jydjc)
|
|||
|
|
{
|
|||
|
|
sql1 = "update charge set status='免费' where id = ( select j.chargeid from jmsq q inner join YMDJ j on q.ymdjid=j.id where q.id=@id)";
|
|||
|
|
conn.Execute(sql1, new { id });
|
|||
|
|
sql1 = "update ymdj set jfzt='已缴费' where id=@id";
|
|||
|
|
conn.Execute(sql1, new { id = jmsq.ymdjid });
|
|||
|
|
ym.sj = "0";
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sql1 = "select * from jmmx where jmsqid=@id";
|
|||
|
|
List<Models.JmmxModel> jmmxs = conn.Query<Models.JmmxModel>(sql1, new { id = id }).ToList();
|
|||
|
|
var jehj = 0.0m;
|
|||
|
|
foreach (var mx in jmmxs)
|
|||
|
|
{
|
|||
|
|
|
|||
|
|
sql1 = "delete from charge_detail where id=@id";
|
|||
|
|
int c = conn.Execute(sql1, new { id = mx.detailid });
|
|||
|
|
if (c > 0)
|
|||
|
|
{
|
|||
|
|
jehj += mx.jmdj * mx.jmsl;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
sql1 = "update charge set status='未缴费',money=money-@money where id = ( select j.chargeid from jmsq q inner join YMDJ j on q.ymdjid=j.id where q.id=@id)";
|
|||
|
|
conn.Execute(sql1, new { id, money = jehj });
|
|||
|
|
ym.sj = (yjje - jmje).ToString();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
sql1 = "select * from jmmx where jmsqid=@id";
|
|||
|
|
List<Models.JmmxModel> jmmxs = conn.Query<Models.JmmxModel>(sql1, new { id = id }).ToList();
|
|||
|
|
var jehj = 0.0m;
|
|||
|
|
foreach (var mx in jmmxs)
|
|||
|
|
{
|
|||
|
|
//jehj += mx.jmdj * mx.jmsl;
|
|||
|
|
sql1 = "delete from charge_detail where id=@id";
|
|||
|
|
int c = conn.Execute(sql1, new { id = mx.detailid });
|
|||
|
|
if (c > 0)
|
|||
|
|
{
|
|||
|
|
jehj += mx.jmdj * mx.jmsl;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
sql1 = "update charge set status='未缴费',money=money-@money where id = ( select j.chargeid from jmsq q inner join YMDJ j on q.ymdjid=j.id where q.id=@id)";
|
|||
|
|
conn.Execute(sql1, new { id, money = jehj });
|
|||
|
|
ym.sj = (yjje - jmje).ToString();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
else if (lx == "2")
|
|||
|
|
{
|
|||
|
|
string sql1 =
|
|||
|
|
"update charge set status='未缴费' where id = ( select j.chargeid from jmsq q inner join YMDJ j on q.ymdjid=j.id where q.id=@id)";
|
|||
|
|
conn.Execute(sql1, new { id });
|
|||
|
|
ym.jz = "";
|
|||
|
|
}
|
|||
|
|
conn.Execute(sql, new { id, lx, shrid = erpUser.ID, shr = erpUser.TrueName });
|
|||
|
|
return ym;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|