2025-03-28 09:49:56 +08:00

181 lines
9.1 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using SuperMap.RealEstate.ServiceModel;
using CMB = SuperMap.RealEstate.Coop.Merchant.Business;
using MSPB = SuperMap.RealEstate.MobileServicePlatform.Business;
using ESCom = EShang.Common;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
using HZQR.Common;
namespace EShangApi.Helper
{
/// <summary>
/// 营收数据相关方法
/// </summary>
public class RevenueHelper
{
/// <summary>
/// 获取商家门店营收金额
/// </summary>
/// <param name="transaction">事务管理器</param>
/// <param name="Membership_Id">商家会员内码</param>
/// <param name="endaccountDate">统计日期,默认昨日</param>
/// <returns></returns>
public static Models.MerchantRevenueModel GetMerchantRevenue(Transaction transaction, int Membership_Id, string endaccountDate = "")
{
Models.MerchantRevenueModel merchantRevenueModel = new Models.MerchantRevenueModel();
//查询商家门店权限
DataTable dtShop = GetUserServerPartShop(transaction, Membership_Id);
foreach (DataRow drProvinceCode in dtShop.Rows)
{
//获取接口Url地址
string _url = ConfigurationManager.AppSettings[drProvinceCode[0].ToString()].ToString() +
"/Revenue/GetMerchantRevenue?serverpartShopCodes=" + drProvinceCode[1].ToString() + "&endaccountDate=" + endaccountDate;
//生成参数
Dictionary<string, string> jsApiParam = new Dictionary<string, string>();
jsApiParam.Add("serverpartShopCodes", drProvinceCode[1].ToString());
jsApiParam.Add("endaccountDate", endaccountDate);
//调用接口获取返回值
string ResString = ESCom.HttpUtil.HttpUrlPost(ESCom.PayHelper.paramsToString(jsApiParam), _url);
try
{
JObject keyValuePairs = JObject.Parse(ResString);
if (keyValuePairs["Result_Code"].ToString() == "100")
{
Models.MerchantRevenueModel merchantRevenue = JsonConvert.DeserializeObject<
Models.MerchantRevenueModel>(keyValuePairs["Result_Data"].ToString());
if (merchantRevenue != null)
{
//营收金额
merchantRevenueModel.Revenue_Amount += merchantRevenue.Revenue_Amount;
//账期移动支付金额
merchantRevenueModel.Mobilepay_Amount += merchantRevenue.Mobilepay_Amount;
//账期现金支付金额
merchantRevenueModel.CashPay_Amount += merchantRevenue.CashPay_Amount;
//交易笔数
merchantRevenueModel.Ticket_Count += merchantRevenue.Ticket_Count;
//商品数量
merchantRevenueModel.Total_Count += merchantRevenue.Total_Count;
}
}
}
catch (Exception ex)
{
LogUtil.WriteLog(ex, "省份编码:" + drProvinceCode[0] + ",门店编码:" + drProvinceCode[1] +
",统计日期:" + endaccountDate, DateTime.Now.ToString("yyyyMMdd") + "_GetMerchantRevenue");
}
}
return merchantRevenueModel;
}
/// <summary>
/// 获取商家门店营收金额
/// </summary>
/// <param name="transaction">事务管理器</param>
/// <param name="Membership_Id">商家会员内码</param>
/// <param name="endaccountDate">统计日期,默认昨日</param>
/// <returns></returns>
public static Models.MerchantRevenueModel GetMerchantRevenueList(Transaction transaction,
int Membership_Id, string endaccountDate = "")
{
Models.MerchantRevenueModel merchantRevenueModel = new Models.MerchantRevenueModel();
merchantRevenueModel.RevenueServerpartList = new List<Models.RevenueServerpart>();
//查询商家门店权限
DataTable dtShop = GetUserServerPartShop(transaction, Membership_Id);
foreach (DataRow drProvinceCode in dtShop.Rows)
{
//获取接口Url地址
string _url = ConfigurationManager.AppSettings[drProvinceCode[0].ToString()].ToString() +
"/Revenue/GetMerchantRevenueList?serverpartShopCodes=" +
drProvinceCode[1].ToString() + "&endaccountDate=" + endaccountDate;
//生成参数
Dictionary<string, string> jsApiParam = new Dictionary<string, string>();
jsApiParam.Add("serverpartShopCodes", drProvinceCode[1].ToString());
jsApiParam.Add("endaccountDate", endaccountDate);
//调用接口获取返回值
string ResString = ESCom.HttpUtil.HttpUrlPost(ESCom.PayHelper.paramsToString(jsApiParam), _url);
try
{
JObject keyValuePairs = JObject.Parse(ResString);
if (keyValuePairs["Result_Code"].ToString() == "100")
{
Models.MerchantRevenueModel merchantRevenue = JsonConvert.DeserializeObject<
Models.MerchantRevenueModel>(keyValuePairs["Result_Data"].ToString());
if (merchantRevenue != null)
{
//营收金额
merchantRevenueModel.Revenue_Amount += merchantRevenue.Revenue_Amount;
//账期移动支付金额
merchantRevenueModel.Mobilepay_Amount += merchantRevenue.Mobilepay_Amount;
//账期现金支付金额
merchantRevenueModel.CashPay_Amount += merchantRevenue.CashPay_Amount;
//交易笔数
merchantRevenueModel.Ticket_Count += merchantRevenue.Ticket_Count;
//商品数量
merchantRevenueModel.Total_Count += merchantRevenue.Total_Count;
merchantRevenueModel.RevenueServerpartList = merchantRevenueModel.RevenueServerpartList.Concat(
merchantRevenue.RevenueServerpartList).ToList();
}
}
}
catch (Exception ex)
{
LogUtil.WriteLog(ex, "省份编码:" + drProvinceCode[0] + ",门店编码:" + drProvinceCode[1] +
",统计日期:" + endaccountDate, DateTime.Now.ToString("yyyyMMdd") + "_GetMerchantRevenueList");
}
}
return merchantRevenueModel;
}
/// <summary>
/// 获取商家门店权限
/// </summary>
/// <param name="transaction">事务管理器</param>
/// <param name="membershipId">商家会员内码</param>
/// <returns></returns>
public static DataTable GetUserServerPartShop(Transaction transaction, int membershipId)
{
DataTable dtShop = new DataTable();
//服务区列表集合
MSPB.RTPASSPORTINFO _RTPASSPORTINFO = new MSPB.RTPASSPORTINFO(transaction);
_RTPASSPORTINFO.AddSearchParameter("MEMBERSHIP_ID", membershipId);
_RTPASSPORTINFO.AddSearchParameter("PROVINCE_CODE", 0);
if (_RTPASSPORTINFO.Search() && _RTPASSPORTINFO.USER_ID != null)
{
/* 平台账号与服务区门店关联表COOP_MERCHANT.T_RTAUTOTYPE
* 服务区门店表COOP_MERCHANT.T_SERVERPARTSHOP【门店内码、门店编码、门店名称、门店简称、门店方位】
* 服务区信息表COOP_MERCHANT.T_SERVERPART【省份编码、服务区内码、服务区编码、服务区名称】
* 门店商户信息表COOP_MERCHANT.T_BUSINESSSHOPCODE【开户银行、银行账号、结算人】
*/
string sql = string.Format(@"
SELECT
C.PROVINCE_CODE,WM_CONCAT(C.SERVERPART_CODE || B.SHOPCODE) AS SERVERPARTSHOPCODES
FROM
COOP_MERCHANT.T_RTAUTOTYPE A,
COOP_MERCHANT.T_SERVERPARTSHOP B,
COOP_MERCHANT.T_SERVERPART C
WHERE
A.PROVINCE_CODE = B.PROVINCE_CODE AND A.SERVERPARTSHOP_ID = B.SERVERPARTSHOP_ID AND
B.SERVERPART_ID = C.SERVERPART_ID AND B.PROVINCE_CODE = C.PROVINCE_CODE AND A.USER_ID = {0}
GROUP BY
C.PROVINCE_CODE", _RTPASSPORTINFO.USER_ID);
dtShop = new CMB.RTAUTOTYPE(transaction).ExecuteDataTable(sql);
}
//获取商户管辖门店列表
return dtShop;
}
}
}