Example #1
0
        //顯示獨立價格
        public static PrdPrice getPrdPrice(TenantPrd prd, string userType, int userId)
        {
            PrdPrice    prdPrice         = new PrdPrice();
            string      type             = UserType.GUEST;
            int         price            = int.MaxValue;
            int         custPriceGradeId = 0;
            string      priceGradeType   = "";
            TenantGrade tenantGrade      = DataManager.tenantDao.GetTenantGrade(prd.tenantId);
            string      tenantGradeType  = "團媽";

            if (tenantGrade != null)
            {
                tenantGradeType = tenantGrade.tenantGrade;
            }
            List <PrdPrice> prices = getPrdPrices(prd, userType, userId, tenantGradeType);

            foreach (PrdPrice itemPrice in prices)
            {
                if (itemPrice.price <= price)
                {
                    price            = itemPrice.price;
                    type             = itemPrice.type;
                    custPriceGradeId = itemPrice.custPriceGradeId;
                    priceGradeType   = itemPrice.priceGradeType;
                }
            }
            prdPrice.price            = price;
            prdPrice.type             = type;
            prdPrice.priceGradeType   = priceGradeType;
            prdPrice.custPriceGradeId = custPriceGradeId;

            return(prdPrice);
        }
        public ActionResult Put([FromBody] ShopCartRequest value)
        {
            ReturnMessage rm = new ReturnMessage();

            try
            {
                string type     = User.Claims.FirstOrDefault(p => p.Type == "type").Value;
                int    memberId = int.Parse(User.Claims.FirstOrDefault(p => p.Type == "jti").Value);
                string sepc     = value.sepc;
                Guid   tenantId = Guid.Parse(User.Claims.FirstOrDefault(p => p.Type == "tenantId").Value);
                Guid   itemId   = Guid.NewGuid();

                TenantPrd prd      = DataManager.tenantPrdDao.getTenandPrd(value.productId);
                PrdPrice  prdPrice = CTenantPrdManager.getPrdPrice(prd, type, memberId);

                if (!string.IsNullOrEmpty(sepc))
                {
                    sepc = (string)JObject.Parse(sepc).GetValue("code");
                }
                ShopCart shopCart = DataManager.shopCartDao.getShopCartPrd(tenantId, memberId, value.productId, sepc);

                if (shopCart == null)
                {
                    shopCart                = new ShopCart();
                    shopCart.id             = itemId;
                    shopCart.memberId       = memberId;
                    shopCart.productId      = value.productId;
                    shopCart.createTime     = DateTime.Now;
                    shopCart.count          = value.count;
                    shopCart.amount         = prdPrice.price * value.count;
                    shopCart.type           = prdPrice.type;
                    shopCart.tenantId       = tenantId;
                    shopCart.prdSepc        = value.sepc;
                    shopCart.prdCustPriceId = prdPrice.custPriceGradeId;
                    shopCart.priceGradeType = prdPrice.priceGradeType;
                    DataManager.shopCartDao.addItem(shopCart);
                }
                else
                {
                    itemId          = shopCart.id;
                    shopCart.count += value.count;
                    shopCart.amount = prdPrice.price * shopCart.count;
                    DataManager.shopCartDao.updateItem(shopCart);
                }
                rm.code = MessageCode.SUCCESS;
                rm.data = itemId;
            }
            catch (Exception e)
            {
                rm.code = MessageCode.ERROR;
                rm.data = e.Message;
            }
            return(Ok(rm));
        }
Example #3
0
        //畫面呈現價格
        public static List <PrdPrice> getPrdPrices(TenantPrd prd, string userType, int userId, string tenantGrade)
        {
            List <PrdPrice> prices = new List <PrdPrice>();

            switch (userType)
            {
            case LoginType.LOGIN_USER:
                TenantMember tenantMember = DataManager.tenantMemberDao.getTenantMemberByMemberId(userId);
                PrdPrice     prdPriceUser = new PrdPrice();
                prdPriceUser.price            = prd.fixedprice == null ? 0 : (int)prd.fixedprice;
                prdPriceUser.type             = CHType.PRICE_NORMAL;
                prdPriceUser.priceGradeType   = "";
                prdPriceUser.custPriceGradeId = 0;
                prices.Add(prdPriceUser);

                prdPriceUser                  = new PrdPrice();
                prdPriceUser.price            = prd.memberPrice == null ? 0 : (int)prd.memberPrice;
                prdPriceUser.type             = CHType.PRICE_MEMBER;
                prdPriceUser.priceGradeType   = "";
                prdPriceUser.custPriceGradeId = 0;
                prices.Add(prdPriceUser);

                if (UserGradeType.TRANS.Equals(tenantMember.gradeType))
                {
                    prdPriceUser                  = new PrdPrice();
                    prdPriceUser.price            = prd.transferPrice == null ? 0 : (int)prd.transferPrice;
                    prdPriceUser.type             = CHType.PRICE_NTRANS;
                    prdPriceUser.priceGradeType   = "轉批價";
                    prdPriceUser.custPriceGradeId = 0;
                    prices.Add(prdPriceUser);
                }
                break;

            case UserType.ADMIN:
                PrdPrice prdPriceAdmin = new PrdPrice();
                prdPriceAdmin.price            = prd.fixedprice == null ? 0 : (int)prd.fixedprice;
                prdPriceAdmin.type             = CHType.PRICE_NORMAL;
                prdPriceAdmin.priceGradeType   = "";
                prdPriceAdmin.custPriceGradeId = 0;
                prices.Add(prdPriceAdmin);

                prdPriceAdmin                  = new PrdPrice();
                prdPriceAdmin.price            = prd.memberPrice == null ? 0 : (int)prd.memberPrice;
                prdPriceAdmin.type             = CHType.PRICE_MEMBER;
                prdPriceAdmin.priceGradeType   = "";
                prdPriceAdmin.custPriceGradeId = 0;
                prices.Add(prdPriceAdmin);
                Debug.WriteLine("[CMemberManager-addMember] error:" + tenantGrade);
                if (tenantGrade != "轉批媽" && tenantGrade != "批發商")
                {
                    break;
                }
                prdPriceAdmin                  = new PrdPrice();
                prdPriceAdmin.price            = prd.transferPrice == null ? 0 : (int)prd.transferPrice;
                prdPriceAdmin.type             = CHType.PRICE_NTRANS;
                prdPriceAdmin.priceGradeType   = "轉批價";
                prdPriceAdmin.custPriceGradeId = 0;
                prices.Add(prdPriceAdmin);
                break;

            default:
                if (userType.StartsWith(UserType.SPC_MEMBER))
                {
                    string   custGrade         = userType.Split(":")[1];
                    PrdPrice prdPriceSPCMember = new PrdPrice();
                    prdPriceSPCMember.price            = prd.fixedprice == null ? 0 : (int)prd.fixedprice;
                    prdPriceSPCMember.type             = CHType.PRICE_NORMAL;
                    prdPriceSPCMember.priceGradeType   = "";
                    prdPriceSPCMember.custPriceGradeId = 0;
                    prices.Add(prdPriceSPCMember);

                    prdPriceSPCMember                  = new PrdPrice();
                    prdPriceSPCMember.price            = prd.memberPrice == null ? 0 : (int)prd.memberPrice;
                    prdPriceSPCMember.type             = CHType.PRICE_MEMBER;
                    prdPriceSPCMember.priceGradeType   = "";
                    prdPriceSPCMember.custPriceGradeId = 0;
                    prices.Add(prdPriceSPCMember);

                    CustSpcPrice spc_price = DataManager.tenantPrdDao.getSpcTenantPrdPrice(prd.tenantId, prd.id, int.Parse(custGrade));
                    if (spc_price != null)
                    {
                        prdPriceSPCMember                  = new PrdPrice();
                        prdPriceSPCMember.price            = spc_price.price;
                        prdPriceSPCMember.type             = spc_price.name;
                        prdPriceSPCMember.priceGradeType   = "自訂價";
                        prdPriceSPCMember.custPriceGradeId = spc_price.id;
                        prices.Add(prdPriceSPCMember);
                    }
                }
                break;
            }
            return(prices);
        }