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.

666 lines
33 KiB

1 year ago
  1. using Common;
  2. using Common.Helper;
  3. using Common.JsonFileParsing;
  4. using Common.Language;
  5. using Common.Model.AutoRefund;
  6. using Common.Model.PowerCall;
  7. using log4net;
  8. using Newtonsoft.Json;
  9. using PushNotification;
  10. using Repository.PowerCallRepository;
  11. using System;
  12. using System.Collections.Generic;
  13. using System.Data;
  14. using System.Linq;
  15. using System.Reflection;
  16. using System.Threading.Tasks;
  17. namespace Business.PowerCall
  18. {
  19. public class PowerCallBusiness : IPowerCallBusiness
  20. {
  21. private static readonly ILog Log = LogManager.GetLogger(typeof(PowerCallBusiness));
  22. private readonly IPowerCallRepository _repoPowerCall;
  23. private readonly string branch_id = ApplicationConfig.ReadWebConfig("BRANCH_ID", "");
  24. private readonly string branch_pwd = ApplicationConfig.ReadWebConfig("BRANCH_PWD", "");
  25. private readonly string powercall_key = ApplicationConfig.ReadWebConfig("POWER_CALL_KEY", "");
  26. public PowerCallBusiness(IPowerCallRepository requestPowerCall)
  27. {
  28. _repoPowerCall = requestPowerCall;
  29. }
  30. public JsonRxResponse GetChargeHistory(PowerCallInfo.GetPowerCallChargeHistory getHistory)
  31. {
  32. JsonRxResponse res = new JsonRxResponse();
  33. List<PowerCallInfo.UserChargeInfos> userInfos = new List<PowerCallInfo.UserChargeInfos>();
  34. DataTable dts = _repoPowerCall.GetUserChageInfo(getHistory.CustomerId, getHistory.FromDate, getHistory.ToDate);
  35. if (dts == null || dts.Rows.Count <= 0)
  36. {
  37. res.ErrorCode = "0";
  38. res.Msg = "Not Charge Histories";
  39. res.Data = userInfos.ToArray();
  40. return res;
  41. }
  42. foreach (DataRow row in dts.Rows)
  43. {
  44. PowerCallInfo.UserChargeInfos info = new PowerCallInfo.UserChargeInfos();
  45. var request = row["request"].ToString();
  46. var errorMsg = row["errorMessage"].ToString();
  47. var errorCode = row["errorCode"].ToString();
  48. var requestTime = row["requestTime"].ToString();
  49. var controllNo = row["orderId"].ToString();
  50. int splitIndex = controllNo.IndexOf("_");
  51. controllNo = controllNo.Remove(0, splitIndex + 1);
  52. var parse = JsonConvert.DeserializeObject<PowerCallInfo.BuyItem>(request);
  53. switch (Convert.ToInt32(parse.BuyType))
  54. {
  55. case (int)PowerCallInfo.CARD_LIST_TYPE.MANGO_INTERNATIONAL_PHONE_CHARGE:
  56. info.ChargeType = "MANGO CHARGE";
  57. break;
  58. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_NOMAL_CHARGE:
  59. info.ChargeType = "NOMAL CHARGE";
  60. break;
  61. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_MONTH:
  62. info.ChargeType = "MONTH CHARGE";
  63. break;
  64. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_DATA:
  65. info.ChargeType = "DATA CHARGE";
  66. break;
  67. }
  68. info.ProductPrice = parse.ProductPrice;
  69. info.PhoneNo = parse.PhoneNo;
  70. info.Status = errorCode;
  71. info.ErrorMsg = errorMsg;
  72. info.CardName = parse.CardName;
  73. info.RequestTime = requestTime;
  74. info.ControllNo = controllNo;
  75. userInfos.Add(info);
  76. }
  77. res.ErrorCode = "0";
  78. res.Msg = "SUCCESS";
  79. res.Data = userInfos;
  80. return res;
  81. }
  82. public JsonRxResponse CallBackPowerCall(string callBack)
  83. {
  84. JsonRxResponse res = new JsonRxResponse();
  85. Log.Debug(callBack);
  86. var callBackRes = JsonConvert.DeserializeObject<PowerCallInfo.callbackJson>(callBack);
  87. var chargeInfo = JsonConvert.DeserializeObject<PowerCallInfo.BuyItem>(_repoPowerCall.GetChargeInfo(callBackRes.sale_no));
  88. string fcmId = _repoPowerCall.GetFcmId(chargeInfo.CustomerId);
  89. var processId = _repoPowerCall.GetProcessId(callBackRes.sale_no);
  90. string chargeString = "charge_success";
  91. KJAutoRefundModel model = new KJAutoRefundModel()
  92. {
  93. customerId = chargeInfo.CustomerId,
  94. amount = chargeInfo.UseBalancePrice,
  95. action = "REQ",
  96. customerSummary = processId,
  97. bankAccountNo = "null",
  98. bankCode = "null",
  99. actionBy = "",
  100. actionDate = "",
  101. rowId = "",
  102. };
  103. string restoreMoney = model.amount;
  104. string mainCategory = null;
  105. bool isNomal = false;
  106. switch (Convert.ToInt32(chargeInfo.BuyType))
  107. {
  108. case (int)PowerCallInfo.CARD_LIST_TYPE.MANGO_INTERNATIONAL_PHONE_CHARGE:
  109. break;
  110. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_DATA:
  111. mainCategory = "Date";
  112. break;
  113. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_NOMAL_CHARGE:
  114. mainCategory = "Nomal";
  115. chargeInfo.ChargeType = "Nomal";
  116. isNomal = true;
  117. break;
  118. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_MONTH:
  119. mainCategory = "Month";
  120. break;
  121. }
  122. var commision = _repoPowerCall.GetCommision(mainCategory, chargeInfo.ChargeType);
  123. if (callBackRes.result.Equals("0000") == false)
  124. {
  125. var errorDic = JsonFileParsing.Deserialize<Dictionary<string, string>>("powerCallErrorCode");
  126. string errorMsg = null;
  127. errorDic.TryGetValue(callBackRes.cause, out errorMsg);
  128. res.ErrorCode = "1";
  129. res.Msg = errorMsg == null ? callBackRes.cause : errorMsg;
  130. res.Data = callBackRes;
  131. chargeString = "charge_fail";
  132. model.action = "FAIL";
  133. if (callBackRes.result.Equals("1000") == true)
  134. {
  135. if (Convert.ToInt32(chargeInfo.BuyType) == (int)PowerCallInfo.CARD_LIST_TYPE.PPS_NOMAL_CHARGE)
  136. {
  137. var convertSuccess_cnt = Convert.ToInt32(callBackRes.success_cnt);
  138. var convertPrice = convertSuccess_cnt * 10000;
  139. model.amount = convertPrice.ToString();
  140. restoreMoney = (Convert.ToInt32(chargeInfo.UseBalancePrice) - convertPrice).ToString();
  141. res.ErrorCode = "0";
  142. chargeString = "charge_success";
  143. res.Msg += "Charge Amount:" + convertPrice;
  144. var convertComission = Convert.ToDouble(commision);
  145. convertComission = convertComission * convertSuccess_cnt;
  146. commision = convertComission.ToString();
  147. model.action = "SUCCESS";
  148. var restoreWallet = _repoPowerCall.ReStoreWallet(model, restoreMoney, commision, chargeInfo.PhoneNo);
  149. if (restoreWallet.ResponseCode == "1")
  150. {
  151. res.Msg = restoreWallet.Msg;
  152. _repoPowerCall.CallBackPowerCallHistory(callBackRes.sale_no, res.ErrorCode, res.Msg, JsonConvert.SerializeObject(res.Data));
  153. Task.Run(() => FcmNotifier.Notify(fcmId, Languages.GetMessage(chargeString, "en"), Languages.GetTitle("Charge", "en"), false, new { destination = "RechargeHistory" }));
  154. return res;
  155. }
  156. _repoPowerCall.CallBackPowerCallHistory(callBackRes.sale_no, res.ErrorCode, res.Msg, JsonConvert.SerializeObject(res.Data));
  157. Task.Run(() => FcmNotifier.Notify(fcmId, Languages.GetMessage(chargeString, "en"), Languages.GetTitle("Charge", "en"), false, new { destination = "RechargeHistory" }));
  158. return res;
  159. }
  160. }
  161. var Fail = _repoPowerCall.FailWallet(model);
  162. if (Fail.ResponseCode == "1")
  163. {
  164. res.Msg = Fail.Msg;
  165. _repoPowerCall.CallBackPowerCallHistory(callBackRes.sale_no, res.ErrorCode, res.Msg, JsonConvert.SerializeObject(res.Data));
  166. Task.Run(() => FcmNotifier.Notify(fcmId, Languages.GetMessage(chargeString, "en"), Languages.GetTitle("Charge", "en"), false, new { destination = "RechargeHistory" }));
  167. return res;
  168. }
  169. _repoPowerCall.CallBackPowerCallHistory(callBackRes.sale_no, res.ErrorCode, res.Msg, JsonConvert.SerializeObject(res.Data));
  170. Task.Run(() => FcmNotifier.Notify(fcmId, Languages.GetMessage(chargeString, "en"), Languages.GetTitle("Charge", "en"), false, new { destination = "RechargeHistory" }));
  171. return res;
  172. }
  173. if (isNomal)
  174. {
  175. var convertPrice = Convert.ToInt32(chargeInfo.ProductPrice);
  176. var cardCnt = convertPrice / 10000;
  177. var convertComission = Convert.ToDouble(commision);
  178. convertComission = convertComission * cardCnt;
  179. commision = convertComission.ToString();
  180. }
  181. res.ErrorCode = "0";
  182. res.Msg = "Success";
  183. res.Data = callBackRes;
  184. _repoPowerCall.ResultWallet(model, commision, chargeInfo.PhoneNo);
  185. _repoPowerCall.CallBackPowerCallHistory(callBackRes.sale_no, res.ErrorCode, res.Msg, JsonConvert.SerializeObject(res.Data));
  186. Task.Run(() => FcmNotifier.Notify(fcmId, Languages.GetMessage(chargeString, "en"), Languages.GetTitle("Charge", "en"), false, new { destination = "RechargeHistory" }));
  187. return res;
  188. }
  189. public JsonRxResponse GetCardInfo(PowerCallInfo.GetCardInfo getCardInfo)
  190. {
  191. PowerCallPostGet requestPowerCall = new PowerCallPostGet();
  192. JsonRxResponse res = new JsonRxResponse();
  193. string url = null;
  194. var getCardType = Convert.ToInt32(getCardInfo.GetcardType);
  195. var cardTypeInfos = new List<PowerCallInfo.CardTypeInfo>();
  196. PowerCallInfo.cardListResult cardResult = null;
  197. var chargeState = _repoPowerCall.GetPowerCallHistory(getCardInfo.CustomerId);
  198. if (chargeState != null && chargeState["errorCode"].ToString() == "5")
  199. {
  200. res.ErrorCode = chargeState["errorCode"].ToString();
  201. res.Msg = chargeState["errorMessage"].ToString();
  202. res.Data = cardResult;
  203. return res;
  204. }
  205. if (getCardType == (int)PowerCallInfo.CARD_LIST_TYPE.PPS_MONTH)
  206. {
  207. PowerCallInfo.PlanInfo planInfoJson = null;
  208. var phoneNo = Crypto.Encrypt128(getCardInfo.PhoneNo, powercall_key);
  209. url = $@"/flatCheck/all?phone_no={phoneNo}&agent_code={branch_id}";
  210. var respones = requestPowerCall.GetFromPowerCAll(url);
  211. var monthInfo = JsonConvert.DeserializeObject<PowerCallInfo.JoinMonthInfo>(respones);
  212. if (monthInfo.result.Equals("0000"))
  213. {
  214. /// PowerCALL API 로 호출 되는 타입이 일정치 않아서, PlanInfo Json 형태로 변경 (josn string 형태가 아니면
  215. /// null로 전달)
  216. try
  217. {
  218. planInfoJson = JsonConvert.DeserializeObject<PowerCallInfo.PlanInfo>(monthInfo.plan_info);
  219. }
  220. catch
  221. {
  222. planInfoJson = null;
  223. }
  224. var removeCardNameIndex = monthInfo.card_name.IndexOf('(');
  225. PowerCallInfo.CardTypeInfo cardInfo = new PowerCallInfo.CardTypeInfo();
  226. cardInfo.CardName = monthInfo.card_name.Remove(removeCardNameIndex);
  227. cardInfo.CardCode = null;
  228. cardInfo.FacePrice = null;
  229. cardInfo.Promotion_price = null;
  230. cardInfo.SubInfo = new PowerCallInfo.ProductListInfo[] {
  231. new PowerCallInfo.ProductListInfo()
  232. {
  233. Card_name = monthInfo.card_name,
  234. Card_type = monthInfo.card_type,
  235. Face_price = monthInfo.face_price,
  236. Sale_price = monthInfo.sale_price,
  237. Mvno_code = monthInfo.mvno_info.mvno_code.ToString(),
  238. Plan_info = planInfoJson,
  239. Telecom_code = monthInfo.telecom_code,
  240. }
  241. };
  242. cardResult = new PowerCallInfo.cardListResult()
  243. {
  244. CardListType = getCardInfo.GetcardType,
  245. ButtonsGrid = null,
  246. CountryPriceCode = null,
  247. CardInfo = new PowerCallInfo.CardTypeInfo[] { cardInfo }
  248. };
  249. Log.Debug(JsonConvert.SerializeObject(respones));
  250. res.ErrorCode = "0";
  251. res.Msg = "Success";
  252. res.Data = cardResult;
  253. return res;
  254. }
  255. url = $@"/getFlatProductList?agent_code={branch_id}";
  256. respones = requestPowerCall.GetFromPowerCAll(url);
  257. var getShopItems = JsonConvert.DeserializeObject<PowerCallInfo.NotJoinMonthInfo>(respones);
  258. var itemGroups = getShopItems.product_list.GroupBy(i => i.Mvno_code).ToArray();
  259. List<PowerCallInfo.CardTypeInfo> typeInfos = new List<PowerCallInfo.CardTypeInfo>();
  260. foreach (var itemGroup in itemGroups)
  261. {
  262. /// PowerCALL API 로 호출 되는 타입이 일정치 않아서, PlanInfo Json 형태로 변경 (josn string 형태가 아니면
  263. /// null로 전달)
  264. List<PowerCallInfo.ProductListInfo> product_list = new List<PowerCallInfo.ProductListInfo>();
  265. foreach (var jsonparse in itemGroup)
  266. {
  267. try
  268. {
  269. planInfoJson = JsonConvert.DeserializeObject<PowerCallInfo.PlanInfo>(jsonparse.Plan_info);
  270. }
  271. catch
  272. {
  273. planInfoJson = null;
  274. }
  275. product_list.Add(new PowerCallInfo.ProductListInfo()
  276. {
  277. Card_name = jsonparse.Card_name,
  278. Card_type = jsonparse.Card_type,
  279. Face_price = jsonparse.Face_price,
  280. Mvno_code = jsonparse.Mvno_code,
  281. Plan_info = planInfoJson,
  282. Product_name = jsonparse.Product_name,
  283. Product_type = jsonparse.Product_type,
  284. Sale_price = jsonparse.Sale_price,
  285. Telecom_code = jsonparse.Telecom_code
  286. });
  287. }
  288. var getKey = itemGroup.Key;
  289. var card_name = itemGroup.Select(i => i.Card_name).FirstOrDefault();
  290. PowerCallInfo.CardTypeInfo cardInfo = new PowerCallInfo.CardTypeInfo();
  291. var removeIndexStr = card_name.IndexOf('(');
  292. cardInfo.CardName = card_name.Remove(removeIndexStr);
  293. cardInfo.Promotion_price = null;
  294. cardInfo.CardCode = null;
  295. cardInfo.SubInfo = product_list.ToArray();
  296. typeInfos.Add(cardInfo);
  297. }
  298. cardResult = new PowerCallInfo.cardListResult()
  299. {
  300. CardListType = getCardInfo.GetcardType,
  301. ButtonsGrid = null,
  302. CountryPriceCode = null,
  303. CardInfo = typeInfos.ToArray()
  304. };
  305. Log.Debug(JsonConvert.SerializeObject(respones));
  306. }
  307. else if (getCardType == (int)PowerCallInfo.CARD_LIST_TYPE.MANGO_INTERNATIONAL_PHONE_CHARGE)
  308. {
  309. var user_id = Crypto.Encrypt128(branch_id, powercall_key);
  310. var user_pwd = Crypto.Encrypt128(branch_pwd, powercall_key);
  311. var phoneNo = Crypto.Encrypt128(getCardInfo.PhoneNo, powercall_key);
  312. url = $@"/mangoCustInfo?user_id={user_id}&user_pwd={user_pwd}&phone_no={phoneNo}&agent_code={branch_id}";
  313. var respones = requestPowerCall.GetFromPowerCAll(url);
  314. Log.Debug(JsonConvert.SerializeObject(respones));
  315. var parseResnpones = JsonConvert.DeserializeObject<PowerCallInfo.MangoJoinUser>(respones);
  316. if (parseResnpones == null || parseResnpones.result.Equals("9999"))
  317. {
  318. res.ErrorCode = "1";
  319. res.Msg = "Not Join Mango";
  320. res.Data = null;
  321. return res;
  322. }
  323. PowerCallInfo.StaticPrice getButton = JsonFileParsing.Deserialize<PowerCallInfo.StaticPrice>();
  324. if (getButton == null)
  325. {
  326. res.ErrorCode = "1";
  327. res.Msg = "invaild Table Button";
  328. res.Data = null;
  329. return res;
  330. }
  331. var codePrice = JsonFileParsing.Deserialize<PowerCallInfo.CountryPriceCode>();
  332. if (codePrice == null)
  333. {
  334. res.ErrorCode = "1";
  335. res.Msg = "invaild Table codePrice";
  336. res.Data = null;
  337. return res;
  338. }
  339. PowerCallInfo.CardTypeInfo cardInfo = new PowerCallInfo.CardTypeInfo();
  340. cardInfo.CardCode = "MANGO_001";
  341. cardInfo.CardName = "MANGO_CARD";
  342. cardInfo.SubInfo = null;
  343. cardTypeInfos.Add(cardInfo);
  344. cardResult = new PowerCallInfo.cardListResult()
  345. {
  346. CardListType = getCardInfo.GetcardType,
  347. ButtonsGrid = getButton.ButtonPriceType.NomalGirld,
  348. CountryPriceCode = codePrice.countryPriceCode.ToArray(),
  349. CardInfo = cardTypeInfos.ToArray()
  350. };
  351. }
  352. else if (getCardType == (int)PowerCallInfo.CARD_LIST_TYPE.PPS_NOMAL_CHARGE)
  353. {
  354. PowerCallInfo.ButtonType[] getButtonGrid = null;
  355. res = new JsonRxResponse();
  356. var getButton = JsonFileParsing.Deserialize<PowerCallInfo.StaticPrice>();
  357. if (getButton == null)
  358. {
  359. res.ErrorCode = "1";
  360. res.Msg = "invaild Table Button";
  361. res.Data = null;
  362. return res;
  363. }
  364. getButtonGrid = getButton.ButtonPriceType.NomalGirld.ToArray();
  365. cardResult = new PowerCallInfo.cardListResult()
  366. {
  367. CardListType = getCardInfo.GetcardType,
  368. ButtonsGrid = getButtonGrid,
  369. CountryPriceCode = null,
  370. CardInfo = null,
  371. };
  372. }
  373. else
  374. {
  375. var user_id = Crypto.Encrypt128(branch_id, powercall_key);
  376. var user_pwd = Crypto.Encrypt128(branch_pwd, powercall_key);
  377. var card_type = Crypto.Encrypt128(getCardInfo.GetcardType, powercall_key);
  378. url = $@"/getPdsCardList?user_id={user_id}&user_pwd={user_pwd}&card_type={card_type}&agent_code={branch_id}";
  379. var respones = requestPowerCall.GetFromPowerCAll(url);
  380. Log.Debug(JsonConvert.SerializeObject(respones));
  381. var parseRespones = JsonConvert.DeserializeObject<PowerCallInfo.GetGetCardByPowerCall[]>(respones);
  382. if (parseRespones == null || parseRespones.Count() == 0)
  383. {
  384. res.ErrorCode = "1";
  385. res.Msg = "Invaild Info CardList";
  386. res.Data = null;
  387. return res;
  388. }
  389. var enableItems = parseRespones.Where(i => i.ct_enable == "Y").ToArray();
  390. foreach (var enableItem in enableItems)
  391. {
  392. PowerCallInfo.CardTypeInfo cardInfo = new PowerCallInfo.CardTypeInfo();
  393. cardInfo.CardName = enableItem.ct_card_name;
  394. cardInfo.CardCode = enableItem.ct_card_type;
  395. cardInfo.FacePrice = enableItem.ct_face_price.ToString();
  396. cardInfo.Promotion_price = enableItem.ct_promotion.ToString();
  397. cardInfo.SubInfo = null;
  398. cardTypeInfos.Add(cardInfo);
  399. }
  400. cardResult = new PowerCallInfo.cardListResult()
  401. {
  402. CardListType = PowerCallInfo.CARD_LIST_TYPE.PPS_DATA.ToString("d"),
  403. ButtonsGrid = null,
  404. CountryPriceCode = null,
  405. CardInfo = cardTypeInfos.ToArray()
  406. };
  407. }
  408. res.ErrorCode = "0";
  409. res.Msg = "Success";
  410. res.Data = cardResult;
  411. return res;
  412. }
  413. public JsonRxResponse VerificationAndBuy(PowerCallInfo.BuyItem buyItem)
  414. {
  415. JsonRxResponse res = new JsonRxResponse();
  416. var buyType = Convert.ToInt32(buyItem.BuyType);
  417. var useBalncePrice = Convert.ToInt32(buyItem.UseBalancePrice);
  418. if ((int)PowerCallInfo.CARD_LIST_TYPE.PPS_NOMAL_CHARGE == buyType)
  419. {
  420. buyItem.ChargeType = "Nomal";
  421. }
  422. var request = _repoPowerCall.Request(buyItem.CustomerId, buyItem.BuyType, buyItem.ChargeType, buyItem.CardName, buyItem.ProductPrice, buyItem.PhoneNo, JsonConvert.SerializeObject(buyItem), MethodBase.GetCurrentMethod().Name);
  423. var powerCallRowId = Convert.ToInt64(request.Id);
  424. var orderId = request.Extra2;
  425. if (Enum.IsDefined(typeof(PowerCallInfo.CARD_LIST_TYPE), Convert.ToInt32(buyItem.BuyType)) == false)
  426. {
  427. res.ErrorCode = "1";
  428. res.Msg = "Invaild BuyType";
  429. res.Data = null;
  430. _repoPowerCall.PowerCallHistory(powerCallRowId, res.ErrorCode, res.Msg, "");
  431. return res;
  432. }
  433. if (string.IsNullOrWhiteSpace(buyItem.PhoneNo) == true || Convert.ToInt32(buyItem.UseBalancePrice) <= 0
  434. || Convert.ToInt32(buyItem.ProductPrice) <= 0 || (Convert.ToInt32(buyItem.ProductPrice) - Convert.ToInt32(buyItem.UseBalancePrice)) != 0)
  435. {
  436. res.ErrorCode = "1";
  437. res.Msg = "Invaild PhoneNo or Price";
  438. res.Data = null;
  439. _repoPowerCall.PowerCallHistory(powerCallRowId, res.ErrorCode, res.Msg, "");
  440. return res;
  441. }
  442. KJAutoRefundModel model = new KJAutoRefundModel()
  443. {
  444. flag = "useWalletMoney",
  445. customerId = buyItem.CustomerId,
  446. amount = buyItem.UseBalancePrice,
  447. action = "REQ",
  448. customerSummary = request.Extra,
  449. bankAccountNo = "null",
  450. bankCode = "null",
  451. actionBy = "",
  452. actionDate = "",
  453. };
  454. try
  455. {
  456. string commision = string.Empty;
  457. switch (buyType)
  458. {
  459. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_NOMAL_CHARGE:
  460. commision = _repoPowerCall.GetCommision("Nomal", "Nomal");
  461. break;
  462. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_DATA:
  463. commision = _repoPowerCall.GetCommision("Data", buyItem.ChargeType);
  464. break;
  465. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_MONTH:
  466. commision = _repoPowerCall.GetCommision("Month", buyItem.ChargeType);
  467. break;
  468. case (int)PowerCallInfo.CARD_LIST_TYPE.MANGO_INTERNATIONAL_PHONE_CHARGE:
  469. commision = _repoPowerCall.GetCommision("cardCailng", "cardCailng");
  470. break;
  471. }
  472. if (string.IsNullOrEmpty(commision))
  473. {
  474. res.ErrorCode = "1";
  475. res.Msg = "Not Setting CardList";
  476. res.Data = null;
  477. _repoPowerCall.PowerCallHistory(powerCallRowId, res.ErrorCode, res.Msg, "");
  478. return res;
  479. }
  480. var result = _repoPowerCall.CheckWallet(model, buyItem.PassWord);
  481. if (result.ResponseCode == "1")
  482. {
  483. res.ErrorCode = result.ResponseCode;
  484. res.Msg = result.Msg;
  485. res.Data = null;
  486. _repoPowerCall.PowerCallHistory(powerCallRowId, res.ErrorCode, res.Msg, "");
  487. return res;
  488. }
  489. _repoPowerCall.PowerCallHistory(powerCallRowId, "5", "W", "");
  490. // request 요청
  491. switch (buyType)
  492. {
  493. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_NOMAL_CHARGE:
  494. int charge_cnt = Convert.ToInt32(buyItem.ProductPrice) / 10000;
  495. res = BuyNomalCharge(charge_cnt.ToString(), "2", orderId, buyItem.PhoneNo, powerCallRowId);
  496. break;
  497. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_DATA:
  498. res = BuyDataCharge("1", buyItem.ChargeType, "2", orderId, buyItem.PhoneNo, powerCallRowId);
  499. break;
  500. case (int)PowerCallInfo.CARD_LIST_TYPE.PPS_MONTH:
  501. res = BuyMonthCharge("1", buyItem.ChargeType, "2", orderId, buyItem.PhoneNo, powerCallRowId);
  502. break;
  503. case (int)PowerCallInfo.CARD_LIST_TYPE.MANGO_INTERNATIONAL_PHONE_CHARGE:
  504. res = BuyMangoCharge(buyItem.ProductPrice, buyItem.ChargeType, orderId, buyItem.PhoneNo, powerCallRowId);
  505. break;
  506. }
  507. }
  508. catch (Exception ex) { }
  509. if (res.ErrorCode == "1")
  510. {
  511. model.action = "FAIL";
  512. _repoPowerCall.FailWallet(model);
  513. return res;
  514. }
  515. res.ErrorCode = "0";
  516. res.Msg = "Success Request";
  517. return res;
  518. }
  519. /// <summary>
  520. /// 일반 요금 충전
  521. /// </summary>
  522. /// <returns></returns>
  523. public JsonRxResponse BuyNomalCharge(string chargeCnt, string flag, string orderNo, string phoneNo, long rowId)
  524. {
  525. JsonRxResponse res = new JsonRxResponse();
  526. PowerCallPostGet requestPowerCall = new PowerCallPostGet();
  527. var user_id = Crypto.Encrypt128(branch_id, powercall_key);
  528. var user_pwd = Crypto.Encrypt128(branch_pwd, powercall_key);
  529. var charge_cnt = Crypto.Encrypt128(chargeCnt, powercall_key);
  530. var sales_no = Crypto.Encrypt128(orderNo, powercall_key);
  531. var sale_flag = Crypto.Encrypt128(flag, powercall_key);
  532. var phone_no = Crypto.Encrypt128(phoneNo, powercall_key);
  533. var url = $@"/autoCharge?user_id={user_id}&user_pwd={user_pwd}&charge_cnt={charge_cnt}&sale_no={sales_no}&sale_flag={sale_flag}&phone_no={phone_no}&agent_code={branch_id}";
  534. _repoPowerCall.PowercallLog(rowId, url);
  535. requestPowerCall.GetFromPowerCAll(url);
  536. res.ErrorCode = "5";
  537. res.Msg = "W";
  538. res.Data = null;
  539. return res;
  540. }
  541. /// <summary>
  542. /// 데이터충전
  543. /// </summary>
  544. /// <param name="chargeCnt"></param>
  545. /// <param name="flag"></param>
  546. /// <param name="orderNo"></param>
  547. /// <param name="phoneNo"></param>
  548. /// <returns></returns>
  549. public JsonRxResponse BuyDataCharge(string chargeCnt, string cardType, string flag, string orderNo, string phoneNo, long rowId)
  550. {
  551. JsonRxResponse res = new JsonRxResponse();
  552. PowerCallPostGet requestPowerCall = new PowerCallPostGet();
  553. var user_id = Crypto.Encrypt128(branch_id, powercall_key);
  554. var user_pwd = Crypto.Encrypt128(branch_pwd, powercall_key);
  555. var charge_cnt = Crypto.Encrypt128(chargeCnt.ToString(), powercall_key);
  556. var card_type = Crypto.Encrypt128(cardType, powercall_key);
  557. var sales_no = Crypto.Encrypt128(orderNo, powercall_key);
  558. var sale_flag = Crypto.Encrypt128(flag, powercall_key);
  559. var phone_no = Crypto.Encrypt128(phoneNo, powercall_key);
  560. var url = $@"/dataCharge?user_id={user_id}&user_pwd={user_pwd}&card_type={card_type}&charge_cnt={charge_cnt}&sale_no={sales_no}&sale_flag={sale_flag}&phone_no={phone_no}&agent_code={branch_id}";
  561. _repoPowerCall.PowercallLog(rowId, url);
  562. requestPowerCall.GetFromPowerCAll(url);
  563. res.ErrorCode = "5";
  564. res.Msg = "W";
  565. res.Data = null;
  566. return res;
  567. }
  568. /// <summary>
  569. /// 월충전 구매
  570. /// </summary>
  571. /// <param name="chargeCnt"></param>
  572. /// <param name="flag"></param>
  573. /// <param name="orderNo"></param>
  574. /// <param name="phoneNo"></param>
  575. /// <returns></returns>
  576. public JsonRxResponse BuyMonthCharge(string chargeCnt, string cardType, string flag, string orderNo, string phoneNo, long rowId)
  577. {
  578. JsonRxResponse res = new JsonRxResponse();
  579. PowerCallPostGet requestPowerCall = new PowerCallPostGet();
  580. var user_id = Crypto.Encrypt128(branch_id, powercall_key);
  581. var user_pwd = Crypto.Encrypt128(branch_pwd, powercall_key);
  582. var charge_cnt = Crypto.Encrypt128(chargeCnt, powercall_key);
  583. var card_type = Crypto.Encrypt128(cardType, powercall_key);
  584. var sales_no = Crypto.Encrypt128(orderNo, powercall_key);
  585. var sale_flag = Crypto.Encrypt128(flag, powercall_key);
  586. var phone_no = Crypto.Encrypt128(phoneNo, powercall_key);
  587. var url = $@"/flatCharge?user_id={user_id}&user_pwd={user_pwd}&card_type={card_type}&charge_cnt={charge_cnt}&sale_no={sales_no}&sale_flag={sale_flag}&phone_no={phone_no}&agent_code={branch_id}";
  588. _repoPowerCall.PowercallLog(rowId, url);
  589. requestPowerCall.GetFromPowerCAll(url);
  590. res.ErrorCode = "5";
  591. res.Msg = "W";
  592. res.Data = null;
  593. return res;
  594. }
  595. /// <summary>
  596. /// 망고 상품 구매
  597. /// </summary>
  598. /// <param name="chargeCnt"></param>
  599. /// <param name="flag"></param>
  600. /// <param name="orderNo"></param>
  601. /// <param name="phoneNo"></param>
  602. /// <returns></returns>
  603. public JsonRxResponse BuyMangoCharge(string price, string cardType, string orderNo, string phoneNo, long rowId)
  604. {
  605. JsonRxResponse res = new JsonRxResponse();
  606. PowerCallPostGet requestPowerCall = new PowerCallPostGet();
  607. var user_id = Crypto.Encrypt128(branch_id, powercall_key);
  608. var user_pwd = Crypto.Encrypt128(branch_pwd, powercall_key);
  609. var sale_price = Crypto.Encrypt128(price, powercall_key);
  610. var card_type = Crypto.Encrypt128(cardType, powercall_key);
  611. var sale_no = Crypto.Encrypt128(orderNo, powercall_key);
  612. var phone_no = Crypto.Encrypt128(phoneNo, powercall_key);
  613. var url = $@"/mangoCharge?user_id={user_id}&user_pwd={user_pwd}&card_type={card_type}&sale_price={sale_price}&sale_no={sale_no}&phone_no={phone_no}&agent_code={branch_id}";
  614. _repoPowerCall.PowercallLog(rowId, url);
  615. var respones = requestPowerCall.GetFromPowerCAll(url);
  616. var responesbyPowerCall = JsonConvert.DeserializeObject<PowerCallInfo.ChargePowerCall>(respones);
  617. if (responesbyPowerCall == null || responesbyPowerCall.result.Equals("0000") == false) // PowerCallInfo.cs
  618. {
  619. res.ErrorCode = "1";
  620. res.Msg = responesbyPowerCall == null ? "PowerCall Respones Null" : responesbyPowerCall.cause;
  621. res.Data = "";
  622. return res;
  623. }
  624. res.ErrorCode = "0";
  625. res.Msg = "Success";
  626. res.Data = responesbyPowerCall;
  627. return res;
  628. }
  629. }
  630. }