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.

250 lines
10 KiB

3 years ago
  1. using EasyBL.WebApi.Message;
  2. using Entity.Sugar;
  3. using Entity.ViewModels;
  4. using SqlSugar.Base;
  5. using System;
  6. using System.Linq;
  7. namespace EasyBL.WEBAPP.WSM
  8. {
  9. public class PackingOrder_UpdService : ServiceBase
  10. {
  11. #region 依據展覽獲取展覽報價規則
  12. /// <summary>
  13. /// 依據展覽獲取展覽報價規則
  14. /// </summary>
  15. /// <param name="i_crm"></param>
  16. /// <returns></returns>
  17. public ResponseMessage GetExhibitionRules(RequestMessage i_crm)
  18. {
  19. ResponseMessage rm = null;
  20. string sMsg = null;
  21. var db = SugarBase.GetIntance();
  22. try
  23. {
  24. do
  25. {
  26. var iId = _fetchInt(i_crm, "Id");
  27. var oRules = db.Queryable<CusExhibitionRules, OTB_OPM_Exhibition>((t1, t2) => t1.Guid == t2.CostRulesId)
  28. .Where((t1, t2) => t2.SN == iId)
  29. .Select((t1, t2) => new CusExhibitionRules
  30. {
  31. Guid = t1.Guid,
  32. Title = t1.Title,
  33. ExhibitionCode = t2.ExhibitionCode,
  34. CostRules = t1.CostRules,
  35. PackingPrice = t1.PackingPrice,
  36. FeedingPrice = t1.FeedingPrice,
  37. StoragePrice = t1.StoragePrice,
  38. CostInstruction = t1.CostInstruction,
  39. Currency = t1.Currency,
  40. }).Single();
  41. rm = new SuccessResponseMessage(null, i_crm);
  42. rm.DATA.Add(BLWording.REL, oRules);
  43. } while (false);
  44. }
  45. catch (Exception ex)
  46. {
  47. sMsg = Util.GetLastExceptionMsg(ex);
  48. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.WSM.PackingOrder_UpdService", "", "GetExhibitionRules(依據展覽獲取展覽報價規則)", "", "", "");
  49. }
  50. finally
  51. {
  52. if (null != sMsg)
  53. {
  54. rm = new ErrorResponseMessage(sMsg, i_crm);
  55. }
  56. }
  57. return rm;
  58. }
  59. #endregion 依據展覽獲取展覽報價規則
  60. #region 設置匯入廠商下拉單
  61. /// <summary>
  62. /// 設置匯入廠商下拉單
  63. /// </summary>
  64. /// <param name="i_crm"></param>
  65. /// <returns></returns>
  66. public ResponseMessage SetImpCusDrop(RequestMessage i_crm)
  67. {
  68. ResponseMessage rm = null;
  69. string sMsg = null;
  70. var db = SugarBase.GetIntance();
  71. try
  72. {
  73. do
  74. {
  75. var sId = _fetchString(i_crm, "Id");
  76. //var saImportCustomers = db.Queryable<OTB_CRM_ImportCustomers>()
  77. // .Select(x => new { x.guid, x.CustomerCName, x.ExhibitionNO })
  78. // .Where(x => x.ExhibitionNO == iId).ToList();
  79. var saImportCustomers = db.Queryable<OTB_OPM_ExhibitionCustomers, OTB_CRM_Customers>(
  80. (t1, t2) => t1.CustomerId == t2.guid
  81. )
  82. .Select((t1,t2) => new { t2.guid, t2.CustomerCName, t1.ExhibitionNO })
  83. .Where(t1 => t1.ExhibitionNO == sId).ToList();
  84. rm = new SuccessResponseMessage(null, i_crm);
  85. rm.DATA.Add(BLWording.REL, saImportCustomers);
  86. } while (false);
  87. }
  88. catch (Exception ex)
  89. {
  90. sMsg = Util.GetLastExceptionMsg(ex);
  91. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.WSM.PackingOrder_UpdService", "", "SetImpCusDrop(設置匯入廠商下拉單)", "", "", "");
  92. }
  93. finally
  94. {
  95. if (null != sMsg)
  96. {
  97. rm = new ErrorResponseMessage(sMsg, i_crm);
  98. }
  99. }
  100. return rm;
  101. }
  102. #endregion 設置匯入廠商下拉單
  103. #region 獲取匯入廠商資料
  104. /// <summary>
  105. /// 獲取匯入廠商資料
  106. /// </summary>
  107. /// <param name="i_crm"></param>
  108. /// <returns></returns>
  109. public ResponseMessage GetImpCusData(RequestMessage i_crm)
  110. {
  111. ResponseMessage rm = null;
  112. string sMsg = null;
  113. var db = SugarBase.GetIntance();
  114. try
  115. {
  116. do
  117. {
  118. var sId = _fetchString(i_crm, "Id");
  119. var sExhibitionNO = _fetchString(i_crm, "ExhibitionNO");
  120. //var oImportCustomers = db.Queryable<OTB_CRM_ImportCustomers>().Single(x => x.OrgID == i_crm.ORIGID && x.guid == sId);
  121. var oExhibitionCustomers = db.Queryable<OTB_OPM_ExhibitionCustomers, OTB_CRM_Customers>(
  122. (t1, t2) => t1.CustomerId == t2.guid
  123. )
  124. .Select((t1, t2) => new { t1.ExhibitionNO, t1.BoothNumber, t1.CustomerId, t2.UniCode, Contactor = "", t2.Email, t2.Telephone, t2.EXT })
  125. .Where(t1 => t1.ExhibitionNO == sExhibitionNO && t1.CustomerId == sId).Single();
  126. View_CRM_ImportCustomers oImportCustomers = new View_CRM_ImportCustomers();
  127. oImportCustomers.MuseumMumber = oExhibitionCustomers.BoothNumber;
  128. oImportCustomers.UniCode = oExhibitionCustomers.UniCode;
  129. oImportCustomers.Contactor = "";
  130. oImportCustomers.Email = "";
  131. oImportCustomers.Telephone = "";
  132. oImportCustomers.Ext = "";
  133. if (oExhibitionCustomers != null)
  134. {
  135. var listContactor = db.Queryable<OTB_OPM_ExhibitionContactors, OTB_CRM_Contactors>((t1, t2) => t1.ContactorId==t2.guid)
  136. .Select((t1, t2) => new { t1.ExhibitionNO, t1.CustomerId, t2.ContactorName, t2.Email1, t2.Telephone1, t2.Ext1, t1.IsMain, t2.OrderByValue }).MergeTable()
  137. .Where(t1 => t1.ExhibitionNO == sExhibitionNO && t1.CustomerId == sId).OrderBy("OrderByValue").ToList();
  138. if (listContactor.Count > 0)
  139. {
  140. var listMain = listContactor.Where(t => t.IsMain == "Y").ToList();
  141. if (listMain.Count == 0)
  142. {
  143. listMain = listContactor;
  144. }
  145. oImportCustomers.Contactor = listMain[0].ContactorName;
  146. oImportCustomers.Email = listMain[0].Email1;
  147. oImportCustomers.Telephone = listMain[0].Telephone1;
  148. oImportCustomers.Ext = listMain[0].Ext1;
  149. }
  150. }
  151. rm = new SuccessResponseMessage(null, i_crm);
  152. rm.DATA.Add(BLWording.REL, oImportCustomers);
  153. } while (false);
  154. }
  155. catch (Exception ex)
  156. {
  157. sMsg = Util.GetLastExceptionMsg(ex);
  158. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.WSM.PackingOrder_UpdService", "", "GetImpCusData(獲取匯入廠商資料)", "", "", "");
  159. }
  160. finally
  161. {
  162. if (null != sMsg)
  163. {
  164. rm = new ErrorResponseMessage(sMsg, i_crm);
  165. }
  166. }
  167. return rm;
  168. }
  169. #endregion 獲取匯入廠商資料
  170. #region 對應匯入廠商
  171. /// <summary>
  172. /// 對應匯入廠商
  173. /// </summary>
  174. /// <param name="i_crm"></param>
  175. /// <returns></returns>
  176. public ResponseMessage CorrespondImpCus(RequestMessage i_crm)
  177. {
  178. ResponseMessage rm = null;
  179. string sMsg = null;
  180. var db = SugarBase.GetIntance();
  181. try
  182. {
  183. do
  184. {
  185. var sId = _fetchString(i_crm, "Id");
  186. var sCustomerId = _fetchString(i_crm, "CustomerId");
  187. //var oImportCustomers = db.Queryable<OTB_CRM_ImportCustomers>().Single(x => x.OrgID == i_crm.ORIGID && x.guid == sCustomerId);
  188. var oImportCustomers = db.Queryable<OTB_CRM_Customers>().Single(x => x.guid == sCustomerId);
  189. var iRel = db.Updateable(
  190. new OTB_WSM_PackingOrder
  191. {
  192. CustomerId = sCustomerId,
  193. CompName = oImportCustomers.CustomerCName,
  194. Unicode = oImportCustomers.UniCode
  195. }
  196. )
  197. .UpdateColumns(x => new { x.CustomerId, x.CompName })
  198. .Where(x => x.OrgID == i_crm.ORIGID && x.AppointNO == sId).ExecuteCommand();
  199. rm = new SuccessResponseMessage(null, i_crm);
  200. rm.DATA.Add(BLWording.REL, iRel > 0 ? true : false);
  201. } while (false);
  202. }
  203. catch (Exception ex)
  204. {
  205. sMsg = Util.GetLastExceptionMsg(ex);
  206. LogAndSendEmail(sMsg + "Params:" + JsonToString(i_crm), ex, i_crm.ORIGID, i_crm.USERID, "EasyBL.WEBAPP.WSM.PackingOrder_UpdService", "", "CorrespondImpCus(對應匯入廠商)", "", "", "");
  207. }
  208. finally
  209. {
  210. if (null != sMsg)
  211. {
  212. rm = new ErrorResponseMessage(sMsg, i_crm);
  213. }
  214. }
  215. return rm;
  216. }
  217. #endregion 對應匯入廠商
  218. }
  219. public class CusExhibitionRules : OTB_WSM_ExhibitionRules
  220. {
  221. public CusExhibitionRules()
  222. {
  223. ExhibitionCode = "";
  224. }
  225. public string ExhibitionCode { get; set; }
  226. }
  227. }