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.
 
 
 
 
 
 

281 lines
9.8 KiB

  1. using Learun.DataBase.Repository;
  2. using Learun.Util;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Linq;
  7. namespace Learun.Application.CRM
  8. {
  9. /// <summary>
  10. /// 版 本 Learun-ADMS-Ultimate V7.0.0 数字化智慧校园
  11. /// Copyright (c) 2013-2018 北京泉江科技有限公司
  12. /// 创 建:超级管理员
  13. /// 日 期:2017-07-11 11:30
  14. /// 描 述:商机管理
  15. /// </summary>
  16. public class CrmChanceService : RepositoryFactory
  17. {
  18. private CrmTrailRecordService crmTrailRecordService = new CrmTrailRecordService();
  19. #region 获取数据
  20. /// <summary>
  21. /// 获取列表
  22. /// </summary>
  23. /// <param name="pagination">分页</param>
  24. /// <param name="queryJson">查询参数</param>
  25. /// <returns>返回分页列表</returns>
  26. public IEnumerable<CrmChanceEntity> GetPageList(Pagination pagination, string queryJson)
  27. {
  28. try
  29. {
  30. var expression = LinqExtensions.True<CrmChanceEntity>();
  31. var queryParam = queryJson.ToJObject();
  32. //查询条件
  33. if (!queryParam["keyword"].IsEmpty())
  34. {
  35. string keyword = queryParam["keyword"].ToString();
  36. expression = expression.And(t => t.F_FullName.Contains(keyword)
  37. || t.F_Contacts.Contains(keyword)
  38. || t.F_Mobile.Contains(keyword)
  39. || t.F_Tel.Contains(keyword)
  40. || t.F_QQ.Contains(keyword)
  41. || t.F_Wechat.Contains(keyword)
  42. || t.F_CompanyName.Contains(keyword)
  43. || t.F_Contacts.Contains(keyword)
  44. || t.F_City.Contains(keyword)
  45. );
  46. }
  47. return this.BaseRepository().FindList(expression, pagination);
  48. }
  49. catch (Exception ex)
  50. {
  51. if (ex is ExceptionEx)
  52. {
  53. throw;
  54. }
  55. else
  56. {
  57. throw ExceptionEx.ThrowServiceException(ex);
  58. }
  59. }
  60. }
  61. /// <summary>
  62. /// 获取实体
  63. /// </summary>
  64. /// <param name="keyValue">主键值</param>
  65. /// <returns></returns>
  66. public CrmChanceEntity GetEntity(string keyValue)
  67. {
  68. try
  69. {
  70. return this.BaseRepository().FindEntity<CrmChanceEntity>(keyValue);
  71. }
  72. catch (Exception ex)
  73. {
  74. if (ex is ExceptionEx)
  75. {
  76. throw;
  77. }
  78. else
  79. {
  80. throw ExceptionEx.ThrowServiceException(ex);
  81. }
  82. }
  83. }
  84. #endregion
  85. #region 验证数据
  86. /// <summary>
  87. /// 商机名称不能重复
  88. /// </summary>
  89. /// <param name="fullName">名称</param>
  90. /// <param name="keyValue">主键</param>
  91. /// <returns></returns>
  92. public bool ExistFullName(string fullName, string keyValue)
  93. {
  94. try
  95. {
  96. var expression = LinqExtensions.True<CrmChanceEntity>();
  97. expression = expression.And(t => t.F_FullName == fullName);
  98. if (!string.IsNullOrEmpty(keyValue))
  99. {
  100. expression = expression.And(t => t.F_ChanceId != keyValue);
  101. }
  102. return this.BaseRepository().IQueryable(expression).Count() == 0 ? true : false;
  103. }
  104. catch (Exception ex)
  105. {
  106. if (ex is ExceptionEx)
  107. {
  108. throw;
  109. }
  110. else
  111. {
  112. throw ExceptionEx.ThrowServiceException(ex);
  113. }
  114. }
  115. }
  116. #endregion
  117. #region 提交数据
  118. /// <summary>
  119. /// 删除数据
  120. /// </summary>
  121. /// <param name="keyValue">主键</param>
  122. public void DeleteEntity(string keyValue)
  123. {
  124. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  125. try
  126. {
  127. db.Delete<CrmChanceEntity>(t => t.F_ChanceId == keyValue);
  128. db.Delete<CrmTrailRecordEntity>(t => t.F_ObjectId.Equals(keyValue));
  129. db.Commit();
  130. }
  131. catch (Exception ex)
  132. {
  133. db.Rollback();
  134. if (ex is ExceptionEx)
  135. {
  136. throw;
  137. }
  138. else
  139. {
  140. throw ExceptionEx.ThrowServiceException(ex);
  141. }
  142. }
  143. }
  144. /// <summary>
  145. /// 保存表单(新增、修改)
  146. /// </summary>
  147. /// <param name="keyValue">主键值</param>
  148. /// <param name="entity">实体对象</param>
  149. /// <returns></returns>
  150. public void SaveEntity(string keyValue, CrmChanceEntity entity)
  151. {
  152. try
  153. {
  154. if (!string.IsNullOrEmpty(keyValue))
  155. {
  156. entity.Modify(keyValue);
  157. this.BaseRepository().Update(entity);
  158. }
  159. else
  160. {
  161. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  162. try
  163. {
  164. entity.Create();
  165. db.Insert(entity);
  166. db.Commit();
  167. }
  168. catch (Exception)
  169. {
  170. db.Rollback();
  171. throw;
  172. }
  173. }
  174. }
  175. catch (Exception ex)
  176. {
  177. if (ex is ExceptionEx)
  178. {
  179. throw;
  180. }
  181. else
  182. {
  183. throw ExceptionEx.ThrowServiceException(ex);
  184. }
  185. }
  186. }
  187. /// <summary>
  188. /// 商机作废
  189. /// </summary>
  190. /// <param name="keyValue">主键值</param>
  191. public void Invalid(string keyValue)
  192. {
  193. try
  194. {
  195. CrmChanceEntity entity = new CrmChanceEntity();
  196. entity.Modify(keyValue);
  197. entity.F_ChanceState = 0;
  198. this.BaseRepository().Update(entity);
  199. }
  200. catch (Exception ex)
  201. {
  202. if (ex is ExceptionEx)
  203. {
  204. throw;
  205. }
  206. else
  207. {
  208. throw ExceptionEx.ThrowServiceException(ex);
  209. }
  210. }
  211. }
  212. /// <summary>
  213. /// 商机转换客户
  214. /// </summary>
  215. /// <param name="keyValue">主键</param>
  216. /// <param name="customerCode">客户编号</param>
  217. public void ToCustomer(string keyValue,string customerCode)
  218. {
  219. CrmChanceEntity chanceEntity = this.GetEntity(keyValue);
  220. IEnumerable<CrmTrailRecordEntity> trailRecordList = crmTrailRecordService.GetList(keyValue);
  221. IRepository db = new RepositoryFactory().BaseRepository().BeginTrans();
  222. try
  223. {
  224. chanceEntity.Modify(keyValue);
  225. chanceEntity.F_IsToCustom = 1;
  226. db.Update<CrmChanceEntity>(chanceEntity);
  227. CrmCustomerEntity customerEntity = new CrmCustomerEntity();
  228. customerEntity.Create();
  229. customerEntity.F_EnCode = customerCode;
  230. customerEntity.F_FullName = chanceEntity.F_CompanyName;
  231. customerEntity.F_TraceUserId = chanceEntity.F_TraceUserId;
  232. customerEntity.F_TraceUserName = chanceEntity.F_TraceUserName;
  233. customerEntity.F_CustIndustryId = chanceEntity.F_CompanyNatureId;
  234. customerEntity.F_CompanySite = chanceEntity.F_CompanySite;
  235. customerEntity.F_CompanyDesc = chanceEntity.F_CompanyDesc;
  236. customerEntity.F_CompanyAddress = chanceEntity.F_CompanyAddress;
  237. customerEntity.F_Province = chanceEntity.F_Province;
  238. customerEntity.F_City = chanceEntity.F_City;
  239. customerEntity.F_Contact = chanceEntity.F_Contacts;
  240. customerEntity.F_Mobile = chanceEntity.F_Mobile;
  241. customerEntity.F_Tel = chanceEntity.F_Tel;
  242. customerEntity.F_Fax = chanceEntity.F_Fax;
  243. customerEntity.F_QQ = chanceEntity.F_QQ;
  244. customerEntity.F_Email = chanceEntity.F_Email;
  245. customerEntity.F_Wechat = chanceEntity.F_Wechat;
  246. customerEntity.F_Hobby = chanceEntity.F_Hobby;
  247. customerEntity.F_Description = chanceEntity.F_Description;
  248. customerEntity.F_CustLevelId = "C";
  249. customerEntity.F_CustDegreeId = "往来客户";
  250. db.Insert<CrmCustomerEntity>(customerEntity);
  251. foreach (CrmTrailRecordEntity item in trailRecordList)
  252. {
  253. item.F_TrailId = Guid.NewGuid().ToString();
  254. item.F_ObjectId = customerEntity.F_CustomerId;
  255. item.F_ObjectSort = 2;
  256. db.Insert<CrmTrailRecordEntity>(item);
  257. }
  258. db.Commit();
  259. }
  260. catch (Exception ex)
  261. {
  262. db.Rollback();
  263. if (ex is ExceptionEx)
  264. {
  265. throw;
  266. }
  267. else
  268. {
  269. throw ExceptionEx.ThrowServiceException(ex);
  270. }
  271. }
  272. }
  273. #endregion
  274. }
  275. }