三元财务API

CustomerNewController.cs 40KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918
  1. using CallCenter.Utility;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using CallCenterApi.Interface.Models.Input;
  4. using Newtonsoft.Json;
  5. using NPOI.HSSF.UserModel;
  6. using NPOI.SS.UserModel;
  7. using NPOI.XSSF.UserModel;
  8. using System;
  9. using System.Collections.Generic;
  10. using System.Data;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Web;
  14. using System.Web.Mvc;
  15. namespace CallCenterApi.Interface.Controllers.customer
  16. {
  17. public class CustomerNewController : BaseController
  18. {
  19. BLL.T_Cus_CustomerBaseNew cusbll = new BLL.T_Cus_CustomerBaseNew();
  20. BLL.T_Cus_ContactPersonNew conbll = new BLL.T_Cus_ContactPersonNew();
  21. BLL.T_Sys_Department deptbll = new BLL.T_Sys_Department();
  22. BLL.T_Sys_RoleInfo rolebll = new BLL.T_Sys_RoleInfo();
  23. BLL.T_Cus_CustomerFinance finbll = new BLL.T_Cus_CustomerFinance();
  24. #region 客户管理
  25. /// <summary>
  26. /// 获取客户列表
  27. /// </summary>
  28. /// <param name="code">客户编号</param>
  29. /// <param name="cmpname">公司名称</param>
  30. /// <param name="cmpaddress">公司地址</param>
  31. /// <param name="legname">法人姓名</param>
  32. /// <param name="legtel">法人电话</param>
  33. /// <param name="subtrade">所属行业</param>
  34. /// <param name="layer">客户信誉等级</param>
  35. /// <param name="bedept">客户归属部门</param>
  36. /// <param name="bereladd">客户归属涉税会计</param>
  37. /// <param name="beaudacc">客户归属审核会计</param>
  38. /// <param name="bemakeacc">客户归属做账会计</param>
  39. /// <param name="conname">联系人姓名</param>
  40. /// <param name="contel">联系人电话</param>
  41. /// <returns></returns>
  42. public ActionResult GetList(string keywords, string code, string cmpname, string cmpaddress,
  43. string legname, string legtel, string subtrade, string layer, string bedept,
  44. string berelacc, string beaudacc, string bemakeacc, string conname, string contel,
  45. int pageindex = 1, int pagesize = 10)
  46. {
  47. string sql = "";
  48. DataTable dt = new DataTable();
  49. #region 筛选条件
  50. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  51. sql += $" and F_KeyWords like '%" + keywords.Trim() + "%'";
  52. if (!string.IsNullOrWhiteSpace(code))//客户编号
  53. sql += $" and F_CustomerCode like '%" + code.Trim() + "%'";
  54. if (!string.IsNullOrWhiteSpace(cmpname))//公司名称
  55. sql += $" and F_KeyWords like '%" + cmpname.Trim() + "%'";
  56. if (!string.IsNullOrWhiteSpace(cmpaddress))//公司地址
  57. sql += $" and (F_CompanyAddress like '%" + cmpaddress.Trim()
  58. + "%' or F_RegisteredAddress like '%" + cmpaddress.Trim()
  59. + "%' or F_Address like '%" + cmpaddress.Trim()
  60. + "%' or F_Address1 like '%" + cmpaddress.Trim()
  61. + "%' or F_Address2 like '%" + cmpaddress.Trim()
  62. + "%' or F_Address3 like '%" + cmpaddress.Trim()
  63. + "%' or F_Address4 like '%" + cmpaddress.Trim()
  64. + "%')";
  65. if (!string.IsNullOrWhiteSpace(legname))//法人姓名
  66. sql += $" and F_LegalName like '%" + legname.Trim() + "%'";
  67. if (!string.IsNullOrWhiteSpace(legtel))//法人电话
  68. sql += $" and F_LegalTel like '%" + legtel.Trim() + "%'";
  69. if (!string.IsNullOrWhiteSpace(subtrade))//所属行业
  70. sql += $" and isnull(F_SubTrade,'') = '" + subtrade.Trim() + "'";
  71. if (!string.IsNullOrWhiteSpace(layer))//客户信誉等级
  72. sql += $" and isnull(F_Layer,'') = '" + layer.Trim() + "'";
  73. if (!string.IsNullOrWhiteSpace(bedept))//客户所属部门
  74. sql += $" and isnull(F_BeDept,'') = '" + bedept.Trim() + "'";
  75. if (!string.IsNullOrWhiteSpace(berelacc))//涉税会计
  76. sql += $" and F_BeRelatedAcc like '%" + berelacc.Trim() + "%'";
  77. if (!string.IsNullOrWhiteSpace(beaudacc))//审核会计
  78. sql += $" and F_BeAuditAcc like '%" + beaudacc.Trim() + "%'";
  79. if (!string.IsNullOrWhiteSpace(bemakeacc))//做账会计
  80. sql += $" and F_BeMakeAcc like '%" + bemakeacc.Trim() + "%'";
  81. if (!string.IsNullOrWhiteSpace(conname) || !string.IsNullOrWhiteSpace(contel))
  82. {
  83. var sqlcon = " where F_DeleteFlag=0 ";
  84. if (!string.IsNullOrWhiteSpace(conname)) // 联系人
  85. sqlcon += " and F_Name like '%" + conname + "%'";
  86. if (!string.IsNullOrWhiteSpace(contel)) //联系人电话
  87. sqlcon += " and F_Telephone like '%" + contel + "%'";
  88. sql += $" and F_CustomerId in (select F_CustomerId from T_Cus_ContactPersonNew " + sqlcon + " )";
  89. }
  90. #endregion
  91. int recordCount = 0;
  92. if(CurrentUser.UserData.F_RoleId==17)
  93. {
  94. sql += " and F_DeleteFlag=0";
  95. }
  96. if (!string.IsNullOrWhiteSpace(sql))
  97. {
  98. sql += " and F_DeleteFlag=0";
  99. dt = BLL.PagerBLL.GetListPager(
  100. "T_Cus_CustomerBaseNew",
  101. "F_CustomerId",
  102. "*,dbo.GetDeptName(F_BeDept) as F_BeDeptName",
  103. sql,
  104. "ORDER BY F_CustomerId desc",
  105. pagesize,
  106. pageindex,
  107. true,
  108. out recordCount);
  109. #region
  110. dt.Columns.Add("F_Contact");
  111. var dept = new BLL.T_Sys_Department().GetModelList("");
  112. foreach (DataRow dr in dt.Rows)
  113. {
  114. #region 绑定联系人信息
  115. var contact = "";
  116. string cusid = dr["F_CustomerId"] != null ? dr["F_CustomerId"].ToString() : "";
  117. if (cusid != "")
  118. {
  119. var conlist = conbll.GetModelList(" F_CustomerId=" + cusid);
  120. if (conlist.Count > 0)
  121. {
  122. foreach (var item in conlist)
  123. {
  124. contact += item.F_Name + "(" + item.F_Telephone + "),";
  125. }
  126. }
  127. dr["F_Contact"] = contact.TrimEnd(',');
  128. }
  129. #endregion
  130. }
  131. #endregion
  132. }
  133. var obj = new
  134. {
  135. state = "success",
  136. message = "成功",
  137. rows = dt,
  138. total = recordCount
  139. };
  140. return Content(obj.ToJson());
  141. }
  142. /// <summary>
  143. /// 根据关键字搜索公司
  144. /// </summary>
  145. public ActionResult GetListByKey(string keywords)
  146. {
  147. string sql = "";
  148. if (!string.IsNullOrWhiteSpace(keywords))//关键字搜索
  149. sql += $" F_KeyWords like '%" + keywords.Trim() + "%'";
  150. var list = new List<Model.T_Cus_CustomerBaseNew>();
  151. if (!string.IsNullOrWhiteSpace(sql))
  152. {
  153. sql += " and F_DeleteFlag=0";
  154. list = cusbll.GetModelList(sql);
  155. }
  156. if (list.Count > 0)
  157. return Success("根据关键字获取公司信息", list.FirstOrDefault());
  158. else
  159. return Error("没有获取到相关公司,请重新搜索");
  160. }
  161. /// <summary>
  162. /// 获取客户信息
  163. /// </summary>
  164. /// <returns></returns>
  165. public ActionResult GetCustomer(int cusid)
  166. {
  167. if (cusid != 0)
  168. {
  169. Model.T_Cus_CustomerBaseNew userModel = cusbll.GetModel(cusid);
  170. if (userModel != null)
  171. {
  172. #region 绑定部门
  173. var deptname = "";
  174. if (userModel.F_BeDept != null)
  175. {
  176. var deptmodel = deptbll.GetModel(userModel.F_BeDept.Value);
  177. if (deptmodel != null)
  178. deptname = deptmodel.F_DeptName;
  179. }
  180. #endregion
  181. var conlist = conbll.GetModelList(" F_DeleteFlag=0 and F_CustomerId=" + cusid);
  182. var finlist = finbll.GetModelList(" F_DeleteFlag=0 and F_CustomerId=" + cusid);
  183. var obj = new
  184. {
  185. CustomerBase = userModel,
  186. BeDeptName = deptname,
  187. ContactList = conlist,
  188. FinaceList = finlist,
  189. };
  190. return Success("获取成功", obj);
  191. }
  192. else
  193. {
  194. return Error("获取失败");
  195. }
  196. }
  197. else
  198. {
  199. return Error("参数传输失败");
  200. }
  201. }
  202. /// <summary>
  203. /// 通过来电号码获取来电弹屏左侧客户信息
  204. /// </summary>
  205. /// <returns></returns>
  206. public ActionResult GetCustomerByTel(string tel)
  207. {
  208. if (!string.IsNullOrWhiteSpace(tel))
  209. {
  210. var sql = $" and (F_LegalTel like '%" + tel.Trim() + "%') or F_CustomerId in (select F_CustomerId from T_Cus_ContactPersonNew where F_Telephone like '%" + tel.Trim() + "%')";
  211. var userModel = new BLL.T_Cus_CustomerBaseNew().GetModelList(" F_DeleteFlag = 0 " + sql);
  212. if (userModel.Count() > 0)
  213. {
  214. var model = userModel.Last();
  215. int cusid = model.F_CustomerId;
  216. var conlist = conbll.GetModelList(" F_DeleteFlag=0 and F_CustomerId=" + cusid);
  217. var finlist=finbll.GetModelList(" F_DeleteFlag=0 and F_CustomerId=" + cusid);
  218. #region 绑定部门
  219. var deptname = "";
  220. if (model.F_BeDept != null)
  221. {
  222. var deptmodel = deptbll.GetModel(model.F_BeDept.Value);
  223. if (deptmodel != null)
  224. deptname = deptmodel.F_DeptName;
  225. }
  226. #endregion
  227. var obj = new
  228. {
  229. CustomerBase = model,
  230. BeDeptName = deptname,
  231. ContactList = conlist,
  232. FinaceList = finlist,
  233. };
  234. return Success("获取成功", obj);
  235. }
  236. else
  237. {
  238. return Success("获取成功");
  239. }
  240. }
  241. else
  242. {
  243. return Error("参数传输失败");
  244. }
  245. }
  246. /// <summary>
  247. /// 添加客户信息
  248. /// </summary>
  249. /// <returns></returns>
  250. public ActionResult Add(CustomerBaseNewInput input)
  251. {
  252. string usercode = CurrentUser.UserData.F_UserCode;
  253. #region 添加验证判断
  254. if (string.IsNullOrEmpty(input.F_CustomerCode))
  255. return Error("编号不能为空!");
  256. if (getunique(0, input.F_CustomerCode))
  257. return Error("编号已被占用,请重新输入!");
  258. #endregion
  259. var model = new Model.T_Cus_CustomerBaseNew();
  260. #region 保存客户基本信息
  261. model = inputtoobj(model, input);
  262. model.F_CreateBy = usercode;
  263. model.F_CreatedOn = DateTime.Now;
  264. model.F_DeleteFlag = 0;
  265. #endregion
  266. int n = cusbll.Add(model);
  267. if (n > 0)
  268. {
  269. #region 添加联系人
  270. if (input.ContactList != null && input.ContactList.Count > 0)
  271. {
  272. var conmodel = new Model.T_Cus_ContactPersonNew();
  273. conmodel.F_CustomerId = n;
  274. conmodel.F_CreateBy = usercode;
  275. conmodel.F_CreateOn = DateTime.Now;
  276. conmodel.F_DeleteFlag = 0;
  277. foreach (var item in input.ContactList)
  278. {
  279. conmodel.F_IsMain = item.F_IsMain;
  280. conmodel.F_Name = item.F_Name;
  281. conmodel.F_Telephone = item.F_Telephone;
  282. conmodel.F_Duties = item.F_Duties;
  283. conmodel.F_Email = item.F_Email;
  284. conmodel.F_MSN = item.F_MSN;
  285. conmodel.F_QQ = item.F_QQ;
  286. conmodel.F_Remark = item.F_Remark;
  287. conbll.Add(conmodel);
  288. }
  289. }
  290. #endregion
  291. #region 添加财税情况
  292. var fincmodel = new CustomerFinanceInput();
  293. fincmodel.F_CustomerId = n;
  294. fincmodel.F_CustomerCode = model.F_CustomerCode;
  295. fincmodel.F_CreateBy = usercode;
  296. savefin(input.FinanceInfos);
  297. #endregion
  298. return Success("新增成功!");
  299. }
  300. else
  301. return Error("新增失败!");
  302. }
  303. /// <summary>
  304. /// 修改客户信息
  305. /// </summary>
  306. /// <returns></returns>
  307. public ActionResult Update(CustomerBaseNewInput input)
  308. {
  309. string usercode = CurrentUser.UserData.F_UserCode;
  310. #region 添加验证判断
  311. if (input.F_CustomerId <= 0)
  312. return Error("参数错误!");
  313. if (getunique(input.F_CustomerId, input.F_CustomerCode))
  314. return Error("编号已被占用,请重新输入!");
  315. #endregion
  316. var model = cusbll.GetModel(input.F_CustomerId);
  317. #region 保存客户基本信息
  318. model = inputtoobj(model, input);
  319. #endregion
  320. bool n = cusbll.Update(model);
  321. if (n)
  322. {
  323. return Success("保存成功!");
  324. }
  325. else
  326. return Error("保存失败!");
  327. }
  328. /// <summary>
  329. /// 根据传入的对象和input的内容返回对象
  330. /// </summary>
  331. private Model.T_Cus_CustomerBaseNew inputtoobj(Model.T_Cus_CustomerBaseNew model,CustomerBaseNewInput input)
  332. {
  333. var newmodel = model;
  334. if (!string.IsNullOrWhiteSpace(input.F_CustomerCode))
  335. {
  336. model.F_CustomerCode = input.F_CustomerCode;
  337. }
  338. else
  339. model.F_CustomerCode = model.F_CustomerCode;
  340. if (!string.IsNullOrWhiteSpace(input.F_CompanyName))
  341. {
  342. model.F_CompanyName = input.F_CompanyName;
  343. #region 处理关键字
  344. var keyword = model.F_CompanyName;
  345. var keyconfig = Configs.GetValue("keystring");
  346. var keystring = keyconfig.Split(',');
  347. foreach (var item in keystring)
  348. {
  349. if (model.F_CompanyName.Contains(item))
  350. keyword = keyword.Replace(item, "");
  351. }
  352. model.F_KeyWords = keyword;
  353. #endregion
  354. }
  355. if (!string.IsNullOrWhiteSpace(input.F_RegisteredAddress))
  356. model.F_RegisteredAddress = input.F_RegisteredAddress;
  357. if (!string.IsNullOrWhiteSpace(input.F_CompanyAddress))
  358. model.F_CompanyAddress = input.F_CompanyAddress;
  359. if (!string.IsNullOrWhiteSpace(input.F_LegalName))
  360. model.F_LegalName = input.F_LegalName;
  361. if (!string.IsNullOrWhiteSpace(input.F_LegalIDCards))
  362. model.F_LegalIDCards = input.F_LegalIDCards;
  363. if (!string.IsNullOrWhiteSpace(input.F_LegalTel))
  364. model.F_LegalTel = input.F_LegalTel;
  365. if (!string.IsNullOrWhiteSpace(input.F_Qualification))
  366. model.F_Qualification = input.F_Qualification;
  367. if (!string.IsNullOrWhiteSpace(input.F_Layer))
  368. model.F_Layer = input.F_Layer;
  369. if (!string.IsNullOrWhiteSpace(input.F_InvoiceRange))
  370. model.F_InvoiceRange = input.F_InvoiceRange;
  371. if (!string.IsNullOrWhiteSpace(input.F_SubTrade))
  372. model.F_SubTrade = input.F_SubTrade;
  373. if (!string.IsNullOrWhiteSpace(input.F_TaxCategory))
  374. model.F_TaxCategory = input.F_TaxCategory;
  375. if (!string.IsNullOrWhiteSpace(input.F_TaxPointDes))
  376. model.F_TaxPointDes = input.F_TaxPointDes;
  377. if (!string.IsNullOrWhiteSpace(input.F_WxPassword))
  378. model.F_WxPassword = input.F_WxPassword;
  379. if (input.F_BeDept > 0)
  380. model.F_BeDept = input.F_BeDept;
  381. if (!string.IsNullOrWhiteSpace(input.F_FinancialManager))
  382. model.F_FinancialManager = input.F_FinancialManager;
  383. if (!string.IsNullOrWhiteSpace(input.F_BusinessOwner))
  384. model.F_BusinessOwner = input.F_BusinessOwner;
  385. if (!string.IsNullOrWhiteSpace(input.F_BeRelatedAcc))
  386. model.F_BeRelatedAcc = input.F_BeRelatedAcc;
  387. if (!string.IsNullOrWhiteSpace(input.F_BeAuditAcc))
  388. model.F_BeAuditAcc = input.F_BeAuditAcc;
  389. if (!string.IsNullOrWhiteSpace(input.F_BeMakeAcc))
  390. model.F_BeMakeAcc = input.F_BeMakeAcc;
  391. if (!string.IsNullOrWhiteSpace(input.F_Remark1))
  392. model.F_Remark1 = input.F_Remark1;
  393. if (!string.IsNullOrWhiteSpace(input.F_Remark2))
  394. model.F_Remark2 = input.F_Remark2;
  395. if (!string.IsNullOrWhiteSpace(input.F_Remark3))
  396. model.F_Remark3 = input.F_Remark3;
  397. if (!string.IsNullOrWhiteSpace(input.F_CusService))
  398. model.F_CusService = input.F_CusService;
  399. if (!string.IsNullOrWhiteSpace(input.F_HandoverDate))
  400. model.F_HandoverDate = input.F_HandoverDate;
  401. if (input.F_ISBankSlips > 0)
  402. model.F_ISBankSlips = input.F_ISBankSlips;
  403. else
  404. model.F_ISBankSlips = 0;
  405. if (!string.IsNullOrWhiteSpace(input.F_Address))
  406. model.F_Address = input.F_Address;
  407. if (!string.IsNullOrWhiteSpace(input.F_Address1))
  408. model.F_Address1 = input.F_Address1;
  409. if (!string.IsNullOrWhiteSpace(input.F_Address2))
  410. model.F_Address2 = input.F_Address2;
  411. if (!string.IsNullOrWhiteSpace(input.F_Address3))
  412. model.F_Address3 = input.F_Address3;
  413. if (!string.IsNullOrWhiteSpace(input.F_Address4))
  414. model.F_Address4 = input.F_Address4;
  415. if (!string.IsNullOrWhiteSpace(input.F_Charges))
  416. model.F_Charges = input.F_Charges;
  417. if (input.F_ChargeType > 0)
  418. model.F_ChargeType = input.F_ChargeType;
  419. if (!string.IsNullOrWhiteSpace(input.F_CompanyLogo))
  420. model.F_CompanyLogo = input.F_CompanyLogo;
  421. if (input.F_CycleStart != null)
  422. model.F_CycleStart = input.F_CycleStart;
  423. if (input.F_CycleEnd != null)
  424. model.F_CycleEnd = input.F_CycleEnd;
  425. if (!string.IsNullOrWhiteSpace(input.F_TaxNumber))
  426. model.F_TaxNumber = input.F_TaxNumber;
  427. if (input.F_FeeExpires != null)
  428. model.F_FeeExpires = input.F_FeeExpires;
  429. return model;
  430. }
  431. /// <summary>
  432. /// 验证客户编号是否唯一
  433. /// </summary>
  434. private bool getunique(int id, string code)
  435. {
  436. var sql = " F_DeleteFlag=0 and F_CustomerCode='" + code + "'";
  437. if (id > 0)
  438. sql += " and F_CustomerId<>"+id;
  439. var count=cusbll.GetModelList(sql).Count();
  440. return count > 0;
  441. }
  442. /// <summary>
  443. /// 删除客户
  444. /// </summary>
  445. /// <param name="ids"></param>
  446. /// <returns></returns>
  447. public ActionResult DelCustomer(string[] ids)
  448. {
  449. if (ids != null && ids.Length > 0)
  450. {
  451. string idd = " ";
  452. foreach (string str in ids)
  453. {
  454. idd += str + ",";
  455. }
  456. if (!string.IsNullOrEmpty(idd.Trim()))
  457. {
  458. if (cusbll.DeleteList(idd.TrimEnd(',')))
  459. {
  460. conbll.DeleteListByCusid(idd.TrimEnd(','));
  461. return Success("设置成功");
  462. }
  463. else
  464. {
  465. return Error("设置失败");
  466. }
  467. }
  468. else
  469. {
  470. return Error("请选择用户");
  471. }
  472. }
  473. else
  474. {
  475. return Error("获取参数失败");
  476. }
  477. }
  478. #endregion
  479. #region 联系人
  480. /// <summary>
  481. /// 获取客户联系人列表
  482. /// </summary>
  483. public ActionResult GetConList(string tel, string cusid, int pageindex = 1, int pagesize = 10)
  484. {
  485. string sql = "";
  486. DataTable dt = new DataTable();
  487. #region 筛选条件
  488. if (!string.IsNullOrWhiteSpace(cusid))
  489. sql += " and F_CustomerId=" + cusid + "";
  490. if (!string.IsNullOrWhiteSpace(tel)) //联系人电话
  491. sql += " and F_Telephone like '%" + tel + "%'";
  492. #endregion
  493. int recordCount = 0;
  494. if (!string.IsNullOrWhiteSpace(sql))
  495. {
  496. sql += " and F_DeleteFlag=0";
  497. dt = BLL.PagerBLL.GetListPager(
  498. "T_Cus_ContactPersonNew",
  499. "F_ManId",
  500. "*",
  501. sql,
  502. "ORDER BY F_ManId desc",
  503. pagesize,
  504. pageindex,
  505. true,
  506. out recordCount);
  507. }
  508. var obj = new
  509. {
  510. state = "success",
  511. message = "成功",
  512. rows = dt,
  513. total = recordCount
  514. };
  515. return Content(obj.ToJson());
  516. }
  517. /// <summary>
  518. /// 添加联系人
  519. /// </summary>
  520. /// <param name="coninput"></param>
  521. /// <returns></returns>
  522. public ActionResult AddContact(ContactPersonNewInput coninput)
  523. {
  524. string usercode = CurrentUser.UserData.F_UserCode;
  525. #region 添加验证判断
  526. if (coninput.F_CustomerId <= 0)
  527. return Error("客户ID获取失败!");
  528. #endregion
  529. var conmodel = new Model.T_Cus_ContactPersonNew();
  530. conmodel.F_CustomerId = coninput.F_CustomerId;
  531. conmodel.F_IsMain = coninput.F_IsMain;
  532. conmodel.F_Name = coninput.F_Name;
  533. conmodel.F_Telephone = coninput.F_Telephone;
  534. conmodel.F_Duties = coninput.F_Duties;
  535. conmodel.F_Email = coninput.F_Email;
  536. conmodel.F_MSN = coninput.F_MSN;
  537. conmodel.F_QQ = coninput.F_QQ;
  538. conmodel.F_Remark = coninput.F_Remark;
  539. conmodel.F_CreateBy = usercode;
  540. conmodel.F_CreateOn = DateTime.Now;
  541. conmodel.F_DeleteFlag = 0;
  542. int n = conbll.Add(conmodel);
  543. if (n > 0)
  544. return Success("联系人保存成功!");
  545. else
  546. return Error("联系人保存失败!");
  547. }
  548. /// <summary>
  549. /// 修改联系人
  550. /// </summary>
  551. /// <param name="coninput"></param>
  552. /// <returns></returns>
  553. public ActionResult UpdateContact(ContactPersonNewInput coninput)
  554. {
  555. string usercode = CurrentUser.UserData.F_UserCode;
  556. #region 添加验证判断
  557. if (coninput.F_ManId <= 0)
  558. return Error("参数错误!");
  559. if (coninput.F_CustomerId <= 0)
  560. return Error("客户ID获取失败!");
  561. #endregion
  562. var conmodel = conbll.GetModel(coninput.F_ManId);
  563. conmodel.F_CustomerId = coninput.F_CustomerId;
  564. conmodel.F_IsMain = coninput.F_IsMain;
  565. conmodel.F_Name = coninput.F_Name;
  566. conmodel.F_Telephone = coninput.F_Telephone;
  567. conmodel.F_Duties = coninput.F_Duties;
  568. conmodel.F_Email = coninput.F_Email;
  569. conmodel.F_MSN = coninput.F_MSN;
  570. conmodel.F_QQ = coninput.F_QQ;
  571. conmodel.F_Remark = coninput.F_Remark;
  572. var n = conbll.Update(conmodel);
  573. if (n)
  574. return Success("联系人保存成功!");
  575. else
  576. return Error("联系人保存失败!");
  577. }
  578. /// <summary>
  579. /// 删除联系人
  580. /// </summary>
  581. /// <param name="ids"></param>
  582. /// <returns></returns>
  583. public ActionResult DelContact(string[] ids)
  584. {
  585. if (ids != null && ids.Length > 0)
  586. {
  587. string idd = " ";
  588. foreach (string str in ids)
  589. {
  590. idd += str + ",";
  591. }
  592. if (!string.IsNullOrEmpty(idd.Trim()))
  593. {
  594. if (conbll.DeleteList(idd.TrimEnd(',')))
  595. {
  596. return Success("设置成功");
  597. }
  598. else
  599. {
  600. return Error("设置失败");
  601. }
  602. }
  603. else
  604. {
  605. return Error("请选择联系人");
  606. }
  607. }
  608. else
  609. {
  610. return Error("获取参数失败");
  611. }
  612. }
  613. #endregion
  614. #region 财税情况
  615. /// <summary>
  616. /// 根据客户id获取财税情况
  617. /// </summary>
  618. public ActionResult GetFinc(int cusid)
  619. {
  620. if (cusid != 0)
  621. {
  622. var model = finbll.GetModelList(" F_CustomerId=" + cusid).FirstOrDefault();
  623. if (model != null)
  624. return Success("获取财税情况成功", model);
  625. }
  626. return Error("获取财税情况失败");
  627. }
  628. /// <summary>
  629. /// 保存财税情况
  630. /// </summary>
  631. public ActionResult SaveFinance(CustomerFinanceInput input)
  632. {
  633. string usercode = CurrentUser.UserData.F_UserCode;
  634. input.F_CreateBy = usercode;
  635. var res = savefin(input);
  636. if (res)
  637. return Success("保存成功");
  638. else
  639. return Error("保存失败");
  640. }
  641. /// <summary>
  642. /// 公用方法保存财税情况
  643. /// </summary>
  644. public bool savefin(CustomerFinanceInput input)
  645. {
  646. Model.T_Cus_CustomerFinance model = new Model.T_Cus_CustomerFinance();
  647. if (input.F_CusFinId > 0)
  648. {
  649. model = finbll.GetModel(input.F_CusFinId);
  650. if (model == null)
  651. model = new Model.T_Cus_CustomerFinance();
  652. }
  653. #region 设置信息
  654. model.F_MonthState = input.F_MonthState;
  655. model.F_AnnualIncome = input.F_AnnualIncome;
  656. model.F_AnnualProfit = input.F_AnnualProfit;
  657. model.F_AnnualPersonCount = input.F_AnnualPersonCount;
  658. model.F_AnnualWages = input.F_AnnualWages;
  659. model.F_AnnualCost = input.F_AnnualCost;
  660. model.F_QuarterlyCost = input.F_QuarterlyCost;
  661. model.F_QuarterlyPersonCount = input.F_QuarterlyPersonCount;
  662. model.F_QuarterlyWages = input.F_QuarterlyWages;
  663. model.F_QuarterlyIncome = input.F_QuarterlyIncome;
  664. model.F_QPVAT = input.F_QPVAT;
  665. model.F_QPSurtax = input.F_QPSurtax;
  666. model.F_QPTaxes = input.F_QPTaxes;
  667. model.F_QPConTax = input.F_QPConTax;
  668. model.F_QPPerinTax = input.F_QPPerinTax;
  669. model.F_QPStampTax = input.F_QPStampTax;
  670. model.F_QPOtherTax = input.F_QPOtherTax;
  671. #endregion
  672. var res = false;
  673. if (input.F_CusFinId > 0)
  674. {
  675. res = finbll.Update(model);
  676. }
  677. else
  678. {
  679. model.F_CustomerId = input.F_CustomerId;
  680. model.F_CustomerCode = input.F_CustomerCode;
  681. model.F_CreateBy = input.F_CreateBy;
  682. model.F_CreatedOn = DateTime.Now;
  683. model.F_DeleteFlag = 0;
  684. res = finbll.Add(model)>0;
  685. }
  686. if (res)
  687. savefinlog(input);
  688. return res;
  689. }
  690. #region 财税情况日志
  691. private void savefinlog(CustomerFinanceInput input)
  692. {
  693. var model = new Model.T_Cus_CustomerFinanceLog();
  694. #region 设置信息
  695. model.F_CustomerId = input.F_CustomerId;
  696. model.F_CustomerCode = input.F_CustomerCode;
  697. model.F_CreateBy = input.F_CreateBy;
  698. model.F_CreatedOn = DateTime.Now;
  699. model.F_DeleteFlag = 0;
  700. model.F_MonthState = input.F_MonthState;
  701. model.F_AnnualIncome = input.F_AnnualIncome;
  702. model.F_AnnualProfit = input.F_AnnualProfit;
  703. model.F_AnnualPersonCount = input.F_AnnualPersonCount;
  704. model.F_AnnualWages = input.F_AnnualWages;
  705. model.F_AnnualCost = input.F_AnnualCost;
  706. model.F_QuarterlyCost = input.F_QuarterlyCost;
  707. model.F_QuarterlyPersonCount = input.F_QuarterlyPersonCount;
  708. model.F_QuarterlyWages = input.F_QuarterlyWages;
  709. model.F_QuarterlyIncome = input.F_QuarterlyIncome;
  710. model.F_QPVAT = input.F_QPVAT;
  711. model.F_QPSurtax = input.F_QPSurtax;
  712. model.F_QPTaxes = input.F_QPTaxes;
  713. model.F_QPConTax = input.F_QPConTax;
  714. model.F_QPPerinTax = input.F_QPPerinTax;
  715. model.F_QPStampTax = input.F_QPStampTax;
  716. model.F_QPOtherTax = input.F_QPOtherTax;
  717. #endregion
  718. new BLL.T_Cus_CustomerFinanceLog().Add(model);
  719. }
  720. #endregion
  721. #endregion
  722. #region 导入客户资料
  723. /// <summary>
  724. /// 导入excel
  725. /// </summary>
  726. public ActionResult ImportExcel()
  727. {
  728. string usercode = CurrentUser.UserData.F_UserCode;
  729. if (!string.IsNullOrWhiteSpace(usercode))
  730. {
  731. HttpPostedFile _upFile = RequestString.GetFile("upFile");
  732. if (_upFile != null)
  733. {
  734. int headrow = 0;
  735. #region 上传文件
  736. string filepath = "";
  737. string datepath = DateTime.Now.ToString("yyyyMMddHHMMss");
  738. string aLastName = _upFile.FileName.Substring(_upFile.FileName.LastIndexOf(".") + 1, (_upFile.FileName.Length - _upFile.FileName.LastIndexOf(".") - 1)); //扩展名
  739. if (aLastName != "xls" && aLastName != "xlsx")
  740. {
  741. return Error("文件类型错误,请选择Excel文件");
  742. }
  743. string newpath = datepath + "_" + _upFile.FileName;
  744. if (!Directory.Exists(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData")))
  745. {
  746. Directory.CreateDirectory(Server.MapPath(this.Request.ApplicationPath + "\\ExcelData"));
  747. }
  748. filepath = this.Request.ApplicationPath + "/ExcelData/" + newpath;
  749. string PhysicalPath = Server.MapPath(filepath);
  750. _upFile.SaveAs(PhysicalPath);
  751. #endregion
  752. DataTable dt = new DataTable();
  753. #region 读取excel中内容
  754. IWorkbook workbook = null;
  755. using (FileStream file = new FileStream(PhysicalPath, FileMode.Open, FileAccess.Read))
  756. {
  757. if (aLastName == "xlsx") // 2007版本
  758. {
  759. workbook = new XSSFWorkbook(file);
  760. }
  761. else if (aLastName == "xls") // 2003版本
  762. {
  763. workbook = new HSSFWorkbook(file);
  764. }
  765. }
  766. ISheet sheet = workbook.GetSheetAt(0);
  767. System.Collections.IEnumerator rows = sheet.GetRowEnumerator();
  768. //获取sheet的第一行
  769. IRow headerRow = sheet.GetRow(headrow);
  770. int cellCount = headerRow.LastCellNum;
  771. if (cellCount < 1)
  772. return Error("文件标题没有数据");
  773. for (int j = 0; j < cellCount; j++)
  774. {
  775. ICell cell = headerRow.GetCell(j);
  776. dt.Columns.Add(cell.ToString());
  777. }
  778. #endregion
  779. int count = 0;
  780. for (int i = (sheet.FirstRowNum + headrow + 1); i <= sheet.LastRowNum; i++)
  781. {
  782. #region 数据入库
  783. IRow row = sheet.GetRow(i);
  784. DataRow dataRow = dt.NewRow();
  785. for (int j = row.FirstCellNum; j < cellCount; j++)
  786. {
  787. if (row.GetCell(j) != null)
  788. dataRow[j] = row.GetCell(j).ToString();
  789. }
  790. dt.Rows.Add(dataRow);
  791. if (dt.Rows.Count < 1)
  792. return Error("文件内容没有数据");
  793. var cusmodel = new Model.T_Cus_CustomerBaseNew();
  794. var conmodel = new Model.T_Cus_ContactPersonNew();
  795. #region 信息对应
  796. //报税会计 做账会计 编号 客服 公司名称 负责人电话 交接日期
  797. cusmodel.F_CustomerCode = dataRow["编号"].ToString();
  798. //判断编号唯一
  799. if (getunique(0, cusmodel.F_CustomerCode))
  800. continue;
  801. cusmodel.F_CompanyName = dataRow["公司名称"].ToString();
  802. #region 处理关键字
  803. var keyword = cusmodel.F_CompanyName;
  804. var keyconfig = Configs.GetValue("keystring");
  805. var keystring = keyconfig.Split(',');
  806. foreach (var item in keystring)
  807. {
  808. if (cusmodel.F_CompanyName.Contains(item))
  809. keyword = keyword.Replace(item, "");
  810. }
  811. cusmodel.F_KeyWords = keyword;
  812. #endregion
  813. cusmodel.F_BeRelatedAcc = dataRow["报税会计"].ToString();
  814. cusmodel.F_BeMakeAcc = dataRow["做账会计"].ToString();
  815. cusmodel.F_HandoverDate = dataRow["交接日期"].ToString();
  816. cusmodel.F_CusService = dataRow["客服"].ToString();
  817. cusmodel.F_CompanyAddress= dataRow["公司地址"].ToString();
  818. cusmodel.F_RegisteredAddress = dataRow["注册地址"].ToString();
  819. cusmodel.F_Address = dataRow["地址"].ToString();
  820. cusmodel.F_Address1 = dataRow["地址1"].ToString();
  821. cusmodel.F_Address2 = dataRow["地址2"].ToString();
  822. cusmodel.F_Address3 = dataRow["地址3"].ToString();
  823. cusmodel.F_Address4 = dataRow["地址4"].ToString();
  824. cusmodel.F_WxPassword = "123456";
  825. cusmodel.F_CreateBy = usercode;
  826. cusmodel.F_CreatedOn = DateTime.Now;
  827. cusmodel.F_DeleteFlag = 0;
  828. #endregion
  829. int n = cusbll.Add(cusmodel);
  830. if (n > 0)
  831. {
  832. #region 添加联系人
  833. conmodel.F_CustomerId = n;
  834. conmodel.F_CreateBy = usercode;
  835. conmodel.F_CreateOn = DateTime.Now;
  836. conmodel.F_DeleteFlag = 0;
  837. conmodel.F_IsMain = true;
  838. if ((dataRow["负责人电话"] != null && dataRow["负责人电话"].ToString() != "")
  839. || (dataRow["负责人姓名"] != null && dataRow["负责人姓名"].ToString() != ""))
  840. {
  841. if (dataRow["负责人电话"] != null && dataRow["负责人电话"].ToString() != "")
  842. conmodel.F_Telephone = dataRow["负责人电话"].ToString();
  843. if (dataRow["负责人姓名"] != null && dataRow["负责人姓名"].ToString() != "")
  844. conmodel.F_Name = dataRow["负责人姓名"].ToString();
  845. conbll.Add(conmodel);
  846. }
  847. for (int nn = 0; nn <= 10; nn++)
  848. {
  849. if ((dataRow["负责人电话" + nn.ToString()] != null && dataRow["负责人电话" + nn.ToString()].ToString() != "")
  850. || (dataRow["负责人姓名" + nn.ToString()] != null && dataRow["负责人姓名" + nn.ToString()].ToString() != ""))
  851. {
  852. if (dataRow["负责人电话" + nn.ToString()] != null && dataRow["负责人电话" + nn.ToString()].ToString() != "")
  853. conmodel.F_Telephone = dataRow["负责人电话" + nn.ToString()].ToString();
  854. if (dataRow["负责人姓名" + nn.ToString()] != null && dataRow["负责人姓名" + nn.ToString()].ToString() != "")
  855. conmodel.F_Name = dataRow["负责人姓名" + nn.ToString()].ToString();
  856. conbll.Add(conmodel);
  857. }
  858. }
  859. #endregion
  860. #region 添加财税情况
  861. var finmodel = new Model.T_Cus_CustomerFinance();
  862. finmodel.F_CustomerId = n;
  863. finbll.Add(finmodel);
  864. #endregion
  865. count++;
  866. }
  867. #endregion
  868. }
  869. if (dt == null || dt.Rows.Count == 0)
  870. return Error("文件没有数据");
  871. else
  872. {
  873. var jstr = DataTableToJson(dt);
  874. if (count > 0)
  875. {
  876. return Success("导入成功 " + count + "条信息", jstr);
  877. }
  878. else
  879. {
  880. return Success("导入成功 " + count + "条信息", jstr);
  881. }
  882. }
  883. }
  884. return Error("数据源上传失败");
  885. }
  886. return Error("用户登录失败,请重新登录");
  887. }
  888. public string DataTableToJson(DataTable dt)
  889. {
  890. string JsonString = string.Empty;
  891. JsonString = JsonConvert.SerializeObject(dt);
  892. return JsonString;
  893. }
  894. #endregion
  895. }
  896. }