using System; using System.Collections.Generic; using System.Web.Http; using System.Web.Http.Description; using SuperMap.RealEstate.Utility; using ESCM = CommercialApi.Model; using ESCG = CommercialApi.GeneralMethod; using HZQR.Common; namespace CommercialApi.Controllers { /// /// 客群分析相关接口 /// public class CustomerController : BaseController { #region 方法 -> 获取客群分析占比 /// /// 获取客群分析占比 /// /// /// 应用场景:分别显示男性、女性、年龄层次的占比,可以按交易笔数或消费金额统计占比结果
/// 返参内容:
/// name:名称(男性/女性/年龄)
/// data:
/// name=男性/女性:[交易占比]
/// name=年龄:[00后,90后,80后,70后] ///
/// /// 统计类型:
/// 1【按交易笔数】
/// 2【按消费金额】 /// /// 业主单位标识 /// 服务区内码 /// 服务区编码 /// 统计月份,格式如202110 /// [AcceptVerbs("GET")] [Route("Customer/GetCustomerRatio")] [ResponseType(typeof(Models.JsonMsg>))] public IHttpActionResult GetCustomerRatio(int statisticsType, string provinceCode, int? serverpartId = null, string serverpartCode = "", int? statisticsMonth = null) { string Parameter = "入参信息:统计类型【" + statisticsType + "】,业主单位标识【" + provinceCode + "】," + "服务区内码【" + serverpartId + "】,服务区编码【" + serverpartCode + "】,统计月份【" + statisticsMonth + "】"; try { //获取客群分析占比图 List CustomerRatioChart = ESCG.CustomerHelper.GetCustomerRatio( transaction, statisticsType, provinceCode, serverpartId, serverpartCode, statisticsMonth); //返回数据,将返回结果转换成API接口的JsonList格式 Models.JsonList jsonList = Models.JsonList.Success(CustomerRatioChart); //返回数据 return Ok(Models.JsonMsg>.Success(jsonList, 100, "查询成功")); } catch (Exception ex) { transaction.Rollback(); LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter, DateTime.Now.ToString("yyyyMMdd") + "_GetCustomerRatio"); return Ok(ESCG.Common.ReturnJson(999, "查询失败" + ex.Message)); } } #endregion #region 方法 -> 获取客群消费能力占比 /// /// 获取客群消费能力占比 /// /// /// 应用场景:按性别统计客群消费的能力,统计4种金额区间(0<X≤30,30<X≤60,60<X≤90,X>90)交易客单数量的占比
/// 返参内容:
/// name:性别
/// data:[0<X≤30,30<X≤60,60<X≤90,X>90]客单交易占比的数组 ///
/// 业主单位标识 /// 服务区内码 /// 服务区编码 /// 统计月份,格式如202110 /// [AcceptVerbs("GET")] [Route("Customer/GetCustomerConsumeRatio")] [ResponseType(typeof(Models.JsonMsg>))] public IHttpActionResult GetCustomerConsumeRatio(string provinceCode, int? serverpartId = null, string serverpartCode = "", int? statisticsMonth = null) { string Parameter = "入参信息:业主单位标识【" + provinceCode + "】," + "服务区内码【" + serverpartId + "】,服务区编码【" + serverpartCode + "】,统计月份【" + statisticsMonth + "】"; try { //获取客群消费能力占比图 List CustomerConsumeRatioChart = ESCG.CustomerHelper.GetCustomerConsumeRatio( transaction, provinceCode, serverpartId, serverpartCode, statisticsMonth); //返回数据,将返回结果转换成API接口的JsonList格式 Models.JsonList jsonList = Models.JsonList.Success(CustomerConsumeRatioChart); //返回数据 return Ok(Models.JsonMsg>.Success(jsonList, 100, "查询成功")); } catch (Exception ex) { transaction.Rollback(); LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter, DateTime.Now.ToString("yyyyMMdd") + "_GetCustomerConsumeRatio"); return Ok(ESCG.Common.ReturnJson(999, "查询失败" + ex.Message)); } } #endregion #region 方法 -> 获取客群年龄层次占比 /// /// 获取客群年龄层次占比 /// /// /// 应用场景:按性别统计客群消费的能力,统计00后、90后、80后、70后交易客单数量的占比
/// 返参内容:
/// name:性别
/// data:[00后,90后,80后,70后]客单交易占比的数组 ///
/// 业主单位标识 /// 服务区内码 /// 服务区编码 /// 统计月份,格式如202110 /// [AcceptVerbs("GET")] [Route("Customer/GetCustomerAgeRatio")] [ResponseType(typeof(Models.JsonMsg>))] public IHttpActionResult GetCustomerAgeRatio(string provinceCode, int? serverpartId = null, string serverpartCode = "", int? statisticsMonth = null) { string Parameter = "入参信息:业主单位标识【" + provinceCode + "】," + "服务区内码【" + serverpartId + "】,服务区编码【" + serverpartCode + "】,统计月份【" + statisticsMonth + "】"; try { //获取客群年龄层次占比图 List CustomerAgeRatioChart = ESCG.CustomerHelper.GetCustomerAgeRatio( transaction, provinceCode, serverpartId, serverpartCode, statisticsMonth); //返回数据,将返回结果转换成API接口的JsonList格式 Models.JsonList jsonList = Models.JsonList.Success(CustomerAgeRatioChart); //返回数据 return Ok(Models.JsonMsg>.Success(jsonList, 100, "查询成功")); } catch (Exception ex) { transaction.Rollback(); LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter, DateTime.Now.ToString("yyyyMMdd") + "_GetCustomerAgeRatio"); return Ok(ESCG.Common.ReturnJson(999, "查询失败" + ex.Message)); } } #endregion #region 方法 -> 获取客群特征分析 /// /// 获取客群特征分析 /// /// /// 应用场景:按性别、年龄层次统计客群消费的能力,展示什么年龄段消费多少金额占总交易笔数的比例
/// 返参内容:
/// name:性别
/// data:[年龄,交易金额,交易占比]的二维数组 ///
/// 业主单位标识 /// 服务区内码 /// 服务区编码 /// 统计月份,格式如202110 /// [AcceptVerbs("GET")] [Route("Customer/GetCustomerGroupRatio")] [ResponseType(typeof(Models.JsonMsg>))] public IHttpActionResult GetCustomerGroupRatio(string provinceCode, int? serverpartId = null, string serverpartCode = "", int? statisticsMonth = null) { string Parameter = "入参信息:业主单位标识【" + provinceCode + "】," + "服务区内码【" + serverpartId + "】,服务区编码【" + serverpartCode + "】,统计月份【" + statisticsMonth + "】"; try { //获取客群特征分析图 List CustomerGroupRatioChart = ESCG.CustomerHelper.GetCustomerGroupRatio( transaction, provinceCode, serverpartId, serverpartCode, statisticsMonth); //返回数据,将返回结果转换成API接口的JsonList格式 Models.JsonList jsonList = Models.JsonList.Success(CustomerGroupRatioChart); //返回数据 return Ok(Models.JsonMsg>.Success(jsonList, 100, "查询成功")); } catch (Exception ex) { transaction.Rollback(); LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter, DateTime.Now.ToString("yyyyMMdd") + "_GetCustomerGroupRatio"); return Ok(ESCG.Common.ReturnJson(999, "查询失败" + ex.Message)); } } #endregion #region 方法 -> 获取客群分析说明表列表 /// /// 获取客群分析说明表列表 /// /// 统计月份 /// 服务区内码 /// 服务区编码 /// 省份编码 /// 统计类型 /// 1:消费人群占比 /// 2:消费能力占比 /// 3:客群特征分析 /// 4:消费能力分析 /// 5:年龄层次分析 /// [Route("Customer/GetAnalysisDescList")] [AcceptVerbs("GET")] [ResponseType(typeof(Models.JsonMsg>))] public IHttpActionResult GetAnalysisDescList(int? statisticsMonth = null, int? serverpartId = null, string serverpartCode = "", string provinceCode = "", int? statisticsType = null) { string Parameter = "入参信息:统计类型【" + statisticsType + "】,业主单位标识【" + provinceCode + "】," + "服务区内码【" + serverpartId + "】,服务区编码【" + serverpartCode + "】,统计月份【" + statisticsMonth + "】"; try { //获取客群分析说明表列表 List AnalysisDescList = ESCG.CustomerHelper.GetAnalysisDescList( transaction, statisticsMonth, serverpartId, serverpartCode, provinceCode, statisticsType); //转化json形式 Models.JsonList jsonList = Models.JsonList.Success(AnalysisDescList); return Ok(Models.JsonMsg>.Success(jsonList, 100, "查询成功")); } catch (Exception ex) { transaction.Rollback(); LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter, DateTime.Now.ToString("yyyyMMdd") + "_GetAnalysisDescList"); return Ok(ESCG.Common.ReturnJson(999, "查询失败" + ex.Message)); } } #endregion #region 方法 -> 获取客群分析说明表明细 /// /// 获取客群分析说明表明细 /// /// 统计类型 /// 1:消费人群占比 /// 2:消费能力占比 /// 3:客群特征分析 /// 4:消费能力分析 /// 5:年龄层次分析 /// 统计月份 /// 服务区内码 /// 服务区编码 /// 省份编码 /// [Route("Customer/GetAnalysisDescDetail")] [AcceptVerbs("GET")] [ResponseType(typeof(Models.JsonMsg))] public IHttpActionResult GetAnalysisDescDetail(int statisticsType, int? statisticsMonth = null, int? serverpartId = null, string serverpartCode = "", string provinceCode = "") { string Parameter = "入参信息:统计类型【" + statisticsType + "】,业主单位标识【" + provinceCode + "】," + "服务区内码【" + serverpartId + "】,服务区编码【" + serverpartCode + "】,统计月份【" + statisticsMonth + "】"; try { //获取客群分析说明表明细 ESCM.AnalysisDescModel customer_analysisModel = ESCG.CustomerHelper.GetAnalysisDescDetail( transaction, statisticsType, statisticsMonth, serverpartId, serverpartCode, provinceCode); return Ok(Models.JsonMsg.Success(customer_analysisModel, 100, "查询成功")); } catch (Exception ex) { transaction.Rollback(); LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter, DateTime.Now.ToString("yyyyMMdd") + "_GetAnalysisDescDetail"); return Ok(ESCG.Common.ReturnJson(999, "查询失败" + ex.Message)); } } #endregion #region 方法 -> 获取客群消费偏好数据 /// /// 获取客群消费偏好数据 /// /// /// 应用场景:展示客群消费偏好的数据接口,可以从经营业态、服务区、片区、月份的角度进行显示, /// 返回的结果中包含男性、女性、70后、80后、90后、00后组合维度的数据集。
/// 返回结果:
/// StatisticsMonth: 统计月份
/// SPRegionTypeId: 片区内码
/// SPRegionTypeName: 片区名称
/// ServerpartId: 服务区内码
/// ServerpartName: 服务区名称
/// BusinessTradeValue: 经营业态内码
/// BusinessTradeName: 经营业态名称
/// TotalRatio: 总占比
/// MaleRatio: 男性占比
/// FemaleRatio: 女性占比
/// Ratio_00: 00后占比
/// Ratio_90: 90后占比
/// Ratio_80: 80后占比
/// Ratio_70: 70后占比
/// MaleRatio_00: 00后男性占比
/// MaleRatio_90: 90后男性占比
/// MaleRatio_80: 80后男性占
/// MaleRatio_70: 70后男性占比
/// FemaleRatio_00: 00后女性占比
/// FemaleRatio_90: 90后女性占比
/// FemaleRatio_80: 80后女性占比
/// FemaleRatio_70: 70后女性占比 ///
/// /// 统计类型,多个用,隔开:
/// 1、按经营业态分组显示
/// 2、按服务区分组显示
/// 3、按片区分组显示
/// 4、按月份分组显示 /// /// 统计开始月份,格式如202301 /// 统计结束月份,格式如202301 /// 业主单位标识 /// 片区内码,多个用,隔开 /// 服务区内码,多个用,隔开 /// 经营业态,多个用,隔开 /// /// 经营业态显示级别:
/// 0:最低级别业态
/// 1:一级业态,父级id=-1
/// 2:二级业态,父级是一级业态
/// /// /// 单品明细显示数量:
/// 传0不显示,否则显示明细 /// /// 排序字段 /// [AcceptVerbs("GET")] [Route("Customer/GetCustomerSaleRatio")] [ResponseType(typeof(Models.JsonMsg))] public IHttpActionResult GetCustomerSaleRatio(string statisticsType, string startMonth, string endMonth, string provinceCode, string spRegionTypeId = "", string serverpartId = "", string businessTrade = "", int showTradeLevel = 0, int showDetailCount = 10, string sortStr = "") { provinceCode = GetStringHeader("ProvinceCode", provinceCode); //根据业主单位标识转译成省份内码 provinceCode = ESCG.BaseInfoHelper.GetProvinceID(transaction, provinceCode); string Parameter = "入参信息:统计类型【" + statisticsType + "】,统计开始月份【" + startMonth + "】," + "统计结束月份【" + startMonth + "】,业主单位标识【" + provinceCode + "】,片区内码【" + spRegionTypeId + "】," + "服务区内码【" + serverpartId + "】,经营业态【" + businessTrade + "】," + "经营业态显示级别【" + showTradeLevel + "】,单品明细显示数量【" + showDetailCount + "】"; try { if (string.IsNullOrWhiteSpace(statisticsType) || string.IsNullOrWhiteSpace(provinceCode)) { return Ok(ESCG.Common.ReturnJson(101, "查询失败:请传入正确的参数")); } //获取客群消费偏好数据 ESCM.CustomerSaleRatioModel customerSaleRatioModel = ESCG.CustomerHelper.GetCustomerSaleRatio(transaction, statisticsType, startMonth, endMonth, provinceCode, spRegionTypeId, serverpartId, businessTrade, showTradeLevel, showDetailCount, sortStr); if (customerSaleRatioModel == null) { return Ok(ESCG.Common.ReturnJson(101, "查询失败:无数据返回")); } return Ok(Models.JsonMsg.Success(customerSaleRatioModel, 100, "查询成功")); } catch (Exception ex) { transaction.Rollback(); LogUtil.WriteLog(null, "查询失败!失败原因:" + ex.Message + "\r\n" + Parameter, DateTime.Now.ToString("yyyyMMdd") + "_GetCustomerSaleRatio"); return Ok(ESCG.Common.ReturnJson(999, "查询失败" + ex.Message)); } } #endregion } }