422 lines
18 KiB
C#
422 lines
18 KiB
C#
using AllBase;
|
||
using AllBase.Helper;
|
||
using AllBase.Model.DBModel;
|
||
using AllBase.Model.Result;
|
||
using CefSharp;
|
||
using CefSharp.WinForms;
|
||
using DevComponents.AdvTree;
|
||
using DevComponents.WinForms.Drawing;
|
||
using NaiBa.CefHelper;
|
||
using NaiBa.Util.Extension;
|
||
using Newtonsoft.Json.Linq;
|
||
using System;
|
||
using System.Collections.Generic;
|
||
using System.ComponentModel;
|
||
using System.Data;
|
||
using System.Data.SQLite;
|
||
using System.Diagnostics;
|
||
using System.Drawing;
|
||
using System.Drawing.Printing;
|
||
using System.Linq;
|
||
using System.Security.Cryptography.X509Certificates;
|
||
using System.Security.Policy;
|
||
using System.Text;
|
||
using System.Threading;
|
||
using System.Threading.Tasks;
|
||
using System.Windows.Forms;
|
||
using TemuKJD.BaseForms;
|
||
using TemuKJD.BLL;
|
||
using TemuKJD.Extension;
|
||
using Work;
|
||
|
||
namespace TemuKJD.WXForms.AdminForms
|
||
{
|
||
public partial class WXAdminAccountBalanceForm : BaseGeneralForm
|
||
{
|
||
// (拍单后)回调函数,更新拍单余额
|
||
private Action updateBalanceAction = null;
|
||
public static List<UserSubAccountInfo> AllUsers { get; set; } = new List<UserSubAccountInfo>();
|
||
|
||
public WXAdminAccountBalanceForm()
|
||
{
|
||
InitializeComponent();
|
||
}
|
||
|
||
private async void WXGetTopUpQrCode_Load(object sender, EventArgs e)
|
||
{
|
||
var chkAll = this.dgvPayment.AddSelectorColumn("colCheck");
|
||
chkAll.Click += ChkAll_Click;
|
||
|
||
this.dgvUser.AddSelectorColumn("colSelect");
|
||
this.dtpTimeBegin.Value = DateTime.Now.Date.AddMonths(-3);
|
||
this.dtpTimeEnd.Value = DateTime.Now.Date.AddDays(1).AddSeconds(-1);
|
||
|
||
ucSplitPage1.cmbPageSize.Items.Remove("5000");
|
||
|
||
pictureBox2.Visible = true;
|
||
await Task.Run(() => { GetBalanceList(); });
|
||
pictureBox2.Visible = false;
|
||
|
||
|
||
}
|
||
|
||
private void ChkAll_Click(object sender, EventArgs e)
|
||
{
|
||
this.dgvPayment.CellValueChanged -= this.dgvPayment_CellValueChanged;
|
||
this.GetProfit();
|
||
this.dgvPayment.CellValueChanged += this.dgvPayment_CellValueChanged;
|
||
}
|
||
|
||
private void btnBalanceTopUp_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
public async void GetBalanceList()
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
this.dgvPayment.Rows.Clear();
|
||
dgvPayment.CellValueChanged -= dgvPayment_CellValueChanged;
|
||
}));
|
||
|
||
await Task.Run(() =>
|
||
{
|
||
int pageCount = 1;
|
||
int pageSize = 50;
|
||
var url3 = BaseClass.BuildWXObjString("user/get_user_balance");
|
||
var data3 = UserLogin.GetSignaturex();
|
||
Invoke(new Action(() =>
|
||
{
|
||
if (!string.IsNullOrEmpty(txtUserName.Text.Trim()))
|
||
data3 += "&user_name_in=" + txtUserName.Text.Trim();
|
||
data3 += "&create_time_begin=" + dtpTimeBegin.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
||
data3 += "&create_time_end=" + dtpTimeEnd.Value.ToString("yyyy-MM-dd HH:mm:ss");
|
||
if (cmbType.Text == "充值")
|
||
data3 += "&type_in=1,30";
|
||
else if (cmbType.Text == "管理员充值")
|
||
data3 += "&type_in=1";
|
||
else if (cmbType.Text == "支付宝充值")
|
||
data3 += "&type_in=30";
|
||
else if (cmbType.Text == "礼物单支出/礼物单退费")
|
||
data3 += "&type_in=16,34";
|
||
else if (cmbType.Text == "拍单扣除/作废返还")
|
||
data3 += "&type_in=20,23";
|
||
else if (cmbType.Text == "超重扣费支出")
|
||
data3 += "&type_in=24";
|
||
else if (cmbType.Text == "退货包裹扣费支出")
|
||
data3 += "&type_in=26";
|
||
else if (cmbType.Text == "云仓退货扣费支出")
|
||
data3 += "&type_in=31";
|
||
else if (!string.IsNullOrEmpty(cmbType.Text))
|
||
data3 += "&type_in=" + cmbType.Text;
|
||
if (!string.IsNullOrEmpty(txtOutOrderId.Text.Trim()))
|
||
data3 += "&order_id_in=" + txtOutOrderId.Text.Trim();
|
||
if (!string.IsNullOrEmpty(txtShopOrderNo.Text.Trim()))
|
||
data3 += "&remark_fulltext=" + txtShopOrderNo.Text.Trim();
|
||
data3 += "&page=" + ucSplitPage1.CurrentPage;
|
||
data3 += "&page_size=" + ucSplitPage1.PageSize;
|
||
pageSize = ucSplitPage1.PageSize;
|
||
}));
|
||
var html3 = GetHtml.PostUtf8(url3, data3);
|
||
if (string.IsNullOrEmpty(html3) || !html3.Contains("\"code\":200"))
|
||
html3 = GetHtml.PostUtf8(url3, data3);
|
||
if (string.IsNullOrEmpty(html3) || !html3.Contains("\"code\":200"))
|
||
{
|
||
BaseMsgForm.ShowError("查询失败:" + BaseRegex.GetStringJsonByRegs(ref html3, html3, "msg"));
|
||
return;
|
||
}
|
||
|
||
List<user_payment_record> paymentList = new List<user_payment_record>();
|
||
paymentList = JsonHelper.DeserializeJsonToList<user_payment_record>(JsonHelper.JObjectParse(html3)["data"].ParseToString());
|
||
foreach (var payment in paymentList)
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
var rowIndex = this.dgvPayment.Rows.Add(
|
||
true,
|
||
((EnumOrderPaymentType)payment.type.ParseToInt()).ParseToString(),
|
||
payment.user_name,
|
||
payment.order_id,
|
||
payment.amount,
|
||
payment.oem_amount,
|
||
payment.balance,
|
||
payment.create_time.ToString("yyyy-MM-dd HH:mm:ss"),
|
||
payment.remark
|
||
);
|
||
var row = this.dgvPayment.Rows[rowIndex];
|
||
row.Height = 60;
|
||
|
||
var rowExists = dgvPayment.Rows.Cast<DataGridViewRow>()
|
||
.Where(r => r.Cells["colOrderId"].Value.ParseToString() == payment.order_id && r.Cells["colType"].Value.ParseToString() == "中转仓作废返还收入").ToList();
|
||
if (rowExists.Count > 1)
|
||
{
|
||
var c = Color.FromArgb(Randomx.GetId(127, 200), Randomx.GetId(127, 200), Randomx.GetId(127, 200));
|
||
foreach (var rowExist in rowExists)
|
||
{
|
||
rowExist.Cells["colOrderId"].Style.BackColor = c;
|
||
}
|
||
}
|
||
}));
|
||
}
|
||
int count = BaseRegex.GetIntJson(ref html3, "count");
|
||
pageCount = Math.Ceiling(1.0 * count / pageSize).ParseToInt();
|
||
pageCount = Math.Max(pageCount, 1);
|
||
ucSplitPage1.TotalPage = pageCount;
|
||
});
|
||
Invoke(new Action(() =>
|
||
{
|
||
GetProfit();
|
||
dgvPayment.CellValueChanged += dgvPayment_CellValueChanged;
|
||
}));
|
||
}
|
||
|
||
private async void btnSearch_Click(object sender, EventArgs e)
|
||
{
|
||
if (this.ucSplitPage1.CurrentPage != 1)
|
||
this.ucSplitPage1.CurrentPage = 1;
|
||
|
||
pictureBox2.Visible = true;
|
||
await Task.Run(() => { GetBalanceList(); });
|
||
pictureBox2.Visible = false;
|
||
}
|
||
|
||
private async void ucSplitPage1_PageChange(object obj)
|
||
{
|
||
pictureBox2.Visible = true;
|
||
await Task.Run(() => { GetBalanceList(); });
|
||
pictureBox2.Visible = false;
|
||
}
|
||
|
||
private async void btnGetUser_Click(object sender, EventArgs e)
|
||
{
|
||
if (pageUser.CurrentPage != 1)
|
||
pageUser.CurrentPage = 1;
|
||
else
|
||
{
|
||
pictureBox1.Visible = true;
|
||
await Task.Run(() => { GetUser(); });
|
||
pictureBox1.Visible = false;
|
||
}
|
||
}
|
||
|
||
private void GetUser()
|
||
{
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvUser.Rows.Clear();
|
||
AllUsers.Clear();
|
||
}));
|
||
|
||
if (BaseClass.SaLevel == 0)
|
||
return;
|
||
string url = BaseClass.BuildObjString("user/get_all_user");
|
||
StringBuilder data = new StringBuilder();
|
||
data.Append(UserLogin.GetSignaturex());
|
||
Invoke(new Action(() =>
|
||
{
|
||
// 账户类型
|
||
if (cmbGroup.Text == "主账户")
|
||
data.Append("&group_id=3");
|
||
else if (cmbGroup.Text == "客服")
|
||
data.Append("&group_id=4");
|
||
if (!string.IsNullOrWhiteSpace(txtSearch.Text))
|
||
data.Append("&search=" + txtSearch.Text.Replace("'", "'"));
|
||
data.Append("&page_size=" + pageUser.PageSize);
|
||
data.Append("&page=" + pageUser.CurrentPage);
|
||
}));
|
||
string html = GetHtml.PostUtf8(url, data.ToString());
|
||
if (string.IsNullOrEmpty(html))
|
||
return;
|
||
if (html.Contains("\"data\""))
|
||
{
|
||
var userObj = Newtonsoft.Json.Linq.JObject.Parse(html);
|
||
foreach (Newtonsoft.Json.Linq.JObject obj in userObj["data"])
|
||
{
|
||
string oStr = JsonHelper.SerializeObject(obj);
|
||
UserSubAccountInfo user = new UserSubAccountInfo();
|
||
user.id = BaseRegex.GetIntJson(ref oStr, "id");
|
||
user.user_name = BaseRegex.GetStringJson(ref oStr, "user_name");
|
||
user.nick_name = BaseRegex.GetStringJson(ref oStr, "nick_name");
|
||
user.mobile = BaseRegex.GetStringJson(ref oStr, "mobile");
|
||
user.group_id = BaseRegex.GetStringJson(ref oStr, "group_id");
|
||
user.shop_count = BaseRegex.GetIntJson(ref oStr, "shop_count");
|
||
user.company_name = BaseRegex.GetStringJson(ref oStr, "company_name");
|
||
user.sa_level = BaseRegex.GetIntJson(ref oStr, "sa_level");
|
||
user.authority = BaseRegex.GetStringJson(ref oStr, "authority");
|
||
user.points = BaseRegex.GetIntJson(ref oStr, "points");
|
||
user.balance = BaseRegex.GetDecimalJson(ref oStr, "balance");
|
||
user.shop_points_per_month = BaseRegex.GetIntJson(ref oStr, "shop_points_per_month");
|
||
user.postage_per_order = BaseRegex.GetDecimalJson(ref oStr, "postage_per_order");
|
||
user.refund_postage_per_order = BaseRegex.GetDecimalJson(ref oStr, "refund_postage_per_order");
|
||
user.gift_oem_amount_per_order = BaseRegex.GetDecimalJson(ref oStr, "gift_oem_amount_per_order");
|
||
user.oem_id = BaseRegex.GetStringJson(ref oStr, "oem_id");
|
||
user.oem_name = BaseRegex.GetStringJson(ref oStr, "oem_name");
|
||
var parent_user_name = BaseRegex.GetStringJson(ref oStr, "parent_user_name");
|
||
AllUsers.Add(user);
|
||
Invoke(new Action(() =>
|
||
{
|
||
dgvUser.Rows.Add(
|
||
false,
|
||
user.id,
|
||
user.nick_name,
|
||
user.user_name,
|
||
parent_user_name,
|
||
user.group_id,
|
||
user.group_name,
|
||
user.company_name,
|
||
user.shop_count,
|
||
user.sa_level,
|
||
user.sa_level_name /*+ (user.group_id == "4" ? "(客服)" : "")*/,
|
||
user.authority,
|
||
user.oem_id,
|
||
user.oem_name,
|
||
(user.authority.Contains("充值用户") && user.group_id == "3") ? (int?)user.points : null,
|
||
(user.authority.Contains("充值用户") && user.group_id == "3") ? "+" : null,
|
||
(user.authority.Contains("充值用户") && user.group_id == "3") ? (int?)user.shop_points_per_month : null,
|
||
(user.authority.Contains("充值用户") && user.group_id == "3") ? "改" : null,
|
||
user.balance.ParseToDecimal(),
|
||
"+",
|
||
Math.Max(2.2m, user.postage_per_order.ParseToDecimal()),
|
||
(user.group_id == "3") ? "改" : null,
|
||
Math.Max(2.5m, user.refund_postage_per_order.ParseToDecimal()),
|
||
(user.group_id == "3") ? "改" : null,
|
||
Math.Max(2.5m, user.gift_oem_amount_per_order.ParseToDecimal()),
|
||
(user.group_id == "3") ? "改" : null,
|
||
user.group_id == "3" ? "添加店铺" : "",
|
||
"编辑",
|
||
"删除");
|
||
}));
|
||
}
|
||
int count = BaseRegex.GetIntJson(ref html, "count");
|
||
var pageCount = Math.Ceiling(1.0 * count / pageUser.PageSize).ParseToInt();
|
||
pageCount = Math.Max(pageCount, 1);
|
||
pageUser.TotalPage = pageCount;
|
||
}
|
||
}
|
||
|
||
void GetProfit()
|
||
{
|
||
//foreach (var row in dgvPayment.Rows.Cast<DataGridViewRow>().ToList())
|
||
//{
|
||
// if (row.Cells["colCheck"].Value.ParseToBool() == false)
|
||
// continue;
|
||
|
||
// if (row.Cells[""].Value.ParseToString() == "中转仓扣费支出")
|
||
// {
|
||
|
||
// }
|
||
//}
|
||
|
||
var checkRows = dgvPayment.Rows.Cast<DataGridViewRow>().Where(r => r.Cells["colCheck"].Value.ParseToBool() == true).ToList();
|
||
|
||
lblPostageTotal.Text = checkRows
|
||
.Where(r => r.Cells["colType"].Value.ParseToString() == EnumOrderPaymentType.中转仓扣费支出.ParseToString())
|
||
.Sum(r => r.Cells["colAmount"].Value.ParseToDecimal()).ToString();
|
||
lblPostageReturnTotal.Text = checkRows
|
||
.Where(r => r.Cells["colType"].Value.ParseToString() == EnumOrderPaymentType.中转仓作废返还收入.ParseToString())
|
||
.Sum(r => r.Cells["colAmount"].Value.ParseToDecimal()).ToString();
|
||
lblPostageWeightTotal.Text = checkRows
|
||
.Where(r => r.Cells["colType"].Value.ParseToString() == EnumOrderPaymentType.中转仓超重支出.ParseToString())
|
||
.Sum(r => r.Cells["colAmount"].Value.ParseToDecimal()).ToString();
|
||
lblPostageNotReturnCnt.Text = (checkRows
|
||
.Where(r => r.Cells["colType"].Value.ParseToString() == EnumOrderPaymentType.中转仓扣费支出.ParseToString()).Count() - checkRows
|
||
.Where(r => r.Cells["colType"].Value.ParseToString() == EnumOrderPaymentType.中转仓作废返还收入.ParseToString()).Count()).ToString();
|
||
lblProfit.Text = (lblPostageTotal.Text.ParseToDecimal() - lblPostageReturnTotal.Text.ParseToDecimal() - lblPostageNotReturnCnt.Text.ParseToInt() * 2.2m).ToString();
|
||
}
|
||
|
||
private async void btnSearchShop_Click(object sender, EventArgs e)
|
||
{
|
||
pnlGetUser.Visible = true;
|
||
|
||
if (pageUser.CurrentPage != 1)
|
||
pageUser.CurrentPage = 1;
|
||
else
|
||
{
|
||
pictureBox1.Visible = true;
|
||
await Task.Run(() => { GetUser(); });
|
||
pictureBox1.Visible = false;
|
||
}
|
||
}
|
||
|
||
private void btnClose_Click(object sender, EventArgs e)
|
||
{
|
||
this.pnlGetUser.Visible = false;
|
||
}
|
||
|
||
private void btnOk_Click(object sender, EventArgs e)
|
||
{
|
||
var ids = dgvUser.Rows.Cast<DataGridViewRow>()
|
||
.Where(r => r.Cells["colSelect"].Value.ParseToBool() == true)
|
||
.Select(r => r.Cells["mobileColumn"].Value.ParseToString());
|
||
this.txtUserName.Text = string.Join(",", ids);
|
||
this.pnlGetUser.Visible = false;
|
||
}
|
||
|
||
private void dgvUser_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
var row = dgvUser.Rows[e.RowIndex];
|
||
string headerText = dgvUser.Columns[e.ColumnIndex].HeaderText;
|
||
string columnName = dgvUser.Columns[e.ColumnIndex].Name;
|
||
switch (headerText)
|
||
{
|
||
case "":
|
||
dgvUser.Rows[e.RowIndex].Cells["colSelect"].Value = !(bool)dgvUser.Rows[e.RowIndex].Cells["colSelect"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void dgvPayment_CellContentClick(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex < 0 || e.RowIndex < 0)
|
||
return;
|
||
var row = dgvPayment.Rows[e.RowIndex];
|
||
string headerText = dgvPayment.Columns[e.ColumnIndex].HeaderText;
|
||
string columnName = dgvPayment.Columns[e.ColumnIndex].Name;
|
||
switch (headerText)
|
||
{
|
||
case "":
|
||
dgvPayment.Rows[e.RowIndex].Cells["colCheck"].Value = !(bool)dgvPayment.Rows[e.RowIndex].Cells["colCheck"].Value;
|
||
break;
|
||
default:
|
||
break;
|
||
}
|
||
}
|
||
|
||
private void btnClearFilter_Click(object sender, EventArgs e)
|
||
{
|
||
cmbGroup.Text = "全部";
|
||
this.txtSearch.Text = "";
|
||
}
|
||
|
||
private void dgvPayment_CellValueChanged(object sender, DataGridViewCellEventArgs e)
|
||
{
|
||
if (e.ColumnIndex == 0)
|
||
{
|
||
GetProfit();
|
||
}
|
||
}
|
||
|
||
private async void pageUser_PageChange(object obj)
|
||
{
|
||
pictureBox1.Visible = true;
|
||
await Task.Run(() => { GetUser(); });
|
||
pictureBox1.Visible = false;
|
||
}
|
||
|
||
private void label6_Click(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
|
||
private void dtpTimeBegin_ValueChanged(object sender, EventArgs e)
|
||
{
|
||
|
||
}
|
||
}
|
||
}
|