| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267 |
- using BizCom;
- using Newtonsoft.Json;
- using NHibernate.Cache;
- using NHibernate.Engine;
- using NPOI.OpenXmlFormats.Shared;
- using NPOI.OpenXmlFormats.Wordprocessing;
- using NPOI.SS.Formula.Functions;
- using SiteCore.Handler;
- using SiteCore.taoObj;
- using SQLData;
- using System;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Data;
- using System.Linq;
- using System.Net;
- using System.Reflection;
- using System.Security.Cryptography.X509Certificates;
- using System.Text;
- using System.Threading.Tasks;
- using System.Web;
- using static NHibernate.Linq.Visitors.LeftJoinDetector;
- using static SiteCore.taoObj.Api_refund_info;
- using static SiteCore.taoObj.Api_trade_info;
- using static SiteCore.taoObj.Refunds_receive_get_response_Obj;
- using static SiteCore.taoObj.work_core_vo;
- namespace SiteCore.Handler
- {
- public class preSalesHelper : BaseHandler, IHttpHandler
- {
- public void ProcessRequest(HttpContext context)
- {
- if (UrlParmsCheck("t"))
- {
- String tname = GetString("t");
- MethodInfo method;
- Type type = this.GetType();
- method = type.GetMethod(tname);
- con = context;
- if (method == null)
- {
- conError("找不到对应方法,服务器返回错误");
- return;
- }
- successFlag = false;
- context.Response.ContentType = "application/json";
- context.Response.Headers.Set("Access-Control-Allow-Origin", "*");
- try
- {
- method.Invoke(this, null);
- }
- catch (Exception ex)
- {
- conError("处理接口错误,服务器返回错误");
- }
- finally
- {
- }
- }
- }
- /**
- * 加急
- * ctid
- * name 客服名称
- * urgencytime 出货时间
- **/
- public void set_urgency()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eid = GetPostString("ctid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- string utime = GetPostString("urgencytime");
- if (utime.Length > 0)
- {
- entity.UrgencyTime = Convert.ToDateTime(utime);
- }
- else
- {
- returnErrorMsg("请选择加急时间");
- return;
- }
- if (entity.OrderState <= 4 || entity.ctid.IndexOf("S_") != -1)
- {
- //entity.seller_memo = entity.seller_memo + "-加急";
- string smemo = entity.seller_memo;
- int kindex = smemo.IndexOf(")");
- string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
- if (lastoneStr != "-")
- {
- smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
- }
- string prememo = smemo.Substring(0, kindex + 2);
- string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
- int lastkindex = lastmemo.IndexOf("(");
- DateTime urgtime = Convert.ToDateTime(utime);
- string newlastmemo = "";
- if (lastkindex == 0)
- {
- string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
- newlastmemo = "(加急." + urgtime.Day + "号出货." + useLastmemo;
- }
- else
- {
- newlastmemo = "(加急." + urgtime.Day + "号出货)-" + lastmemo;
- }
- entity.seller_memo = prememo + newlastmemo;
- }
- entity.IsUrgency = true;
- entity.Update();
- LogHelper.addLog(eid, UserID, name + "手动订单加急", 0, 1);
- returnSuccessMsg("设置成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 拿样
- * ctid
- *
- **/
- public void upd_sampleorder()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eid = GetPostString("ctid");
- int UserID = GetPostInt("UserID");
- string[] eArr = eid.Split(',');
- if (eArr.Length > 1)
- {
- List<string> eLst = new List<string>();
- for (int i = 0; i < eArr.Length; i++)
- {
- eLst.Add("'" + eArr[i] + "'");
- }
- eid = string.Join(",", eLst.ToArray());
- }
- else
- {
- eid = "'" + eid + "'";
- }
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select * from view_ErpTradeCell where ctid in ({0});", eid);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- int supplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- if (dt.Rows.Count > 0)
- {
- string errmsg = "";
- foreach (DataRow dr in dt.Rows)
- {
- StringBuilder sqlsb = new StringBuilder();
- sqlsb.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsSample=1 ,OrderState=6,SupplierId={1},seller_memo='拿样订单【标记】' where ctid='{0}';", dr["tid"].ToString(), supplierId);
- sqlsb.AppendFormat("insert into CE_ErpTradeSample(ctid,SampleUserId ,SampleDate) Values('{0}',{1},getdate());", dr["tid"].ToString(), UserID);
- DbHelper.DbConn.ExecuteNonQuery(sqlsb.ToString());
- //string res = taobaoHelper.TradeMemoUpdate(dt.Rows[0]["tid"].ToString(), dt.Rows[0]["seller_nick"].ToString(), 5, "拿样订单【标记】");//修改备注,5为紫色旗子
- string apires = apiHelper.API_TradeMemoUpdate(dr["tid"].ToString(), dr["posCode"].ToString(), "PURPLE", "拿样订单【标记】");
- if (apires.IndexOf("修改成功") != -1 && apires.IndexOf("true") != -1)
- {
- continue;
- }
- else
- {
- string emsg = commonHelper.KeepChinese(apires);
- errmsg += emsg;
- }
- }
- if (errmsg.Length > 0)
- {
- returnErrorMsg(errmsg);
- return;
- }
- returnSuccessMsg("操作成功");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 标记售后
- *
- * ctid
- * AfterSaleReason 理由
- * name 客服名称
- **/
- public void set_atersale()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eid = GetPostString("ctid");
- string reason = GetPostString("AfterSaleReason");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- if (entity.AfterSaleState > 0)
- {
- returnErrorMsg("此订单已经在售后");
- return;
- }
- entity.AfterSaleState = 1; //1待售后2售后主管审核3主管审核4完成售后
- //entity.AfterSaleReason = reason;
- entity.AfterSaleTime = DateTime.Now;
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + "标记售后-" + reason, entity.OrderState, 1);
- returnSuccessMsg("转售后成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 关联
- * ctid
- * ftid 关联单号
- * name 客服名称
- **/
- public void upd_setrelationorder()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eid = GetPostString("ctid");
- string ftid = GetPostString("ftid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- CeErpTradeCell fentity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (ftid != "") fentity = CeErpTradeCell.GetByCtid(ftid);
- if (fentity == null)
- {
- returnErrorMsg("找不到关联的主订单");
- return;
- }
- if (entity != null)
- {
- if (entity.OrderState >= 5)
- {
- returnErrorMsg("本单已经设计完成无法关联");
- return;
- }
- entity.ptid = ftid;
- entity.OrderState = fentity.OrderState;
- //entity.status = fentity.status;
- entity.CustomerUserId = fentity.CustomerUserId;
- entity.DesignUserId = fentity.DesignUserId;
- entity.seller_memo = "补差价单:" + ftid;
- entity.IsSample = 2;
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + "手动关联补差价", entity.OrderState, 1);
- returnSuccessMsg("关联成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 预发货
- * ctid
- * name 客服名称
- **/
- public void set_predelivery()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eid = GetPostString("ctid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- entity.IsPreDelivery = 1;
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + "预发货", entity.OrderState);
- returnSuccessMsg("预发货成功!");
- return;
- }
- returnErrorMsg("找不到订单记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 返现
- * tid
- * type : 送样返现、退款返现、好评返现、多拍返现、微信返现、其他返现
- * seller_nick 店铺名称
- * payment 支付金额
- * buyer_nick 买家名称
- * returnprice 返现金额
- * con 说明
- * img 图片地址
- **/
- public void ins_returncashrecord()
- {
- if (UrlPostParmsCheck("tid"))
- {
- string tid = GetPostString("tid");
- string retype = GetPostString("type");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("select * from ce_ErpReturnCash where tid='{0}' and rtype like '%{1}%' and cashstate!=2;", tid, retype);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql.ToString()).Tables[0];
- if (dt.Rows.Count > 0)
- {
- returnErrorMsg("相同返现类型记录已存在");
- return;
- }
- CeErpReturnCash entity = new CeErpReturnCash();
- entity.tid = tid;
- entity.seller_nick = GetPostString("seller_nick");
- string pment = GetPostString("payment");
- if (pment.Length > 0)
- {
- entity.payment = Convert.ToDouble(pment);
- }
- entity.buyer_nick = GetPostString("buyer_nick");
- entity.cashstate = 0;
- entity.rtype = retype;
- string rPrice = GetPostString("returnprice");
- if (rPrice.Length > 0)
- {
- entity.returnprice = Convert.ToDouble(rPrice);
- }
- entity.created = DateTime.Now;
- entity.con = GetPostString("con");
- entity.img = GetPostString("img");
- entity.applyuserid = UserID;
- entity.Create();
- LogHelper.addLog(entity.tid, UserID, name + "添加:" + entity.rtype);
- returnSuccessMsg("操作成功!");
- return;
- }
- returnErrorMsg("缺少必要的参数tid");
- }
- /**
- *指派
- *ctid
- *DesignUserId
- *name
- **/
- public void upd_distributedesigner()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eid = GetPostString("ctid");
- int userid = GetPostInt("DesignUserId");
- string custom_name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- string[] idlist = eid.Split(',');
- if (idlist.Length <= 0)
- {
- returnErrorMsg("订单不能为空");
- return;
- }
- foreach (string ctid in idlist)
- {
- CeErpTradeCell entity = null;
- CeErpDesignerBill entitys = null;
- if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
- else continue;
- if (entity != null)
- {
- if (userid == 2125)
- {
- CeErpOrderFormData formData = null;
- formData = CeErpOrderFormData.GetByTid(entity.ctid);
- if (formData == null)
- {
- returnErrorMsg("请填写订单的手机号或者微信号才可指派到设计系统");
- return;
- }
- }
- if (entity.payment <= 0 && entity.ShopId != 34 && entity.ShopId != 94 && entity.isAfterSaleOrder != 1) //公司自用可以为0
- {
- returnErrorMsg("金额错误的订单无法指派");
- return;
- }
- if (entity.OrderState >= 5)
- {
- returnErrorMsg("已经设计完成无法指派");
- return;
- }
- if (entity.OrderState == -1)
- {
- returnErrorMsg("审核中的订单无法指派");
- return;
- }
- if (entity.isAfterSaleOrder == 1 && entity.IsReturn == 3)
- {
- returnErrorMsg("售后单被打回了,到售后打回列表恢复即可!");
- return;
- }
- if (entity.DispatchSort == 2 && userid != 3542)
- {
- returnErrorMsg("指派设计共创无法再次指派!");
- return;
- }
- CeErpUserPost userEntity = CeErpUserPost.GetByUserID(userid);
- if (userEntity != null && entity.ctid.IndexOf("S_") == -1 && userEntity.OrgID == 10)
- {
- int suid = commonHelper.autoDistributeToSupplier(entity); //自动分配供应商
- entity.SupplierId = suid;
- string suname = commonHelper.getSupplierNameById(entity.SupplierId);
- LogHelper.addLog(entity.ctid, 0, "匹配供应商:" + suname, entity.OrderState);
- }
- if (userid == 2125 && entity.seller_memo != "")
- {
- apiDesign.API_GetPrintData_CreateOrder(entity);
- }
- if (userid == 3542 && entity.seller_memo != "")
- {
- designApiResponseVo response = designHelper.API_GetPrintData_CreateOrder(entity, CurrentUser.UserPost.Post.Code);
- LogHelper.addLog(entity.ctid, 3542, "手动派单:" + response.msg, entity.OrderState);
- if (response.msg != "设计共创:成功")
- {
- returnErrorMsg(response.msg);
- return;
- }
- entity.DispatchSort = 2;
- }
- entity.DesignUserId = userid;
- entity.OrderState = 3;
- entity.WaitDesignTime = DateTime.Now;
- entity.Update();
- string name = commonHelper.getUserNameById(userid);
- commonHelper.UpdateRelationOrder(entity.ctid);
- LogHelper.addLog(entity.ctid, UserID, custom_name + "指派设计师" + name + userid, entity.OrderState);
- }
- }
- returnSuccessMsg("操作成功!");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- *重置
- *ctid
- *name
- **/
- public void set_reset()
- {
- if (UrlPostParmsCheck("tid"))
- {
- string eid = GetPostString("tid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- string sql = "select ID,ctid, OrderState from CE_ErpTradeCell where tid='" + eid + "'";
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- foreach (DataRow dr in dt.Rows)
- {
- int OrderState = Convert.ToInt32(dr["OrderState"]);
- if (OrderState >= 4)
- {
- returnErrorMsg(dr["ctid"] + "财务要求已下单已发货无法重置");
- return;
- }
- }
- }
- CeErpTradeCell.ExecuteNonQuery("delete from CE_ErpTradeCell where tid='" + eid + "'");
- CeErpTrade.ExecuteNonQuery("delete from CE_ErpTrade where tid='" + eid + "'");
- CeErpTradeOrder.ExecuteNonQuery("delete from CE_ErpTradeOrder where tid='" + eid + "'");
- returnSuccessMsg("重置成功!");
- CeErpDesignerBill desginBill = CeErpDesignerBill.GetByTid(eid);
- if (desginBill != null)
- {
- desginBill.isDel = 1;
- desginBill.Update();
- LogHelper.addDesignerBillLog(eid, UserID, name + "订单重置", name, 0);
- }
- return;
- }
- returnErrorMsg("缺少必要的参数tid");
- }
- /**
- * 清空退款状态
- * ctid
- * name
- **/
- public void clear_refundstate()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eids = GetPostString("ctid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- string[] ctidList = eids.Split(',');
- foreach (string ctid in ctidList)
- {
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ctid);
- if (entity != null)
- {
- entity.IsRefund = 0;
- entity.Update();
- LogHelper.addLog(ctid, UserID, name + "清除退款状态", 0, 1);
- }
- else
- continue;
- }
- returnSuccessMsg("操作成功");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 顺丰到付\顺丰寄付
- * ctid
- * memotag 顺丰到付、顺丰寄付、撤销顺丰
- * name
- **/
- public void upd_addmemotag()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- int UserID = GetPostInt("UserID");
- string eid = GetPostString("ctid");
- string sfTagstr = GetPostString("memotag");
- string name = GetPostString("name");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- if (entity.OrderState == 0)
- {
- returnErrorMsg("请先领单");
- return;
- }
- //撤销顺丰
- if (sfTagstr == "撤销顺丰")
- {
- entity.IsSF = 0;
- string reMsg = "";
- string oldmemo = entity.seller_memo;
- if (entity.OrderState < 5)
- {
- oldmemo = oldmemo.Replace("顺丰到付", "");
- oldmemo = oldmemo.Replace("顺丰寄付", "");
- entity.seller_memo = oldmemo;
- }
- else
- {
- if (oldmemo.IndexOf("顺丰到付") != -1 || oldmemo.IndexOf("顺丰寄付") != -1)
- {
- reMsg = "(设计文件已上传,所以备注中的顺丰字眼还保留,不然文件名跟备注对不上)";
- }
- }
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + "撤销标记顺丰", entity.OrderState, 1);
- returnSuccessMsg("撤销成功!" + reMsg);
- return;
- }
- if (entity.OrderState < 5 || entity.IsXianHuo == 1)
- {
- //string oldmemo = entity.seller_memo;
- //entity.seller_memo = oldmemo + "-" + GetPostString("memotag");
- string sfStr = GetPostString("memotag");
- string smemo = entity.seller_memo;
- int kindex = smemo.IndexOf(")");
- string lastoneStr = smemo.Substring(kindex + 1, 1);//查看订单号后面有没有一个- ,没有就要补上-
- if (lastoneStr != "-")
- {
- smemo = smemo.Substring(0, kindex + 1) + "-" + smemo.Substring(kindex + 1, smemo.Length - kindex - 1);
- }
- string prememo = smemo.Substring(0, kindex + 2);
- string lastmemo = smemo.Substring(kindex + 2, smemo.Length - kindex - 2);
- int lastkindex = lastmemo.IndexOf("(");
- string newlastmemo = "";
- if (lastkindex == 0)
- {
- string useLastmemo = lastmemo.Substring(1, lastmemo.Length - 1);
- newlastmemo = "(" + sfStr + "." + useLastmemo;
- }
- else
- {
- newlastmemo = "(" + sfStr + ")-" + lastmemo;
- }
- entity.seller_memo = prememo + newlastmemo;
- }
- string sfTagMSg = "";
- if (sfTagstr == "顺丰寄付")
- {
- entity.IsSF = 1;
- sfTagMSg = "顺丰寄付";
- }
- else if (sfTagstr == "顺丰到付")
- {
- entity.IsSF = 2;
- sfTagMSg = "顺丰到付";
- }
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + ":" + sfTagMSg + "--" + entity.seller_memo, entity.OrderState, 1);
- returnSuccessMsg("标记成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 微信单
- * ctid
- * wechattag 1:微信返现 2:推购返现 3:挽回推多 4 :推多 5:推购
- * name
- **/
- public void upd_ordertag()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string name = GetPostString("name");
- string eid = GetPostString("ctid");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- int tag = GetPostInt("wechattag");
- //if(tag==4 && entity.IsSample == 2)
- //{
- // returnErrorMsg("补差价单不能标记微信单");
- // return;
- //}
- entity.wechatTag = tag;
- entity.Update();
- CeErpTrade trade = CeErpTrade.Get(entity.tid);
- if (tag == 1)
- {
- CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
- if (cash == null)
- {
- CeErpTrade main = CeErpTrade.Get(entity.tid);
- cash = new CeErpReturnCash();
- cash.tid = entity.tid;
- cash.seller_nick = main.seller_nick;
- cash.payment = trade.payment;
- cash.buyer_nick = main.buyer_nick;
- cash.cashstate = 0;
- cash.rtype = "微信返现";
- cash.returnprice = 0;
- cash.created = DateTime.Now;
- cash.con = "订单标记微信单";
- cash.img = "";
- cash.applyuserid = UserID;
- cash.Create();
- LogHelper.addLog(entity.ctid, UserID, name + "添加:微信返现");
- }
- else
- {
- cash.cashstate = 0;
- cash.Update();
- }
- }
- else if (tag == 2)
- {
- CeErpReturnCash cash = CeErpReturnCash.GetByTid(entity.tid);
- if (cash == null)
- {
- CeErpTrade main = CeErpTrade.Get(entity.tid);
- cash = new CeErpReturnCash();
- cash.tid = entity.tid;
- cash.seller_nick = main.seller_nick;
- cash.payment = trade.payment;
- cash.buyer_nick = main.buyer_nick;
- cash.cashstate = 0;
- cash.rtype = "推购返现";
- cash.returnprice = 5;
- cash.created = DateTime.Now;
- cash.con = "订单标记推购单";
- cash.img = "";
- cash.applyuserid = UserID;
- cash.Create();
- LogHelper.addLog(entity.ctid, UserID, name + "添加:推购返现");
- }
- else
- {
- cash.cashstate = 0;
- cash.Update();
- }
- }
- else if (tag == 3)
- {
- CeErpPersuade pers = CeErpPersuade.GetByCtid(entity.ctid);
- if (pers == null)
- {
- pers = new CeErpPersuade();
- pers.ctid = entity.ctid;
- pers.pstate = 0;
- pers.created = DateTime.Now;
- pers.applyuserid = UserID;
- pers.Create();
- LogHelper.addLog(entity.ctid, UserID, name + "添加:挽回推多");
- }
- else
- {
- pers.pstate = 0;
- pers.Update();
- }
- }
- else if (tag == 4 || tag == 5)
- {
- CeErpTrade main = CeErpTrade.Get(entity.tid);
- CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid);
- if (pers == null)
- {
- pers = new CeErpStayGoods();
- pers.t_id = entity.tid;
- pers.status = "待审核";
- pers.audit_type = 0;
- if (tag == 4)
- {
- pers.stay_type = "推多";
- }
- else
- {
- pers.stay_type = "推购";
- }
- if (entity.IsXianHuo == 0)
- {
- pers.product_id = entity.ProductId;
- }
- pers.wangwang = main.buyer_nick;
- pers.shop_name = main.seller_nick;
- pers.creata_time = DateTime.Now;
- pers.create_u_id = UserID;
- pers.create_u_name = name;
- pers.Create();
- LogHelper.addLog(entity.ctid, UserID, name + "添加:推多推购");
- }
- else
- {
- pers.audit_type = 0;
- pers.Update();
- }
- }
- //LogHelper.addLog(entity.ctid, CurrentUser.UserID, "标记微信或者推购", entity.OrderState, 1);
- returnSuccessMsg("标记成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 小礼物
- * ctid
- * name
- **/
- public void upd_sendXlw()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string name = GetPostString("name");
- string eid = GetPostString("ctid");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- if (entity.IsSendGift == 1)
- {
- returnErrorMsg("请勿重复标记");
- return;
- }
- entity.IsSendGift = 1;
- entity.Update();
- LogHelper.addLog(eid, UserID, name + "送小礼物");
- returnSuccessMsg("操作成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 添加微信
- * ctid
- * name
- **/
- public void upd_addweichattag()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string name = GetPostString("name");
- string eid = GetPostString("ctid");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- if (entity.IsAddWechat > 0)
- {
- returnErrorMsg("此单已经标记过了");
- return;
- }
- string sql = string.Format("select * from view_erptradecell where IsAddWechat>0 and buyer_nick=(select buyer_nick from ce_erptrade where tid='{0}')", entity.tid);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(sql).Tables[0];
- if (dt.Rows.Count > 0)
- {
- entity.IsAddWechat = 2;
- }
- else
- {
- entity.IsAddWechat = 1;
- }
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + "标记已添加微信", entity.OrderState, 1);
- returnSuccessMsg("标记成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- /**
- * 售后
- *
- * id 售后单id
- * afterstate 1认可0不认可
- * supmemo 理由
- * image 图片
- **/
- public void upd_personaftersale()
- {
- if (UrlPostParmsCheck("id"))
- {
- string id = GetPostString("id");
- int UserID = GetPostInt("UserID");
- int st = GetPostInt("afterstate");
- string afmemo = GetPostString("supmemo");
- string image = GetPostString("image");
- CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
- if (ceErpTradeResponsible != null)
- {
- ceErpTradeResponsible.VerifyState = st == 1 ? 1 : 0;
- ceErpTradeResponsible.VerifyTime = DateTime.Now;
- ceErpTradeResponsible.Update();
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
- if (entity != null)
- {
- entity.AfterSaleSupplierMemo = afmemo;
- if (st == 1)
- {
- bool isAll = commonHelper.tradeResponsibleAll(entity);
- if (isAll)
- {
- entity.AfterSaleState = 4;
- entity.FinishAfterSaleTime = DateTime.Now;
- if (entity.AfterSaleResSupId > 0)
- {
- entity.AfterSaleSupplierState = 1;
- }
- }
- }
- else
- {
- CeErpTradeResponsible.dateByTid(entity.ctid);
- CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
- if (ceErpTradeAfterSaleExtend != null)
- {
- ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
- ceErpTradeAfterSaleExtend.Update();
- }
- else
- {
- ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
- ceErpTradeAfterSaleExtend.tid = entity.ctid;
- ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
- ceErpTradeAfterSaleExtend.Create();
- }
- //退回到主管
- //entity.AfterSaleState = 2;
- }
- if (entity.AfterSaleState == 4)
- {
- ApiVo apiVo = new ApiVo();
- apiVo.orderNumber = entity.ctid;
- apiVo.actionName = "afterOver";
- designHelper.API_WorkCore(apiVo); //afterOver
- }
- entity.Update();
- returnSuccessMsg("操作成功!");
- LogHelper.addLog(entity.ctid, UserID, "责任人" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
- LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任人" + (st == 1 ? "认可" : "不认可"), UserID, st == 1 ? 0 : 1, afmemo, image);
- return;
- }
- }
- returnErrorMsg("找不到订单记录");
- return;
- }
- returnErrorMsg("缺少必要的参数id");
- }
- public void upd_erp_masteraftersale()
- {
- if (UrlPostParmsCheck("id"))
- {
- string id = GetPostString("id");
- int st = GetPostInt("afterstate");
- string afmemo = GetPostString("supmemo");
- string image = GetPostString("image");
- string textResult = GetPostString("textResult");
- int UserID = GetPostInt("UserID");
- CeErpTradeResponsible ceErpTradeResponsible = CeErpTradeResponsible.GetById(id);
- if (ceErpTradeResponsible != null)
- {
- ceErpTradeResponsible.VerifyState = st == 1 ? 3 : 0;
- ceErpTradeResponsible.VerifyTime = DateTime.Now;
- ceErpTradeResponsible.Update();
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(ceErpTradeResponsible.tid);
- if (entity != null)
- {
- entity.AfterSaleSupplierState = st;
- entity.AfterSaleSupplierMemo = afmemo;
- if (st == 1)
- {
- }
- else
- {
- CeErpTradeResponsible.dateByTid(entity.ctid);
- //退回到售后
- string numSql = string.Format("SELECT COUNT ( * ) AS BackNum FROM dbo.Ce_ErpTradeAfterSaleLog WHERE tid = '{0}' AND Con in ('责任主管不认可','供应商不认可')", ceErpTradeResponsible.tid);
- DataTable dt = DbHelper.DbConn.ExecuteDataset(numSql).Tables[0];
- int num = Convert.ToInt32(dt.Rows[0]["BackNum"]);
- if (num <= 1)
- {
- entity.AfterSaleState = 1;
- }
- else
- {
- entity.AfterSaleState = 5;
- }
- CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(entity.ctid);
- if (ceErpTradeAfterSaleExtend != null)
- {
- ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
- ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
- ceErpTradeAfterSaleExtend.Update();
- }
- else
- {
- ceErpTradeAfterSaleExtend = new CeErpTradeAfterSaleExtend();
- ceErpTradeAfterSaleExtend.tid = entity.ctid;
- ceErpTradeAfterSaleExtend.AfterSaleBackImg = image;
- ceErpTradeAfterSaleExtend.DisagreeTime = DateTime.Now;
- ceErpTradeAfterSaleExtend.Create();
- }
- }
- entity.Update();
- returnSuccessMsg("操作成功!");
- LogHelper.addLog(entity.ctid, UserID, "责任主管" + (st == 1 ? "认可" : ("不认可," + afmemo)), 0, 3);
- LogHelper.AddAfterSaleLog(entity.ctid, Convert.ToInt32(id), "责任主管" + (st == 1 ? "认可" : "不认可"), UserID, st == 1 ? 0 : 1, afmemo, image);
- return;
- }
- }
- returnErrorMsg("找不到订单记录");
- }
- }
- public void save_erp_billinfo()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string eid = GetPostString("ctid");
- CeErpTradeCell entity = null;
- if (eid != "") entity = CeErpTradeCell.GetByCtid(eid);
- if (entity != null)
- {
- CeErpBill bill = CeErpBill.GetByTid(eid);
- bool isHave = false;
- if (bill != null)
- {
- isHave = true;
- if (bill.state != 4)
- {
- returnErrorMsg("此单已经申请过发票了");
- return;
- }
- }
- if (entity.IsNeedBill == 0)
- {
- entity.IsNeedBill = 1;
- }
- entity.Update();
- string errjson = "";
- try
- {
- CeErpBill bill_entity = new CeErpBill();
- bill_entity.tid = entity.tid;
- bill_entity.title = GetPostString("title");
- string taxstr = GetPostString("tax");
- taxstr = taxstr.Replace(" ", "");
- bill_entity.tax = taxstr;
- bill_entity.bank = GetPostString("bank");
- string bankacstr = GetPostString("bankac");
- bankacstr = bankacstr.Replace(" ", "");
- bill_entity.bankac = bankacstr;
- bill_entity.address = GetPostString("address");
- bill_entity.phone = GetPostString("phone");
- bill_entity.price = GetPostString("price");
- int billCount = (int)Math.Floor(Convert.ToDouble(bill_entity.price) / 1000.00);
- if (Convert.ToDouble(bill_entity.price) % 1000.00 > 0.00001)
- {
- billCount += 1;
- }
- string prebill = "ltb";
- for (int idx = 1; idx <= billCount; idx++)
- {
- string dtstr = DateTime.Now.ToString("yyyyMMddHHmmss");
- string billoid = prebill + idx + dtstr;
- bill_entity.billOrderId += billoid;
- if (idx < billCount)
- {
- bill_entity.billOrderId += ",";
- }
- }
- bill_entity.productId = GetPostInt("ProductName");
- bill_entity.num = GetPostInt("num");
- bill_entity.unit = GetPostString("unit");
- bill_entity.type = GetPostString("type");
- bill_entity.sendType = GetPostString("SendType");
- bill_entity.email = GetPostString("email");
- bill_entity.buyer_nick = GetPostString("buyer_nick");
- bill_entity.shopName = GetPostString("ShopName");
- bill_entity.applymemo = GetPostString("applyMemo");
- bill_entity.createTime = DateTime.Now;
- bill_entity.state = 0;
- bill_entity.userId = 11;
- errjson = Utils.Serialization.JsonString.ConvertObject(bill_entity);
- bill_entity.Create();
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, errjson + "创建发票出错," + ex.Message);
- returnErrorMsg("创建发票出错!");
- return;
- }
- LogHelper.addLog(entity.ctid, CurrentUser.UserID, "申请发票", entity.OrderState, 1);
- returnSuccessMsg("发票申请成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- }
- }
- /**
- * 查货
- * ctid
- * name
- **/
- public void ins_checkorder()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string ctid = GetPostString("ctid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
- if (entity != null)
- {
- if (entity.OrderState < 6)
- {
- returnErrorMsg("下单完成后才可查货");
- return;
- }
- if (entity.OrderState > 6)
- {
- returnErrorMsg("订单已发货");
- return;
- }
- if (entity.FinishPlaceTime != null)
- {
- if (DateTime.Now.AddHours(-5) < entity.FinishPlaceTime)
- {
- returnErrorMsg("下单时间不足,无法查货");
- return;
- }
- }
- entity.MemoOpt = 3;
- entity.CheckOrderTime = DateTime.Now;
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + "标记:查货", entity.OrderState, 1);
- returnSuccessMsg("操作成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- public void ins_checkdesign()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string ctid = GetPostString("ctid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- int memoopt = GetPostInt("memoopt");
- CeErpTradeCell entity = null;
- if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
- if (entity != null)
- {
- string stropt = "";
- if (memoopt == 1)
- {
- stropt = "“改稿”";
- }
- else if (memoopt == 2)
- {
- stropt = "“定稿”";
- }
- entity.MemoOpt = memoopt;
- entity.Update();
- LogHelper.addLog(entity.ctid, UserID, name + "标记:" + stropt, entity.OrderState, 1);
- returnSuccessMsg("操作成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- public void save_othermemo()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string ctid = GetPostString("ctid");
- string name = GetPostString("name");
- int UserID = GetPostInt("UserID");
- CeErpTradeCell entity = null;
- if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
- if (entity != null)
- {
- entity.OtherMemo = GetPostString("otherMemo");
- entity.Update();
- returnSuccessMsg("保存成功!");
- LogHelper.addLog(entity.ctid, UserID, name + "额外:" + entity.OtherMemo, entity.OrderState);
- return;
- }
- returnErrorMsg("找不到记录");
- return;
- }
- returnErrorMsg("缺少必要的参数ctid");
- }
- public void save_customermemo()
- {
- if (UrlPostParmsCheck("ctid"))
- {
- string ctid = GetPostString("ctid");
- CeErpTradeCell entity = null;
- if (ctid != "") entity = CeErpTradeCell.GetByCtid(ctid);
- if (entity != null)
- {
- entity.CustomerMemo = GetPostString("CustomerMemo");
- entity.Update();
- ApiVo apiVo = new ApiVo();
- apiVo.orderNumber = entity.ctid;
- apiVo.actionName = "followRemarks";
- apiVo.orderRemarks = entity.CustomerMemo;
- designHelper.API_WorkCore(apiVo);//followRemarks
- returnSuccessMsg("保存成功!");
- return;
- }
- returnErrorMsg("找不到记录");
- }
- }
- public void create_order()
- {
- if (UrlPostParmsCheck("data"))
- {
- string data = GetPostString("data");
- Api_trade_info info = null;
- try
- {
- info = JsonConvert.DeserializeObject<Api_trade_info>(data);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "create_order|1|" + ex.Message);
- returnErrorMsg(ex.Message);
- return;
- }
- if (info == null)
- {
- XLog.SaveLog(0, "Api_trade_info isNull");
- return;
- }
- BizOrder bizOrder = info.bizOrder;
- if (bizOrder == null)
- {
- returnErrorMsg("接口对象处理错误bizOrder=null");
- return;
- }
- bool isCreate = false;
- CeErpTrade trade = null;
- trade = CeErpTrade.Get(bizOrder.thirdOrderId);
- if (trade == null)
- {
- isCreate = true;
- }
- List<tempResponse> callResult = null;
- try
- {
- trade = createTradeOrder(bizOrder, trade, isCreate);
- List<Api_trade_info.TradeItemOrder> orderList = bizOrder.bizOrderItems;
- createItemOrder(orderList, trade);
- List<Api_trade_info.bizOrderSplit> bizOrderSplit = bizOrder.bizOrderSplits;
- callResult = createCellOrder(bizOrderSplit, trade, isCreate);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "create_order|2|" + ex);
- returnErrorMsg(ex.Message);
- return;
- }
- returnSuccessMsg(JsonConvert.SerializeObject(callResult));
- return;
- }
- returnErrorMsg("缺少必要的参数data");
- }
- public void refundOrder()
- {
- if (UrlPostParmsCheck("data"))
- {
- string data = GetPostString("data");
- Api_refund_info info = null;
- try
- {
- info = JsonConvert.DeserializeObject<Api_refund_info>(data);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "refundOrder|4|" + ex.Message);
- returnErrorMsg(ex.Message);
- return;
- }
- if (info == null)
- {
- XLog.SaveLog(0, "Api_refund_info isNull");
- returnErrorMsg("接口对象处理错误RefundOrder=null1");
- return;
- }
- RefundOrder refundOrder = info.refundOrder;
- if (refundOrder == null)
- {
- returnErrorMsg("接口对象处理错误RefundOrder=null2");
- return;
- }
- CeErpTrade trade = CeErpTrade.Get(refundOrder.tid);
- if (trade != null)
- {
- CeErpTradeRefund refund = CeErpTradeRefund.GetByOidAndReId(refundOrder.ctid, refundOrder.orderSn);
- LogHelper.addLog(refundOrder.ctid, 0, "客户退款", 0);
- if (refund == null)
- {
- refund = new CeErpTradeRefund();
- refund.refund_id = refundOrder.orderSn;
- refund.tid = refundOrder.tid;
- refund.oid = refundOrder.ctid;
- if (refundOrder.createTime != null && refundOrder.createTime.Length > 0)
- {
- refund.created = Convert.ToDateTime(refundOrder.createTime);
- }
- if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
- {
- refund.modified = Convert.ToDateTime(refundOrder.updateTime);
- }
- refund.status = refundOrder.status;
- refund.order_status = refundOrder.orderStatus;
- refund.payment = refundOrder.payment.ToString();
- refund.refund_fee = refundOrder.refundFee;//退款金额
- refund.buyer_nick = GetNull_tostring(refundOrder.openBuyerNick);
- refund.seller_nick = refundOrder.seller_nick;
- refund.total_fee = refundOrder.totalFee;
- refund.RefundState = 1;
- refund.reason = refundOrder.reason;
- refund.refundDesc = refundOrder.desc;
- refund.IsPartRefund = refundOrder.isPartRefund;
- refund.Create();
- try
- {
- StringBuilder CeErpTradeCellSql = new StringBuilder();
- CeErpTradeCellSql.AppendFormat("select * from CE_ErpTradeCell where ctid='{0}';", refundOrder.ctid);
- DataSet cell = DbHelper.DbConn.ExecuteDataset(CeErpTradeCellSql.ToString());
- DataTable datatable = cell.Tables[0];
- if (datatable.Rows.Count > 0)
- {
- foreach (DataRow dr in datatable.Rows)
- {
- int DesignUserId = Convert.ToInt32(dr["DesignUserId"]);
- int OrderState = Convert.ToInt32(dr["OrderState"]);
- int CustomerUserId = Convert.ToInt32(dr["CustomerUserId"]);
- if (DesignUserId > 0 && OrderState == 4)
- {
- createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, DesignUserId, 1);
- }
- if (CustomerUserId > 0)
- {
- createRefundMessage(dr["ctid"].ToString(), MessageState.订单退款, CustomerUserId, 1);
- }
- }
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "退款推送通知创建失败!!" + ex);
- }
- int rstate = commonHelper.getRefundTagByState(refundOrder.status);
- StringBuilder sql = new StringBuilder();
- if (refund.IsPartRefund == 1)
- {
- double paylast = Convert.ToDouble(refundOrder.payment) - Convert.ToDouble(refund.refund_fee);
- sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1},payment={2} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 3, paylast);
- }
- else
- sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, rstate);
- CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
- string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
- //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
- StringBuilder sqls = new StringBuilder();
- sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
- CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
- LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
- }
- else
- {
- if (refund.status != refundOrder.status)
- {
- refund.modified = DateTime.Now;
- if (refundOrder.updateTime != null && refundOrder.updateTime.Length > 0)
- {
- refund.modified = Convert.ToDateTime(refundOrder.updateTime);
- }
- refund.order_status = refundOrder.orderStatus;
- refund.status = refundOrder.status;
- refund.Update();
- int rstate = commonHelper.getRefundTagByState(refundOrder.status);
- string rstateWord = commonHelper.getRefundStringByState(refundOrder.status);
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("update CE_ErpTradeCell with(rowlock) set IsRefund={0} where ctid='{1}' and isAfterSaleOrder=0;", rstate, refundOrder.ctid);
- CeErpTradeRefund.ExecuteNonQuery(sql.ToString());
- //commonHelper.UpdateRefundOrderState(tObj.refOid, rstate);
- LogHelper.addLog(refundOrder.tid, 0, "更新退款状态:" + rstateWord, (int)OrderState.交易关闭);
- // 取消设计费
- StringBuilder sqls = new StringBuilder();
- sqls.AppendFormat("update CE_ErpDesignerBill set isDel = 1 where tid = '{0}'", refundOrder.tid);
- CeErpDesignerBill.ExecuteNonQuery(sqls.ToString());
- LogHelper.addDesignerBillLog(refundOrder.tid, 0, "客户退款", "系统自动", 0);
- }
- }
- List<RefundItemOrder> goodsItems = refundOrder.goodsItems;
- foreach (RefundItemOrder item in goodsItems)
- {
- CeErpTradeOrder goods = CeErpTradeOrder.GetByOid(item.refOlId);
- if (goods != null)
- {
- goods.refund_status = item.refundStatus;
- goods.Update();
- }
- }
- if (refundOrder.status == "WAIT_SELLER_AGREE")
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 1);
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- designHelper.API_refundOrder(refundOrder.tid, "refundIng", refundOrder.reason);
- LogHelper.addLog(refundOrder.tid, 0, "申请退款中", 0);
- }
- else if (refundOrder.status == "CLOSED")
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("update ce_erptradecell with(rowlock) set isrefund={1} where ctid='{0}' and isAfterSaleOrder=0;", refundOrder.ctid, 0);
- DbHelper.DbConn.ExecuteNonQuery(sql.ToString());
- designHelper.API_refundOrder(refundOrder.tid, "refundCancel", refundOrder.reason);
- LogHelper.addLog(refundOrder.tid, 0, "关闭申请退款中", 0);
- }
- else if (refundOrder.status == "REFUNDED" || refundOrder.status == "SUCCESS")
- {
- designHelper.API_refundOrder(refundOrder.tid, "refundEd", refundOrder.reason);
- }
- }
- else
- {
- }
- }
- returnErrorMsg("缺少必要的参数data");
- }
- public void createRefundMessage(string ctid, MessageState messageState, int userId, int type)
- {
- CeErpMessageTip ceErpMessageTip = new CeErpMessageTip();
- ceErpMessageTip.tid = ctid;
- ceErpMessageTip.type = Convert.ToInt32(messageState);
- ceErpMessageTip.userId = userId;
- ceErpMessageTip.isVisit = false;
- ceErpMessageTip.content = "订单" + ctid + "申请了退款!";
- ceErpMessageTip.Create();
- StringBuilder sqlTip = new StringBuilder();
- if (type == 1)
- {
- sqlTip.AppendFormat(" select top 1 B.id from view_ErpUser A JOIN view_ErpUser b ON a.OrgID = B.OrgID and b.PostName Like '设计主管%' WHERE A.ID = '{0}';", userId);
- }
- if (type == 2)
- {
- sqlTip.AppendFormat(" select top 1 B.id from view_ErpUser A JOIN view_ErpUser b ON a.OrgID = B.OrgID and b.PostName Like '店长%' WHERE A.ID = '{0}';", userId);
- }
- DataTable dth = DbHelper.DbConn.ExecuteDataset(sqlTip.ToString()).Tables[0];
- if (dth.Rows.Count > 0)
- {
- foreach (DataRow dthdr in dth.Rows)
- {
- int Bid = Convert.ToInt32(dthdr["id"]);
- if (Bid > 0)
- {
- CeErpMessageTip ceErpMessageTipB = new CeErpMessageTip();
- ceErpMessageTipB.tid = ctid;
- ceErpMessageTipB.type = Convert.ToInt32(messageState);
- ceErpMessageTipB.userId = Bid;
- ceErpMessageTipB.isVisit = false;
- ceErpMessageTipB.content = "订单" + ctid + "申请了退款!";
- ceErpMessageTipB.Create();
- }
- }
- }
- }
- public List<tempResponse> createCellOrder(List<Api_trade_info.bizOrderSplit> bizOrderSplit, CeErpTrade trade, bool isCreate)
- {
- List<tempResponse> tempResponses = new List<tempResponse>();
- CeErpShop nShop = CeErpShop.GetShopIdByName(trade.seller_nick);
- foreach (Api_trade_info.bizOrderSplit item in bizOrderSplit)
- {
- bool create = false;
- CeErpTradeCell entity = CeErpTradeCell.GetByCtid(item.splitNo);
- if (entity == null)
- {
- entity = new CeErpTradeCell();
- create = true;
- entity.tid = trade.tid;
- entity.pay_time = trade.pay_time;
- }
- if (entity.OrderState > 4)
- {
- continue;
- }
- entity.ctid = item.splitNo;
- entity.seller_memo = item.systemRemark;
- if (!string.IsNullOrEmpty(item.splitAmount))
- {
- entity.payment = Convert.ToDouble(item.splitAmount);
- }
- if (!string.IsNullOrEmpty(item.splitAmount))
- {
- entity.AfterSalePayment = Convert.ToDouble(item.splitAmount);
- }
- if (!string.IsNullOrEmpty(item.sfMark))
- {
- entity.IsSF = Convert.ToInt32(item.sfMark);
- }
- entity.ProductSize = item.size;
- entity.Material = item.material;
- entity.CustomerUserId = item.erpCustomerServiceId;
- //entity.Craft = item.craft;
- entity.ProductCount = item.productQuantity;
- entity.ProductId = tmcHelper.getProductIdByName(item.cate3Id);
- if (!string.IsNullOrEmpty(item.internalStatus))
- {
- entity.OrderState = Convert.ToInt32(item.internalStatus);
- }
- entity.IsUrgency = item.isUrgent;
- entity.ptid = item.ptid;
- entity.SplitTag = item.splitInfoNo;
- if (!string.IsNullOrEmpty(item.paymentFile))
- {
- entity.PayProofImg = item.paymentFile;
- }
- if (item.shippingTime != null && item.shippingTime.Length > 0)
- {
- entity.UnusualTime = Convert.ToDateTime(item.shippingTime);
- entity.UrgencyTime = Convert.ToDateTime(item.shippingTime);
- }
- if (!string.IsNullOrEmpty(item.sendGiftMark))
- {
- entity.IsSendGift = Convert.ToInt32(item.sendGiftMark);
- }
- entity.OtherMemo = item.otherRemark;
- entity.IsOldCustomer = item.isRepurchase ? 1 : 0;
- entity.IsOldCustomerMore = item.isOldCustomerMore;
- entity.MemoOpt = item.memoOpt;
- entity.isDianziOrder = item.isDianziOrder;
- if (item.isPreShipping != null && item.isPreShipping.Length > 0)
- {
- entity.IsPreDelivery = Convert.ToInt32(item.isPreShipping);
- }
- if (item.checkOrderTime != null && item.checkOrderTime.Length > 0)
- {
- entity.CheckOrderTime = Convert.ToDateTime(item.checkOrderTime);
- }
- int shopId = 0;
- if (nShop != null)
- {
- shopId = nShop.ID;
- }
- entity.ShopId = shopId;
- entity.OrderSn = item.OrderSn;
- entity.ParentSplitNo = item.parentSplitNo;
- CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(entity.ctid);
- if (ceErpTradeCellExtend == null)
- {
- ceErpTradeCellExtend = new CeErpTradeCellExtend();
- ceErpTradeCellExtend.ctid = entity.ctid;
- }
- ceErpTradeCellExtend.cate1 = item.cate1;
- ceErpTradeCellExtend.cate2 = item.cate2;
- ceErpTradeCellExtend.scene = item.scene;
- ceErpTradeCellExtend.material = item.material;
- ceErpTradeCellExtend.offerAmount = item.offerAmount;
- ceErpTradeCellExtend.numbers = item.numbers;
- ceErpTradeCellExtend.typeScene = item.typeScene;
- ceErpTradeCellExtend.opScene = item.opScene;
- ceErpTradeCellExtend.craft = item.craft;
- ceErpTradeCellExtend.numberType = item.numberType;
- ceErpTradeCellExtend.cate1Id = item.cate1Id;
- ceErpTradeCellExtend.cate2Id = item.cate2Id;
- ceErpTradeCellExtend.cate3Id = item.cate3Id;
- ceErpTradeCellExtend.sceneId = item.sceneId;
- ceErpTradeCellExtend.typeSceneId = item.typeSceneId;
- ceErpTradeCellExtend.opSceneId = item.opSceneId;
- ceErpTradeCellExtend.materialId = item.materialId;
- ceErpTradeCellExtend.width = item.width;
- ceErpTradeCellExtend.height = item.height;
- ceErpTradeCellExtend.length = item.length;
- ceErpTradeCellExtend.recSize = item.recSize;
- ceErpTradeCellExtend.sizeUnit = item.sizeUnit;
- ceErpTradeCellExtend.numberUnit = item.numberUnit;
- ceErpTradeCellExtend.orderFrom = 30;
- ceErpTradeCellExtend.spu_id = item.spuId;
- ceErpTradeCellExtend.quantity = item.quantity;
- ceErpTradeCellExtend.discountAmount = item.discountAmount;
- ceErpTradeCellExtend.differentAmount = item.compensateAmount;
- ceErpTradeCellExtend.differentSplitNo = item.compensateSplitOrderUniqueNo;
- ceErpTradeCellExtend.orderType = item.orderType;
- ceErpTradeCellExtend.parentOrderSn = item.parentSplitNo;
- if (ceErpTradeCellExtend.ID > 0)
- {
- ceErpTradeCellExtend.Update();
- }
- else
- {
- ceErpTradeCellExtend.Create();
- }
- if (item.isGift == 1)
- {
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier); //圆通仓库
- entity.IsXianHuo = 1;
- entity.IsGift = 1;
- entity.FinishPlaceTime = trade.pay_time;
- if (entity.OrderState < 6)
- {
- entity.OrderState = Convert.ToInt32(OrderState.下单完成);
- }
- }
- if (item.isSpot)
- {
- if (entity.OrderState < 6)
- {
- entity.OrderState = Convert.ToInt32(OrderState.下单完成);
- }
- entity.seller_memo = item.systemRemark;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- entity.IsXianHuo = 1;
- entity.FinishPlaceTime = entity.pay_time;
- if (item.systemRemark.IndexOf("封酒贴") != -1)
- {
- entity.SupplierId = Convert.ToInt32(webConfig.Fengjiutie_supid);//得力
- if (trade.buyer_memo != "")
- {
- entity.OrderState = 2;
- entity.ProductId = 1;
- entity.IsXianHuo = 0;
- item.systemRemark = item.systemRemark.Replace("现货", "");
- item.systemRemark = item.systemRemark.Replace(" ", "");
- entity.seller_memo = item.systemRemark;
- if (entity.ShopId != 0)
- {
- entity.OrderState = orderAudit(entity.ShopId);
- }
- }
- }
- else if (item.systemRemark.IndexOf("#") != -1)
- {
- entity.SupplierId = 87;
- }
- else if (item.systemRemark.IndexOf("喜字贴") != -1)
- {
- entity.SupplierId = 70;
- }
- else if (item.systemRemark.IndexOf("兔团团") != -1)
- {
- entity.SupplierId = 101;
- }
- else if (item.systemRemark.IndexOf("手拉旗") != -1)
- {
- entity.SupplierId = 108;
- }
- try
- {
- string goodsSql = "select * from CE_ErpSupplier where IsClose = 0 and XianhuoMemo IS NOT NULL AND XianhuoMemo != ''";
- DataTable goodsDt = CeErpTradeCell.ExecuteDataset(goodsSql).Tables[0];
- List<Dictionary<string, string>> material_list = new List<Dictionary<string, string>>();
- List<Dictionary<string, string>> name_list = new List<Dictionary<string, string>>();
- foreach (DataRow dr in goodsDt.Rows)
- {
- string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ",");
- List<string> xianhuo = sqlMemo.Split(',').ToList();
- foreach (var val in xianhuo)
- {
- if (string.IsNullOrEmpty(val)) continue;
- Dictionary<string, string> material_map = new Dictionary<string, string>();//材质
- Dictionary<string, string> name_map = new Dictionary<string, string>();//特殊名称
- if (val.IndexOf('-') > -1)
- {
- List<string> list = val.Split('-').ToList();
- material_map.Add(dr["id"].ToString(), list[0]);
- name_map.Add(dr["id"].ToString(), list[1]);
- }
- else
- {
- material_map.Add(dr["id"].ToString(), val);
- }
- material_list.Add(material_map);
- name_list.Add(name_map);
- }
- }
- List<string> materials = new List<string>();
- List<string> names = new List<string>();
- List<string> result = new List<string>();
- for (int i = 0; i < material_list.Count; i++)
- {
- Dictionary<string, string> map = material_list[i];
- foreach (var val in map)
- {
- if (item.systemRemark.IndexOf(val.Value) > -1)
- {
- Dictionary<string, string> map2 = name_list[i];
- if (map2.Count > 0)//材质匹配中后是否有特殊名称去匹配
- {
- foreach (var item1 in map2)
- {
- if (item.systemRemark.IndexOf(item1.Value) > -1)
- {
- names.Add(item1.Key);
- materials.Add(val.Key);
- }
- }
- }
- else
- {
- materials.Add(val.Key);
- }
- }
- }
- }
- if (names.Count > 0)//特殊名称有只先在特殊名称里选择
- {
- result = names.Distinct().ToList();
- }
- else
- {
- result = materials.Distinct().ToList();
- }
- if (result.Count > 0)
- {
- Random rnd = new Random();
- int index = rnd.Next(result.Count);
- entity.SupplierId = int.Parse(result[index]);
- }
- }
- catch (Exception e)
- {
- XLog.SaveLog(0, "|现货匹配|" + e.Message);
- }
- }
- if (isCreate)
- {
- int oldRes = isOldAndInsertCustomerInfo(trade, entity);
- if (oldRes > 0)
- {
- //entity.IsOldCustomer = 1;
- //if (oldRes == 2) entity.IsOldCustomerMore = 1;
- }
- }
- if (item.sampleMark == "1")
- {
- entity.IsSample = 1;
- entity.OrderState = 6;
- entity.FinishPlaceTime = DateTime.Now;
- entity.IsOldCustomer = 0;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- }
- if (item.sampleMark == "3")
- {
- entity.IsSample = 3;
- entity.OrderState = 6;
- entity.FinishPlaceTime = DateTime.Now;
- entity.IsOldCustomer = 0;
- entity.SupplierId = Convert.ToInt32(webConfig.SampleOrderSupplier);
- }
- if (item.sampleMark == "2" && !string.IsNullOrEmpty(item.parentSplitNo))
- {
- CeErpTradeCell ceErpTradeCell = CeErpTradeCell.GetByCtid(item.parentSplitNo);
- if (ceErpTradeCell != null)
- {
- entity.CustomerUserId = ceErpTradeCell.CustomerUserId;
- entity.DesignUserId = ceErpTradeCell.DesignUserId;
- entity.SupplierId = ceErpTradeCell.SupplierId;
- entity.IsSample = 2;
- entity.WaitDesignTime = ceErpTradeCell.WaitDesignTime;
- entity.StartDesignTime = ceErpTradeCell.StartDesignTime;
- entity.FinishDesignTime = ceErpTradeCell.FinishDesignTime;
- entity.FinishPlaceTime = ceErpTradeCell.FinishPlaceTime;
- }
- CeErpTradeCellExtend parentCell = CeErpTradeCellExtend.getByTid(item.parentSplitNo);
- if (parentCell == null)
- {
- parentCell = new CeErpTradeCellExtend();
- parentCell.ctid = item.parentSplitNo;
- }
- if (!string.IsNullOrEmpty(item.splitAmount))
- {
- parentCell.differentAmount += Convert.ToDouble(item.splitAmount);
- }
- if (parentCell.ID > 0)
- {
- parentCell.Update();
- }
- else
- {
- parentCell.Create();
- }
- ApiVo apiVo = new ApiVo();
- apiVo.orderNumber = entity.ptid;
- apiVo.payment = entity.payment;
- apiVo.actionName = "repairDesign";
- designHelper.API_WorkCore(apiVo);//repairDesign
- }
- bool isCopyFile = false;
- //老客户
- if (item.isRepurchase)
- {
- if (item.isOldCustomer == 1)
- {
- tmcHelper.dealOldCustomerEntityTag(ref entity, trade);
- }
- if (item.isOldCustomer == 3)
- {
- entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
- entity.WaitDesignTime = DateTime.Now;
- isCopyFile = true;
- }
- if (item.isOldCustomer == 2)
- {
- entity.OrderState = 3;
- entity.DesignUserId = Convert.ToInt32(webConfig.PlaceDesigner_id);
- entity.WaitDesignTime = DateTime.Now;
- LogHelper.addLog(entity.ctid, 0, "老客户单指派到下单部", entity.OrderState);
- }
- }
- if (create)
- {
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "创建推送生成:" + entity.seller_memo, entity.OrderState);
- entity.Create();
- }
- else
- {
- LogHelper.addLog(entity.ctid, entity.CustomerUserId, "更新推送生成:" + entity.seller_memo, entity.OrderState);
- designHelper.API_update_order(entity);
- entity.Update();
- }
- if (isCopyFile)
- {
- apiUploaderResponse upResult = CopyDesignFile(entity.ctid, item.oldOrderSn, entity.CustomerUserId);
- if (upResult == null || "error".Equals(upResult.type))
- {
- tempResponse response = new tempResponse();
- response.flag = "1";
- response.flagData = entity.ctid;
- response.flagMsg = upResult == null ? "复制文件出错!" : upResult.result;
- }
- }
- }
- return tempResponses;
- }
- public void createItemOrder(List<Api_trade_info.TradeItemOrder> orderList, CeErpTrade trade)
- {
- foreach (Api_trade_info.TradeItemOrder item in orderList)
- {
- CeErpTradeOrder order = CeErpTradeOrder.GetByOid(item.thirdOrderItemId);
- bool isCreateOrder = false;
- if (order == null)
- {
- order = new CeErpTradeOrder();
- isCreateOrder = true;
- order.oid = item.thirdOrderItemId;
- order.tid = trade.tid;
- order.buyer_nick = trade.buyer_nick;
- }
- order.refund_status = item.refundStatus;
- order.status = trade.status;
- order.title = item.title;
- if (!string.IsNullOrEmpty(item.price))
- {
- order.price = Convert.ToDouble(item.price);
- }
- if (item.picUrl != null)
- {
- order.pic_path = item.picUrl;
- }
- if (!string.IsNullOrEmpty(item.num))
- {
- order.num = Convert.ToDouble(item.num);
- }
- if (!string.IsNullOrEmpty(item.totalAmount))
- {
- order.payment = Convert.ToDouble(item.totalAmount);
- }
- if (!string.IsNullOrEmpty(item.totalSellPrice))
- {
- order.total_fee = Convert.ToDouble(item.totalSellPrice);
- }
- //order.adjust_fee = Convert.ToDouble(item.price);
- if (item.thirdSkuId != null && item.thirdSkuId != "")
- {
- order.sku_id = item.thirdSkuId;
- }
- if (item.specification != null && item.specification != "")
- {
- order.sku_properties_name = item.specification;
- }
- if (item.thirdSpuId != null && item.thirdSpuId != "")
- {
- order.spu_id = item.thirdSpuId;
- }
- if (isCreateOrder)
- {
- order.Create();
- }
- else
- {
- order.Update();
- }
- }
- }
- public CeErpTrade createTradeOrder(BizOrder bizOrder, CeErpTrade trade, bool isCreate)
- {
- if (trade == null)
- { //新生成订单的
- isCreate = true;
- trade = new CeErpTrade();
- trade.tid = bizOrder.thirdOrderId;
- trade.type = bizOrder.orderPlatform;
- if (!string.IsNullOrEmpty(bizOrder.payAmount))
- {
- trade.price = Convert.ToDouble(bizOrder.payAmount);
- }
- trade.discount_fee = 0;
- if (!string.IsNullOrEmpty(bizOrder.payAmount))
- {
- trade.total_fee = Convert.ToDouble(bizOrder.payAmount);
- }
- if (bizOrder.orderTime != null && bizOrder.orderTime.Length > 0)
- {
- trade.created = Convert.ToDateTime(bizOrder.orderTime);
- }
- if (bizOrder.payTime != null && bizOrder.payTime.Length > 0)
- {
- trade.pay_time = Convert.ToDateTime(bizOrder.payTime);
- }
- trade.seller_nick = GetNull_tostring(bizOrder.openSellerNick);
- if (!string.IsNullOrEmpty(bizOrder.payAmount))
- {
- trade.payment = Convert.ToDouble(bizOrder.payAmount);
- }
- }
- trade.buyer_nick = GetNull_tostring(bizOrder.openBuyerNick);
- trade.receiver_state = bizOrder.province;
- if (!string.IsNullOrEmpty(bizOrder.num))
- {
- trade.num = Convert.ToDouble(bizOrder.num);
- }
- trade.receiver_city = bizOrder.city;
- trade.receiver_address = GetNoNullValue_string(bizOrder.address);
- trade.receiver_town = GetNoNullValue_string(bizOrder.receiverTown);
- trade.receiver_district = GetNoNullValue_string(bizOrder.area);
- trade.seller_flag = bizOrder.thirdFlag;
- trade.orderType = bizOrder.orderType;
- trade.orderFrom = 30;
- trade.unrefundedAmount = bizOrder.unrefundedAmount;
- if (bizOrder.modifyTime != null && bizOrder.modifyTime.Length > 0)
- {
- trade.modified = Convert.ToDateTime(bizOrder.modifyTime);
- }
- if (bizOrder.finishTime != null && bizOrder.finishTime.Length > 0)
- {
- trade.end_time = Convert.ToDateTime(bizOrder.finishTime);
- }
- if (bizOrder.shippingTime != null && bizOrder.shippingTime.Length > 0)
- {
- trade.delivery_time = Convert.ToDateTime(bizOrder.shippingTime);
- }
- if (bizOrder.confirmTime != null && bizOrder.confirmTime.Length > 0)
- {
- trade.confirmTime = Convert.ToDateTime(bizOrder.confirmTime);
- }
- trade.buyer_memo = GetNoNullValue_string(bizOrder.buyerRemark);
- bool isSellerMemoChange = false;
- //备注修改
- bizOrder.sellerRemark = GetNoNullValue_string(bizOrder.sellerRemark);
- if (trade.seller_memo != bizOrder.sellerRemark || trade.seller_memo.Length != bizOrder.sellerRemark.Length)
- {
- isSellerMemoChange = true;
- }
- trade.status = bizOrder.status;
- trade.seller_memo = bizOrder.sellerRemark;
- trade.buyer_id = bizOrder.openBuyerId;
- trade.posCode = bizOrder.shopCode;
- if (isCreate)
- {
- trade.Create();
- }
- else
- {
- if (bizOrder.status == "CLOSE")
- {
- trade.consign_time = DateTime.Now;
- }
- trade.Update();
- }
- try
- {
- if (bizOrder.status == "CLOSE" || bizOrder.status == "CANCEL")
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_close',getdate());", (int)OrderState.交易关闭, bizOrder.thirdOrderId);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- ApiVo apiVo = new ApiVo();
- apiVo.actionName = "closeDesign";
- apiVo.orderNumber = bizOrder.thirdOrderId;
- //designHelper.API_WorkCore(apiVo);//closeDesign
- LogHelper.addLog(bizOrder.thirdOrderId, 0, "交易关闭", (int)OrderState.交易关闭);
- // commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易关闭, "updatestate_close");
- // removeOldCustomerInfo(trade);
- }
- else if (bizOrder.status == "COMPLETE")
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_complete',getdate());", (int)OrderState.交易完成, bizOrder.thirdOrderId);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.交易完成, "updatestate_complete");
- }
- else if (bizOrder.status == "SHIPPED")//已发货
- {
- StringBuilder sql = new StringBuilder();
- sql.AppendFormat("insert into S_BuChaJia(ctid,orderState,dotype,addtime) values('{1}',{0},'updatestate_shipped',getdate());", (int)OrderState.已发货, bizOrder.thirdOrderId);
- CeErpTradeCell.ExecuteNonQuery(sql.ToString());
- //commonHelper.updateOrderStateForShipped(tObj.refOid, (int)OrderState.已发货, "updatestate_shipped");
- }
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, bizOrder.thirdOrderId + "shipped:" + ex.Message);
- throw ex;
- }
- return trade;
- }
- public static apiUploaderResponse CopyDesignFile(string ctid, string oldCtid, int userId)
- {
- string post_url = "http://183.250.143.56:8088/autocopy.aspx";
- WebClient wc = new WebClient();
- wc.Encoding = Encoding.GetEncoding("utf-8");
- //json参数
- NameValueCollection PostVars = new NameValueCollection();
- PostVars.Add("hexdata", oldCtid + "," + ctid);
- PostVars.Add("userid", userId.ToString());
- apiUploaderResponse result = null;
- try
- {
- byte[] ret = wc.UploadValues(post_url, "POST", PostVars);
- string remoteInfo = Encoding.GetEncoding("utf-8").GetString(ret);
- result = JsonConvert.DeserializeObject<apiUploaderResponse>(remoteInfo);
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, "CopyDesignFile:" + ex.Message);
- }
- return result;
- }
- public static DateTime StampToDateTime(string timeStamp)
- {
- DateTime dateTimeStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1));
- long lTime = long.Parse(timeStamp + "0000");
- TimeSpan toNow = new TimeSpan(lTime);
- return dateTimeStart.Add(toNow);
- }
- public static string GetNull_tostring(object value)
- {
- if (value == null)
- {
- return "";
- }
- return value.ToString();
- }
- public static string GetNoNullValue_string(string value)
- {
- if (value == null)
- {
- return "";
- }
- value = value.Replace("\n", " ");
- value = value.Replace("\r", " ");
- return value;
- }
- public static string getShopNameByECode(string code)
- {
- string sql = "select * from CE_ErpShop where AppSecret='" + code + "'";
- DataTable dt = CeErpTradeCell.ExecuteDataset(sql).Tables[0];
- if (dt != null && dt.Rows.Count > 0)
- {
- return dt.Rows[0]["ShopName"].ToString();
- }
- return "";
- }
- public static int orderAudit(int shopId)
- {
- try
- {
- CeErpShop ceErpShop = CeErpShop.GetShopById(shopId);
- if (ceErpShop == null) return 2;
- if (!ceErpShop.orderAudit) return 2;
- return -1;
- }
- catch (Exception ex)
- {
- return 2;
- }
- }
- public static int isOldAndInsertCustomerInfo(CeErpTrade father, CeErpTradeCell tradecell)
- {
- if (father.seller_nick == "") return 0;
- CeErpCustomer cus = null;
- cus = CeErpCustomer.GetByNickAndShop(father.buyer_nick, father.seller_nick);
- if (cus == null)
- {
- cus = CeErpCustomer.GetByIdAndShop(father.buyer_id, father.seller_nick);
- }
- int pcount = commonHelper.getIntCountFromString(tradecell.ProductCount);
- if (cus != null)
- {
- if (cus.lastbuy_time.ToString() == "") return 0;
- if (((DateTime)cus.lastbuy_time).CompareTo((DateTime)father.pay_time) > 0) return 0;
- cus.buyer_id = father.buyer_id;
- if (cus.lastTid == father.tid)
- {
- if (pcount != cus.product_count)
- {
- cus.product_count = pcount;
- cus.Update();
- }
- }
- else
- {
- int returnNum = 0;
- TimeSpan tsday = ((DateTime)(father.pay_time)).Subtract((DateTime)cus.lastbuy_time);
- cus.buy_day = Convert.ToInt32(tsday.TotalDays);
- cus.total_fee = cus.total_fee + Convert.ToDouble(father.payment);
- cus.buy_count = cus.buy_count + 1;
- cus.lastbuy_time2 = cus.lastbuy_time;
- cus.buyer_id = father.buyer_id;
- cus.lastbuy_time = father.pay_time;
- int lastpCount = cus.product_count;
- cus.product_count = pcount;
- cus.lastTid2 = cus.lastTid;
- cus.lastTid = father.tid;
- if (cus.buy_day > 1)
- {
- if (pcount > lastpCount && cus.product_count != 0)
- {
- cus.isMore = 1;
- returnNum = 2;
- }
- else
- returnNum = 1; //上次跟这次超过1天 算老客户、、防止补差价
- }
- else
- returnNum = 0;
- cus.Update();
- return returnNum;
- }
- }
- else
- {
- try
- {
- cus = new CeErpCustomer();
- cus.buyer_nick = father.buyer_nick;
- cus.seller_nick = father.seller_nick;
- cus.buyer_id = father.buyer_id;
- cus.buy_day = 0;
- cus.buy_count = 1;
- cus.lastbuy_time = father.pay_time;
- cus.lastTid = father.tid;
- cus.total_fee = Convert.ToDouble(father.payment);
- cus.product_count = pcount;
- cus.Create();
- return 0;
- }
- catch (Exception ex)
- {
- XLog.SaveLog(0, father.tid + father.buyer_nick + ":" + ex.Message);
- }
- }
- return 0;
- }
- }
- }
|