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.

247 lines
9.1 KiB

1 year ago
  1. using Common;
  2. using Common.Helper;
  3. using Common.Model;
  4. using Common.Model.Reward;
  5. using log4net;
  6. using Repository.Reward;
  7. using System;
  8. using System.Threading.Tasks;
  9. namespace Business.Reward
  10. {
  11. public class RewardServices : IRewardServices
  12. {
  13. private readonly IRewardRepository requestServices;
  14. private static readonly ILog Log = LogManager.GetLogger(typeof(RewardServices));
  15. public RewardServices(RewardRepository requestServices)
  16. {
  17. this.requestServices = requestServices;
  18. }
  19. JsonRxResponse IRewardServices.GetProductLists(string rooturl)
  20. {
  21. var jsonResult = requestServices.GetProductLists(rooturl);
  22. if (jsonResult.ErrorCode == "0")
  23. {
  24. Log.Debug("Get Products success.");
  25. }
  26. else
  27. {
  28. Log.Debug("Get Products failed.");
  29. }
  30. return jsonResult;
  31. }
  32. JsonRxResponse IRewardServices.BuyProduct(RequestedOrderDetail orderRequest)
  33. {
  34. JsonRxResponse jsonResult = new JsonRxResponse();
  35. var checkresult = checkBuyProduct(orderRequest);
  36. Log.Debug("[REWARD-POINT] BuyProduct : CheckResult.ErrorCode =" + checkresult.ErrorCode + ",CheckResult.Msg =" + checkresult.Msg);
  37. if (checkresult.ErrorCode == "0")
  38. {
  39. try
  40. {
  41. jsonResult = requestServices.BuyProduct(orderRequest);
  42. Log.Debug("[REWARD-POINT] BuyProduct : jsonResult.ErrorCode =" + jsonResult.ErrorCode + ",jsonResult.Msg =" + jsonResult.Msg);
  43. if (jsonResult.ErrorCode == "0")
  44. {
  45. string branchemail = jsonResult.Extra;
  46. if (string.IsNullOrEmpty(branchemail))
  47. {
  48. jsonResult.ErrorCode = "1";
  49. jsonResult.Msg = "branch email is null";
  50. jsonResult.Data = new System.Collections.ArrayList();
  51. }
  52. else
  53. {
  54. var dbvar = jsonResult.Extra2.Split(',');
  55. EmailParameters _emailParams = new EmailParameters()
  56. {
  57. To = branchemail,
  58. To_1 = GetStatic.ReadWebConfig("RewardAdminEmail", ""),
  59. MsgSubject = "Reward Product is orderd_" + DateTime.Now.ToString("yyyy-MM-dd HH:mm"),
  60. MsgBody = "Hello, Reward Product is orderd. <br>"
  61. + "Customer Id : " + orderRequest.userId + "<br> Mobile Number : " + dbvar[2] + "<br> Branch Name : " + dbvar[0] + "<br> Product : " + dbvar[1]
  62. };
  63. Task.Run(() => GetStatic.SendMultipleEmail(_emailParams));
  64. jsonResult.Extra = "";
  65. jsonResult.Extra2 = "";
  66. }
  67. }
  68. if (jsonResult.ErrorCode == "0")
  69. {
  70. Log.Debug("Buy Products success.");
  71. }
  72. else
  73. {
  74. Log.Debug("Buy Products failed.");
  75. }
  76. }
  77. catch (Exception e)
  78. {
  79. Log.DebugFormat($"Exception : {e.ToString()}");
  80. jsonResult.ErrorCode = "1";
  81. jsonResult.Msg = e.ToString();
  82. jsonResult.Data = new System.Collections.ArrayList();
  83. return jsonResult;
  84. }
  85. return jsonResult;
  86. }
  87. else
  88. {
  89. return checkresult;
  90. }
  91. }
  92. JsonRxResponse IRewardServices.OrderedProductList(RequestedOrderDetail orderRequest)
  93. {
  94. if (string.IsNullOrEmpty(orderRequest.userId))
  95. {
  96. JsonRxResponse jsonRx = new JsonRxResponse
  97. {
  98. ErrorCode = "1",
  99. Msg = "No UserId",
  100. Data = new System.Collections.ArrayList()
  101. };
  102. return jsonRx;
  103. }
  104. if (!string.IsNullOrEmpty(orderRequest.startDate) && !string.IsNullOrEmpty(orderRequest.endDate))
  105. {
  106. if (!Utilities.CheckDateType(orderRequest.startDate) || !Utilities.CheckDateType(orderRequest.endDate))
  107. {
  108. JsonRxResponse jsonRx = new JsonRxResponse
  109. {
  110. ErrorCode = "1",
  111. Msg = "No DateType",
  112. Data = new System.Collections.ArrayList()
  113. };
  114. return jsonRx;
  115. }
  116. }
  117. else
  118. {
  119. orderRequest.endDate = DateTime.Now.ToString("yyyy-MM-dd");
  120. orderRequest.startDate = DateTime.Now.AddDays(-7).ToString("yyyy-MM-dd");
  121. }
  122. var jsonResult = requestServices.OrderedProductList(orderRequest);
  123. if (jsonResult.ErrorCode == "0")
  124. {
  125. Log.Debug("Get Ordered Products list success.");
  126. }
  127. else
  128. {
  129. Log.Debug("Get Ordered Products list failed.");
  130. }
  131. return jsonResult;
  132. }
  133. JsonRxResponse IRewardServices.GetAgentInfo()
  134. {
  135. var jsonResult = requestServices.GetAgentInfo();
  136. if (jsonResult.ErrorCode == "0")
  137. {
  138. Log.Debug("Get Agent Infos success.");
  139. }
  140. else
  141. {
  142. Log.Debug("Get Agent Infos failed.");
  143. }
  144. return jsonResult;
  145. }
  146. private JsonRxResponse checkBuyProduct(RequestedOrderDetail orderRequest)
  147. {
  148. JsonRxResponse jsonRx = new JsonRxResponse();
  149. if (string.IsNullOrEmpty(orderRequest.userId))
  150. {
  151. jsonRx.ErrorCode = "1";
  152. jsonRx.Msg = "No UserId";
  153. jsonRx.Data = new System.Collections.ArrayList();
  154. return jsonRx;
  155. }
  156. if (string.IsNullOrEmpty(orderRequest.productCode))
  157. {
  158. jsonRx.ErrorCode = "1";
  159. jsonRx.Msg = "No productCode";
  160. jsonRx.Data = new System.Collections.ArrayList();
  161. return jsonRx;
  162. }
  163. if (string.IsNullOrEmpty(orderRequest.usePoint))
  164. {
  165. jsonRx.ErrorCode = "1";
  166. jsonRx.Msg = "No usePoint";
  167. jsonRx.Data = new System.Collections.ArrayList();
  168. return jsonRx;
  169. }
  170. if (orderRequest.orderType != "1" && orderRequest.orderType != "9")
  171. {
  172. jsonRx.ErrorCode = "1";
  173. jsonRx.Msg = "No orderType";
  174. jsonRx.Data = new System.Collections.ArrayList();
  175. return jsonRx;
  176. }
  177. if (orderRequest.recvType != "1" && orderRequest.recvType != "2")
  178. {
  179. jsonRx.ErrorCode = "1";
  180. jsonRx.Msg = "No recvType";
  181. jsonRx.Data = new System.Collections.ArrayList();
  182. return jsonRx;
  183. }
  184. if (orderRequest.recvType == "1")
  185. {
  186. if (string.IsNullOrEmpty(orderRequest.recvAddress))
  187. {
  188. jsonRx.ErrorCode = "1";
  189. jsonRx.Msg = "No recvAddress";
  190. jsonRx.Data = new System.Collections.ArrayList();
  191. return jsonRx;
  192. }
  193. if (string.IsNullOrEmpty(orderRequest.recvZipCode))
  194. {
  195. jsonRx.ErrorCode = "1";
  196. jsonRx.Msg = "No recvZipCode";
  197. jsonRx.Data = new System.Collections.ArrayList();
  198. return jsonRx;
  199. }
  200. if (string.IsNullOrEmpty(orderRequest.recvPhoneNumber))
  201. {
  202. jsonRx.ErrorCode = "1";
  203. jsonRx.Msg = "No recvPhoneNumber";
  204. jsonRx.Data = new System.Collections.ArrayList();
  205. return jsonRx;
  206. }
  207. if (string.IsNullOrEmpty(orderRequest.recvName))
  208. {
  209. jsonRx.ErrorCode = "1";
  210. jsonRx.Msg = "No recvName";
  211. jsonRx.Data = new System.Collections.ArrayList();
  212. return jsonRx;
  213. }
  214. }
  215. else if (orderRequest.recvType == "2")
  216. {
  217. if (string.IsNullOrEmpty(orderRequest.branchCode))
  218. {
  219. jsonRx.ErrorCode = "1";
  220. jsonRx.Msg = "No branchCode";
  221. jsonRx.Data = new System.Collections.ArrayList();
  222. return jsonRx;
  223. }
  224. }
  225. jsonRx.ErrorCode = "0";
  226. jsonRx.Msg = null;
  227. jsonRx.Data = new System.Collections.ArrayList();
  228. return jsonRx;
  229. }
  230. }
  231. }