OrderController.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using LeaRun.Application.Busines.CustomerManage;
  2. using LeaRun.Application.Busines.SystemManage;
  3. using LeaRun.Application.Cache;
  4. using LeaRun.Application.Code;
  5. using LeaRun.Application.Entity.CustomerManage;
  6. using LeaRun.Util;
  7. using LeaRun.Util.Extension;
  8. using LeaRun.Util.Offices;
  9. using LeaRun.Util.WebControl;
  10. using System;
  11. using System.Collections.Generic;
  12. using System.Linq;
  13. using System.Web;
  14. using System.Web.Mvc;
  15. namespace LeaRun.Application.Web.Areas.CustomerManage.Controllers
  16. {
  17. /// <summary>
  18. /// 版 本 6.1
  19. /// Copyright (c) 2013-2016 上海力软信息技术有限公司
  20. /// 创建人:佘赐雄
  21. /// 日 期:2016.3.11 14:22
  22. /// 描 述:客户订单
  23. /// </summary>
  24. public class OrderController : MvcControllerBase
  25. {
  26. private CodeRuleBLL codeRuleBLL = new CodeRuleBLL();
  27. private OrderBLL orderBLL = new OrderBLL();
  28. private OrderEntryBLL orderEntryBLL = new OrderEntryBLL();
  29. #region 视图功能
  30. /// <summary>
  31. /// 订单列表页面
  32. /// </summary>
  33. /// <returns></returns>
  34. [HttpGet]
  35. [HandlerAuthorize(PermissionMode.Enforce)]
  36. public ActionResult Index()
  37. {
  38. return View();
  39. }
  40. /// <summary>
  41. /// 订单表单页面
  42. /// </summary>
  43. /// <returns></returns>
  44. [HttpGet]
  45. [HandlerAuthorize(PermissionMode.Enforce)]
  46. public ActionResult Form()
  47. {
  48. if (Request["keyValue"] == null)
  49. {
  50. ViewBag.OrderCode = codeRuleBLL.GetBillCode(SystemInfo.CurrentUserId, "", ((int)CodeRuleEnum.Customer_OrderCode).ToString());
  51. }
  52. return View();
  53. }
  54. /// <summary>
  55. /// 订单详细页面
  56. /// </summary>
  57. /// <returns></returns>
  58. [HttpGet]
  59. [HandlerAuthorize(PermissionMode.Enforce)]
  60. public ActionResult Detail()
  61. {
  62. return View();
  63. }
  64. /// <summary>
  65. /// 选择商品信息
  66. /// </summary>
  67. /// <returns></returns>
  68. public ActionResult OptionProduct()
  69. {
  70. return View();
  71. }
  72. #endregion
  73. #region 获取数据
  74. /// <summary>
  75. /// 获取列表(订单主表)
  76. /// </summary>
  77. /// <param name="pagination">分页参数</param>
  78. /// <param name="queryJson">查询参数</param>
  79. /// <returns>返回分页列表Json</returns>
  80. [HttpGet]
  81. public ActionResult GetPageListJson(Pagination pagination, string queryJson)
  82. {
  83. var watch = CommonHelper.TimerStart();
  84. var data = orderBLL.GetPageList(pagination, queryJson);
  85. var jsonData = new
  86. {
  87. rows = data,
  88. total = pagination.total,
  89. page = pagination.page,
  90. records = pagination.records,
  91. costtime = CommonHelper.TimerEnd(watch)
  92. };
  93. return ToJsonResult(jsonData);
  94. }
  95. /// <summary>
  96. /// 获取列表(订单明细表)
  97. /// </summary>
  98. /// <param name="orderId">订单Id</param>
  99. /// <returns>返回列表Json</returns>
  100. [HttpGet]
  101. public ActionResult GetOrderEntryListJson(string orderId)
  102. {
  103. var data = orderEntryBLL.GetList(orderId);
  104. return ToJsonResult(data);
  105. }
  106. /// <summary>
  107. /// 获取实体 (主表+明细)
  108. /// </summary>
  109. /// <param name="keyValue">主键值</param>
  110. /// <returns>返回对象Json</returns>
  111. [HttpGet]
  112. public ActionResult GetFormJson(string keyValue)
  113. {
  114. var jsonData = new
  115. {
  116. order = orderBLL.GetEntity(keyValue),
  117. orderEntry = orderEntryBLL.GetList(keyValue)
  118. };
  119. return ToJsonResult(jsonData);
  120. }
  121. /// <summary>
  122. /// 获取前单数据实体
  123. /// </summary>
  124. /// <param name="keyValue">主键值</param>
  125. /// <returns>返回对象Json</returns>
  126. [HttpGet]
  127. public ActionResult GetPrevJson(string keyValue)
  128. {
  129. var data = orderBLL.GetPrevOrNextEntity(keyValue, 1);
  130. return ToJsonResult(data);
  131. }
  132. /// <summary>
  133. /// 获取后单数据实体
  134. /// </summary>
  135. /// <param name="keyValue">主键值</param>
  136. /// <returns>返回对象Json</returns>
  137. [HttpGet]
  138. public ActionResult GetNextJson(string keyValue)
  139. {
  140. var data = orderBLL.GetPrevOrNextEntity(keyValue, 2);
  141. return ToJsonResult(data);
  142. }
  143. #endregion
  144. #region 提交数据
  145. /// <summary>
  146. /// 删除订单数据
  147. /// </summary>
  148. /// <param name="keyValue">主键值</param>
  149. /// <returns></returns>
  150. [HttpPost]
  151. [ValidateAntiForgeryToken]
  152. [AjaxOnly]
  153. [HandlerAuthorize(PermissionMode.Enforce)]
  154. public ActionResult RemoveForm(string keyValue)
  155. {
  156. orderBLL.RemoveForm(keyValue);
  157. return Success("删除成功。");
  158. }
  159. /// <summary>
  160. /// 保存订单表单(新增、修改)
  161. /// </summary>
  162. /// <param name="keyValue">主键值</param>
  163. /// <param name="entity">实体对象</param>
  164. /// <param name="orderEntryJson">明细实体对象Json</param>
  165. /// <returns></returns>
  166. [HttpPost]
  167. [ValidateAntiForgeryToken]
  168. [AjaxOnly]
  169. public ActionResult SaveForm(string keyValue, OrderEntity entity, string orderEntryJson)
  170. {
  171. var orderEntryList = orderEntryJson.ToList<OrderEntryEntity>();
  172. orderBLL.SaveForm(keyValue, entity, orderEntryList);
  173. return Success("操作成功。");
  174. }
  175. #endregion
  176. #region 导出数据
  177. /// <summary>
  178. /// 导出订单明细(Excel模板导出)
  179. /// </summary>
  180. /// <param name="orderId">订单Id</param>
  181. /// <returns></returns>
  182. public void ExportOrderEntry(string orderId)
  183. {
  184. var order = orderBLL.GetEntity(orderId);
  185. var orderEntry = orderEntryBLL.GetList(orderId);
  186. List<TemplateMode> list = new List<TemplateMode>();
  187. //设置主表信息
  188. list.Add(new TemplateMode() { row = 1, cell = 1, value = order.CustomerName });
  189. list.Add(new TemplateMode() { row = 1, cell = 5, value = order.SellerName });
  190. list.Add(new TemplateMode() { row = 1, cell = 8, value = order.OrderDate.ToDate().ToString("yyyy-MM-dd") });
  191. list.Add(new TemplateMode() { row = 1, cell = 11, value = order.OrderCode });
  192. list.Add(new TemplateMode() { row = 17, cell = 1, value = order.DiscountSum.ToString() });
  193. list.Add(new TemplateMode() { row = 17, cell = 5, value = order.Accounts.ToString() });
  194. list.Add(new TemplateMode() { row = 17, cell = 8, value = order.PaymentDate.ToDate().ToString("yyyy-MM-dd") });
  195. list.Add(new TemplateMode() { row = 17, cell = 11, value = new DataItemCache().ToItemName("Client_PaymentMode", order.PaymentMode) });
  196. list.Add(new TemplateMode() { row = 18, cell = 1, value = order.SaleCost.ToString() });
  197. list.Add(new TemplateMode() { row = 18, cell = 5, value = order.CreateUserName });
  198. list.Add(new TemplateMode() { row = 18, cell = 8, value = order.ContractCode });
  199. list.Add(new TemplateMode() { row = 18, cell = 11, value = order.ContractFile });
  200. list.Add(new TemplateMode() { row = 19, cell = 1, value = order.AbstractInfo });
  201. list.Add(new TemplateMode() { row = 20, cell = 1, value = order.Description });
  202. //设置明细信息
  203. int rowIndex = 4;
  204. foreach (OrderEntryEntity item in orderEntry)
  205. {
  206. list.Add(new TemplateMode() { row = rowIndex, cell = 0, value = item.ProductName });
  207. list.Add(new TemplateMode() { row = rowIndex, cell = 3, value = item.ProductCode });
  208. list.Add(new TemplateMode() { row = rowIndex, cell = 4, value = item.UnitId });
  209. list.Add(new TemplateMode() { row = rowIndex, cell = 5, value = item.Qty.ToString() });
  210. list.Add(new TemplateMode() { row = rowIndex, cell = 6, value = item.Price.ToString() });
  211. list.Add(new TemplateMode() { row = rowIndex, cell = 7, value = item.Amount.ToString() });
  212. list.Add(new TemplateMode() { row = rowIndex, cell = 8, value = item.TaxRate.ToString() });
  213. list.Add(new TemplateMode() { row = rowIndex, cell = 9, value = item.Taxprice.ToString() });
  214. list.Add(new TemplateMode() { row = rowIndex, cell = 10, value = item.Tax.ToString() });
  215. list.Add(new TemplateMode() { row = rowIndex, cell = 11, value = item.TaxAmount.ToString() });
  216. list.Add(new TemplateMode() { row = rowIndex, cell = 12, value = item.Description });
  217. rowIndex++;
  218. }
  219. //设置明细合计
  220. list.Add(new TemplateMode() { row = 16, cell = 5, value = orderEntry.Sum(t => t.Qty).ToString() });
  221. list.Add(new TemplateMode() { row = 16, cell = 6, value = orderEntry.Sum(t => t.Price).ToString() });
  222. list.Add(new TemplateMode() { row = 16, cell = 7, value = orderEntry.Sum(t => t.Amount).ToString() });
  223. list.Add(new TemplateMode() { row = 16, cell = 9, value = orderEntry.Sum(t => t.Taxprice).ToString() });
  224. list.Add(new TemplateMode() { row = 16, cell = 10, value = orderEntry.Sum(t => t.Tax).ToString() });
  225. list.Add(new TemplateMode() { row = 16, cell = 11, value = orderEntry.Sum(t => t.TaxAmount).ToString() });
  226. //执行导出
  227. ExcelHelper.ExcelDownload(list, "OrderEntry.xlsx", "订单明细-" + order.OrderCode + ".xlsx");
  228. }
  229. #endregion
  230. }
  231. }