|
|
|
using BBWYB.Common.Log;
|
|
|
|
using BBWYB.Common.Models;
|
|
|
|
using BBWYB.Server.Model;
|
|
|
|
using BBWYB.Server.Model.Db.Mds;
|
|
|
|
using BBWYB.Server.Model.Db.MDS;
|
|
|
|
using BBWYB.Server.Model.Dto;
|
|
|
|
using SDKAdapter.OperationPlatform.Client;
|
|
|
|
using SDKAdapter.OperationPlatform.Models;
|
|
|
|
using Yitter.IdGenerator;
|
|
|
|
|
|
|
|
namespace BBWYB.Server.Business
|
|
|
|
{
|
|
|
|
public class VenderBusiness : BaseBusiness, IDenpendency
|
|
|
|
{
|
|
|
|
private OP_PlatformClientFactory opPlatformClientFactory;
|
|
|
|
private FreeSqlMultiDBManager fsqlManager;
|
|
|
|
private KuaiDi100Manager kuaiDi100Manager;
|
|
|
|
|
|
|
|
public VenderBusiness(IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator, FreeSqlMultiDBManager fsqlManager, OP_PlatformClientFactory opPlatformClientFactory, KuaiDi100Manager kuaiDi100Manager) : base(fsql, nLogManager, idGenerator)
|
|
|
|
{
|
|
|
|
this.fsqlManager = fsqlManager;
|
|
|
|
this.opPlatformClientFactory = opPlatformClientFactory;
|
|
|
|
this.kuaiDi100Manager = kuaiDi100Manager;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<ShopResponse> GetShopList(long? shopId = null, Enums.Platform? platform = null, string shopName = "")
|
|
|
|
{
|
|
|
|
return fsqlManager.MDSfsql.Select<Shops>().Where(s => !string.IsNullOrEmpty(s.ShopId))
|
|
|
|
.WhereIf(shopId != null, s => s.ShopId == shopId.ToString())
|
|
|
|
.WhereIf(platform != null, s => s.PlatformId == (int)platform)
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(shopName), s => s.ShopName == shopName)
|
|
|
|
.ToList<ShopResponse>();
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<ShopResponse> GetShopList(List<string> shopIds)
|
|
|
|
{
|
|
|
|
return fsqlManager.MDSfsql.Select<Shops>().Where(s => !string.IsNullOrEmpty(s.ShopId) &&
|
|
|
|
shopIds.Contains(s.ShopId))
|
|
|
|
.ToList<ShopResponse>();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public long SaveShopSetting(ShopSettingRequest shopSettingRequest)
|
|
|
|
{
|
|
|
|
//根据shopId查询mds shop的主键Id
|
|
|
|
var shopId = shopSettingRequest.ShopId.ToString();
|
|
|
|
var mdsShop = fsqlManager.MDSfsql.Select<Shops>().Where(s => s.ShopId == shopId).ToOne();
|
|
|
|
if (mdsShop == null)
|
|
|
|
throw new BusinessException($"mds未找到shopId {shopSettingRequest.ShopId}");
|
|
|
|
|
|
|
|
if (shopSettingRequest.PurchaseAccountId == 0)
|
|
|
|
{
|
|
|
|
shopSettingRequest.PurchaseAccountId = idGenerator.NewLong();
|
|
|
|
|
|
|
|
var mdspa = new Purchaseaccount()
|
|
|
|
{
|
|
|
|
Id = shopSettingRequest.PurchaseAccountId.ToString(),
|
|
|
|
AccountName = shopSettingRequest.AccountName,
|
|
|
|
AppKey = shopSettingRequest.AppKey,
|
|
|
|
AppSecret = shopSettingRequest.AppSecret,
|
|
|
|
AppToken = shopSettingRequest.AppToken,
|
|
|
|
CreateTime = DateTime.Now,
|
|
|
|
CreatorId = "",
|
|
|
|
Deleted = 0,
|
|
|
|
PurchasePlatformId = ((int)shopSettingRequest.PurchasePlatformId).ToString(),
|
|
|
|
ShopId = mdsShop.Id
|
|
|
|
};
|
|
|
|
|
|
|
|
fsqlManager.MDSfsql.Insert(mdspa).ExecuteAffrows();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fsqlManager.MDSfsql.Update<Purchaseaccount>(shopSettingRequest.PurchaseAccountId.ToString())
|
|
|
|
.Set(pa => pa.AppKey, shopSettingRequest.AppKey)
|
|
|
|
.Set(pa => pa.AppSecret, shopSettingRequest.AppSecret)
|
|
|
|
.Set(pa => pa.AppToken, shopSettingRequest.AppToken)
|
|
|
|
.Set(pa => pa.AccountName, shopSettingRequest.AccountName)
|
|
|
|
.Set(pa => pa.PurchasePlatformId, ((int)shopSettingRequest.PurchasePlatformId).ToString())
|
|
|
|
.ExecuteAffrows();
|
|
|
|
}
|
|
|
|
return shopSettingRequest.PurchaseAccountId;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<Purchaseaccount> GetPurchaserList(QueryPurchaseAccountRequest request)
|
|
|
|
{
|
|
|
|
var purchasePlatofrmId = request.PurchasePlatofrmId != null ? ((int)request.PurchasePlatofrmId).ToString() : string.Empty;
|
|
|
|
var shopIdStr = request.ShopId.ToString();
|
|
|
|
var mdsShop = fsqlManager.MDSfsql.Select<Shops>().Where(s => s.ShopId == shopIdStr).ToOne();
|
|
|
|
var plist = fsqlManager.MDSfsql.Select<Purchaseaccount>()
|
|
|
|
.Where(pa => pa.ShopId == mdsShop.Id)
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(purchasePlatofrmId), pa => pa.PurchasePlatformId == purchasePlatofrmId)
|
|
|
|
.WhereIf(!string.IsNullOrEmpty(request.AccountName), pa => pa.AccountName == request.AccountName)
|
|
|
|
.ToList();
|
|
|
|
foreach (var pa in plist)
|
|
|
|
pa.ShopId = shopIdStr;
|
|
|
|
return plist;
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<OP_QueryExpressCompanyResponse> GetExpressCompanyList(PlatformRequest request)
|
|
|
|
{
|
|
|
|
return opPlatformClientFactory.GetClient((SDKAdapter.AdapterEnums.PlatformType)request.Platform)
|
|
|
|
.GetExpressCompanyList(new OP_QueryExpressCompanyRequest()
|
|
|
|
{
|
|
|
|
AppKey = request.AppKey,
|
|
|
|
AppSecret = request.AppSecret,
|
|
|
|
AppToken = request.AppToken,
|
|
|
|
Platform = (SDKAdapter.AdapterEnums.PlatformType)request.Platform
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
public IList<KuaiDi100ExpressCompany> GetKuaiDi100ExpressCompanyList(KuaiDi100ExpressSearchRequest request)
|
|
|
|
{
|
|
|
|
return kuaiDi100Manager.GetKuaiDi100ExpressCompanyList(request);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|