ExamineApplyController.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Web;
  5. using System.Web.Mvc;
  6. using EMIS.CommonLogic.Students;
  7. using Bowin.Common.Exceptions;
  8. using EMIS.ViewModel.ExaminationApply;
  9. using EMIS.CommonLogic.ExaminationApply;
  10. using EMIS.ViewModel.Students;
  11. using EMIS.ViewModel;
  12. using EMIS.Entities;
  13. using EMIS.Web.Controls;
  14. using EMIS.Utility;
  15. using System.IO;
  16. using EMIS.ViewModel.FeeManage;
  17. namespace EMIS.Web.Controllers.StudentSystem.Examine
  18. {
  19. [Authorization]
  20. public class ExamineApplyController : Controller
  21. {
  22. public IStudentsServices StudentsServices { get; set; }
  23. public IStudentRecordServices StudentRecordService { get; set; }
  24. public IExamineApplyServices ExamineApplyService { get; set; }
  25. public IExaminationSubjectServices ExaminationSubjectServices { get; set; }
  26. //
  27. // GET: /ExamineApply/
  28. [HttpGet]
  29. public ActionResult Apply()
  30. {
  31. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  32. var Student = StudentRecordService.GetStudentByStudentNo(user.UserID);
  33. return View(Student);
  34. }
  35. [HttpGet]
  36. public ActionResult RegisterList()
  37. {
  38. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  39. var Student = StudentRecordService.GetStudentByStudentNo(user.UserID);
  40. return View(Student);
  41. }
  42. /// <summary>
  43. /// 获取可报名列表
  44. /// </summary>
  45. /// <param name="pararms"></param>
  46. /// <returns></returns>
  47. [HttpPost]
  48. public ActionResult GetExaminationSubjectList()
  49. {
  50. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  51. return base.Json(ExamineApplyService.GetExaminationSubjectList(user.UserID));
  52. }
  53. /// <summary>
  54. /// 获取已报名列表
  55. /// </summary>
  56. /// <returns></returns>
  57. [HttpPost]
  58. public ActionResult GetExaminationRegisterList()
  59. {
  60. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  61. return base.Json(ExamineApplyService.GetExaminationRegisterList(user.UserID));
  62. }
  63. [HttpGet]
  64. public ActionResult Register(Guid? ExaminationBatchProjectID)
  65. {
  66. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  67. StudentListView registerView = new StudentListView();
  68. if (ExaminationBatchProjectID.HasValue)
  69. {
  70. registerView = ExamineApplyService.GetRegisterViewByExaminationBatchProjectID(ExaminationBatchProjectID, user.UserID);
  71. }
  72. return View(registerView);
  73. }
  74. [HttpPost]
  75. public ActionResult Register(StudentListView registerView)
  76. {
  77. try
  78. {
  79. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  80. var accepts = new List<string> { ".jpg" };
  81. var postedFile = Request.Files["RegistView.PhotoUrl"];
  82. if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && !accepts.Contains(Path.GetExtension(postedFile.FileName).ToLower()))
  83. {
  84. throw new Exception("只允许上传.jpg格式的文件。");
  85. }
  86. if (postedFile != null && !string.IsNullOrEmpty(postedFile.FileName) && (postedFile.ContentLength > (200 * 1024) || postedFile.ContentLength < (50 * 1024)))
  87. {
  88. throw new Exception("只允许上传50-200k大小的照片。");
  89. }
  90. string photoUrl = FileUploadHelper.UploadFile(postedFile);
  91. if (photoUrl != null)
  92. {
  93. registerView.RegistView.PhotoUrl = photoUrl;
  94. }
  95. var register = ExamineApplyService.StudentRegister(registerView, user.UserID);
  96. //return Json(new ReturnMessage()
  97. //{
  98. // IsSuccess = true,
  99. // Message = "报名成功",
  100. // Type = 1,
  101. //});
  102. if (register.IsOnlinePay)
  103. {
  104. return RedirectToAction("MsgShowAndOpenAddUrl", "Common", new
  105. {
  106. title = "在线缴费",
  107. WindowID = Request["WindowID"],
  108. msg = "报名成功,请进入”已报项目“在规定时间内完成缴费",
  109. url = Url.Content("~/Weixin/NativePay").AddMenuParameter() + "&examinationRegistrationID=" + register.ExaminationRegistrationID + "&fee=" + register.Fee + "&feeTypeName=" + register.FeeTypeName,
  110. });
  111. }
  112. else {
  113. return RedirectToAction("MsgShow", "Common", new
  114. {
  115. WindowID = Request["WindowID"],
  116. msg = "报名成功,请进入”已报项目“在规定时间内完成缴费",
  117. url = Url.Action("Apply").AddMenuParameter()
  118. });
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. return RedirectToAction("MsgShow", "Common", new
  124. {
  125. WindowID = Request["WindowID"],
  126. msg = "报名失败,原因:" + ex.Message,
  127. url = Url.Action("Apply").AddMenuParameter()
  128. });
  129. //return Json(new ReturnMessage()
  130. //{
  131. // IsSuccess = false,
  132. // Message = "报名失败,原因:" + ex.Message
  133. //});
  134. }
  135. }
  136. public ActionResult Cancel(string ExaminationRegistrationIDs)
  137. {
  138. try
  139. {
  140. var examinationRegistrationIDList = ExaminationRegistrationIDs.Split(',').Where(x => x.IndexOf("-") >= 0).Select(x => new Guid(x)).ToList();
  141. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  142. var registrationList = ExamineApplyService.GetExaminationRegistrationPayViewByRegistrationID(examinationRegistrationIDList);
  143. if (registrationList.Where(x => x.RecordStatus != (int)EX_ExaminationRegistrationStatus.Paid && x.RecordStatus != (int)EX_ExaminationRegistrationStatus.ForPay).Count() > 0)
  144. {
  145. throw new Exception("只有待缴费或者已缴费状态的数据才能取消报名!");
  146. }
  147. var changeIDList = registrationList.Where(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid).Select(x => x.ExaminationRegistrationID).ToList();
  148. var deleteIDList = registrationList.Where(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.ForPay).Select(x => x.ExaminationRegistrationID).ToList();
  149. //待缴费的需要按照原来的判断(已打包,报名时间)
  150. ExamineApplyService.CheckCanCancelOnline(deleteIDList);
  151. ExamineApplyService.ChangeAndDelete(new List<Guid>(), deleteIDList);
  152. //已缴费的撤销报名需要进行退费申请
  153. if (changeIDList.Count() > 0)
  154. {
  155. return Json(new ReturnMessage()
  156. {
  157. IsSuccess = true,
  158. Message = ExaminationRegistrationIDs,
  159. Type = 99,
  160. });
  161. }
  162. //foreach (var registration in registrationList.Where(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid))
  163. //{
  164. // //是否线上缴费
  165. // var isOnlinePay = ExamineApplyService.CheckIsOnlinePay(registration.ExaminationRegistrationID);
  166. // if (isOnlinePay)
  167. // {
  168. // WechatHelper.Refund(registration.OrderID, registration.Fee ?? 0, (registration.Fee ?? 0) - (registration.RefundTotal ?? 0));
  169. // }
  170. //}
  171. //ExamineApplyService.ChangeAndDelete(changeIDList, deleteIDList);
  172. return Json(new ReturnMessage()
  173. {
  174. IsSuccess = true,
  175. Message = "撤销成功",
  176. });
  177. }
  178. catch (Exception ex)
  179. {
  180. return Json(new ReturnMessage()
  181. {
  182. IsSuccess = false,
  183. Message = "撤销失败,原因:" + ex.Message,
  184. });
  185. }
  186. }
  187. public ActionResult CheckIsOnlinePay(string ExaminationRegistrationIDs)
  188. {
  189. try
  190. {
  191. var examinationRegistrationIDList = ExaminationRegistrationIDs.Split(',').Where(x => x.IndexOf("-") >= 0).Select(x => new Guid(x)).ToList();
  192. var registrationList = ExamineApplyService.GetExaminationRegistrationPayViewByRegistrationID(examinationRegistrationIDList);
  193. List<bool> isOnlinePayList = new List<bool>();
  194. foreach (var registration in registrationList.Where(x => x.RecordStatus == (int)EX_ExaminationRegistrationStatus.Paid))
  195. {
  196. var isOnlinePay = ExamineApplyService.CheckIsOnlinePay(registration.ExaminationRegistrationID);
  197. isOnlinePayList.Add(isOnlinePay);
  198. }
  199. if (isOnlinePayList.Where(x => x == true).Count() > 0 && isOnlinePayList.Where(x => x == false).Count() > 0)
  200. {
  201. return Json(new ReturnMessage()
  202. {
  203. IsSuccess = false,
  204. Message = "批量撤销已缴费的报名,只能撤销同样是线上缴费或者同样是线下缴费的数据",
  205. });
  206. }
  207. else if (isOnlinePayList.Where(x => x == true).Count() == isOnlinePayList.Count())
  208. {
  209. Cancel(ExaminationRegistrationIDs);
  210. }
  211. else
  212. {
  213. return Json(new ReturnMessage()
  214. {
  215. IsSuccess = true,
  216. Message = ExaminationRegistrationIDs,
  217. Type = 99,
  218. });
  219. //return RedirectToAction("MsgShowAndOpenAddUrl", "Common", new
  220. //{
  221. // title = "退款信息确认",
  222. // WindowID = Request["WindowID"],
  223. // msg = "请对开户银行和银行卡号信息进行填写确认",
  224. // url = Url.Content("~/ExamineApply/Refund").AddMenuParameter() + "&examinationRegistrationIDs=" + ExaminationRegistrationIDs,
  225. //});
  226. }
  227. return Json(new ReturnMessage()
  228. {
  229. IsSuccess = true,
  230. Message = "撤销成功",
  231. });
  232. }
  233. catch (Exception ex)
  234. {
  235. string mge = ex.Message;
  236. return Json(new ReturnMessage()
  237. {
  238. IsSuccess = false,
  239. Message = "撤销失败,原因:" + mge,
  240. });
  241. }
  242. }
  243. [HttpPost]
  244. [AllowAnonymous]
  245. public ActionResult CanPay(Guid examinationRegistrationID)
  246. {
  247. try
  248. {
  249. this.ExamineApplyService.CheckCanPay(examinationRegistrationID);
  250. return Json(new ReturnMessage()
  251. {
  252. IsSuccess = true,
  253. Message = "可以缴费"
  254. });
  255. }
  256. catch (Exception ex)
  257. {
  258. return Json(new ReturnMessage()
  259. {
  260. IsSuccess = false,
  261. Message = "缴费失败,原因:" + ex.Message
  262. });
  263. }
  264. }
  265. public ActionResult NativePay(Guid examinationRegistrationID, decimal fee, string feeTypeName)
  266. {
  267. var nativePayView = new NativePayView();
  268. nativePayView.ExaminationRegistrationID = examinationRegistrationID;
  269. nativePayView.Fee = fee;
  270. nativePayView.FeeTypeName = feeTypeName;
  271. return View(nativePayView);
  272. }
  273. [HttpGet]
  274. public ActionResult Refund(string examinationRegistrationIDs)
  275. {
  276. var refundView = new RefundView();
  277. var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  278. refundView = ExamineApplyService.GetRefundViewByUserID(user.UserID);
  279. ViewBag.ExaminationRegistrationIDs = examinationRegistrationIDs;
  280. return View(refundView);
  281. }
  282. [HttpPost]
  283. public ActionResult Refund(RefundView refundView)
  284. {
  285. try
  286. {
  287. var examinationRegistrationIDs = Request.Form["SelectIDs"];
  288. var examinationRegistrationIDList = examinationRegistrationIDs.Split(',').Where(x => x.IndexOf("-") >= 0).Select(x => new Guid(x)).ToList();
  289. ExamineApplyService.RefundApply(refundView, examinationRegistrationIDList);
  290. return RedirectToAction("MsgShow", "Common", new
  291. {
  292. WindowID = Request["WindowID"],
  293. msg = "已提交退费申请,请在24小时内带齐办理资料(收费票据、银行卡复印件)到鉴定考试中心审核是否可以退费。",
  294. url = Url.Action("RegisterList").AddMenuParameter()
  295. });
  296. //return Json(new ReturnMessage()
  297. //{
  298. // IsSuccess = true,
  299. // Message = "退费申请提交成功,请等待老师审核!"
  300. //});
  301. }
  302. catch (Exception ex)
  303. {
  304. return RedirectToAction("MsgShow", "Common", new
  305. {
  306. WindowID = Request["WindowID"],
  307. msg = "退费申请提交失败,原因:" + ex.Message,
  308. url = Url.Action("RegisterList").AddMenuParameter()
  309. });
  310. //return Json(new ReturnMessage()
  311. //{
  312. // IsSuccess = false,
  313. // Message = "退费申请提交失败,原因:" + ex.Message
  314. //});
  315. }
  316. }
  317. //public ActionResult ApplySubmit(string ExaminationSubjectID)
  318. //{
  319. // try
  320. // {
  321. // Guid subjectID = Guid.Parse(Request.Params["ExaminationSubjectID"]);
  322. // int version = int.Parse(Request.Params["Version"]);
  323. // var user = HttpContext.User as EMIS.Utility.FormValidate.CustomPrincipal;
  324. // ExamineApplyService.Value.ApplySubmit(subjectID, user.UserID);
  325. // return base.Json("报名成功");
  326. // }
  327. // catch (Exception ex)
  328. // {
  329. // GetExceptionDetailMessage(ex);
  330. // string mge = GetExceptionDetailMessage(ex).Message;
  331. // return base.Json("报名失败,原因:" + mge);
  332. // }
  333. //}
  334. //Exception GetExceptionDetailMessage(Exception ex)
  335. //{
  336. // if (ex.InnerException == null)
  337. // {
  338. // return ex;
  339. // }
  340. // else
  341. // return GetExceptionDetailMessage(ex.InnerException);
  342. //}
  343. }
  344. }