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.
 
 
 

274 lines
12 KiB

using Common;
using Common.Helper;
using Common.Model.Config;
using Common.Model.Reward;
using log4net;
using System;
using System.Collections.Generic;
using System.Data;
using System.IO;
using System.Runtime.Remoting.Messaging;
namespace Repository.Reward
{
public class RewardRepository : IRewardRepository
{
private readonly Dao _dao = new Dao();
private static readonly ILog Log = LogManager.GetLogger(typeof(RewardRepository));
JsonRxResponse IRewardRepository.GetProductLists(string rooturl)
{
JsonRxResponse jsonRx = new JsonRxResponse();
try
{
var sql = "EXEC proc_RewardPointOperation @flag='productlist' ";
Log.Debug(sql);
var dataSet = _dao.ExecuteDataset(sql);
List<ResponsingProductsListDetail> productDetails = new List<ResponsingProductsListDetail>();
if (dataSet.Tables[0].Rows.Count == 0)
{
Log.DebugFormat("ProductList count is 0");
jsonRx.ErrorCode = "0";
jsonRx.Msg = "No Product List";
jsonRx.Data = new System.Collections.ArrayList();
return jsonRx;
}
string currentpath = AppDomain.CurrentDomain.BaseDirectory;
foreach (DataRow row in dataSet.Tables[0].Rows)
{
string imgtemppath = null, resultimgpath = null;
string ipath = row["productImgPath"].ToString();
if (File.Exists(ipath))
{
imgtemppath = ipath.Replace(currentpath, "");
resultimgpath = rooturl + "/" + imgtemppath.Replace("\\", "/");
}
productDetails.Add(new ResponsingProductsListDetail
{
productCode = row["productCode"].ToString(),
productName = row["productName"].ToString(),
pointPrice = (Convert.ToDouble(row["pointPrice"].ToString())).ToString(),
deliverYN = row["deliveryYN"].ToString(),
productImgPath = resultimgpath
});
}
jsonRx.ErrorCode = "0";
jsonRx.Msg = "Success";
jsonRx.Data = productDetails;
return jsonRx;
}
catch (Exception e)
{
Log.DebugFormat($"Exception : {e.ToString()}");
jsonRx.ErrorCode = "1";
jsonRx.Msg = "Failed";
jsonRx.Data = e.ToString();
return jsonRx;
}
}
JsonRxResponse IRewardRepository.BuyProduct(RequestedOrderDetail orderRequest)
{
JsonRxResponse jsonRx = new JsonRxResponse();
// 동대문 코드 1034
var sql = string.Format($@"EXEC proc_RewardPointOperation @flag='buyproduct',
@orderId = '{DateTime.Now.ToString("yyyyMMddHHmmssfff")}',
@email = '{orderRequest.userId}',
@branchCode = '{orderRequest.branchCode}',
@productCode = '{orderRequest.productCode}',
@recvType = '{orderRequest.recvType}',
@recvAddress = '{orderRequest.recvAddress}',
@recvZipCode = '{orderRequest.recvZipCode}',
@recvPhoneNumber = '{orderRequest.recvPhoneNumber}',
@recvName = '{orderRequest.recvName}',
@orderType = '{orderRequest.orderType}'
").Replace("\r\n", string.Empty);
Log.Debug(sql);
var dbdataset = _dao.ExecuteDataset(sql);
if (dbdataset.Tables.Count == 0)
{
Log.DebugFormat("[REWARD-POINT] proc_RewardPointOperation fail");
jsonRx.ErrorCode = "1";
jsonRx.Msg = "[REWARD-POINT] Please contact GME";
return jsonRx;
}
var dbresult = _dao.ParseDbResult(dbdataset.Tables[0]);
string branchemail = null, branchname = null, productname = null, mobile = null;
if (dbdataset.Tables.Count >= 2)
{
foreach (DataRow row in dbdataset.Tables[1].Rows)
{
branchemail = row["agentEmail1"].ToString();
branchname = row["agentName"].ToString();
productname = row["productname"].ToString();
mobile = row["mobile"].ToString();
}
}
jsonRx.ErrorCode = dbresult.ResponseCode;
jsonRx.Msg = dbresult.Msg;
jsonRx.Data = new System.Collections.ArrayList();
jsonRx.Extra = branchemail;
jsonRx.Extra2 = branchname + "," + productname + "," + mobile;
return jsonRx;
}
JsonRxResponse IRewardRepository.OrderedProductList(RequestedOrderDetail orderRequest)
{
JsonRxResponse jsonRx = new JsonRxResponse();
try
{
var sql = string.Format($@"EXEC proc_RewardPointOperation @flag='orderedlist',
@email = '{orderRequest.userId}',
@startDate = '{orderRequest.startDate}',
@endDate = '{orderRequest.endDate}'
").Replace("\r\n", string.Empty);
Log.Debug(sql);
var dataSet = _dao.ExecuteDataset(sql);
var dbresult = _dao.ParseDbResult(dataSet.Tables[0]);
if (dbresult.ResponseCode == "0")
{
List<RequestedProductDetail> orderProductDetail = new List<RequestedProductDetail>();
if (dataSet.Tables[1].Rows.Count == 0)
{
Log.DebugFormat("Orderd List count is 0");
jsonRx.ErrorCode = "0";
jsonRx.Msg = "Orderd List count is 0";
jsonRx.Data = new System.Collections.ArrayList();
return jsonRx;
}
foreach (DataRow row in dataSet.Tables[1].Rows)
{
orderProductDetail.Add(new RequestedProductDetail
{
orderId = row["orderId"].ToString(),
productCode = row["productCode"].ToString(),
productName = row["productName"].ToString(),
usePoint = (Convert.ToDouble(row["usePoint"].ToString())).ToString(),
orderType = row["orderType"].ToString(),
recvType = row["recvType"].ToString(),
branchCode = row["branchCode"].ToString(),
branchName = row["agentName"].ToString(),
recvAddress = row["recvAddress"].ToString(),
recvZipCode = row["recvZipCode"].ToString(),
recvPhoneNumber = row["recvPhoneNumber"].ToString(),
recvName = row["recvName"].ToString(),
orderStatus = row["orderStatus"].ToString(),
createdDate = row["createdDate"].ToString(),
modifiedDate = row["modifiedDate"].ToString(),
recvDate = row["recvDate"].ToString()
});
}
jsonRx.ErrorCode = "0";
jsonRx.Msg = "Success";
jsonRx.Data = orderProductDetail;
return jsonRx;
}
else
{
return new JsonRxResponse { ErrorCode = dbresult.ResponseCode, Msg = dbresult.Msg };
}
}
catch (Exception e)
{
Log.DebugFormat($"Exception : {e.ToString()}");
jsonRx.ErrorCode = "1";
jsonRx.Msg = "Failed";
jsonRx.Data = e.ToString();
return jsonRx;
}
}
JsonRxResponse IRewardRepository.GetAgentInfo()
{
var lang = Convert.ToString(CallContext.GetData(Constants.Language));
JsonRxResponse jsonRx = new JsonRxResponse();
try
{
var sql = string.Format($@"EXEC mobile_proc_userLogin @flag = 'agentDetail'").Replace("\r\n", string.Empty);
Log.Debug(sql);
var dataSet = _dao.ExecuteDataset(sql);
List<ResponsingAgentDetail> agentList = new List<ResponsingAgentDetail>();
if (dataSet.Tables[0].Rows.Count == 0)
{
Log.DebugFormat("Agent List count is 0");
jsonRx.ErrorCode = "0";
jsonRx.Msg = "Agent List count is 0";
jsonRx.Data = new System.Collections.ArrayList();
return jsonRx;
}
foreach (DataRow row in dataSet.Tables[0].Rows)
{
agentList.Add(new ResponsingAgentDetail
{
agentId = row["agentId"].ToString(),
agentName = row["agentName"].ToString(),
agentState = row["agentState"].ToString(),
agentCity = row["agentCity"].ToString(),
agentAddress = row["agentAddress"].ToString(),
agentZip = row["agentZip"].ToString(),
agentPhone1 = row["agentPhone1"].ToString()
});
}
var map = Utilities.GetLanguageMapping(RESPONSE_MSG.GET_BRANCH_INFOS_SUCCESS.ToString(), lang);
jsonRx.ErrorCode = "0";
jsonRx.Msg = map.Message;
jsonRx.Data = agentList;
return jsonRx;
}
catch (Exception e)
{
var map = Utilities.GetLanguageMapping(RESPONSE_MSG.GET_BRANCH_INFOS_FAIL.ToString(), lang);
Log.DebugFormat($"Exception : {e.ToString()}");
jsonRx.ErrorCode = "1";
jsonRx.Msg = map.Message;
jsonRx.Data = e.ToString();
return jsonRx;
}
}
string IRewardRepository.GetExpectedReward(string customerId, string tranId)
{
JsonRxResponse jsonRx = new JsonRxResponse();
try
{
string reward = null;
var sql = string.Format($@"EXEC PROC_PointMasterDetails @flag = 'expectedreward',
@customerId = '{customerId}', @holdtranId = '{tranId}'
").Replace("\r\n", string.Empty);
Log.Debug(sql);
var dataSet = _dao.ExecuteDataset(sql);
if (dataSet.Tables[0].Rows.Count == 0)
{
return null;
}
foreach (DataRow row in dataSet.Tables[0].Rows)
{
reward = row["expectedReward"].ToString();
}
double dreward = 0;
if (double.TryParse(reward, out dreward))
{
reward = Math.Round(dreward, 0).ToString();
}
return reward;
}
catch (Exception e)
{
Log.DebugFormat($"Exception : {e.ToString()}");
return null;
}
}
}
}