示例#1
0
        public ActionResult FetchProductWithCostPriceByPid(string pid, string activityId)
        {
            var product = new ProductModel();

            using (var client = new ProductClient())
            {
                var sku = client.FetchProduct(pid);
                sku.ThrowIfException(true);
                if (sku.Success && sku.Result != null)
                {
                    product.PID           = pid;
                    product.OnSale        = sku.Result.Onsale;
                    product.Stockout      = sku.Result.Stockout;
                    product.DisplayName   = sku.Result.DisplayName;
                    product.Image         = sku.Result.Image;
                    product.cy_list_price = sku.Result.Price;
                }
            };
            //var product = QiangGouManager.FetchProductByPID(pid);

            if (!string.IsNullOrEmpty(product.PID) && product.PID != pid)
            {
                product.CaseSensitive = true;
            }
            if (!string.IsNullOrEmpty(activityId))
            {
                var saleoutqty = QiangGouManager.SelectFlashSaleSaleOutQuantity(activityId, pid);
                product.TotalQuantity   = saleoutqty;
                product.SaleOutQuantity = saleoutqty ?? 0;
            }
            var costPriceModel = QiangGouManager.SelectcostPriceSql(pid).FirstOrDefault();

            if (costPriceModel != null)
            {
                product.CostPrice = costPriceModel.CostPrice;
            }
            product = QiangGouManager.AssemblyProductInstalService(product);
            return(Json(product, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        private ActionResult CheckExcelData(IEnumerable <QiangGouImportModel> data, string aid)
        {
            int excelRow = 1;
            List <QiangGouProductModel> products   = new List <QiangGouProductModel>();
            List <string> errorMessage             = new List <string>();
            Dictionary <string, string> installPay = new Dictionary <string, string>()
            {
                { "不限", "" }, { "在线支付", "PayOnline" }, { "到店安装", "InstallAtShop" }, { "在线支付且到店安装", "PayOnlineAndInstallAtShop" }
            };
            Dictionary <string, bool> isUseCode = new Dictionary <string, bool>()
            {
                { "使用", true }, { "不使用", false }
            };

            Dictionary <string, bool> isyes = new Dictionary <string, bool>()
            {
                { "是", true }, { "否", false }
            };
            Dictionary <string, string> channels = new Dictionary <string, string> {
                { "全部", "all" }, { "仅网站", "pc" }, { "仅APP", "app" }
            };
            List <string> tags = new List <string>()
            {
                "无", "热卖", "秒杀", "限量"
            };

            foreach (var model in data)
            {
                excelRow++;
                StringBuilder sb = new StringBuilder();
                #region PID
                if (string.IsNullOrWhiteSpace(model.PID))
                {
                    sb.Append("PID为空_");
                }
                #endregion

                #region 排序
                int postion = 0;
                if (!string.IsNullOrWhiteSpace(model.排序) && !int.TryParse(model.排序, out postion))
                {
                    sb.Append("排序不合法_");
                }
                #endregion

                #region 促销价
                decimal activityPrice = 0;
                if (!string.IsNullOrWhiteSpace(model.促销价) && !decimal.TryParse(model.促销价, out activityPrice))
                {
                    sb.Append("促销价不合法_");
                }
                #endregion

                #region 伪原价
                decimal falsePrice = 0;
                if (!string.IsNullOrWhiteSpace(model.伪原价) && !decimal.TryParse(model.伪原价, out falsePrice))
                {
                    sb.Append("伪原价不合法_");
                }
                #endregion

                #region 每人限购
                int max = 0;
                if (!string.IsNullOrWhiteSpace(model.每人限购) && !int.TryParse(model.每人限购, out max))
                {
                    sb.Append("每人限购不合法_");
                }
                #endregion

                #region 总限购
                int total = 0;
                if (!string.IsNullOrWhiteSpace(model.总限购) && !int.TryParse(model.总限购, out total))
                {
                    sb.Append("总限购不合法_");
                }
                //int total = 0;
                //var saleoutQty = 0;
                //if (!string.IsNullOrEmpty(model.PID))
                // saleoutQty = QiangGouManager.SelectFlashSaleSaleOutQuantity(aid, model.PID)??0;
                //if (!string.IsNullOrWhiteSpace(model.总限购) && !int.TryParse(model.总限购, out total))
                //    sb.Append("总限购不合法_");
                //else if(!string.IsNullOrWhiteSpace(model.总限购)&&saleoutQty > Convert.ToInt32(model.总限购))
                //{
                //    sb.Append("总限购数量小于已经售出数量请调整_");
                //}
                #endregion

                #region 安装和支付方式
                if (string.IsNullOrWhiteSpace(model.安装和支付方式))
                {
                    model.安装和支付方式 = "不限";
                }
                if (!installPay.ContainsKey(model.安装和支付方式))
                {
                    sb.Append("安装和支付方式不合法_");
                }
                #endregion

                #region 优惠券
                if (string.IsNullOrWhiteSpace(model.优惠券))
                {
                    model.优惠券 = "使用";
                }
                if (!isUseCode.ContainsKey(model.优惠券))
                {
                    sb.Append("优惠券不合法_");
                }
                #endregion

                #region  道
                if (string.IsNullOrWhiteSpace(model.道))
                {
                    model.道 = "全部";
                }
                if (!channels.ContainsKey(model.道))
                {
                    sb.Append("渠道不合法_");
                }
                #endregion

                #region 是否加入会长限购
                if (string.IsNullOrWhiteSpace(model.是否加入会场限购))
                {
                    model.是否加入会场限购 = "否";
                }
                if (!isyes.ContainsKey(model.是否加入会场限购))
                {
                    sb.Append("是否加入会场限购不合法_");
                }
                #endregion

                #region 标签
                if (string.IsNullOrWhiteSpace(model.标签))
                {
                    model.标签 = "无";
                }
                if (!tags.Contains(model.标签))
                {
                    sb.Append("标签不合法_");
                }
                #endregion

                #region 显示
                if (string.IsNullOrWhiteSpace(model.显示))
                {
                    model.显示 = "是";
                }
                if (!isyes.ContainsKey(model.显示))
                {
                    sb.Append("显示不合法_");
                }
                #endregion
                var error = sb.ToString();
                if (!string.IsNullOrWhiteSpace(error))
                {
                    errorMessage.Add("第" + excelRow + "行:" + error);
                }
                else
                {
                    var productModel = new QiangGouProductModel()
                    {
                        PID                = model.PID,
                        Position           = postion,
                        ProductName        = model.称,
                        Price              = activityPrice,
                        FalseOriginalPrice = falsePrice,
                        MaxQuantity        = max,
                        TotalQuantity      = total,
                        InstallAndPay      = installPay[model.安装和支付方式],
                        IsUsePCode         = isUseCode[model.优惠券],
                        Channel            = channels[model.道],
                        IsJoinPlace        = isyes[model.是否加入会场限购],
                        Label              = model.标签,
                        IsShow             = isyes[model.显示]
                    };
                    var assembalModel = QiangGouManager.AssemblyProductInstalService(productModel);
                    products.Add(assembalModel);
                }
            }
            return(Content(JsonConvert.SerializeObject(new { data = products, error = errorMessage, code = 1 })));
        }