940 lines
42 KiB
C#
940 lines
42 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
using System.Linq;
|
||
using System.Web.Mvc;
|
||
using WX.CRM.Common;
|
||
using WX.CRM.IBLL.Base;
|
||
using WX.CRM.IBLL.QH;
|
||
using WX.CRM.IBLL.Util;
|
||
using WX.CRM.Model.Entity;
|
||
using WX.CRM.Model.Enum;
|
||
using WX.CRM.WebHelper;
|
||
namespace WX.CRM.WEB.Controllers.QH
|
||
{
|
||
public class CommissionApplyController : BaseController
|
||
{
|
||
private readonly IQH_COMMISSIONAPPLY_Q _commissionApplyBiz;
|
||
private readonly IQH_COMMISSIONAPPLY _commissionApplyQBiz;
|
||
private readonly IQH_CUSTOMER _customerBiz;
|
||
private readonly IQH_CUSTOMER_SALEUSER _customerSaleuserBiz;
|
||
private readonly IBAS_INNERUSER_Q _innerUserBiz;
|
||
private readonly IQH_MONTHLYSTATEMENT_Q _monthBiz;
|
||
private readonly ICACHE_Q _cacheBiz;
|
||
//private IQH_CUSTOMERCHECK_Q _customercheckQ;
|
||
//private readonly IGJS_CUSTOMERCATEGORYTYPE_Q _gjsCustomercategorytypeQ;
|
||
[Ninject.Inject]
|
||
public IBAS_PARAMETER_Q BAS_PARAMETER_BL { get; set; }
|
||
ValidationErrors errors = new ValidationErrors();
|
||
public CommissionApplyController(
|
||
IQH_COMMISSIONAPPLY_Q p_commissionApplyBiz,
|
||
IQH_CUSTOMER p_customerBiz,
|
||
IBAS_INNERUSER_Q p_innerUserBiz,
|
||
IQH_COMMISSIONAPPLY p_commissionApplyQBiz,
|
||
IQH_MONTHLYSTATEMENT_Q p_monthBiz,
|
||
ICACHE_Q p_cacheBiz,
|
||
IQH_CUSTOMER_SALEUSER p_customerSaleuserBiz
|
||
)
|
||
{
|
||
_commissionApplyBiz = p_commissionApplyBiz;
|
||
_customerBiz = p_customerBiz;
|
||
_innerUserBiz = p_innerUserBiz;
|
||
_commissionApplyQBiz = p_commissionApplyQBiz;
|
||
_monthBiz = p_monthBiz;
|
||
_cacheBiz = p_cacheBiz;
|
||
_customerSaleuserBiz = p_customerSaleuserBiz;
|
||
}
|
||
#region 初始化视图
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_期货佣金分成设置)]
|
||
public ActionResult Index()
|
||
{
|
||
ToolBar tool = new ToolBar();
|
||
|
||
string[] toolbtn = new ToolButtonView().ToolButtonRight(InitRights.期货佣金分成设置, userRightId);
|
||
tool.AllowButton(toolbtn);
|
||
|
||
// tool.AllowButton("Create", "Details", "Delete", "Check");
|
||
tool.AddOtherButton("Other1", "导出", "icon-export", "btnexport_Click", true);
|
||
ViewBag.ToolBar = tool;
|
||
|
||
|
||
Pager pager = new Pager() { order = "pkid", page = 1, rows = 10 };
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHeadCol("userName", "20%", "经纪人");
|
||
tab.AddHeadCol("userEid", "20%", "经纪人工号");
|
||
tab.AddHeadCol("groupName", "", "组名");
|
||
tab.AddHeadCol("USERACCOUNT", "", "交易商号");
|
||
tab.AddHeadCol("USERNAME", "", "交易商姓名");
|
||
tab.AddHeadCol("applyDate", "", "申请时间");
|
||
tab.AddHeadCol("checkUserName", "", "审核人");
|
||
tab.AddHeadCol("verifitime", "", "审核时间");
|
||
tab.AddHeadCol("remark", "", "审核说明");
|
||
tab.AddHeadCol("statusChar", "", "状态");
|
||
tab.AddHiddenHeadCol("PKID", "keyId");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15");
|
||
|
||
//var gjsCustomerType = _gjsCustomercategorytypeQ.GetList();
|
||
//ViewBag.CustomerCateogryType = gjsCustomerType.Where(p => p.CATEGORYGROUP == 0).Select(item => new System.Web.UI.WebControls.ListItem() { Text = item.CATEGORYNAME, Value = item.CATEGORYNAME });
|
||
|
||
return View();
|
||
}
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_期货佣金分成设置)]
|
||
public JsonResult GetHtmlList(Pager pager, string columns)
|
||
{
|
||
try
|
||
{
|
||
DateTime month1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||
DateTime month30 = month1.AddMonths(1).AddDays(-1);
|
||
string txtTradeCode = Request["txtTradeCode"];
|
||
string txtEid = Request["txtEid"];
|
||
string txtName = Request["txtName"];
|
||
string SltCheckStatus = Request["SltCheckStatus"];
|
||
string sdCTime = Request["sdCTime"];
|
||
string edCTime = Request["edCTime"];
|
||
string sdVTime = Request["sdVTime"];
|
||
string edVTime = Request["edVTime"];
|
||
string sdATime = Request["sdATime"];
|
||
string edATime = Request["edATime"];
|
||
string customerCategoryTypeFrom = Request["customerCategoryType"];
|
||
string curMonActiva = Request["curMonActiva"];
|
||
string curMonTransaction = Request["curMonTransaction"];
|
||
string preMonTransaction = Request["preMonTransaction"];
|
||
if (!string.IsNullOrEmpty(customerCategoryTypeFrom))
|
||
customerCategoryTypeFrom = customerCategoryTypeFrom.Trim(',');
|
||
if (!string.IsNullOrEmpty(curMonActiva))
|
||
curMonActiva = curMonActiva.Trim(',');
|
||
if (!string.IsNullOrEmpty(curMonTransaction))
|
||
curMonTransaction = curMonTransaction.Trim(',');
|
||
if (!string.IsNullOrEmpty(preMonTransaction))
|
||
preMonTransaction = preMonTransaction.Trim(',');
|
||
int status = -1;
|
||
int? _userEid = null;
|
||
DateTime? ctime1 = null;
|
||
DateTime? ctime2 = null;
|
||
DateTime? vtime1 = null;
|
||
DateTime? vtime2 = null;
|
||
DateTime? atime1 = null;
|
||
DateTime? atime2 = null;
|
||
DateTime? jtime1 = null;
|
||
DateTime? jtime2 = null;
|
||
if (!string.IsNullOrEmpty(SltCheckStatus))
|
||
status = int.Parse(SltCheckStatus);
|
||
if (!string.IsNullOrEmpty(txtEid))
|
||
_userEid = int.Parse(txtEid);
|
||
|
||
if (!string.IsNullOrEmpty(sdCTime))
|
||
ctime1 = DateTime.Parse(sdCTime);
|
||
if (!string.IsNullOrEmpty(edCTime))
|
||
ctime2 = DateTime.Parse(edCTime);
|
||
|
||
if (!string.IsNullOrEmpty(sdVTime))
|
||
vtime1 = DateTime.Parse(sdVTime);
|
||
if (!string.IsNullOrEmpty(edVTime))
|
||
vtime2 = DateTime.Parse(edVTime);
|
||
|
||
if (!string.IsNullOrEmpty(sdATime))
|
||
atime1 = DateTime.Parse(sdATime);
|
||
if (!string.IsNullOrEmpty(edATime))
|
||
atime2 = DateTime.Parse(edATime);
|
||
string[] arr = new string[] { };
|
||
if (!string.IsNullOrEmpty(customerCategoryTypeFrom))
|
||
{
|
||
arr = customerCategoryTypeFrom.Split(',');
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonActiva))
|
||
{
|
||
atime1 = month1;
|
||
atime2 = month30;
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonTransaction))
|
||
{
|
||
jtime1 = month1;
|
||
jtime2 = month30;
|
||
}
|
||
if (!string.IsNullOrEmpty(preMonTransaction))
|
||
{
|
||
jtime1 = month1.AddMonths(-1);
|
||
jtime2 = month30.AddMonths(-1);
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonTransaction) && !string.IsNullOrEmpty(preMonTransaction))
|
||
{
|
||
jtime1 = month1.AddMonths(-1);
|
||
jtime2 = month30;
|
||
}
|
||
|
||
List<QH_COMMISSIONAPPLY> lis = new List<QH_COMMISSIONAPPLY>();
|
||
lis = _commissionApplyBiz.GetList(ref pager, txtTradeCode, _userEid, txtName, status, ctime1, ctime2, vtime1, vtime2, atime1, atime2, jtime1, jtime2, arr);
|
||
Table table = new Table(columns, true);
|
||
table.gridPager = pager;
|
||
foreach (QH_COMMISSIONAPPLY model in lis)
|
||
{
|
||
table.AddCol(model.userName);
|
||
table.AddCol(model.userEid);
|
||
table.AddCol(model.groupName);
|
||
table.AddCol(model.USERACCOUNT);
|
||
table.AddCol(model.USERNAME);
|
||
table.AddCol(model.applyDate);
|
||
table.AddCol(model.checkUserName);
|
||
table.AddCol(model.VERIFITIME);
|
||
table.AddCol(model.REMARK);
|
||
table.AddCol(model.statusChar);
|
||
table.AddHiddenCol(model.PKID);
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
totalPages = pager.totalPages,
|
||
totalRows = pager.totalRows,
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("GJSCommissionApplyController:" + ex.Message + ex.StackTrace);
|
||
return JsonHandler.ManageMessage(ex.Message, false);
|
||
}
|
||
}
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_期货佣金分成列表)]
|
||
public ActionResult RuleList()
|
||
{
|
||
ToolBar tool = new ToolBar();
|
||
tool.AllowButton("Create");
|
||
ViewBag.ToolBar = tool;
|
||
|
||
Pager pager = new Pager() { order = "pkid", page = 1, rows = 10 };
|
||
string tableId = "tablist";
|
||
Table tab = new Table(tableId);
|
||
tab.AddHeadCol("USERACCOUNT", "", "交易商代吗");
|
||
tab.AddHeadCol("mainSalesEid", "", "主经纪人");
|
||
tab.AddHeadCol("THEDATE", "", "日期");
|
||
tab.AddHeadCol("customerRate", "", "客户佣金比例");
|
||
tab.AddHeadCol("userEid", "", "分成工号");
|
||
tab.AddHeadCol("COMMISSTIONRATIO", "", "分成比例");
|
||
tab.AddHeadCol("CTIME", "", "申请时间");
|
||
tab.AddHeadCol("VERIFITIME", "", "审核时间");
|
||
tab.AddHeadCol("STATUS", "", "审核状态");
|
||
tab.AddHeadRow();
|
||
ViewBag.gridTable = tab.GetTable() + Pagination.GetPage(pager, tableId, "5,8,10,15");
|
||
|
||
ViewBag.inneruserid = UserId;
|
||
ViewBag.userGroupId = userGroupId;
|
||
ViewBag.saleDeptId = saleDeptId;
|
||
ViewBag.roleCodes = DataCacheHelper.GetCache().Get_RoleCodes(userRoleId);
|
||
return View();
|
||
}
|
||
[AuthorizeRedirect(Roles = InitRights.CONST_期货佣金分成列表)]
|
||
public JsonResult GetHtmlRuleList(Pager pager, string columns)
|
||
{
|
||
try
|
||
{
|
||
DateTime month1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||
DateTime month30 = month1.AddMonths(1).AddDays(-1);
|
||
string txtTradeCode = Request["txtTradeCode"];
|
||
string txtEid = Request["txtEid"];
|
||
string txtAssignEid = Request["txtAssignEid"];
|
||
string sdCTime = Request["sdCTime"];
|
||
string edCTime = Request["edCTime"];
|
||
string groupId = Request.Form["groupId"];
|
||
decimal userId = Request.Form["userId"].GetDecimal(0);
|
||
string sdATime = Request["sdATime"];
|
||
string edATime = Request["edATime"];
|
||
string curMonActiva = Request["curMonActiva"];
|
||
string curMonTransaction = Request["curMonTransaction"];
|
||
string preMonTransaction = Request["preMonTransaction"];
|
||
if (!string.IsNullOrEmpty(curMonActiva))
|
||
curMonActiva = curMonActiva.Trim(',');
|
||
if (!string.IsNullOrEmpty(curMonTransaction))
|
||
curMonTransaction = curMonTransaction.Trim(',');
|
||
if (!string.IsNullOrEmpty(preMonTransaction))
|
||
preMonTransaction = preMonTransaction.Trim(',');
|
||
int status = -1;
|
||
int? _userEid = null;
|
||
int? _txtAssignEid = null;
|
||
DateTime? ctime1 = null;
|
||
DateTime? ctime2 = null;
|
||
DateTime? atime1 = null;
|
||
DateTime? atime2 = null;
|
||
DateTime? jtime1 = null;
|
||
DateTime? jtime2 = null;
|
||
if (!string.IsNullOrEmpty(txtEid))
|
||
_userEid = int.Parse(txtEid);
|
||
if (!string.IsNullOrEmpty(txtAssignEid))
|
||
_txtAssignEid = int.Parse(txtAssignEid);
|
||
|
||
if (!string.IsNullOrEmpty(sdCTime))
|
||
ctime1 = DateTime.Parse(sdCTime);
|
||
if (!string.IsNullOrEmpty(edCTime))
|
||
ctime2 = DateTime.Parse(edCTime);
|
||
if (!string.IsNullOrEmpty(sdATime))
|
||
atime1 = DateTime.Parse(sdATime);
|
||
if (!string.IsNullOrEmpty(edATime))
|
||
atime2 = DateTime.Parse(edATime);
|
||
if (!string.IsNullOrEmpty(curMonActiva))
|
||
{
|
||
atime1 = month1;
|
||
atime2 = month30;
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonTransaction))
|
||
{
|
||
jtime1 = month1;
|
||
jtime2 = month30;
|
||
}
|
||
if (!string.IsNullOrEmpty(preMonTransaction))
|
||
{
|
||
jtime1 = month1.AddMonths(-1);
|
||
jtime2 = month30.AddMonths(-1);
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonTransaction) && !string.IsNullOrEmpty(preMonTransaction))
|
||
{
|
||
jtime1 = month1.AddMonths(-1);
|
||
jtime2 = month30;
|
||
}
|
||
|
||
var lis = _commissionApplyBiz.GetRouleList(ref pager, txtTradeCode, _userEid, _txtAssignEid, ctime1, ctime2, userId, groupId, atime1, atime2, jtime1, jtime2);
|
||
Table table = new Table(columns, true);
|
||
table.gridPager = pager;
|
||
foreach (var model in lis)
|
||
{
|
||
table.AddCol(model.USERACCOUNT);
|
||
table.AddCol(InnerUserHelper.Instance.EidAndName(InnerUserHelper.Instance.GetUserIdByEid(model.mainSalesEid)));
|
||
table.AddCol(model.THEDATE.ToUnityString(1));
|
||
table.AddCol(model.customerRate);
|
||
table.AddCol(InnerUserHelper.Instance.EidAndName(InnerUserHelper.Instance.GetUserIdByEid(model.userEid)));
|
||
table.AddCol(model.COMMISSTIONRATIO.ToString() + "%");
|
||
table.AddCol(model.CTIME);
|
||
table.AddCol(model.VERIFITIME);
|
||
table.AddCol(model.statusChar);
|
||
table.AddRow();
|
||
}
|
||
var json = new
|
||
{
|
||
totalPages = pager.totalPages,
|
||
totalRows = pager.totalRows,
|
||
rowsList = table.GetRows()
|
||
};
|
||
return Json(json, JsonRequestBehavior.AllowGet);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("GJSCommissionApplyController:" + ex.Message + ex.StackTrace);
|
||
return JsonHandler.ManageMessage(ex.Message, false);
|
||
}
|
||
}
|
||
#endregion
|
||
[HttpGet]
|
||
[AuthorizeToolBar(InitRights.CONST_期货签约分成申请, InitToolBar.CONST_Add)]
|
||
public ActionResult Edit()
|
||
{
|
||
string id = Request["id"];
|
||
string cmd = Request["cmd"];
|
||
string tradeCode = Request["tradeCode"];
|
||
string mySelf = Request["mySelf"];
|
||
mySelf = mySelf ?? "0";
|
||
cmd = cmd ?? "";
|
||
tradeCode = tradeCode ?? "";
|
||
decimal pkid = 0;
|
||
if (!string.IsNullOrEmpty(id))
|
||
pkid = decimal.Parse(id);
|
||
WX.CRM.Model.QueryMap.QHCommissionRuleInfo model = new Model.QueryMap.QHCommissionRuleInfo();
|
||
//model.sdDate = System.DateTime.Now;
|
||
model.sdDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||
model.edDate = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.AddMonths(1).Day);
|
||
if (cmd.ToLower() != "add")
|
||
{
|
||
QH_COMMISSIONAPPLY info = _commissionApplyBiz.GetInfo(pkid);
|
||
if (info != null)
|
||
model = ConvertViewModel(info);
|
||
if (cmd.ToLower() == "view")
|
||
model.isEdit = false;
|
||
else
|
||
model.isEdit = true;
|
||
}
|
||
else
|
||
{
|
||
if (!string.IsNullOrEmpty(tradeCode))
|
||
model = InitNewViewModelByTradeCode(tradeCode);
|
||
model.isEdit = true;
|
||
}
|
||
model.isOwner = mySelf;
|
||
return View(model);
|
||
}
|
||
[HttpPost]
|
||
[AuthorizeToolBar(InitRights.CONST_期货签约分成申请, InitToolBar.CONST_Add)]
|
||
public JsonResult Edit(WX.CRM.Model.QueryMap.QHCommissionRuleInfo model)
|
||
{
|
||
|
||
if (!ModelState.IsValid)
|
||
{
|
||
string messages = string.Join("; ", ModelState.Values
|
||
.SelectMany(x => x.Errors)
|
||
.Select(x => x.ErrorMessage));
|
||
return JsonHandler.ManageMessage(messages, false);
|
||
}
|
||
try
|
||
{
|
||
string v_str = "";
|
||
bool r = false;
|
||
if (!model.ValidationRatio(out v_str))
|
||
{
|
||
errors.Add(v_str);
|
||
return JsonHandler.ManageMessage(errors, false);
|
||
};
|
||
if (model.sdDate > model.edDate)
|
||
throw new Exception("开始日期不能大于结束日期!");
|
||
if (model.sdDate.Year != model.edDate.Year || model.sdDate.Month != model.edDate.Month)
|
||
throw new Exception("每次只能修改一个月的规则!");
|
||
|
||
DateTime d1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);//当月第一天
|
||
DateTime d2 = DateTime.Parse(DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.Day).ToShortDateString());//当月最后一天
|
||
|
||
if (DateTime.Parse(model.sdDate.ToShortDateString()).CompareTo(d1) >= 0 && d2.CompareTo(DateTime.Parse(model.edDate.ToShortDateString())) >= 0)
|
||
{
|
||
//申请时间在本月,正常流程,不做处理
|
||
}
|
||
else
|
||
{
|
||
if (DateTime.Parse(model.sdDate.ToShortDateString()).CompareTo(d1) < 0)
|
||
{
|
||
//申请时间在前一个月
|
||
var fenchengTime = _cacheBiz.GetValue_Parameter(Parameter.QH_FenChengTime);
|
||
if (string.IsNullOrEmpty(fenchengTime))
|
||
throw new Exception("只能申请:" + d1.ToShortDateString() + "-" + d2.ToShortDateString() + "数据");
|
||
var fcTime = 0;
|
||
int.TryParse(fenchengTime, out fcTime);
|
||
if (fcTime == 0)
|
||
throw new Exception("只能申请:" + d1.ToShortDateString() + "-" + d2.ToShortDateString() + "数据");
|
||
//加上分成配置的天数,如果当前时间超过了就不能再申请了
|
||
if (d1.AddDays(fcTime).CompareTo(DateTime.Now) < 0)
|
||
throw new Exception("只能申请:" + d1.ToShortDateString() + "-" + d2.ToShortDateString() + "数据");
|
||
}
|
||
}
|
||
|
||
var customerInfo = _customerBiz.Get(m => m.USERACCOUNT == model.userAccount);
|
||
|
||
decimal? monthCode = _monthBiz.getMaxMonthCode();
|
||
string maxDataStr = "1900-01-01";
|
||
if (monthCode.HasValue)
|
||
maxDataStr = string.Format("{0}-{1}-01", monthCode.ToString().Substring(0, 4), monthCode.ToString().Substring(4));
|
||
if (model.sdDate < DateTime.Parse(maxDataStr).AddMonths(1))
|
||
throw new Exception("已结算不能再审请修改");
|
||
|
||
//执行一下自动补充规则
|
||
var sysenv = _cacheBiz.GetValue_Parameter(Model.Enum.Parameter.Sys_Environment_DeptCode);
|
||
_commissionApplyQBiz.genCommissionRoule(model.userAccount, model.sdDate, sysenv);
|
||
|
||
if (_commissionApplyBiz.isExistsRule(model.userAccount, model.sdDate, model.edDate) == false)
|
||
throw new Exception("申请修改的规则不存在!");
|
||
if (_commissionApplyBiz.isExistsApply(model.userAccount, model.sdDate, model.edDate))
|
||
throw new Exception("该交易商号已申请过修改规则!");
|
||
if (model.pkid > 0)
|
||
{
|
||
r = editInfo(model, out v_str);
|
||
errors.Add(v_str);
|
||
return JsonHandler.UpdateMessage(errors, r);
|
||
}
|
||
else
|
||
{
|
||
r = AddInfo(model, out v_str);
|
||
errors.Add(v_str);
|
||
return JsonHandler.InsertMessage(errors, r);
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("QHCommissionApplyController_Edit:" + ex.Message + ex.StackTrace);
|
||
return JsonHandler.ManageMessage(ex.Message, false);
|
||
}
|
||
}
|
||
[AuthorizeToolBar(InitRights.CONST_期货佣金分成设置, InitToolBar.CONST_Delete)]
|
||
public JsonResult Delete()
|
||
{
|
||
string tem = Request["id"] ?? "0";
|
||
res r = new res() { result = true, data = tem };
|
||
try
|
||
{
|
||
decimal _id = decimal.Parse(tem);
|
||
var del = _commissionApplyBiz.GetInfo(_id);
|
||
if (del.STATUS == 1)
|
||
{
|
||
_commissionApplyQBiz.Delete(del);
|
||
r.data = "删除成功!";
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("已做过审核处理,不能删除!");
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
r.result = false;
|
||
r.data = ex.Message;
|
||
}
|
||
return Json(r, JsonRequestBehavior.AllowGet);
|
||
}
|
||
[AuthorizeToolBar(InitRights.CONST_期货佣金分成设置, InitToolBar.CONST_Check)]
|
||
public JsonResult Audit()
|
||
{
|
||
string id = Request["id"] ?? "0";
|
||
string sta = Request["status"] ?? "0";
|
||
string remark = Request["remark"] ?? "0";
|
||
res r = new res() { result = true, data = "" };
|
||
try
|
||
{
|
||
decimal _id = decimal.Parse(id);
|
||
int _sta = int.Parse(sta);
|
||
var c = _commissionApplyBiz.GetInfo(_id);
|
||
if (c.STATUS == _sta)
|
||
throw new Exception("已做过相同的审核操作");
|
||
if (_sta != (int)WX.CRM.Model.Enum.QHCommissionAuditSta.unAduit)
|
||
{
|
||
//var customerInfo = _customerBiz.Get(m => m.USERACCOUNT== c.USERACCOUNT);
|
||
//if (customerInfo.SIGNEDDATE.HasValue)
|
||
//{
|
||
// if (customerInfo.SIGNEDDATE.Value > DateTime.Parse("2015-06-01"))
|
||
// {
|
||
// var customerCheck = _customercheckQ.GetCustomerCheck(c.TRADECODE, 20);
|
||
// if (null != customerCheck)
|
||
// {
|
||
// if (customerCheck.QUALITYSTATUS.HasValue && customerCheck.QUALITYSTATUS.Value != 200)
|
||
// {
|
||
// _customercheckQ.GenCommissionUnQCCustomer(c.STARTDATE, c.ENDDATE, c.TRADECODE,
|
||
// c.REMARK);
|
||
// throw new Exception("质检签约审核未通过");
|
||
// }
|
||
// }
|
||
// }
|
||
//}
|
||
//else
|
||
//{
|
||
// throw new Exception("签约日期不正确");
|
||
//}
|
||
}
|
||
|
||
if (_sta > (int)WX.CRM.Model.Enum.QHCommissionAuditSta.newRecord)
|
||
{
|
||
c.VERIFIERUSER = UserId;
|
||
c.VERIFITIME = System.DateTime.Now;
|
||
c.STATUS = _sta;
|
||
c.REMARK = remark;
|
||
_commissionApplyQBiz.Audit(c);
|
||
r.data = "审核成功!";
|
||
}
|
||
else
|
||
{
|
||
throw new Exception("未识别的审核状态!" + _sta.ToString());
|
||
}
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
r.result = false;
|
||
r.data = ex.Message;
|
||
LogHelper.Error("QHCommissionApplyController_Audit:" + ex.Message + ex.StackTrace);
|
||
}
|
||
return Json(r, JsonRequestBehavior.AllowGet);
|
||
}
|
||
/// <summary>
|
||
/// 审核时,需要加信息预览,此时加载将审核的记录
|
||
/// </summary>
|
||
/// <returns></returns>
|
||
public JsonResult InitDataByCheckView()
|
||
{
|
||
string tem = Request["id"] ?? "0";
|
||
WX.CRM.Model.QueryMap.QHCommissionRuleInfo model = new Model.QueryMap.QHCommissionRuleInfo();
|
||
try
|
||
{
|
||
decimal pkid = decimal.Parse(tem);
|
||
WX.CRM.Model.Entity.QH_COMMISSIONAPPLY info = _commissionApplyBiz.GetInfo(pkid);
|
||
model = ConvertViewModel(info);
|
||
model.tradeStatus = 1;
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
model.tradeStatus = 0;
|
||
model.errStr = ex.Message;
|
||
LogHelper.Error("QHCommissionApplyController_InitDataByCheckView:" + ex.Message + ex.StackTrace);
|
||
}
|
||
return Json(model, JsonRequestBehavior.AllowGet);
|
||
}
|
||
public JsonResult InitDataByTradeCode()
|
||
{
|
||
WX.CRM.Model.QueryMap.QHCommissionRuleInfo model = new Model.QueryMap.QHCommissionRuleInfo();
|
||
try
|
||
{
|
||
string v_tradeCode = Request["tradeCode"];
|
||
if (!string.IsNullOrEmpty(v_tradeCode))
|
||
v_tradeCode = v_tradeCode.Trim();
|
||
string mySelf = Request["mySelf"];
|
||
mySelf = mySelf ?? "0";
|
||
model.tradeStatus = 0;
|
||
QH_CUSTOMER customer = _customerBiz.Get(m => m.USERACCOUNT == v_tradeCode);
|
||
QH_CUSTOMER_SALEUSER saleUser = _customerSaleuserBiz.Get(m => m.USERACCOUNT == v_tradeCode);
|
||
var saleUserId = saleUser != null ? saleUser.INNERUSERID : 0;
|
||
//bool isBC = BAS_PARAMETER_BL.GetModel_Patameter("Sys_Environment_DeptCode").PARAVALUE == Sys_Environment_DeptCode.BCCF01.ToString();
|
||
if (customer == null)
|
||
throw new Exception("此交易商代码不存在!");
|
||
//主管给员工申请
|
||
if (mySelf == "1")
|
||
{
|
||
LogHelper.Info("UserId:" + UserId.ToString() + "SaleUserId:" + saleUserId.ToString());
|
||
//if (UserId != customer.SALEUSERID)
|
||
// throw new Exception("此交易商号的归属人不正确!UserId=" + UserId + ",SALEUSERID:" + customer.SALEUSERID);
|
||
var lis = _commissionApplyBiz.GetuserIDSByGrouper(UserId); //如果是主管,可以申请所属组已离职成员的分成
|
||
if (lis == null)
|
||
lis = new List<decimal>();
|
||
lis.Add(UserId);
|
||
if (!lis.Contains(saleUserId))
|
||
throw new Exception("此交易商号的归属人不正确!UserId=" + UserId + ",SALEUSERID:" + saleUserId);
|
||
|
||
}
|
||
var u = _innerUserBiz.GetModel(saleUserId);
|
||
if (u == null)
|
||
throw new Exception("此交易商经纪人为空!");
|
||
//if (isBC)
|
||
//{
|
||
// if (u.ISDISMISS == 1 && !userRoleNames.Contains("总监") && !userRoleNames.Contains("总监助理"))//离职
|
||
// {
|
||
// throw new Exception("经纪人已经离职,只能总监或总监助理申请!");
|
||
// }
|
||
// if (u.ISDISMISS == 0 && UserId != u.PKID && !userRoleNames.Contains("总监") && !userRoleNames.Contains("总监助理"))
|
||
// {
|
||
// throw new Exception("经纪人在职,只能本人、总监或总监助理申请!");
|
||
// }
|
||
//}
|
||
|
||
model.userAccount = customer.USERACCOUNT;
|
||
model.userName = customer.USERNAME;
|
||
model.item0.eid = u.EID;
|
||
model.item0.ratio = 100;
|
||
model.tradeStatus = 1;
|
||
//model.sdDate = System.DateTime.Now;
|
||
model.sdDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||
model.edDate = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.AddMonths(1).Day);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
model.tradeStatus = 0;
|
||
model.errStr = ex.Message;
|
||
}
|
||
return Json(model, JsonRequestBehavior.AllowGet);
|
||
}
|
||
public string GetUserByEid(int EID)
|
||
{
|
||
return InnerUserHelper.Instance.GetUsername(InnerUserHelper.Instance.GetUserIdByEid(EID));
|
||
}
|
||
#region 添加,修改及辅助类
|
||
bool AddInfo(WX.CRM.Model.QueryMap.QHCommissionRuleInfo model, out string errstr)
|
||
{
|
||
errstr = "添加成功!";
|
||
try
|
||
{
|
||
WX.CRM.Model.Entity.QH_COMMISSIONAPPLY info = new QH_COMMISSIONAPPLY();
|
||
info.USERACCOUNT = model.userAccount;
|
||
info.USERNAME = model.userName;
|
||
info.STARTDATE = model.sdDate;
|
||
info.ENDDATE = model.edDate;
|
||
info.CREATEUSER = UserId;
|
||
info.CTIME = System.DateTime.Now;
|
||
info.STATUS = 1;
|
||
info.COMMISSTIONXML = model.itemsXml;
|
||
_commissionApplyQBiz.Insert(info);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("QHCommissionApplyController_AddInfo:" + ex.Message + ex.StackTrace);
|
||
errstr = ex.Message;
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
bool editInfo(WX.CRM.Model.QueryMap.QHCommissionRuleInfo model, out string errStr)
|
||
{
|
||
errStr = "修改成功!";
|
||
try
|
||
{
|
||
WX.CRM.Model.Entity.QH_COMMISSIONAPPLY oldInfo = _commissionApplyBiz.GetInfo(model.pkid);
|
||
if (oldInfo == null)
|
||
throw new Exception("修改的记录不存在!");
|
||
if (oldInfo.STATUS == 2)
|
||
throw new Exception("审核已通过不能再修改!");
|
||
|
||
oldInfo.USERACCOUNT = model.userAccount;
|
||
oldInfo.STARTDATE = model.sdDate;
|
||
oldInfo.ENDDATE = model.edDate;
|
||
oldInfo.COMMISSTIONXML = model.itemsXml;
|
||
_commissionApplyQBiz.Update(oldInfo);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
LogHelper.Error("GjsCommissionApplyController_editInfo:" + ex.Message + ex.StackTrace);
|
||
errStr = ex.Message;
|
||
return false;
|
||
}
|
||
return true;
|
||
}
|
||
public class res
|
||
{
|
||
public bool result { get; set; }
|
||
public string data { get; set; }
|
||
}
|
||
public class user
|
||
{
|
||
public decimal? userId { get; set; }
|
||
public decimal? commisstionRatio { get; set; }
|
||
public int ison { get; set; }
|
||
public int divType { get; set; }
|
||
}
|
||
public class root
|
||
{
|
||
public List<user> users { get; set; }
|
||
}
|
||
/// <summary>
|
||
/// 将数据库的模型转换成view的编辑模型
|
||
/// </summary>
|
||
/// <param name="info"></param>
|
||
/// <returns></returns>
|
||
WX.CRM.Model.QueryMap.QHCommissionRuleInfo ConvertViewModel(WX.CRM.Model.Entity.QH_COMMISSIONAPPLY info)
|
||
{
|
||
WX.CRM.Model.QueryMap.QHCommissionRuleInfo model = new Model.QueryMap.QHCommissionRuleInfo();
|
||
//model.sdDate = System.DateTime.Now;
|
||
model.sdDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||
model.edDate = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.AddMonths(1).Day);
|
||
if (info != null)
|
||
{
|
||
model.pkid = info.PKID;
|
||
model.userAccount = info.USERACCOUNT;
|
||
model.userName = info.USERNAME;
|
||
model.sdDate = info.STARTDATE;
|
||
model.edDate = info.ENDDATE;
|
||
root items = Common.Utility.XMLToObject<root>(info.COMMISSTIONXML);
|
||
var item0 = items.users.Where(p => p.ison == 1).FirstOrDefault();
|
||
if (item0 != null)
|
||
{
|
||
model.item0.eid = item0.userId;
|
||
model.item0.ratio = item0.commisstionRatio;
|
||
}
|
||
var temItems = items.users.Where(p => p.ison == 2);
|
||
int i = 1;
|
||
#region 参与分成人员分成
|
||
foreach (var o in temItems)
|
||
{
|
||
switch (i)
|
||
{
|
||
case 1:
|
||
model.item1.eid = o.userId;
|
||
model.item1.ratio = o.commisstionRatio;
|
||
break;
|
||
case 2:
|
||
model.item2.eid = o.userId;
|
||
model.item2.ratio = o.commisstionRatio;
|
||
break;
|
||
case 3:
|
||
model.item3.eid = o.userId;
|
||
model.item3.ratio = o.commisstionRatio;
|
||
break;
|
||
}
|
||
i++;
|
||
}
|
||
#endregion
|
||
temItems = items.users.Where(p => p.ison == 3);
|
||
i = 1;
|
||
#region 需返还人员分成
|
||
foreach (var o in temItems)
|
||
{
|
||
switch (i)
|
||
{
|
||
case 1:
|
||
model.item4.eid = o.userId;
|
||
model.item4.ratio = o.commisstionRatio;
|
||
break;
|
||
case 2:
|
||
model.item5.eid = o.userId;
|
||
model.item5.ratio = o.commisstionRatio;
|
||
break;
|
||
case 3:
|
||
model.item6.eid = o.userId;
|
||
model.item6.ratio = o.commisstionRatio;
|
||
break;
|
||
}
|
||
i++;
|
||
}
|
||
#endregion
|
||
temItems = items.users.Where(p => p.ison == 4);
|
||
i = 1;
|
||
#region 操盘手分成
|
||
foreach (var o in temItems)
|
||
{
|
||
switch (i)
|
||
{
|
||
case 1:
|
||
model.item7.eid = o.userId;
|
||
model.item7.ratio = o.commisstionRatio;
|
||
break;
|
||
case 2:
|
||
model.item8.eid = o.userId;
|
||
model.item8.ratio = o.commisstionRatio;
|
||
break;
|
||
}
|
||
i++;
|
||
}
|
||
#endregion
|
||
}
|
||
return model;
|
||
}
|
||
WX.CRM.Model.QueryMap.QHCommissionRuleInfo InitNewViewModelByTradeCode(string tradeCode)
|
||
{
|
||
WX.CRM.Model.QueryMap.QHCommissionRuleInfo model = new Model.QueryMap.QHCommissionRuleInfo();
|
||
try
|
||
{
|
||
model.tradeStatus = 0;
|
||
WX.CRM.Model.Entity.QH_CUSTOMER customer = _customerBiz.Get(m => m.USERACCOUNT == tradeCode);
|
||
if (customer == null)
|
||
throw new Exception("此交易商代码不存在!交易商代码:" + tradeCode);
|
||
model.userAccount = customer.USERACCOUNT;
|
||
model.userName = customer.USERNAME;
|
||
var saler = _customerSaleuserBiz.Get(m => m.USERACCOUNT == tradeCode);
|
||
if (saler == null)
|
||
throw new Exception("此交易商经纪人为空!");
|
||
var u = _innerUserBiz.GetModel(saler.INNERUSERID);
|
||
if (u == null)
|
||
throw new Exception("此交易商经纪人为空!");
|
||
model.item0.eid = u.EID;
|
||
model.item0.ratio = 100;
|
||
model.tradeStatus = 1;
|
||
//model.sdDate = System.DateTime.Now;
|
||
model.sdDate = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||
model.edDate = DateTime.Now.AddMonths(1).AddDays(-DateTime.Now.AddMonths(1).Day);
|
||
}
|
||
catch (Exception ex)
|
||
{
|
||
model.tradeStatus = 0;
|
||
model.errStr = ex.Message;
|
||
throw ex;
|
||
}
|
||
return model;
|
||
}
|
||
#endregion
|
||
|
||
#region 导出
|
||
[AuthorizeToolBar(InitRights.CONST_期货佣金分成设置, InitToolBar.CONST_Other1)]
|
||
public FileResult ListExport()
|
||
{
|
||
Pager pager = new Pager();
|
||
pager.page = 1;
|
||
pager.rows = int.MaxValue;
|
||
DateTime month1 = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
|
||
DateTime month30 = month1.AddMonths(1).AddDays(-1);
|
||
string checkedFilds = PageRequest.GetQueryString("checkedFilds");
|
||
string checkedTitles = PageRequest.GetQueryString("checkedTitles");
|
||
|
||
string txtTradeCode = Request.QueryString["TradeCode"];
|
||
string txtEid = Request.QueryString["Eid"];
|
||
string txtName = Request.QueryString["Name"];
|
||
string SltCheckStatus = Request.QueryString["SltCheckStatus"];
|
||
string sdCTime = Request.QueryString["sdCTime"];
|
||
string edCTime = Request.QueryString["edCTime"];
|
||
string sdVTime = Request.QueryString["sdVTime"];
|
||
string edVTime = Request.QueryString["edVTime"];
|
||
string sdATime = Request.QueryString["sdATime"];
|
||
string edATime = Request.QueryString["edATime"];
|
||
string customerCategoryTypeFrom = Request["customerCategoryType"];
|
||
string curMonActiva = Request["curMonActiva"];
|
||
string curMonTransaction = Request["curMonTransaction"];
|
||
string preMonTransaction = Request["preMonTransaction"];
|
||
if (!string.IsNullOrEmpty(customerCategoryTypeFrom))
|
||
customerCategoryTypeFrom = customerCategoryTypeFrom.Trim(',');
|
||
if (!string.IsNullOrEmpty(curMonActiva))
|
||
curMonActiva = curMonActiva.Trim(',');
|
||
if (!string.IsNullOrEmpty(curMonTransaction))
|
||
curMonTransaction = curMonTransaction.Trim(',');
|
||
if (!string.IsNullOrEmpty(preMonTransaction))
|
||
preMonTransaction = preMonTransaction.Trim(',');
|
||
if (string.IsNullOrEmpty(txtTradeCode))
|
||
{
|
||
txtTradeCode = "";
|
||
}
|
||
if (string.IsNullOrEmpty(txtName))
|
||
{
|
||
txtName = "";
|
||
}
|
||
int status = -1;
|
||
int? _userEid = null;
|
||
DateTime? ctime1 = null;
|
||
DateTime? ctime2 = null;
|
||
DateTime? vtime1 = null;
|
||
DateTime? vtime2 = null;
|
||
DateTime? atime1 = null;
|
||
DateTime? atime2 = null;
|
||
DateTime? jtime1 = null;
|
||
DateTime? jtime2 = null;
|
||
if (!string.IsNullOrEmpty(SltCheckStatus))
|
||
status = int.Parse(SltCheckStatus);
|
||
if (!string.IsNullOrEmpty(txtEid))
|
||
_userEid = int.Parse(txtEid);
|
||
|
||
if (!string.IsNullOrEmpty(sdCTime))
|
||
ctime1 = DateTime.Parse(sdCTime);
|
||
if (!string.IsNullOrEmpty(edCTime))
|
||
ctime2 = DateTime.Parse(edCTime);
|
||
|
||
if (!string.IsNullOrEmpty(sdVTime))
|
||
vtime1 = DateTime.Parse(sdVTime);
|
||
if (!string.IsNullOrEmpty(edVTime))
|
||
vtime2 = DateTime.Parse(edVTime);
|
||
|
||
if (!string.IsNullOrEmpty(sdATime))
|
||
atime1 = DateTime.Parse(sdATime);
|
||
if (!string.IsNullOrEmpty(edATime))
|
||
atime2 = DateTime.Parse(edATime);
|
||
string[] arr = new string[] { };
|
||
if (!string.IsNullOrEmpty(customerCategoryTypeFrom))
|
||
{
|
||
arr = customerCategoryTypeFrom.Split(',');
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonActiva))
|
||
{
|
||
atime1 = month1;
|
||
atime2 = month30;
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonTransaction))
|
||
{
|
||
jtime1 = month1;
|
||
jtime2 = month30;
|
||
}
|
||
if (!string.IsNullOrEmpty(preMonTransaction))
|
||
{
|
||
jtime1 = month1.AddMonths(-1);
|
||
jtime2 = month30.AddMonths(-1);
|
||
}
|
||
if (!string.IsNullOrEmpty(curMonTransaction) && !string.IsNullOrEmpty(preMonTransaction))
|
||
{
|
||
jtime1 = month1.AddMonths(-1);
|
||
jtime2 = month30;
|
||
}
|
||
|
||
List<WX.CRM.Model.Entity.QH_COMMISSIONAPPLY> lis = new List<Model.Entity.QH_COMMISSIONAPPLY>();
|
||
lis = _commissionApplyBiz.GetList(ref pager, txtTradeCode, _userEid, txtName, status, ctime1, ctime2, vtime1, vtime2, atime1, atime2, jtime1, jtime2, arr);
|
||
return File(ExcelHelper.ExportListModelToExcel<WX.CRM.Model.Entity.QH_COMMISSIONAPPLY>(lis, "佣金分成比例审核", 10000, checkedFilds, checkedTitles, null), "application/ms-excel", PageRequest.GetDlownLoadName("佣金分成比例审核.xls"));
|
||
}
|
||
public string DataFormart(string key, object value)
|
||
{
|
||
string formartValue = string.Empty;
|
||
switch (key)
|
||
{
|
||
case "statusChar":
|
||
switch (Convert.ToString(value))
|
||
{
|
||
case "0": formartValue = "未开通"; break;
|
||
case "1": formartValue = "已开通"; break;
|
||
default: formartValue = ""; break;
|
||
}; break;
|
||
default: formartValue = string.Format("{0}", value); break;
|
||
}
|
||
return formartValue;
|
||
}
|
||
|
||
#endregion
|
||
}
|
||
}
|