|
|
@ -6,18 +6,19 @@ using BBWYB.Server.Model.Db; |
|
|
|
using BBWYB.Server.Model.Dto; |
|
|
|
using FreeSql; |
|
|
|
using Newtonsoft.Json; |
|
|
|
using Yitter.IdGenerator; |
|
|
|
|
|
|
|
namespace BBWYB.Server.Business |
|
|
|
{ |
|
|
|
public class QiKuManager : IDenpendency |
|
|
|
public class QiKuManager : BaseBusiness, IDenpendency |
|
|
|
{ |
|
|
|
private RestApiService restApiService; |
|
|
|
private IFreeSql fsql; |
|
|
|
private NLogManager nLogManager; |
|
|
|
public QiKuManager(RestApiService restApiService, IFreeSql fsql, NLogManager nLogManager) |
|
|
|
|
|
|
|
public QiKuManager(RestApiService restApiService, IFreeSql fsql, NLogManager nLogManager, IIdGenerator idGenerator) : base(fsql, nLogManager, idGenerator) |
|
|
|
{ |
|
|
|
this.restApiService = restApiService; |
|
|
|
this.fsql = fsql; |
|
|
|
} |
|
|
|
|
|
|
|
/// <summary>
|
|
|
@ -124,16 +125,17 @@ namespace BBWYB.Server.Business |
|
|
|
/// <summary>
|
|
|
|
/// 查询齐库合格证
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="orderId"></param>
|
|
|
|
/// <param name="order"></param>
|
|
|
|
/// <param name="packTaskSkuPurchaseSchemeIdList"></param>
|
|
|
|
/// <param name="orderSkuList"></param>
|
|
|
|
public void SearchCerConfigured(string orderId, IList<QiKuPackTaskSkuPurchaseSchemeIdRequest> packTaskSkuPurchaseSchemeIdList, IList<OrderSku> orderSkuList) |
|
|
|
public void SearchCerConfigured(Order order, IList<QiKuPackTaskSkuPurchaseSchemeIdRequest> packTaskSkuPurchaseSchemeIdList, IList<OrderSku> orderSkuList) |
|
|
|
{ |
|
|
|
try |
|
|
|
{ |
|
|
|
nLogManager.Default().Info($"SearchCerConfigured OrderId {order.Id}, packTaskSkuPurchaseSchemeIdList {JsonConvert.SerializeObject(packTaskSkuPurchaseSchemeIdList)}"); |
|
|
|
var restApiResult = restApiService.SendRequest("http://qiku.qiyue666.com", "api/PackPurchaseTask/SearchCerConfigured", new |
|
|
|
{ |
|
|
|
orderId, |
|
|
|
orderId = order.Id, |
|
|
|
packTaskSkuPurchaseSchemeIdList |
|
|
|
}, null, HttpMethod.Post); |
|
|
|
|
|
|
@ -146,6 +148,7 @@ namespace BBWYB.Server.Business |
|
|
|
if (response.Data.PackTaskSkuPurchaseSchemeIdList != null && response.Data.PackTaskSkuPurchaseSchemeIdList.Count() > 0) |
|
|
|
{ |
|
|
|
IList<IUpdate<OrderSku>> updateOrderSkuList = new List<IUpdate<OrderSku>>(); |
|
|
|
List<TimeLimitTask> insertTimeLimitTaskList = new List<TimeLimitTask>(); |
|
|
|
foreach (var skuConfigured in response.Data.PackTaskSkuPurchaseSchemeIdList) |
|
|
|
{ |
|
|
|
var orderSku = orderSkuList.FirstOrDefault(osku => osku.BelongSkuId == skuConfigured.SkuId); |
|
|
@ -160,9 +163,21 @@ namespace BBWYB.Server.Business |
|
|
|
updateOrderSkuList.Add(update); |
|
|
|
} |
|
|
|
|
|
|
|
if (qiKuPackState == Enums.PackConfigState.待配置) |
|
|
|
if (qiKuPackState == Enums.PackConfigState.待配置 && order.ShopId != 9) |
|
|
|
{ |
|
|
|
//创建合格证拟定任务
|
|
|
|
var t = new TimeLimitTask() |
|
|
|
{ |
|
|
|
CreateTme = DateTime.Now, |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
OrderId = order.Id, |
|
|
|
SkuId = orderSku.SkuId, |
|
|
|
OrderSn = order.OrderSn, |
|
|
|
ShopId = order.ShopId, |
|
|
|
TaskType = Enums.TimeLimitTaskType.合格证拟定任务, |
|
|
|
ExpirationTime = DateTime.Now.AddDays(1), |
|
|
|
}; |
|
|
|
insertTimeLimitTaskList.Add(t); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@ -173,13 +188,89 @@ namespace BBWYB.Server.Business |
|
|
|
foreach (var update in updateOrderSkuList) |
|
|
|
update.ExecuteAffrows(); |
|
|
|
} |
|
|
|
if (insertTimeLimitTaskList.Count() > 0) |
|
|
|
fsql.Insert(insertTimeLimitTaskList).ExecuteAffrows(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
catch (Exception ex) |
|
|
|
{ |
|
|
|
nLogManager.Default().Error(ex, $"SearchCerConfigured\r\n{JsonConvert.SerializeObject(new { orderId, packTaskSkuPurchaseSchemeIdList })}"); |
|
|
|
nLogManager.Default().Error(ex, $"SearchCerConfigured\r\n{JsonConvert.SerializeObject(new { order.Id, packTaskSkuPurchaseSchemeIdList })}"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// 齐库推送sku配置状态
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="request"></param>
|
|
|
|
public void QikuPublishOrderSkuPackConfigState(QikuPublishOrderSkuPackConfigStateRequest request) |
|
|
|
{ |
|
|
|
var order = fsql.Select<Order>(request.OrderId).ToOne(); |
|
|
|
if (order == null) |
|
|
|
throw new BusinessException($"未查询到订单{request.OrderId}"); |
|
|
|
|
|
|
|
if (request.PackConfigState == Enums.PackConfigState.需修改 && order.ShopId != 9) |
|
|
|
return; |
|
|
|
|
|
|
|
var orderSku = fsql.Select<OrderSku>().Where(osku => osku.OrderId == request.OrderId && osku.BelongSkuId == request.SkuId).ToOne(); |
|
|
|
if (orderSku == null) |
|
|
|
throw new BusinessException($"未查询到订单来源sku{request.SkuId}"); |
|
|
|
|
|
|
|
|
|
|
|
IInsert<TimeLimitTask> insertTimeLimitTask = null; |
|
|
|
IUpdate<TimeLimitTask> updateTimeLimitTask = null; |
|
|
|
IUpdate<OrderSku> updateOrderSku = null; |
|
|
|
|
|
|
|
if (orderSku.PackConfigState != request.PackConfigState) |
|
|
|
updateOrderSku = fsql.Update<OrderSku>(orderSku.Id).Set(osku => osku.PackConfigState, request.PackConfigState); |
|
|
|
|
|
|
|
if (request.PackConfigState == Enums.PackConfigState.需修改) |
|
|
|
{ |
|
|
|
var isExists = fsql.Select<TimeLimitTask>().Where(t => t.OrderId == request.OrderId && |
|
|
|
t.SkuId == orderSku.SkuId && |
|
|
|
t.TaskType == Enums.TimeLimitTaskType.合格证补充任务) |
|
|
|
.Any(); |
|
|
|
if (!isExists) |
|
|
|
{ |
|
|
|
var t = new TimeLimitTask() |
|
|
|
{ |
|
|
|
CreateTme = DateTime.Now, |
|
|
|
Id = idGenerator.NewLong(), |
|
|
|
OrderId = request.OrderId, |
|
|
|
SkuId = orderSku.SkuId, |
|
|
|
OrderSn = order.OrderSn, |
|
|
|
ShopId = order.ShopId, |
|
|
|
TaskType = Enums.TimeLimitTaskType.合格证补充任务 |
|
|
|
}; |
|
|
|
if (DateTime.Now.Hour < 16) |
|
|
|
t.ExpirationTime = DateTime.Now.AddHours(2); |
|
|
|
else |
|
|
|
t.ExpirationTime = DateTime.Now.Date.AddDays(1).AddHours(13); |
|
|
|
insertTimeLimitTask = fsql.Insert(t); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (request.PackConfigState == Enums.PackConfigState.已配置) |
|
|
|
{ |
|
|
|
var taskTypeList = new List<Enums.TimeLimitTaskType?>() |
|
|
|
{ |
|
|
|
Enums.TimeLimitTaskType.合格证拟定任务, |
|
|
|
Enums.TimeLimitTaskType.合格证补充任务 |
|
|
|
}; |
|
|
|
updateTimeLimitTask = fsql.Update<TimeLimitTask>().Set(t => t.CompletionTime, DateTime.Now) |
|
|
|
.Set(t => t.IsTimely == (DateTime.Now < t.ExpirationTime ? true : false)) |
|
|
|
.Where(t => t.OrderId == request.OrderId) |
|
|
|
.Where(t => t.SkuId == orderSku.SkuId) |
|
|
|
.Where(t => t.CompletionTime == null) |
|
|
|
.Where(t => taskTypeList.Contains(t.TaskType)); |
|
|
|
} |
|
|
|
|
|
|
|
fsql.Transaction(() => |
|
|
|
{ |
|
|
|
insertTimeLimitTask?.ExecuteAffrows(); |
|
|
|
updateTimeLimitTask?.ExecuteAffrows(); |
|
|
|
updateOrderSku?.ExecuteAffrows(); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|