Beispiel #1
0
 public List<ProductCombo> groupNumQuery(ProductCombo query)
 {
     
     try
     {
         return _combDao.groupNumQuery(query);
     }
     catch (Exception ex)
     {
         throw new Exception("ProductComboMgr-->groupNumQuery-->" + ex.Message, ex);
     }
 }
Beispiel #2
0
 public string Save(ProductCombo combo)
 {
     return _combDao.Save(combo);
 }
 public List<ProductComboMap> ComboItemQuery(ProductCombo query)
 {
     return _ProductItemMapDao.ComboItemQuery(query);
 }
Beispiel #4
0
        public void PrepareData(List<CombinationExcel> source)
        {
            if (source != null)
            {
                source.ForEach(m => m.Validate());
                var parents = source.Where(m => m.combination.Trim() != "299" && string.IsNullOrEmpty(m.msg));

                _productMgr = new ProductMgr(strConn);
                _productItemMgr = new ProductItemMgr(strConn);
                _vendorMgr = new VendorMgr(strConn);
                _vendorBrandMgr = new VendorBrandMgr(strConn);
                _siteMgr = new SiteMgr(strConn);
                _productMigrationMgr = new ProductMigrationMgr(strConn);
                _productComboMgr = new ProductComboMgr(strConn);
                _cateMgr = new ProductCategoryMgr(strConn);
                _productCategorySetMgr = new ProductCategorySetMgr(strConn);
                _productNoticeSetMgr = new ProductNoticeSetMgr(strConn);
                _productTagSetMgr = new ProductTagSetMgr(strConn);
                _productPictureMgr = new ProductPictureMgr(strConn);
                _productStatusHistoryMgr = new ProductStatusHistoryMgr(strConn);

                foreach (var parent in parents)
                {
                    form.change(1);
                    uint product_id = uint.Parse(parent.product_id);
                    #region Product

                    ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = parent.is_exist.ToUpper().Trim().Equals("OLD") ? parent.product_id : parent.temp_id });
                    if (prodMigra != null)
                    {
                        parent.msg = "此記錄暫時編號(temp_id)已經存在;";
                        continue;
                    }

                    Product newPro = parent.is_exist.ToUpper().Trim() == "OLD" ? _productMgr.Query(new Product { Product_Id = product_id }).FirstOrDefault() : new Product();
                    if (newPro == null)
                    {
                        parent.msg = "商品不存在";
                        continue;
                    }
                    newPro.Product_Name = parent.product_name.Trim();
                    VendorBrand brand = _vendorBrandMgr.GetProductBrand(new VendorBrand { Brand_Name = parent.brand_name.Trim() });
                    if (brand == null)
                    {
                        parent.msg = "品牌不存在";
                        continue;
                    }
                    newPro.Brand_Id = brand.Brand_Id;
                    switch (parent.combination.Trim())
                    {
                        case "2":
                            newPro.Combination = 2; break;
                        case "3":
                            newPro.Combination = 3; break;
                        case "4":
                            newPro.Combination = 4; break;
                        default: break;
                    }
                    switch (parent.status.Trim().ToUpper())
                    {
                        case "SAME":
                            break;
                        case "ON":
                            newPro.Product_Status = 5; break;
                        case "OFF":
                            newPro.Product_Status = 6; break;
                        case "NEW":
                            newPro.Product_Status = 0; break;
                        default:
                            break;
                    }
                    newPro.Price_type = 1;
                    newPro.Product_Spec = 0;
                    newPro.Spec_Title_1 = string.Empty;
                    newPro.Spec_Title_2 = string.Empty;
                    newPro.Ignore_Stock = 0;// parent.ignore_stock.ToUpper().Trim() == "Y" ? 1 : 0;
                    newPro.Shortage = 0;// parent.shortage.ToUpper().Trim() == "Y" ? 1 : 0;
                    newPro.Cate_Id = parent.cate_id.Trim();
                    var vendor = _vendorMgr.GetSingle(new Vendor { vendor_id = brand.Vendor_Id });
                    if (vendor == null)
                    {
                        parent.msg = "供應商不存在";
                        continue;
                    }
                    newPro.user_id = vendor.product_manage;
                    if (!string.IsNullOrEmpty(parent.service_fee))
                    { 
                        uint bag_check_money=0;
                        uint.TryParse(parent.service_fee,out bag_check_money);
                        newPro.Bag_Check_Money = bag_check_money;
                    }
                    #endregion

                    bool result = true;
                    ArrayList sqls = new ArrayList();
                    #region PriceMaster

                    Site site = _siteMgr.Query(new Site { Site_Name = parent.site.Trim() }).FirstOrDefault();
                    if (site == null)
                    {
                        parent.msg = "價格檔站臺不存在";
                        result = false;
                        break;
                    }
                    List<PriceMaster> priceMasters = new List<PriceMaster>();
                    //首先默認加入一筆吉甲地站臺
                    PriceMaster newPriceMaster = new PriceMaster { site_id = 1, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                    newPriceMaster.product_name = newPro.Product_Name;
                    newPriceMaster.price_status = 1;

                    var item = _productItemMgr.Query(new ProductItem { Product_Id = newPro.Product_Id }).FirstOrDefault();
                    if (item == null)
                    {
                        parent.msg = "商品細項不存在";
                        continue;
                    }
                    #region 成本

                    int cost = 0;
                    if (!string.IsNullOrEmpty(parent.cost))
                    {
                        int.TryParse(parent.cost, out cost);
                    }
                    else
                    {
                        cost = Convert.ToInt32(item.Item_Cost);
                    }
                    newPriceMaster.cost = cost;
                    #endregion

                    #region 售價

                    int price = 0;
                    if (!string.IsNullOrEmpty(parent.price))
                    {
                        int.TryParse(parent.price, out price);
                    }
                    else
                    {
                        price = Convert.ToInt32(item.Item_Money);
                    }
                    newPriceMaster.price = price;
                    #endregion

                    newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                    newPriceMaster.event_start = item.Event_Product_Start;
                    newPriceMaster.event_end = item.Event_Product_End;
                    priceMasters.Add(newPriceMaster);

                    if (site.Site_Id != 1)
                    {
                        //如果站臺不是吉甲地就把吉甲地站臺的價格狀態改為4(下架)
                        priceMasters[0].price_status = 4;
                        //再加入非吉甲地站臺
                        newPriceMaster = new PriceMaster { site_id = site.Site_Id, user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                        newPriceMaster.product_name = newPro.Product_Name;
                        newPriceMaster.price_status = 1;
                        #region 成本

                        cost = 0;
                        if (!string.IsNullOrEmpty(parent.cost))
                        {
                            int.TryParse(parent.cost, out cost);
                        }
                        else
                        {
                            cost = Convert.ToInt32(item.Item_Cost);
                        }
                        newPriceMaster.cost = cost;
                        #endregion

                        #region 售價

                        price = 0;
                        if (!string.IsNullOrEmpty(parent.price))
                        {
                            int.TryParse(parent.price, out price);
                        }
                        else
                        {
                            price = Convert.ToInt32(item.Item_Money);
                        }
                        newPriceMaster.price = price;
                        #endregion
                        newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                        newPriceMaster.event_start = item.Event_Product_Start;
                        newPriceMaster.event_end = item.Event_Product_End;
                        priceMasters.Add(newPriceMaster);
                    }

                    #region 其他站臺價格

                    var child = source.Where(m =>
                                    m.combination.Trim() == "299"
                                    && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim()
                                    && string.IsNullOrEmpty(m.msg)
                                    && m.new_old.ToUpper().Trim() == "NEW"
                                    && m.formula.ToUpper().Trim().StartsWith("P"));
                    if (child != null)
                    {
                        foreach (var c in child)
                        {
                            item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault();
                            if (item == null)
                            {
                                c.msg = "價格檔商品細項不存在";
                                result = false;
                                break;
                            }
                            site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault();
                            if (site == null)
                            {
                                c.msg = "站臺不存在";
                                result = false;
                                break;
                            }
                            if (priceMasters.Exists(m => m.site_id == site.Site_Id))
                            {
                                c.msg = "站臺重複";
                                result = false;
                                break;
                            }
                            newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                            newPriceMaster.product_name = c.product_name.Trim();
                            newPriceMaster.site_id = site.Site_Id;
                            newPriceMaster.price_status = 1;
                            #region 成本

                            cost = 0;
                            if (!string.IsNullOrEmpty(c.cost))
                            {
                                int.TryParse(c.cost, out cost);
                            }
                            else
                            {
                                cost = Convert.ToInt32(item.Item_Cost);
                            }
                            newPriceMaster.cost = cost;
                            #endregion

                            #region 售價

                            price = 0;
                            if (!string.IsNullOrEmpty(c.price))
                            {
                                int.TryParse(c.price, out price);
                            }
                            else
                            {
                                price = Convert.ToInt32(item.Item_Money);
                            }
                            newPriceMaster.price = price;
                            #endregion
                            newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                            newPriceMaster.event_start = item.Event_Product_Start;
                            newPriceMaster.event_end = item.Event_Product_End;
                            priceMasters.Add(newPriceMaster);

                            if (site.Site_Name.Trim().ToLower() == "chinatrust")
                            {
                                ArrayList category_set = CategorySet(c, brand.Brand_Id);
                                if (category_set == null)
                                {
                                    result = false;
                                    break;
                                }
                                else
                                {
                                    sqls.AddRange(category_set);
                                }
                            }
                        }
                        if (!result) continue;
                    }
                    #endregion

                    #endregion

                    #region ProductCombo

                    string[] strIds = parent.formula.IndexOf(",") != -1 ? parent.formula.Trim().Split(',') : new string[] { parent.formula.Trim() };
                    string[] nums = parent.number.IndexOf(",") != -1 ? parent.number.Trim().Split(',') : new string[] { parent.number.Trim() };

                    List<Product> children = new List<Product>();
                    ProductCombo tmp;
                    for (int i = 0; i < strIds.Length; i++)
                    {
                        tmp = new ProductCombo();
                        if (parent.combination.Trim() != "2")
                        {
                            tmp.Buy_Limit = parent.buylimit.Trim().ToUpper() == "Y" ? 1 : 0;
                        }
                        else
                        {
                            tmp.S_Must_Buy = int.Parse(i >= nums.Length ? nums[nums.Length - 1] : nums[i]);
                        }
                        if (parent.combination.Trim() == "3")//為3任選時 數量為G_Must_Buy
                        {
                            tmp.G_Must_Buy = int.Parse(nums[0]);
                        }
                        switch (parent.new_old.Trim().ToUpper())
                        {
                            case "NEW":
                                var map = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] });
                                if (map == null)
                                {
                                    parent.msg = "原料編號未找到對應";
                                    break;
                                }
                                tmp.Child_Id = Convert.ToInt32(map.product_id);
                                break;
                            case "OLD":
                                tmp.Child_Id = int.Parse(strIds[i]);
                                break;
                            case "BOTH":
                                if (strIds[i].ToUpper().Trim().StartsWith("P"))
                                {
                                    var tMap = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = strIds[i] });
                                    if (tMap == null)
                                    {
                                        parent.msg = "原料編號未找到對應";
                                        break;
                                    }
                                    tmp.Child_Id = Convert.ToInt32(tMap.product_id);
                                }
                                else
                                {
                                    tmp.Child_Id = int.Parse(strIds[i]);
                                }
                                break;
                        }
                        if (tmp.Child_Id == 0)
                        {
                            result = false;
                            break;
                        }
                        else
                        {
                            Product tmpPro = _productMgr.Query(new Product { Product_Id = Convert.ToUInt32(tmp.Child_Id) }).FirstOrDefault();
                            if (tmpPro == null)
                            {
                                parent.msg = strIds[i] + "不存在";
                                result = false;
                                break;
                            }
                            if (tmpPro.Product_Status == 0 || tmpPro.Product_Status ==1)
                            {
                                parent.msg = strIds[i] + "商品状态不為新增、申請審核";
                                result = false;
                                break;
                            }
                            if (tmpPro.Combination != 0 && tmpPro.Combination != 1)
                            {
                                parent.msg = strIds[i] + "不是單一商品";
                                result = false;
                                break;
                            }
                            switch (newPro.Product_Freight_Set)
                            {
                                case 1:
                                case 3:
                                    if (tmpPro.Product_Freight_Set != 1 && tmpPro.Product_Freight_Set != 3) 
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                case 2:
                                case 4:
                                    if (tmpPro.Product_Freight_Set != 2 && tmpPro.Product_Freight_Set != 4)
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                case 5:
                                case 6:
                                    if (tmpPro.Product_Freight_Set != 5 && tmpPro.Product_Freight_Set != 6)
                                    {
                                        parent.msg = strIds[i] + "运费模式与主商品不匹配";
                                        result = false;
                                    }
                                    break;
                                default:
                                    break;
                            }
                            if (!result) break;
                            children.Add(tmpPro);
                        }
                        sqls.Add(_productComboMgr.Save(tmp));
                    }
                    if (!result) continue;
                    #endregion

                    #region product_category_set
                    if (!string.IsNullOrEmpty(parent.display))
                    {
                        ArrayList category_set = CategorySet(parent, brand.Brand_Id);
                        if (category_set == null)
                            continue;
                        else
                        {
                            foreach (var set in category_set)
                            {
                                if (!sqls.Contains(set))
                                {
                                    sqls.Add(set);
                                }
                            }
                        }
                    }
                    else
                    {
                        sqls.Add(_productCategorySetMgr.SaveFromOtherPro(new ProductCategorySet { Product_Id = product_id }));
                    }
                    #endregion

                    #region product_migration_map

                    ProductMigrationMap pMap = new ProductMigrationMap();
                    if (parent.is_exist.ToUpper().Equals("OLD"))
                    {
                        pMap.temp_id = parent.product_id;
                    }
                    else if (parent.is_exist.ToUpper().Equals("NEW"))
                    {
                        pMap.temp_id = parent.temp_id;
                    }
                    sqls.Add(_productMigrationMgr.SaveNoPrid(pMap));

                    #endregion

                    #region notice tag picture

                    sqls.Add(_productNoticeSetMgr.SaveFromOtherPro(new ProductNoticeSet { product_id = product_id }));
                    sqls.Add(_productTagSetMgr.SaveFromOtherPro(new ProductTagSet { product_id = product_id }));
                    sqls.Add(_productPictureMgr.SaveFromOtherPro(new ProductPicture { product_id = Convert.ToInt32(product_id) }));
                    sqls.Add(_productStatusHistoryMgr.SaveNoProductId(new ProductStatusHistory { type = 7, product_status = Convert.ToInt32(newPro.Product_Status) }));
                    #endregion

                    string str = string.Empty;
                    if (_productMgr.ProductMigration(newPro, priceMasters, null, null, sqls, null))
                    {
                        str = "匯入成功";
                    }
                    else
                    {
                        str = "保存至數據庫失敗";
                    }
                    parent.msg = str;
                    source.FindAll(m =>
                                    m.combination.Trim() == "299"
                                    && m.formula.ToUpper().Trim() == parent.temp_id.ToUpper().Trim()
                                    && string.IsNullOrEmpty(m.msg)
                                    && m.new_old.ToUpper().Trim() == "NEW"
                                    && m.formula.ToUpper().Trim().StartsWith("P")).ForEach(m => m.msg = str);
                }

                #region 其他站臺價格

                var pChild = source.Where(m => m.combination.Trim() == "299" && m.new_old.ToUpper().Trim() == "OLD" && string.IsNullOrEmpty(m.msg));
                if (pChild != null)
                {
                    ProductItem item;
                    PriceMaster newPriceMaster;
                    Site site;
                    _priceMasterMgr = new PriceMasterMgr(strConn);
                    foreach (var c in pChild)
                    {
                        ProductMigrationMap prodMigra = _productMigrationMgr.GetSingle(new ProductMigrationMap { temp_id = c.formula.Trim() });
                        if (prodMigra == null)
                        {
                            c.msg = "原料編號對照不存在";
                            continue;
                        }
                        item = _productItemMgr.Query(new ProductItem { Product_Id = uint.Parse(c.product_id) }).FirstOrDefault();
                        if (item == null)
                        {
                            c.msg = "價格檔商品細項不存在";
                            continue;
                        }
                        site = _siteMgr.Query(new Site { Site_Name = c.site.Trim() }).FirstOrDefault();
                        if (site == null)
                        {
                            c.msg = "站臺不存在";
                            continue;
                        }
                        newPriceMaster = new PriceMaster { user_level = 1, same_price = 1, accumulated_bonus = 1, default_bonus_percent = 1, bonus_percent = 1 };
                        newPriceMaster.product_name = c.product_name.Trim();
                        newPriceMaster.product_id = prodMigra.product_id;
                        newPriceMaster.child_id = Convert.ToInt32(prodMigra.product_id);
                        newPriceMaster.site_id = site.Site_Id;
                        newPriceMaster.price_status = 1;
                        #region 成本

                        int cost = 0;
                        if (!string.IsNullOrEmpty(c.cost))
                        {
                            int.TryParse(c.cost, out cost);
                        }
                        else
                        {
                            cost = Convert.ToInt32(item.Item_Cost);
                        }
                        newPriceMaster.cost = cost;
                        #endregion

                        #region 售價

                        int price = 0;
                        if (!string.IsNullOrEmpty(c.price))
                        {
                            int.TryParse(c.price, out price);
                        }
                        else
                        {
                            price = Convert.ToInt32(item.Item_Money);
                        }
                        newPriceMaster.price = price;
                        #endregion
                        newPriceMaster.event_price = Convert.ToInt32(item.Event_Item_Money);
                        newPriceMaster.event_start = item.Event_Product_Start;
                        newPriceMaster.event_end = item.Event_Product_End;

                        ArrayList category_set = new ArrayList();
                        if (site.Site_Name.Trim().ToLower() == "chinatrust")
                        {
                            Product pro= _productMgr.Query(new Product { Product_Id = item.Product_Id }).FirstOrDefault();
                            if (pro == null)
                            {
                                c.msg = "商品不存在";
                                continue;
                            }
                            #region 更新該站臺商品的 product_category_set
                            
                            bool result = true;
                            System.Text.RegularExpressions.Regex regx = new System.Text.RegularExpressions.Regex("^[0-9]*$");
                            string[] cateArray = c.display.Split(',');
                            foreach (string strcate in cateArray)
                            {
                                if (!string.IsNullOrEmpty(strcate))
                                {
                                    if (regx.IsMatch(strcate))
                                    {
                                        ProductCategory query = _cateMgr.QueryAll(new ProductCategory { category_id = uint.Parse(strcate) }).FirstOrDefault();
                                        if (query == null || strcate.Equals("0"))
                                        {
                                            c.msg = "display:" + strcate + " 不存在;";
                                            result = false;
                                            break;
                                        }
                                        else
                                        {
                                            ProductCategorySet category = new ProductCategorySet { Brand_Id = pro.Brand_Id, Category_Id = uint.Parse(strcate), Product_Id = prodMigra.product_id };
                                            if (_productCategorySetMgr.Query(category).FirstOrDefault() == null)
                                            {
                                                category_set.Add(_productCategorySetMgr.Save(category));
                                            }
                                            else
                                            {
                                                c.msg = "display:" + strcate + " 已存在;";
                                                result = false;
                                                break;
                                            }
                                        }
                                    }
                                    else
                                    {
                                        c.msg = "display:" + strcate + " 格式不正確 ";
                                        result = false;
                                        break;
                                    }
                                }
                            }
                            if (!result) continue;
                            #endregion
                        }

                        string str = string.Empty;
                        if (_priceMasterMgr.Save(newPriceMaster, null, category_set, ref str) > 0)
                        {
                            c.msg = "匯入成功";
                        }
                        else
                        {
                            c.msg = string.IsNullOrEmpty(str) ? "保存至數據庫失敗" : str;
                        }
                    }
                }
                #endregion
            }
        }
Beispiel #5
0
        public HttpResponseBase OrderInfoQueryByGigade()
        {
            string jsonStr = "{success:false}";
            uint pid = 0;
            uint spec1 = 0;
            uint spec2 = 0;
            UInt32.TryParse(Request.Params["pid"] ?? "0", out pid);
            IProductImplMgr _proMgr = new ProductMgr(connectionString);
            ProductCombo pcombo = new ProductCombo();
            if (pid != 0)
            {
                long time = BLL.gigade.Common.CommonFunction.GetPHPTime(Request.Params["combOrderDate"]);//獲取頁面上的訂單日期  edit by zhuoqin0830w  2015/11/17
                Product prod = _proMgr.Query(new Product { Product_Id = pid }).FirstOrDefault();
                if (prod != null)
                {
                    //判断商品是否上架
                    long ltime = BLL.gigade.Common.CommonFunction.GetPHPTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    bool upFlag = prod.Product_Status == 5 && ltime >= prod.Product_Start && ltime <= prod.Product_End;//判斷商品是否上架
                    if (Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd" || upFlag)//edit by xiangwang0413w 內部訂單輸入不進行商品是否上架判斷
                    {
                        if (prod.Combination == 3)
                        {
                            #region 無規格任選
                            try
                            {
                                bool hasSpec = false;
                                //查詢子商品信息
                                _prodCombMgr = new ProductComboMgr(connectionString);
                                _proItemMgr = new ProductItemMgr(connectionString);
                                _priceMasterMgr = new PriceMasterMgr(connectionString);
                                List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(pid.ToString()) });
                                //組合商品信息
                                OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = pid }, 1, 0, 1); // add by wwei0216w 2015/2/10 將之前的0,1,1改成 1,0,1 因為參數不對查詢不出結果
                                orderAdd.childCount = prodComList.Count();
                                jsonStr = "{success:true";
                                double comboPrice = 0.0;     //組合商品的價格 =sum( 子商品價格 * 子商品必選數量(s_must_buy);
                                double comboCost = 0.0;  //組合商品的成本
                                double comboEventCost = 0.0;  //組合商品的活動成本  add by zhuoqin0830w  2015/11/09
                                int childSum = 0;      //必選商品的必購數量之和
                                int minStock = 0;
                                int stockIndex = 0;
                                List<OrderAddCustom> orderAddList = new List<OrderAddCustom>();   //存放必選商品集
                                //此循環是計算子商品的庫存,總價(供按比例拆分時計算子商品的價格使用)等其它信息
                                for (int i = 0, j = prodComList.Count(); i < j; i++)
                                {
                                    ProductComboCustom item = prodComList[i];
                                    uint c_product_id = uint.Parse(item.Child_Id.ToString());
                                    Product pResult = _proMgr.Query(new Product { Product_Id = c_product_id }).FirstOrDefault();
                                    //判斷子商品是否有規格
                                    if (pResult.Product_Spec > 0)
                                    {
                                        hasSpec = true;
                                        break;
                                    }
                                    //補貨中停止販售 1:是 0:否
                                    if (pResult.Shortage == 1)
                                    {
                                        jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}";
                                        this.Response.Clear();
                                        this.Response.Write(jsonStr);
                                        this.Response.End();
                                        return this.Response;
                                    }
                                    OrderAddCustom oc = new OrderAddCustom();
                                    ProductItem pItemResult = _proItemMgr.Query(new ProductItem { Product_Id = c_product_id }).FirstOrDefault();
                                    if (pItemResult != null)
                                    {
                                        oc.Item_Id = pItemResult.Item_Id;
                                        oc.Item_Stock = pItemResult.Item_Stock;
                                        oc.s_must_buy = item.S_Must_Buy;
                                        oc.parent_id = int.Parse(pid.ToString());
                                        oc.ignore_stock = pResult.Ignore_Stock;
                                        //計算必先商品之最小庫存
                                        if (item.S_Must_Buy > 0)
                                        {
                                            oc.Product_Id = c_product_id;
                                            childSum += item.S_Must_Buy;
                                            if (stockIndex == 0)
                                            {
                                                minStock = int.Parse((pItemResult.Item_Stock / item.S_Must_Buy).ToString());
                                            }
                                            else
                                            {
                                                int curStock = int.Parse((pItemResult.Item_Stock / item.S_Must_Buy).ToString());
                                                if (curStock < minStock)
                                                {
                                                    minStock = curStock;
                                                }
                                            }
                                            stockIndex++;
                                        }
                                    }
                                    PriceMaster pm = null;
                                    if (prod.Price_type == 1)        //按比例拆分
                                    {
                                        pm = _priceMasterMgr.QueryPriceMaster(new PriceMaster
                                        {
                                            site_id = 1,
                                            child_id = 0,
                                            user_level = 1,
                                            user_id = 0,
                                            product_id = c_product_id
                                        });
                                    }
                                    else if (prod.Price_type == 2)      //各自定價
                                    {
                                        pm = _priceMasterMgr.QueryPriceMaster(new PriceMaster
                                        {
                                            site_id = 1,
                                            child_id = int.Parse(c_product_id.ToString()),
                                            user_level = 1,
                                            user_id = 0,
                                            product_id = pid
                                        });
                                    }
                                    if (pm != null)
                                    {
                                        //計算Item的價格
                                        ItemPriceCustom ipResult = new ItemPriceCustom();
                                        IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);
                                        ipResult = iPMgr.Query(new ItemPrice { item_id = pItemResult.Item_Id, price_master_id = pm.price_master_id }).FirstOrDefault();

                                        oc.product_name = pm.product_name;
                                        oc.price_master_id = pm.price_master_id;
                                        oc.Item_Money = ipResult.item_money;
                                        oc.product_cost = ipResult.item_money;
                                        oc.original_price = int.Parse(ipResult.item_money.ToString());
                                        oc.Item_Cost = ipResult.item_cost;
                                        //計算必選商品之總價
                                        if (item.S_Must_Buy > 0)
                                        {
                                            comboPrice += int.Parse((ipResult.item_money * item.S_Must_Buy).ToString());
                                            comboCost += int.Parse((ipResult.item_cost * item.S_Must_Buy).ToString());
                                        }
                                        orderAddList.Add(oc);
                                    }
                                    else
                                    {
                                        jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}";
                                        this.Response.Clear();
                                        this.Response.Write(jsonStr);
                                        this.Response.End();
                                        return this.Response;
                                    }
                                }
                                //將計算的最小庫存價賦值給組合商品
                                orderAdd.stock = minStock;
                                //各自定價時將組合商品的定價賦值給組合商品
                                if (prod.Price_type == 2)
                                {
                                    orderAdd.product_cost = int.Parse(comboPrice.ToString());
                                }
                                //如果子商品含有規格則提示
                                if (hasSpec)
                                {
                                    jsonStr = "{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_NO_SPEC + "'}";
                                    this.Response.Clear();
                                    this.Response.Write(jsonStr);
                                    this.Response.End();
                                    return this.Response;
                                }
                                jsonStr += ",child:[";
                                string priceScales = "";//單一商品價格所占比例
                                string costScalses = ""; //單一商品成本所占比例
                                var rightList = orderAddList.Where(rec => rec.s_must_buy > 0).ToList();
                                var totalPrice = orderAdd.product_cost;  //組合商品的定價
                                var totalCost = orderAdd.cost;  //組合商品的成本
                                foreach (var item in rightList)
                                {
                                    //如果組合商品的價格類型為 按比例拆分 則需重新為必選子商品定價
                                    if (prod.Price_type == 1)
                                    {
                                        //if (comboCost != 0)
                                        if (comboPrice != 0)
                                        {
                                            //new logic  计算按比例拆分之比例
                                            double priceScale = double.Parse((item.Item_Money * item.s_must_buy / comboPrice).ToString());
                                            //double costScale = double.Parse((item.Item_Cost * item.s_must_buy / comboCost).ToString());
                                            priceScales += priceScale + ",";
                                            //costScalses += costScale + ",";
                                            int afterPrice = Convert.ToInt16(Math.Round(totalPrice * priceScale / item.s_must_buy));
                                            //int afterCost = Convert.ToInt16(Math.Round(totalCost * costScale / item.s_must_buy));
                                            comboPrice -= Convert.ToInt16(item.Item_Money * item.s_must_buy);
                                            //comboCost -= Convert.ToInt16(item.Item_Cost * item.s_must_buy);
                                            totalPrice -= afterPrice * item.s_must_buy;
                                            //totalCost -= afterCost * item.s_must_buy;
                                            item.product_cost = uint.Parse(afterPrice.ToString());
                                            //item.Item_Cost = uint.Parse(afterCost.ToString());
                                        }
                                        else
                                        {
                                            priceScales += "0";
                                            //costScalses += "0";
                                            item.product_cost = 0;
                                        }
                                    }
                                    jsonStr += JsonConvert.SerializeObject(item);
                                }
                                //jsonStr = jsonStr.Substring(0, jsonStr.Length - 1);
                                jsonStr = jsonStr.Replace("}{", "},{");
                                jsonStr += "],data:[";
                                //拼接組合商品   s_must_buy:當前任選中必選商品的記錄數
                                jsonStr += "{product_id:'" + orderAdd.product_id + "',product_name:'" + orderAdd.product_name + "',Item_Cost:'" + orderAdd.cost + "',product_cost:'" + orderAdd.product_cost + "',item_id:0";
                                jsonStr += ",child_scale:'" + priceScales + "',child_cost_scale:'" + costScalses + "',stock:'" + minStock + "',g_must_buy:'" + prodComList[0].G_Must_Buy + "',s_must_buy:" + rightList.Count() + "";
                                jsonStr += ",combination:" + orderAdd.child + ",buy_limit:" + prodComList[0].Buy_Limit + ",child:" + orderAdd.child + ",childCount:" + orderAdd.childCount + ",childSum:" + childSum + ",price_type:" + orderAdd.price_type + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}]}";
                            }
                            catch (Exception ex)
                            {
                                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                log.Error(logMessage);
                            }
                            #endregion
                        }
                        else if (prod.Combination == 2)
                        {
                            #region 固定組合
                            try
                            {
                                OrderComboAddCustom orderAdd = _proMgr.OrderQuery(new Product { Product_Id = pid }, 1, 0, 1);
                                jsonStr = "{success:true";
                                //查詢子商品信息
                                _prodCombMgr = new ProductComboMgr(connectionString);
                                List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = int.Parse(pid.ToString()) });
                                IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString);
                                IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString);
                                foreach (var item in prodComList)
                                {
                                    Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }).FirstOrDefault();
                                    //補貨中停止販售 1:是 0:否
                                    if (pResult.Shortage == 1)
                                    {
                                        jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}";
                                        this.Response.Clear();
                                        this.Response.Write(jsonStr);
                                        this.Response.End();
                                        return this.Response;
                                    }
                                }
                                jsonStr += ",child:[";
                                double totalPrice = 0;
                                double totalCost = 0;
                                double totalEventCost = 0; //add by zhuoqin0830w  2015/11/09
                                double totalEventPrice = 0;//add by zhuoqin0830w  2015/11/17
                                string priceScales = "";//單一商品價格所占比例
                                string costScales = ""; //單一商品成本所占比例
                                string eventcostScales = "";//單一商品活動成本所占比例  add by zhuoqin0830w  2015/11/09
                                string eventpriceScales = "";//單一商品活動價所占比例  add by zhuoqin0830w  2015/11/17
                                int minStock = 0;
                                if (prod.Price_type == 1)
                                {
                                    #region 按比例拆分
                                    //計算子商品的總價
                                    List<ProductItem> price_data_right_list = new List<ProductItem>();
                                    foreach (var item in prodComList)
                                    {
                                        bool findState = false;
                                        List<Product> pList = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) });
                                        List<ProductItem> pItemList = _proItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Child_Id.ToString()) });
                                        //在item_price中查找對應item_id的商品規格價格
                                        IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);
                                        PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster
                                        {
                                            product_id = uint.Parse(item.Child_Id.ToString()),
                                            user_id = 0,
                                            user_level = 1,
                                            site_id = uint.Parse(Request.Params["Site_Id"]),  //edit by zhuoqin0830w  2015/11/16  添加站台欄位詳細查詢是哪一個站台下的價格
                                            child_id = 0
                                        });
                                        List<ItemPriceCustom> ipList = new List<ItemPriceCustom>();

                                        if (pM != null)
                                        {
                                            //add by zhuoqin0830w  2015/11/06  添加判斷 活動時間是否過期  如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本
                                            if (time > pM.event_end)
                                            {
                                                pM.event_cost = 0;
                                                pM.event_price = 0;
                                            }

                                            //遍歷此商品所有item_id,找出第一筆在item_price中的item_id返回,若無,則此組合商品不能加入訂單
                                            foreach (ProductItem items in pItemList)
                                            {
                                                ipList = iPMgr.Query(new ItemPrice
                                                {
                                                    item_id = uint.Parse(items.Item_Id.ToString()),
                                                    price_master_id = pM.price_master_id
                                                });
                                                if (ipList.Count == 1)
                                                {
                                                    if (pM.same_price == 1)
                                                    {
                                                        totalPrice += pM.price * item.S_Must_Buy;
                                                        totalCost += pM.cost * item.S_Must_Buy;
                                                        totalEventCost += pM.event_cost * item.S_Must_Buy;//add by zhuoqin0830w  2015/11/09
                                                        totalEventPrice += pM.event_price * item.S_Must_Buy;//add by zhuoqin0830w  2015/11/17
                                                    }
                                                    else
                                                    {
                                                        totalPrice += ipList[0].item_money * item.S_Must_Buy;
                                                        totalCost += ipList[0].item_cost * item.S_Must_Buy;
                                                        totalEventCost += ipList[0].event_cost * item.S_Must_Buy;//add by zhuoqin0830w  2015/11/09
                                                        totalEventPrice += ipList[0].event_money * item.S_Must_Buy;//add by zhuoqin0830w  2015/11/17
                                                    }
                                                    price_data_right_list.Add(items);
                                                    findState = true;
                                                    break;
                                                }
                                            }
                                            if (!findState)
                                            {
                                                //在item_price中未查出對應價格
                                                this.Response.Clear();
                                                this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.COMBO_CHILD_PRICE_NULL + "'}");
                                                this.Response.End();
                                                return this.Response;
                                            }
                                        }
                                        else
                                        {
                                            //price_master表中沒有相對應的站台價格  add by zhuoqin0830w  2015/11/16
                                            jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}";
                                            this.Response.Clear();
                                            this.Response.Write(jsonStr);
                                            this.Response.End();
                                            return this.Response;
                                        }
                                    }
                                    int index = 0;
                                    int comboPrice = orderAdd.product_cost;   //組合商品的定價
                                    int comboCost = orderAdd.cost;
                                    int comboEventCost = 0;
                                    int comboEventPrice = 0;
                                    //add by zhuoqin0830w  2015/11/06  添加判斷 活動時間是否過期  如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本
                                    if (orderAdd != null)
                                    {
                                        if (time > orderAdd.event_start && time < orderAdd.event_end)
                                        {
                                            comboEventCost = orderAdd.event_cost;
                                            comboEventPrice = orderAdd.event_price;
                                        }
                                        else
                                        {
                                            orderAdd.event_cost = 0;
                                            orderAdd.event_price = 0;
                                        }
                                    }
                                    for (int i = 0; i < prodComList.Count; i++)
                                    {
                                        index++;
                                        OrderAddCustom oc = new OrderAddCustom();
                                        oc.Product_Id = uint.Parse(prodComList[i].Child_Id.ToString());
                                        oc.parent_id = prodComList[i].Parent_Id;
                                        //讀取product_name
                                        IPriceMasterImplMgr pMgr = new PriceMasterMgr(connectionString);
                                        PriceMaster pm = pMgr.QueryPriceMaster(new PriceMaster
                                        {
                                            site_id = uint.Parse(Request.Params["Site_Id"]),  //edit by zhuoqin0830w  2015/11/16  添加站台欄位詳細查詢是哪一個站台下的價格
                                            child_id = 0,
                                            user_level = 1,
                                            user_id = 0,
                                            product_id = oc.Product_Id
                                        });
                                        if (pm != null)
                                        {
                                            oc.product_name = pm.product_name;
                                        }
                                        oc.s_must_buy = prodComList[i].S_Must_Buy;
                                        if (price_data_right_list.Count != 0)
                                        {
                                            if (index == 1)
                                            {
                                                //最小庫存為組合下子商品的最小庫存/該子商品必購數量(如果必購數量為0則按1計算)
                                                minStock = int.Parse((price_data_right_list[i].Item_Stock / (prodComList[i].S_Must_Buy == 0 ? 1 : prodComList[i].S_Must_Buy)).ToString());
                                            }
                                            Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(prodComList[i].Child_Id.ToString()) }).FirstOrDefault();
                                            //有規格
                                            oc.Spec_Name_1 = price_data_right_list[i].Spec_Name_1;
                                            oc.Spec_Name_2 = price_data_right_list[i].Spec_Name_2;
                                            oc.Item_Stock = price_data_right_list[i].Item_Stock;
                                            oc.Item_Id = price_data_right_list[i].Item_Id;
                                            int curStock = int.Parse((oc.Item_Stock / (prodComList[i].S_Must_Buy == 0 ? 1 : prodComList[i].S_Must_Buy)).ToString());
                                            if (curStock < minStock)
                                            {
                                                minStock = curStock;
                                            }
                                            oc.Spec_Id_1 = price_data_right_list[i].Spec_Id_1;
                                            oc.Spec_Id_2 = price_data_right_list[i].Spec_Id_2;
                                            oc.ignore_stock = pResult.Ignore_Stock;
                                            //在item_price中查找對應item_id的商品規格價格
                                            IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);
                                            PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster
                                            {
                                                product_id = uint.Parse(price_data_right_list[i].Product_Id.ToString()),
                                                user_id = 0,
                                                user_level = 1,
                                                site_id = uint.Parse(Request.Params["Site_Id"]),  //edit by zhuoqin0830w  2015/11/16  添加站台欄位詳細查詢是哪一個站台下的價格
                                                child_id = 0
                                            });
                                            List<ItemPriceCustom> ipList = new List<ItemPriceCustom>();
                                            if (pM != null)
                                            {
                                                double singlePrice = 0;
                                                double singleCost = 0;
                                                double singleEventCost = 0;//add by zhuoqin0830w  2015/11/09
                                                double singleEventPrice = 0;//add by zhuoqin0830w  2015/11/17

                                                if (pM.same_price == 1)
                                                {
                                                    oc.original_price = pM.price;
                                                    oc.Item_Cost = uint.Parse(pM.cost.ToString());
                                                    oc.Event_Item_Cost = uint.Parse(pm.event_cost.ToString());//add by zhuoqin0830w  2015/11/09
                                                    oc.Event_Item_Money = uint.Parse(pm.event_price.ToString());//add by zhuoqin0830w  2015/11/17
                                                    singlePrice = pM.price * oc.s_must_buy;
                                                    singleCost = pM.cost * oc.s_must_buy;
                                                    singleEventCost = pM.event_cost * oc.s_must_buy;//add by zhuoqin0830w  2015/11/09
                                                    singleEventPrice = pM.event_price * oc.s_must_buy;//add by zhuoqin0830w  2015/11/17
                                                }
                                                else
                                                {
                                                    ipList = iPMgr.Query(new ItemPrice
                                                    {
                                                        item_id = uint.Parse(price_data_right_list[i].Item_Id.ToString()),
                                                        price_master_id = pM.price_master_id
                                                    });
                                                    if (ipList.Count == 1)
                                                    {
                                                        oc.original_price = int.Parse(ipList[0].item_money.ToString());
                                                        oc.Item_Cost = ipList[0].item_cost;
                                                        oc.Event_Item_Cost = ipList[0].event_cost;//add by zhuoqin0830w  2015/11/09
                                                        oc.Event_Item_Money = ipList[0].event_money;//add by zhuoqin0830w  2015/11/17
                                                        singlePrice = ipList[0].item_money * oc.s_must_buy;
                                                        singleCost = ipList[0].item_cost * oc.s_must_buy;
                                                        singleEventCost = ipList[0].event_cost * oc.s_must_buy;//add by zhuoqin0830w  2015/11/09
                                                        singleEventPrice = ipList[0].event_money * oc.s_must_buy;//add by zhuoqin0830w  2015/11/17
                                                    }
                                                }
                                                if (totalPrice == 0)
                                                {
                                                    priceScales += "0";
                                                    costScales += "0";
                                                    eventcostScales += "0";//add by zhuoqin0830w  2015/11/09
                                                    eventpriceScales += "0";//add by zhuoqin0830w  2015/11/09
                                                    oc.product_cost = 0;
                                                }
                                                else
                                                {
                                                    //new logic 算比例
                                                    double priceScale = double.Parse((singlePrice / totalPrice).ToString());
                                                    double costScale = double.Parse((singleCost / totalCost).ToString());
                                                    //add by zhuoqin0830w  2015/11/09  添加活動成本的比例
                                                    double eventcostScale = 0;
                                                    if (totalEventCost != 0)
                                                    {
                                                        eventcostScale = double.Parse((singleEventCost / totalEventCost).ToString());
                                                    }
                                                    else
                                                    {
                                                        eventcostScale = priceScale;// 如果 活動成本的比例為0 則表示沒有活動成本則按照價格的比例進行計算
                                                    }
                                                    double eventpriceScale = 0;
                                                    if (totalEventPrice != 0)
                                                    {
                                                        eventpriceScale = double.Parse((singleEventPrice / totalEventPrice).ToString());
                                                    }
                                                    else
                                                    {
                                                        eventpriceScale = priceScale;// 如果 活動價的比例為0 則表示沒有活動成本則按照價格的比例進行計算
                                                    }

                                                    priceScales += priceScale + ",";
                                                    costScales += costScale + ",";
                                                    eventcostScales += eventcostScale + ",";//add by zhuoqin0830w  2015/11/09
                                                    eventpriceScales += eventpriceScale + ",";//add by zhuoqin0830w  2015/11/17

                                                    var afterprice = Convert.ToInt16(Math.Round(comboPrice * priceScale / oc.s_must_buy));
                                                    var aftercost = Convert.ToInt16(Math.Round(comboCost * costScale / oc.s_must_buy));
                                                    var aftereventcost = Convert.ToInt16(Math.Round(comboEventCost * eventcostScale / oc.s_must_buy));//add by zhuoqin0830w  2015/11/09
                                                    var aftereventprice = Convert.ToInt16(Math.Round(comboEventPrice * eventpriceScale / oc.s_must_buy));//add by zhuoqin0830w  2015/11/17

                                                    comboPrice -= afterprice * oc.s_must_buy;
                                                    comboCost -= aftercost * oc.s_must_buy;
                                                    comboEventCost -= aftereventcost * oc.s_must_buy;//add by zhuoqin0830w  2015/11/09
                                                    comboEventPrice -= aftereventprice * oc.s_must_buy;//add by zhuoqin0830w  2015/11/17

                                                    totalPrice -= singlePrice;
                                                    totalCost -= singleCost;
                                                    totalEventCost -= singleEventCost;//add by zhuoqin0830w  2015/11/09
                                                    totalEventPrice -= singleEventPrice;//add by zhuoqin0830w  2015/11/17

                                                    oc.product_cost = uint.Parse(afterprice.ToString());
                                                    oc.Item_Cost = uint.Parse(aftercost.ToString());
                                                    oc.Event_Item_Cost = uint.Parse(aftereventcost.ToString());//add by zhuoqin0830w  2015/11/09
                                                    oc.Event_Item_Money = uint.Parse(aftereventprice.ToString());//add by zhuoqin0830w  2015/11/17
                                                }
                                            }
                                        }
                                        jsonStr += JsonConvert.SerializeObject(oc) + ",";
                                    }
                                    #endregion
                                }
                                else
                                {
                                    #region 各自定價
                                    orderAdd.product_cost = 0;
                                    foreach (var item in prodComList)
                                    {
                                        Product pResult = _proMgr.Query(new Product { Product_Id = uint.Parse(item.Child_Id.ToString()) }).FirstOrDefault();
                                        OrderAddCustom oc = new OrderAddCustom();
                                        oc.price_type = prod.Price_type;
                                        oc.parent_id = item.Parent_Id;
                                        oc.Product_Id = uint.Parse(item.Child_Id.ToString());
                                        List<ProductItem> pItemList = _proItemMgr.Query(new ProductItem { Product_Id = uint.Parse(item.Child_Id.ToString()) });
                                        if (prodComList.IndexOf(item) == 0)
                                        {
                                            minStock = int.Parse((pItemList[0].Item_Stock / (item.S_Must_Buy == 0 ? 1 : item.S_Must_Buy)).ToString()); //最小庫存為組合下子商品的最小庫存/該子商品必購數量(如果必購數量為0則按1計算)
                                        }
                                        PriceMaster pM = priceMgr.QueryPriceMaster(new PriceMaster
                                        {
                                            product_id = pid,
                                            user_id = 0,
                                            user_level = 1,
                                            site_id = uint.Parse(Request.Params["Site_Id"]),  //edit by zhuoqin0830w  2015/11/16  添加站台欄位詳細查詢是哪一個站台下的價格
                                            child_id = Int32.Parse(item.Child_Id) //add by wangwei02016w 2014/9/24 
                                        });
                                        ItemPriceCustom ip = new ItemPriceCustom();
                                        IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);
                                        if (pM != null)
                                        {
                                            oc.product_name = pM.product_name;
                                            oc.price_master_id = pM.price_master_id;

                                            ip = iPMgr.Query(new ItemPrice
                                            {
                                                item_id = uint.Parse(pItemList[0].Item_Id.ToString()),
                                                price_master_id = pM.price_master_id
                                            }).First();

                                            oc.Spec_Name_1 = pItemList[0].Spec_Name_1;
                                            oc.Spec_Name_2 = pItemList[0].Spec_Name_2;
                                            oc.Item_Stock = pItemList[0].Item_Stock;
                                            oc.Spec_Id_1 = pItemList[0].Spec_Id_1;
                                            oc.Spec_Id_2 = pItemList[0].Spec_Id_2;
                                            oc.ignore_stock = pResult.Ignore_Stock;
                                            int curStock = int.Parse((pItemList[0].Item_Stock / (item.S_Must_Buy == 0 ? 1 : item.S_Must_Buy)).ToString());
                                            if (curStock < minStock)
                                            {
                                                minStock = curStock;
                                            }
                                            oc.Item_Id = pItemList[0].Item_Id;
                                            oc.product_cost = ip.item_money;
                                            oc.original_price = int.Parse(ip.item_money.ToString());
                                            orderAdd.product_cost += Convert.ToInt32(oc.product_cost * item.S_Must_Buy);
                                        }
                                        oc.s_must_buy = item.S_Must_Buy;
                                        jsonStr += JsonConvert.SerializeObject(oc) + ",";
                                    }
                                    #endregion
                                }
                                jsonStr = jsonStr.Substring(0, jsonStr.Length - 1) + "]";
                                jsonStr += ",data:[";
                                //拼接組合商品   cost為組合商品之成本,product_cost為組合商品之售價
                                jsonStr += "{product_id:'" + orderAdd.product_id + "',product_name:'" + orderAdd.product_name + "',Item_Cost:'" + orderAdd.cost + "',product_cost:'" + orderAdd.product_cost + "',item_id:0" + ",Event_Item_Cost:" + orderAdd.event_cost + ",Event_Item_Money:" + orderAdd.event_price;
                                jsonStr += ",s_must_buy:'" + prodComList.Count + "',child_scale:'" + priceScales + "',child_cost_scale:'" + costScales + "',child_event_cost_scale:'" + eventcostScales + "',stock:'" + minStock + "',g_must_buy:'" + prodComList.Count + "',child:" + orderAdd.child + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}";
                                jsonStr += "]}";
                            }
                            catch (Exception ex)
                            {
                                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                log.Error(logMessage);
                            }
                            #endregion
                        }
                        else
                        {
                            #region 單一商品
                            // 判斷 輸入的商品是否是單一商品 並且是 內部訂單輸入  如果是 則彈出提示框  add by zhuoqin0830w 2015/07/10
                            if (Request.UrlReferrer.AbsolutePath == "/Order/InteriorOrderAdd")
                            {
                                if (prod.Combination == 1 && Convert.ToInt32(Request.Params["pid"].Length) != 6 && Request.Params["parent_id"] == "")
                                {
                                    this.Response.Clear();
                                    this.Response.Write("{success:false,msg:'單一商品必須輸入六碼編號!'}");
                                    this.Response.End();
                                    return this.Response;
                                }
                            }
                            IProductItemImplMgr _proItemMgr = new ProductItemMgr(connectionString);
                            Product p = new Product();
                            p.Product_Id = pid;
                            ProductItem pItem = new ProductItem();
                            pItem.Product_Id = pid;
                            UInt32.TryParse(Request.Params["spec1"] ?? "0", out spec1);
                            UInt32.TryParse(Request.Params["spec2"] ?? "0", out spec2);
                            pItem.Spec_Id_1 = spec1;
                            pItem.Spec_Id_2 = spec2;
                            try
                            {
                                List<OrderAddCustom> oalist = new List<OrderAddCustom>();
                                OrderAddCustom oc = new OrderAddCustom();
                                List<Product> pList = _proMgr.Query(p);
                                List<ProductItem> pItemList = _proItemMgr.Query(pItem);
                                if (pList.Count() <= 0 || pItemList.Count() <= 0)
                                {
                                    jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}";//商品不存在
                                    this.Response.Clear();
                                    this.Response.Write(jsonStr);
                                    this.Response.End();
                                    return this.Response;
                                }
                                //補貨中停止販售 1:是 0:否
                                if (pList[0].Shortage == 1)
                                {
                                    jsonStr = "{success:false,msg:'" + Resources.OrderAdd.SHPRT_AGE + "'}";//補貨中不能販賣
                                    this.Response.Clear();
                                    this.Response.Write(jsonStr);
                                    this.Response.End();
                                    return this.Response;
                                }
                                int parent_id = 0;
                                int price_type = 0;
                                uint c_combination = 0;
                                int c_buy_limit = 0;
                                //組合商品子商品查詢
                                if (!string.IsNullOrEmpty(Request.Params["parent_id"]))
                                {
                                    parent_id = int.Parse(Request.Params["parent_id"]);
                                    //查詢組合商品的價格類型
                                    Product parentResult = _proMgr.Query(new Product { Product_Id = uint.Parse(parent_id.ToString()) }).FirstOrDefault();
                                    if (parentResult != null)
                                    {
                                        price_type = parentResult.Price_type;
                                        c_combination = parentResult.Combination;
                                    }
                                    oc.price_type = price_type;
                                    //找出該商品在組合商品中的必購數量
                                    _prodCombMgr = new ProductComboMgr(connectionString);
                                    List<ProductComboCustom> prodComList = _prodCombMgr.combQuery(new ProductComboCustom { Parent_Id = parent_id, Child_Id = pid.ToString() });//add by wangwei02016w 2014/9/24 
                                    if (prodComList.Count == 1)
                                    {
                                        oc.s_must_buy = prodComList[0].S_Must_Buy;
                                        c_buy_limit = prodComList[0].Buy_Limit;
                                    }
                                }
                                //在item_price中查找對應item_id的商品規格價格
                                IPriceMasterImplMgr priceMgr = new PriceMasterMgr(connectionString);
                                IItemPriceImplMgr iPMgr = new ItemPriceMgr(connectionString);
                                PriceMaster pM = null;
                                if (price_type == 2)        //各自定價時取價格
                                {
                                    pM = priceMgr.QueryPriceMaster(new PriceMaster
                                    {
                                        product_id = uint.Parse(parent_id.ToString()),
                                        user_id = 0,
                                        user_level = 1,
                                        site_id = uint.Parse(Request.Params["Site_Id"]),  //edit by zhuoqin0830w  2015/11/16  添加站台欄位詳細查詢是哪一個站台下的價格
                                        child_id = int.Parse(pList[0].Product_Id.ToString())
                                    });
                                }
                                else
                                {
                                    pM = priceMgr.QueryPriceMaster(new PriceMaster
                                    {
                                        product_id = pList[0].Product_Id,
                                        user_id = 0,
                                        user_level = 1,
                                        site_id = uint.Parse(Request.Params["Site_Id"]),  //edit by zhuoqin0830w  2015/11/16  添加站台欄位詳細查詢是哪一個站台下的價格
                                        child_id = 0
                                    });
                                }
                                if (pM != null)
                                {
                                    oc.price_master_id = pM.price_master_id;
                                    List<ItemPriceCustom> ipList = iPMgr.Query(new ItemPrice
                                    {
                                        item_id = uint.Parse(pItemList[0].Item_Id.ToString()),
                                        price_master_id = pM.price_master_id
                                    });

                                    oc.Product_Id = pList[0].Product_Id;
                                    oc.product_name = pList[0].Product_Name;
                                    oc.Spec_Id_1 = pItemList[0].Spec_Id_1;
                                    oc.Spec_Id_2 = pItemList[0].Spec_Id_2;
                                    oc.Item_Id = pItemList[0].Item_Id;
                                    oc.Item_Stock = pItemList[0].Item_Stock;
                                    if (ipList.Count() > 0)
                                    {
                                        //edit by zhuoqin0830w  2015/11/16   將售價和活動售價的邏輯改為與成本和活動成本的邏輯一樣  eric說需要修改
                                        if (pM.same_price == 1)
                                        {
                                            oc.Item_Cost = uint.Parse(pM.cost.ToString());//成本
                                            oc.Item_Money = uint.Parse(pM.price.ToString());//定價
                                        }
                                        else
                                        {
                                            oc.Item_Cost = ipList[0].item_cost;
                                            oc.Item_Money = ipList[0].item_money;
                                        }

                                        //add by zhuoqin0830w  2015/11/06  添加判斷 活動時間是否過期  如果過期則在頁面上顯示的活動成本為 0 如果沒有過期則顯示活動成本
                                        if (time > pM.event_start && time < pM.event_end)
                                        {
                                            oc.Event_Item_Cost = uint.Parse(pM.event_cost.ToString());
                                            //add by zhuoqin0830w  2015/11/16  添加判斷 活動時間是否過期  如果過期則在頁面上顯示的活動售價為 0 如果沒有過期則顯示活動售價
                                            oc.Event_Item_Money = uint.Parse(pM.event_price.ToString());
                                        }
                                        else
                                        {
                                            oc.Event_Item_Cost = 0;
                                            oc.Event_Item_Money = 0;
                                        }
                                    }
                                    else
                                    {
                                        this.Response.Clear();
                                        this.Response.Write("{success:false,msg:'" + Resources.OrderAdd.SINGLE_SPEC_PRICE_WRONG + "'}");
                                        this.Response.End();
                                        return this.Response;
                                    }
                                    IProductSpecImplMgr _specMgr = new BLL.gigade.Mgr.ProductSpecMgr(connectionString);
                                    List<ProductSpec> specList1 = _specMgr.query(Int32.Parse(pItemList[0].Product_Id.ToString()), "spec_id_1");
                                    List<ProductSpec> specList2 = _specMgr.query(Int32.Parse(pItemList[0].Product_Id.ToString()), "spec_id_2");
                                    oc.specList1 = specList1;
                                    oc.specList2 = specList2;
                                    oalist.Add(oc);
                                    StringBuilder stb = new StringBuilder();
                                    stb.Append("[");
                                    stb.Append("{product_id:" + oc.Product_Id + ",price_type:" + oc.price_type + ",child:" + c_combination + ",buy_limit:" + c_buy_limit + ",item_id:" + oc.Item_Id + ",product_name:'" + oc.product_name + "',");
                                    //添加 活動成本 金額顯示 ",Event_Item_Cost:" + pM.event_cost  zhuoqin0830w  2015/04/30  添加活動售價  ",Event_Item_Money:" + oc.Event_Item_Money  zhuoqin0830w 2015/11/16
                                    stb.Append("product_cost:" + oc.Item_Money + ",Event_Item_Money:" + oc.Event_Item_Money + ",Item_Cost:" + oc.Item_Cost + ",Event_Item_Cost:" + pM.event_cost + ",stock:" + oc.Item_Stock + ",s_must_buy:" + oc.s_must_buy + ",Spec_Name_1:'" + pItemList[0].Spec_Name_1 + "',Spec_Name_2:'" + pItemList[0].Spec_Name_2 + "',spec1:" + pItemList[0].Spec_Id_1 + ",spec2:" + pItemList[0].Spec_Id_2 + ",price_master_id:" + oc.price_master_id + ",ignore_stock:" + pList[0].Ignore_Stock + ",product_status_name:'" + (upFlag ? "上架" : "未上架") + "'}");
                                    stb.Append("]");
                                    jsonStr = "{success:true,data:" + stb.ToString() + "}";
                                }
                                else
                                {
                                    jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_PRICE_NOT_EXIST + "'}";
                                }
                            }
                            catch (Exception ex)
                            {
                                Log4NetCustom.LogMessage logMessage = new Log4NetCustom.LogMessage();
                                logMessage.Content = string.Format("TargetSite:{0},Source:{1},Message:{2}", ex.TargetSite.Name, ex.Source, ex.Message);
                                logMessage.MethodName = System.Reflection.MethodBase.GetCurrentMethod().Name;
                                log.Error(logMessage);
                            }
                            #endregion
                        }
                    }
                    else
                    {
                        jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_DOWN + "'}";
                    }
                }
                else
                {
                    jsonStr = "{success:false,msg:'" + Resources.OrderAdd.PRODUCT_NOT_EXIST + "'}";
                }
            }
            else
            {
                jsonStr = "[{success:true,data:{product_id:''}}]";
            }
            this.Response.Clear();
            this.Response.Write(jsonStr);
            this.Response.End();
            return this.Response;
        }
 public List<ProductComboMap> ComboItemQuery(ProductCombo query)
 {
     StringBuilder sql = new StringBuilder("select p.product_name,p.prod_sz,i.item_id from product_combo c inner join product p on c.child_id = p.product_id inner join product_item i on p.product_id = i.product_id");
     sql.AppendFormat(" where parent_id = {0}", query.Parent_Id);
     return _accessMySql.getDataTableForObj<ProductComboMap>(sql.ToString());
 }
Beispiel #7
0
 public List<ProductCombo> groupNumQuery(ProductCombo query)
 {
     string sql = string.Format("select pile_id,g_must_buy,buy_limit from product_combo where parent_id = {0} group by pile_id,g_must_buy", query.Parent_Id);
     return _access.getDataTableForObj<ProductCombo>(sql);
 }
Beispiel #8
0
 public string Save(ProductCombo combo)
 {
     StringBuilder stb = new StringBuilder("insert into product_combo(`parent_id`,`child_id`,`s_must_buy`,`g_must_buy`,`pile_id`,`buy_limit`) values({0},");
     stb.AppendFormat("{0},{1},{2},{3},{4})", combo.Child_Id, combo.S_Must_Buy, combo.G_Must_Buy, combo.Pile_Id, combo.Buy_Limit);
     return stb.ToString();
 }