Example #1
0
        //組合商品
        public List<ProductItemMapCustom> FixedComboProductItemMapExc(PriceMasterCustom pmc)
        {
            ProductItemMapMgr _mapMgr = new ProductItemMapMgr(connectionString);
            List<ProductItemMapCustom> pimcs = new List<ProductItemMapCustom>();
            List<ProductMapCustom> resultList = _ProductItemMapDao.CombinationQuery(
                new ProductItemMapCustom { product_id = pmc.product_id }
                );

            if (resultList.Count() > 0)
            {
                List<List<ProductComboMap>> itemAll = new List<List<ProductComboMap>>();
                for (int i = 0, j = resultList.Count(); i < j; i++)
                {
                    List<ProductComboMap> itemList = _mapMgr.ProductComboItemQuery(resultList[i].child_id, (int)pmc.product_id);
                    if (itemList.Count > 0)//當子商品有規格時才可以建立對照
                    {
                        itemAll.Add(itemList);
                    }
                }
                if (itemAll.Count == 0) return pimcs;
                string s = "";
                getCombo(0, itemAll, "", ref s);
                s = s.Remove(s.Length - 1);
                string[] itemstr = s.Split('&');
                for (int Si = 0, Sj = itemstr.Length; Si < Sj; Si++)
                {
                    ProductItemMapCustom _productitemmap = new ProductItemMapCustom();
                    _productitemmap.channel_detail_id = pmc.product_id + ((Sj > 1) ? ("-" + (Si + 1)) : "");//如果組合種類為多種,則加序號
                    _productitemmap.product_name = pmc.product_name;
                    _productitemmap.product_id = pmc.product_id;
                    _productitemmap.group_item_id = itemstr[Si];
                    _productitemmap.product_price = pmc.price;
                    _productitemmap.product_cost = pmc.cost;
                    _productitemmap.site_id = pmc.site_id;
                    _productitemmap.user_level = pmc.user_level;
                    _productitemmap.user_id = pmc.user_id;
                    pimcs.Add(_productitemmap);
                }
            }
            return pimcs;
        }
Example #2
0
        //單一商品
        public List<ProductItemMapCustom> SingleProductItemMapExc(PriceMasterCustom pmc)
        {
            IProductItemImplMgr _proItem = new ProductItemMgr(connectionString);
            List<ProductItem> resultList = _proItem.Query(pmc);
            List<ProductItemMapCustom> pimcs = new List<ProductItemMapCustom>();
            int i=1;
            foreach (var item in resultList)
            {
                var p = new ProductItemMapCustom();
                p.channel_detail_id = pmc.product_id + ((resultList.Count > 1) ? ("-" + i) : "");//如果該商品只有一個子項,則不拼接序號
                p.product_name = pmc.product_name + ((item.Spec_Name_1 == "" && item.Spec_Name_2 == "") ? "" : ("-" + item.Spec_Name_1 + item.Spec_Name_2));
                p.product_id = pmc.product_id;
                p.group_item_id = item.Item_Id.ToString() ;
                p.product_price = pmc.price;
                p.product_cost = pmc.cost;

                p.site_id = pmc.site_id;
                p.user_level = pmc.user_level;
                p.user_id = pmc.user_id;
                pimcs.Add(p);
                i++;
            }
            return pimcs;
        }
        /// <summary>
        /// 商品列表中各 自定價類型 商品的新增
        /// <param name="productID">商品Id號</param>
        /// add by wangwei0216w 2014/8/28
        /// <param name="chkCost">0 為 活動成本 設定 原成本,1 為 活動成本 依 折數 計算</param>  //add by zhuoqin0830w  2015/04/02
        /// </summary>
        public string ProductByPriceEach(PriceMasterCustom pmc, HistoryBatch batch, List<PriceMaster> list_priceMaster, int chkCost)
        {
            //價格修改 申請審核
            PriceUpdateApply priceUpdateApply = new PriceUpdateApply();
            priceUpdateApply.apply_user = Convert.ToUInt32((Session["caller"] as Caller).user_id);

            //價格審核記錄
            PriceUpdateApplyHistory applyHistroy = new PriceUpdateApplyHistory();
            applyHistroy.user_id = Convert.ToInt32(priceUpdateApply.apply_user);
            applyHistroy.price_status = 1;
            //applyHistroy.type = 3;
            applyHistroy.type = 1;//edit by wwei0216w 所作操作為 1:申請審核的操作 
            _priceUpdateApplyMgr = new PriceUpdateApplyMgr(connectionString);
            _priceUpdateApplyHistoryMgr = new PriceUpdateApplyHistoryMgr(connectionString);
            _tableHistoryMgr = new TableHistoryMgr(connectionString);
            ArrayList excuteSql = new ArrayList();
            string msg = "";  //定義json字符串
            _priceMasterMgr = new PriceMasterMgr(connectionString);
            //定義priceMaster對象
            var priceStores = list_priceMaster.FindAll(m => m.product_id == pmc.product_id);  //獲取各自定價商品的各自信息

            priceStores.ForEach(m =>
            {
                m.site_id = pmc.site_id;
                m.user_level = pmc.user_level;
                m.user_id = pmc.user_id;

                int event_price = m.event_price;
                int event_cost = m.event_cost;
                //將p對象賦予pm
                m.price = CommonFunction.ArithmeticalDiscount(event_price, pmc.price_discount);// Convert.ToInt32(Convert.ToDouble(event_price) * (pmc._discount * 0.01));  //新的售價
                m.cost = CommonFunction.ArithmeticalDiscount(event_cost, pmc.cost_discount); //Convert.ToInt32(Convert.ToDouble(event_cost) * (pmc._cost_discount * 0.01));//新的成本
                m.event_price = CommonFunction.ArithmeticalDiscount(event_price, pmc.event_price_discount);// Convert.ToInt32(Convert.ToDouble(event_price) * (pmc.event_price_discount * 0.01));//活動售價
                //eidt by zhuoqin0830w  更改商品活動成本驗算公式使活動價乘以折扣  2015/02/27
                if (chkCost == 1)
                {
                    m.event_cost = CommonFunction.ArithmeticalDiscount(m.event_price, pmc.event_cost_discount);// Convert.ToInt32(Convert.ToDouble(event_cost) * (pmc.event_cost_discount * 0.01));//活動成本
                }
                else { m.event_cost = event_cost; }
                m.price_status = 2;                                                                        //設置狀態為申請審核
                if (pmc.event_start.ToString() != "")
                {
                    m.event_start = pmc.event_start;
                }
                if (pmc.event_end.ToString() != "")
                {
                    m.event_end = pmc.event_end;   //設置時間
                }

            });
            var parent = priceStores.Find(m => m.product_id == m.child_id);
            //為parent賦予值
            uint userId = 0;
            int priceMasterId = -1;
            var result = _priceMasterMgr.Query(new PriceMaster { product_id = parent.product_id, child_id = parent.child_id, user_id = userId, site_id = parent.site_id });
            if (result.Count > 0)
            {
                msg = parent.product_id.ToString();
                return msg;
            }

            priceMasterId = _priceMasterMgr.Save(parent, null, null, ref msg);
            var pm = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault();
            int apply_id = -1;
            if (priceMasterId != -1)
            {
                priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId);
                apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply);
                if (apply_id == -1) return msg = parent.product_id.ToString();
                applyHistroy.apply_id = apply_id;
                pm.apply_id = (uint)apply_id;
                excuteSql.Add(_priceMasterMgr.Update(pm));
                excuteSql.Add(_priceMasterTsMgr.UpdateTs(pm)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核
                excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy));
            }

            foreach (PriceMaster p in priceStores.FindAll(m => m.product_id != m.child_id))                 //遍歷集合
            {
                priceMasterId = _priceMasterMgr.Save(p, null, null, ref msg);
                if (priceMasterId == -1) return msg = parent.product_id.ToString();
                pm = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault();
                pm.apply_id = (uint)apply_id;
                excuteSql.Add(_priceMasterMgr.Update(pm));
                excuteSql.Add(_priceMasterTsMgr.UpdateTs(pm)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核
            }

            _tableHistoryMgr = new TableHistoryMgr(connectionString);
            if (_tableHistoryMgr.SaveHistory<PriceMaster>(parent, batch, excuteSql))
            {
                msg = "success";
            }
            else { msg = parent.product_id.ToString(); }
            return msg;
        }
        /// <summary>
        /// 批量新增組合商品價格
        /// </summary>
        /// <param name="pmc"></param>
        /// <param name="batch"></param>
        /// <param name="typePrice"></param>
        /// <param name="list_priceMaster"></param>
        /// <param name="chkCost">0 為 活動成本 設定 原成本,1 為 活動成本 依 折數 計算</param>  //add by zhuoqin0830w  2015/04/02
        /// <returns></returns>
        public string AddItemProduct(PriceMasterCustom pmc, HistoryBatch batch, string typePrice, List<PriceMaster> list_priceMaster, int chkCost)
        {
            ProductTemp pTemp = new ProductTemp();
            //List<List<ItemPrice>> ItemPList = new List<List<ItemPrice>>();
            PriceMasterTemp pMasterTemp = new PriceMasterTemp();
            string json = "{success:true}";
            if (!string.IsNullOrEmpty(pmc.product_id.ToString()))
            {
                #region 正式表操作
                //插入price_master
                _priceMasterMgr = new PriceMasterMgr(connectionString);
                _priceMasterTsMgr = new PriceMasterTsMgr(connectionString);
                PriceMaster gigade = list_priceMaster.Where(m => m.product_id == pmc.product_id).FirstOrDefault();
                PriceMaster pMaster = new PriceMaster();
                pMaster.product_id = pmc.product_id;
                if (pmc.combination == 1)
                {
                    pMaster.child_id = 0;
                }
                else if (pmc.combination != 1 && pmc.combination != 0)
                {
                    pMaster.child_id = Convert.ToInt32(pmc.product_id);
                }

                pMaster.site_id = pmc.site_id;
                uint userId = 0;
                if (userId != 0)
                {
                    pMaster.user_id = userId;
                }
                if (pmc.user_level.ToString() != "")
                {
                    pMaster.user_level = pmc.user_level;
                }
                pMaster.product_name = pmc.product_name;
                pMaster.bonus_percent = gigade.bonus_percent;
                pMaster.cost = pmc.cost_at;
                pMaster.price = pmc.price_at;
                pMaster.max_price = pmc.max_price;
                pMaster.max_event_price = pmc.max_price;
                pMaster.default_bonus_percent = gigade.default_bonus_percent;
                if (typePrice == "discount")
                {
                    pMaster.event_price = CommonFunction.ArithmeticalDiscount(pmc.price, pmc.event_price_discount);//Convert.ToInt32(Convert.ToDouble(pmc.price) * (pmc.event_price_discount * 0.01));
                    //add by zhuoqin0830w  2015/04/02  判斷是否是  依原成本設定值
                    if (chkCost == 1)
                    {
                        //eidt by zhuoqin0830w  更改商品活動成本驗算公式使活動價乘以折扣  2015/02/27
                        pMaster.event_cost = CommonFunction.ArithmeticalDiscount(pmc.event_price, pmc.event_cost_discount);// Convert.ToInt32(Convert.ToDouble(pmc.cost) * (pmc.event_cost_discount * 0.01));
                    }
                    else { pMaster.event_cost = pmc.event_cost; }
                }
                else
                {
                    pMaster.event_price = pmc.event_price;
                    pMaster.event_cost = pmc.event_cost;
                }
                pMaster.same_price = gigade.same_price;
                pMaster.price_status = 2;//申請審核
                pMaster.accumulated_bonus = gigade.accumulated_bonus;

                #region 時間 活動時間
                if (pmc.event_start.ToString() != "")
                {
                    pMaster.event_start = pmc.event_start;
                }
                if (pmc.event_end.ToString() != "")
                {
                    pMaster.event_end = pmc.event_end;
                }
                #endregion

                //價格修改 申請審核
                PriceUpdateApply priceUpdateApply = new PriceUpdateApply();
                priceUpdateApply.apply_user = Convert.ToUInt32((Session["caller"] as Caller).user_id);

                //價格審核記錄
                PriceUpdateApplyHistory applyHistroy = new PriceUpdateApplyHistory();
                applyHistroy.user_id = Convert.ToInt32(priceUpdateApply.apply_user);
                applyHistroy.price_status = 1;
                //applyHistroy.type = 3;
                applyHistroy.type = 1;//edit by wwei0216w 所作操作為 1:申請審核的操作 

                _priceUpdateApplyMgr = new PriceUpdateApplyMgr(connectionString);
                _priceUpdateApplyHistoryMgr = new PriceUpdateApplyHistoryMgr(connectionString);
                _tableHistoryMgr = new TableHistoryMgr(connectionString);
                ArrayList excuteSql = new ArrayList();
                #region 新增
                string msg = string.Empty;
                int status = 0;
                int priceMasterId = 0;
                IPriceMasterImplMgr i = new PriceMasterMgr(connectionString);
                List<ItemPrice> iprice = i.AddSingleProduct(pmc, typePrice);
                var result = _priceMasterMgr.Query(pMaster);
                if (result.Count > 0)
                {
                    priceMasterId = -1;
                    msg = pMaster.product_id.ToString();
                    return msg;
                }
                if (typePrice == "discount")
                {
                    pMaster.price = CommonFunction.ArithmeticalDiscount(pmc.price, pmc.price_discount);// Convert.ToInt32(Convert.ToDouble(pmc.price) * (pmc._discount * 0.01));
                    pMaster.cost = CommonFunction.ArithmeticalDiscount(pmc.cost, pmc.cost_discount);// Convert.ToInt32(Convert.ToDouble(pmc.cost) * (pmc._cost_discount * 0.01));
                    pMaster.event_price = CommonFunction.ArithmeticalDiscount(pmc.price, pmc.event_price_discount);// Convert.ToInt32(Convert.ToDouble(pmc.price) * (pmc.event_price_discount * 0.01));
                    //add by zhuoqin0830w  2015/04/02  判斷是否是  依原成本設定值
                    if (chkCost == 1)
                    {
                        pMaster.event_cost = CommonFunction.ArithmeticalDiscount(pmc.event_price, pmc.event_cost_discount);// Convert.ToInt32(Convert.ToDouble(pmc.cost) * (pmc.event_cost_discount * 0.01));
                    }
                    else { pMaster.event_cost = pmc.cost; }
                }

                priceMasterId = _priceMasterMgr.Save(pMaster, iprice, null, ref msg);
                if (priceMasterId != -1)
                {
                    priceUpdateApply.price_master_id = Convert.ToUInt32(priceMasterId); //價格更新申請記錄(設置更新記錄中,更新的價格id)
                    int apply_id = _priceUpdateApplyMgr.Save(priceUpdateApply);//價格更新申請記錄(新增或者更新價格后,將記錄下來插入該表)返回更新記錄的Id號
                    if (apply_id != -1)
                    {
                        pMaster = _priceMasterMgr.Query(new PriceMaster { price_master_id = Convert.ToUInt32(priceMasterId) }).FirstOrDefault();
                        pMaster.apply_id = Convert.ToUInt32(apply_id);
                        applyHistroy.apply_id = apply_id;

                        excuteSql.Add(_priceMasterMgr.Update(pMaster));
                        excuteSql.Add(_priceMasterTsMgr.UpdateTs(pMaster)); //edit by xiangwang0413w 2014/07/22 更新price_master_ts表後同時更新price_master_ts表,以便價格審核
                        excuteSql.Add(_priceUpdateApplyHistoryMgr.SaveSql(applyHistroy));
                        _tableHistoryMgr = new TableHistoryMgr(connectionString);
                        if (_tableHistoryMgr.SaveHistory<PriceMaster>(pMaster, batch, excuteSql))
                        {
                            status = 1;
                        }
                        else { status = 2; }
                    }
                    else { status = 2; }
                }
                else { status = 3; }
                if (status == 1)
                {
                    return "success";
                }
                else if (status == 2)
                {
                    return json = "商品:" + pmc.product_name + Resources.Product.SAVE_FAIL + "'}";
                }
                else
                {
                    return json = msg;
                }
                #endregion

                #endregion
            }
            return "";
        }
 /// <summary>
 /// 組合商品各自定價
 /// </summary>
 /// <param name="pMaster"></param>
 /// <param name="batch"></param>
 /// <param name="applyHistroy"></param>
 /// <param name="excuteSql"></param>
 /// <param name="chkCost">0 為 活動成本 設定 原成本,1 為 活動成本 依 折數 計算</param>  //add by zhuoqin0830w  2015/04/02
 /// <returns></returns>
 public bool SaveComboProductSelf(PriceMasterCustom priceMaster, HistoryBatch batch, int applyId, ArrayList excuteSql, int chkCost)
 {
     List<PriceMaster> childProducts = _priceMasterMgr.QuerySelf(priceMaster).FindAll(p => p.product_id != p.child_id && p.child_id != 0);//查詢子商品
     foreach (var child in childProducts)
     {
         child.apply_id = (uint)applyId;
         child.event_price = CommonFunction.ArithmeticalDiscount(child.price, priceMaster.event_price_discount);// (int)Math.Round(child.price * priceMaster.event_price_discount * 0.01, 0);
         //add by zhuoqin0830w  2015/04/02  判斷是否是  依原成本設定值
         if (chkCost == 1)
         {
             //eidt by zhuoqin0830w  更改商品活動成本驗算公式使活動價乘以折扣  2015/02/27
             child.event_cost = CommonFunction.ArithmeticalDiscount(child.event_price, priceMaster.event_cost_discount);// (int)Math.Round(child.cost * priceMaster.event_cost_discount * 0.01, 0); 
         }
         else { child.event_cost = child.event_cost; }
         // excuteSql.Add(_priceMasterTsMgr.UpdateEventTs(child));UpdateTs
         excuteSql.Add(_priceMasterTsMgr.UpdateTs(child));
     }
     return _tableHistoryMgr.SaveHistory<PriceMaster>(priceMaster, batch, excuteSql);
 }
        /// <summary>
        /// 單一商品
        /// </summary>
        /// <param name="priceMaster"></param>
        /// <param name="batch"></param>
        /// <param name="applyId"></param>
        /// <param name="excuteSql"></param>
        /// <param name="priceType">1為依折扣,2為依活動價</param>  // add by zhuoqin0830w  2015/02/10
        /// <param name="chkCost">0 為 活動成本 設定 原成本,1 為 活動成本 依 折數 計算</param>  //add by zhuoqin0830w  2015/04/02
        /// <returns></returns>
        public bool SaveSingleProduct(PriceMasterCustom priceMaster, HistoryBatch batch, int applyId, ArrayList excuteSql, int priceType, int chkCost)
        {
            bool result = false;
            if (_tableHistoryMgr.SaveHistory<PriceMaster>(priceMaster, batch, excuteSql))
            {
                _itemPriceTsMgr = new ItemPriceTsMgr("");
                _itemPriceMgr = new ItemPriceMgr(connectionString);
                List<ItemPriceCustom> itemPrices = _itemPriceMgr.Query(new ItemPrice() { price_master_id = priceMaster.price_master_id });

                DBTableInfo tableInfo = BLL.gigade.Common.CommonFunction.GetDBInfo<ItemPrice>();
                IParametersrcImplMgr parametersrcMgr = new ParameterMgr(connectionString);
                var paras = parametersrcMgr.QueryUsed(new Parametersrc { ParameterType = "ColumnHistory", ParameterCode = tableInfo.DBName, Used = 1 });
                List<string> cols = (from p in paras
                                     select p.parameterName.Trim().ToLower()).ToList();

                var columns = _tableHistoryMgr.Query_COL_Comment(tableInfo.DBName);
                string pkName = _tableHistoryMgr.Query_TB_PK(tableInfo.DBName);

                foreach (var item in itemPrices)
                {
                    item.apply_id = (uint)applyId;
                    if (priceType == 1)
                    {
                        item.event_money = (uint)CommonFunction.ArithmeticalDiscount((int)item.item_money, priceMaster.event_price_discount);// (uint)Math.Round(item.item_money * priceMaster.event_price_discount * 0.01, 0);
                        //add by zhuoqin0830w  2015/04/02  判斷是否是  依原成本設定值
                        if (chkCost == 1)
                        {
                            //eidt by zhuoqin0830w  更改商品活動成本驗算公式使活動價乘以折扣  2015/02/27
                            item.event_cost = (uint)CommonFunction.ArithmeticalDiscount((int)item.event_money, priceMaster.event_cost_discount);// (uint)Math.Round(item.item_cost * priceMaster.event_cost_discount * 0.01, 0);
                        }
                        else { item.event_cost = (uint)priceMaster.event_cost; }
                    }
                    else
                    {
                        item.event_money = (uint)priceMaster.event_price;
                        item.event_cost = (uint)priceMaster.event_cost;
                    }
                    excuteSql = new ArrayList();
                    excuteSql.Add(_itemPriceTsMgr.UpdateTs(item));
                    if (_tableHistoryMgr.SaveHistory<ItemPrice>(item, batch, excuteSql, cols, columns, pkName))
                    {
                        result = true;
                    }
                }
            }
            return result;
        }