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

190 lines
8.5 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.Data;
using System.Linq;
using System.Web;
using SuperMap.RealEstate.ServiceModel;
using COMB = SuperMap.RealEstate.Coop.Merchant.Business;
using MSPB = SuperMap.RealEstate.MobileServicePlatform.Business;
using ESCom = EShang.Common;
using HZQR.Common;
namespace YFBusinessApi.Helper
{
public class CouponHelper
{
#region ->
/// <summary>
/// 查看优惠券详情
/// </summary>
/// <param name="_Transaction">事务管理器</param>
/// <param name="membershipId">商家会员内码</param>
/// <param name="Coupon_Code">卡券编码</param>
/// <returns></returns>
public static Models.CouponModel GetCouponDetail(
Transaction _Transaction, string membershipId, string Coupon_Code)
{
Models.CouponModel couponModel = new Models.CouponModel();
if (Coupon_Code.Length == 12 || Coupon_Code.Length == 13)
{
//加长后的券码是12或者13位截取前9位作为优惠券码
Coupon_Code = Coupon_Code.Substring(0, 9);
}
else if (Coupon_Code.Length == 9)
{
//原券码是9位截取前6位作为优惠券码
Coupon_Code = Coupon_Code.Substring(0, 6);
}
COMB.COUPON_SEND _COUPON_SEND = new COMB.COUPON_SEND(_Transaction);
_COUPON_SEND.AddSearchParameter("COUPON_CODE", Coupon_Code);
if (_COUPON_SEND.Search())
{
COMB.COUPON _COUPON = new COMB.COUPON(_Transaction);
_COUPON.COUPON_ID = _COUPON_SEND.COUPON_ID;
if (_COUPON.Select())
{
//商家版小程序通过会员服务区门店权限判断是否支持该卡券使用
string provinceCodes = "", serverpartShopCodes = "";
ESCom.BusinessMan.GetUserServerPartShop(membershipId.TryParseToInt(),
_Transaction, ref provinceCodes, ref serverpartShopCodes);
if (_COUPON.ExecuteDataTable($@"SELECT 1 FROM COOP_MERCHANT.T_COOPSHOP_RULE_ITEM
WHERE COOPSHOP_RULE_ID = {_COUPON_SEND.COOPSHOP_RULE_ID} AND
SERVERPART_CODE || SHOPCODE IN ('{serverpartShopCodes.Replace(",", "','")}')").Rows.Count <= 0)
{
couponModel.Coupon_WriteOffType = 0;
}
else
{
couponModel.Coupon_WriteOffType = 1;
}
couponModel.CouponSend_Id = _COUPON_SEND.COUPON_SEND_ID.Value;
couponModel.Coupon_Name = _COUPON_SEND.COUPON_NAME;
couponModel.Coupon_Code = _COUPON_SEND.COUPON_CODE;
couponModel.Coupon_Type = _COUPON_SEND.COUPON_TYPE.Value;
couponModel.Coupon_Valid_EndTime = _COUPON_SEND.VALID_END_TIME.TryParseToString();
couponModel.Coupon_PayMethod = _COUPON_SEND.PAY_METHOD.Value;
couponModel.Coupon_UsedAmount = (decimal)_COUPON_SEND.USED_AMOUNT;
couponModel.Coupon_Point = (decimal)_COUPON_SEND.COUPON_POINT;
couponModel.Coupon_Overlay = _COUPON_SEND.OVERLAY.Value;
couponModel.Coupon_State = _COUPON_SEND.COUPON_STATE.Value;
couponModel.Coupon_Instructions = _COUPON.COUPON_INSTRUCTIONS;
couponModel.Coupon_Desc = _COUPON_SEND.COUPON_DESC;
MSPB.MEMBERSHIP _MEMBERSHIP = new MSPB.MEMBERSHIP(_Transaction);
_MEMBERSHIP.MEMBERSHIP_ID = _COUPON_SEND.MEMBERSHIP_ID;
if (_MEMBERSHIP.Select())
{
couponModel.Membership_Name = _MEMBERSHIP.MEMBERSHIP_NAME;
couponModel.Membership_Mobilephone = _MEMBERSHIP.MEMBERSHIP_MOBILEPHONE;
}
}
couponModel.CouponShopList = new List<Models.CouponShopModel>();
string sqlShop = "SELECT SERVERPART_NAME,SHOPNAME FROM COOP_MERCHANT.T_COOPSHOP_RULE_ITEM " +
"WHERE COOPSHOP_RULE_ID = " + _COUPON_SEND.COOPSHOP_RULE_ID;
DataTable dtShop = new COMB.COUPON(_Transaction).ExecuteDataTable(sqlShop);
foreach (DataRow drShop in dtShop.Rows)
{
Models.CouponShopModel couponShopModel = new Models.CouponShopModel();
couponShopModel.Serverpart_Name = drShop["SERVERPART_NAME"].ToString();
couponShopModel.Serverpart_ShopName = drShop["SHOPNAME"].ToString();
couponModel.CouponShopList.Add(couponShopModel);
}
}
return couponModel;
}
#endregion
#region ->
/// <summary>
/// 商家卡券核销
/// </summary>
/// <param name="transaction">事务管理器</param>
/// <param name="membershipId">商家会员内码</param>
/// <param name="couponSendId">卡券内码</param>
/// <param name="couponSendCode">卡券编码</param>
/// <param name="Result_Desc">核销结果说明</param>
/// <returns></returns>
public static int WriteOffCoupon(Transaction transaction,
string membershipId, string couponSendId, string couponSendCode, ref string Result_Desc)
{
int ResultCode = 100;
COMB.COUPON_SEND _COUPON_SEND = new COMB.COUPON_SEND(transaction);
if (!string.IsNullOrWhiteSpace(couponSendId))
{
_COUPON_SEND.COUPON_SEND_ID_Encrypt = couponSendId.ToEncrypt();
_COUPON_SEND.Select();
}
else if (!string.IsNullOrWhiteSpace(couponSendCode))
{
if (couponSendCode.Length == 12 || couponSendCode.Length == 13)
{
//加长后的券码是12或者13位截取前9位作为优惠券码
couponSendCode = couponSendCode.Substring(0, 9);
}
else if (couponSendCode.Length == 9)
{
//原券码是9位截取前6位作为优惠券码
couponSendCode = couponSendCode.Substring(0, 6);
}
_COUPON_SEND.AddSearchParameter("COUPON_CODE", couponSendCode);
_COUPON_SEND.Search();
}
if (_COUPON_SEND != null && _COUPON_SEND.COUPON_ID != null)
{
int COUPON_STATE = _COUPON_SEND.COUPON_STATE == null ? 0 : _COUPON_SEND.COUPON_STATE.TryParseToInt();
switch (COUPON_STATE)
{
case 0:
//查询登录会员信息
_COUPON_SEND.COUPON_STATE = 1;
_COUPON_SEND.USED_DATE = DateTime.Now;
MSPB.BUSINESSMAN _BUSINESSMAN = new MSPB.BUSINESSMAN(transaction);
_BUSINESSMAN.BUSINESSMAN_ID = membershipId.TryParseToInt();
if (_BUSINESSMAN.Select())
{
_COUPON_SEND.UPDATE_STAFF_ID = _BUSINESSMAN.BUSINESSMAN_ID;
_COUPON_SEND.UPDATE_STAFF_NAME = _BUSINESSMAN.BUSINESSMAN_NAME;
_COUPON_SEND.Update();
ResultCode = 100;
Result_Desc = "使用成功!";
//推送券核销通知
WeChatPushHelper.PushWechatMessage(transaction, _COUPON_SEND);
}
else
{
ResultCode = 102;
Result_Desc = "请登录后核销!";
break;
}
break;
case 1:
ResultCode = 101;
Result_Desc = "该券已被使用!";
break;
case 2:
ResultCode = 201;
Result_Desc = "该券已失效!";
break;
}
}
else
{
ResultCode = 102;
Result_Desc = $"券{couponSendId}不存在";
}
return ResultCode;
}
#endregion
}
}