old_flsystem/FLSystem/Forms/cps_order_alimama.cs

1310 lines
58 KiB
C#
Raw Normal View History

2022-09-20 03:10:29 +00:00
using Api.Framework;
using Api.Framework.Enums;
using Api.Framework.Events;
using Api.Framework.Model;
using Api.Framework.SDK;
using Api.Framework.Timers;
using Api.Framework.Tools;
using CsharpHttpHelper;
using DevExpress.XtraEditors;
using FLSystem.Events;
using SqlSugar;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UI.Framework.Forms;
using static Api.Framework.Cps.AlimamaApi;
namespace FLSystem.Forms
{
public partial class cps_order_alimama : DevExpress.XtraEditors.XtraUserControl
{
public class view_cps_order_alimama
{
/// <summary>
/// id
/// </summary>
public long id { get; set; }
/// <summary>
/// 商品标题
/// </summary>
public string item_title { get; set; }
/// <summary>
/// 购买数量
/// </summary>
public string num_iid { get; set; }
/// <summary>
/// 实际付款
/// </summary>
public double pay_price { get; set; }
/// <summary>
/// 实际总共佣金
/// </summary>
public double commission { get; set; }
/// <summary>
/// 订单父id
/// </summary>
public string trade_parent_id { get; set; }
/// <summary>
/// 订单子id
/// </summary>
public string trade_id { get; set; }
/// <summary>
/// 订单状态
/// </summary>
public SystemOrderStatus db_status { get; set; }
private string _robotname;
/// <summary>
/// 机器人微信号
/// </summary>
public string robotname
{
get { return _robotname; }
set { if (string.IsNullOrEmpty(value)) _robotname = string.Empty; else _robotname = value; }
}
/// <summary>
/// 机器人昵称
/// </summary>
public string robotnick { get; set; }
private string _username;
/// <summary>
/// 用户账号
/// </summary>
public string username
{
get { return _username; }
set { if (string.IsNullOrEmpty(value)) _username = string.Empty; else _username = value; }
}
private string _usernick;
/// <summary>
/// 用户昵称
/// </summary>
public string usernick
{
get { return _usernick; }
set { if (string.IsNullOrEmpty(value)) _usernick = string.Empty; else _usernick = value; }
}
public long db_userid { get; set; }
/// <summary>
/// 订单类型
/// </summary>
public string order_type { get; set; }
/// <summary>
/// 总佣金
/// </summary>
public double pub_share_pre_fee { get; set; }
/// <summary>
/// 付款金额
/// </summary>
public double alipay_total_price { get; set; }
/// <summary>
/// 商品单价
/// </summary>
public double price { get; set; }
/// <summary>
/// 购买数量
/// </summary>
public int item_num { get; set; }
/// <summary>
/// 推广位
/// </summary>
public string adzone_id { get; set; }
/// <summary>
/// 创建时间
/// </summary>
public DateTime create_time { get; set; }
public string db_point { get; set; }
/// <summary>
/// 联盟账号
/// </summary>
public string db_cpsname { get; set; }
/// <summary>
/// 联盟昵称
/// </summary>
public string db_cpsnick { get; set; }
/// <summary>
/// 冻结时间
/// </summary>
public DateTime db_endtime { get; set; }
/// <summary>
/// 显示返回的费用
/// </summary>
public double showReturnFee { get; set; }
/// <summary>
/// 退款手续费
/// </summary>
public double refundFee { get; set; }
/// <summary>
/// 卖方编码
/// </summary>
public string seller_id { get; set; }
/// <summary>
/// 预付款金额
/// </summary>
public string deposit_price { get; set; }
/// <summary>
/// 预售时期,用户对预售商品支付定金的付款时间
/// </summary>
public string tb_deposit_time { get; set; }
/// <summary>
/// 联盟技术费用比率
/// </summary>
public double alimama_rate { get; set; }
/// <summary>
/// 联盟技术费用
/// </summary>
public double alimama_share_fee { get; set; }
/// <summary>
///
/// </summary>
public string auction_category { get; set; }
}
public cps_order_alimama(string textedit = "")
{
try
{
InitializeComponent();
var session = ApiClient.GetSession();
this.textEdit1.Text = textedit;
this.comboBoxEdit1.SelectedIndex = string.IsNullOrEmpty(textedit) ? 0 : 5;
this.dateTimePicker1.Value = DateTime.Parse(DateTime.Today.AddDays(-30).ToString("yyyy-MM-01"));
this.dateTimePicker2.Value = DateTime.Parse(DateTime.Now.AddDays(30).ToString("yyyy-MM-dd HH:mm:ss"));
this.gridView1.CustomDrawRowIndicator += gridView1_CustomDrawRowIndicator;
this.checkBox1.Checked = false;
#region
this.comboBoxEdit3.Properties.Items.Clear();
var weixinBases = Chat.Framework.ChatClient.WXClient.Values.ToList();
var objList = new List<object>() { "全部平台" };
foreach (var item in weixinBases)
{
objList.Add(item.WeixinHao);
}
var qqBases = Chat.Framework.ChatClient.QQClients.Values;
foreach (var item in qqBases)
{
objList.Add(item.QQ.ToString());
}
this.comboBoxEdit3.Properties.Items.AddRange(objList);
#endregion
this.pageControl1.Bind(SerchData, this.gridControl1, 50, false, true);
MainEvent.CommonEvents += Main_CommonEvents;
this.Disposed += Control_Disposed;
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
}
}
private void Control_Disposed(object sender, EventArgs e)
{
MainEvent.CommonEvents -= Main_CommonEvents;
}
private UI.Framework.Controls.PageControl.SerchResult SerchData(int index, int pagesize)
{
try
{
var session = ApiClient.GetSession();
var isOld = true;
List<view_cps_order_alimama> result = null;
var sqlwhere = string.Empty;
if (this.checkBox1.Checked)
{
isOld = false;
sqlwhere += $" and '{this.dateTimePicker1.Value.ToString("yyyy-MM-dd HH:mm:ss")}' <= create_time and create_time <= '{this.dateTimePicker2.Value.ToString("yyyy-MM-dd HH:mm:ss")}'";
}
string where = string.Empty;
string keyword = this.textEdit1.Text.Trim();
if (!string.IsNullOrEmpty(keyword) || comboBoxEdit1.Text == "未绑定用户")
{
switch (this.comboBoxEdit1.Text)
{
case "订单编号":
if (keyword.Length == 6)
sqlwhere += $" and trade_parent_id like '%{keyword}'";
else
sqlwhere += $" and trade_parent_id = '{keyword}'";
break;
case "商品编号":
sqlwhere += $" and num_iid = '{keyword}'";
break;
case "商品标题":
sqlwhere += $" and item_title like '%{keyword}%'";
break;
case "客户编号":
sqlwhere += $" and db_userid = '{keyword}'";
break;
case "客户账号":
var ids = FindMemberIdByKey("username", keyword);
if (ids != null)
{
if (ids.Count == 0)
ids.Add("-1");
sqlwhere += $" and db_userid in ('{string.Join("','", ids)}')";
}
break;
case "客户昵称":
ids = FindMemberIdByKey("usernick", keyword);
if (ids != null)
{
if (ids.Count == 0)
ids.Add("-1");
sqlwhere += $" and db_userid in ('{string.Join("','", ids)}')";
}
break;
case "店铺编码":
sqlwhere += $" and seller_id = '{keyword}'";
break;
case "PID最后1段":
sqlwhere += $" and adzone_id = '{keyword}'";
break;
case "联盟账号":
sqlwhere += $" and db_cpsname = '{keyword}'";
break;
case "联盟昵称":
sqlwhere += $" and db_cpsnick = '{keyword}'";
break;
case "未绑定用户":
sqlwhere += $" and db_userid = '0'";
break;
}
}
var status = this.comboBoxEdit2.SelectedIndex == 0 ? SystemOrderStatus. : Util.ConvertEnum<SystemOrderStatus>(this.comboBoxEdit2.Text);
if (status != SystemOrderStatus.)
sqlwhere += $" and db_status = '{((int)status).ToString()}'";
if (this.comboBoxEdit3.SelectedIndex != 0)
sqlwhere += $" and db_robotname = '{comboBoxEdit3.Text.Trim()}'";
//总记录数
int totalNumber = 0;
if (isOld && checkBox_isOld.Checked)
sqlwhere += $" and '{DateTime.Now.AddYears(-1).ToString("yyyy-MM-dd HH:mm:ss")}' <= create_time";
sqlwhere += $" order by id desc";
var getCount = session.Find<int>("select count(*) from fl_order_alimama where 1=1 " + sqlwhere);
if (getCount != null && getCount.Count != 0)
totalNumber = getCount[0];
sqlwhere += $" limit {(index - 1) * pagesize},{pagesize}";
var resultTmp = session.Find<fl_order_alimama>("select * from fl_order_alimama where 1=1 " + sqlwhere);
result = new List<view_cps_order_alimama>();
foreach (var o in resultTmp)
{
result.Add(new view_cps_order_alimama()
{
id = o.id,
adzone_id = o.adzone_id,
alipay_total_price = o.alipay_total_price,
create_time = o.create_time,
db_cpsname = o.db_cpsname,
db_cpsnick = o.db_cpsnick,
db_endtime = o.db_endtime,
db_point = o.db_point,
db_status = o.db_status,
item_num = o.item_num,
item_title = o.item_title,
num_iid = o.num_iid,
order_type = o.order_type,
price = o.price,
pub_share_pre_fee = o.pub_share_pre_fee,
robotname = o.db_robotname,
trade_id = o.trade_id,
trade_parent_id = o.trade_parent_id,
db_userid = o.db_userid,
seller_id = o.seller_id,
deposit_price = o.deposit_price,
tb_deposit_time = o.tb_deposit_time,
pay_price = o.pay_price,
commission = o.commission,
alimama_rate = o.alimama_rate,
alimama_share_fee = o.alimama_share_fee,
auction_category = o.auction_category,
//refundFee = ra.refundfee,
//showReturnFee = ra.showreturnfee,D:\代码同步\fl_system\类库\Grant.Framework\LoginCard.cs
//username = u.username,
//usernick = u.usernick
});
}
if (result.Count != 0)
{
#region
var bindUsersList = result.Where(f => f.db_userid != 0).GroupBy(f => f.db_userid).Select(f => f.Key).ToList();
var memberData = new List<fl_member_info>();
if (bindUsersList != null && bindUsersList.Count != 0)
{
memberData = session.Queryable<fl_member_info>().Where(new List<IConditionalModel>() { new ConditionalModel() { FieldName = "id", ConditionalType = ConditionalType.In, FieldValue = string.Join(",", bindUsersList) } }).ToList();
}
foreach (var member in memberData)
{
var items = result.Where(f => f.db_userid == member.id).ToList();
foreach (var item in items)
{
item.usernick = member.usernick;
item.username = member.username;
}
}
#endregion
#region
var robotList = result.Where(f => !string.IsNullOrWhiteSpace(f.robotname)).GroupBy(f => f.robotname).Select(f => f.Key).ToList();
var robotData = session.FindRobots().Where(f => robotList.Contains(f.name)).ToList();
foreach (var robot in robotData)
{
var items = result.Where(f => f.robotname == robot.name).ToList();
foreach (var item in items)
{
item.robotnick = robot.nick;
}
}
#endregion
var refundData = result.Where(f => (int)f.db_status == 1003 || (int)f.db_status == 1000 || (int)f.db_status == 999 || (int)f.db_status == 998).ToList();
List<string> wherelist = new List<string>();
foreach (var item in refundData)
{
wherelist.Add($"(tbtradeparentid = {item.trade_parent_id} and tbtradeid = {item.trade_id})");
}
var _where = string.Join(" or ", wherelist);
_where = string.IsNullOrWhiteSpace(_where) ? string.Empty : $"and { _where}";
var refundResult = session.Find<fl_order_refund_alimama>($"select * from fl_order_refund_alimama where 1 = 1 { _where}");
foreach (var item in refundResult)
{
var order = result.FirstOrDefault(f => f.trade_parent_id == item.tbtradeparentid && f.trade_id == item.tbtradeid);
if (order != null)
{
if (order.auction_category != "手动处理")
{
order.refundFee = item.refundfee;
order.showReturnFee = item.showreturnfee;
}
}
}
}
//EventClient.OnEvent(this, sb_time.ToString());
return new UI.Framework.Controls.PageControl.SerchResult() { Result = result, Total = totalNumber };
}
catch (Exception ex)
{
if (!this.IsDisposed)
this.UpdateUI(() =>
{
BaseForm.ShowError(ex);
});
}
return null;
}
/// <summary>
/// 代理委托更新UI
/// </summary>
/// <param name="act"></param>
protected delegate void DelegateUpdateUI(Action act);
/// <summary>
/// 代理委托更新UI
/// </summary>
/// <param name="act"></param>
protected void UpdateUI(Action act)
{
try
{
if (!InvokeRequired)
{
act.Invoke();
}
else
{
DelegateUpdateUI delegateUpdateUI = new DelegateUpdateUI(UpdateUI);
Invoke(delegateUpdateUI, act);
}
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
}
}
/// <summary>
/// 条件查询(用户账号/用户昵称),模糊查询,获取用户的id
/// </summary>
/// <param name="type">查询的字段</param>
/// <param name="keyword">模糊的关键词</param>
/// <returns></returns>
private List<string> FindMemberIdByKey(string type, string keyword)
{
try
{
var session = ApiClient.GetSession();
return session.Find<int>($"select id from fl_member_info where {type} like '%{keyword}%'").Select(f => f.ToString()).ToList();
}
catch (Exception ex)
{
return new List<string>();
}
}
private void Main_CommonEvents(object sender, CommonEvents e)
{
try
{
if (e.Commons != null && e.Commons.Count != 0)
{
if (e.Commons.ContainsKey("cps_type") && e.Commons.ContainsKey("username"))
{
var cps_type = (CpsType)int.Parse(e.Commons["cps_type"].ToString());
if (cps_type == CpsType.)
{
textEdit1.Text = e.Commons["username"].ToString();
comboBoxEdit1.SelectedIndex = 5;
comboBoxEdit3.SelectedIndex = comboBoxEdit2.SelectedIndex = 0;
checkBox1.Checked = false;
pageControl1.GotoPage(1);
}
}
}
}
catch (Exception ex)
{
BaseForm.ShowError(ex);
}
}
private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIndicatorCustomDrawEventArgs e)
{
if (e.Info.IsRowIndicator && e.RowHandle >= 0) e.Info.DisplayText = (e.RowHandle + 1).ToString();
}
private void simpleButton1_Click(object sender, EventArgs e)
{
this.pageControl1.Go(sender, e);
}
private void gridView1_CustomColumnDisplayText(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDisplayTextEventArgs e)
{
switch (e.Column.Caption)
{
case "软件状态":
e.DisplayText = Util.ConvertEnum<SystemOrderStatus>(int.Parse(e.Value.ToString())).ToString();
break;
case "一级提成":
e.DisplayText = HttpExtend.JsonToDictionary(e.Value.ToString().ToLower())["awardone"].ToString();
break;
case "二级提成":
e.DisplayText = HttpExtend.JsonToDictionary(e.Value.ToString().ToLower())["awardtwo"].ToString();
break;
case "三级提成":
{
var result = HttpExtend.JsonToDictionary(e.Value.ToString().ToLower());
e.DisplayText = (result != null && result.ContainsKey("awardthree")) ? result["awardthree"].ToString() : "0";
}
break;
case "群负责人提成":
e.DisplayText = HttpExtend.JsonToDictionary(e.Value.ToString().ToLower())["awardcreate"].ToString();
break;
}
}
private void gridView1_CustomUnboundColumnData(object sender, DevExpress.XtraGrid.Views.Base.CustomColumnDataEventArgs e)
{
var row = e.Row as view_cps_order_alimama;
if (e.Column.Caption == "客户所得")
{
//var ss = Newtonsoft.Json.JsonConvert.DeserializeObject<ItemPoint>(row.db_point);
var point = HttpHelper.JsonToObject<ItemPoint>(row.db_point) as ItemPoint;
e.Value = point.UserPoint;
}
else if (e.Column.Caption == "订单类型")
{
if (row.create_time > DateTime.Parse("2020-08-04 00:00:00"))
e.Value = row.alimama_rate != 0 ? "正常订单" : "比价订单";
else
e.Value = "历史订单";
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var rows = this.gridView1.GetSelectedRows();
if (rows.Length != 0)
{
var info = this.gridView1.GetRow(rows[0]) as view_cps_order_alimama;
if (XtraMessageBox.Show("您确定要删除选中数据嘛?\r\n" + info.item_title, "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var session = ApiClient.GetSession();
session.ExcuteSQL("delete from fl_order_alimama where id=" + info.id);
}
this.pageControl1.GotoPage(1);
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.pageControl1.GotoPage(1);
}
private void comboBoxEdit1_SelectedIndexChanged(object sender, EventArgs e)
{
this.textEdit1.Enabled = (comboBoxEdit1.SelectedIndex != 0 && comboBoxEdit1.SelectedIndex != 11);
if (!textEdit1.Enabled)
this.textEdit1.Text = string.Empty;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
this.dateTimePicker1.Enabled = this.dateTimePicker2.Enabled = this.checkBox1.Checked;
}
/// <summary>
/// 订单绑定用户
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void toolStripMenuItem1_Click(object sender, EventArgs e)
{
try
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
//获取选中数据
var row = this.gridView1.GetRow(rows[0]) as view_cps_order_alimama;
var db_status = row.db_status;
if (db_status == SystemOrderStatus. || db_status == SystemOrderStatus. || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.)
{
throw new Exception("该订单状态,不允许修改!");
}
var session = ApiClient.GetSession();
if (row.db_userid != 0)
{
var member = session.FindMemberInfoById(row.db_userid);
if (member != null)
{
if (member.bind_order > 0)
{
member.bind_order--;
member = session.UpdateMemberGroup(member);
}
}
}
select_member_form select_form = new select_member_form();
select_form.ShowDialog();
if (select_form.fl_member_info != null)
{
var alimama = session.FindSingle<fl_order_alimama>("id = @id", new { id = row.id });
if (alimama != null)
{
if (alimama.db_robottype == 0) alimama.db_robottype = select_form.fl_member_info.robot_type;
if (string.IsNullOrWhiteSpace(alimama.db_robotname)) alimama.db_robotname = select_form.fl_member_info.robot_name;
#region ,
var isTljOrder = session.CheckIsTljOrder(row.adzone_id);
#endregion
//计算的佣金 - 判断使用设置模式,符合将扣除用户自定义预扣佣金
var commission = session.GetTbComparisonFeeRate(alimama);
//var itempoint = session.FindItemPoint(select_form.fl_member_info, isTljOrder ? 0 : alimama.pub_share_pre_fee, alimama.item_num, CpsType.阿里妈妈);
var itempoint = session.FindItemPoint(select_form.fl_member_info, isTljOrder ? 0 : commission, alimama.item_num, CpsType.);
if (itempoint != null)
{
alimama.db_point = HttpHelper.ObjectToJson(itempoint);
alimama.db_userpoint = itempoint.UserPoint;
}
alimama.db_userid = select_form.fl_member_info.id;
session.SaveOrUpdate(alimama);
#region
var query_item = session.FindSingle<fl_query_hist>("userid=@userid and itemid=@itemid and adzoneid = @adzoneid and crt_time > @time order by id", new { userid = alimama.db_userid, itemid = alimama.num_iid, adzoneid = alimama.adzone_id, time = DateTime.Now.AddHours(-24).ToString("yyyy-MM-dd HH:mm:ss") });
if (query_item != null && !string.IsNullOrWhiteSpace(query_item.compute_configdic))
{
if (alimama.id == 0)
session.SaveOrUpdate(alimama);
var queryRatioHist = new fl_query_ratio_hist()
{
compute_config = query_item.compute_configdic,
db_orderid = alimama.id,
createtime = DateTime.Now,
cpstype = CpsType.
};
session.SaveOrUpdate(queryRatioHist);
}
#endregion
}
simpleButton1_Click(null, null);
//更新显示值
row.db_userid = select_form.fl_member_info.id;
row.username = select_form.fl_member_info.username;
row.usernick = select_form.fl_member_info.usernick;
row.db_point = alimama.db_point;
select_form.fl_member_info.bind_order++;
#region
try
{
var record = session.FindStatisticsRecord(select_form.fl_member_info.id);
if (record == null)
{
record = new fl_statistics_record() { uid = select_form.fl_member_info.id, ex2 = 0, ex4 = HttpExtend.GetTimeStamp(DateTime.Now), ex5 = HttpExtend.GetTimeStamp(alimama.paid_time) };
session.Saveable<fl_statistics_record>(record).ExecuteCommand();
}
else
{
if (record.ex2 == 0 && record.ex4 == 0)
record.ex4 = CsharpHttpHelper.HttpExtend.GetTimeStamp(DateTime.Now);
record.ex5 = CsharpHttpHelper.HttpExtend.GetTimeStamp(alimama.paid_time);
session.Saveable<fl_statistics_record>(record).ExecuteCommand();
}
}
catch (Exception)
{ }
#endregion
session.UpdateMemberGroup(select_form.fl_member_info);
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
/// <summary>
/// 订单解绑
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
//获取选中数据
var row = this.gridView1.GetRow(rows[0]) as view_cps_order_alimama;
var db_status = row.db_status;
if (db_status == SystemOrderStatus. || db_status == SystemOrderStatus. || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.)
{
throw new Exception("该订单状态,不允许解绑!");
}
var session = ApiClient.GetSession();
if (row.db_userid != 0)
{
var member = session.FindMemberInfoById(row.db_userid);
if (member != null && member.bind_order > 0)
{
member.bind_order--;
member = session.UpdateMemberGroup(member);
}
}
session.ExcuteSQL("delete from fl_query_hist where itemid = @num_iid", new { num_iid = row.num_iid });
session.ExcuteSQL("update fl_order_alimama set db_userid = @userid where id=@id", new { userid = 0, id = row.id });
session.ExcuteSQL("delete from fl_query_ratio_hist where db_orderid=@id", new { id = row.id });
//更新显示值
row.db_userid = 0;
row.username = string.Empty;
row.usernick = string.Empty;
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (XtraMessageBox.Show("确定要结算选中订单?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
//获取选中数据
var row = this.gridView1.GetRow(rows[0]) as view_cps_order_alimama;
var db_status = row.db_status;
if (db_status == SystemOrderStatus. || db_status == SystemOrderStatus. || db_status == SystemOrderStatus. || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退)
throw new Exception($"选中订单:{db_status},不予操作");
var session = ApiClient.GetSession();
var alimama = session.FindSingle<fl_order_alimama>("select * from fl_order_alimama where trade_id = @trade_id and trade_parent_id = @trade_parent_id", new { trade_id = row.trade_id, trade_parent_id = row.trade_parent_id });
if (alimama == null) throw new Exception("数据查询失败,请稍后重试");
alimama.earning_time = DateTime.Now.AddSeconds(-2);
alimama.tk_status = (int)AlimamaOrderStatus.;
alimama.db_endtime = DateTime.Now;
alimama.db_status = SystemOrderStatus.;
alimama.auction_category = "手动处理";
var task = TimerTask.GetTimer<DownAlimamaTimer>() as DownAlimamaTimer;
var notices = new List<OrderNoticeEvent>();
var strb = new StringBuilder();
try
{
strb.Append($@"手动结算 数据1:{HttpHelper.ObjectToJson(alimama)}");
}
catch (Exception)
{ }
task.UpdateOrder(alimama, notices, session);
try
{
strb.AppendLine($@"返回: {HttpHelper.ObjectToJson(alimama)}");
EventClient.OnEvent("淘宝订单手动结算: ", strb.ToString());
}
catch (Exception)
{ }
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_alimama;
tasks.Add(item);
}
//更新显示值
row.db_status = SystemOrderStatus.;
row.db_endtime = DateTime.Now;
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (XtraMessageBox.Show("确定要失效选中订单?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
//获取选中数据
var row = this.gridView1.GetRow(rows[0]) as view_cps_order_alimama;
var db_status = row.db_status;
var session = ApiClient.GetSession();
var alimama = session.FindSingle<fl_order_alimama>("trade_id = @trade_id and trade_parent_id = @trade_parent_id", new { trade_id = row.trade_id, trade_parent_id = row.trade_parent_id });
if (alimama == null) throw new Exception("数据查询失败,请稍后重试");
var flag = false;
var notices = new List<OrderNoticeEvent>();
if (db_status == SystemOrderStatus. || db_status == SystemOrderStatus.退)
flag = true;
else if (db_status != SystemOrderStatus. && alimama.IsFinish())
throw new Exception($"选中订单:{db_status},不予操作");
alimama.earning_time = DateTime.Now.AddSeconds(-2);
alimama.tk_status = (int)AlimamaOrderStatus.;
alimama.db_endtime = DateTime.Now;
alimama.db_status = SystemOrderStatus.;
alimama.auction_category = "手动处理";
var task = TimerTask.GetTimer<DownAlimamaTimer>() as DownAlimamaTimer;
if (!flag)
{
var strb = new StringBuilder();
try
{
strb.Append($@"手动失效A 数据1:{HttpHelper.ObjectToJson(alimama)}");
}
catch (Exception)
{ }
task.UpdateOrder(alimama, notices, session);
try
{
strb.AppendLine($@"返回: {HttpHelper.ObjectToJson(alimama)}");
EventClient.OnEvent("淘宝订单手动失效: ", strb.ToString());
}
catch (Exception)
{ }
}
else
{
new OrderHelper().DeductAliOrderPoint(notices, alimama);
session.SaveOrUpdate(alimama);
}
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_alimama;
tasks.Add(item);
}
row.db_status = SystemOrderStatus.;
row.db_endtime = DateTime.Now;
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void cps_order_alimama_Load(object sender, EventArgs e)
{
simpleButton1_Click(this.simpleButton1, null);
}
private void ToolStripMenuItem1_Click(object sender, EventArgs e)
{
try
{
var rows = gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
var username = gridView1.GetRowCellValue(rows[0], "username").ToString();//获取列的数据;
if (!string.IsNullOrWhiteSpace(username))
{
var tsmi = sender as ToolStripMenuItem;
if (tsmi == null) throw new Exception("数据异常");
var common = new Dictionary<string, object>();
common["control_name"] = tsmi.Text;
common["username"] = username;
MainEvent.OnEvent(null, new CommonEvents(common));
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
var username = this.gridView1.GetRowCellValue(rows[0], "username").ToString();//获取列的数据
var tsmi = sender as ToolStripMenuItem;
if (tsmi == null) throw new Exception("数据异常");
var text = tsmi.Text.Replace("订单", "").Replace("所有", "");
var cps = (CpsType)Enum.Parse(typeof(CpsType), text);
var common = new Dictionary<string, object>();
common["cps_type"] = (int)cps;
common["username"] = username;
MainEvent.OnEvent(null, new CommonEvents(common));
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message);
}
}
/// <summary>
/// 查询用户对应积分列表
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
var username = this.gridView1.GetRowCellValue(rows[0], "username").ToString();//获取列的数据
var tsmi = sender as ToolStripMenuItem;
if (tsmi == null) throw new Exception("数据异常");
var common = new Dictionary<string, object>();
common["control_name"] = "提现管理";
common["query_type"] = tsmi.Text;
common["username"] = username;
MainEvent.OnEvent(null, new CommonEvents(common));
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void contextMenuStrip1_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
try
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
this.ToolStripMenuItem.Enabled = this.gridView1.GetRowCellValue(rows[0], "username") != null;
var status = this.gridView1.GetRowCellValue(rows[0], "db_status").ToString();
this.ToolStripMenuItem.Enabled = status == "订单冻结";
this.ToolStripMenuItem.Enabled = (status == "订单维权中" || status == "全额退款" || status == "部分退款");
}
else
e.Cancel = true;
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "系统错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (XtraMessageBox.Show("确定要延长冻结选中订单?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
//获取选中数据
var row = this.gridView1.GetRow(rows[0]) as view_cps_order_alimama;
var db_status = row.db_status;
if (db_status != SystemOrderStatus.)
throw new Exception($"选中订单:{db_status},不予操作");
var session = ApiClient.GetSession();
setting_endtime_form endtime_form = new setting_endtime_form(row.db_endtime);
endtime_form.ShowDialog();
if (endtime_form.newtime == DateTime.MinValue) return;
var alimama = session.FindSingle<fl_order_alimama>("id = @id", new { id = row.id });
if (endtime_form.newtime != row.db_endtime)
{
alimama.db_endtime = endtime_form.newtime;
session.Updateable(alimama).ExecuteCommand();
}
row.db_endtime = endtime_form.newtime;//更新显示值
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var rows = this.gridView1.GetSelectedRows();
if (rows != null && rows.Length > 0)
{
var trade_parent_id = this.gridView1.GetRowCellValue(rows[0], "trade_parent_id").ToString();//获取列的数据
var tsmi = sender as ToolStripMenuItem;
if (tsmi == null) throw new Exception("数据异常");
var common = new Dictionary<string, object>();
common["type"] = "阿里妈妈维权订单";
common["trade_parent_id"] = trade_parent_id;
MainEvent.OnEvent(null, new CommonEvents(common));
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void groupControl1_Paint(object sender, PaintEventArgs e)
{
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (XtraMessageBox.Show("确定要结算当前页所有的订单?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var rows = this.gridView1.DataSource as List<view_cps_order_alimama>;
if (rows != null && rows.Count > 0)
{
for (int i = 0; i < rows.Count; i++)
{
//获取选中数据
var row = rows[i];
var db_status = row.db_status;
if (db_status == SystemOrderStatus. || db_status == SystemOrderStatus. || db_status == SystemOrderStatus. || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退 || db_status == SystemOrderStatus.退)
throw new Exception($"选中订单:{db_status},不予操作");
var session = ApiClient.GetSession();
var alimama = session.FindSingle<fl_order_alimama>("select * from fl_order_alimama where trade_id = @trade_id and trade_parent_id = @trade_parent_id", new { trade_id = row.trade_id, trade_parent_id = row.trade_parent_id });
if (alimama == null) throw new Exception("数据查询失败,请稍后重试");
alimama.earning_time = DateTime.Now.AddSeconds(-2);
alimama.tk_status = (int)AlimamaOrderStatus.;
alimama.db_endtime = DateTime.Now;
alimama.db_status = SystemOrderStatus.;
alimama.auction_category = "手动处理";
var task = TimerTask.GetTimer<DownAlimamaTimer>() as DownAlimamaTimer;
var notices = new List<OrderNoticeEvent>();
var strb = new StringBuilder();
try
{
strb.Append($@"手动结算 数据1:{HttpHelper.ObjectToJson(alimama)}");
}
catch (Exception)
{ }
task.UpdateOrder(alimama, notices, session);
try
{
strb.AppendLine($@"返回: {HttpHelper.ObjectToJson(alimama)}");
EventClient.OnEvent("淘宝订单手动结算: ", strb.ToString());
}
catch (Exception)
{ }
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_alimama;
tasks.Add(item);
}
//更新显示值
row.db_status = SystemOrderStatus.;
row.db_endtime = DateTime.Now;
}
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (XtraMessageBox.Show("确定要失效当前页所有的订单?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var rows = this.gridView1.DataSource as List<view_cps_order_alimama>;
if (rows != null && rows.Count > 0)
{
for (int i = 0; i < rows.Count; i++)
{
//获取选中数据
var row = rows[i];
var db_status = row.db_status;
var session = ApiClient.GetSession();
var alimama = session.FindSingle<fl_order_alimama>("trade_id = @trade_id and trade_parent_id = @trade_parent_id", new { trade_id = row.trade_id, trade_parent_id = row.trade_parent_id });
if (alimama == null) throw new Exception("数据查询失败,请稍后重试");
var flag = false;
var notices = new List<OrderNoticeEvent>();
if (db_status == SystemOrderStatus. || db_status == SystemOrderStatus.退)
flag = true;
else if (db_status != SystemOrderStatus. && alimama.IsFinish())
throw new Exception($"选中订单:{db_status},不予操作");
alimama.earning_time = DateTime.Now.AddSeconds(-2);
alimama.tk_status = (int)AlimamaOrderStatus.;
alimama.db_endtime = DateTime.Now;
alimama.db_status = SystemOrderStatus.;
alimama.auction_category = "手动处理";
var task = TimerTask.GetTimer<DownAlimamaTimer>() as DownAlimamaTimer;
if (!flag)
{
var strb = new StringBuilder();
try
{
strb.Append($@"手动失效A 数据1:{HttpHelper.ObjectToJson(alimama)}");
}
catch (Exception)
{ }
task.UpdateOrder(alimama, notices, session);
try
{
strb.AppendLine($@"返回: {HttpHelper.ObjectToJson(alimama)}");
EventClient.OnEvent("淘宝订单手动失效: ", strb.ToString());
}
catch (Exception)
{ }
}
else
{
new OrderHelper().DeductAliOrderPoint(notices, alimama);
session.SaveOrUpdate(alimama);
}
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_alimama;
tasks.Add(item);
}
row.db_status = SystemOrderStatus.;
row.db_endtime = DateTime.Now;
}
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
if (XtraMessageBox.Show("确定要延长冻结当前页所有的订单?", "友情提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
{
var rows = this.gridView1.DataSource as List<view_cps_order_alimama>;
if (rows != null && rows.Count > 0)
{
for (int i = 0; i < rows.Count; i++)
{
//获取选中数据
var row = rows[i];
var db_status = row.db_status;
if (db_status != SystemOrderStatus.)
throw new Exception($"选中订单:{db_status},不予操作");
var session = ApiClient.GetSession();
setting_endtime_form endtime_form = new setting_endtime_form(row.db_endtime);
endtime_form.ShowDialog();
if (endtime_form.newtime == DateTime.MinValue) return;
var alimama = session.FindSingle<fl_order_alimama>("id = @id", new { id = row.id });
if (endtime_form.newtime != row.db_endtime)
{
alimama.db_endtime = endtime_form.newtime;
session.Updateable(alimama).ExecuteCommand();
}
row.db_endtime = endtime_form.newtime;//更新显示值
}
}
}
}
catch (Exception ex)
{
XtraMessageBox.Show(ex.Message, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}
private void ToolStripMenuItem_Click(object sender, EventArgs e)
{
try
{
var db = ApiClient.GetSession();
var orders = db.Queryable<fl_order_alimama>().Where(f =>
f.db_userid != 0 && (f.db_status == SystemOrderStatus. ||
f.db_status == SystemOrderStatus. ||
f.db_status == SystemOrderStatus.)).ToList();
EventClient.OnEvent("", $"淘宝需要重新计算的订单数:{orders.Count}");
foreach (var order in orders)
{
var member = db.FindMemberInfoById(order.db_userid);
var commission = db.GetTbComparisonFeeRate(order);
var itempoint = db.FindItemPoint(member, commission, order.item_num, CpsType.);
if (itempoint != null)
{
order.db_point = HttpHelper.ObjectToJson(itempoint);
order.db_userpoint = itempoint.UserPoint;
db.SaveOrUpdate(order);
EventClient.OnEvent("", $"淘宝单号:{order.trade_parent_id}-{order.trade_id},重新计算完成");
}
}
}
catch (Exception ex)
{
EventClient.OnEvent("", $"淘宝重新计算异常:{ex.Message}");
}
}
}
}