You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

253 lines
8.6 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Text;
  6. namespace Learun.Application.CRM
  7. {
  8. /// <summary>
  9. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  10. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  11. /// 创建人:陈彬彬
  12. /// 日 期:2017.03.09
  13. /// 描 述:订单管理
  14. /// </summary>
  15. public class CrmOrderService :RepositoryFactory
  16. {
  17. private string fieldSql;
  18. public CrmOrderService()
  19. {
  20. fieldSql = @"
  21. t.F_OrderId,
  22. t.F_CustomerId,
  23. t.F_SellerId,
  24. t.F_OrderDate,
  25. t.F_OrderCode,
  26. t.F_DiscountSum,
  27. t.F_Accounts,
  28. t.F_ReceivedAmount,
  29. t.F_PaymentDate,
  30. t.F_PaymentMode,
  31. t.F_PaymentState,
  32. t.F_SaleCost,
  33. t.F_AbstractInfo,
  34. t.F_ContractCode,
  35. t.F_ContractFile,
  36. t.F_SortCode,
  37. t.F_DeleteMark,
  38. t.F_EnabledMark,
  39. t.F_Description,
  40. t.F_CreateDate,
  41. t.F_CreateUserId,
  42. t.F_CreateUserName,
  43. t.F_ModifyDate,
  44. t.F_ModifyUserId,
  45. t.F_ModifyUserName
  46. ";
  47. }
  48. #region 获取数据
  49. /// <summary>
  50. /// 订单列表
  51. /// </summary>
  52. /// <returns></returns>
  53. public IEnumerable<CrmOrderEntity> GetPageList(Pagination pagination, string queryJson, string custmerQuerySql)
  54. {
  55. try
  56. {
  57. StringBuilder strSql = new StringBuilder();
  58. strSql.Append("SELECT " + fieldSql + " FROM LR_CRM_Order t WHERE 1=1 ");
  59. var queryParam = queryJson.ToJObject();
  60. DateTime startTime = new DateTime(), endTime = new DateTime();
  61. //单据日期
  62. if (!queryParam["StartTime"].IsEmpty() && !queryParam["EndTime"].IsEmpty())
  63. {
  64. startTime = queryParam["StartTime"].ToDate();
  65. endTime = queryParam["EndTime"].ToDate().AddDays(1);
  66. strSql.Append(" AND ( t.F_OrderDate >= @startTime AND t.F_OrderDate <= @endTime ) ");
  67. }
  68. // 单据编号
  69. string orderCode = "";
  70. if (!queryParam["orderCode"].IsEmpty())
  71. {
  72. orderCode = queryParam["orderCode"].ToString();
  73. strSql.Append(" AND ( t.F_OrderCode = @orderCode ) ");
  74. }
  75. // 客户名称
  76. string customerId = "";
  77. if (!queryParam["customerId"].IsEmpty())
  78. {
  79. customerId = queryParam["customerId"].ToString();
  80. strSql.Append(" AND ( t.F_CustomerId = @customerId ) ");
  81. }
  82. // 销售人员
  83. string sellerId = "";
  84. if (!queryParam["sellerId"].IsEmpty())
  85. {
  86. sellerId = queryParam["sellerId"].ToString();
  87. strSql.Append(" AND ( t.F_SellerId = @sellerId ) ");
  88. }
  89. // 收款状态
  90. string paymentState = "";
  91. if (!queryParam["paymentState"].IsEmpty())
  92. {
  93. paymentState = queryParam["paymentState"].ToString();
  94. strSql.Append(" AND ( t.F_PaymentState = @paymentState ) ");
  95. }
  96. if (!string.IsNullOrEmpty(custmerQuerySql))
  97. {
  98. strSql.Append(" AND " + custmerQuerySql);
  99. }
  100. return this.BaseRepository().FindList<CrmOrderEntity>(strSql.ToString(), new { startTime, endTime, orderCode, customerId, sellerId, paymentState }, pagination);
  101. }
  102. catch (Exception ex)
  103. {
  104. if (ex is ExceptionEx)
  105. {
  106. throw;
  107. }
  108. else
  109. {
  110. throw ExceptionEx.ThrowServiceException(ex);
  111. }
  112. }
  113. }
  114. /// <summary>
  115. /// 获取订单信息主键
  116. /// </summary>
  117. /// <param name="keyValue">主键</param>
  118. /// <returns></returns>
  119. public CrmOrderEntity GetCrmOrderEntity(string keyValue)
  120. {
  121. try
  122. {
  123. return this.BaseRepository().FindEntity<CrmOrderEntity>(keyValue);
  124. }
  125. catch (Exception ex)
  126. {
  127. if (ex is ExceptionEx)
  128. {
  129. throw;
  130. }
  131. else
  132. {
  133. throw ExceptionEx.ThrowServiceException(ex);
  134. }
  135. }
  136. }
  137. /// <summary>
  138. /// 获取订单产品明细数据
  139. /// </summary>
  140. /// <param name="orderId">订单主键</param>
  141. /// <returns></returns>
  142. public IEnumerable<CrmOrderProductEntity> GetCrmOrderProductEntity(string orderId)
  143. {
  144. try
  145. {
  146. return this.BaseRepository().FindList<CrmOrderProductEntity>(t => t.F_OrderId == orderId);
  147. }
  148. catch (Exception ex)
  149. {
  150. if (ex is ExceptionEx)
  151. {
  152. throw;
  153. }
  154. else
  155. {
  156. throw ExceptionEx.ThrowServiceException(ex);
  157. }
  158. }
  159. }
  160. #endregion
  161. #region 提交数据
  162. /// <summary>
  163. /// 删除数据
  164. /// </summary>
  165. /// <param name="keyValue">主键</param>
  166. public void DeleteEntity(string keyValue)
  167. {
  168. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  169. try
  170. {
  171. db.Delete<CrmOrderEntity>(t => t.F_OrderId.Equals(keyValue));
  172. db.Delete<CrmOrderProductEntity>(t => t.F_OrderId.Equals(keyValue));
  173. db.Commit();
  174. }
  175. catch (Exception ex)
  176. {
  177. db.Rollback();
  178. if (ex is ExceptionEx)
  179. {
  180. throw;
  181. }
  182. else
  183. {
  184. throw ExceptionEx.ThrowServiceException(ex);
  185. }
  186. }
  187. }
  188. /// <summary>
  189. /// 保存表单(新增、修改)
  190. /// </summary>
  191. /// <param name="keyValue">主键值</param>
  192. /// <param name="crmOrderEntity">实体对象</param>
  193. /// <param name="CrmOrderProductEntity">明细实体对象</param>
  194. /// <returns></returns>
  195. public void SaveEntity(string keyValue, CrmOrderEntity crmOrderEntity, List<CrmOrderProductEntity> crmOrderProductList)
  196. {
  197. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  198. try
  199. {
  200. if (!string.IsNullOrEmpty(keyValue))
  201. {
  202. //主表
  203. crmOrderEntity.Modify(keyValue);
  204. db.Update(crmOrderEntity);
  205. //明细
  206. db.Delete<CrmOrderProductEntity>(t => t.F_OrderId.Equals(keyValue));
  207. foreach (CrmOrderProductEntity crmOrderProductEntity in crmOrderProductList)
  208. {
  209. crmOrderProductEntity.Create();
  210. crmOrderProductEntity.F_OrderId = crmOrderEntity.F_OrderId;
  211. db.Insert(crmOrderProductEntity);
  212. }
  213. }
  214. else
  215. {
  216. //主表
  217. crmOrderEntity.Create();
  218. db.Insert(crmOrderEntity);
  219. //明细
  220. foreach (CrmOrderProductEntity crmOrderProductEntity in crmOrderProductList)
  221. {
  222. crmOrderProductEntity.Create();
  223. crmOrderProductEntity.F_OrderId = crmOrderEntity.F_OrderId;
  224. db.Insert(crmOrderProductEntity);
  225. }
  226. }
  227. db.Commit();
  228. }
  229. catch (Exception ex)
  230. {
  231. db.Rollback();
  232. if (ex is ExceptionEx)
  233. {
  234. throw;
  235. }
  236. else
  237. {
  238. throw ExceptionEx.ThrowServiceException(ex);
  239. }
  240. }
  241. }
  242. #endregion
  243. }
  244. }