Beispiel #1
0
        /// <summary>
        /// 提交退款的记录
        /// </summary>
        /// <param name="orderList"></param>
        /// <param name="itemList"></param>
        public void SendRejectData(List <Order> orderList, List <OrderItem> itemList, List <Order> orderRejectList, List <OrderItem> itemRejectList)
        {
            int     k        = 0;
            decimal sumPrice = 0;
            int     sumCount = 0;

            foreach (Order order in orderRejectList)
            {
                if (order.Remark1 == "")
                {
                    continue;
                }
                string orderIDOLD = order.Remark1.Split('流')[0];; //原单号: S001170330171356  流水号: 164;
                orderIDOLD = orderIDOLD.Split(':')[1];
                orderIDOLD = orderIDOLD.Trim();

                Order oldOrder = GetRejectOrder(orderIDOLD);
                if (oldOrder == null)
                {
                    continue;
                }

                WebReference.sales sales = new WebReference.sales();

                WebReference.postsalescreaterequest request = new WebReference.postsalescreaterequest();

                #region header;          //标头
                requestheader header = new requestheader();
                header.lang        = ""; //语言
                header.pageno      = 0;  //页数
                header.pagerecords = 0;  //每页记录数
                header.updatecount = 0;  //每次更新记录数

                header.licensekey  = licensekey;
                header.password    = password;
                header.username    = username;
                header.messageid   = "332";       //固定值:332
                header.messagetype = "SALESDATA"; //固定值:SALESDATA
                header.version     = "V332M";     //固定值:
                request.header     = header;
                #endregion

                sumPrice += order.TtlPrice1;

                #region 销售开单主表
                saleshdr salestotal = new saleshdr();
                // 销售开单主表
                #region 可以为空
                //salestotal.buyerremark = "";//卖家备注 允许为空
                //salestotal.coupongroup = "";//优惠券组 允许为空
                //salestotal.couponnumber = "";//优惠券号码 允许为空
                //salestotal.couponqty = "";//优惠券数量 允许为空
                //salestotal.coupontype = "";//优惠券类型 允许为空
                //salestotal.demographiccode = "";//顾客统计代码 允许为空
                //salestotal.demographicdata = "";//顾客统计值 允许为空
                //salestotal.ecorderno = "";//网购订单号 允许为空
                //salestotal.extendparam = "";//扩展参数 允许为空
                //salestotal.invoicecontent = "";//发票内容 允许为空
                //salestotal.invoicetitle = "";//发票抬头 允许为空
                //salestotal.orderremark = "";//交易备注 允许为空
                //salestotal.shoptaxgroup = "";//店铺税组 允许为空
                //salestotal.vipcode = ""; //VIP 卡号 允许为空
                //salestotal.status = "";//状态 允许为空 保留
                //10:新增/ 20:付款/30:付款取消
                ///40:订单取消
                //在【销售开单查询】中用于显示
                //salestotal.totaldiscount = "";//整单折扣信息 允许为空
                //salestotal.ttltaxamount1 = "";//总税额1   允许为空
                //salestotal.ttltaxamount2 = "";//总税额2   允许为空
                //salestotal.priceincludetax = "";//售价是否含税 允许为空
                //salestotal.reservedocno = "";//销售预留库存单号 允许为空
                //salestotal.salesman = "";//销售员 允许为空
                salestotal.orgtxdocno   = orderIDOLD; //原销售单号  允许为空 长度:30
                salestotal.orgstorecode = storeCode;  //原交易店铺号 允许为空 退货时,原交易店铺号 如果是按单退货,提供此店铺号
                salestotal.orgtillid    = "01";       // 原收银机号 允许为空 退货时,原收银机号  如果是按单退货,提供此收银机号
                //专柜原销售单号
                //如果提供了【原销售单号】,Web
                //服务系统判断此单号【是否存
                //在】或者【是否已经退货】,如
                //果【不存在】或者【已退货】,
                //Web 服务系统返回错误信息
                //salestotal.localstorecode = "";//本地店铺号 允许为空
                salestotal.originalamount     = oldOrder.TtlPrice1;                                     //原始金额 允许为空 decimal { 4 }
                salestotal.orgtxdate_yyyymmdd = DateTime.Parse(oldOrder.OptTime1).ToString("yyyyMMdd"); //原交易日期 允许为空 长度:8
                //固定格式:YYYYMMDD
                //退货时,原交易日期
                //如果是按单退货,提供此日期
                #endregion
                salestotal.changeamount       = 0;                                                               //找零金额 允许为空 需给零值
                salestotal.cashier            = order.OptNo1;                                                    //收银员编号 否
                salestotal.issueby            = order.PortNo1;                                                   //创建人 否
                salestotal.issuedate_yyyymmdd = DateTime.Parse(order.OptTime1).ToString("yyyyMMdd");             //"20170408";//创建日期 否 长度:8
                salestotal.txdate_yyyymmdd    = DateTime.Parse(order.OptTime1).ToString("yyyyMMdd");             // 交易日期 固定格式:YYYYMMDD 否
                salestotal.issuetime_hhmmss   = DateTime.Parse(order.OptTime1).ToString("HHmmss");               // "140601";//创建时间 否 长度:6
                salestotal.txtime_hhmmss      = DateTime.Parse(order.OptTime1).ToString("HHmmss");               // "140601";//交易时间 否 固定格式:HHMMSS
                salestotal.mallid             = mallid;                                                          //商场编号 长度:4 商场提供固定值 否
                salestotal.mallitemcode       = "";                                                              //RMS 货号 否  长度:30  Web 服务系统校验货号是否有效
                salestotal.netamount          = -order.TtlPrice1;                                                // 销售净金额 decimal { 4 }  否
                salestotal.netqty             = itemList.Where(n => n.ExchNo == order.ExchNo1).ToList().Count(); //净数量 否 销售总数量 decimal { 4 }
                salestotal.paidamount         = -order.CashPayed1;                                               //付款金额 否
                salestotal.salestype          = "SR";                                                            // 单据类型 否 SA:店内销售 SR:店内退货/取消交易
                //长度:2
                //销售总金额为正数时,销售类型
                //为 SA;销售总金额为负数时,销
                //单类型为 SR;销售总结 SZ 单据
                //类型是为每日销售总结时发送
                //核对整日销售交易总金额的
                salestotal.sellingamount = -order.TtlPrice1; //销售金额 否 decimal { 4 }
                salestotal.storecode     = storeCode;        //店铺号 否
                salestotal.tillid        = "01";             //收银机号 可用 01 或者 02 表示
                //如果专柜只有一台收银机就用
                //01 表示,如果有两台则第二台用
                //02 表示,依次类推
                //Web 服务系统需要校验该收银机
                //编号的有效性
                salestotal.ttpossalesdocno = "";            //
                salestotal.txdocno         = order.ExchNo1; //销售单号 否 长度:30 专柜销售单号

                request.salestotal = salestotal;
                #endregion

                int qtys = 0;
                #region 销售开单明细表
                //销售开单明细表
                // request.salesitems;
                List <OrderItem> items = itemRejectList.Where(n => n.ExchNo == order.ExchNo1).ToList();
                int         leng       = items.Count();
                salesitem[] salesitems = new salesitem[leng];
                for (int i = 0; i < items.Count; i++)
                {
                    OrderItem it   = items[i];
                    salesitem item = new salesitem();
                    it.ItemNo = itemcode;// "A000011";
                    #region 允许为空
                    //item.bonusearn = 0;// 获得积分 允许为空
                    //item.colorcode = "";// 商品颜色 允许为空
                    //item.coupongroup = "";//优惠券组 允许为空
                    //item.couponnumber = "";//优惠劵号码 允许为空
                    //item.coupontype = "";//优惠劵类型 允许为空
                    //item.exstk2sales = 1;//库存销售比例 允许为空 需给 1 值
                    //item.extendparam = "";//扩展参数 允许为空
                    //item.invttype = "1";//库存类型 允许为空 0:坏货退回/1:好货退回
                    //默认为 1
                    //主要用于店内退货,在 PDA 店内
                    //退货时选择库存类型,单品后台
                    //系统根据库存类型进行控制是
                    //否增加库存
                    //item.isdeposit = "";//是否定金单  允许为空
                    //item.iswholesale = "";//是否批发 允许为空
                    //item.priceapprove = "";//允许改价 允许为空
                    //item.pricemode = "";//价格模式  允许为空
                    //item.promotion = "";//商品促销信息 允许为空
                    //item.tax = "";//商品税信息 允许为空
                    //item.sellingprice = 0;//售价 允许为空 需给零值
                    //item.serialnum = "";// 序列号 允许为空
                    //item.sizecode = "";//商品尺码 允许为空
                    //item.totaldiscountless = 0;//整单折扣差额 需给零值 允许为空
                    //item.totaldiscountless1 = 0;//整单折扣差额 1 需给零值 允许为空
                    //item.totaldiscountless2 = 0;//整单折扣差额 2 需给零值 允许为空
                    //item.vipdiscountless = 0;//VIP 折扣差额  需给零值 允许为空
                    //item.vipdiscountpercent = 0;//VIP 折扣率 需给零值    允许为空
                    //item.refundreasoncode = "";//退货原因  允许为空
                    //item.salesitemremark = "";// 交易明细备注  允许为空
                    //item.itemdiscount = "";//单品折扣信息 允许为空
                    //item.itemlotnum = "";// 商品批次 允许为空
                    //item.originalprice = 0;//原始售价  允许为空 需给零值
                    #endregion
                    item.iscounteritemcode = "1";                      //是否专柜货号 否 默认为 1 长度:1
                    item.lineno            = int.Parse(order.ExchID1); //行号 否
                    item.mallitemcode      = it.ItemNo;                //货号 否
                    item.plucode           = it.ItemNo;                //商品内部编号 否 同 itemcode
                    item.counteritemcode   = it.ItemNo;                // 专柜货号 否 如果不区分【专柜货号】与【商品编号】二者赋予相同值
                    item.itemcode          = it.ItemNo;                //商品编号 否 Web 服务系统校验货号是否有效同 mallitemcode ,counteritemcode
                    item.netamount         = -it.Price;                // 销售净金额 decimal { 4 }  否
                    item.qty       = it.Qty;                           //数量 否 decimal { 4 }
                    item.storecode = storeCode;                        //店铺号 否
                    salesitems[i]  = item;
                    qtys          += it.Qty;
                }
                sumCount += qtys;
                #endregion
                request.salesitems = salesitems;
                #region 销售开单付款明细表
                //销售开单付款明细表
                //request.salestenders;
                WebReference.salestender salestender = new WebReference.salestender();
                salestender.baseamount = -order.TtlPrice1;//本位币金额  否 同 payamount
                //salestender.excessamount = ""; //超额金额 可以为空
                //salestender.extendparam = "";//扩展参数 可以为空
                //salestender.tendertype = "";//付款类型 可以为空
                salestender.lineno    = int.Parse(order.ExchID1); //行号 否
                salestender.payamount = -order.TtlPrice1;         //付款金额 否
                //salestender.remark = "";//备注 可以为空
                //salestender.tendercategory = "";//付款种类 可以为空
                salestender.tendercode = "CH";//付款代码 否 长度:2
                //CH----现金
                //CI----国内银行卡
                //CO----国外银行卡
                //OT-----其他付款方式。
                //接口数据应在 TenderCode 付款
                //方式中填写对应方式付款实际
                //金额,无对应付款方式时在其他
                //付款方式字段填写剩余付款方
                //式金额的合计;若交易类型为 SZ
                //可以默认为 OT
                //Web 服务系统需要校验付款方式
                //编号有效性
                request.salestenders = new WebReference.salestender[] { salestender };
                #endregion

                #region 销售开单配送表
                //销售开单配送表 允许为空
                // request.salesdlvy
                request.salesdlvy = new salesdelivery();
                #endregion

                //返回码(<responsecode>short</responsecode>)为【0】,表示调用 Web Service 成功。
                //交易被完整接纳。
                //返回码(<responsecode>short</responsecode>)为非【0】,表示调用 Web Service 不
                //成功。软件开发商收到此返回信息清除重传交易队列销售资料。
                //其他返回码表示不成功,不成功信息从( <responsemessage>string</responsemessage> )获取。
                //软件开发商收到其他返回码请将未成功传送的交易放入重传交易队列。

                WebReference.postsalescreateresponse response = sales.postsalescreate(request);
                short  resposeCode     = response.header.responsecode;
                string responseMessage = response.header.responsemessage;
                if (resposeCode == 0)
                {
                    //调用成功
                    responseMessage = "同步成功";
                }
                else
                {
                    responseMessage = "错误码:" + resposeCode + ";错误信息:" + responseMessage;
                    //调用失败
                }
                k++;
                this.Dispatcher.BeginInvoke(new Action(
                                                () =>
                {
                    btnDataSync.Content  = "正在同步数据第(" + (k) + "/" + (orderList.Count + orderRejectList.Count) + ")";
                    this.RejectText.Text = "同步退款总金额:" + String.Format("{0:N2}", -sumPrice) + ";总数量:" + sumCount;

                    logs.Items.Add(new { NID = k, ExchNo1 = order.ExchNo1 + "(原始单号:" + orderIDOLD + ")", TtlPrice1 = String.Format("{0:N2}", -order.TtlPrice1), qtys = qtys, responseMessage = responseMessage });
                }));
            }
            this.Dispatcher.BeginInvoke(new Action(
                                            () =>
            {
                this.btnDataSync.Content = "开始同步";
                btnDataSync.IsEnabled    = true;
                MessageBox.Show("同步完成");
                //MessageBox.Show("同步总金额:" + String.Format("{0:N2}", sumPrice) + ";总数量:" + sumCount);
            }));
        }
Beispiel #2
0
        public void Send(object sender, EventArgs e)
        {
            dispatcherTimer.Stop();

            requestheader header = new requestheader();

            header.licensekey  = ConfigurationManager.AppSettings["licensekey"].ToString();
            header.username    = ConfigurationManager.AppSettings["username"].ToString();
            header.password    = ConfigurationManager.AppSettings["password"].ToString();
            header.lang        = "中文";
            header.pagerecords = 1;
            header.pageno      = 1;
            header.updatecount = 1;
            header.messagetype = "SALESDATA";
            header.messageid   = "332";
            header.version     = "V332M";

            StringBuilder sb = new StringBuilder();

            DataTable payflow = Obtain("select t_rm_payflow.pay_way,sell_way,com_no,t_rm_payflow.flow_no,t_rm_payflow.sale_man,t_rm_payflow.vip_no,t_rm_payflow.pay_amount  from  t_rm_payflow where pay_way !='CHG' and com_no > " + ConfigurationManager.AppSettings["com_no"]);

            if (payflow == null)
            {
                dispatcherTimer.Start();

                return;
            }
            //去重
            for (int i = payflow.Rows.Count - 2; i > 0; i--)
            {
                DataRow[] rows = payflow.Select(string.Format("{0}='{1}'", "flow_no", payflow.Rows[i]["flow_no"]));
                if (rows.Length > 1)
                {
                    payflow.Rows.RemoveAt(i);
                }
            }
            //一次获取付款表的销售单号 并把当前最大的标识列取出保存
            foreach (DataRow item in payflow.Rows)
            {
                sb.Append(item["flow_no"] + ",");
            }
            //截掉最后一个逗号
            string strS = "";

            sb.Append(ConfigurationManager.AppSettings["error"]);
            if (sb.Length > 0)
            {
                strS = sb.ToString().Remove(sb.ToString().LastIndexOf(","), 1);
            }
            else
            {
                dispatcherTimer.Start();

                return;
            }
            //查询流水表 用来赋值
            DataTable saleflow = Obtain("select posid, flow_no,sell_way, CASE a.sell_way WHEN 'B' THEN -sale_qnty ELSE sale_qnty END sale_qnty, CONVERT(varchar(100), oper_date, 112) as oper_day,REPLACE(CONVERT(varchar(100),oper_date, 8),':','') as oper_time,oper_id,"
                                        + "CASE a.sell_way WHEN 'B' THEN - sale_qnty ELSE sale_qnty END sale_qnty,"
                                        + "CASE A.sell_way WHEN 'B' THEN - sale_money ELSE sale_money END sale_money,"
                                        + "item_no,(source_price - sale_price) * sale_qnty as salequt,"
                                        + "(select sum(CASE sell_way WHEN 'B' THEN - sale_money ELSE sale_money END) from t_rm_saleflow where flow_no in (a.flow_no)) as sale_moneyCount,"
                                        + "(select sum(CASE sell_way WHEN 'B' THEN - sale_qnty ELSE sale_qnty END) from t_rm_saleflow where flow_no in (a.flow_no)) as sale_qntyCount"
                                        + " FROM t_rm_saleflow  a"
                                        + " WHERE flow_no  in (" + strS + ") ");

            if (saleflow == null)
            {
                dispatcherTimer.Start();

                return;
            }

            List <SalesModel> list = new List <SalesModel>();

            list = ConvertToModel(saleflow);

            foreach (DataRow payRow in payflow.Rows)
            {
                string  oper_id         = "";
                string  oper_day        = "";
                string  oper_time       = "";
                string  posid           = "";
                decimal sale_moneyCount = 0;
                decimal sale_qnty       = 0;
                decimal sale_money      = 0;

                string            sell_way       = "";
                decimal           sale_qntyCount = 0;
                decimal           salequt        = 0;
                ArrayOfEsalesitem item           = new ArrayOfEsalesitem();

                foreach (DataRow saleRow in saleflow.Rows)
                {
                    if (payRow["flow_no"].ToString() == saleRow["flow_no"].ToString() && saleRow["sell_way"].ToString() != "C")
                    {
                        oper_id         = saleRow["oper_id"].ToString();
                        oper_day        = saleRow["oper_day"].ToString();
                        oper_time       = saleRow["oper_time"].ToString();
                        posid           = saleRow["posid"].ToString();
                        sale_moneyCount = Convert.ToDecimal(saleRow["sale_moneyCount"]);
                        sale_qnty       = Convert.ToDecimal(saleRow["sale_qnty"]);
                        sale_money      = Convert.ToDecimal(saleRow["sale_money"]);
                        sell_way        = saleRow["sell_way"].ToString();
                        sale_qntyCount  = Convert.ToInt32(saleRow["sale_qntyCount"]);
                        salequt         = Convert.ToDecimal(saleRow["salequt"]);

                        esalesitem items = new esalesitem();                                                     //销售单货品明细表 多
                        items.itemcode        = ConfigurationManager.AppSettings["storecode"].ToString() + "1";; //"01L501N011";货号
                        items.lineno          = Convert.ToInt32(ConfigurationManager.AppSettings["lineno"]) + 1;
                        items.bonusearn       = 0;
                        items.discountamount  = salequt;
                        items.extendparam     = "";
                        items.salesitemremark = "";

                        //数量
                        items.qty = sale_qnty;
                        //单货品金额
                        items.netamount = sale_money;

                        using (var fs = new FileStream(DateTime.Now.ToString("yyyyMMdd") + "DetailData.txt", FileMode.Append))
                            using (StreamWriter streamWriter = new StreamWriter(fs))
                            {
                                streamWriter.Write("\r\n");//换行

                                streamWriter.Write("行号:" + items.lineno + ",商品编号:" + items.itemcode + ",数量:" + items.qty + ",折扣金额:" + items.discountamount + ",净金额:" + items.netamount + ",积分:" + items.bonusearn + ",销售单号:" + payRow["flow_no"].ToString());
                                streamWriter.Write("\r\n");
                                streamWriter.Write("\r\n"); //换行
                                                            //关闭此文件
                            }
                        Configuration lineno = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                        lineno.AppSettings.Settings["lineno"].Value = items.lineno.ToString();
                        lineno.Save();
                        ConfigurationManager.RefreshSection("appSettings");

                        item.Add(items);
                    }
                }
                //销售
                esaleshdr sales = new esaleshdr();

                sales.mallid          = ConfigurationManager.AppSettings["mallid"];//商场编号
                sales.txdate_yyyymmdd = oper_day;

                sales.txtime_hhmmss = oper_time;
                sales.storecode     = ConfigurationManager.AppSettings["storecode"].ToString();
                if (posid.ToString() == "")
                {
                    sales.tillid = "01";//?
                }
                else
                {
                    sales.tillid = posid;                      //?
                }
                sales.txdocno  = payRow["flow_no"].ToString(); //单号
                sales.cashier  = oper_id;
                sales.vipcode  = payRow["vip_no"].ToString();
                sales.salesman = payRow["sale_man"].ToString();
                string flow_no = payRow["flow_no"].ToString();

                ArrayOfEsalestender enderList = new ArrayOfEsalestender();
                //付款信息
                esalestender esals = new esalestender();
                esals.lineno     = Convert.ToInt32(ConfigurationManager.AppSettings["lineno1"]) + 1;
                esals.tendercode = "CH";
                //支付金额
                esals.payamount  = sale_moneyCount;
                esals.baseamount = sale_moneyCount;


                esals.excessamount = 0;
                esals.extendparam  = "";
                esals.remark       = "";
                enderList.Add(esals);
                Configuration lineno1 = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                lineno1.AppSettings.Settings["lineno1"].Value = esals.lineno.ToString();
                lineno1.Save();
                decimal qty = 0;

                //净数量
                sales.netqty = sale_qntyCount;
                //销售总额
                sales.netamount = sale_moneyCount;

                sales.extendparam = "";

                postesalescreaterequest postsale = new postesalescreaterequest();
                postsale.header        = header;
                postsale.esalesitems   = item;
                postsale.esalestenders = enderList;
                postsale.esalestotal   = sales;

                postesalescreateRequest1Body body = new postesalescreateRequest1Body();
                body.astr_request = postsale;

                postesalescreateRequest1 request = new postesalescreateRequest1();
                request.Body = body;

                //string endpointConfigurationName = GetEndpointAddress("salesSoap");
                string          remoteAddress = ConfigurationManager.AppSettings["address"].ToString();
                salesSoapClient salesCreate   = new salesSoapClient("salesSoap", remoteAddress);

                try
                {
                    postesalescreateresponse respone = new postesalescreateresponse();
                    respone = salesCreate.postesalescreate(postsale);

                    //返回码
                    short code = respone.header.responsecode;
                    //错误信息
                    string str = respone.header.responsemessage;

                    if (code == 0 || code == 1000)
                    {
                        int num = 0;

                        foreach (DataRow payfRows in payflow.Rows)
                        {
                            if (Convert.ToInt32(payfRows["com_no"]) > num)
                            {
                                num = Convert.ToInt32(payfRows["com_no"]);
                            }
                            Configuration com_no = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
                            com_no.AppSettings.Settings["com_no"].Value = num.ToString();
                            com_no.Save();
                        }
                    }

                    //保存日志
                    Save(DateTime.Now.ToString("yyyyMMdd") + "Log.txt", code.ToString(), str, flow_no);
                    using (var fs = new FileStream(DateTime.Now.ToString("yyyyMMdd") + "Data.txt", FileMode.Append))
                        using (StreamWriter streamWriter = new StreamWriter(fs))
                        {
                            streamWriter.Write("\r\n");//换行

                            streamWriter.Write("商场编号:" + sales.mallid + "   交易日期:" + sales.txdate_yyyymmdd + "   交易时间:" + sales.txtime_hhmmss + "   店铺号:" + sales.storecode + "   收银机号:" + sales.tillid + "   销售单号:" + sales.txdocno + "   收银员编号:" + sales.cashier + "   VIP卡号:" + sales.vipcode + "   销售员:" + sales.salesman + "   付款金额:" + sale_moneyCount + "   货号:" + ConfigurationManager.AppSettings["storecode"].ToString() + "1" + "   数量:" + sale_qntyCount + "   折扣金额:0");
                            streamWriter.Write("\r\n");
                            streamWriter.Write("\r\n");//换行

                            //关闭此文件
                        }
                }
                catch (Exception ex)
                {
                    //判断是否是网络问题 是休息一分钟后继续执行
                    if (ex.ToString().Contains("没有终结点在侦听可以接受消息"))
                    {
                        Thread.Sleep(60000);//一分钟
                        Send(sender, e);
                    }
                    throw ex;
                }
                item.Clear();
                oper_id         = "";
                oper_day        = "";
                oper_time       = "";
                posid           = "";
                sale_moneyCount = 0;
                sale_qnty       = 0;
                sale_money      = 0;

                sell_way       = "";
                sale_qntyCount = 0;
                salequt        = 0;
            }
            Infomation(sender, e);

            dispatcherTimer.Start();
        }