1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516 |
- using JCSoft.WX.Framework.Api;
- using Microsoft.AspNetCore.Mvc;
- using Microsoft.AspNetCore.Http;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Threading.Tasks;
- using Common.Wechat;
- using Common;
- using System.Data;
- using ZcPeng.PublicLibrary;
- using CoreEntity.Entity;
- using Common.Model;
- using Newtonsoft.Json.Converters;
- using Newtonsoft.Json;
- using System.Data.SqlClient;
- using ZcPeng.weixin.PublicAccount;
- using CoreEntity.DAL;
- using PublicLibrary.Model;
- using Microsoft.Extensions.Caching.Memory;
- using CoreEntity.BAL;
- using static CoreEntity.BAL.PushBAL;
- using SupplierWeb.Codes.mvc;
- using SupplierWeb.Codes.Push;
- using CoreEntity.TimedTask;
- using System.Collections.Concurrent;
- using Microsoft.AspNetCore.Hosting;
- using static SupplierWeb.Controllers.NewGoodsController;
- using System.IO;
- using Npoi.Mapper;
- using LigerRM.Common;
- namespace SupplierWeb.Controllers
- {
- [Route("web/pushall")]
- public class PushController : BaseController
- {
- public PushController(IMemoryCache cache, IApiClient client) : base(cache, client)
- {
- }
- private ConcurrentDictionary<int, Role> roleMap = new ConcurrentDictionary<int, Role>();
- [AuthPermission]
- [HttpPost, Route("permissionRole")]
- public JsonResult PermissionRole(QueryFilter[] filters, String permissions, [FromBody]dynamic data)
- {
- string result;
- String roleids = "";
- if (data != null)
- {
- filters = data.filters.ToObject<QueryFilter[]>();
- permissions = data.temp;
- }
- #region 获取权限列表
- DataTable dt = new DataTable();
- IList<Permission> permss = new List<Permission>(0);
- List<SqlParameter> parameters = new List<SqlParameter>();
- string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters, new Permission(), "A.");
- #endregion
- if (dt != null && dt.Rows.Count > 0)
- {
- // 把DataTable转换为IList<Permission>
- permss = ModelConvertHelper<Permission>.ConvertToModel(dt);
- #region 获取权限的角色列表
- //角色列表
- IList<Role> roles = RoleDAL.GetRoles();
- // 把DataTable转换为IList<Role>
- if (roleMap.Count < roles.Count)
- {
- foreach (Role role in roles)
- {
- roleMap.TryAdd(role.Id, role);
- }
- }
- //for (var i = 0;i < )
- //{
- //}
- String permissionIds = permissions.Substring(0, permissions.Length - 1);
- string commonText = "select RO.roleId as roleId from " +
- Config.TablePrefix + "Permission A," +
- Config.TablePrefix + "RoleRelatePermission RP "
- + " WHERE 1=1 AND A.isdelete = '0' AND A.AuthType in('A','O') " +
- "and A.id = RP.PermissionId and A.id in (" + permissionIds + ")";
- bool success = DataAccess.GetValues(commonText, ref dt, parameters.ToArray(), out result);
- // 把DataTable转换为IList<RoleRelatePermission>
- if (dt != null && dt.Rows.Count > 0)
- {
- IList<RoleRelatePermission> permRelates = ModelConvertHelper<RoleRelatePermission>.ConvertToModel(dt);
- List<int> superior_list = new List<int>(0);
- foreach (RoleRelatePermission permsr in permRelates)
- {
- superior_list.Add(permsr.RoleId);
- }
- roleids = string.Join(",", superior_list.ToArray());
- }
- //}
- #endregion
- }
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- var jsonData = JsonConvert.SerializeObject(permss, timejson);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- RoleId = roleids
- });
- }
- /// <summary>
- ////手动保存并推送:
- ///选出已经建立账户的供应商业务员推送
- /// </summary>
- /// <param name="Id">推送id</param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("saveandpush")]
- public ActionResult SaveAndPush(
- //string Id,
- DateTime start,
- [FromBody]dynamic data)
- {
- string userids;
- string LoginAccountId = userids = getStaff("userid");
- string RoleId = getStaff("roleid");
- //判断参数是否合法
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- success = 0,
- msg="没有登陆"
- });
- }
- string[] goodsIds = null;
- PushContactWithGoods[] contacws = null;
- if (data != null)
- {
- //Newtonsoft.Json.Linq.JArray
- //Id = data.Id;
- goodsIds = data.goodsIds.ToObject<string[]>();
- contacws = data.contactws.ToObject<PushContactWithGoods[]>();
- }
- string filterlimit = "";
- string filtercont = "";
- //string filtercontact = "";
- //if (Id != null&& Id != "")
- //{
- // filterlimit =
- // "and GoodsId in (select GoodsId from "
- // + Config.TablePrefix+"PushFeedback where " +
- // "PushRecordId = "+Id+")";
- // filtercontact = " and exists (select 1 from "
- // + Config.TablePrefix + "PushFeedback where 1=1 " +
- // " and PushRecordId = " + Id + "" +
- // " and PushAccountId = UserId " +
- // ") ";
- //}
- if (goodsIds!=null && goodsIds.Length > 0)
- {
- string goodsIdStr = string.Join("','", goodsIds);
- filterlimit =
- " and GoodsId in ('" + goodsIdStr + "') ";
- string contactwgs = string.Join("','", contacws.Where(contact => (contact.ContactId != "" && contact.ContactId !=null)));
- filtercont =
- " and ContactId in ('" + contactwgs + "') ";
- }
- if (start != null && !start.ToString().StartsWith("0001"))
- {
- TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), RoleId, LoginAccountId,
- filterlimit,filtercont, _client).GetAwaiter().GetResult();
- }
- /*
- //获取推送上下限
- IList<PushStorLimit> pushLimits = PushRecordDAL.GetPushLimit(filterlimit);
- if(pushLimits.Count == 0)
- return Json(new
- {
- success = 0,
- result = "没有选择库存低于下限品种",
- });
- // 获取待推联系人 绑定账户 和微信
- 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 + "' ") //只查询当前采购员的联系人
- //+ filtercontact
- ;
- Dictionary<string, PushStorLimit> gapnum;
- List<PushContactWithGoods> GetPushContacts = ContactBAL.GetPushContactWithGoods( filterstr,"", pushLimits, out gapnum);
- //判断参数是否合法
- if (GetPushContacts.Count == 0)
- {
- return Json(new
- {
- success = 0,
- msg = "没有建立账户,或者业务员没有绑定"
- });
- }
- 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);
- }
- */
-
- bool success = PushBAL.Push(LoginAccountId, RoleId,filterlimit,filtercont, out var result,_client);
-
- return Json(new
- {
- success = success,
- result = result,
- });
- }
- //自动推送
- [AuthPermission]
- [HttpPost, Route("push")]
- public ActionResult Push(
- DateTime start,
- [FromBody]dynamic data)
- {
- string userids;
- string LoginAccountId = userids = getStaff("userid");
- string RoleId = getStaff("roleid");
- //判断参数是否合法
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- success = 0,
- msg = "没有登陆"
- });
- }
-
- string[] goodsIds = null;
- PushContactWithGoods[] contacws = null;
- if (data != null)
- {
- //Newtonsoft.Json.Linq.JArray
- start = data.start;
- goodsIds = data.goodsIds.ToObject<string[]>();
- contacws = data.contactws.ToObject<PushContactWithGoods[]>();
- }
- string filterlimit = "";
- string filtercont = "";
- if (goodsIds != null && goodsIds.Length > 0)
- {
- string goodsIdStr = string.Join("','", goodsIds);
- filterlimit =
- " and GoodsId in ('" + goodsIdStr + "') ";
- string contactwgs = string.Join("','", contacws.Where(contact => (contact.ContactId != "" && contact.ContactId != null)));
- filtercont =
- " and ContactId in ('" + contactwgs + "') ";
- }
- TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), RoleId, LoginAccountId,
- filterlimit,filtercont,_client).GetAwaiter().GetResult();
- return Json(new
- {
- success = 1
- });
- }
- ////供应商业务员修改过的记录:手动保存并添加待推业务员:
- //[AuthPermission]
- //[HttpPost, Route("saveandrepush/{editpush}")]
- //public ActionResult SaveAndRePush(
- // string Id, string LoginAccountId,
- // DateTime start,
- // int editpush,
- // List<PushFeedbackExt> pfbs,
- // [FromBody]dynamic data)
- //{
- // string RecordId = string.Empty;
- // if (data != null)
- // {
- // //Newtonsoft.Json.Linq.JArray
- // Id = data.Id;
- // if (Id != null)
- // RecordId = Id;
- // LoginAccountId = data.LoginAccountId;
- // start = data.PushTime!=null? data.PushTime:DateTime.Now;
- // pfbs = data.pfbs.ToObject<PushFeedbackExt[]>();
- // }
- // //string userids;
- // //string LoginAccountId = userids = getStaffUserid(staffId);
- // //判断参数是否合法
- // if (string.IsNullOrEmpty(LoginAccountId))
- // {
- // return Json(new
- // {
- // success = 0,
- // msg = "没有登陆"
- // });
- // }
- // //if (start != null && !start.ToString().StartsWith("0001"))
- // //{
- // // TimedProgram.RunProgram(start.Second.ToString(), start.Minute.ToString(), start.Hour.ToString(), _client).GetAwaiter().GetResult();
- // //}
- // string filterlimit = "";
- // string filtercontact = "";
- // if (Id != null && Id != "")
- // {
- // filterlimit =
- // " and GoodsId in (select GoodsId from LJHYBZK.dbo."
- // + Config.TablePrefix + "PushFeedback where 1=1 " +
- // " and PushRecordId = '" + Id + "' " +
- // " and State IS NULL or State in (0,6,5)" +
- // ")";
- // filtercontact = " and exists (select 1 from "
- // + Config.TablePrefix + "PushFeedback A where 1=1 " +
- // " and A.PushRecordId = '" + Id + "' " +
- // " and State IS NULL or State in (0,6,5) " +
- // " and PushAccountId = UserId " +
- // " and A.GoodsId = GoodsId " +
- // ")";
- // }
- // //获取推送上下限
- // IList<PushStorLimit> pushLimits = PushRecordDAL.GetPushLimit(filterlimit);
- // string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
- // // 获取待推联系人 绑定账户 保存推送记录不需要绑定微信
- // string filterstr =
- // " and UserId IS NOT NULL and UserId !=''" +
- // //" and FocusMicNo IS NOT NULL and FocusMicNo !='' "+
- // //" and SaleManId = '"+StaffDocId+"' " +//只查询当前采购员的联系人
- // filtercontact;
- // Dictionary<string, PushStorLimit> gapnum;
- // List<PushContactWithGoods> GetPushContacts = ContactBAL.GetPushContactWithGoods(filterstr, ",t1.ContactId,t1.SuppliersId ", pushLimits, out gapnum);
- // //判断参数是否合法
- // if (GetPushContacts.Count == 0)
- // {
- // return Json(new
- // {
- // success = 0,
- // msg = "业务员没有绑定,或者没有建立账户"
- // });
- // }
- // DateTime EndTime = DateTime.Now.AddHours((double)24);
- // String loginAccountId = string.Empty;
-
- // string filter = "";
- // if (editpush == 0)
- // filter = " and State in (5,6) ";
- // else if(editpush == 1)
- // filter = " and State IS NULL or State = 0 " +
- // " ";
- // List<PushFeedbackExt> list = PushFeedBackDAL.GetFeedbacks(Id, filter);
- // PushRecord prec = PushRecordDAL.GetRecord(Id);
- // List<Object> result = new List<object>();
- // int successAll = 1;
- // foreach(PushFeedback feedback in list) {
- // int OldPushAccountId = feedback.PushAccountId;
- // int newPushAccountId = OldPushAccountId;
- // PushFeedback newpfb = null;
- // foreach (PushFeedback pfb in pfbs)
- // {
- // //根据userid 初始化PushAccountId SuppliersId
- // string[] ContactIds = pfb.ContactId.Split("_");
- // string PushAccountId = "";
- // if (ContactIds.Length > 2)
- // {
- // pfb.ContactId = ContactIds[0];
- // pfb.SuppliersId = ContactIds[1];
- // PushAccountId = ContactIds[3];
- // }
- // if(PushAccountId!=null&& PushAccountId != "")
- // pfb.PushAccountId = Convert.ToInt32(PushAccountId);
- // if (PushAccountId == ""|| PushAccountId==null)
- // {
- // return Json(new
- // {
- // success = 0,
- // msg = "业务员没有绑定,或者没有建立账户"
- // });
- // }
- // ////ContactDoc cdoc = AccountDAL.getContactor(pfb.ContactId);
- // //List<PushContactWithGoods> users = ContactBAL.GetPushContactWithGoods(
- // // " and ContactId in ('" + ContactId + "') " +
- // // " and GoodsId in ('" + pfb.GoodsId + "')", ",t1.ContactId,t1.SuppliersId",
- // // new List<PushStorLimit>(),
- // // out gapnum);
- // //PushContactWithGoods cdoc = null;
- // //if (users.Count > 0) {
- // // cdoc = users[0];
- // //}
- // //else
- // //{//contactid不合法
- // // return Json(new
- // // {
- // // success = 0,
- // // msg = "contactid不合法"
- // // });
- // //}
- // //if (cdoc.UserId!=null&& cdoc.UserId != "") {
- // // pfb.PushAccountId = Convert.ToInt32(cdoc.UserId);
- // // pfb.SuppliersId = cdoc.SuppliersId;
- // //}
- // if (pfb.Id.Equals(feedback.Id)) {
- // newpfb = pfb;
- // if ( pfb.PushAccountId != Convert.ToInt32(OldPushAccountId)
- // || pfb.SuppliersId != feedback.SuppliersId)
- // {
- // Message msg = TimeTask.sendSupplyMassMesage(_client,
- // Convert.ToInt32(feedback.PushAccountId),
- // pfb.PushRecordId.ToString(),
- // feedback.GoodsName,
- // feedback.StoreGapNum.ToString(),
- // feedback.PurPrice.ToString(),
- // EndTime);
- // newPushAccountId = pfb.PushAccountId;
- // result.Add(msg);
- // }
- // }
- // }
- // //添加或修改推送记录
- // IDictionary<string, Object> successs =
- // PushRecordDAL.AddOrUpdatePushFeedBack(
- // prec.PushCode,
- // Id
- // , feedback.Id.ToString(),
- // newPushAccountId,
- // newpfb.ContactId,
- // feedback.GoodsId, feedback.GoodsCode
- // , feedback.GoodsName, feedback.StoreGapNum
- // , feedback.GoodsSpec, feedback.Manufacturer
- // , feedback.BusinessId, feedback.BusinessCode, feedback.BusinessName
- // , feedback.SuppliersId, feedback.BrandName, feedback.BrandId
- // , feedback.EntId, feedback.Remark, LoginAccountId
- // , feedback.PurPrice
- // , feedback.ActPrice
- // , feedback.PurchaseTotalNum);
- // result.Add(successs);
- // Object successDT;
- // Object resultDT;
- // successs.TryGetValue("successRecord", out successDT);
- // successs.TryGetValue("resultRecord", out resultDT);
- // if (((string)resultDT).StartsWith("在执行数据操作时发生错误"))
- // {
- // successAll = 0;
- // }
- // }
- // if(successAll > 0)
- // {
- // #region 更新记录
- // string commandTextRecord = "UPDATE " + Config.TablePrefix + "PushRecord " +
- // " SET LastModifiedPerson = @LastModifiedPerson, " +
- // " State = 5 " +
- // " WHERE Id= @RecordId ";
- // string resultRecord;
- // //准备参数
- // List<List<Object>> parametersRecord = new List<List<Object>>();
- // parametersRecord.Add(new List<Object>() { "RecordId", Id });
- // parametersRecord.Add(new List<Object>() { "LastModifiedPerson", Convert.ToInt32(LoginAccountId) });
- // List<SqlParameter> parametersRecord1 = DataAccess.ToParameters(parametersRecord);
- // int successRecord = DataAccess.ExecuteCommand(commandTextRecord, parametersRecord1, out resultRecord);
- // #endregion
- // result.Add(successRecord);
- // result.Add(resultRecord);
- // }
- // return Json(new
- // {
- // success = successAll,
- // successAll = successAll,
- // result = result,
- // });
- //}
- ////修改过供应商的记录重推
- //[AuthPermission]
- //[HttpPost, Route("repush")]
- //public ActionResult RePush(string LoginAccountId,
- // DateTime start)
- //{
- // string filter = " and State in (5,6) ";
- // List<PushFeedbackExt> list = PushFeedBackDAL.GetFeedbacks(new List<SqlParameter>(), filter);
- // List<Object> result = new List<object>();
- // #region 更新记录
- // List<DataAccessCommand> listcmd = new List<DataAccessCommand>();
- // string resultFeed;
- // int successAll = 1;
- // DateTime EndTime = DateTime.Now.AddHours((double)24);
- // foreach (PushFeedbackExt feedback in list)
- // {
- // Message msg = TimeTask.sendSupplyMassMesage(_client,
- // Convert.ToInt32(feedback.PushAccountId),
- // feedback.PushRecordId.ToString(),
- // feedback.GoodsName,
- // feedback.StoreGapNum.ToString(),
- // feedback.PurPrice.ToString(),
- // EndTime);
- // result.Add(msg);
- // string commandTextFeed = "UPDATE " + Config.TablePrefix + "PushFeedback " +
- // " SET IsPush = @IsPush, " +
- // " WHERE Id= @Id AND (state in (5,6)) " +
- // " and IsPush = 0";
- // //准备参数
- // List<List<Object>> parametersFeed = new List<List<Object>>();
- // parametersFeed.Add(new List<Object>() { "Id", feedback.Id });
- // parametersFeed.Add(new List<Object>() { "IsPush", 1 });
- // List<SqlParameter> parametersFeed1 = DataAccess.ToParameters(parametersFeed);
- // listcmd.Add(new DataAccessCommand(commandTextFeed, parametersFeed1, CommandType.Text, true));
- // }
- // bool success = DataAccess.ExecuteBatchCommands(listcmd, out resultFeed);
- // #endregion
- // return Json(new
- // {
- // success = success,
- // successAll = successAll,
- // result = resultFeed,
- // });
- //}
- ///保存到采购计划
- [HttpPost, Route("savetoplan")]
- [AuthPermission]
- public ActionResult SaveToPlan(
- string Id
- , string LoginAccountId,
- //Int32 ReceiptMd, Int32 CentPayMd,
- PushFeedbackExt[] pfbs,
- string EntId,
- string OrgId,String DeptId,
- // DateTime RequestDate,
- [FromBody]dynamic data)
- {
- if (data != null)
- {
- //Newtonsoft.Json.Linq.JArray
- Id = data.Id;
- LoginAccountId = data.LoginAccountId;
- //ReceiptMd = data.ReceiptMd;
- //CentPayMd = data.CentPayMd;
- OrgId = data.OrgId;
- DeptId = data.DeptId;
- //RequestDate = data.RequestDate;
- pfbs = data.pfbs ==null? new PushFeedbackExt[] { } : data.pfbs.ToObject<PushFeedbackExt[]>();
- }
- //PushRecord rec = PushRecordDAL.GetRecord(Id);
- //int IsCompleteAll = 1;
- //if (IsCompleteAll == 1)
- // return Json(new
- // {
- // success = 0,
- // msg = "已经全部生成采购计划!"
- // });
- //List<PushFeedbackExt> listAll = PushFeedBackDAL.GetFeedbacks(Id);
- List<PushFeedbackExt> list = PushFeedBackDAL.GetFeedbacks(Id," and state in (1,2) ");
- //
- if(list == null)
- {
- return Json(new
- {
- success = 0,
- msg = "不能重复提交,已经全部生成采购计划!"
- });
- }
-
- Dictionary<string, List<PushFeedbackExt>> groups = new Dictionary<string, List<PushFeedbackExt>>();
- Dictionary<string, PushInfo> groupGoodsNames = new Dictionary<string, PushInfo>();
- //Dictionary<string, bool> haveSupp = new Dictionary<string, bool>();
- foreach (PushFeedbackExt fb in list)
- {
- //初始化付款方式 发货方式 要求日期
- foreach (PushFeedbackExt fb0 in pfbs) {
- if (fb0.Id.Equals(fb.Id))
- {
- //采购员可以编辑付款方式
- fb.CentPayMd = fb0.CentPayMd;
- fb.ReceiptMd = fb0.ReceiptMd;
- fb.RequestDate = fb0.RequestDate;
- fb.Remark = fb0.Remark;
- //采购员可以编辑供货数量
- fb.StoreGapNum = fb0.StoreGapNum;
- //预付款
- fb.PrepayAmt = fb0.PrepayAmt;
- fb.IsPrepay = fb0.IsPrepayI == 1?"Y":"N";
- //对方业务员,isyw='Y' and IsSaleDelegate='N'
- fb.OppContId = fb0.OppContId;
- }
- }
- if (fb.StoreGapNum > 0)
- {
- ContactDoc cd = ContactDAL.getContactor(fb.ContactId);
- string SuppliersId = fb.SuppliersId;
- if (cd != null)
- SuppliersId = cd.BusinessId;
- fb.SuppliersId = SuppliersId;
- fb.BusinessId = SuppliersId;
- var accountSuppliers = fb.PushAccountId +"_" + SuppliersId;
- if (groups.ContainsKey(accountSuppliers))
- {
- List<PushFeedbackExt> to;
- groups.TryGetValue(accountSuppliers, out to);
- to.Add(fb);
- groups.Remove(accountSuppliers);
- groups.Add(accountSuppliers, to);
-
- }
- else
- {
- List<PushFeedbackExt> to = new List<PushFeedbackExt>();
- to.Add(fb);
- groups.Add(accountSuppliers, to);
-
- }
- }
- //生成计划
- string contactid = fb.ContactId;
- if (fb.StoreGapNum <= 0)//对方没货 找下一个有货的供应商推送 生成计划前推送状态Y 生成计划后生成计划前推送状态N
- {
- //删除明细
- //PushFeedBackDAL.DeleteFeedback(fb.Id.ToString());
- ContactDAL.UpdatePushContactState(fb.GoodsId, contactid, fb.SuppliersId.Trim(), "Y", null);
- }
- else
- {//有货的记录需要推送状态为N 生成计划算在途
- ContactDAL.UpdatePushContactState(fb.GoodsId, contactid, fb.SuppliersId.Trim(), "N", null);
- }
- PushInfo.saveGoodsNames(fb, ref groupGoodsNames);
- }
- List<Object> result = new List<object>();
- int successAll = 0;
- int tempSuccess = 1;
- foreach (string groupkey in groups.Keys) {
- DateTime EndTime = DateTime.Now.AddHours((double)24);
- //string LoginStaffId = StaffDocDAL.GetStaffId(LoginAccountId);//改成谁绑定的品种就是谁的订单
-
- List<PushFeedbackExt> to;
- groups.TryGetValue(groupkey, out to);
- PushFeedbackExt fb0 = to.ToArray()[0];
- string StaffId = fb0.SaleManId;
- //添加采购计划
- IDictionary<string, Object> successs =
- PushRecordDAL.AddPlan(Id, fb0.Id.ToString(),
- fb0.PushAccountId,
- fb0.EntId, fb0.ReceiptMd, fb0.CentPayMd
- , OrgId, DeptId//depid
- , "采购计划", fb0.Remark //Summaries
- , fb0.GoodsId, fb0.SuppliersId
- , fb0.BusinessId, fb0.BusinessCode
- , StaffId
- , fb0.RequestDate
- , fb0.PrepayAmt
- , fb0.IsPrepay
- , fb0.OppContId
- , fb0.ContactId);
- Dictionary<string, Object> successsR = new Dictionary<string, object>();
- successsR.Add("successsPlan", successs);
- Object successPlan;
- successs.TryGetValue("successRecord", out successPlan);
- //billno
- Object PlanBillNo0;
- successs.TryGetValue("PlanBillNo", out PlanBillNo0);
- int PlanBillNo = (int)PlanBillNo0;
- if ((int)successPlan > 0)
- {
- List<Object> resultDt = new List<object>();
- int index = 1;
- foreach (PushFeedbackExt feedback in to)
- {
- Decimal LastPrice = feedback.PurPrice;
- string Summaries = feedback.Feedback;
- //添加采购计划明细
- int SafeDays = 0;
- IDictionary<string, Object> successs1 =
- PushRecordDAL.AddPlanDT(feedback.Id.ToString(), PlanBillNo, index,
- feedback.GoodsId, feedback.GoodsSpec, Convert.ToInt32(feedback.StoreGapNum),
- LastPrice, feedback.Remark,
- feedback.EntId,
- feedback.BusinessId, feedback.BusinessCode,
- feedback.SuppliersId,
- Convert.ToInt32(feedback.PurchaseTotalNum), SafeDays
- , StaffId
- , feedback.RequestDate);
- resultDt.Add(successs1);
- Object successPlanDT1;
- successs1.TryGetValue("successRecord", out successPlanDT1);
- if((int)successPlanDT1 > 0)
- {
- //更新推送状态 生成计划
- string resultState;
- var successState = PurPlanDAL.UpdatePlanState(feedback.Id.ToString(), Id, LoginAccountId,out resultState,
- " Remark = '" + feedback.Remark + "',StoreGapNum = '" + feedback.StoreGapNum + "',"
- + "OppContId = '" + feedback.OppContId + "',");
- if (resultState.StartsWith("在执行数据操作时发生错误"))
- tempSuccess = 0;
- }
- //记录失败
- else
- {
- tempSuccess = 0;
- }
- index += 1;
- }
- successsR.Add("successsPlanDT", resultDt);
- }
- else
- {
- //记录失败
- tempSuccess = 0;
- }
- result.Add(successsR);
- }
-
- if ((int)tempSuccess > 0)//&& listAll.Count == list.Count 全部生成计划
- {
- //更新推送状态 生成计划
- string resultState;
- var successState = PurPlanDAL.UpdateRecordPlanState(Id, LoginAccountId,out resultState);
- result.Add(successState);
- if (resultState.StartsWith("在执行数据操作时发生错误"))
- successAll = 1;
- foreach(string groupkey in groupGoodsNames.Keys) {
- //推送计划
- PushInfo pushInfos = null;
- groupGoodsNames.TryGetValue(groupkey, out pushInfos);
- DateTime EndTime = DateTime.Now.AddHours((double)Config.HoursToCancel);
- Message msg = PlanBAL.PushPlan(_client,
- Convert.ToInt32(groupkey),
- Id,
- pushInfos.GoodsName,
- pushInfos.GoodsNums,
- pushInfos.TotalAmount,
- EndTime);
- Dictionary<string, Object> msgd = new Dictionary<string, object>(1);
- msgd.Add("msg", msg);
- result.Add(msgd);
- }
- }
- if (tempSuccess > 0) {
- return Json(new
- {
- success = 1,
- result = result,
- successAll = successAll
- });
- }
- else
- {
- return Json(new
- {
- success = 0,
- result = result,
- successAll = successAll
- });
- }
- }
- ////待推送联系人--所有推送的业务员,查询业务员的推送记录
- [AuthPermission]
- [HttpPost, Route("pendingcontacts")]
- public JsonResult PendingContacts(QueryFilter[] filters, Int32 pageIndex, Int32 pageSize,
- string sortField, Int32 sortDirection, string[] sumFields, [FromBody]dynamic data)
- {
- string LoginAccountId = getStaff("userid");
- string RoleId = getStaff("roleid");
- //判断参数是否合法
- if (string.IsNullOrEmpty(LoginAccountId))
- {
- return Json(new
- {
- items = new string[] { },
- sum = new { },
- totalCount = 0,
- timeout = 1
- });
- }
- if (data != null)
- {
- //Newtonsoft.Json.Linq.JArray
- filters = data.filters.ToObject<QueryFilter[]>();
- pageIndex = data.pageIndex;
- pageSize = data.pageSize;
- sortField = data.sortField;
- sortDirection = data.sortDirection;
- sumFields = data.sumFields.ToObject<string[]>();
- }
- #region 获取待推联系人
- DataTable dt = new DataTable();
- string result = string.Empty;
- string direct = " desc ";
- if (sortDirection != 1)
- direct = " asc";
- int start = (pageIndex - 1) * pageSize;
- int end = (start + 1 + pageSize);
- //string filterstr = QueryFilter.getFilterString(filters);
- List<SqlParameter> parameters1 = new List<SqlParameter>();
- string filterstr = QueryFilter.getFilterSqlParam(filters, out parameters1, new PushContactWithGoods());
- string StaffDocId = StaffDocDAL.GetStaffId(LoginAccountId);
- //filterstr += ((RoleId == "1" || RoleId == "6" || RoleId == "7") ? "" : (" and SaleManId = '" + StaffDocId + "' "));
- filterstr += FilterTranslator.ruleSql(ref parameters1);
- IList<PushContactWithGoods> users = new List<PushContactWithGoods>();
- Int64 totalcount = 0;
- //跨库 获取存储上下限
- //IList<PushStorLimit> limits = new List<PushStorLimit>();
- IList<PushStorLimit> limits = PushRecordDAL.GetPushLimit();
- if (limits.Count > 0)
- {
- //List<string> superior_list = new List<string>(0);
- Dictionary<string, PushStorLimit> gapnum = new Dictionary<string, PushStorLimit>();
- //foreach (PushStorLimit limit in limits)
- //{
- // //Role role;
- // //if (roleMap.TryGetValue(permsr.RoleId, out role))
- // //{
- // // listRoles.Add(role);
- // //}
- // superior_list.Add(limit.GoodsId);
- // gapnum.Add(limit.GoodsId, limit);
- //}
- ////perms.RoleList = listRoles;
- //string limitss = string.Join("','", superior_list.ToArray());
- string commandText0 = "select * from ( select *, row_number() over (order by ContactCode " + direct + " ) as rownum ";
- string commandText1 = "";
- //string commandText1 = "" +
- // " FROM(SELECT ROW_NUMBER() OVER(PARTITION BY t1.GoodsId ORDER BY t1.LastPrice asc,t1.SysDates1 asc) AS RNUM," +//,t1.ContactId
- // " * " +
- // "FROM sup_PushContactWithGoods t1" +
- // " WHERE 1=1 " +
- // //" and exists(" +
- // //" select 1 from LJHYBZK.dbo.sup_PushStorLimit A " +
- // //" where A.GoodsId = t1.GoodsId)" +
- // " and t1.GoodsId IN ('" +
- // limitss +
- // " ')" +
- // filterstr +
- // ") AS T " +
- // " WHERE T.RNUM = 1";
- string commandText2 = ")AAA where AAA.rownum>" + start + " and AAA.rownum<" + end + " ";
- //string commandText = commandText0 + commandText1 + commandText2;
- //bool result1 = DataAccess.GetValues(commandText, ref dt, parameters1.ToArray(), out result);
- //// 把DataTable转换为IList<UserInfo>
- //if (dt != null && dt.Rows.Count > 0)
- //{
- // // 把DataTable转换为IList<UserInfo>
- // users = ModelConvertHelper<PushContactWithGoods>.ConvertToModel(dt);
- // foreach (PushContactWithGoods user in users)
- // {
- // //Role role;
- // //if (roleMap.TryGetValue(permsr.RoleId, out role))
- // //{
- // // listRoles.Add(role);
- // //}
- // PushStorLimit StorLimit;
- // gapnum.TryGetValue(user.GoodsId, out StorLimit);
- // user.StoreGapNum = StorLimit.StoreGapNum;
- // user.EntId = StorLimit.EntId;
- // user.PurchaseTotalNum = StorLimit.PurchaseTotalNum;//StoreGapNum
- // }
- //}
- #endregion
- users = ContactBAL.GetPushContactWithGoods(filterstr,null, limits,out gapnum,out commandText1,false, commandText0, commandText2, parameters1.ToArray());
- foreach (PushContactWithGoods user in users)
- {
- //Role role;
- //if (roleMap.TryGetValue(permsr.RoleId, out role))
- //{
- // listRoles.Add(role);
- //}
- PushStorLimit StorLimit;
- gapnum.TryGetValue(user.GoodsId, out StorLimit);
- user.StoreGapNum = StorLimit.StoreGapNum;
- user.EntId = StorLimit.EntId;
- user.PurchaseTotalNum = StorLimit.PurchaseTotalNum;//StoreGapNum
- }
- string resultrow;
- string commandTextRowCount = "select count(*) " + commandText1;
- //totalcount = DataAccess.GetRowCountDefine(connectstr, commandTextRowCount, out resultrow);
- totalcount = DataAccess.GetRowCountDefine(commandTextRowCount, parameters1.ToArray(), out resultrow);
- }
- IsoDateTimeConverter timejson = new IsoDateTimeConverter
- {
- DateTimeFormat = "yyyy'-'MM'-'dd' 'HH':'mm':'ss"
- };
- var jsonData = JsonConvert.SerializeObject(users, timejson);
- return Json(new
- {
- items = JsonConvert.DeserializeObject(jsonData),
- sum = new { },
- totalCount = totalcount
- });
- }
- ////待推送联系人--所有推送的业务员,查询业务员的推送记录
- [AuthPermission]
- [HttpGet, Route("getcontacts")]
- public JsonResult GetContacts(string GoodsId)
- {
- IList<PushContactWithGoods> users = new List<PushContactWithGoods>();
- DataTable dt = new DataTable();
- string result = string.Empty;
- if (GoodsId == null || GoodsId == "") {
- return Json(new String[] { ""});
- }
- GoodsId = GoodsId.Replace(",","','");
- //跨库 获取存储上下限
- IList<PushStorLimit> limits = new List<PushStorLimit>();//PushRecordDAL.GetPushLimit(" and GoodsId in ('"+GoodsId+"')");
- //if (limits.Count > 0)
- //{
- List<string> superior_list = new List<string>(0);
- Dictionary<string, PushStorLimit> gapnum = new Dictionary<string, PushStorLimit>();
- users = ContactBAL.GetPushContactWithGoods(" and GoodsId in ('" + GoodsId + "') ", ",t1.ContactId,t1.SuppliersId", limits,out gapnum, out _);
-
- //}
- IList<Option> options = new List<Option>();
- foreach (PushContactWithGoods role in users) {
-
- var option = new Option() { label = role.Contact+" 最近价格:"+role.LastPrice+"供应商:"+role.BusinessName,
- //value = (role.UserId==null)? "" :role.UserId.Trim(),
- value = (role.ContactId == null) ? ("_"+role.SuppliersId+"_" + (role.UserId==null?"":role.UserId.Trim())) : (role.ContactId.Trim() + "_" +role.SuppliersId + "_" + (role.UserId == null ? "" : role.UserId.Trim())),
- disabled = (role.UserId == null|| role.UserId.Trim() == "")?true:false };
- options.Add(option);
- }
- return Json(options);
- }
- [AuthPermission]
- [HttpPost, Route("cancelrecord")]
- public JsonResult CancelRecord(string staffId, string RecordId,
- string IsCancel,
- [FromBody]dynamic data)
- {
- string userids;
- string LoginAccountId = userids = getStaffUserid(staffId);
- //判断参数是否合法
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- success = 0,
- msg = "登陆超时",
- timeout = 1
- });
- }
- Int32 SalemanAccountId = Convert.ToInt32(userids);
- string PushAccountId = string.Empty;
- if (data != null)
- {
- RecordId = data.Id;
- PushAccountId = data.PushAccountId;
- IsCancel = data.IsCancel;
- }
- List<DataAccessCommand> list = new List<DataAccessCommand>();
- #region 更新记录状态
- string commandTextStateR = "UPDATE " + Config.TablePrefix + "PushRecord " +
- " SET CancelTime = @CancelTime, " +
- " CancelPerson = @CancelPerson, " +
- " IsCancel = @IsCancel" +
- " WHERE Id = @RecordId " +
- " and PushAccountId = @PushAccountId "+
- " and (state IS NULL or state = 0) or state in(2) " +
- " and IsCancel = "+ (IsCancel == "1" ? "0":"1")
- ;
- //string resultStateR;
- //准备参数
- List<List<Object>> parametersStateR = new List<List<Object>>();
- parametersStateR.Add(new List<Object>() { "CancelTime", DateTime.Now });
- parametersStateR.Add(new List<Object>() { "CancelPerson", SalemanAccountId });
- parametersStateR.Add(new List<Object>() { "IsCancel", IsCancel });
- parametersStateR.Add(new List<Object>() { "RecordId", RecordId });
- parametersStateR.Add(new List<Object>() { "PushAccountId", PushAccountId });
- List<SqlParameter> parametersStateR1 = DataAccess.ToParameters(parametersStateR);
- list.Add(new DataAccessCommand(commandTextStateR, parametersStateR1, CommandType.Text, true));
- #endregion
- string pushflag = (IsCancel == "1" ? "N" : "Y");
- List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacks(RecordId, " and IsCancel = '" + (IsCancel == "1" ? "0" : "1") + "'");
- #region 更新推送状态
- if (listpfb != null)
- {
- foreach (PushFeedbackExt pfb in listpfb)
- {
- //设置推送状态
- //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
- string commandText = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
- " Where 1=1 " +
- " and GoodsId=@GoodsId " +
- " and ContactId=@ContactId "
- //+" and SuppliersId=@SuppliersId "
- ;
- //string result;
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
- parameters.Add(new List<Object>() { "ContactId", pfb.ContactId });
- //parameters.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
- list.Add(new DataAccessCommand(commandText, DataAccess.ToParameters(parameters), CommandType.Text, false));
- //bool success = DataAccess.ExecuteBatchCommands(list, out result);
- }
- }
- #endregion
- #region 更新明细状态
- string commandTextStateF = "UPDATE " + Config.TablePrefix + "PushFeedback " +
- " SET CancelTime = @CancelTime, " +
- " CancelPerson = @CancelPerson, " +
- " IsCancel = @IsCancel" +
- " WHERE PushRecordId = @RecordId " +
- " and PushAccountId = @PushAccountId " +
- " and (state IS NULL or state = 0 or state in(5,6))" +
- " and IsCancel = " + (IsCancel == "1" ? "0" : "1")
- ;
- string resultStateF;
- //准备参数
- List<List<Object>> parametersStateF = new List<List<Object>>();
- parametersStateF.Add(new List<Object>() { "CancelTime", DateTime.Now });
- parametersStateF.Add(new List<Object>() { "CancelPerson", SalemanAccountId });
- parametersStateF.Add(new List<Object>() { "IsCancel", IsCancel });
- parametersStateF.Add(new List<Object>() { "RecordId", RecordId });
- parametersStateF.Add(new List<Object>() { "PushAccountId", PushAccountId });
- List<SqlParameter> parametersStateF1 = DataAccess.ToParameters(parametersStateF);
- list.Add(new DataAccessCommand(commandTextStateF, parametersStateF1, CommandType.Text, true));
- #endregion
- bool success = DataAccess.ExecuteBatchCommands(list, out resultStateF);
- return Json(new
- {
- success = success,
- result = resultStateF,
- });
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="staffId"></param>
- /// <param name="RecordId"></param>
- /// <param name="IsCancel"></param>
- /// <param name="data"></param>
- /// <returns></returns>
- [AuthPermission]
- [HttpPost, Route("cancelPush")]
- public JsonResult CancelPush(string staffId, string RecordId,
- string IsCancel,
- [FromBody]dynamic data)
- {
- string userids;
- string LoginAccountId = userids = getStaffUserid(staffId);
- //判断参数是否合法
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- success = 0,
- msg = "登陆超时",
- timeout = 1
- });
- }
- Int32 SalemanAccountId = Convert.ToInt32(userids);
- string PushAccountId = string.Empty;
- if (data != null)
- {
- RecordId = data.Id;
- PushAccountId = data.PushAccountId;
- IsCancel = data.IsCancel;
- }
- List<DataAccessCommand> list = new List<DataAccessCommand>();
-
- string pushflag = (IsCancel == "1" ? "N" : "Y");
- List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacks(RecordId, "");
- #region 更新推送状态
- foreach (PushFeedbackExt pfb in listpfb)
- {
- //设置推送状态
- //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
- string commandText = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
- " Where 1=1 " +
- " and GoodsId=@GoodsId " +
- " and ContactId=@ContactId " +
- " and SuppliersId=@SuppliersId ";
- //string result;
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
- parameters.Add(new List<Object>() { "ContactId", pfb.ContactId });
- parameters.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
- list.Add(new DataAccessCommand(commandText, DataAccess.ToParameters(parameters), CommandType.Text, true));
- //bool success = DataAccess.ExecuteBatchCommands(list, out result);
- }
- #endregion
- string resultStateF;
- bool success = DataAccess.ExecuteBatchCommands(list, out resultStateF);
- return Json(new
- {
- success = success,
- result = resultStateF,
- });
- }
- ///删除记录
- [AuthPermission]
- [HttpPost, Route("delete")]
- public ActionResult Delete(
- [FromBody]dynamic data)
- {
- string userids;
- string Idstr = string.Empty;
- string LoginAccountId = userids = getStaff("userid");
- //判断参数是否合法
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- success = 0,
- msg = "登陆超时",
- timeout = 1
- });
- }
- if (data != null)
- {
- Idstr = data.Id;
- }
- string[] Ids = new string[] { };
- if (Idstr.IndexOf(",") > 0)
- {
- Ids = Idstr.Split(',');
- }
- else
- {
- Ids = new string[1] { Idstr};
- }
- List<DataAccessCommand> list = new List<DataAccessCommand>();
- string result = "";
- foreach (string Id in Ids) {
- #region 删除记录
- string commandText = "DELETE FROM " + Config.TablePrefix + "PushRecord WHERE Id = @Id";
- //准备参数
- List<List<Object>> parameters = new List<List<Object>>();
- parameters.Add(new List<Object>() { "Id", Id });
- List<SqlParameter> parameters1 = DataAccess.ToParameters(parameters);
- list.Add(new DataAccessCommand(commandText, parameters1, CommandType.Text, true));
- //int successDel = DataAccess.ExecuteCommand(commandText, parameters1, out result);
- #endregion
- string pushflag = "N";
- List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacks(Id, "");// and IsCancel = '1'
- if(listpfb!=null)
- #region 更新推送状态
- foreach (PushFeedbackExt pfb in listpfb)
- {
- //设置推送状态
- //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
- string commandTextFlag = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
- " Where 1=1 " +
- " and GoodsId=@GoodsId " +
- " and ContactId=@ContactId "
- // + " and SuppliersId=@SuppliersId "
- ;
- //string result;
- List<List<Object>> parametersFlag = new List<List<Object>>();
- parametersFlag.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
- parametersFlag.Add(new List<Object>() { "ContactId", pfb.ContactId });
- //parametersFlag.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
- list.Add(new DataAccessCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), CommandType.Text, false));
- //bool success = DataAccess.ExecuteBatchCommands(list, out result);
- //string resultsp = "";
- //int success = DataAccess.ExecuteCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), out resultsp);
- }
- #endregion
- if (listpfb != null && listpfb.Count > 0) {
- #region 删除明细
- string commandTextDT = "DELETE FROM " + Config.TablePrefix + "PushFeedback WHERE PushRecordId = @Id";
- //准备参数
- List<List<Object>> parametersDT = new List<List<Object>>();
- parametersDT.Add(new List<Object>() { "Id", Id });
- List<SqlParameter> parametersDT1 = DataAccess.ToParameters(parametersDT);
- list.Add(new DataAccessCommand(commandTextDT, parametersDT1, CommandType.Text, true));
- //string resultDT = "";
- //int successDelDT = DataAccess.ExecuteCommand(commandTextDT, parametersDT1, out resultDT);
- #endregion
- }
- }
- bool successDel = DataAccess.ExecuteBatchCommands(list, out result);
- return Json(new
- {
- success = successDel,
- resultDel = result,
- });
- }
- ///删除记录
- [AuthPermission]
- [HttpPost, Route("deleteabandon")]
- public ActionResult deleteAbandon(
- [FromBody]dynamic data)
- {
- string userids;
- string Idstr = string.Empty;
- string LoginAccountId = userids = getStaff("userid");
- //判断参数是否合法
- if (string.IsNullOrEmpty(userids))
- {
- return Json(new
- {
- success = 0,
- msg = "登陆超时",
- timeout = 1
- });
- }
- if (data != null)
- {
- Idstr = data.Id;
- }
- string[] Ids = new string[] { };
- if (Idstr.IndexOf(",") > 0)
- {
- Ids = Idstr.Split(',');
- }
- else
- {
- Ids = new string[1] { Idstr };
- }
- Idstr = string.Join("','", Ids);
- DataTable dt = new DataTable();
- List<SqlParameter> param = new List<SqlParameter>();
- //param.Add(new SqlParameter("BusinessId", BusinessIds));
- DataAccess.GetValues("select * from sup_PushRecord where " +
- " state in(0,1) " +
- " and Id in(select PushRecordId from sup_PushFeedback where Id in ('" + Idstr + "') " +
- ")" +
- "", ref dt, param.ToArray(), out var msg);
- IList<Option> options = new List<Option>();
-
- if(dt!=null && dt.Rows.Count > 0)
- {
- return Json(new
- {
- success = 0,
- msg = "请选择上次生成计划不要的品种删除",
- });
- }
- List<DataAccessCommand> list = new List<DataAccessCommand>(Ids.Length*2);
- string result = "";
- foreach (string Id in Ids)
- {
- string pushflag = "N";
- List<PushFeedbackExt> listpfb = PushFeedBackDAL.GetFeedbacksIn(Id, "");// and IsCancel = '1'
- #region 更新推送状态
- foreach (PushFeedbackExt pfb in listpfb)
- {
- //设置推送状态
- //ContactDAL.UpdatePushContactState(pfb.GoodsId, contactid, pfb.SuppliersId.Trim(), "N");
- string commandTextFlag = "Update k_contactsp set PushFlag = '" + pushflag + "' " +
- " Where 1=1 " +
- " and GoodsId=@GoodsId " +
- " and ContactId=@ContactId "
- // + " and SuppliersId=@SuppliersId "
- ;
- //string result;
- List<List<Object>> parametersFlag = new List<List<Object>>();
- parametersFlag.Add(new List<Object>() { "GoodsId", pfb.GoodsId });
- parametersFlag.Add(new List<Object>() { "ContactId", pfb.ContactId });
- //parametersFlag.Add(new List<Object>() { "SuppliersId", pfb.SuppliersId.Trim() });
- list.Add(new DataAccessCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), CommandType.Text, false));
- //bool success = DataAccess.ExecuteBatchCommands(list, out result);
- //string resultsp = "";
- //int success = DataAccess.ExecuteCommand(commandTextFlag, DataAccess.ToParameters(parametersFlag), out resultsp);
- }
- #endregion
- #region 删除明细
- string commandTextDT = "DELETE FROM " + Config.TablePrefix + "PushFeedback WHERE Id = @Id and state in (1,2) and PushRecordId in (select Id from sup_PushRecord where Id = PushRecordId and State in (3,4))";
- //准备参数
- List<List<Object>> parametersDT = new List<List<Object>>();
- parametersDT.Add(new List<Object>() { "Id", Id });
- List<SqlParameter> parametersDT1 = DataAccess.ToParameters(parametersDT);
- list.Add(new DataAccessCommand(commandTextDT, parametersDT1, CommandType.Text, true));
- //string resultDT = "";
- //int successDelDT = DataAccess.ExecuteCommand(commandTextDT, parametersDT1, out resultDT);
- #endregion
- }
- bool successDel = DataAccess.ExecuteBatchCommands(list, out result);
- return Json(new
- {
- success = successDel,
- msg = result,
- });
- }
- ////待推送联系人--所有推送的业务员,查询业务员的推送记录
- [HttpGet, Route("getstates")]
- public JsonResult GetStates()
- {
- IList<Option> options = new List<Option>();
- var option = new Option()
- {
- label = "未填写",
- //value = (role.UserId==null)? "" :role.UserId.Trim(),
- value = "0",
- disabled = false
- };
- options.Add(option);
- var option1 = new Option()
- {
- label = "已填写",
- //value = (role.UserId==null)? "" :role.UserId.Trim(),
- value = "1",
- disabled = false
- };
- options.Add(option1);
- var option4 = new Option()
- {
- label = "低于缺口",
- //value = (role.UserId==null)? "" :role.UserId.Trim(),
- value = "2",
- disabled = false
- };
- options.Add(option4);
- var option2 = new Option()
- {
- label = "已生成采购计划",
- //value = (role.UserId==null)? "" :role.UserId.Trim(),
- value = "3",
- disabled = false
- };
- options.Add(option2);
- var option3 = new Option()
- {
- label = "已生成订单",
- //value = (role.UserId==null)? "" :role.UserId.Trim(),
- value = "4",
- disabled = false
- };
- options.Add(option3);
- return Json(options);
- }
- [HttpGet, Route("getOppContact")]
- public JsonResult getOppContact(string BusinessId)
- {
- string BusinessIds = string.IsNullOrEmpty(BusinessId)?"":BusinessId.TrimEnd(',');
- if(string.IsNullOrEmpty(BusinessIds))
- return Json(new string[] { });
- BusinessIds = "'"+BusinessIds.Replace(",","','")+"'";
- DataTable dt = new DataTable();
- List<SqlParameter> param = new List<SqlParameter>();
- //param.Add(new SqlParameter("BusinessId", BusinessIds));
- DataAccess.GetValues("select ContactId,Contact from ContactDoc where " +
- "BusinessId in("+ BusinessIds + ") " +
- " and isyw='Y' and IsSaleDelegate='N' and BeActive='Y'", ref dt,param.ToArray(),out var result);
- IList <Option> options = new List<Option>();
- foreach(DataRow item in dt.Rows) {
- var option3 = new Option()
- {
- label = item["Contact"].ToString(),
- //value = (role.UserId==null)? "" :role.UserId.Trim(),
- value = item["ContactId"].ToString(),
- disabled = false
- };
- options.Add(option3);
- }
- return Json(options);
- }
- }
- }
|