You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

550 lines
19 KiB
C#

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using DevComponents.DotNetBar;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using NLog;
using POSV.HttpApi;
using POSV.HttpResponse;
using POSV.Proxy.ThirdPartyOrder;
using POSV.ThirdPartyOrderData;
using POSV.Utils;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace POSV.WeiXin
{
public partial class WeixinProgramForm : BusinessForm
{
private static Logger logger = NLog.LogManager.GetCurrentClassLogger();
private JuWeiAppOrderProxy _juWeiAppOrderProxy = null;
/// <summary>
/// 小程序门店信息
/// </summary>
private ProgramStoreDetailData _storeDetailData = null;
/// <summary>
/// 小程序门店商品信息
/// </summary>
private ProgramProductObject _programProductObject = null;
public WeixinProgramForm()
{
InitializeComponent();
this.Name = "WeixinMiniProgramForm";
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
if (this.DesignMode) return;
this._juWeiAppOrderProxy = new JuWeiAppOrderProxy();
var _shopInfo = _juWeiAppOrderProxy.GetShopInfo();
if (_shopInfo.Item1)
{
this._storeDetailData = _shopInfo.Item3;
//获取门店成功
if (this._storeDetailData != null)
{
this.lblStoreName.Text = this._storeDetailData.Storename;
this.lblIsOpen.Text = (this._storeDetailData.Isopen == 1) ? "营业中" : "歇业中";
this.lblOpenTime.Text = this._storeDetailData.Opentime.Replace(",", "\r\n");
RefreshUI();
}
else
{
this.ShowToastNotify(this, "获取门店信息失败!");
}
}
else
{
this.ShowToastNotify(this, _shopInfo.Item2);
}
}
private void RefreshUI()
{
if (this.IsDisposed || !this.IsHandleCreated) return;
if (!Global.Instance.Online)
{
this.ShowToastNotify(this, "网络不稳定或脱机模式下,无法使用本功能");
return;
}
Task.Factory.StartNew(() =>
{
if (this._storeDetailData != null)
{
var _data = _juWeiAppOrderProxy.GetProduct(this._storeDetailData.ProgramId, this._storeDetailData.Storeid);
if (_data.Item1)
{
this._programProductObject = _data.Item3.Data;
}
if (this._programProductObject != null)
{
this.Invoke(new Action(() =>
{
//绑定分类显示
this.weixinCategoryX.BindDataSource(_data.Item3.Data.listCategory);
var selectedCategorys = this.weixinCategoryX.SelectedCategorys.Keys.ToList();
//全部小程序商品
var allSpecsList = _data.Item3.Data.listProductSpec.OrderBy(x=>x.typePath).OrderBy(x => x.stock).ToList();
//售罄小程序商品
var selloutSpecsList = allSpecsList.Where(x => {
//是否售罄0-售罄
decimal stock = 0.0M;
decimal.TryParse(string.IsNullOrEmpty(x.stock) ? "0" : x.stock, out stock);
return stock <= 0;
}).ToList();
//可售小程序商品
var sellinSpecsList = allSpecsList.Where(x => {
//是否售罄0-售罄
decimal stock = 0.0M;
decimal.TryParse(string.IsNullOrEmpty(x.stock) ? "0" : x.stock, out stock);
return stock > 0;
}).ToList();
var _dataSource = new List<ListProductSpec>();
//仅显示售罄
if (this.chkSellout.Checked)
{
_dataSource.AddRange(selloutSpecsList);
}
else if (this.chkSellin.Checked)
{
_dataSource.AddRange(sellinSpecsList);
}
else
{
_dataSource.AddRange(selloutSpecsList);
_dataSource.AddRange(sellinSpecsList);
}
this.weixinProductX.BindDataSource(_dataSource, selectedCategorys);
this.lblTotal.Text = string.Format(this.lblTotal.Tag.ToString(), allSpecsList.Count, selloutSpecsList.Count, sellinSpecsList.Count);
}));
}
else
{
this.Invoke(new Action(() =>
{
this.ShowToastNotify(this, "获取小程序商品信息失败!");
}));
}
}
});
}
private void OnControlBoxMinClick(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
}
private void OnCloseTouchClick(object sender, EventArgs e)
{
//先关闭父窗体
if (this.Owner != null)
{
this.Owner.Close();
}
//再关闭当前窗体
this.Close();
}
private void BtnClose(object sender, EventArgs e)
{
OnCloseTouchClick(sender, e);
}
private void OnButtonSaleIn(object sender, EventArgs e)
{
if (!Global.Instance.Online)
{
this.ShowToastNotify(this, "网络不稳定或脱机模式下,无法使用本功能");
return;
}
if (this._storeDetailData == null)
{
this.ShowToastNotify(this, "获取门店绑定的小程序信息失败");
return;
}
if (this._programProductObject == null)
{
this.ShowToastNotify(this, "获取门店小程序商品信息失败");
return;
}
var button = sender as ButtonX;
try
{
button.Enabled = false;
if (weixinCategoryX.SelectedCategorys.Count <=0 && weixinProductX.SelectedProducts.Count <= 0)
{
this.ShowToastNotify(this, "请选择要开卖的品类或者单品");
return;
}
string message = "";
ProgramProductSaleinRequest request = new ProgramProductSaleinRequest();
request.StoreId = this._storeDetailData.Storeid;
//优先处理单品信息
if(weixinProductX.SelectedProducts.Count > 0)
{
var obj = from o in weixinProductX.SelectedProducts select o.specId;
var specIds = string.Join(",", obj.ToArray());
request.SpecIds = specIds;
request.ProductTypeIds = "";
message = "开卖选中的"+ obj.Count() + "个单品";
}
else
{
var obj = weixinProductX.SelectedCategorys.ToArray();
var productTypeIds = string.Join(",", obj);
request.ProductTypeIds = productTypeIds;
request.SpecIds = "";
message = "开卖选中的" + obj.Length + "个品类";
}
var dialog = new DialogForm("操作提醒", "确定" + message + "", MessageBoxIcon.Warning, MessageBoxButtons.OKCancel);
dialog.BringToFront();
if (dialog.ShowDialog(this) == DialogResult.OK)
{
var response = _juWeiAppOrderProxy.ProductSalein(request);
if (response.Item1)
{
this.ShowToastNotify(this, "开卖操作成功");
this.weixinProductX.SelectedProducts.Clear();
RefreshUI();
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
}
finally
{
button.Enabled = true;
}
}
private void OnCategoryXCheckedChanged(object sender, WeixinCategoryXEventArgs e)
{
if(e.Data != null)
{
if(this._programProductObject == null)
{
this.ShowToastNotify(this,"获取小程序门店商品信息失败");
return;
}
var selectedCategorys = e.Data.Keys.ToList();
this.Invoke(new Action(() =>
{
var dataSource = processListData(this._programProductObject.listProductSpec);
this.weixinProductX.BindDataSource(dataSource, selectedCategorys.Count > 0 ? selectedCategorys : null );
}));
}
}
private List<ListProductSpec> processListData(List<ListProductSpec> lists)
{
var _dataSource = new List<ListProductSpec>();
try
{
//全部小程序商品
var allSpecsList = lists.OrderBy(x => x.typePath).OrderBy(x => x.stock).ToList();
//售罄小程序商品
var selloutSpecsList = allSpecsList.Where(x => {
//是否售罄0-售罄
decimal stock = 0.0M;
decimal.TryParse(string.IsNullOrEmpty(x.stock) ? "0" : x.stock, out stock);
return stock <= 0;
}).ToList();
//可售小程序商品
var sellinSpecsList = allSpecsList.Where(x => {
//是否售罄0-售罄
decimal stock = 0.0M;
decimal.TryParse(string.IsNullOrEmpty(x.stock) ? "0" : x.stock, out stock);
return stock > 0;
}).ToList();
//仅显示售罄
if (this.chkSellout.Checked)
{
_dataSource.AddRange(selloutSpecsList);
}
else if (this.chkSellin.Checked)
{
_dataSource.AddRange(sellinSpecsList);
}
else
{
_dataSource.AddRange(selloutSpecsList);
_dataSource.AddRange(sellinSpecsList);
}
}
catch(Exception ex)
{
logger.Error(ex, "排序小程序商品异常");
}
return _dataSource;
}
private void OnButtonSaleout(object sender, EventArgs e)
{
if (!Global.Instance.Online)
{
this.ShowToastNotify(this, "网络不稳定或脱机模式下,无法使用本功能");
return;
}
if (this._storeDetailData == null)
{
this.ShowToastNotify(this, "获取门店绑定的小程序信息失败");
return;
}
if (this._programProductObject == null)
{
this.ShowToastNotify(this, "获取门店小程序商品信息失败");
return;
}
var button = sender as ButtonX;
try
{
button.Enabled = false;
if (weixinCategoryX.SelectedCategorys.Count <= 0 && weixinProductX.SelectedProducts.Count <= 0)
{
this.ShowToastNotify(this, "请选择要开卖的品类或者单品");
return;
}
string message = "";
ProgramProductSaleoutRequest request = new ProgramProductSaleoutRequest();
request.StoreId = this._storeDetailData.Storeid;
//优先处理单品信息
if (weixinProductX.SelectedProducts.Count > 0)
{
var obj = from o in weixinProductX.SelectedProducts select o.specId;
var specIds = string.Join(",", obj.ToArray());
request.SpecIds = specIds;
request.ProductTypeIds = "";
message = "停售选中的" + obj.Count() + "个单品";
}
else
{
var obj = weixinProductX.SelectedCategorys.ToArray();
var productTypeIds = string.Join(",", obj);
request.SpecIds = "";
message = "停售选中的" + obj.Length + "个品类";
}
var dialog = new DialogForm("操作提醒", "确定"+ message + "", MessageBoxIcon.Warning, MessageBoxButtons.OKCancel);
if (dialog.ShowDialog(this) == DialogResult.OK)
{
var response = _juWeiAppOrderProxy.ProductSaleout(request);
if (response.Item1)
{
this.ShowToastNotify(this, "停售操作成功");
this.weixinProductX.SelectedProducts.Clear();
RefreshUI();
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
}
finally
{
button.Enabled = true;
}
}
private void OnButtonSaleInAll(object sender, EventArgs e)
{
if (!Global.Instance.Online)
{
this.ShowToastNotify(this, "网络不稳定或脱机模式下,无法使用本功能");
return;
}
if (this._storeDetailData == null)
{
this.ShowToastNotify(this, "获取门店绑定的小程序信息失败");
return;
}
if (this._programProductObject == null)
{
this.ShowToastNotify(this, "获取门店小程序商品信息失败");
return;
}
var dialog = new DialogForm("操作提醒", "是否开卖全部小程序商品?", MessageBoxIcon.Warning, MessageBoxButtons.OKCancel);
if (dialog.ShowDialog(this) == DialogResult.OK)
{
var button = sender as ButtonX;
try
{
button.Enabled = false;
ProgramProductSaleinRequest request = new ProgramProductSaleinRequest();
request.StoreId = this._storeDetailData.Storeid;
request.ProductTypeIds = "";
request.SpecIds = "";
var response = _juWeiAppOrderProxy.ProductSalein(request);
if (response.Item1)
{
this.ShowToastNotify(this, "全部开卖操作成功");
this.weixinCategoryX.SelectedCategorys.Clear();
this.weixinProductX.SelectedProducts.Clear();
RefreshUI();
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
finally
{
button.Enabled = true;
}
}
}
private void OnButtonSaleoutAll(object sender, EventArgs e)
{
if (!Global.Instance.Online)
{
this.ShowToastNotify(this, "网络不稳定或脱机模式下,无法使用本功能");
return;
}
if (this._storeDetailData == null)
{
this.ShowToastNotify(this, "获取门店绑定的小程序信息失败");
return;
}
if (this._programProductObject == null)
{
this.ShowToastNotify(this, "获取门店小程序商品信息失败");
return;
}
var dialog = new DialogForm("操作提醒", "是否停售全部小程序商品?", MessageBoxIcon.Warning, MessageBoxButtons.OKCancel);
if (dialog.ShowDialog(this) == DialogResult.OK)
{
var button = sender as ButtonX;
try
{
button.Enabled = false;
ProgramProductSaleoutRequest request = new ProgramProductSaleoutRequest();
request.StoreId = this._storeDetailData.Storeid;
request.ProductTypeIds = "";
request.SpecIds = "";
var response = _juWeiAppOrderProxy.ProductSaleout(request);
if (response.Item1)
{
this.ShowToastNotify(this, "全部停售操作成功");
this.weixinCategoryX.SelectedCategorys.Clear();
this.weixinProductX.SelectedProducts.Clear();
RefreshUI();
}
else
{
this.ShowToastNotify(this, response.Item2);
}
}
finally
{
button.Enabled = true;
}
}
}
private void OnSelloutChecked(object sender, EventArgs e)
{
if (this.chkSellout.Checked)
{
this.chkSellin.Checked = false;
}
RefreshUI();
}
private void OnSellinChecked(object sender, EventArgs e)
{
if (this.chkSellin.Checked)
{
this.chkSellout.Checked = false;
}
RefreshUI();
}
}
}