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 NPOI.SS.Formula.PTG; 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) { XLog.SaveLog(0, "preSalesHelper:" + 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.UpdateTime = DateTime.Now; entity.Update(); ApiVo apiVo = new ApiVo(); apiVo.orderNumber = entity.ctid; apiVo.actionName = "changeDesign"; apiVo.orderRemarks = entity.seller_memo; apiVo.remarkSign = 3; designHelper.API_WorkCore(apiVo); //changeDesign 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 eLst = new List(); 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; } LogHelper.addLog(dr["ctid"].ToString(), UserID, "售前:" + errmsg, 0, 1); } 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.UpdateTime = 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.UpdateTime = DateTime.Now; entity.Update(); LogHelper.addLog(entity.ctid, UserID, name + "手动关联补差价", entity.OrderState, 1); returnSuccessMsg("关联成功!"); return; } returnErrorMsg("找不到记录"); return; } returnErrorMsg("缺少必要的参数ctid"); } /// /// 转单 /// public void upd_erp_transcustomer() { if (UrlPostParmsCheck("ctid")) { string eid = GetPostString("ctid"); int customerUserId = GetPostInt("CustomerUserId"); int userid = GetPostInt("UserID"); CeErpTradeCell entity = null; if (eid != "") entity = CeErpTradeCell.GetByCtid(eid); if (entity != null) { entity.CustomerUserId = customerUserId; entity.UpdateTime = DateTime.Now; entity.Update(); returnSuccessMsg("操作成功!"); LogHelper.addLog(entity.ctid, userid, "转单给其他客服" + userid, entity.OrderState); return; } returnErrorMsg("找不到记录"); } } /// /// 推购审核 /// public void upd_erp_staygoods() { if (UrlPostParmsCheck("id")) { int eid = GetPostInt("id"); int userid = GetPostInt("UserID"); string name = GetPostString("name"); CeErpStayGoods entity = null; if (eid != 0) entity = CeErpStayGoods.GetStayId(eid); if (entity != null) { entity.audit_type = 1; entity.audit_time = DateTime.Now; entity.audit_u_id = userid; entity.audit_u_name = name; entity.Update(); returnSuccessMsg("审核成功!"); return; } returnErrorMsg("找不到订单记录"); } } /// /// 推购退回 /// public void upd_erp_stayGoodsback() { if (UrlPostParmsCheck("id")) { int eid = GetPostInt("id"); int userid = GetPostInt("UserID"); string name = GetPostString("name"); CeErpStayGoods entity = null; if (eid != 0) entity = CeErpStayGoods.GetStayId(eid); if (entity != null) { entity.audit_text = GetPostString("reason"); entity.audit_type = 2; entity.audit_time = DateTime.Now; entity.audit_u_id = userid; entity.audit_u_name = name; entity.Update(); returnSuccessMsg("退回成功!"); return; } returnErrorMsg("找不到订单记录"); } } /// /// 取消推购 /// public void upd_erp_ordertag_cancel() { if (UrlPostParmsCheck("ctid")) { int userid = GetPostInt("UserID"); string eid = GetPostString("ctid"); CeErpTradeCell entity = null; if (eid != "") entity = CeErpTradeCell.GetByCtid(eid); if (entity != null) { entity.wechatTag = 0; entity.UpdateTime = DateTime.Now; entity.Update(); CeErpStayGoods pers = CeErpStayGoods.GetByTid(entity.tid); if (pers != null) { pers.status = "取消推购"; pers.audit_type = 3; pers.Update(); } LogHelper.addLog(entity.ctid, userid, "取消:推多推购"); returnSuccessMsg("标记成功!"); return; } returnErrorMsg("找不到记录"); } } /// /// 获取推购列表 /// public void get_erp_staygoods() { DataStruct dStruct = GetPostStruct(); int userId = GetPostInt("UserId"); CeErpUser ceErpUser = CeErpUser.Get(userId); if (ceErpUser == null) { returnErrorMsg("查无该用户"); return; } List lw = new List(); string tid = GetPostString("tid"); if (tid.Length > 0) lw.Add(string.Format("tid like '%{0}%'", tid)); string shopname = GetPostString("shopname"); if (shopname.Length > 0) lw.Add(string.Format("shop_name like '%{0}%'", shopname)); string wangwang = GetPostString("wangwang"); if (wangwang.Length > 0) lw.Add(string.Format("wangwang like '%{0}%'", wangwang)); string customer = GetPostString("customer"); if (customer.Length > 0) lw.Add(string.Format("create_u_name like '%{0}%'", customer)); string returndate1 = GetPostString("returndate1"); string returndate2 = GetPostString("returndate2"); string dw = GetDateMinuteWhere("creata_time", returndate1, returndate2); if (dw.Length > 0) lw.Add(dw); string finishDate1 = GetPostString("finishdate1"); string finishDate2 = GetPostString("finishdate2"); string dw_finish = GetDateMinuteWhere("audit_time", finishDate1, finishDate2); if (dw_finish.Length > 0) lw.Add(dw_finish); string returnvstate = GetPostString("returnvstate"); if (!string.IsNullOrEmpty(returnvstate) && !"null".Equals(returnvstate)) lw.Add(string.Format("audit_type={0}", Convert.ToInt32(returnvstate))); string persuadetype = GetPostString("persuadetype"); if (persuadetype.Length > 0) lw.Add(string.Format("stay_type like '%{0}%'", persuadetype)); string customerOrg = GetPostString("customerOrg"); if (customerOrg.Length > 0) { lw.Add(string.Format("OrgID = {0}", customerOrg)); } if (ceErpUser != null && !string.IsNullOrEmpty(ceErpUser.ManageOrgIds)) { lw.Add(string.Format("OrgId in ({0}) ", ceErpUser.ManageOrgIds)); } dStruct.Order = "creata_time desc"; dStruct.MainWhere = string.Join(" and ", lw.ToArray()); DataTable dt = WebCache.GetData("view_ErpStayGoods", dStruct); ReturnSuccess("{" + string.Format("\"total\":{0},\"data\":{1}", dStruct.TotalCount, Utils.Serialization.JsonString.DataTable2MiniAjaxJson(dt)) + "}"); } /** * 预发货 * 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.UpdateTime = DateTime.Now; 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); 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.UpdateTime = 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 >= 5) { returnErrorMsg(dr["ctid"] + "设计完成订单无法重置"); return; } LogHelper.addLog(dr["ctid"].ToString(), UserID, "售前:订单重置", 0, 1); } } 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.UpdateTime = DateTime.Now; entity.Update(); LogHelper.addLog(ctid, UserID, name + "清除退款状态", 0, 1); } else continue; } returnSuccessMsg("操作成功"); return; } returnErrorMsg("缺少必要的参数ctid"); } /// /// 标识回访 /// public void set_return_visit() { string ctid = GetPostString("ctid"); int UserID = GetPostInt("UserID"); if (!string.IsNullOrEmpty(ctid)) { CeErpTradeCellExtend ceErpTradeCellExtend = CeErpTradeCellExtend.getByTid(ctid); if (ceErpTradeCellExtend == null) { ceErpTradeCellExtend = new CeErpTradeCellExtend(); ceErpTradeCellExtend.ctid = ctid; } ceErpTradeCellExtend.returnVisit = 1; if (ceErpTradeCellExtend.ID == 0) { ceErpTradeCellExtend.Create(); } else { ceErpTradeCellExtend.Update(); } CeErpTradeAfterSaleExtend ceErpTradeAfterSaleExtend = CeErpTradeAfterSaleExtend.getByTid(ctid); if (ceErpTradeAfterSaleExtend != null) { ceErpTradeAfterSaleExtend.TextResult = ""; ceErpTradeAfterSaleExtend.Update(); } LogHelper.addLog(ctid, UserID, "售前添加客户回访信息", 6); returnSuccessMsg("修改成功!"); return; } returnErrorMsg("找不到订单"); } public void up_attachments() { string tid = GetPostString("tid"); int UserID = GetPostInt("UserID"); string atta = GetPostString("atta"); if (!string.IsNullOrEmpty(tid)) { if (string.IsNullOrEmpty(atta)) { returnErrorMsg("文件地址为空"); } CeErpTrade ceErpTrade = CeErpTrade.Get(tid); if (ceErpTrade == null) { returnErrorMsg("找不到订单"); } ceErpTrade.Attachments = atta; ceErpTrade.Update(); LogHelper.addLog(tid, UserID, "上传文件地址", 6); returnSuccessMsg("上传成功!"); return; } returnErrorMsg("找不到订单"); } /** * 顺丰到付\顺丰寄付 * 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 = "顺丰到付"; } ApiVo apiVo = new ApiVo(); apiVo.orderNumber = entity.ctid; apiVo.actionName = "orderRemarks"; apiVo.orderRemarks = entity.seller_memo; designHelper.API_WorkCore(apiVo);//changeDesign/orderRemarks entity.UpdateTime = DateTime.Now; 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.UpdateTime = DateTime.Now; 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.UpdateTime = DateTime.Now; 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.UpdateTime = DateTime.Now; 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.UpdateTime = DateTime.Now; 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, 11, "申请发票", 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.UpdateTime = DateTime.Now; 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.UpdateTime = DateTime.Now; 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.UpdateTime = DateTime.Now; 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(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 callResult = null; try { trade = createTradeOrder(bizOrder, trade, isCreate); List orderList = bizOrder.bizOrderItems; createItemOrder(orderList, trade); List 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(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 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 createCellOrder(List bizOrderSplit, CeErpTrade trade, bool isCreate) { List tempResponses = new List(); 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; entity.UpdateTime = DateTime.Now; 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 { if (!string.IsNullOrEmpty(ceErpTradeCellExtend.spu_id)) { string result = designHelper.API_CheckOrderTo(ceErpTradeCellExtend.ctid, ceErpTradeCellExtend.spu_id, entity.ShopId); ceErpTradeCellExtend.ToType = result; List products = new List() { 13, 2524, 2557, 4, 2554, 57, 19 }; if (products.Contains(entity.ProductId) || entity.seller_memo.IndexOf("手绘") > -1 || entity.seller_memo.IndexOf("电子稿") > -1 || entity.isDianziOrder > 0) { ceErpTradeCellExtend.ToType = "外协"; } if ("外协".Equals(ceErpTradeCellExtend.ToType)) { string sql_pay = "update CE_ErpTradeCell with(rowlock) set DispatchSort=2 where ctid='" + ceErpTradeCellExtend.ctid + "';"; CeErpTradeCell.ExecuteNonQuery(sql_pay.ToString()); } } 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> material_list = new List>(); List> name_list = new List>(); foreach (DataRow dr in goodsDt.Rows) { string sqlMemo = dr["XianhuoMemo"].ToString().Replace(",", ","); List xianhuo = sqlMemo.Split(',').ToList(); foreach (var val in xianhuo) { if (string.IsNullOrEmpty(val)) continue; Dictionary material_map = new Dictionary();//材质 Dictionary name_map = new Dictionary();//特殊名称 if (val.IndexOf('-') > -1) { List 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 materials = new List(); List names = new List(); List result = new List(); for (int i = 0; i < material_list.Count; i++) { Dictionary map = material_list[i]; foreach (var val in map) { if (item.systemRemark.IndexOf(val.Value) > -1) { Dictionary 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_renewOrder(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 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; trade.receiverId = bizOrder.receiverId; 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.IsNew = bizOrder.IsNew; 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(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; } } }