Пример #1
0
        public string UpToGY(int ID)
        {
            using (TransactionScope sc = new TransactionScope())
            {
                string shibai = "0";
                var    aa     = "";
                try
                {
                    Dictionary <string, string> dic = new Dictionary <string, string>();
                    T_WDTHandOrder ordermodel       = db.T_WDTHandOrder.SingleOrDefault(a => a.ID == ID && a.Isdelete == 0);
                    string         tid = ordermodel.OrderID;
                    //int trade_status = 10;
                    //int pay_status = 2;
                    //int delivery_term = 1;
                    DateTime trade_time    = DateTime.Parse(ordermodel.SingleShotTime.ToString());
                    DateTime pay_time      = DateTime.Parse(ordermodel.SingleShotTime.ToString());
                    string   buyer_nick    = ordermodel.MemberName;
                    string   receiver_name = ordermodel.DeliveryName;

                    string ShopName          = ordermodel.shopName;
                    string receiver_province = ordermodel.ProvinceAddress;
                    string receiver_city     = ordermodel.CityAddress;
                    string receiver_district = ordermodel.AreaAddress;
                    string receiver_address  = ordermodel.address;
                    string receiver_mobile   = ordermodel.DeliveryNumber;
                    // decimal post_amount = decimal.Parse(ordermodel.PostAmount.ToString());
                    // int logistics_type = -1;
                    string  seller_memo = ordermodel.Remarks;
                    decimal paid        = decimal.Parse(ordermodel.Cost.ToString());

                    List <T_WDTHandOrderDetail> orderItems = db.T_WDTHandOrderDetail.Where(a => a.PorderID == tid).ToList();
                    string order_list = "";
                    for (int i = 0; i < orderItems.Count; i++)
                    {
                        decimal num       = decimal.Parse(orderItems[i].num.ToString());
                        decimal UnitPrice = decimal.Parse(orderItems[i].UnitPrice.ToString());
                        string  goods_no  = orderItems[i].ProductCode;
                        string  spec_no   = orderItems[i].ProductCode;
                        //    string Guid = System.Guid.NewGuid().ToString();
                        T_WDTGoods cofig      = db.T_WDTGoods.SingleOrDefault(s => s.goods_no == goods_no);
                        string     goods_name = "";
                        if (cofig != null)
                        {
                            goods_name = cofig.goods_name;
                        }
                        if (order_list == "")
                        {
                            order_list += "{" +
                                          "\"oid\": \"" + tid + "\"," +
                                          "\"num\": \"" + num + "\"," +
                                          "\"price\": \"" + UnitPrice + "\"," +
                                          "\"status\": \"40\"," +
                                          "\"refund_status\": \"0\"," +
                                          "\"adjust_amount\": \"0\"," +
                                          "\"discount\": \"0\"," +
                                          "\"share_discount\": \"0\"," +
                                          "\"goods_id\": \"" + goods_no + "\"," +
                                          "\"goods_no\": \"" + goods_no + "\"," +
                                          "\"spec_no\": \"" + goods_no + "\"," +
                                          "\"goods_name\": \"" + goods_name + "\"," +
                                          "\"cid\": \"\"" +
                                          "}";
                        }
                        else
                        {
                            order_list += ",{" +
                                          "\"oid\": \"" + tid + "\"," +
                                          "\"num\": \"" + num + "\"," +
                                          "\"price\": \"" + UnitPrice + "\"," +
                                          "\"status\": \"40\"," +
                                          "\"refund_status\": \"0\"," +
                                          "\"adjust_amount\": \"0\"," +
                                          "\"discount\": \"0\"," +
                                          "\"share_discount\": \"0\"," +
                                          "\"goods_id\": \"" + goods_no + "\"," +
                                          "\"goods_no\": \"" + goods_no + "\"," +
                                          "\"spec_no\": \"" + goods_no + "\"," +
                                          "\"goods_name\": \"" + goods_name + "\"," +
                                          "\"cid\": \"\"" +
                                          "}";
                        }
                    }
                    //旺店通
                    T_WDTshop queryData = db.T_WDTshop.SingleOrDefault(a => a.shop_name == ShopName);
                    if (queryData != null)
                    {
                        string Code = queryData.shop_no;
                        dic.Add("shop_no", Code);
                    }
                    else
                    {
                        return("0");
                    }



                    string cmd = "[{" +
                                 "\"tid\": \"" + tid + "\"," +
                                 "\"trade_status\": \"30\"," +
                                 "\"pay_status\": \"2\"," +
                                 "\"delivery_term\": \"1\"," +
                                 "\"trade_time\": \"" + trade_time + "\"," +
                                 "\"pay_time\": \"" + pay_time + "\"," +
                                 "\"buyer_nick\": \"" + buyer_nick + "\"," +
                                 "\"buyer_email\": \"\"," +
                                 "\"receiver_name\": \"" + receiver_name + "\"," +
                                 "\"receiver_province\": \"" + receiver_province + "\"," +
                                 "\"receiver_city\": \"" + receiver_city + "\"," +
                                 "\"receiver_district\": \"" + receiver_district + "\"," +
                                 "\"receiver_address\": \"" + receiver_address + "\"," +
                                 "\"receiver_mobile\": \"" + receiver_mobile + "\"," +
                                 "\"receiver_zip\": \"\"," +
                                 "\"logistics_type\": \"8\"," +
                                 "\"buyer_message\": \"\"," +
                                 "\"seller_memo\": \"" + seller_memo + "\"," +
                                 "\"post_amount\": \"0\"," +
                                 "\"cod_amount\": \"0\"," +
                                 "\"ext_cod_fee\": \"0\"," +
                                 "\"paid\": \"" + paid + "\"," +
                                 "\"order_list\": [" + order_list + "]}]";
                    dic.Remove("trade_list");
                    dic.Remove("sid");
                    dic.Remove("appkey");
                    dic.Remove("timestamp");
                    dic.Add("trade_list", cmd);
                    dic.Add("sid", "hhs2");
                    dic.Add("appkey", "hhs2-ot");
                    dic.Add("timestamp", GetTimeStamp());
                    aa = CreateParam(dic, true);

                    string ret = Post("http://api.wangdian.cn/openapi2/trade_push.php", aa);


                    JsonData jsonData = null;
                    jsonData = JsonMapper.ToObject(ret);
                    string sd = jsonData[0].ToString();
                    if (sd == "0")
                    {
                        int sdz = int.Parse(jsonData[2].ToString());
                        sc.Complete();
                        if (sdz > 0)
                        {
                            return("1");
                        }
                    }
                    return("0");
                }
                catch (Exception ex)
                {
                    return("0");
                }
            }
        }
Пример #2
0
        public JsonResult ShopTb()
        {
            int page_no = 0;
            int c       = 0;
            int s       = 0;

            App_Code.GY gy = new App_Code.GY();
            //List<T_WDTshop> delMod = db.T_WDTshop.AsQueryable().ToList();
            //foreach (var item in delMod)
            //{
            //    db.T_WDTshop.Remove(item);
            //}
            //db.SaveChanges();
            do
            {
                dic.Clear();
                dic.Add("mine", "0");
                dic.Add("sid", "hhs2");
                dic.Add("appkey", "hhs2-ot");
                dic.Add("timestamp", GetTimeStamp());
                dic.Add("page_no", page_no.ToString());//页号
                var      cmd      = CreateParam(dic, true);
                string   ret      = gy.DoPostnew("http://api.wangdian.cn/openapi2/shop.php", cmd, Encoding.UTF8);
                string   ssx      = Regex.Unescape(ret);
                JsonData jsonData = null;
                jsonData = JsonMapper.ToObject(ret);
                string iscode = jsonData["code"].ToString();
                if (iscode != "0")
                {
                    return(Json("", JsonRequestBehavior.AllowGet));
                }
                JsonData jsontrades = jsonData["shoplist"];
                c = jsontrades.Count;


                for (int i = 0; i < jsontrades.Count; i++)
                {
                    string    shopno = jsontrades[i]["shop_no"].ToString();
                    T_WDTshop model  = db.T_WDTshop.FirstOrDefault(a => a.shop_no == shopno);
                    if (model == null)
                    {
                        T_WDTshop WDTshop = new T_WDTshop();
                        WDTshop.platform_id     = jsontrades[i]["platform_id"].ToString();
                        WDTshop.sub_platform_id = jsontrades[i]["sub_platform_id"].ToString();
                        WDTshop.shop_id         = jsontrades[i]["shop_id"].ToString();
                        WDTshop.shop_no         = jsontrades[i]["shop_no"].ToString();
                        WDTshop.shop_name       = jsontrades[i]["shop_name"].ToString();
                        WDTshop.account_id      = jsontrades[i]["account_id"].ToString();
                        WDTshop.account_nick    = jsontrades[i]["account_nick"].ToString();
                        WDTshop.province        = jsontrades[i]["province"].ToString();
                        WDTshop.city            = jsontrades[i]["city"].ToString();
                        WDTshop.district        = jsontrades[i]["district"].ToString();
                        WDTshop.address         = jsontrades[i]["address"].ToString();
                        WDTshop.contact         = jsontrades[i]["contact"].ToString();
                        WDTshop.zip             = jsontrades[i]["zip"].ToString();
                        WDTshop.mobile          = jsontrades[i]["mobile"].ToString();
                        WDTshop.telno           = jsontrades[i]["telno"].ToString();
                        db.T_WDTshop.Add(WDTshop);
                        s += db.SaveChanges();
                    }
                }
                page_no++;
            } while (c != 0);
            if (s > 0)
            {
                return(Json(new { State = "Success" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { State = "Faile" }, JsonRequestBehavior.AllowGet));
        }