89 lines
2.5 KiB
C#
89 lines
2.5 KiB
C#
using MAX.Core.DependencyInjection;
|
|
using MAX.Core.Logger;
|
|
using Org.BouncyCastle.Utilities;
|
|
using Store.Contracts.Order.Entitys;
|
|
using Store.Contracts.Shops;
|
|
using Store.Contracts.User.Interfaces;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Web;
|
|
|
|
namespace KJD_Web.Services.Shops;
|
|
|
|
public class ShopService : ITransientDependency
|
|
{
|
|
private readonly IFreeSql _freeSql;
|
|
private readonly ILoggerFacade _logger;
|
|
private readonly IUserService _userService;
|
|
|
|
public ShopService(IFreeSql freeSql, ILoggerFacade logger, IUserService userService)
|
|
{
|
|
_freeSql = freeSql;
|
|
_logger = logger;
|
|
_userService = userService;
|
|
}
|
|
public long GetShopCount()
|
|
{
|
|
return _freeSql.Select<ShopEntity>().Count();
|
|
}
|
|
/// <summary>
|
|
/// 当前商铺是否属于当前用户
|
|
/// </summary>
|
|
/// <param name="shopId"></param>
|
|
/// <param name="userName"></param>
|
|
/// <returns></returns>
|
|
public bool IsShopOwnedByUser(long shopId, string userName)
|
|
{
|
|
var shopIds = GetShopIds(userName);
|
|
return shopIds.Contains(shopId);
|
|
}
|
|
/// <summary>
|
|
/// 修改商铺永不过期
|
|
/// </summary>
|
|
public bool UpdateShopNeverExpires(string userName, string shopId, string ownerUser, bool isNever)
|
|
{
|
|
if (string.IsNullOrEmpty(userName)) return false;
|
|
if (string.IsNullOrEmpty(shopId)) return false;
|
|
var user = _userService.GetUserByUserName(userName);
|
|
if (user == null) return false;
|
|
if (user.SaLevel != 1) return false;
|
|
|
|
var affrows = _freeSql.Update<ShopEntity>()
|
|
.Set(a => a.NeverExpires, isNever)
|
|
.Where(a => a.ShopId == shopId && a.UserName == ownerUser)
|
|
.ExecuteAffrows();
|
|
return affrows == 1;
|
|
}
|
|
|
|
public List<ShopEntity> GetShops(string userName)
|
|
{
|
|
return _freeSql.Select<ShopEntity>()
|
|
.Where(a => a.UserName == userName || a.SubUserName.Contains(userName))
|
|
.ToList();
|
|
}
|
|
|
|
public List<long> GetShopIds(string userName)
|
|
{
|
|
var shops = GetShops(userName);
|
|
var shopAppkeys = shops.Select(a => a.ShopId).Distinct().ToList();
|
|
return _freeSql.Select<WXShopEntity>()
|
|
.Where(a => shopAppkeys.Contains(a.AppKey))
|
|
.ToList(a => a.Id);
|
|
}
|
|
|
|
public string GetShopKey(string orderSn)
|
|
{
|
|
if (string.IsNullOrEmpty(orderSn)) return "";
|
|
var appKey = _freeSql.Select<WeiOrderEntity, WXShopEntity>()
|
|
.InnerJoin((a, b) => a.ShopId == b.Id)
|
|
.Where((a, b) => a.OrderId == orderSn)
|
|
.First((a, b) => b.AppKey);
|
|
return appKey;
|
|
|
|
// SELECT B.app_key from erp.oms_wei_order AS A
|
|
//JOIN erp.o_shop as B on A.shop_id = B.id
|
|
// WHERE A.order_id = '3739958894823388160'
|
|
|
|
}
|
|
} |