示例#1
0
        /// <summary>
        /// 商品詳情規格參數
        /// </summary>
        /// <param name="detailpara">Dr.</param>
        /// <param name="goods_id">Goods identifier.</param>
        public void GoodDetailPara(string detailpara, int goods_id, int cat_id, Dictionary <string, entity.Attribute> specattr)
        {
            //商品詳情參數
            JArray obj = (JArray)JsonConvert.DeserializeObject(detailpara);

            foreach (JToken d in obj)
            {
                string attributeName = d["attributeName"].ToString();
                if (!specattr.ContainsKey(attributeName))
                {
                    string val = d["value"].ToString();
                    dscapi.dsc.goods.Attribute at = new dscapi.dsc.goods.Attribute();
                    at.setcat_id(cat_id);
                    at.setattr_name(attributeName);
                    at.setattr_cat_type(0);
                    at.setattr_input_type(0);
                    at.setattr_type(0);
                    at.setattr_values("");
                    string  result  = instance.send <string>(at);
                    JObject attrobj = (JObject)JsonConvert.DeserializeObject(result);

                    if (attrobj["result"].ToString() == "success")
                    {
                        GoodsAttr ga = new GoodsAttr();
                        ga.setattr_id(attrobj["id"].ToString());
                        ga.setgoods_id(goods_id);
                        ga.setattr_value(val);
                        ga.setattr_img_flie("");
                        ga.setattr_gallery_flie("");
                        ga.setattr_checked("0");
                        result = instance.send <string>(ga);
                        JObject attrresult = (JObject)JsonConvert.DeserializeObject(result);
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Qus the chong.
        /// </summary>
        /// <returns>The chong.</returns>
        /// <param name="dr">Dr.</param>
        /// <param name="speclist">Speclist.</param>
        /// <param name="goods_id">Goods identifier.</param>
        /// <param name="uploadimg">Uploadimg.</param>
        public JArray QuChong(string skumodelstr, string specinfo, Dictionary <string, entity.Attribute> speclist, int goods_id, Dictionary <string, JObject> uploadimg)
        {
            Stream s      = null;
            string result = "";
            Image  img    = new Image();

            img.setid(goods_id);
            List <string> goods_attr = new List <string>();

            //规格匹配包括价格,第二次使用该字段数据
            //解析规格对应图片

            JObject obj = (JObject)JsonConvert.DeserializeObject(skumodelstr);

            if (obj != null)
            {
                JToken jt       = obj["skuList"];
                object oo       = JsonConvert.DeserializeObject(specinfo);
                JArray spinfosm = (JArray)oo;
                if (oo != null)
                {
                    //合并相同属性值
                    Dictionary <string, string> qucongspec = new Dictionary <string, string>();

                    foreach (JToken ssm in spinfosm)
                    {
                        foreach (JToken d in ssm["attributes"].Children())
                        {
                            string attributeValue = d["attributeValue"].ToString();
                            string skuImageUrl    = d["skuImageUrl"].ToString();
                            if (!qucongspec.ContainsKey(attributeValue))
                            {
                                qucongspec.Add(attributeValue, skuImageUrl);
                            }
                        }
                    }

                    //获取属性值所属ID
                    Dictionary <string, string[]> newval = new Dictionary <string, string[]>();
                    int setchecked = 0;
                    foreach (KeyValuePair <string, string> jj in qucongspec)
                    {
                        foreach (KeyValuePair <string, entity.Attribute> sl in speclist)
                        {
                            entity.Attribute attr = sl.Value;
                            //和现有规格比较是否已存在
                            List <string> speval = new List <string>(attr.attr_values.Split(new string[] { "\r\n" }, StringSplitOptions.None));
                            //判断图片是否已在图片相册中,有则获取现有相册中图片地址,没有则上传图片获取返回图片地址

                            if (speval.Contains(jj.Key) && jj.Value.Trim() != "")
                            {
                                GoodsAttr ga = new GoodsAttr();
                                ga.setattr_id(attr.attr_id.ToString());
                                ga.setgoods_id(goods_id);
                                ga.setattr_value(jj.Key);

                                string goods_thumb = "";
                                string goods_img   = "";
                                if (uploadimg.ContainsKey(jj.Value))
                                {
                                    JObject oop = uploadimg[jj.Value];
                                    goods_thumb = oop["data"]["goods_thumb"].ToString();
                                    goods_img   = oop["data"]["goods_img"].ToString();
                                }
                                else
                                {
                                    using (HttpClientClass hc = new HttpClientClass())
                                    {
                                        s = hc.htmlimg(alistr + jj.Value);
                                    }
                                    result = instance.sendimg <string>(new UploadParameterType {
                                        UploadStream = s, FileNameValue = "goudiw.jpg"
                                    }, img);
                                    JObject oop = (JObject)JsonConvert.DeserializeObject(result);
                                    goods_thumb = oop["data"]["goods_thumb"].ToString();
                                    goods_img   = oop["data"]["goods_img"].ToString();
                                }
                                ga.setattr_img_flie(goods_thumb);
                                ga.setattr_gallery_flie(goods_img);
                                if (sl.Key == "颜色" && setchecked == 0)
                                {
                                    ga.setattr_checked("1");
                                    setchecked = 1;
                                }
                                else
                                {
                                    ga.setattr_checked("0");
                                }

                                result = instance.send <string>(ga);
                                JObject attrresult = (JObject)JsonConvert.DeserializeObject(result);
                                if (attrresult["result"].ToString() == "success")
                                {
                                    checkattr(ref spinfosm, jt, jj.Key, attrresult["id"].ToString());
                                }
                            }
                            else if (speval.Contains(jj.Key))
                            {
                                GoodsAttr ga = new GoodsAttr();
                                ga.setattr_id(attr.attr_id.ToString());
                                ga.setgoods_id(goods_id);
                                ga.setattr_value(jj.Key);
                                ga.setattr_img_flie("");
                                ga.setattr_gallery_flie("");
                                if (sl.Key == "颜色" && setchecked == 0)
                                {
                                    ga.setattr_checked("1");
                                    setchecked = 1;
                                }
                                else
                                {
                                    ga.setattr_checked("0");
                                }
                                result = instance.send <string>(ga);
                                JObject attrresult = (JObject)JsonConvert.DeserializeObject(result);
                                if (attrresult["result"].ToString() == "success")
                                {
                                    checkattr(ref spinfosm, jt, jj.Key, attrresult["id"].ToString());
                                }
                            }
                        }
                    }
                }
                return(spinfosm);
            }
            else
            {
                return(null);
            }
        }