123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- using Common.Wechat;
- using CoreEntity.DAL;
- using CoreEntity.Entity;
- using JCSoft.WX.Framework.Api;
- using PublicLibrary.Common;
- using CoreEntity.TimedTask;
- using System;
- using System.Collections.Generic;
- using System.Text;
- using ZcPeng.weixin.PublicAccount;
- using CoreEntity.Push;
- using CoreEntity.TimeJob;
- using System.Data;
- using ZcPeng.PublicLibrary;
- using System.Data.SqlClient;
- using Common.Model;
- namespace CoreEntity.BAL
- {
- public class PushBAL
- {
- //public static Dictionary<string,Object> BatchPush(string RecordId, string FeedbackId,
- // string PushAccountId, string GoodsId, string GoodsCode
- // , string GoodsName, decimal StoreGapNum
- // , string GoodsSpec, string Manufacturer
- // , string BusinessId, string BusinessCode, string BusinessName
- // , string SuppliersId, string BrandName, string BrandId
- // , decimal PurchaseTotalNum, Decimal PurPrice
- // , string EntId, string Remark
- // , string LoginAccountId
- // , IApiClient _client)
- //{
- // List<Object> list = new List<object>(2);
- // //Object successRecord1 = 0;
- // //Object resultRecord1 = "";
- // //添加或修改推送记录
- // IDictionary<string, Object> successs1 =
- // PushRecordDAL.AddOrUpdatePushFeedBack(
- // RecordId
- // , FeedbackId,
- // Convert.ToInt32(PushAccountId), GoodsId, GoodsCode
- // , GoodsName, StoreGapNum
- // , GoodsSpec, Manufacturer
- // , BusinessId, BusinessCode, BusinessName
- // , SuppliersId, BrandName, BrandId
- // , EntId, Remark, LoginAccountId, PurPrice, PurchaseTotalNum);
- // //successs1.TryGetValue("successRecord", out successRecord1);
- // //successs1.TryGetValue("resultRecord", out resultRecord1);
- // Dictionary<string,Object> dic = new Dictionary<string, object>(2);
- // //dic.Add("successRecord1", successRecord1);
- // //dic.Add("resultRecord1", resultRecord1);
- // dic.Add("success", successs1);
- // return dic;
- //}
- public class PushInfo
- {
- private string _goodsName;
- private string _goodsNums;
- private string _totalAmount;
- private string _RecordId;
- public string GoodsName { get => _goodsName; set => _goodsName = value; }
- public string GoodsNums { get => _goodsNums; set => _goodsNums = value; }
- public string TotalAmount { get => _totalAmount; set => _totalAmount = value; }
- public string RecordId { get => _RecordId; set => _RecordId = value; }
- public static void saveGoodsNames(PushContactWithGoods fb, ref Dictionary<string, PushInfo> groupGoodsNames)
- {
- string userid = fb.UserId;
- if (fb.GetType().ToString() == "CoreEntity.Entity.PushFeedbackExt")
- userid = ((PushFeedbackExt)fb).UserId.ToString();
- if (groupGoodsNames.ContainsKey(userid))
- {
- PushInfo pushInfos;
- groupGoodsNames.TryGetValue(userid, out pushInfos);
- string GoodsName = fb.GoodsName;
- if (fb.GetType().ToString() == "CoreEntity.Entity.PushFeedbackExt")
- GoodsName = ((PushFeedbackExt)fb).GoodsName.ToString();
- decimal PurchaseTotalNum = fb.PurchaseTotalNum;
- if (fb.GetType().ToString() == "CoreEntity.Entity.PushFeedbackExt")
- PurchaseTotalNum = ((PushFeedbackExt)fb).PurchaseTotalNum;
- decimal TotalAmount = fb.PurchaseTotalNum * fb.LastPrice;
- if (fb.GetType().ToString() == "CoreEntity.Entity.PushFeedbackExt")
- TotalAmount = ((PushFeedbackExt)fb).PurchaseTotalNum * ((PushFeedbackExt)fb).LastPrice;
- pushInfos.GoodsName += "," + GoodsName;
- pushInfos.GoodsNums += "," + PurchaseTotalNum;
- pushInfos.TotalAmount += "," + TotalAmount;
- groupGoodsNames.Remove(userid);
- groupGoodsNames.Add(userid, pushInfos);
- }
- else
- {
- var pushInfo = new PushInfo { GoodsName = "", GoodsNums = "", TotalAmount = "" };
- string GoodsName = fb.GoodsName;
- if (fb.GetType().ToString() == "CoreEntity.Entity.PushFeedbackExt")
- GoodsName = ((PushFeedbackExt)fb).GoodsName.ToString();
- decimal PurchaseTotalNum = fb.PurchaseTotalNum;
- if (fb.GetType().ToString() == "CoreEntity.Entity.PushFeedbackExt")
- PurchaseTotalNum = ((PushFeedbackExt)fb).PurchaseTotalNum;
- decimal TotalAmount = fb.PurchaseTotalNum * fb.LastPrice;
- if (fb.GetType().ToString() == "CoreEntity.Entity.PushFeedbackExt")
- TotalAmount = ((PushFeedbackExt)fb).PurchaseTotalNum * ((PushFeedbackExt)fb).LastPrice;
- pushInfo.GoodsName = GoodsName;
- pushInfo.GoodsNums = PurchaseTotalNum.ToString();
- pushInfo.TotalAmount = (TotalAmount).ToString();
- groupGoodsNames.Add(userid, pushInfo);
- }
- }
- }
- public static List<Dictionary<string, Object>> pushAll(List<PushContactWithGoods> GetPushContacts, Dictionary<string, PushStorLimit> gapnum,
- string LoginAccountId, IApiClient _client)
- {
- Dictionary<string, List<PushContactWithGoods>> groups = new Dictionary<string, List<PushContactWithGoods>>();
- Dictionary<string, PushInfo> groupGoodsNames = new Dictionary<string, PushInfo>();
- foreach (PushContactWithGoods fb in GetPushContacts)
- {
- if (gapnum.ContainsKey(fb.GoodsId))
- {
- PushStorLimit limit;
- gapnum.TryGetValue(fb.GoodsId, out limit);
- fb.PurchaseTotalNum = Convert.ToInt32(limit.StoreGapNum);
- }
- if (groups.ContainsKey(fb.UserId.Trim()+"_"+fb.SaleManId))
- {
- List<PushContactWithGoods> to;
- groups.TryGetValue(fb.UserId.Trim() + "_" + fb.SaleManId, out to);
- to.Add(fb);
- groups.Remove(fb.UserId.Trim() + "_" + fb.SaleManId);
- groups.Add(fb.UserId.Trim() + "_" + fb.SaleManId, to);
-
- }
- else
- {
- List<PushContactWithGoods> to = new List<PushContactWithGoods>();
- to.Add(fb);
- groups.Add(fb.UserId.Trim() + "_" + fb.SaleManId, to);
-
- }
- fb.UserId = fb.UserId.Trim();
- PushInfo.saveGoodsNames(fb,ref groupGoodsNames);
- }
- List<Dictionary<string, Object>> result = new List<Dictionary<string, Object>>();
- //添加推送记录
- string PushCode = RandHelper.GetTimeRandId().ToString();
- var codeids = new Dictionary<string, object>(2);
- List<string> Ids = new List<string>();
- foreach (string groupkey in groups.Keys)
- {
- var grouparr = groupkey.Split("_");
- string userId = grouparr[0];
- string SaleManId = grouparr[1];
- var ContactPush = groups[groupkey][0];
- Dictionary<string, Object> successs2 =
- PushRecordDAL.AddPushRecord(PushCode,
- Convert.ToInt32(userId),
- ContactPush.ContactId,//contactid 默认关联第一个ContactId 因为可能有多个供应商对应的ContactId
- "",
- LoginAccountId,
- SaleManId
- );
- result.Add(successs2);
- Object successRecord = 0;
- successs2.TryGetValue("successRecord", out successRecord);
- Object recordId;
- successs2.TryGetValue("PushRecordId", out recordId);
- string RecordId = ((Guid)recordId).ToString();
- Ids.Add(RecordId);
- if ((int)successRecord > 0)
- {
- List<PushContactWithGoods> to;
- groups.TryGetValue(groupkey, out to);
- PushContactWithGoods fb0 = to.ToArray()[0];
- foreach (PushContactWithGoods contact in to)
- {
- int StoreGapNum = 0;
- if (gapnum.ContainsKey(contact.GoodsId))
- {
- PushStorLimit limit;
- gapnum.TryGetValue(contact.GoodsId, out limit);
- StoreGapNum = Convert.ToInt32(limit.StoreGapNum);
- }
- //string PushAccountId = contact.UserId;
- string FeedbackId = null;
- //var success = PushBAL.BatchPush(RecordId, FeedbackId,
- // contact.UserId, contact.GoodsId, contact.GoodsCode
- // , contact.GoodsName, StoreGapNum
- // , contact.GoodsSpec, contact.Manufacturer
- // , contact.BusinessId, contact.BusinessCode, contact.BusinessName
- // , contact.SuppliersId, contact.BrandName, contact.BrandId
- // , StoreGapNum, contact.LastPrice
- //, contact.EntId, ""
- //, LoginAccountId
- //, _client); IDictionary<string, Object> successs1 =
- Dictionary<string, Object>success = (Dictionary<string, Object>)PushRecordDAL.AddOrUpdatePushFeedBack(
- PushCode,
- RecordId
- , FeedbackId,
- Convert.ToInt32(userId),
- contact.ContactId,
- contact.GoodsId, contact.GoodsCode
- , contact.GoodsName, StoreGapNum
- , contact.GoodsSpec, contact.Manufacturer
- , contact.BusinessId, contact.BusinessCode, contact.BusinessName
- , contact.SuppliersId.Trim(), contact.BrandName, contact.BrandId
- , contact.EntId, contact.Remark, LoginAccountId,
- contact.LastPrice,
- contact.PurPrice,
- StoreGapNum
- , contact.SaleManId);
- result.Add(success);
- //推送供应商联系人状态设置为Y
- Dictionary<string, Object> successPush = ContactDAL.UpdatePushContactState(contact.GoodsId,contact.ContactId, contact.SuppliersId);
- result.Add(successPush);
- }
- //推送
- PushInfo pushInfos = null;
- groupGoodsNames.TryGetValue(userId, out pushInfos);
- DateTime EndTime = DateTime.Now.AddHours((double)Config.HoursToCancel);
- Message msg = TimeJob.TimeTask.sendSupplyMassMesage(_client,
- Convert.ToInt32(userId),
- RecordId,
- pushInfos.GoodsName,
- pushInfos.GoodsNums,
- pushInfos.TotalAmount,
- EndTime);
- Dictionary<string, Object> msgd = new Dictionary<string, object>(1);
- msgd.Add("msg", msg);
- result.Add(msgd);
- }
- }
- codeids.Add("PushCode", PushCode);
- codeids.Add("Ids", Ids);
- result.Add(codeids);
- return result;
- }
- public static bool Push(string LoginAccountId, string RoleId,string FilterLimit,string FilterCont,out string resultstr, IApiClient _client=null)
- {
- string msg;
- //获取推送上下限
- IList<PushStorLimit> pushLimits = PushRecordDAL.GetPushLimit(FilterLimit);
- if (pushLimits.Count == 0)
- {
- resultstr = "没有选择库存低于下限品种";
- return false;
- }
- string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
- //获取待推送账户:上次供货业务员,取最低价格的业务员
- string filterstr = FilterCont + " and UserId IS NOT NULL and UserId !='' "
- // +" and FocusMicNo IS NOT NULL and FocusMicNo !='' "
- + FilterRuleByPur.getRolePermFilter(RoleId, " and SaleManId = '" + StaffDocId + "' ") //只查询当前采购员的联系人
- ;
- Dictionary<string, PushStorLimit> gapnum;
- List<PushContactWithGoods> GetPushContacts = ContactBAL.GetPushContactWithGoods(filterstr, "", pushLimits, out gapnum,out _);
- //判断参数是否合法
- if (GetPushContacts.Count == 0)
- {
- resultstr = "没有建立账户,或者业务员没有绑定";
- return false;
- }
- //添加推送记录并推送
- var result = PushBAL.pushAll(GetPushContacts, gapnum, LoginAccountId, _client);
- var codeids = result[result.Count - 1];
- Object Ids;
- codeids.TryGetValue("Ids", out Ids);
- List<String> ids = (List<String>)Ids;
- foreach (String recordId in ids)
- {
- CancelPushRecordTimedJob.CancelPushRecord(recordId, DateTime.Now, CancelPushRecordTimedJob.HoursToCancel);
- }
- resultstr = result.ToString();
- return true;
- }
- public static bool PushOrderConfirm(string LoginAccountId, string RoleId, string Filter, out string resultstr, IApiClient _client = null)
- {
- var sql = "select A.* from PurOrderMT A "+
- "left join sup_PushOrderMT B on B.BillNo = A.BillNo " +
- "where A.IsEnd = 'N' and A.IsDone = 'N' and A.BillState = 0 and A.source != 'coop.360lj.com' " +
- " and B.Id is null ";
- string result = "";
- DataTable dt = new DataTable();
- List<SqlParameter> param = new List<SqlParameter>(0);
- DataAccess.GetValues(sql,ref dt, param.ToArray(), out result);
- IList<PurOrderMTEx> psls = new List<PurOrderMTEx>();
- Dictionary<string, List<PurOrderMTEx>> group = new Dictionary<string, List<PurOrderMTEx>>();
- List<DataAccessCommand> list = new List<DataAccessCommand>(5);
- if (dt != null && dt.Rows.Count > 0)
- {
- // 把DataTable转换为IList<UserInfo>
- psls = ModelConvertHelper<PurOrderMTEx>.ConvertToModel(dt);
- foreach (PurOrderMTEx purOrder in psls)
- {
- ContactDoc cont = null;
- if(!string.IsNullOrWhiteSpace(purOrder.K_ContactId))
- cont = ContactDAL.getContactor(purOrder.K_ContactId.Trim(' '));
- if(cont!=null && !string.IsNullOrWhiteSpace(cont.UserId) && !string.IsNullOrWhiteSpace(cont.FocusMicNo))
- {
- var sql1 = "select A.*,B.AccountRealName as Contact,C.GoodsName,C.GoodsSpec,C.GoodsCode,C.Manufacturer" +
- ",D.ApprovalNo,E.BusinessName from PurOrderDT A " +
- " left join PurOrderMT A1 on A1.BillNo = A.BillNo " +
- " left join sup_Account B on B.PurStaffId = A1.SaleManId " +
- " left join GoodsDoc C on C.EntId = A.EntId and C.GoodsId = A.GoodsId " +
- " left join GoodsAttr D on D.GoodsId = C.GoodsId and D.EntId = C.EntId " +
- " left join BusinessDoc E on E.BusinessId = A1.SuppliersId and E.EntId = A1.EntId " +
- " where A.BillNo = @BillNo ";
- List<SqlParameter> param1 = new List<SqlParameter>(1);
- param1.Add(new SqlParameter("BillNo", purOrder.BillNo));
- purOrder.Orderdts = DataAccess.GetValues<PurOrderDTEx>(sql1, param1,out var msg);
- //添加推送记录
- PushOrderDAL.AddPushOrderMT(cont.UserId, purOrder, ref list,out var Id);
- //添加推送记录明细
- foreach(PurOrderDTEx orderDt in purOrder.Orderdts) {
- PushOrderDAL.AddPushOrderDT(cont.UserId, Id, purOrder, orderDt, ref list);
- }
- //加入推送分组
- if (!group.ContainsKey(cont.UserId)) {
- List < PurOrderMTEx > orlist = new List<PurOrderMTEx>(3);
- orlist.Add(purOrder);
- group[cont.UserId] = orlist;
- }
- else
- {
- List<PurOrderMTEx> orlist = group[cont.UserId];
- orlist.Add(purOrder);
- group.Remove(cont.UserId);
- group[cont.UserId] = orlist;
- }
- //foreach (var orderlist in group)
- //{
- var sendmsg = ConfirmOrderTask.sendSupplyMassMesage(_client, cont.UserId, purOrder.BillNo.ToString(),
- purOrder.Orderdts[0].GoodsName+"...", purOrder.Orderdts[0].Num.ToString() + "...",
- purOrder.Orderdts[0].TaxAmount.ToString() + "...", new DateTime());
- //}
- }
- }
- }
- DataAccess.ExecuteBatchCommands(list, out var resultmsg);
- resultstr = resultmsg;
- return false;
- }
- public static string PreOPaidTypeId = "PICDM6CL55K";
- public static string OPaidTypeId = "PICDM6CGKQC";
- public static string PicPreHost = "http://119.130.113.246:8999/";
- public static bool PushPaidBackMsg(string LoginAccountId, string RoleId, string Filter, out string resultstr, IApiClient _client = null)
- {
- var sql = " select A.* from sup_PushPaidBackMsg A "+
- " left join sup_PaidBackMsg B on B.ReBillNo = A.ReBillNo " +
- " where 1=1 " +
- " and B.BillNo is null ";
- string result = "";
- DataTable dt = new DataTable();
- List<SqlParameter> param = new List<SqlParameter>(0);
- DataAccess.GetValues(sql, ref dt, param.ToArray(), out result);
- IList<sup_PushPaidBackMsg> psls = new List<sup_PushPaidBackMsg>();
- Dictionary<string, List<sup_PushPaidBackMsg>> group = new Dictionary<string, List<sup_PushPaidBackMsg>>();
- List<DataAccessCommand> list = new List<DataAccessCommand>(5);
- if (dt != null && dt.Rows.Count > 0)
- {
- // 把DataTable转换为IList<UserInfo>
- psls = ModelConvertHelper<sup_PushPaidBackMsg>.ConvertToModel(dt);
- foreach (sup_PushPaidBackMsg PaidBackMsg in psls)
- {
- ContactDoc cont = null;
- if (!string.IsNullOrWhiteSpace(PaidBackMsg.K_ContactId))
- cont = ContactDAL.getContactor(PaidBackMsg.K_ContactId.Trim(' '));
- String url = "";
- if (cont != null && !string.IsNullOrWhiteSpace(cont.UserId) && !string.IsNullOrWhiteSpace(cont.FocusMicNo))
- {
- if (PaidBackMsg.PICTYPEID !=null && PaidBackMsg.PICTYPEID.Trim().Equals(PreOPaidTypeId))
- {
- var sql1 = "select A.*,B.AccountRealName as Contact,C.GoodsName,C.GoodsSpec,C.GoodsCode,C.Manufacturer" +
- ",D.ApprovalNo,E.BusinessName from PurOrderDT A " +
- " left join PurOrderMT A1 on A1.BillNo = A.BillNo " +
- " left join sup_Account B on B.PurStaffId = A1.SaleManId " +
- " left join GoodsDoc C on C.EntId = A.EntId and C.GoodsId = A.GoodsId " +
- " left join GoodsAttr D on D.GoodsId = C.GoodsId and D.EntId = C.EntId " +
- " left join BusinessDoc E on E.BusinessId = A1.SuppliersId and E.EntId = A1.EntId " +
- " where A.BillNo = @BillNo ";
- List<SqlParameter> param1 = new List<SqlParameter>(1);
- param1.Add(new SqlParameter("BillNo", PaidBackMsg.ReBillNo));
- PaidBackMsg.Orderdts = DataAccess.GetValues<PurOrderDTEx>(sql1, param1, out var msg);
- url = "https://" + Config.Host + "/web/supplymobile/listorder?TypeId=" + PreOPaidTypeId + "&OrderBillNo=" + PaidBackMsg.ReBillNo + "&picUrl=" +
- PicPreHost + PaidBackMsg.ATTACHID;
- }
- else if (PaidBackMsg.PICTYPEID != null && PaidBackMsg.PICTYPEID.Trim().Equals(OPaidTypeId))
- {
- PaidBackMsg.Orderdts = PushPaidBackMsgDAL.GetPaidBackMsgDT(PaidBackMsg.ReBillNo);
- url = "https://" + Config.Host + "/web/supplymobile/listorder?TypeId="+ OPaidTypeId + "&OrderBillNo=" + PaidBackMsg.ReBillNo+"&picUrl="+
- PicPreHost + PaidBackMsg.ATTACHID;
- }
- //添加推送记录
- PushOrderDAL.AddPaidBackMsg(cont.UserId, PaidBackMsg, ref list, out var Id);
- //加入推送分组
- if (!group.ContainsKey(cont.UserId))
- {
- List<sup_PushPaidBackMsg> orlist = new List<sup_PushPaidBackMsg>(1);
- orlist.Add(PaidBackMsg);
- group[cont.UserId] = orlist;
- }
- else
- {
- List<sup_PushPaidBackMsg> orlist = group[cont.UserId];
- orlist.Add(PaidBackMsg);
- group.Remove(cont.UserId);
- group[cont.UserId] = orlist;
- }
- //foreach (var orderlist in group)
- //{
- var sendmsg = PaidBackMsgTask.sendSupplyMassMesage(_client, cont.UserId, PaidBackMsg.ReBillNo.ToString(),
- PaidBackMsg.Orderdts[0].GoodsName + "...", PaidBackMsg.Orderdts[0].Num.ToString() + "...",
- PaidBackMsg.Orderdts[0].TaxAmount.ToString() + "...",url, new DateTime());
- //}
- }
- }
- }
- DataAccess.ExecuteBatchCommands(list, out var resultmsg);
- resultstr = resultmsg;
- return false;
- }
- }
- }
|