1121 lines
70 KiB
C#
1121 lines
70 KiB
C#
|
using Api.Framework.Config;
|
|||
|
using Api.Framework.Cps;
|
|||
|
using Api.Framework.Enums;
|
|||
|
using Api.Framework.Events;
|
|||
|
using Api.Framework.Model;
|
|||
|
using Api.Framework.SDK;
|
|||
|
using Api.Framework.Tools;
|
|||
|
using Api.Framework.Utils;
|
|||
|
using CsharpHttpHelper;
|
|||
|
using Newtonsoft.Json;
|
|||
|
using SqlSugar;
|
|||
|
using System;
|
|||
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using System.Linq;
|
|||
|
using System.Text;
|
|||
|
using System.Threading;
|
|||
|
using System.Threading.Tasks;
|
|||
|
|
|||
|
namespace Api.Framework.Timers
|
|||
|
{
|
|||
|
/// <summary>
|
|||
|
/// 京东订单下载定时器
|
|||
|
/// </summary>
|
|||
|
public class DownJingdongTimer : TimerTask
|
|||
|
{
|
|||
|
|
|||
|
private static long number = 0;
|
|||
|
private DateTime update_time = DateTime.Now.AddHours(-2);
|
|||
|
public override void Run(object state, bool timedOut)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
number++;
|
|||
|
if (number % 30 == 0) update_time = DateTime.Now.AddHours(-12);
|
|||
|
else if (number % 100 == 0) update_time = DateTime.Now.AddHours(-24);
|
|||
|
else update_time = DateTime.Now.AddHours(-2);
|
|||
|
|
|||
|
var not_onlines = CpsClient.Members.Where(f => f.cpstype == CpsType.京东联盟 && f.abnormal_tip == SwitchType.开启 && !f.online).ToList();
|
|||
|
if (not_onlines != null && not_onlines.Count != 0)
|
|||
|
{
|
|||
|
foreach (var cps in not_onlines)
|
|||
|
{
|
|||
|
var key = $"jingdong_not_online_{cps.usernick}";
|
|||
|
var value = ApiClient.Cache.Get<string>(key);
|
|||
|
if (string.IsNullOrWhiteSpace(value))
|
|||
|
{
|
|||
|
var _session = ApiClient.GetSession();
|
|||
|
var robot = _session.FindRobots().FirstOrDefault();
|
|||
|
|
|||
|
StringBuilder strb = new StringBuilder();
|
|||
|
strb.AppendLine("京东状态异常");
|
|||
|
strb.AppendLine("---------------------");
|
|||
|
if (robot != null)
|
|||
|
strb.AppendLine("所在机器人:" + robot.name);
|
|||
|
|
|||
|
strb.AppendLine("京东ID:" + cps.usernick);
|
|||
|
strb.AppendLine();
|
|||
|
strb.AppendLine("解决方法:重新授权Key后,重新登录");
|
|||
|
//ApiClient.SendNewDingdingMessage(strb.ToString());
|
|||
|
ApiClient.SendNoticeMessage(strb.ToString());
|
|||
|
ApiClient.Cache.Set(key, ".", 300);
|
|||
|
Thread.Sleep(50);
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
UpdateOrder(CpsClient.Members.Where(f => f.cpstype == CpsType.京东联盟 && f.online && f.is_download == SwitchType.开启).ToArray(), update_time);
|
|||
|
|
|||
|
#region 更新冻结的订单
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
var result = session.Find<fl_order_jingdong>("db_status = @db_status and finishTime != @min and finishTime <= @now and db_endtime <= @endtime", new { db_status = 1001, min = DateTime.MinValue.ToString("yyyy-MM-dd HH:mm:ss"), now = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), endtime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });//所有完成冻结,但是还没改状态的订单,
|
|||
|
//var cpsnicks = result.Select(f => f.db_cpsnick).GroupBy(f => f).Select(f => f.Key).ToList();
|
|||
|
//TaskTool task = new TaskTool();
|
|||
|
|
|||
|
List<OrderNoticeEvent> notices = new List<OrderNoticeEvent>();
|
|||
|
|
|||
|
foreach (var order in result)
|
|||
|
{
|
|||
|
UpdateOrder(order, session, notices);
|
|||
|
}
|
|||
|
|
|||
|
//foreach (var _cpsnick in cpsnicks)
|
|||
|
//{
|
|||
|
//var cpsnick = _cpsnick;
|
|||
|
//var cps = CpsClient.Members.Where(f => f.cpstype == CpsType.京东联盟 && f.is_download == SwitchType.开启).ToList().FirstOrDefault(f => f.usernick == cpsnick);
|
|||
|
//if (cps == null) continue;
|
|||
|
//var client = new JingdongApi(cps);
|
|||
|
|
|||
|
//task.AddTask(delegate
|
|||
|
//{
|
|||
|
// try
|
|||
|
// {
|
|||
|
// var orderTimes = result.Where(f => f.db_cpsnick == cpsnick).Select(f => f.finishTime).OrderBy(f => f).ToList();
|
|||
|
// if (orderTimes.Count == 0) return;
|
|||
|
|
|||
|
// if (orderTimes != null && orderTimes.Count != 0)
|
|||
|
// {
|
|||
|
// var time = orderTimes[0];
|
|||
|
// List<DateTime> times = new List<DateTime>() { time };
|
|||
|
// do
|
|||
|
// {
|
|||
|
// time = time.AddHours(1);
|
|||
|
// var _time = orderTimes.FirstOrDefault(f => f > time);
|
|||
|
// if (_time != DateTime.MinValue)
|
|||
|
// {
|
|||
|
// time = _time;
|
|||
|
// times.Add(_time);
|
|||
|
// }
|
|||
|
// else
|
|||
|
// break;
|
|||
|
// } while (true);
|
|||
|
|
|||
|
// if (times.Count > 0)
|
|||
|
// {
|
|||
|
// foreach (var _time in times)
|
|||
|
// {
|
|||
|
// ProcessOrder(_time, client, notices);
|
|||
|
// }
|
|||
|
// }
|
|||
|
// }
|
|||
|
|
|||
|
// if (notices.Count != 0)
|
|||
|
// {
|
|||
|
// var tasks = TimerTask.GetTimer<Update_NoticeQueue>() as Update_NoticeQueue;
|
|||
|
// foreach (var item in notices)
|
|||
|
// {
|
|||
|
// if (item.Member == null) continue;
|
|||
|
// var order = item.Order as fl_order_jingdong;
|
|||
|
// if (order.orderId.ToString() == order_id) continue;
|
|||
|
// tasks.Add(item);
|
|||
|
// }
|
|||
|
// }
|
|||
|
|
|||
|
// }
|
|||
|
// catch (Exception ex)
|
|||
|
// {
|
|||
|
// EventClient.OnEvent(this, "更新阿里妈妈异常:" + ex.Message);
|
|||
|
// }
|
|||
|
//});
|
|||
|
//}
|
|||
|
//task.Start(1, null);
|
|||
|
|
|||
|
if (notices.Count != 0)
|
|||
|
{
|
|||
|
var tasks = TimerTask.GetTimer<Update_NoticeQueue>() as Update_NoticeQueue;
|
|||
|
foreach (var item in notices)
|
|||
|
{
|
|||
|
if (item.Member == null) continue;
|
|||
|
var order = item.Order as fl_order_jingdong;
|
|||
|
if (order.orderId.ToString() == order_id) continue;
|
|||
|
tasks.Add(item);
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
EventClient.OnEvent(this, $"更新京东异常:{ex.Message},{ex.StackTrace}");
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 手动同步订单
|
|||
|
/// </summary>
|
|||
|
/// <param name="member">京东cps对象集合</param>
|
|||
|
/// <param name="start_time">开始同步的时间</param>
|
|||
|
public void UpdateOrder(List<fl_cps_member> members, DateTime start_time)
|
|||
|
{
|
|||
|
foreach (var member in members)
|
|||
|
{
|
|||
|
if (!member.online)
|
|||
|
EventClient.OnEvent(this, $"【{member.usernick}】该账号失效,请重新生成京东联盟Key");
|
|||
|
}
|
|||
|
members = members.Where(f => f.online).ToList();
|
|||
|
if (IsRunning) throw new Exception("任务繁忙,请稍后重试!");
|
|||
|
try
|
|||
|
{
|
|||
|
IsRunning = true;
|
|||
|
//start_time = DateTime.Now.AddDays(-1);//TODO 由于调用量有限京东只能同步1天,以后要删除的
|
|||
|
UpdateOrder(members.ToArray(), start_time);
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
EventClient.OnEvent(this, "更新京东订单异常:" + ex.Message);
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
IsRunning = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 京东下载订单执行
|
|||
|
/// </summary>
|
|||
|
/// <param name="members">京东cps对象集合</param>
|
|||
|
/// <param name="start_time">开始同步的时间</param>
|
|||
|
private void UpdateOrder(fl_cps_member[] members, DateTime start_time)
|
|||
|
{
|
|||
|
if (members == null || members.Length == 0) return;
|
|||
|
int pageCount = 100;//下载每页的数量
|
|||
|
//var session = ApiClient.GetSession();
|
|||
|
TaskTool task = new TaskTool();
|
|||
|
List<OrderNoticeEvent> notices = new List<OrderNoticeEvent>();
|
|||
|
|
|||
|
foreach (var item in members)
|
|||
|
{
|
|||
|
var _item = item;
|
|||
|
var client = new JingdongApi(_item);
|
|||
|
|
|||
|
task.AddTask(delegate
|
|||
|
{
|
|||
|
var end_time = DateTime.Now;
|
|||
|
try
|
|||
|
{
|
|||
|
do
|
|||
|
{
|
|||
|
if (!ProcessOrder(end_time, client, notices).Result)
|
|||
|
{
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
//就近原则,先更新最近的
|
|||
|
end_time = end_time.AddHours(-1);
|
|||
|
|
|||
|
//多账号,多线程处理的时候,肯定有问题
|
|||
|
// start_time = start_time.AddHours(1); //增加一小时
|
|||
|
}
|
|||
|
while (end_time > start_time);//当前结束时间,必须大于启动时间,否则退出
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
if (ex.Message == "京东繁忙,请稍后再试")
|
|||
|
EventClient.OnEvent(this, "更新京东联盟订单异常:" + ex.Message + ",已终止操作");
|
|||
|
else
|
|||
|
EventClient.OnEvent(this, "更新京东联盟订单异常:" + ex.Message);
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
task.Start(1, null);
|
|||
|
|
|||
|
|
|||
|
if (notices.Count != 0)
|
|||
|
{
|
|||
|
var tasks = TimerTask.GetTimer<Update_NoticeQueue>() as Update_NoticeQueue;
|
|||
|
foreach (var item in notices)
|
|||
|
{
|
|||
|
if (item.Member == null) continue;
|
|||
|
var order = item.Order as fl_order_jingdong;
|
|||
|
if (order.orderId.ToString() == order_id) continue;
|
|||
|
tasks.Add(item);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 无效的订单类型
|
|||
|
/// </summary>
|
|||
|
private static List<int> InvalidValidCodes = new List<int>() { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 20, 21, 22, 23, 24, 25, 26, 27, 28 };
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 处理下载到的订单
|
|||
|
/// </summary>
|
|||
|
/// <param name="session"></param>
|
|||
|
/// <param name="time"></param>
|
|||
|
/// <param name="cps"></param>
|
|||
|
/// <param name="client"></param>
|
|||
|
/// <param name="notices"></param>
|
|||
|
private Task<bool> ProcessOrder(DateTime time, JingdongApi client, List<OrderNoticeEvent> notices)
|
|||
|
{
|
|||
|
Thread.Sleep(10);
|
|||
|
return Task.Run<bool>(() =>
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var cps = client.Member;
|
|||
|
#region 处理每一个小时的订单
|
|||
|
bool hasMore = false; //是否还有更多数据【true:还有数据;false:已查询完毕,没有数据】
|
|||
|
int page_index = 1; //当前查询的页数
|
|||
|
Dictionary<string, object> result = null;
|
|||
|
do
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
//订单时间查询类型(1:下单时间, 2:完成时间, 3:更新时间)
|
|||
|
#region 更新时间
|
|||
|
//2019-08-19 12:15:01
|
|||
|
result = client.DownOrder(time, cps.username, page_index, 500, 3);
|
|||
|
if (result == null) break;
|
|||
|
if (result["code"].ToString() != "200") throw new Exception($"京东订单下载失败 - 下单时间:{time.ToString("yyyy-MM-dd HH:mm:ss")} - {result["message"]}");
|
|||
|
if (result.ContainsKey("data"))
|
|||
|
{
|
|||
|
var orders = result["data"] as ArrayList;
|
|||
|
if (orders != null && orders.Count > 0)
|
|||
|
{
|
|||
|
int count = 1;
|
|||
|
foreach (Dictionary<string, object> order in orders)
|
|||
|
{
|
|||
|
count++;
|
|||
|
if (ApiClient.Setting.DbConfig.DatabaseType == DatabaseType.SQLITE && count % 10 == 0)
|
|||
|
Thread.Sleep(200);
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
try
|
|||
|
{
|
|||
|
if (order["orderId"].ToString() == "250364082656")
|
|||
|
{
|
|||
|
}
|
|||
|
|
|||
|
var db_orders = session.Find<fl_order_jingdong>("orderId = @orderId", new { orderId = order["orderId"].ToString() }).ToList();
|
|||
|
|
|||
|
//var orderTime = long.Parse(order["orderTime"].ToString());//下单时间
|
|||
|
//var finishTime = long.Parse(order["finishTime"].ToString());//完成时间
|
|||
|
var orderTime = string.IsNullOrWhiteSpace(order["orderTime"].ToString()) ? DateTime.MinValue : DateTime.Parse(order["orderTime"].ToString());//下单时间
|
|||
|
var finishTime = string.IsNullOrWhiteSpace(order["finishTime"].ToString()) ? DateTime.MinValue : DateTime.Parse(order["finishTime"].ToString());//完成时间
|
|||
|
var modifyTime = string.IsNullOrWhiteSpace(order["modifyTime"].ToString()) ? DateTime.MinValue : DateTime.Parse(order["modifyTime"].ToString());//更新时间,格式yyyy-MM-dd HH:mm:ss
|
|||
|
|
|||
|
//if (order["parentId"].ToString() != "0")//存在拆单数据
|
|||
|
//{ //父类ID非等于0的不处理
|
|||
|
//if (order.ContainsKey("skuList"))
|
|||
|
//if (order.ContainsKey("orderRowResp"))
|
|||
|
//{
|
|||
|
#region 是否是plus会员下单 plus
|
|||
|
int plus = 0;
|
|||
|
if (order.ContainsKey("plus")) plus = int.Parse(order["plus"].ToString());
|
|||
|
#endregion
|
|||
|
|
|||
|
//var skuList = order["orderRowResp"] as ArrayList;
|
|||
|
//foreach (Dictionary<string, object> sku in skuList)
|
|||
|
//{
|
|||
|
if (order.ContainsKey("estimateCosPrice") && double.Parse(order["estimateCosPrice"].ToString()) == 0) continue;
|
|||
|
if (order.ContainsKey("positionId"))
|
|||
|
{
|
|||
|
var positionId = order["positionId"].ToString();
|
|||
|
|
|||
|
if (ApiClient.Setting.SystemConfig.order_jingdong_download_set_pids == SwitchType.关闭)
|
|||
|
{
|
|||
|
if (!string.IsNullOrWhiteSpace(ApiClient.Setting.SystemConfig.order_jingdong_not_download_pid))
|
|||
|
{
|
|||
|
var pids = ApiClient.Setting.SystemConfig.order_jingdong_not_download_pid.Replace(",", ",").Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).Select(f => f.Trim()).ToList();
|
|||
|
var isExist = (pids.FirstOrDefault(f => f.EndsWith(positionId)) != null);
|
|||
|
if (ApiClient.Setting.SystemConfig.order_jingdong_down_type == DownAdzoneType.不下载推广位 && isExist)
|
|||
|
continue;
|
|||
|
else if (ApiClient.Setting.SystemConfig.order_jingdong_down_type == DownAdzoneType.只下载推广位 && !isExist)
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//var adzone = session.FindAdzoneInfos().Where(f => f.custom_type == "京东返利" && !string.IsNullOrEmpty(f.adzone_pid) && f.adzone_pid.EndsWith(positionId));
|
|||
|
|
|||
|
var adzoneList = new List<fl_adzone_info>();
|
|||
|
var adzones = session.FindAdzoneInfos();
|
|||
|
adzoneList.AddRange(adzones.Where(f => f.custom_type == "京东返利" && !string.IsNullOrEmpty(f.adzone_pid) && f.adzone_pid.EndsWith(positionId)));
|
|||
|
adzoneList.AddRange(adzones.Where(f => f.custom_type == "用户私人pid" && f.extend == "京东私人pid" && !string.IsNullOrEmpty(f.adzone_pid) && f.adzone_pid.EndsWith(positionId)));
|
|||
|
if (adzoneList == null || adzoneList.Count() == 0)
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//2021年1月26日 之前老版
|
|||
|
//sku维度的有效码(-1:未知,2.无效-拆单,3.无效-取消,4.无效-京东帮帮主订单,5.无效-账号异常,6.无效-赠品类目不返佣,7.无效-校园订单,8.无效-企业订单,9.无效-团购订单,10.无效-开增值税专用发票订单,11.无效-乡村推广员下单,13.无效-违规订单,14.无效-来源与备案网址不符,15.待付款,16.已付款,17.已完成,18.已结算(5.9号不再支持结算状态回写展示))
|
|||
|
|
|||
|
//-1:未知,2.无效-拆单,3.无效-取消,4.无效-京东帮帮主订单,5.无效-账号异常,6.无效-赠品类目不返佣,7.无效-校园订单,8.无效-企业订单,9.无效-团购订单,10.无效-开增值税专用发票订单,11.无效-乡村推广员下单,12.无效-自己推广自己下单,13.无效-违规订单,14.无效-来源与备案网址不符,15.待付款,16.已付款,17.已完成,18.已结算 //自定义 19.售后中 //自定义 20.结算后失效
|
|||
|
|
|||
|
//2021年1月26日 之后新版
|
|||
|
//sku维度的有效码(-1:未知,2.无效-拆单,3.无效-取消,4.无效-京东帮帮主订单,5.无效-账号异常,6.无效-赠品类目不返佣,7.无效-校园订单,8.无效-企业订单,9.无效-团购订单,11.无效-乡村推广员下单,13.无效-违规订单,14.无效-来源与备案网址不符,15.待付款,16.已付款,17.已完成(购买用户确认收货),20.无效-此复购订单对应的首购订单无效,21.无效-云店订单,22. 无效-PLUS会员佣金比例为0 19.售后中 //自定义
|
|||
|
|
|||
|
//2021年10月21日 之后新版
|
|||
|
//sku维度的有效码(-1:未知,2.无效 - 拆单,3.无效 - 取消,4.无效 - 京东帮帮主订单,5.无效 - 账号异常,6.无效 - 赠品类目不返佣,7.无效 - 校园订单,8.无效 - 企业订单,9.无效 - 团购订单,11.无效 - 乡村推广员下单,13.无效 - 违规订单,14.无效 - 来源与备案网址不符,15.待付款,16.已付款,17.已完成(购买用户确认收货),20.无效 - 此复购订单对应的首购订单无效,21.无效 - 云店订单,22.无效 - PLUS会员佣金比例为0,23.无效 - 支付有礼,24.已付定金,25. 违规订单-流量劫持,26. 违规订单-流量异常,27. 违规订单-违反京东平台规则,28. 违规订单-多笔交易异常 19.售后中 //自定义
|
|||
|
|
|||
|
var validCode = int.Parse(order["validCode"].ToString());
|
|||
|
var proPriceAmount = double.Parse(order["proPriceAmount"].ToString());
|
|||
|
|
|||
|
if (decimal.Parse(order["commissionRate"].ToString()) == 0m) continue; //无佣金的订单不下载(订单状态:已完成/已结算)
|
|||
|
|
|||
|
if (validCode != 2)//不处理拆单 - 无效
|
|||
|
{
|
|||
|
var jingdong_order = db_orders.FirstOrDefault(f => f.orderId == long.Parse(order["orderId"].ToString()) && f.skuId == long.Parse(order["skuId"].ToString()));
|
|||
|
if (jingdong_order != null) //订单存在 - 判断订单状态是否一样,一样不处理
|
|||
|
{
|
|||
|
var validCode_temp = jingdong_order.validCode;
|
|||
|
#region 存在售后订单
|
|||
|
//var _validCode = validCode;
|
|||
|
var frozenSkuNum = long.Parse(order["skuFrozenNum"].ToString());//商品售后中数量
|
|||
|
|
|||
|
var skuReturnNum = long.Parse(order["skuReturnNum"].ToString());//商品退货数量
|
|||
|
|
|||
|
if (frozenSkuNum != 0)//订单信息中存在维权的情况
|
|||
|
{
|
|||
|
if (jingdong_order.db_status != SystemOrderStatus.订单维权中)
|
|||
|
{
|
|||
|
//if (frozenSkuNum != 0)//这里判断是否为售后状态,数量为0时没有售后订单
|
|||
|
//{
|
|||
|
jingdong_order.frozenSkuNum = frozenSkuNum;//售后中的数量,这个变量不为空,实际佣金和实际计算佣金的金额会变成0
|
|||
|
jingdong_order.refundcreatetime = DateTime.Now;
|
|||
|
validCode = 19;
|
|||
|
//}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (jingdong_order.frozenSkuNum == frozenSkuNum)//维权数量一致时,跳过
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
else if (jingdong_order.skuReturnNum != skuReturnNum && validCode == 17 && jingdong_order.db_status != SystemOrderStatus.全额退款 && jingdong_order.db_status != SystemOrderStatus.部分退款)
|
|||
|
{
|
|||
|
jingdong_order.skuReturnNum = skuReturnNum;
|
|||
|
if (jingdong_order.db_status == SystemOrderStatus.订单结算)
|
|||
|
validCode = 20;
|
|||
|
}
|
|||
|
else//订单信息中不存在维权的情况,判断订单是已经结算
|
|||
|
{
|
|||
|
//if (jingdong_order.db_status != SystemOrderStatus.订单维权中)
|
|||
|
// if (jingdong_order.IsFinish()) continue;//是否已经完成
|
|||
|
|
|||
|
|
|||
|
if (jingdong_order.db_status != SystemOrderStatus.订单维权中)
|
|||
|
{
|
|||
|
if (jingdong_order.db_status == SystemOrderStatus.订单结算 && InvalidValidCodes.Contains(validCode) && validCode_temp != validCode)
|
|||
|
{
|
|||
|
validCode = 20;
|
|||
|
}
|
|||
|
else if (jingdong_order.IsFinish())//是否已经完成
|
|||
|
{
|
|||
|
continue;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
if (validCode_temp == validCode && jingdong_order.db_status != SystemOrderStatus.订单冻结)
|
|||
|
continue;
|
|||
|
|
|||
|
jingdong_order.validCode = validCode;//更新状态
|
|||
|
jingdong_order.finishTime = finishTime;
|
|||
|
jingdong_order.skuReturnNum = long.Parse(order["skuReturnNum"].ToString());//商品已退货数量
|
|||
|
jingdong_order.frozenSkuNum = long.Parse(order["skuFrozenNum"].ToString());//商品售后中数量
|
|||
|
|
|||
|
|
|||
|
#region 这里重新赋值实际的佣金和计算佣金的金额(
|
|||
|
//1、售后中两个金额将为0
|
|||
|
//2、订单收货后两个金额将有实际的佣金值)
|
|||
|
jingdong_order.actualFee = double.Parse(order["actualFee"].ToString());//实际佣金
|
|||
|
jingdong_order.actualCosPrice = double.Parse(order["actualCosPrice"].ToString());//实际计算佣金的金额
|
|||
|
#endregion
|
|||
|
|
|||
|
if (jingdong_order.db_status == SystemOrderStatus.订单维权中 && (jingdong_order.validCode == 17 || jingdong_order.validCode == 18))
|
|||
|
{
|
|||
|
jingdong_order.db_status = SystemOrderStatus.订单退款;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
if (order.ContainsKey("id"))
|
|||
|
order.Remove("id");
|
|||
|
|
|||
|
//订单不存在 - 增加
|
|||
|
jingdong_order = order.ConvertToObj<fl_order_jingdong>();
|
|||
|
jingdong_order.frozenSkuNum = long.Parse(order["skuFrozenNum"].ToString());
|
|||
|
//不保存,赠送商品
|
|||
|
if (jingdong_order.price == 0d) continue;
|
|||
|
|
|||
|
jingdong_order.orderId = long.Parse(order["orderId"].ToString());
|
|||
|
jingdong_order.db_cpsname = cps.username;
|
|||
|
jingdong_order.db_cpsnick = cps.usernick;
|
|||
|
jingdong_order.orderTime = orderTime;
|
|||
|
jingdong_order.finishTime = finishTime;
|
|||
|
//if (validCode == 16 || validCode == 24)
|
|||
|
// jingdong_order.db_status = SystemOrderStatus.订单付款;
|
|||
|
|
|||
|
#region 佣金比例京东联盟
|
|||
|
//var estimateFee = decimal.Round((decimal)jingdong_order.estimateCosPrice * (decimal)jingdong_order.commissionRate * (decimal)jingdong_order.finalRate, 2, MidpointRounding.AwayFromZero); ;//预计佣金
|
|||
|
//var actualFee = decimal.Round((decimal)jingdong_order.actualCosPrice * (decimal)jingdong_order.commissionRate * (decimal)jingdong_order.finalRate, 2, MidpointRounding.AwayFromZero);//实际佣金
|
|||
|
#endregion
|
|||
|
if (jingdong_order.frozenSkuNum != 0)
|
|||
|
{
|
|||
|
jingdong_order.refundcreatetime = DateTime.Now;
|
|||
|
jingdong_order.validCode = 19;
|
|||
|
}
|
|||
|
}
|
|||
|
jingdong_order.proPriceAmount = proPriceAmount;
|
|||
|
jingdong_order.plus = plus;
|
|||
|
UpdateOrder(jingdong_order, session, notices);
|
|||
|
}
|
|||
|
else //拆单订单变成无效
|
|||
|
{
|
|||
|
var jingdong_order = db_orders.FirstOrDefault(f => f.orderId == long.Parse(order["orderId"].ToString()) && f.skuId == long.Parse(order["skuId"].ToString()));
|
|||
|
if (jingdong_order != null)
|
|||
|
{
|
|||
|
if (jingdong_order.IsFinish()) continue;//是否已经完成
|
|||
|
jingdong_order.validCode = 2;
|
|||
|
jingdong_order.db_status = SystemOrderStatus.订单失效;
|
|||
|
session.SaveOrUpdate(jingdong_order);
|
|||
|
}
|
|||
|
}
|
|||
|
// }
|
|||
|
//}
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
throw ex;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
if (ex.Message == "京东key失效" || ex.Message == "授权key无权限或错误")
|
|||
|
{
|
|||
|
EventClient.OnEvent(this, $"更新京东联盟订单异常:{ex.Message} - {ex.StackTrace}");
|
|||
|
var _cps = CpsClient.Members.FirstOrDefault(f => f.cpstype == CpsType.京东联盟 && f.username == cps.username && f.usernick == cps.usernick);
|
|||
|
_cps.online = false;
|
|||
|
var session = ApiClient.GetSession();
|
|||
|
session.Updateable(_cps).ExecuteCommand();
|
|||
|
return false;
|
|||
|
}
|
|||
|
if (ex.Message == "京东繁忙,请稍后再试")
|
|||
|
throw ex;
|
|||
|
EventClient.OnEvent(this, $"同步京东订单列表出错:{ex.Message} - {ex.StackTrace}");
|
|||
|
}
|
|||
|
page_index++;
|
|||
|
Thread.Sleep(50); //请求接口太快,用于减速
|
|||
|
} while (result != null && result.Count != 0 && result.ContainsKey("hasMore") && result["hasMore"].ToString().ToLower() == "true");//是否存在更多的数据,存在去加载下一页数据
|
|||
|
#endregion
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
EventClient.OnEvent(this, $"同步京东出错:{ex.Message} - {ex.StackTrace}");
|
|||
|
return false;
|
|||
|
}
|
|||
|
return true;
|
|||
|
});
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 订单 修改状态/用户绑定等操作通知用户
|
|||
|
/// </summary>
|
|||
|
/// <param name="db_order">京东订单对象</param>
|
|||
|
/// <param name="session">数据库操作对象</param>
|
|||
|
/// <param name="notices">事件集合</param>
|
|||
|
/// <param name="isFrontData"></param>
|
|||
|
public void UpdateOrder(fl_order_jingdong db_order, SqlSugarClient session, List<OrderNoticeEvent> notices, bool isFrontData = false)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
//维权中的订单,直接跳出
|
|||
|
if (db_order.db_status == SystemOrderStatus.订单维权中)
|
|||
|
return;
|
|||
|
|
|||
|
var old_status = db_order.db_status;
|
|||
|
fl_member_info member = null;
|
|||
|
var isRewards = false;//是否获得推荐新人奖励
|
|||
|
var isFirstOrder = false;//是否获得用户首单奖励
|
|||
|
#region 缓存绑定
|
|||
|
if (db_order.db_userid == 0 && (db_order.validCode == 16 || db_order.validCode == 24))
|
|||
|
{
|
|||
|
var bind = session.FindBindCache(db_order.orderId.ToString());
|
|||
|
if (bind != null)
|
|||
|
{
|
|||
|
var memberInfo = session.FindMemberInfoById(bind.db_userid);
|
|||
|
if (memberInfo != null)
|
|||
|
{
|
|||
|
db_order.db_userid = memberInfo.id;
|
|||
|
db_order.db_robotname = memberInfo.robot_name;
|
|||
|
db_order.db_robottype = memberInfo.robot_type;
|
|||
|
db_order.msg_groupid = bind.groupid;
|
|||
|
session.SaveOrUpdate(memberInfo);
|
|||
|
|
|||
|
#region 获取查询时的比例
|
|||
|
var query_item = session.FindSingle<fl_query_hist>("userid=@userid and itemid=@itemid and adzoneid = @adzoneid and crt_time > @time order by id desc", new { userid = db_order.db_userid, itemid = db_order.skuId, adzoneid = db_order.positionId, time = DateTime.Now.AddHours(-24).ToString("yyyy-MM-dd HH:mm:ss") });
|
|||
|
if (query_item != null && !string.IsNullOrWhiteSpace(query_item.compute_configdic))
|
|||
|
{
|
|||
|
if (db_order.id == 0)
|
|||
|
session.SaveOrUpdate(db_order);
|
|||
|
var queryRatioHist = new fl_query_ratio_hist()
|
|||
|
{
|
|||
|
compute_config = query_item.compute_configdic,
|
|||
|
db_orderid = db_order.id,
|
|||
|
createtime = DateTime.Now,
|
|||
|
cpstype = CpsType.京东联盟
|
|||
|
};
|
|||
|
LogHelper.GetSingleObj().Error("历史查询记录1", JsonConvert.SerializeObject(queryRatioHist));
|
|||
|
session.SaveOrUpdate(queryRatioHist);
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
//订单自动绑定
|
|||
|
if (db_order.db_userid == 0 && (db_order.validCode == 16 || db_order.validCode == 24) && ApiClient.Setting.SystemConfig.order_jingdong_bind == SwitchType.开启)
|
|||
|
{
|
|||
|
#region 京东返利进行自动绑定
|
|||
|
|
|||
|
#region 私人推广位
|
|||
|
var privateAdzonePids = session.FindJingdongPrivatePid(db_order.positionId.ToString());//私人推广位对象
|
|||
|
//var privatePids = privateAdzonePids.Select(f => f.adzone_pid).ToList();
|
|||
|
if (privateAdzonePids.Count == 1 && privateAdzonePids[0].is_auto_bind)//无条件设置开启中,直接自动绑定
|
|||
|
{
|
|||
|
var memberInfo = session.Find<fl_member_info>("id=@id", new { id = privateAdzonePids[0].member_id }).FirstOrDefault();
|
|||
|
if (memberInfo != null)
|
|||
|
{
|
|||
|
db_order.db_userid = memberInfo.id;
|
|||
|
db_order.db_robotname = memberInfo.robot_name;
|
|||
|
db_order.db_robottype = memberInfo.robot_type;
|
|||
|
|
|||
|
#region 绑定群号
|
|||
|
if (string.IsNullOrWhiteSpace(db_order.msg_groupid))
|
|||
|
{
|
|||
|
var query_item = session.FindSingle<fl_query_hist>("userid=@userid and itemid=@itemid and adzoneid = @adzoneid and crt_time > @time order by id desc", new { userid = db_order.db_userid, itemid = db_order.skuId, adzoneid = db_order.positionId, time = DateTime.Now.AddHours(-24).ToString("yyyy-MM-dd HH:mm:ss") });
|
|||
|
if (query_item != null)
|
|||
|
{
|
|||
|
if (!string.IsNullOrWhiteSpace(query_item.compute_configdic))
|
|||
|
{
|
|||
|
if (db_order.id == 0)
|
|||
|
session.SaveOrUpdate(db_order);
|
|||
|
var queryRatioHist = new fl_query_ratio_hist()
|
|||
|
{
|
|||
|
compute_config = query_item.compute_configdic,
|
|||
|
db_orderid = db_order.id,
|
|||
|
createtime = DateTime.Now,
|
|||
|
cpstype = CpsType.京东联盟
|
|||
|
};
|
|||
|
LogHelper.GetSingleObj().Error("历史查询记录2", JsonConvert.SerializeObject(queryRatioHist));
|
|||
|
session.SaveOrUpdate(queryRatioHist);
|
|||
|
}
|
|||
|
db_order.msg_groupid = query_item.groupid;
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
else
|
|||
|
{
|
|||
|
var bind_pids = session.FindJingdongAutoBindPid();
|
|||
|
bind_pids.AddRange(privateAdzonePids.Select(f => f.adzone_pid));
|
|||
|
bool support = bind_pids.FirstOrDefault(f => f.EndsWith("_" + db_order.positionId)) != null ? true : false;//TODO 这里的站长ID还是完整的 xxx_x_xxx
|
|||
|
//bool support = bind_pids.FirstOrDefault(f => db_order.pid.StartsWith(f + "_")) != null ? true : false;//这里的站长ID还是完整的 xxx_x_xxx
|
|||
|
|
|||
|
if (support)
|
|||
|
{
|
|||
|
#region 通过查询记录找用户
|
|||
|
var query = session.FindTable("select userid,count(*) as count from fl_query_hist where itemid=@itemid and adzoneid = @adzoneid and crt_time>@time group by userid ", new { itemid = db_order.skuId, adzoneid = db_order.positionId, time = DateTime.Now.AddHours(-24).ToString("yyyy-MM-dd HH:mm:ss") });
|
|||
|
if (query.Rows.Count == 1)
|
|||
|
{
|
|||
|
db_order.db_userid = int.Parse(query.Rows[0]["userid"].ToString()); //根据查询记录认领
|
|||
|
var query_item = session.FindSingle<fl_query_hist>("userid=@userid and itemid=@itemid and adzoneid = @adzoneid and crt_time > @time order by id desc", new { userid = db_order.db_userid, itemid = db_order.skuId, adzoneid = db_order.positionId, time = DateTime.Now.AddHours(-24).ToString("yyyy-MM-dd HH:mm:ss") });
|
|||
|
if (query_item != null)
|
|||
|
{
|
|||
|
if (!string.IsNullOrWhiteSpace(query_item.compute_configdic))
|
|||
|
{
|
|||
|
if (db_order.id == 0)
|
|||
|
session.SaveOrUpdate(db_order);
|
|||
|
var queryRatioHist = new fl_query_ratio_hist()
|
|||
|
{
|
|||
|
compute_config = query_item.compute_configdic,
|
|||
|
db_orderid = db_order.id,
|
|||
|
createtime = DateTime.Now,
|
|||
|
cpstype = CpsType.京东联盟
|
|||
|
};
|
|||
|
LogHelper.GetSingleObj().Error("历史查询记录3", JsonConvert.SerializeObject(queryRatioHist));
|
|||
|
session.SaveOrUpdate(queryRatioHist);
|
|||
|
}
|
|||
|
|
|||
|
db_order.msg_groupid = query_item.groupid; //订单查询群号
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
if ((db_order.validCode == 16 || db_order.validCode == 24) && db_order.db_userid != 0)
|
|||
|
{
|
|||
|
try
|
|||
|
{
|
|||
|
var record = session.FindStatisticsRecord(db_order.db_userid);
|
|||
|
if (record == null)
|
|||
|
record = new fl_statistics_record() { uid = db_order.db_userid };
|
|||
|
record.ex5 = HttpExtend.GetTimeStamp(db_order.orderTime);
|
|||
|
session.Saveable(record).ExecuteCommand();
|
|||
|
}
|
|||
|
catch (Exception)
|
|||
|
{ }
|
|||
|
}
|
|||
|
|
|||
|
member = db_order.db_userid != 0 ? session.FindSingle<fl_member_info>("select * from fl_member_info where id=@id", new { id = db_order.db_userid }) : null;
|
|||
|
if (string.IsNullOrEmpty(db_order.db_robotname) && member != null) //订单没有绑定机器人账号 & 用户存在 (进行机器人账号和机器人类型绑定)
|
|||
|
{
|
|||
|
member.username = member.username;
|
|||
|
db_order.db_robotname = member.robot_name;
|
|||
|
db_order.db_robottype = member.robot_type;
|
|||
|
}
|
|||
|
|
|||
|
var status = Util.ConvertEnum<JingdongOrderStatus>(db_order.validCode);
|
|||
|
|
|||
|
//if (string.IsNullOrEmpty(db_order.db_point)) //进行用户所得佣金计算
|
|||
|
//{
|
|||
|
|
|||
|
#region 积分随着订单状态的改变而改变
|
|||
|
double fee = 0d; //实际佣金和预计佣金
|
|||
|
switch (status)
|
|||
|
{
|
|||
|
case JingdongOrderStatus.未知:
|
|||
|
case JingdongOrderStatus.无效_拆单:
|
|||
|
case JingdongOrderStatus.无效_取消:
|
|||
|
case JingdongOrderStatus.无效_京东帮帮主订单:
|
|||
|
case JingdongOrderStatus.无效_账号异常:
|
|||
|
case JingdongOrderStatus.无效_赠品类目不返佣:
|
|||
|
case JingdongOrderStatus.无效_校园订单:
|
|||
|
case JingdongOrderStatus.无效_企业订单:
|
|||
|
case JingdongOrderStatus.无效_团购订单:
|
|||
|
case JingdongOrderStatus.无效_开增值税专用发票订单:
|
|||
|
case JingdongOrderStatus.无效_乡村推广员下单:
|
|||
|
case JingdongOrderStatus.无效_自己推广自己下单:
|
|||
|
case JingdongOrderStatus.无效_违规订单:
|
|||
|
case JingdongOrderStatus.无效_来源与备案网址不符:
|
|||
|
fee = db_order.estimateFee;//订单取消这里使用 预估佣金
|
|||
|
break;
|
|||
|
case JingdongOrderStatus.结算后失效:
|
|||
|
case JingdongOrderStatus.已完成:
|
|||
|
case JingdongOrderStatus.已结算:
|
|||
|
//if (db_order.proPriceAmount == 0)
|
|||
|
fee = (db_order.actualFee != 0 ? db_order.actualFee : db_order.estimateFee); //实际佣金
|
|||
|
//else
|
|||
|
// fee = 0;//价保赔付金额不为空,将佣金设置为0;...搞不清楚这个是什么完样
|
|||
|
break;
|
|||
|
case JingdongOrderStatus.待付款:
|
|||
|
case JingdongOrderStatus.已付款:
|
|||
|
case JingdongOrderStatus.售后中:
|
|||
|
case JingdongOrderStatus.已付定金:
|
|||
|
fee = db_order.estimateFee; //预计佣金
|
|||
|
break;
|
|||
|
default:
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
ItemPoint itempoint = null;
|
|||
|
|
|||
|
if (db_order.db_status != SystemOrderStatus.订单冻结)
|
|||
|
{
|
|||
|
//查询历史查询比例
|
|||
|
var compute = session.FindQueryRatioHist(CpsType.京东联盟, db_order.id);
|
|||
|
|
|||
|
if (compute != null)
|
|||
|
itempoint = session.FindItemPoint(CpsType.京东联盟, compute, fee, (int)db_order.skuNum);
|
|||
|
else
|
|||
|
itempoint = session.FindItemPoint(member, fee, (int)db_order.skuNum, CpsType.京东联盟);
|
|||
|
if (itempoint != null)
|
|||
|
{
|
|||
|
if (itempoint.UserPoint == 0 && ApiClient.Setting.SystemConfig.SubsidyJd == SwitchType.开启)
|
|||
|
itempoint.UserPoint = 0.01;
|
|||
|
db_order.db_point = HttpHelper.ObjectToJson(itempoint);
|
|||
|
db_order.db_userpoint = itempoint.UserPoint;
|
|||
|
}
|
|||
|
if (db_order.db_status == SystemOrderStatus.订单付款 && member != null)
|
|||
|
{
|
|||
|
member.bind_order++;
|
|||
|
member = session.UpdateMemberGroup(member);
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
itempoint = HttpHelper.JsonToObject<ItemPoint>(db_order.db_point) as ItemPoint;
|
|||
|
#endregion
|
|||
|
|
|||
|
//}
|
|||
|
|
|||
|
switch (status)
|
|||
|
{
|
|||
|
case JingdongOrderStatus.已完成:
|
|||
|
case JingdongOrderStatus.已结算:
|
|||
|
{
|
|||
|
if (db_order.actualCosPrice == 0d && db_order.skuNum == db_order.skuReturnNum)
|
|||
|
{
|
|||
|
db_order.db_status = SystemOrderStatus.全额退款;
|
|||
|
db_order.db_endtime = DateTime.Now.AddMinutes(-1);
|
|||
|
//old_status = SystemOrderStatus.全额退款; //不处理,不通知用户
|
|||
|
}
|
|||
|
if (db_order.db_status != SystemOrderStatus.全额退款)
|
|||
|
{
|
|||
|
if (db_order.db_endtime == DateTime.MinValue) //客户还没有结算
|
|||
|
{
|
|||
|
var sleep = session.FindSleep(CpsType.京东联盟, ApiClient.Setting.SystemConfig.FreezingCondition == FreezingConditionType.商品总佣金 ? db_order.actualFee : db_order.db_userpoint); //计算延迟冻结时间
|
|||
|
if (sleep != null)
|
|||
|
{
|
|||
|
if (!string.IsNullOrEmpty(sleep.white_groups))
|
|||
|
{
|
|||
|
if (member != null && sleep.white_groups.Split(',').Contains(member.group_id.ToString()))
|
|||
|
{
|
|||
|
db_order.db_endtime = DateTime.Now; //该会员组不受限制
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
db_order.db_endtime = DateTime.Now.AddHours(sleep.sleep); //延迟多少小时
|
|||
|
}
|
|||
|
}
|
|||
|
else db_order.db_endtime = DateTime.Now.AddHours(sleep.sleep); //延迟多少小时
|
|||
|
}
|
|||
|
else db_order.db_endtime = DateTime.Now;
|
|||
|
}
|
|||
|
|
|||
|
if (db_order.db_endtime > DateTime.Now) //佣金解冻
|
|||
|
{
|
|||
|
db_order.db_status = SystemOrderStatus.订单冻结;
|
|||
|
//if (db_order.actualCosPrice == 0d)
|
|||
|
//{
|
|||
|
// db_order.db_status = SystemOrderStatus.全额退款;
|
|||
|
// db_order.db_endtime = DateTime.Now.AddMinutes(-1);
|
|||
|
// //old_status = SystemOrderStatus.全额退款; //不处理,不通知用户
|
|||
|
//}
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
db_order.db_status = SystemOrderStatus.订单结算;
|
|||
|
|
|||
|
//if (db_order.skuReturnNum == db_order.skuNum && db_order.actualCosPrice == 0d)
|
|||
|
// db_order.db_status = SystemOrderStatus.全额退款;
|
|||
|
////else if (db_order.skuReturnNum != db_order.skuNum)
|
|||
|
//// db_order.db_status = SystemOrderStatus.部分退款;
|
|||
|
|
|||
|
session.SaveOrUpdate(db_order);
|
|||
|
if (member != null)
|
|||
|
{
|
|||
|
if (itempoint != null)
|
|||
|
{
|
|||
|
List<long> ids = new List<long>();
|
|||
|
ids.Add(member.id);
|
|||
|
//用户自身加积分
|
|||
|
member = session.ChangePoint(PointType.消费补贴, itempoint.UserPoint, member.id, $"京东购买:{db_order.skuName}({db_order.orderId})");
|
|||
|
|
|||
|
#region 判断用户是否符合获得新人奖励
|
|||
|
isFirstOrder = OrderHelper.CheckMemberFirstOrderRewards(member, db_order.db_status);
|
|||
|
#endregion
|
|||
|
|
|||
|
//多级提成计算
|
|||
|
//一级的提成小于等于0时,并且判断一级是否符合获得推荐新人奖励(无奖励一级提成)
|
|||
|
if (itempoint.AwardOne <= 0 && member.inviter_id > 0 && !ids.Contains(member.inviter_id) && member.id != member.inviter_id)
|
|||
|
{
|
|||
|
if (notices != null)
|
|||
|
{
|
|||
|
var inviter = session.FindMemberInfoById(member.inviter_id);
|
|||
|
if (inviter != null)
|
|||
|
{
|
|||
|
#region 判断上级是否符合获得推荐新人奖励
|
|||
|
isRewards = OrderHelper.CheckSuperiorInviteRewards(member, db_order.db_endtime, db_order.estimateCosPrice);
|
|||
|
#endregion
|
|||
|
|
|||
|
notices.Add(new OrderNoticeEvent(CpsType.京东联盟, inviter, db_order, OrderNoticeType.一级提成) { Customer = member, IsRewards = isRewards });//下级首单完成
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
else if (itempoint.AwardOne > 0 && !ids.Contains(member.inviter_id) && member.id != member.inviter_id)
|
|||
|
{
|
|||
|
var flag = session.ChangePoint(PointType.提成奖励, itempoint.AwardOne, member.inviter_id, $"{member.usernick},京东购物1级提成! - {db_order.skuName}({db_order.orderId})");
|
|||
|
if (flag != null)
|
|||
|
{
|
|||
|
ids.Add(flag.id);
|
|||
|
|
|||
|
#region 判断上级是否符合获得推荐新人奖励
|
|||
|
isRewards = OrderHelper.CheckSuperiorInviteRewards(member, db_order.db_endtime, db_order.estimateCosPrice);
|
|||
|
#endregion
|
|||
|
|
|||
|
notices.Add(new OrderNoticeEvent(CpsType.京东联盟, flag, db_order, OrderNoticeType.一级提成) { Customer = member, IsRewards = isRewards });
|
|||
|
|
|||
|
if (itempoint.AwardTwo > 0 && flag.inviter_id != 0 && !ids.Contains(flag.inviter_id))
|
|||
|
{
|
|||
|
var flag2 = session.ChangePoint(PointType.提成奖励, itempoint.AwardTwo, flag.inviter_id, $"{member.usernick},京东购物2级提成! - {db_order.skuName}({db_order.orderId})");
|
|||
|
if (flag2 != null)
|
|||
|
{
|
|||
|
ids.Add(flag2.id);
|
|||
|
if (flag2 != null)
|
|||
|
{
|
|||
|
notices.Add(new OrderNoticeEvent(CpsType.京东联盟, flag2, db_order, OrderNoticeType.二级提成) { Customer = member });
|
|||
|
|
|||
|
if (itempoint.AwardThree > 0 && flag2.inviter_id != 0 && !ids.Contains(flag2.inviter_id))
|
|||
|
{
|
|||
|
var flag3 = session.ChangePoint(PointType.提成奖励, itempoint.AwardThree, flag2.inviter_id, $"{member.usernick},京东购物3级提成! - {db_order.skuName}({db_order.orderId})");
|
|||
|
if (flag3 != null)
|
|||
|
{
|
|||
|
ids.Add(flag3.id);
|
|||
|
if (flag3 != null) notices.Add(new OrderNoticeEvent(CpsType.京东联盟, flag3, db_order, OrderNoticeType.三级提成) { Customer = member });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//创建人计算
|
|||
|
if (itempoint.AwardCreate > 0 && !string.IsNullOrEmpty(db_order.msg_groupid) && !string.IsNullOrEmpty(db_order.db_robotname))
|
|||
|
{
|
|||
|
var robot = session.FindRobotInfo(db_order.db_robotname, db_order.db_robottype);
|
|||
|
if (robot != null)
|
|||
|
{
|
|||
|
var create = session.FindCreateInfo(db_order.msg_groupid, db_order.db_robottype);
|
|||
|
if (create != null && member.id != create.id)
|
|||
|
{
|
|||
|
var flag = session.ChangePoint(PointType.提成奖励, itempoint.AwardCreate, create.mid, $"{member.usernick},京东维护提成! - {db_order.skuName}({db_order.orderId})");
|
|||
|
if (flag != null) notices.Add(new OrderNoticeEvent(CpsType.京东联盟, flag, db_order, OrderNoticeType.群主分成) { Customer = member });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
}
|
|||
|
case JingdongOrderStatus.售后中:
|
|||
|
case JingdongOrderStatus.结算后失效:
|
|||
|
{
|
|||
|
if (status == JingdongOrderStatus.结算后失效)
|
|||
|
{
|
|||
|
if (db_order.actualCosPrice == 0d && db_order.skuNum == db_order.skuReturnNum)
|
|||
|
{
|
|||
|
db_order.db_status = SystemOrderStatus.全额退款;
|
|||
|
db_order.db_endtime = DateTime.Now.AddMinutes(-1);
|
|||
|
//old_status = SystemOrderStatus.全额退款; //不处理,不通知用户
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
db_order.db_status = SystemOrderStatus.订单失效;
|
|||
|
db_order.validCode = 2;
|
|||
|
}
|
|||
|
}
|
|||
|
else
|
|||
|
db_order.db_status = SystemOrderStatus.订单维权中;
|
|||
|
|
|||
|
if (member != null)//订单还没有绑定用户
|
|||
|
{
|
|||
|
if (db_order.db_endtime != DateTime.MinValue) //客户已经在冻结中
|
|||
|
{
|
|||
|
if (db_order.db_endtime <= DateTime.Now) //佣金已经解冻 - 已经把佣金给客户(需要扣除佣金)
|
|||
|
{
|
|||
|
ItemPoint itempointTmp = null;
|
|||
|
|
|||
|
var compute = session.FindQueryRatioHist(CpsType.京东联盟, db_order.id);
|
|||
|
|
|||
|
if (compute != null)
|
|||
|
itempointTmp = session.FindItemPoint(CpsType.京东联盟, compute, (db_order.actualFee != 0 ? db_order.actualFee : db_order.estimateFee), (int)db_order.skuNum);
|
|||
|
else
|
|||
|
//判断用户的订单是否已经结算,如果已经结算通过实际佣金进行退款,如果没有结算通过预计佣进行计算
|
|||
|
itempointTmp = session.FindItemPoint(member, (db_order.actualFee != 0 ? db_order.actualFee : db_order.estimateFee), (int)db_order.skuNum, CpsType.京东联盟);
|
|||
|
new OrderHelper().DeductJingDongOrderPoint(notices, db_order, itempointTmp);
|
|||
|
}
|
|||
|
else
|
|||
|
{
|
|||
|
//if (itempoint != null)
|
|||
|
//{
|
|||
|
// //用户自身加积分
|
|||
|
// //member = session.ChangePoint(PointType.维权扣除, itempoint.UserPoint, member.id, $"京东购买:{db_order.skuName}({db_order.orderId}) - 售后中(扣除) - 订单还未结算(冻结中)");
|
|||
|
//}
|
|||
|
}
|
|||
|
}
|
|||
|
db_order.db_endtime = DateTime.MinValue;
|
|||
|
}
|
|||
|
}
|
|||
|
break;
|
|||
|
case JingdongOrderStatus.已付款:
|
|||
|
case JingdongOrderStatus.已付定金:
|
|||
|
{
|
|||
|
db_order.db_status = SystemOrderStatus.订单付款;
|
|||
|
}
|
|||
|
break;
|
|||
|
case JingdongOrderStatus.无效_乡村推广员下单:
|
|||
|
case JingdongOrderStatus.无效_京东帮帮主订单:
|
|||
|
case JingdongOrderStatus.无效_企业订单:
|
|||
|
case JingdongOrderStatus.无效_取消:
|
|||
|
case JingdongOrderStatus.无效_团购订单:
|
|||
|
case JingdongOrderStatus.无效_开增值税专用发票订单:
|
|||
|
case JingdongOrderStatus.无效_拆单:
|
|||
|
case JingdongOrderStatus.无效_来源与备案网址不符:
|
|||
|
case JingdongOrderStatus.无效_校园订单:
|
|||
|
case JingdongOrderStatus.无效_自己推广自己下单:
|
|||
|
case JingdongOrderStatus.无效_账号异常:
|
|||
|
case JingdongOrderStatus.无效_赠品类目不返佣:
|
|||
|
case JingdongOrderStatus.无效_违规订单:
|
|||
|
case JingdongOrderStatus.违规订单流量劫持:
|
|||
|
case JingdongOrderStatus.违规订单流量异常:
|
|||
|
case JingdongOrderStatus.违规订单违反京东平台规则:
|
|||
|
case JingdongOrderStatus.违规订单多笔交易异常:
|
|||
|
db_order.db_status = SystemOrderStatus.订单失效;
|
|||
|
break;
|
|||
|
case JingdongOrderStatus.待付款:
|
|||
|
db_order.db_status = SystemOrderStatus.订单创建;
|
|||
|
break;
|
|||
|
//case JingdongOrderStatus.已完成:
|
|||
|
// break;
|
|||
|
default:
|
|||
|
db_order.db_status = SystemOrderStatus.订单未知;
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
#region 通知客户订单付款/失效 提示上级
|
|||
|
if (member != null && (db_order.db_status == SystemOrderStatus.订单付款 || db_order.db_status == SystemOrderStatus.订单失效))
|
|||
|
{
|
|||
|
var point = HttpHelper.JsonToObject<ItemPoint>(db_order.db_point) as ItemPoint;
|
|||
|
if (point != null)
|
|||
|
{
|
|||
|
List<long> ids = new List<long>();
|
|||
|
ids.Add(member.id);
|
|||
|
|
|||
|
if (point.AwardOne > 0 && member.inviter_id > 0 && !ids.Contains(member.inviter_id) && member.id != member.inviter_id)
|
|||
|
{
|
|||
|
//一级用户对象
|
|||
|
var member_one = session.FindMemberInfoById(member.inviter_id);
|
|||
|
if (member_one != null)
|
|||
|
{
|
|||
|
ids.Add(member_one.id);
|
|||
|
if (notices != null)
|
|||
|
notices.Add(new OrderNoticeEvent(CpsType.京东联盟, member_one, db_order, OrderNoticeType.一级提成) { Customer = member });
|
|||
|
if (point.AwardTwo > 0 && member_one.inviter_id != 0 && !ids.Contains(member_one.inviter_id))
|
|||
|
{
|
|||
|
//二级用户对象
|
|||
|
var member_two = session.FindMemberInfoById(member_one.inviter_id);
|
|||
|
if (member_two != null)
|
|||
|
{
|
|||
|
ids.Add(member_two.id);
|
|||
|
if (notices != null && member_two != null)
|
|||
|
{
|
|||
|
notices.Add(new OrderNoticeEvent(CpsType.京东联盟, member_two, db_order, OrderNoticeType.二级提成) { Customer = member });
|
|||
|
|
|||
|
if (point.AwardThree > 0 && member_two.inviter_id != 0 && !ids.Contains(member_two.inviter_id))
|
|||
|
{
|
|||
|
//三级用户对象
|
|||
|
var member_three = session.FindMemberInfoById(member_two.inviter_id);
|
|||
|
if (member_three != null)
|
|||
|
{
|
|||
|
ids.Add(member_three.id);
|
|||
|
if (notices != null && member_three != null)
|
|||
|
notices.Add(new OrderNoticeEvent(CpsType.京东联盟, member_three, db_order, OrderNoticeType.三级提成) { Customer = member });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
//创建人计算
|
|||
|
if (point.AwardCreate > 0 && !string.IsNullOrEmpty(db_order.msg_groupid) && !string.IsNullOrEmpty(db_order.db_robotname))
|
|||
|
{
|
|||
|
var create = session.FindCreateInfo(db_order.msg_groupid, db_order.db_robottype);
|
|||
|
if (create != null && member.id != create.id)
|
|||
|
{
|
|||
|
var member_create = session.FindMemberInfoById(create.mid);
|
|||
|
if (notices != null && member_create != null) notices.Add(new OrderNoticeEvent(CpsType.京东联盟, member_create, db_order, OrderNoticeType.群主分成) { Customer = member });
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
#endregion
|
|||
|
|
|||
|
if (old_status != db_order.db_status)
|
|||
|
db_order.db_status_time = HttpExtend.GetTimeStamp();
|
|||
|
session.SaveOrUpdate(db_order);
|
|||
|
|
|||
|
if (db_order.db_status == SystemOrderStatus.订单付款)
|
|||
|
{
|
|||
|
#region 判断用户是否符合获得新人奖励
|
|||
|
isFirstOrder = OrderHelper.CheckMemberFirstOrderRewards(member, db_order.db_status);
|
|||
|
#endregion
|
|||
|
}
|
|||
|
|
|||
|
//if (notices != null && old_status != db_order.db_status)
|
|||
|
// notices.Add(new Events.OrderNoticeEvent(CpsType.京东联盟, member, db_order, OrderNoticeType.客户订单));
|
|||
|
if (notices != null && member != null && (isFrontData || old_status != db_order.db_status))
|
|||
|
notices.Add(new Events.OrderNoticeEvent(CpsType.京东联盟, member, db_order) { IsRewards = isFirstOrder });
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
EventClient.OnEvent(this, "更新京东订单错误 - 更新状态/订单绑定:" + db_order.orderId + "," + ex.Message + "," + ex.StackTrace);
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 订单id
|
|||
|
/// </summary>
|
|||
|
private string order_id = string.Empty;
|
|||
|
|
|||
|
/// <summary>
|
|||
|
/// 更新订单
|
|||
|
/// </summary>
|
|||
|
/// <param name="start_time">开始时间</param>
|
|||
|
/// <param name="order_id">订单id</param>
|
|||
|
/// <returns></returns>
|
|||
|
internal bool UpdateOrder(DateTime start_time, string order_id = "")
|
|||
|
{
|
|||
|
if (IsRunning) throw new Exception("任务繁忙,请稍后重试!");
|
|||
|
try
|
|||
|
{
|
|||
|
IsRunning = true;
|
|||
|
this.order_id = order_id;
|
|||
|
var members = CpsClient.Members.Where(f => f.cpstype == CpsType.京东联盟 && f.is_download == SwitchType.开启 && f.online).ToArray();
|
|||
|
UpdateOrder(members, start_time);
|
|||
|
return true;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
EventClient.OnEvent(this, "更新京东联盟异常:" + ex.Message + "," + ex.StackTrace);
|
|||
|
return false;
|
|||
|
}
|
|||
|
finally
|
|||
|
{
|
|||
|
this.order_id = string.Empty;
|
|||
|
IsRunning = false;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
}
|
|||
|
}
|