예제 #1
0
        public JsonResult vdian_shop_cate_add(string id)
        {
            Class  c      = ClassService.instance().Single(new Guid(id));
            string result = WSApi.vdian_shop_cate_add(WSApiJson.vdian_shop_cate_add(GetToken(), c));
            string msg    = Utils.GetJsonValue(result, "status_reason");

            if (msg == "success")
            {
                string catesJson = WSApi.vdian_shop_cate_get(GetToken());
                catesJson = JsonHelper.GetJsonValue(catesJson, "result");
                List <cates_result> list  = JsonHelper.DeserializeJsonToList <cates_result>(catesJson);
                cates_result        cate_ = list.Find(m => m.cate_name == c.Title);
                if (cate_ != null)
                {
                    c.cate_id = cate_.cate_id;
                    ClassService.instance().Update(c);
                }
            }
            return(Json(msg, JsonRequestBehavior.AllowGet));
        }
예제 #2
0
        public JsonResult Product_Async(string id)
        {
            Hashtable      hash  = new Hashtable();
            Guid           ID    = new Guid(id);
            List <Product> plist = ProductService.instance().GetProductByCid(ID).ToList();

            foreach (var p in plist)
            {
                if (string.IsNullOrEmpty(p.itemid))
                {
                    product_item entity = new product_item();
                    entity.item_name = Utils.DropHTML(p.Description);
                    entity.price     = p.Attr.First().price.Price.ToString();
                    entity.stock     = p.Attr.First().price.Stock.ToString();
                    entity.imgs      = new List <string>();
                    entity.cate_ids  = new List <string>()
                    {
                        ClassService.instance().Single(p.ClassID).cate_id
                    };
                    entity.skus          = new List <skus>();
                    entity.merchant_code = "";
                    foreach (var item in FilesService.instance().GetFilesByRelationID(p.ID))
                    {
                        string reulst_msg = WSApi.upload(GetToken(), item.FilePath);
                        if (Utils.GetJsonValue(reulst_msg, "status_code") == "0")
                        {
                            string imgurl = Utils.GetJsonValue(reulst_msg, "result");
                            if (imgurl.Split('?').Length > 0)
                            {
                                entity.imgs.Add(imgurl.Split('?')[0]);
                            }
                            else
                            {
                                entity.imgs.Add(imgurl);
                            }
                        }
                    }
                    foreach (var item in Product_AttService.GetAttsByPID(ID))
                    {
                        entity.skus.Add(new skus()
                        {
                            price             = item.price.Price.ToString(),
                            sku_merchant_code = "",
                            stock             = item.price.Stock.ToString(),
                            title             = item.key.Name + ":" + item.val.Value
                        });
                    }
                    ;
                    string json        = WSApiJson.vdian_item_add(entity);
                    string msg         = WSApi.vdian_item_add(GetToken(), json);
                    string status_code = Utils.GetJsonValue(msg, "status_code");
                    if (status_code == "0")
                    {
                        p.itemid = Utils.GetJsonValue(msg, "itemid");
                        p.opt    = "1";
                        ProductService.instance().Update(p);
                    }
                    else
                    {
                        hash[p.Title] = Utils.GetJsonValue(msg, "status_reason");
                    }
                }
            }
            return(Json(hash, JsonRequestBehavior.AllowGet));
        }
예제 #3
0
        public JsonResult Product(FormCollection form)
        {
            ResultBase_form result = new ResultBase_form();
            Guid            ID     = new Guid(form["ID"]);
            Product         p      = ProductService.instance().Single(ID);

            if (!string.IsNullOrEmpty(p.itemid))
            {
                string del_msg = WSApi.vdian_item_delete(GetToken(), p.itemid);
                if (Utils.GetJsonValue(del_msg, "status_code") != "0")
                {
                    result.msg = Utils.GetJsonValue(del_msg, "status_reason");
                    return(Json(result, JsonRequestBehavior.AllowGet));
                }
            }
            product_item entity = new product_item();

            entity.item_name = form["Description"];
            entity.price     = form["Price"];
            entity.stock     = form["Stock"];
            entity.imgs      = new List <string>();
            entity.cate_ids  = new List <string>()
            {
                form["cate_ids"]
            };
            entity.skus          = new List <skus>();
            entity.merchant_code = "";
            foreach (var item in FilesService.instance().GetFilesByRelationID(ID))
            {
                string reulst_msg = WSApi.upload(GetToken(), item.FilePath);
                if (Utils.GetJsonValue(reulst_msg, "status_code") == "0")
                {
                    string imgurl = Utils.GetJsonValue(reulst_msg, "result");
                    if (imgurl.Split('?').Length > 0)
                    {
                        entity.imgs.Add(imgurl.Split('?')[0]);
                    }
                    else
                    {
                        entity.imgs.Add(imgurl);
                    }
                }
            }
            foreach (var item in Product_AttService.GetAttsByPID(ID))
            {
                entity.skus.Add(new skus()
                {
                    price             = item.price.Price.ToString(),
                    sku_merchant_code = "",
                    stock             = item.price.Stock.ToString(),
                    title             = item.key.Name + ":" + item.val.Value
                });
            }
            ;
            string json = WSApiJson.vdian_item_add(entity);
            string msg  = WSApi.vdian_item_add(GetToken(), json);

            result.status = Convert.ToInt32(Utils.GetJsonValue(msg, "status_code"));
            if (result.status == 0)
            {
                p.itemid = Utils.GetJsonValue(msg, "itemid");
                p.opt    = "1";
                ProductService.instance().Update(p);
            }
            result.msg       = result.status == 0 ? "操作成功" : "操作失败";
            result.ResultURL = "/WeShop/Product/" + p.ID;
            return(Json(result, JsonRequestBehavior.AllowGet));
        }