Exemplo n.º 1
0
        private static string GetRemark(DataRow row)
        {
            StringBuilder sbuilder = new StringBuilder();
            var           mjly     = row["买家留言"];
            int           index    = 0;

            if (!mjly.IsEmptyObject())
            {
                sbuilder.Append(TaobaoDataHelper.ReplaceHtmlText(string.Format("【买家留言:{0}】", mjly)));
                index++;
            }

            mjly = row["卖家留言"];
            if (!mjly.IsEmptyObject())
            {
                sbuilder.Append(TaobaoDataHelper.ReplaceHtmlText(string.Format("【卖家留言:{0}】", mjly)));
            }
            return(sbuilder.ToString());
        }
Exemplo n.º 2
0
        private static void BuildBillDataFromTable(string suser, bool onlyAdd, DataTable table, HashObjectList billList, HashObjectList detailList, DbHelper db = null, string ids = null, bool sureRate = true)
        {
            Dictionary <string, string> dic = GetExistBills(db, ids);
            List <string>        dicDetail  = GetExistBillDetails(db, ids);
            JavaScriptSerializer serializer = JavaScriptSerializer.CreateInstance();

            foreach (DataRow row in table.Rows)
            {
                var    ddid = row["订单ID"].ToString();
                string id   = Cuid.NewCuid().GetHashCode().ToString();
                string oldid;
                if (dic.TryGetValue(ddid, out oldid))
                {
                    if (onlyAdd)
                    {
                        continue;
                    }
                    id = oldid;
                }
                string user = row["所属用户"].ToString();
                if (user != suser)
                {
                    throw new Exception("分析用户和数据保存用户不匹配,无法做数据保存");
                }
                object sendDate    = row["发货时间"];
                object successDate = row["成交时间"];

                Dictionary <string, decimal> goodsRate = GetGoodsRate(db, user);
                GoodsInfo[] ginfos = serializer.Deserialize <GoodsInfo[]>(row["货物信息"].ToString());

                var     sendWay  = TaobaoDataHelper.GetLogisticsInfo(row["快递公司"]).IsEmptyObject() ? null : "快递";
                string  remark   = GetRemark(row);
                decimal pall     = Decimal.Parse(row["拍下总金额"].ToString());
                decimal total    = Decimal.Parse(row["支付金额"].ToString());
                decimal ltotal   = 0;
                decimal btotal   = 0;
                decimal allPrice = 0;

                string address = TaobaoDataHelper.ReplaceHtmlText(row["具体地址"].ToString());
                if (!dicDetail.Contains(ddid))
                {
                    for (int j = ginfos.Length - 1; j >= 0; j--)
                    {
                        GoodsInfo ginfo   = ginfos[j];
                        string    goodKey = GetGoodsKey(ginfo.Color, ginfo.Size, ginfo.Title);
                        decimal   rate    = 0;
                        if (db != null && (goodsRate == null || !goodsRate.ContainsKey(goodKey)))
                        {
                            if (!sureRate)
                            {
                                rate = 0;
                            }
                            else
                            {
                                throw new Exception(string.Format("【{3}】   color:{0} size:{1} title:{2}没有设置比例goodMatchRate", ginfo.Color, ginfo.Size, ginfo.Title, user));
                            }
                        }
                        else
                        {
                            if (db != null)
                            {
                                rate = goodsRate[goodKey];
                            }
                        }
                        decimal price = ginfo.PriceInfo / pall * total;
                        if (j == 0)
                        {
                            price = total - allPrice;
                        }
                        allPrice += price;
                        decimal tbtotal = (price * rate) * (decimal)(0.01);
                        btotal += tbtotal;
                        decimal    tltotal    = price - tbtotal;
                        HashObject detailHash = new HashObject();
                        detailList.Add(detailHash);
                        detailHash.Add("id", Cuid.NewCuid().GetHashCode());
                        detailHash.Add("bid", id);
                        detailHash.Add("code", ddid);
                        detailHash.Add("size", ginfo.Size);
                        detailHash.Add("amount", ginfo.Amount);
                        detailHash.Add("color", ginfo.Color);
                        detailHash.Add("address", address);
                        detailHash.Add("area", row["区域"]);
                        detailHash.Add("total", price);
                        detailHash.Add("remark", remark);
                        detailHash.Add("ltotal", tltotal);
                        detailHash.Add("sourceTitle", ginfo.Title);
                        detailHash.Add("goodsstatus", int.Parse(row["发货状态status"].ToString()) >= 1 ? 2 : 1);
                        detailHash.Add("sendway", sendWay);
                        detailHash.Add("btotal", tbtotal);
                    }
                    ltotal = total - btotal;
                }

                if (IsNullDate(row["付款时间"]))
                {
                    continue;
                }

                HashObject billHash = new HashObject();
                billHash.Add("id", id);
                billHash.Add("date", row["付款时间"]);
                billHash.Add("taobaocode", row["旺旺名称"]);
                billHash.Add("cname", row["收货客户"]);
                billHash.Add("ctel", row["联系电话"]);
                billHash.Add("caddress", address);
                billHash.Add("carea", row["区域"]);
                billHash.Add("cremark", remark);
                billHash.Add("ltotal", ltotal);
                billHash.Add("status", row["发货状态status"]);
                billHash.Add("scode", TaobaoDataHelper.GetLogisticsInfo(row["物流单号"]));
                billHash.Add("sname", TaobaoDataHelper.GetLogisticsInfo(row["快递公司"]));
                billHash.Add("uid", GetUser(row["所属用户"], db == null));
                billHash.Add("goodsstatus", 1);
                billHash.Add("billfrom", "抓取");
                billHash.Add("createdate", row["创建时间"]);
                billHash.Add("zfbpaycode", row["支付宝交易号"]);
                billHash.Add("tbcode", ddid);
                billHash.Add("total", total);
                billHash.Add("btotal", btotal);
                billHash.Add("senddate", GetDate(sendDate));
                billHash.Add("successdate", GetDate(successDate));
                billList.Add(billHash);
            }
        }