16 changed files with 654 additions and 49 deletions
@ -0,0 +1,77 @@ |
|||
using System.Collections.Generic; |
|||
|
|||
namespace BBWY.Client.Extensions |
|||
{ |
|||
public static class ProcurementAuditExtension |
|||
{ |
|||
/// <summary>
|
|||
/// 跳过引号中的逗号,进行逗号分隔(字段内容中的逗号不参与分隔)
|
|||
/// </summary>
|
|||
/// <param name="strLine"></param>
|
|||
/// <returns></returns>
|
|||
public static string[] CSVstrToArry(this string splitStr) |
|||
{ |
|||
var newstr = string.Empty; |
|||
List<string> sList = new List<string>(); |
|||
|
|||
bool isSplice = false; |
|||
string[] array = splitStr.Split(new char[] { ',' }); |
|||
foreach (var str in array) |
|||
{ |
|||
if (!string.IsNullOrEmpty(str) && str.IndexOf('"') > -1) |
|||
{ |
|||
var firstchar = str.Substring(0, 1); |
|||
var lastchar = string.Empty; |
|||
if (str.Length > 0) |
|||
{ |
|||
lastchar = str.Substring(str.Length - 1, 1); |
|||
} |
|||
if (firstchar.Equals("\"") && !lastchar.Equals("\"")) |
|||
{ |
|||
isSplice = true; |
|||
} |
|||
if (lastchar.Equals("\"")) |
|||
{ |
|||
if (!isSplice) |
|||
newstr += str; |
|||
else |
|||
newstr = newstr + "," + str; |
|||
|
|||
isSplice = false; |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
if (string.IsNullOrEmpty(newstr)) |
|||
newstr += str; |
|||
} |
|||
|
|||
if (isSplice) |
|||
{ |
|||
//添加因拆分时丢失的逗号
|
|||
if (string.IsNullOrEmpty(newstr)) |
|||
newstr += str; |
|||
else |
|||
newstr = newstr + "," + str; |
|||
} |
|||
else |
|||
{ |
|||
sList.Add(newstr.Replace("\"", "").Trim());//去除字符中的双引号和首尾空格
|
|||
newstr = string.Empty; |
|||
} |
|||
} |
|||
return sList.ToArray(); |
|||
} |
|||
|
|||
public static string FormatString(this string str) |
|||
{ |
|||
//if (str.Contains(","))
|
|||
// str = str.Replace(",", string.Empty);
|
|||
if (str.Contains("\"")) |
|||
str = str.Replace("\"", string.Empty); |
|||
if (str.Contains("\t")) |
|||
str = str.Replace("\t", string.Empty); |
|||
return str.Trim(); |
|||
} |
|||
} |
|||
} |
@ -1,15 +0,0 @@ |
|||
namespace BBWY.Client.Models |
|||
{ |
|||
public class AliPayBill : PayBill |
|||
{ |
|||
public AliPayBill() |
|||
{ |
|||
PayBillType = PayBillType.AliPay; |
|||
} |
|||
|
|||
public override string GetMerchantOrderNo() |
|||
{ |
|||
return base.GetMerchantOrderNo(); |
|||
} |
|||
} |
|||
} |
@ -1,10 +0,0 @@ |
|||
namespace BBWY.Client.Models |
|||
{ |
|||
public class WXPayBill : PayBill |
|||
{ |
|||
public WXPayBill() |
|||
{ |
|||
PayBillType = PayBillType.WeiXin; |
|||
} |
|||
} |
|||
} |
@ -0,0 +1,9 @@ |
|||
namespace BBWY.Client.Models |
|||
{ |
|||
public class AuditFile |
|||
{ |
|||
public string FileName { get; set; } |
|||
|
|||
public AuditFileType AuditFileType { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,73 @@ |
|||
using System; |
|||
|
|||
namespace BBWY.Client.Models |
|||
{ |
|||
public class AuditPurchaseOrder |
|||
{ |
|||
public string PurchaseOrderId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 采购平台
|
|||
/// </summary>
|
|||
public Platform Platform { get; set; } |
|||
|
|||
public DateTime CreateTime { get; set; } |
|||
|
|||
public DateTime? PayTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 采购数量
|
|||
/// </summary>
|
|||
public int Quantity { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 货款
|
|||
/// </summary>
|
|||
public decimal ProductAmount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 运费
|
|||
/// </summary>
|
|||
public decimal Freight { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 实付
|
|||
/// </summary>
|
|||
public decimal PayAmount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 联系电话
|
|||
/// </summary>
|
|||
public string Phone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 收货地址
|
|||
/// </summary>
|
|||
public string Address { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 收货人
|
|||
/// </summary>
|
|||
public string ContactName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 归属店铺
|
|||
/// </summary>
|
|||
public string BelongShop { get; set; } |
|||
|
|||
public string BelongFileName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 关联账单Id
|
|||
/// </summary>
|
|||
public string RelationPayBillNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 关联的店铺订单
|
|||
/// </summary>
|
|||
public string RelationShopOrderId { get; set; } |
|||
|
|||
|
|||
public string ErrorMessage { get; set; } |
|||
} |
|||
} |
@ -0,0 +1,70 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Text; |
|||
|
|||
namespace BBWY.Client.Models |
|||
{ |
|||
public class AuditShopOrder |
|||
{ |
|||
public string OrderId { get; set; } |
|||
|
|||
public Platform Platform { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 产品名称
|
|||
/// </summary>
|
|||
public string ProductName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 销售数量
|
|||
/// </summary>
|
|||
public int Quantity { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 实付
|
|||
/// </summary>
|
|||
public decimal PayAmount { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 下单时间
|
|||
/// </summary>
|
|||
public DateTime CreateTime { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 联系电话
|
|||
/// </summary>
|
|||
public string Phone { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 收货地址
|
|||
/// </summary>
|
|||
public string Address { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 收货人
|
|||
/// </summary>
|
|||
public string ContactName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 关联的采购单号
|
|||
/// </summary>
|
|||
public string RelationPurchaseOrderId { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 关联账单Id
|
|||
/// </summary>
|
|||
public string RelationPayBillNo { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 归属店铺
|
|||
/// </summary>
|
|||
public string BelongShop { get; set; } |
|||
|
|||
public string BelongFileName { get; set; } |
|||
|
|||
/// <summary>
|
|||
/// 错误信息
|
|||
/// </summary>
|
|||
public string ErrorMessage { get; set; } |
|||
} |
|||
} |
@ -1,11 +1,291 @@ |
|||
using System; |
|||
using BBWY.Client.Extensions; |
|||
using BBWY.Client.Models; |
|||
using BBWY.Common.Models; |
|||
using GalaSoft.MvvmLight.Command; |
|||
using Microsoft.Win32; |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Collections.ObjectModel; |
|||
using System.IO; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Windows; |
|||
using System.Windows.Input; |
|||
|
|||
namespace BBWY.Client.ViewModels |
|||
{ |
|||
public class ProcurementAuditViewModel : BaseVM |
|||
public class ProcurementAuditViewModel : BaseVM, IDenpendency |
|||
{ |
|||
private AuditFile selectAuditFile; |
|||
|
|||
public IList<AuditFile> AuditFileList { get; set; } |
|||
|
|||
public IList<AuditPayBill> AuditPayBillList { get; set; } |
|||
|
|||
public IList<AuditPurchaseOrder> AuditPurchaseOrderList { get; set; } |
|||
|
|||
public IList<AuditShopOrder> AuditShopOrderList { get; set; } |
|||
|
|||
public IList<AuditPayBill> ShowAuditPayBillList { get; set; } |
|||
|
|||
public IList<AuditPurchaseOrder> ShowAuditPurchaseOrderList { get; set; } |
|||
|
|||
public IList<AuditShopOrder> ShowAuditShopOrderList { get; set; } |
|||
|
|||
public AuditFile SelectAuditFile { get => selectAuditFile; set { Set(ref selectAuditFile, value); } } |
|||
|
|||
public ICommand AuditCommand { get; set; } |
|||
|
|||
public ICommand ClearAuditCommand { get; set; } |
|||
|
|||
public ICommand ImportAliPayBillCommand { get; set; } |
|||
|
|||
|
|||
|
|||
public ICommand Import1688PurchaseOrderCommand { get; set; } |
|||
|
|||
|
|||
|
|||
public ICommand ImportJDShopOrderCommand { get; set; } |
|||
|
|||
|
|||
|
|||
public ProcurementAuditViewModel() |
|||
{ |
|||
AuditFileList = new ObservableCollection<AuditFile>(); |
|||
AuditCommand = new RelayCommand(Audit); |
|||
ClearAuditCommand = new RelayCommand(ClearAudit); |
|||
ImportAliPayBillCommand = new RelayCommand(ImportAliPayBill); |
|||
|
|||
|
|||
Import1688PurchaseOrderCommand = new RelayCommand(Import1688PurchaseOrder); |
|||
|
|||
|
|||
ImportJDShopOrderCommand = new RelayCommand(ImportJDShopOrder); |
|||
|
|||
AuditFileList = new ObservableCollection<AuditFile>(); |
|||
AuditPayBillList = new ObservableCollection<AuditPayBill>(); |
|||
AuditPurchaseOrderList = new ObservableCollection<AuditPurchaseOrder>(); |
|||
AuditShopOrderList = new ObservableCollection<AuditShopOrder>(); |
|||
ShowAuditPayBillList = new ObservableCollection<AuditPayBill>(); |
|||
ShowAuditPurchaseOrderList = new ObservableCollection<AuditPurchaseOrder>(); |
|||
ShowAuditShopOrderList = new ObservableCollection<AuditShopOrder>(); |
|||
|
|||
//AuditFileList.Add(new AuditFile() { FileName = "支付宝账单20220527.csv", AuditFileType = AuditFileType.账单 });
|
|||
//AuditFileList.Add(new AuditFile() { FileName = "1688采购单20220527.csv", AuditFileType = AuditFileType.采购单 });
|
|||
//AuditFileList.Add(new AuditFile() { FileName = "支付宝账单20220527.csv", AuditFileType = AuditFileType.销售订单 });
|
|||
|
|||
} |
|||
|
|||
private void Audit() |
|||
{ |
|||
if (AuditPayBillList.Count() == 0 || |
|||
AuditPurchaseOrderList.Count() == 0 || |
|||
AuditShopOrderList.Count() == 0) |
|||
{ |
|||
MessageBox.Show("审核数据不全", "提示"); |
|||
return; |
|||
} |
|||
|
|||
AuditByPayBill(); |
|||
AuditByPurchaseOrder(); |
|||
} |
|||
|
|||
private void AuditByPayBill() |
|||
{ |
|||
|
|||
} |
|||
|
|||
private void AuditByPurchaseOrder() |
|||
{ |
|||
|
|||
} |
|||
|
|||
private void ClearAudit() |
|||
{ |
|||
SelectAuditFile = null; |
|||
AuditFileList.Clear(); |
|||
AuditPayBillList.Clear(); |
|||
AuditPurchaseOrderList.Clear(); |
|||
AuditShopOrderList.Clear(); |
|||
ShowAuditPayBillList.Clear(); |
|||
ShowAuditPurchaseOrderList.Clear(); |
|||
ShowAuditShopOrderList.Clear(); |
|||
} |
|||
|
|||
private (string ErrorMessage, string FileName, IList<string> Lines) ImportAuditFile(AuditFileType auditFileType) |
|||
{ |
|||
var ofd = new OpenFileDialog() { Filter = "CSV Files (*.csv)|*.csv" }; |
|||
if (ofd.ShowDialog() != true) |
|||
return (string.Empty, string.Empty, null); |
|||
var fileName = ofd.FileName.Substring(ofd.FileName.LastIndexOf("\\") + 1); |
|||
var filePath = ofd.FileName; |
|||
if (AuditFileList.Any(f => f.FileName == fileName)) |
|||
return ("文件已存在", string.Empty, null); |
|||
try |
|||
{ |
|||
var lines = File.ReadAllLines(filePath, Encoding.GetEncoding("GB2312")).ToList(); |
|||
AuditFileList.Add(new AuditFile() { FileName = fileName, AuditFileType = auditFileType }); |
|||
return (string.Empty, fileName, lines); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
return (ex.Message, string.Empty, null); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 导入支付宝账单
|
|||
/// </summary>
|
|||
private void ImportAliPayBill() |
|||
{ |
|||
var importResult = ImportAuditFile(AuditFileType.账单); |
|||
if (!string.IsNullOrEmpty(importResult.ErrorMessage)) |
|||
{ |
|||
MessageBox.Show(importResult.ErrorMessage, "导入支付宝账单"); |
|||
return; |
|||
} |
|||
//忽略前5行
|
|||
/* |
|||
#支付宝账务明细查询 |
|||
#账号:[20883422054731100156] |
|||
#起始日期:[2022年04月01日 00:00:00] 终止日期:[2022年05月01日 00:00:00] |
|||
#-----------------------------------------账务明细列表---------------------------------------- |
|||
账务流水号 业务流水号 商户订单号 商品名称 发生时间 对方账号 收入金额(+元) 支出金额(-元) 账户余额(元) 交易渠道 业务类型 备注 |
|||
*/ |
|||
for (var i = 0; i < 5; i++) |
|||
importResult.Lines.RemoveAt(0); |
|||
|
|||
//忽略后4行
|
|||
/* |
|||
#-----------------------------------------账务明细列表结束------------------------------------ |
|||
#支出合计:681笔,共-39623.27元 |
|||
#收入合计:85笔,共43889.26元 |
|||
#导出时间:[2022年05月01日 10:13:45] |
|||
*/ |
|||
for (var i = 0; i < 4; i++) |
|||
{ |
|||
importResult.Lines.RemoveAt(importResult.Lines.Count() - 1); |
|||
} |
|||
|
|||
var payBillNo = ""; |
|||
try |
|||
{ |
|||
foreach (var line in importResult.Lines) |
|||
{ |
|||
var array = line.CSVstrToArry(); |
|||
payBillNo = array[0].Replace("\"", string.Empty).Replace("\t", string.Empty).Trim(); |
|||
if (AuditPayBillList.Any(p => p.PayBillNo == payBillNo)) |
|||
continue; |
|||
var payBill = new AuditPayBill() |
|||
{ |
|||
BelongFileName = importResult.FileName, |
|||
PayBillNo = payBillNo, |
|||
PayBillType = PayBillType.AliPay, |
|||
SourceMerchantOrderNo = array[2].FormatString(), |
|||
ProductName = array[3].FormatString(), |
|||
PayTime = DateTime.Parse(array[4].FormatString()), |
|||
OppositeAccount = array[5].FormatString(), |
|||
ExpenditureAmount = decimal.Parse(array[7].FormatString()) |
|||
}; |
|||
payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo; |
|||
if (payBill.SourceMerchantOrderNo.StartsWith("T50060NP")) |
|||
payBill.MerchantOrderNo = payBill.SourceMerchantOrderNo.Substring(8); |
|||
AuditPayBillList.Add(payBill); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
MessageBox.Show($"问题账单号{payBillNo} {ex.Message}", "导入支付宝账单"); |
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 导入1688采购单
|
|||
/// </summary>
|
|||
private void Import1688PurchaseOrder() |
|||
{ |
|||
var importResult = ImportAuditFile(AuditFileType.采购单); |
|||
if (!string.IsNullOrEmpty(importResult.ErrorMessage)) |
|||
{ |
|||
MessageBox.Show(importResult.ErrorMessage, "导入1688采购单"); |
|||
return; |
|||
} |
|||
|
|||
//去掉列名
|
|||
importResult.Lines.RemoveAt(0); |
|||
|
|||
var purchaseOrderId = ""; |
|||
try |
|||
{ |
|||
foreach (var line in importResult.Lines) |
|||
{ |
|||
var array = line.CSVstrToArry(); |
|||
purchaseOrderId = array[0].FormatString(); |
|||
if (string.IsNullOrEmpty(purchaseOrderId) || AuditPurchaseOrderList.Any(p => p.PurchaseOrderId == purchaseOrderId)) |
|||
continue; |
|||
var purchaseOrder = new AuditPurchaseOrder() |
|||
{ |
|||
PurchaseOrderId = purchaseOrderId, |
|||
Platform = Platform.阿里巴巴, |
|||
BelongFileName = importResult.FileName, |
|||
ProductAmount = decimal.Parse(array[5].FormatString()), |
|||
Freight = decimal.Parse(array[6].FormatString()), |
|||
PayAmount = decimal.Parse(array[8].FormatString()), |
|||
CreateTime = DateTime.Parse(array[10].FormatString()), |
|||
ContactName = array[13].FormatString(), |
|||
Address = array[14].FormatString(), |
|||
Phone = array[17].FormatString(), |
|||
Quantity = int.Parse(array[20].FormatString()) |
|||
}; |
|||
if (!string.IsNullOrEmpty(array[11])) |
|||
purchaseOrder.PayTime = DateTime.Parse(array[11].FormatString()); |
|||
AuditPurchaseOrderList.Add(purchaseOrder); |
|||
} |
|||
Console.WriteLine(AuditPurchaseOrderList.Count()); |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
MessageBox.Show($"问题采购单号{purchaseOrderId} {ex.Message}", "导入1688采购单"); |
|||
} |
|||
|
|||
} |
|||
|
|||
/// <summary>
|
|||
/// 导入京东销售订单
|
|||
/// </summary>
|
|||
private void ImportJDShopOrder() |
|||
{ |
|||
var importResult = ImportAuditFile(AuditFileType.销售订单); |
|||
if (!string.IsNullOrEmpty(importResult.ErrorMessage)) |
|||
{ |
|||
MessageBox.Show(importResult.ErrorMessage, "导入京东销售订单"); |
|||
return; |
|||
} |
|||
|
|||
//去掉列名
|
|||
importResult.Lines.RemoveAt(0); |
|||
var orderId = ""; |
|||
try |
|||
{ |
|||
foreach (var line in importResult.Lines) |
|||
{ |
|||
var array = line.CSVstrToArry(); |
|||
orderId = array[0].FormatString(); |
|||
if (string.IsNullOrEmpty(orderId) || AuditShopOrderList.Any(p => p.OrderId == orderId)) |
|||
continue; |
|||
var order = new AuditShopOrder() |
|||
{ |
|||
OrderId = orderId, |
|||
|
|||
}; |
|||
AuditShopOrderList.Add(order); |
|||
} |
|||
} |
|||
catch (Exception ex) |
|||
{ |
|||
MessageBox.Show($"问题销售订单号{orderId} {ex.Message}", "导入京东销售订单"); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
Loading…
Reference in new issue